diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-05-02 22:10:46 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-02 22:10:46 +0200 |
| commit | b1afe54c5fd7589e07af5e87d149892bc25582ef (patch) | |
| tree | 017ea0d73195fb0665a27ff97e6da5902e44c25b | |
| parent | e74af83681bc65524acda4ec0a2b52e447c62daf (diff) | |
| parent | a5f5c3a844561d56c91513f36a1077038d8a0336 (diff) | |
Merge pull request #746 from embassy-rs/net-get-config
net: add functions to get current Eth and IP config
| -rw-r--r-- | embassy-net/src/device.rs | 2 | ||||
| -rw-r--r-- | embassy-net/src/lib.rs | 4 | ||||
| -rw-r--r-- | embassy-net/src/stack.rs | 28 | ||||
| -rw-r--r-- | embassy-stm32/src/eth/v1/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/eth/v2/mod.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_ethernet.rs | 2 | ||||
| -rw-r--r-- | examples/std/src/tuntap.rs | 2 |
7 files changed, 30 insertions, 12 deletions
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index fc9d08947..f66ebc193 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -21,7 +21,7 @@ pub trait Device { | |||
| 21 | fn register_waker(&mut self, waker: &Waker); | 21 | fn register_waker(&mut self, waker: &Waker); |
| 22 | fn capabilities(&mut self) -> DeviceCapabilities; | 22 | fn capabilities(&mut self) -> DeviceCapabilities; |
| 23 | fn link_state(&mut self) -> LinkState; | 23 | fn link_state(&mut self) -> LinkState; |
| 24 | fn ethernet_address(&mut self) -> [u8; 6]; | 24 | fn ethernet_address(&self) -> [u8; 6]; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | pub struct DeviceAdapter { | 27 | pub struct DeviceAdapter { |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index c4229446f..ffe786b36 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} | |||
| 15 | 15 | ||
| 16 | pub use device::{Device, LinkState}; | 16 | pub use device::{Device, LinkState}; |
| 17 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf, MTU}; | 17 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf, MTU}; |
| 18 | pub use stack::{init, is_config_up, is_init, is_link_up, run, StackResources}; | 18 | pub use stack::{ |
| 19 | config, ethernet_address, init, is_config_up, is_init, is_link_up, run, StackResources, | ||
| 20 | }; | ||
| 19 | 21 | ||
| 20 | #[cfg(feature = "tcp")] | 22 | #[cfg(feature = "tcp")] |
| 21 | mod tcp_socket; | 23 | mod tcp_socket; |
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}; | |||
| 21 | use crate::config::Configurator; | 21 | use crate::config::Configurator; |
| 22 | use crate::config::Event; | 22 | use crate::config::Event; |
| 23 | use crate::device::{Device, DeviceAdapter, LinkState}; | 23 | use crate::device::{Device, DeviceAdapter, LinkState}; |
| 24 | use crate::Interface; | 24 | use crate::{Config, Interface}; |
| 25 | 25 | ||
| 26 | const LOCAL_PORT_MIN: u16 = 1025; | 26 | const LOCAL_PORT_MIN: u16 = 1025; |
| 27 | const LOCAL_PORT_MAX: u16 = 65535; | 27 | const LOCAL_PORT_MAX: u16 = 65535; |
| @@ -56,7 +56,7 @@ static STACK: ThreadModeMutex<RefCell<Option<Stack>>> = ThreadModeMutex::new(Ref | |||
| 56 | pub(crate) struct Stack { | 56 | pub(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 | ||
| 221 | pub 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 | |||
| 221 | pub fn is_init() -> bool { | 233 | pub 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 | ||
| 229 | pub fn is_config_up() -> bool { | 241 | pub 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 | |||
| 245 | pub fn config() -> Option<Config> { | ||
| 246 | STACK.borrow().borrow().as_ref().unwrap().config.clone() | ||
| 231 | } | 247 | } |
| 232 | 248 | ||
| 233 | pub async fn run() -> ! { | 249 | pub async fn run() -> ! { |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index f102f4314..e6ffd047d 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 | |||
| 334 | } | 334 | } |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | fn ethernet_address(&mut self) -> [u8; 6] { | 337 | fn ethernet_address(&self) -> [u8; 6] { |
| 338 | self.mac_addr | 338 | self.mac_addr |
| 339 | } | 339 | } |
| 340 | } | 340 | } |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 023ec7a0b..d43d4f1a8 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 | |||
| 268 | } | 268 | } |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | fn ethernet_address(&mut self) -> [u8; 6] { | 271 | fn ethernet_address(&self) -> [u8; 6] { |
| 272 | self.mac_addr | 272 | self.mac_addr |
| 273 | } | 273 | } |
| 274 | } | 274 | } |
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 70460d23c..f14a29c49 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 { | |||
| 265 | RX_CHANNEL.try_recv().ok() | 265 | RX_CHANNEL.try_recv().ok() |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | fn ethernet_address(&mut self) -> [u8; 6] { | 268 | fn ethernet_address(&self) -> [u8; 6] { |
| 269 | self.mac_addr | 269 | self.mac_addr |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs index 328479e68..09a4be070 100644 --- a/examples/std/src/tuntap.rs +++ b/examples/std/src/tuntap.rs | |||
| @@ -219,7 +219,7 @@ impl Device for TunTapDevice { | |||
| 219 | LinkState::Up | 219 | LinkState::Up |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | fn ethernet_address(&mut self) -> [u8; 6] { | 222 | fn ethernet_address(&self) -> [u8; 6] { |
| 223 | [0x02, 0x03, 0x04, 0x05, 0x06, 0x07] | 223 | [0x02, 0x03, 0x04, 0x05, 0x06, 0x07] |
| 224 | } | 224 | } |
| 225 | } | 225 | } |
