diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index fc9d0894..f66ebc19 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -21,7 +21,7 @@ pub trait Device { fn register_waker(&mut self, waker: &Waker); fn capabilities(&mut self) -> DeviceCapabilities; fn link_state(&mut self) -> LinkState; - fn ethernet_address(&mut self) -> [u8; 6]; + fn ethernet_address(&self) -> [u8; 6]; } pub struct DeviceAdapter { diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index c4229446..ffe786b3 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -15,7 +15,9 @@ pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator} pub use device::{Device, LinkState}; pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf, MTU}; -pub use stack::{init, is_config_up, is_init, is_link_up, run, StackResources}; +pub use stack::{ + config, ethernet_address, init, is_config_up, is_init, is_link_up, run, StackResources, +}; #[cfg(feature = "tcp")] mod tcp_socket; diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 8623a727..9461f832 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -21,7 +21,7 @@ use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress}; use crate::config::Configurator; use crate::config::Event; use crate::device::{Device, DeviceAdapter, LinkState}; -use crate::Interface; +use crate::{Config, Interface}; const LOCAL_PORT_MIN: u16 = 1025; const LOCAL_PORT_MAX: u16 = 65535; @@ -56,7 +56,7 @@ static STACK: ThreadModeMutex>> = ThreadModeMutex::new(Ref pub(crate) struct Stack { pub iface: Interface, link_up: bool, - config_up: bool, + config: Option, next_local_port: u16, configurator: &'static mut dyn Configurator, waker: WakerRegistration, @@ -113,7 +113,7 @@ impl Stack { debug!(" DNS server {}: {}", i, s); } - self.config_up = true; + self.config = Some(config) } Event::Deconfigured => { debug!("Lost IP configuration"); @@ -122,7 +122,7 @@ impl Stack { if medium == Medium::Ethernet { self.iface.routes_mut().remove_default_ipv4_route(); } - self.config_up = false; + self.config = None } } } @@ -209,7 +209,7 @@ pub fn init( let stack = Stack { iface, link_up: false, - config_up: false, + config: None, configurator, next_local_port: local_port, waker: WakerRegistration::new(), @@ -218,6 +218,18 @@ pub fn init( *STACK.borrow().borrow_mut() = Some(stack); } +pub fn ethernet_address() -> [u8; 6] { + STACK + .borrow() + .borrow() + .as_ref() + .unwrap() + .iface + .device() + .device + .ethernet_address() +} + pub fn is_init() -> bool { STACK.borrow().borrow().is_some() } @@ -227,7 +239,11 @@ pub fn is_link_up() -> bool { } pub fn is_config_up() -> bool { - STACK.borrow().borrow().as_ref().unwrap().config_up + STACK.borrow().borrow().as_ref().unwrap().config.is_some() +} + +pub fn config() -> Option { + STACK.borrow().borrow().as_ref().unwrap().config.clone() } pub async fn run() -> ! { diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index f102f431..e6ffd047 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -334,7 +334,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device } } - fn ethernet_address(&mut self) -> [u8; 6] { + fn ethernet_address(&self) -> [u8; 6] { self.mac_addr } } diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 023ec7a0..d43d4f1a 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -268,7 +268,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device } } - fn ethernet_address(&mut self) -> [u8; 6] { + fn ethernet_address(&self) -> [u8; 6] { self.mac_addr } } diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 70460d23..f14a29c4 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs @@ -265,7 +265,7 @@ impl embassy_net::Device for Device { RX_CHANNEL.try_recv().ok() } - fn ethernet_address(&mut self) -> [u8; 6] { + fn ethernet_address(&self) -> [u8; 6] { self.mac_addr } } diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs index 328479e6..09a4be07 100644 --- a/examples/std/src/tuntap.rs +++ b/examples/std/src/tuntap.rs @@ -219,7 +219,7 @@ impl Device for TunTapDevice { LinkState::Up } - fn ethernet_address(&mut self) -> [u8; 6] { + fn ethernet_address(&self) -> [u8; 6] { [0x02, 0x03, 0x04, 0x05, 0x06, 0x07] } }