net-ppp: add callback for IP configuration.

This commit is contained in:
Dario Nieuwenhuis 2023-08-25 19:49:28 +02:00
parent a026db3f57
commit 623f37a273

View file

@ -13,7 +13,7 @@ use embassy_net_driver_channel as ch;
use embassy_net_driver_channel::driver::LinkState; use embassy_net_driver_channel::driver::LinkState;
use embedded_io_async::{BufRead, Write, WriteAllError}; use embedded_io_async::{BufRead, Write, WriteAllError};
use ppproto::pppos::{BufferFullError, PPPoS, PPPoSAction}; use ppproto::pppos::{BufferFullError, PPPoS, PPPoSAction};
pub use ppproto::Config; pub use ppproto::{Config, Ipv4Status};
const MTU: usize = 1500; const MTU: usize = 1500;
@ -79,6 +79,7 @@ impl<'d> Runner<'d> {
&mut self, &mut self,
mut rw: RW, mut rw: RW,
config: ppproto::Config<'_>, config: ppproto::Config<'_>,
mut on_ipv4_up: impl FnMut(Ipv4Status),
) -> Result<Infallible, RunError<RW::Error>> { ) -> Result<Infallible, RunError<RW::Error>> {
let mut ppp = PPPoS::new(config); let mut ppp = PPPoS::new(config);
ppp.open().unwrap(); ppp.open().unwrap();
@ -91,6 +92,7 @@ impl<'d> Runner<'d> {
let mut tx_buf = [0; 2048]; let mut tx_buf = [0; 2048];
let mut needs_poll = true; let mut needs_poll = true;
let mut was_up = false;
loop { loop {
let rx_fut = async { let rx_fut = async {
@ -124,9 +126,19 @@ impl<'d> Runner<'d> {
PPPoSAction::Transmit(n) => rw.write_all(&tx_buf[..n]).await?, PPPoSAction::Transmit(n) => rw.write_all(&tx_buf[..n]).await?,
} }
match ppp.status().phase { let status = ppp.status();
ppproto::Phase::Open => state_chan.set_link_state(LinkState::Up), match status.phase {
_ => state_chan.set_link_state(LinkState::Down), ppproto::Phase::Open => {
if !was_up {
on_ipv4_up(status.ipv4.unwrap());
}
was_up = true;
state_chan.set_link_state(LinkState::Up);
}
_ => {
was_up = false;
state_chan.set_link_state(LinkState::Down);
}
} }
} }
Either::Second(pkt) => { Either::Second(pkt) => {