From a5f5c3a844561d56c91513f36a1077038d8a0336 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 2 May 2022 16:15:05 +0200 Subject: net: add functions to get current Eth and IP config --- embassy-net/src/stack.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'embassy-net/src/stack.rs') 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}; 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() -> ! { -- cgit