net: add functions to get current Eth and IP config
This commit is contained in:
parent
e74af83681
commit
a5f5c3a844
7 changed files with 30 additions and 12 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() -> ! {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue