Introduce driver::HardwareAddress without smoltcp dependency

This commit is contained in:
Ruben De Smet
2023-07-31 10:40:48 +02:00
parent 69c0a89aa5
commit 4afdce4ec5
11 changed files with 54 additions and 26 deletions

View File

@ -230,6 +230,18 @@ pub(crate) struct SocketStack {
next_local_port: u16,
}
fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> HardwareAddress {
match addr {
#[cfg(feature = "medium-ethernet")]
driver::HardwareAddress::Ethernet(eth) => HardwareAddress::Ethernet(EthernetAddress(eth)),
#[cfg(feature = "medium-ieee802154")]
driver::HardwareAddress::Ieee802154(ieee) => HardwareAddress::Ieee802154(Ieee802154Address::Extended(ieee)),
#[allow(unreachable_patterns)]
_ => panic!("Unsupported address {:?}. Make sure to enable medium-ethernet or medium-ieee802154 in embassy-net's Cargo features.", addr),
}
}
impl<D: Driver + 'static> Stack<D> {
/// Create a new network stack.
pub fn new<const SOCK: usize>(
@ -243,11 +255,11 @@ impl<D: Driver + 'static> Stack<D> {
let hardware_addr = match medium {
#[cfg(feature = "medium-ethernet")]
Medium::Ethernet => device.hardware_address(),
Medium::Ethernet => to_smoltcp_hardware_address(device.hardware_address()),
#[cfg(feature = "medium-ip")]
Medium::Ip => HardwareAddress::Ip,
#[cfg(feature = "medium-ieee802154")]
Medium::Ieee802154 => device.hardware_address(),
Medium::Ieee802154 => to_smoltcp_hardware_address(device.hardware_address()),
#[allow(unreachable_patterns)]
_ => panic!(
"Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.",
@ -338,7 +350,7 @@ impl<D: Driver + 'static> Stack<D> {
/// Get the hardware address of the network interface.
pub fn hardware_address(&self) -> HardwareAddress {
self.with(|_s, i| i.device.hardware_address())
self.with(|_s, i| to_smoltcp_hardware_address(i.device.hardware_address()))
}
/// Get whether the link is up.
@ -744,7 +756,8 @@ impl<D: Driver + 'static> Inner<D> {
if self.device.capabilities().medium == Medium::Ethernet
|| self.device.capabilities().medium == Medium::Ieee802154
{
s.iface.set_hardware_addr(self.device.hardware_address());
s.iface
.set_hardware_addr(to_smoltcp_hardware_address(self.device.hardware_address()));
}
let timestamp = instant_to_smoltcp(Instant::now());