summaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-05-02 16:15:05 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-05-02 16:19:34 +0200
commita5f5c3a844561d56c91513f36a1077038d8a0336 (patch)
tree017ea0d73195fb0665a27ff97e6da5902e44c25b /embassy-net
parente74af83681bc65524acda4ec0a2b52e447c62daf (diff)
downloadembassy-a5f5c3a844561d56c91513f36a1077038d8a0336.zip
net: add functions to get current Eth and IP config
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/src/device.rs2
-rw-r--r--embassy-net/src/lib.rs4
-rw-r--r--embassy-net/src/stack.rs28
3 files changed, 26 insertions, 8 deletions
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<RefCell<Option<Stack>>> = ThreadModeMutex::new(Ref
pub(crate) struct Stack {
pub iface: Interface,
link_up: bool,
- config_up: bool,
+ config: Option<Config>,
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<const ADDR: usize, const SOCK: usize, const NEIGH: usize>(
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<const ADDR: usize, const SOCK: usize, const NEIGH: usize>(
*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<Config> {
+ STACK.borrow().borrow().as_ref().unwrap().config.clone()
}
pub async fn run() -> ! {