diff options
| -rw-r--r-- | embassy-net-esp-hosted/src/control.rs | 2 | ||||
| -rw-r--r-- | embassy-net-esp-hosted/src/lib.rs | 5 | ||||
| -rw-r--r-- | embassy-net/src/lib.rs | 40 |
3 files changed, 30 insertions, 17 deletions
diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs index c8cea8503..b1838a425 100644 --- a/embassy-net-esp-hosted/src/control.rs +++ b/embassy-net-esp-hosted/src/control.rs | |||
| @@ -120,7 +120,7 @@ impl<'a> Control<'a> { | |||
| 120 | pwd: unwrap!(String::try_from(password)), | 120 | pwd: unwrap!(String::try_from(password)), |
| 121 | bssid: String::new(), | 121 | bssid: String::new(), |
| 122 | listen_interval: 3, | 122 | listen_interval: 3, |
| 123 | is_wpa3_supported: false, | 123 | is_wpa3_supported: true, |
| 124 | }; | 124 | }; |
| 125 | ioctl!(self, ReqConnectAp, RespConnectAp, req, resp); | 125 | ioctl!(self, ReqConnectAp, RespConnectAp, req, resp); |
| 126 | self.state_ch.set_link_state(LinkState::Up); | 126 | self.state_ch.set_link_state(LinkState::Up); |
diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index c78578bf1..f05e2a70a 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs | |||
| @@ -137,7 +137,7 @@ where | |||
| 137 | let (ch_runner, device) = ch::new(&mut state.ch, ch::driver::HardwareAddress::Ethernet([0; 6])); | 137 | let (ch_runner, device) = ch::new(&mut state.ch, ch::driver::HardwareAddress::Ethernet([0; 6])); |
| 138 | let state_ch = ch_runner.state_runner(); | 138 | let state_ch = ch_runner.state_runner(); |
| 139 | 139 | ||
| 140 | let mut runner = Runner { | 140 | let runner = Runner { |
| 141 | ch: ch_runner, | 141 | ch: ch_runner, |
| 142 | state_ch, | 142 | state_ch, |
| 143 | shared: &state.shared, | 143 | shared: &state.shared, |
| @@ -148,7 +148,6 @@ where | |||
| 148 | spi, | 148 | spi, |
| 149 | heartbeat_deadline: Instant::now() + HEARTBEAT_MAX_GAP, | 149 | heartbeat_deadline: Instant::now() + HEARTBEAT_MAX_GAP, |
| 150 | }; | 150 | }; |
| 151 | runner.init().await; | ||
| 152 | 151 | ||
| 153 | (device, Control::new(state_ch, &state.shared), runner) | 152 | (device, Control::new(state_ch, &state.shared), runner) |
| 154 | } | 153 | } |
| @@ -174,8 +173,6 @@ where | |||
| 174 | IN: InputPin + Wait, | 173 | IN: InputPin + Wait, |
| 175 | OUT: OutputPin, | 174 | OUT: OutputPin, |
| 176 | { | 175 | { |
| 177 | async fn init(&mut self) {} | ||
| 178 | |||
| 179 | /// Run the packet processing. | 176 | /// Run the packet processing. |
| 180 | pub async fn run(mut self) -> ! { | 177 | pub async fn run(mut self) -> ! { |
| 181 | debug!("resetting..."); | 178 | debug!("resetting..."); |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index ef53fb905..a7b7efa87 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -260,7 +260,10 @@ pub struct Stack<'d> { | |||
| 260 | pub(crate) struct Inner { | 260 | pub(crate) struct Inner { |
| 261 | pub(crate) sockets: SocketSet<'static>, // Lifetime type-erased. | 261 | pub(crate) sockets: SocketSet<'static>, // Lifetime type-erased. |
| 262 | pub(crate) iface: Interface, | 262 | pub(crate) iface: Interface, |
| 263 | /// Waker used for triggering polls. | ||
| 263 | pub(crate) waker: WakerRegistration, | 264 | pub(crate) waker: WakerRegistration, |
| 265 | /// Waker used for waiting for link up or config up. | ||
| 266 | state_waker: WakerRegistration, | ||
| 264 | hardware_address: HardwareAddress, | 267 | hardware_address: HardwareAddress, |
| 265 | next_local_port: u16, | 268 | next_local_port: u16, |
| 266 | link_up: bool, | 269 | link_up: bool, |
| @@ -270,7 +273,6 @@ pub(crate) struct Inner { | |||
| 270 | static_v6: Option<StaticConfigV6>, | 273 | static_v6: Option<StaticConfigV6>, |
| 271 | #[cfg(feature = "dhcpv4")] | 274 | #[cfg(feature = "dhcpv4")] |
| 272 | dhcp_socket: Option<SocketHandle>, | 275 | dhcp_socket: Option<SocketHandle>, |
| 273 | config_waker: WakerRegistration, | ||
| 274 | #[cfg(feature = "dns")] | 276 | #[cfg(feature = "dns")] |
| 275 | dns_socket: SocketHandle, | 277 | dns_socket: SocketHandle, |
| 276 | #[cfg(feature = "dns")] | 278 | #[cfg(feature = "dns")] |
| @@ -326,6 +328,7 @@ pub fn new<'d, D: Driver, const SOCK: usize>( | |||
| 326 | sockets, | 328 | sockets, |
| 327 | iface, | 329 | iface, |
| 328 | waker: WakerRegistration::new(), | 330 | waker: WakerRegistration::new(), |
| 331 | state_waker: WakerRegistration::new(), | ||
| 329 | next_local_port, | 332 | next_local_port, |
| 330 | hardware_address, | 333 | hardware_address, |
| 331 | link_up: false, | 334 | link_up: false, |
| @@ -335,7 +338,6 @@ pub fn new<'d, D: Driver, const SOCK: usize>( | |||
| 335 | static_v6: None, | 338 | static_v6: None, |
| 336 | #[cfg(feature = "dhcpv4")] | 339 | #[cfg(feature = "dhcpv4")] |
| 337 | dhcp_socket: None, | 340 | dhcp_socket: None, |
| 338 | config_waker: WakerRegistration::new(), | ||
| 339 | #[cfg(feature = "dns")] | 341 | #[cfg(feature = "dns")] |
| 340 | dns_socket, | 342 | dns_socket, |
| 341 | #[cfg(feature = "dns")] | 343 | #[cfg(feature = "dns")] |
| @@ -421,10 +423,20 @@ impl<'d> Stack<'d> { | |||
| 421 | v4_up || v6_up | 423 | v4_up || v6_up |
| 422 | } | 424 | } |
| 423 | 425 | ||
| 426 | /// Wait for the network device to obtain a link signal. | ||
| 427 | pub async fn wait_link_up(&self) { | ||
| 428 | self.wait(|| self.is_link_up()).await | ||
| 429 | } | ||
| 430 | |||
| 431 | /// Wait for the network device to lose link signal. | ||
| 432 | pub async fn wait_link_down(&self) { | ||
| 433 | self.wait(|| !self.is_link_up()).await | ||
| 434 | } | ||
| 435 | |||
| 424 | /// Wait for the network stack to obtain a valid IP configuration. | 436 | /// Wait for the network stack to obtain a valid IP configuration. |
| 425 | /// | 437 | /// |
| 426 | /// ## Notes: | 438 | /// ## Notes: |
| 427 | /// - Ensure [`Stack::run`] has been called before using this function. | 439 | /// - Ensure [`Runner::run`] has been started before using this function. |
| 428 | /// | 440 | /// |
| 429 | /// - This function may never return (e.g. if no configuration is obtained through DHCP). | 441 | /// - This function may never return (e.g. if no configuration is obtained through DHCP). |
| 430 | /// The caller is supposed to handle a timeout for this case. | 442 | /// The caller is supposed to handle a timeout for this case. |
| @@ -451,13 +463,17 @@ impl<'d> Stack<'d> { | |||
| 451 | /// // ... | 463 | /// // ... |
| 452 | /// ``` | 464 | /// ``` |
| 453 | pub async fn wait_config_up(&self) { | 465 | pub async fn wait_config_up(&self) { |
| 454 | // If the config is up already, we can return immediately. | 466 | self.wait(|| self.is_config_up()).await |
| 455 | if self.is_config_up() { | 467 | } |
| 456 | return; | ||
| 457 | } | ||
| 458 | 468 | ||
| 459 | poll_fn(|cx| { | 469 | /// Wait for the network stack to lose a valid IP configuration. |
| 460 | if self.is_config_up() { | 470 | pub async fn wait_config_down(&self) { |
| 471 | self.wait(|| !self.is_config_up()).await | ||
| 472 | } | ||
| 473 | |||
| 474 | fn wait<'a>(&'a self, mut predicate: impl FnMut() -> bool + 'a) -> impl Future<Output = ()> + 'a { | ||
| 475 | poll_fn(move |cx| { | ||
| 476 | if predicate() { | ||
| 461 | Poll::Ready(()) | 477 | Poll::Ready(()) |
| 462 | } else { | 478 | } else { |
| 463 | // If the config is not up, we register a waker that is woken up | 479 | // If the config is not up, we register a waker that is woken up |
| @@ -465,13 +481,12 @@ impl<'d> Stack<'d> { | |||
| 465 | trace!("Waiting for config up"); | 481 | trace!("Waiting for config up"); |
| 466 | 482 | ||
| 467 | self.with_mut(|i| { | 483 | self.with_mut(|i| { |
| 468 | i.config_waker.register(cx.waker()); | 484 | i.state_waker.register(cx.waker()); |
| 469 | }); | 485 | }); |
| 470 | 486 | ||
| 471 | Poll::Pending | 487 | Poll::Pending |
| 472 | } | 488 | } |
| 473 | }) | 489 | }) |
| 474 | .await; | ||
| 475 | } | 490 | } |
| 476 | 491 | ||
| 477 | /// Get the current IPv4 configuration. | 492 | /// Get the current IPv4 configuration. |
| @@ -775,7 +790,7 @@ impl Inner { | |||
| 775 | .update_servers(&dns_servers[..count]); | 790 | .update_servers(&dns_servers[..count]); |
| 776 | } | 791 | } |
| 777 | 792 | ||
| 778 | self.config_waker.wake(); | 793 | self.state_waker.wake(); |
| 779 | } | 794 | } |
| 780 | 795 | ||
| 781 | fn poll<D: Driver>(&mut self, cx: &mut Context<'_>, driver: &mut D) { | 796 | fn poll<D: Driver>(&mut self, cx: &mut Context<'_>, driver: &mut D) { |
| @@ -813,6 +828,7 @@ impl Inner { | |||
| 813 | // Print when changed | 828 | // Print when changed |
| 814 | if old_link_up != self.link_up { | 829 | if old_link_up != self.link_up { |
| 815 | info!("link_up = {:?}", self.link_up); | 830 | info!("link_up = {:?}", self.link_up); |
| 831 | self.state_waker.wake(); | ||
| 816 | } | 832 | } |
| 817 | 833 | ||
| 818 | #[allow(unused_mut)] | 834 | #[allow(unused_mut)] |
