diff options
| author | Ruben De Smet <[email protected]> | 2023-07-31 10:40:48 +0200 |
|---|---|---|
| committer | Ruben De Smet <[email protected]> | 2023-07-31 14:21:26 +0200 |
| commit | 4afdce4ec5e39324f8a690961070a25f16397f56 (patch) | |
| tree | cd0c35f8eb67001349bc48cd7d643565760a6eff /embassy-net | |
| parent | 69c0a89aa5d52e048fdd8ddc5d47b767da07e88b (diff) | |
Introduce driver::HardwareAddress without smoltcp dependency
Diffstat (limited to 'embassy-net')
| -rw-r--r-- | embassy-net/src/lib.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index efd820a63..7587b46ff 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -230,6 +230,18 @@ pub(crate) struct SocketStack { | |||
| 230 | next_local_port: u16, | 230 | next_local_port: u16, |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> HardwareAddress { | ||
| 234 | match addr { | ||
| 235 | #[cfg(feature = "medium-ethernet")] | ||
| 236 | driver::HardwareAddress::Ethernet(eth) => HardwareAddress::Ethernet(EthernetAddress(eth)), | ||
| 237 | #[cfg(feature = "medium-ieee802154")] | ||
| 238 | driver::HardwareAddress::Ieee802154(ieee) => HardwareAddress::Ieee802154(Ieee802154Address::Extended(ieee)), | ||
| 239 | |||
| 240 | #[allow(unreachable_patterns)] | ||
| 241 | _ => panic!("Unsupported address {:?}. Make sure to enable medium-ethernet or medium-ieee802154 in embassy-net's Cargo features.", addr), | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 233 | impl<D: Driver + 'static> Stack<D> { | 245 | impl<D: Driver + 'static> Stack<D> { |
| 234 | /// Create a new network stack. | 246 | /// Create a new network stack. |
| 235 | pub fn new<const SOCK: usize>( | 247 | pub fn new<const SOCK: usize>( |
| @@ -243,11 +255,11 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 243 | 255 | ||
| 244 | let hardware_addr = match medium { | 256 | let hardware_addr = match medium { |
| 245 | #[cfg(feature = "medium-ethernet")] | 257 | #[cfg(feature = "medium-ethernet")] |
| 246 | Medium::Ethernet => device.hardware_address(), | 258 | Medium::Ethernet => to_smoltcp_hardware_address(device.hardware_address()), |
| 247 | #[cfg(feature = "medium-ip")] | 259 | #[cfg(feature = "medium-ip")] |
| 248 | Medium::Ip => HardwareAddress::Ip, | 260 | Medium::Ip => HardwareAddress::Ip, |
| 249 | #[cfg(feature = "medium-ieee802154")] | 261 | #[cfg(feature = "medium-ieee802154")] |
| 250 | Medium::Ieee802154 => device.hardware_address(), | 262 | Medium::Ieee802154 => to_smoltcp_hardware_address(device.hardware_address()), |
| 251 | #[allow(unreachable_patterns)] | 263 | #[allow(unreachable_patterns)] |
| 252 | _ => panic!( | 264 | _ => panic!( |
| 253 | "Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.", | 265 | "Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.", |
| @@ -338,7 +350,7 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 338 | 350 | ||
| 339 | /// Get the hardware address of the network interface. | 351 | /// Get the hardware address of the network interface. |
| 340 | pub fn hardware_address(&self) -> HardwareAddress { | 352 | pub fn hardware_address(&self) -> HardwareAddress { |
| 341 | self.with(|_s, i| i.device.hardware_address()) | 353 | self.with(|_s, i| to_smoltcp_hardware_address(i.device.hardware_address())) |
| 342 | } | 354 | } |
| 343 | 355 | ||
| 344 | /// Get whether the link is up. | 356 | /// Get whether the link is up. |
| @@ -744,7 +756,8 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 744 | if self.device.capabilities().medium == Medium::Ethernet | 756 | if self.device.capabilities().medium == Medium::Ethernet |
| 745 | || self.device.capabilities().medium == Medium::Ieee802154 | 757 | || self.device.capabilities().medium == Medium::Ieee802154 |
| 746 | { | 758 | { |
| 747 | s.iface.set_hardware_addr(self.device.hardware_address()); | 759 | s.iface |
| 760 | .set_hardware_addr(to_smoltcp_hardware_address(self.device.hardware_address())); | ||
| 748 | } | 761 | } |
| 749 | 762 | ||
| 750 | let timestamp = instant_to_smoltcp(Instant::now()); | 763 | let timestamp = instant_to_smoltcp(Instant::now()); |
