diff options
Diffstat (limited to 'embassy-net')
| -rw-r--r-- | embassy-net/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-net/src/stack.rs | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index efa5f3cb1..13f14b836 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -18,7 +18,7 @@ pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator} | |||
| 18 | 18 | ||
| 19 | pub use device::{Device, LinkState}; | 19 | pub use device::{Device, LinkState}; |
| 20 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; | 20 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; |
| 21 | pub use stack::{init, is_init, run}; | 21 | pub use stack::{init, is_config_up, is_init, is_link_up, run}; |
| 22 | 22 | ||
| 23 | #[cfg(feature = "tcp")] | 23 | #[cfg(feature = "tcp")] |
| 24 | mod tcp_socket; | 24 | mod tcp_socket; |
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 83cd71707..e436beb1e 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -46,6 +46,7 @@ pub(crate) struct Stack { | |||
| 46 | iface: Interface, | 46 | iface: Interface, |
| 47 | pub sockets: SocketSet, | 47 | pub sockets: SocketSet, |
| 48 | link_up: bool, | 48 | link_up: bool, |
| 49 | config_up: bool, | ||
| 49 | next_local_port: u16, | 50 | next_local_port: u16, |
| 50 | configurator: &'static mut dyn Configurator, | 51 | configurator: &'static mut dyn Configurator, |
| 51 | waker: WakerRegistration, | 52 | waker: WakerRegistration, |
| @@ -102,6 +103,8 @@ impl Stack { | |||
| 102 | for (i, s) in config.dns_servers.iter().enumerate() { | 103 | for (i, s) in config.dns_servers.iter().enumerate() { |
| 103 | debug!(" DNS server {}: {}", i, s); | 104 | debug!(" DNS server {}: {}", i, s); |
| 104 | } | 105 | } |
| 106 | |||
| 107 | self.config_up = true; | ||
| 105 | } | 108 | } |
| 106 | Event::Deconfigured => { | 109 | Event::Deconfigured => { |
| 107 | debug!("Lost IP configuration"); | 110 | debug!("Lost IP configuration"); |
| @@ -110,6 +113,7 @@ impl Stack { | |||
| 110 | if medium == Medium::Ethernet { | 113 | if medium == Medium::Ethernet { |
| 111 | self.iface.routes_mut().remove_default_ipv4_route(); | 114 | self.iface.routes_mut().remove_default_ipv4_route(); |
| 112 | } | 115 | } |
| 116 | self.config_up = false; | ||
| 113 | } | 117 | } |
| 114 | } | 118 | } |
| 115 | } | 119 | } |
| @@ -209,6 +213,7 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf | |||
| 209 | iface, | 213 | iface, |
| 210 | sockets, | 214 | sockets, |
| 211 | link_up: false, | 215 | link_up: false, |
| 216 | config_up: false, | ||
| 212 | configurator, | 217 | configurator, |
| 213 | next_local_port: local_port, | 218 | next_local_port: local_port, |
| 214 | waker: WakerRegistration::new(), | 219 | waker: WakerRegistration::new(), |
| @@ -221,6 +226,14 @@ pub fn is_init() -> bool { | |||
| 221 | STACK.borrow().borrow().is_some() | 226 | STACK.borrow().borrow().is_some() |
| 222 | } | 227 | } |
| 223 | 228 | ||
| 229 | pub fn is_link_up() -> bool { | ||
| 230 | STACK.borrow().borrow().as_ref().unwrap().link_up | ||
| 231 | } | ||
| 232 | |||
| 233 | pub fn is_config_up() -> bool { | ||
| 234 | STACK.borrow().borrow().as_ref().unwrap().config_up | ||
| 235 | } | ||
| 236 | |||
| 224 | pub async fn run() { | 237 | pub async fn run() { |
| 225 | futures::future::poll_fn(|cx| { | 238 | futures::future::poll_fn(|cx| { |
| 226 | Stack::with(|stack| stack.poll(cx)); | 239 | Stack::with(|stack| stack.poll(cx)); |
