aboutsummaryrefslogtreecommitdiff
path: root/embassy-net/src/stack.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-05-02 16:15:05 +0200
committerDario Nieuwenhuis <[email protected]>2022-05-02 16:19:34 +0200
commita5f5c3a844561d56c91513f36a1077038d8a0336 (patch)
tree017ea0d73195fb0665a27ff97e6da5902e44c25b /embassy-net/src/stack.rs
parente74af83681bc65524acda4ec0a2b52e447c62daf (diff)
net: add functions to get current Eth and IP config
Diffstat (limited to 'embassy-net/src/stack.rs')
-rw-r--r--embassy-net/src/stack.rs28
1 files changed, 22 insertions, 6 deletions
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs
index 8623a7275..9461f832f 100644
--- a/embassy-net/src/stack.rs
+++ b/embassy-net/src/stack.rs
@@ -21,7 +21,7 @@ use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress};
21use crate::config::Configurator; 21use crate::config::Configurator;
22use crate::config::Event; 22use crate::config::Event;
23use crate::device::{Device, DeviceAdapter, LinkState}; 23use crate::device::{Device, DeviceAdapter, LinkState};
24use crate::Interface; 24use crate::{Config, Interface};
25 25
26const LOCAL_PORT_MIN: u16 = 1025; 26const LOCAL_PORT_MIN: u16 = 1025;
27const LOCAL_PORT_MAX: u16 = 65535; 27const LOCAL_PORT_MAX: u16 = 65535;
@@ -56,7 +56,7 @@ static STACK: ThreadModeMutex<RefCell<Option<Stack>>> = ThreadModeMutex::new(Ref
56pub(crate) struct Stack { 56pub(crate) struct Stack {
57 pub iface: Interface, 57 pub iface: Interface,
58 link_up: bool, 58 link_up: bool,
59 config_up: bool, 59 config: Option<Config>,
60 next_local_port: u16, 60 next_local_port: u16,
61 configurator: &'static mut dyn Configurator, 61 configurator: &'static mut dyn Configurator,
62 waker: WakerRegistration, 62 waker: WakerRegistration,
@@ -113,7 +113,7 @@ impl Stack {
113 debug!(" DNS server {}: {}", i, s); 113 debug!(" DNS server {}: {}", i, s);
114 } 114 }
115 115
116 self.config_up = true; 116 self.config = Some(config)
117 } 117 }
118 Event::Deconfigured => { 118 Event::Deconfigured => {
119 debug!("Lost IP configuration"); 119 debug!("Lost IP configuration");
@@ -122,7 +122,7 @@ impl Stack {
122 if medium == Medium::Ethernet { 122 if medium == Medium::Ethernet {
123 self.iface.routes_mut().remove_default_ipv4_route(); 123 self.iface.routes_mut().remove_default_ipv4_route();
124 } 124 }
125 self.config_up = false; 125 self.config = None
126 } 126 }
127 } 127 }
128 } 128 }
@@ -209,7 +209,7 @@ pub fn init<const ADDR: usize, const SOCK: usize, const NEIGH: usize>(
209 let stack = Stack { 209 let stack = Stack {
210 iface, 210 iface,
211 link_up: false, 211 link_up: false,
212 config_up: false, 212 config: None,
213 configurator, 213 configurator,
214 next_local_port: local_port, 214 next_local_port: local_port,
215 waker: WakerRegistration::new(), 215 waker: WakerRegistration::new(),
@@ -218,6 +218,18 @@ pub fn init<const ADDR: usize, const SOCK: usize, const NEIGH: usize>(
218 *STACK.borrow().borrow_mut() = Some(stack); 218 *STACK.borrow().borrow_mut() = Some(stack);
219} 219}
220 220
221pub fn ethernet_address() -> [u8; 6] {
222 STACK
223 .borrow()
224 .borrow()
225 .as_ref()
226 .unwrap()
227 .iface
228 .device()
229 .device
230 .ethernet_address()
231}
232
221pub fn is_init() -> bool { 233pub fn is_init() -> bool {
222 STACK.borrow().borrow().is_some() 234 STACK.borrow().borrow().is_some()
223} 235}
@@ -227,7 +239,11 @@ pub fn is_link_up() -> bool {
227} 239}
228 240
229pub fn is_config_up() -> bool { 241pub fn is_config_up() -> bool {
230 STACK.borrow().borrow().as_ref().unwrap().config_up 242 STACK.borrow().borrow().as_ref().unwrap().config.is_some()
243}
244
245pub fn config() -> Option<Config> {
246 STACK.borrow().borrow().as_ref().unwrap().config.clone()
231} 247}
232 248
233pub async fn run() -> ! { 249pub async fn run() -> ! {