aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-10-16 23:41:58 +0200
committerDario Nieuwenhuis <[email protected]>2023-10-18 05:28:16 +0200
commit3cbc6874247d7b814cab8ec8762bfe2f6f385828 (patch)
treeaac4c615c816f6465559874a98c9d3cf60c21817
parent51708c8ed1962618ac7bc244a3f5e7ceced28182 (diff)
net/driver: remove Medium, make HardwareAddress non_exhaustive.
-rw-r--r--cyw43/src/control.rs4
-rw-r--r--embassy-net-driver-channel/CHANGELOG.md10
-rw-r--r--embassy-net-driver-channel/README.md18
-rw-r--r--embassy-net-driver-channel/src/lib.rs20
-rw-r--r--embassy-net-driver/CHANGELOG.md10
-rw-r--r--embassy-net-driver/src/lib.rs54
-rw-r--r--embassy-net-enc28j60/src/lib.rs3
-rw-r--r--embassy-net-esp-hosted/src/control.rs4
-rw-r--r--embassy-net/CHANGELOG.md4
-rw-r--r--embassy-net/src/device.rs19
-rw-r--r--embassy-net/src/lib.rs36
-rw-r--r--embassy-stm32-wpan/src/mac/driver.rs11
12 files changed, 76 insertions, 117 deletions
diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs
index 2585b31dc..d2709304c 100644
--- a/cyw43/src/control.rs
+++ b/cyw43/src/control.rs
@@ -1,7 +1,7 @@
1use core::cmp::{max, min}; 1use core::cmp::{max, min};
2 2
3use ch::driver::LinkState;
4use embassy_net_driver_channel as ch; 3use embassy_net_driver_channel as ch;
4use embassy_net_driver_channel::driver::{HardwareAddress, LinkState};
5use embassy_time::Timer; 5use embassy_time::Timer;
6 6
7pub use crate::bus::SpiBusCyw43; 7pub use crate::bus::SpiBusCyw43;
@@ -133,7 +133,7 @@ impl<'a> Control<'a> {
133 133
134 Timer::after_millis(100).await; 134 Timer::after_millis(100).await;
135 135
136 self.state_ch.set_ethernet_address(mac_addr); 136 self.state_ch.set_hardware_address(HardwareAddress::Ethernet(mac_addr));
137 137
138 debug!("INIT DONE"); 138 debug!("INIT DONE");
139 } 139 }
diff --git a/embassy-net-driver-channel/CHANGELOG.md b/embassy-net-driver-channel/CHANGELOG.md
index 589996cfd..b04d0a86b 100644
--- a/embassy-net-driver-channel/CHANGELOG.md
+++ b/embassy-net-driver-channel/CHANGELOG.md
@@ -5,14 +5,12 @@ All notable changes to this project will be documented in this file.
5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 7
8## 0.2.0 - 2023-10-15 8## 0.2.0 - 2023-10-18
9 9
10- Update embassy-net-driver 10- Update `embassy-net-driver` to v0.2
11- `Runner::new` now takes an `embassy_net_driver::HardwareAddress` parameter 11- `Runner::new` now takes an `embassy_net_driver::HardwareAddress` parameter.
12- Added `Runner::set_ieee802154_address`, `Runner::ieee802154_address` 12- `Runner::set_ethernet_address` is now `set_hardware_address`.
13 13
14## 0.1.0 - 2023-06-29 14## 0.1.0 - 2023-06-29
15 15
16- First release 16- First release
17
18
diff --git a/embassy-net-driver-channel/README.md b/embassy-net-driver-channel/README.md
index 8f904ce95..90a216388 100644
--- a/embassy-net-driver-channel/README.md
+++ b/embassy-net-driver-channel/README.md
@@ -7,7 +7,9 @@ The `embassy-net-driver` trait is polling-based. To implement it, you must write
7hand, and hook up the `Waker`s provided by `embassy-net` to the right interrupt handlers so that `embassy-net` 7hand, and hook up the `Waker`s provided by `embassy-net` to the right interrupt handlers so that `embassy-net`
8knows when to poll your driver again to make more progress. 8knows when to poll your driver again to make more progress.
9 9
10With `embassy-net-driver-channel` 10With `embassy-net-driver-channel` you get a "channel-like" interface instead, where you can send/receive packets
11to/from embassy-net. The intended usage is to spawn a "driver task" in the background that does this, passing
12packets between the hardware and the channel.
11 13
12## A note about deadlocks 14## A note about deadlocks
13 15
@@ -18,19 +20,19 @@ loop {
18 // Wait for either.. 20 // Wait for either..
19 match select( 21 match select(
20 // ... the chip signaling an interrupt, indicating a packet is available to receive, or 22 // ... the chip signaling an interrupt, indicating a packet is available to receive, or
21 irq_pin.wait_for_low(), 23 irq_pin.wait_for_low(),
22 // ... a TX buffer becoming available, i.e. embassy-net wants to send a packet 24 // ... a TX buffer becoming available, i.e. embassy-net wants to send a packet
23 tx_chan.tx_buf(), 25 tx_chan.tx_buf(),
24 ).await { 26 ).await {
25 Either::First(_) => { 27 Either::First(_) => {
26 // a packet is ready to be received! 28 // a packet is ready to be received!
27 let buf = rx_chan.rx_buf().await; // allocate a rx buf from the packet queue 29 let buf = rx_chan.rx_buf().await; // allocate a rx buf from the packet queue
28 let n = receive_packet_over_spi(buf).await; 30 let n = receive_packet_over_spi(buf).await;
29 rx_chan.rx_done(n); 31 rx_chan.rx_done(n);
30 } 32 }
31 Either::Second(buf) => { 33 Either::Second(buf) => {
32 // a packet is ready to be sent! 34 // a packet is ready to be sent!
33 send_packet_over_spi(buf).await; 35 send_packet_over_spi(buf).await;
34 tx_chan.tx_done(); 36 tx_chan.tx_done();
35 } 37 }
36 } 38 }
@@ -41,7 +43,7 @@ However, this code has a latent deadlock bug. The symptom is it can hang at `rx_
41 43
42The reason is that, under load, both the TX and RX queues can get full at the same time. When this happens, the `embassy-net` task stalls trying to send because the TX queue is full, therefore it stops processing packets in the RX queue. Your driver task also stalls because the RX queue is full, therefore it stops processing packets in the TX queue. 44The reason is that, under load, both the TX and RX queues can get full at the same time. When this happens, the `embassy-net` task stalls trying to send because the TX queue is full, therefore it stops processing packets in the RX queue. Your driver task also stalls because the RX queue is full, therefore it stops processing packets in the TX queue.
43 45
44The fix is to make sure to always service the TX queue while you're waiting for space to become available in the TX queue. For example, select on either "tx_chan.tx_buf() available" or "INT is low AND rx_chan.rx_buf() available": 46The fix is to make sure to always service the TX queue while you're waiting for space to become available in the RX queue. For example, select on either "tx_chan.tx_buf() available" or "INT is low AND rx_chan.rx_buf() available":
45 47
46```rust,ignore 48```rust,ignore
47loop { 49loop {
@@ -58,12 +60,12 @@ loop {
58 ).await { 60 ).await {
59 Either::First(buf) => { 61 Either::First(buf) => {
60 // a packet is ready to be received! 62 // a packet is ready to be received!
61 let n = receive_packet_over_spi(buf).await; 63 let n = receive_packet_over_spi(buf).await;
62 rx_chan.rx_done(n); 64 rx_chan.rx_done(n);
63 } 65 }
64 Either::Second(buf) => { 66 Either::Second(buf) => {
65 // a packet is ready to be sent! 67 // a packet is ready to be sent!
66 send_packet_over_spi(buf).await; 68 send_packet_over_spi(buf).await;
67 tx_chan.tx_done(); 69 tx_chan.tx_done();
68 } 70 }
69 } 71 }
@@ -79,12 +81,10 @@ These `embassy-net` drivers are implemented using this crate. You can look at th
79- [`embassy-net-wiznet`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-wiznet) for Wiznet SPI Ethernet MAC+PHY chips. 81- [`embassy-net-wiznet`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-wiznet) for Wiznet SPI Ethernet MAC+PHY chips.
80- [`embassy-net-esp-hosted`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-esp-hosted) for using ESP32 chips with the [`esp-hosted`](https://github.com/espressif/esp-hosted) firmware as WiFi adapters for another non-ESP32 MCU. 82- [`embassy-net-esp-hosted`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-esp-hosted) for using ESP32 chips with the [`esp-hosted`](https://github.com/espressif/esp-hosted) firmware as WiFi adapters for another non-ESP32 MCU.
81 83
82
83## Interoperability 84## Interoperability
84 85
85This crate can run on any executor. 86This crate can run on any executor.
86 87
87
88## License 88## License
89 89
90This work is licensed under either of 90This work is licensed under either of
diff --git a/embassy-net-driver-channel/src/lib.rs b/embassy-net-driver-channel/src/lib.rs
index bf7ae5217..bfb2c9c03 100644
--- a/embassy-net-driver-channel/src/lib.rs
+++ b/embassy-net-driver-channel/src/lib.rs
@@ -8,9 +8,8 @@ use core::cell::RefCell;
8use core::mem::MaybeUninit; 8use core::mem::MaybeUninit;
9use core::task::{Context, Poll}; 9use core::task::{Context, Poll};
10 10
11use driver::HardwareAddress;
12pub use embassy_net_driver as driver; 11pub use embassy_net_driver as driver;
13use embassy_net_driver::{Capabilities, LinkState, Medium}; 12use embassy_net_driver::{Capabilities, LinkState};
14use embassy_sync::blocking_mutex::raw::NoopRawMutex; 13use embassy_sync::blocking_mutex::raw::NoopRawMutex;
15use embassy_sync::blocking_mutex::Mutex; 14use embassy_sync::blocking_mutex::Mutex;
16use embassy_sync::waitqueue::WakerRegistration; 15use embassy_sync::waitqueue::WakerRegistration;
@@ -161,18 +160,10 @@ impl<'d> StateRunner<'d> {
161 }); 160 });
162 } 161 }
163 162
164 pub fn set_ethernet_address(&self, address: [u8; 6]) { 163 pub fn set_hardware_address(&self, address: driver::HardwareAddress) {
165 self.shared.lock(|s| { 164 self.shared.lock(|s| {
166 let s = &mut *s.borrow_mut(); 165 let s = &mut *s.borrow_mut();
167 s.hardware_address = driver::HardwareAddress::Ethernet(address); 166 s.hardware_address = address;
168 s.waker.wake();
169 });
170 }
171
172 pub fn set_ieee802154_address(&self, address: [u8; 8]) {
173 self.shared.lock(|s| {
174 let s = &mut *s.borrow_mut();
175 s.hardware_address = driver::HardwareAddress::Ieee802154(address);
176 s.waker.wake(); 167 s.waker.wake();
177 }); 168 });
178 } 169 }
@@ -232,11 +223,6 @@ pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>(
232) -> (Runner<'d, MTU>, Device<'d, MTU>) { 223) -> (Runner<'d, MTU>, Device<'d, MTU>) {
233 let mut caps = Capabilities::default(); 224 let mut caps = Capabilities::default();
234 caps.max_transmission_unit = MTU; 225 caps.max_transmission_unit = MTU;
235 caps.medium = match &hardware_address {
236 HardwareAddress::Ethernet(_) => Medium::Ethernet,
237 HardwareAddress::Ieee802154(_) => Medium::Ieee802154,
238 HardwareAddress::Ip => Medium::Ip,
239 };
240 226
241 // safety: this is a self-referential struct, however: 227 // safety: this is a self-referential struct, however:
242 // - it can't move while the `'d` borrow is active. 228 // - it can't move while the `'d` borrow is active.
diff --git a/embassy-net-driver/CHANGELOG.md b/embassy-net-driver/CHANGELOG.md
index 7be622820..165461eff 100644
--- a/embassy-net-driver/CHANGELOG.md
+++ b/embassy-net-driver/CHANGELOG.md
@@ -5,13 +5,13 @@ All notable changes to this project will be documented in this file.
5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 7
8## 0.2.0 - 2023-10-15 8## 0.2.0 - 2023-10-18
9 9
10- Added `Driver::ieee802154_address` 10- Added support for IEEE 802.15.4 mediums.
11- Added `Medium::Ieee802154` 11- Added `Driver::hardware_address()`, `HardwareAddress`.
12- Removed `Medium` enum. The medium is deduced out of the hardware address.
13- Removed `Driver::ethernet_address()`. Replacement is `hardware_address()`.
12 14
13## 0.1.0 - 2023-06-29 15## 0.1.0 - 2023-06-29
14 16
15- First release 17- First release
16
17
diff --git a/embassy-net-driver/src/lib.rs b/embassy-net-driver/src/lib.rs
index b64c10000..87f9f6ed1 100644
--- a/embassy-net-driver/src/lib.rs
+++ b/embassy-net-driver/src/lib.rs
@@ -7,12 +7,23 @@ use core::task::Context;
7/// Representation of an hardware address, such as an Ethernet address or an IEEE802.15.4 address. 7/// Representation of an hardware address, such as an Ethernet address or an IEEE802.15.4 address.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)] 8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))] 9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10#[non_exhaustive]
10pub enum HardwareAddress { 11pub enum HardwareAddress {
11 /// A six-octet Ethernet address 12 /// Ethernet medium, with a A six-octet Ethernet address.
13 ///
14 /// Devices of this type send and receive Ethernet frames,
15 /// and interfaces using it must do neighbor discovery via ARP or NDISC.
16 ///
17 /// Examples of devices of this type are Ethernet, WiFi (802.11), Linux `tap`, and VPNs in tap (layer 2) mode.
12 Ethernet([u8; 6]), 18 Ethernet([u8; 6]),
13 /// An eight-octet IEEE802.15.4 address 19 /// 6LoWPAN over IEEE802.15.4, with an eight-octet address.
14 Ieee802154([u8; 8]), 20 Ieee802154([u8; 8]),
15 /// Indicates that a Driver is IP-native, and has no hardware address 21 /// Indicates that a Driver is IP-native, and has no hardware address.
22 ///
23 /// Devices of this type send and receive IP frames, without an
24 /// Ethernet header. MAC addresses are not used, and no neighbor discovery (ARP, NDISC) is done.
25 ///
26 /// Examples of devices of this type are the Linux `tun`, PPP interfaces, VPNs in tun (layer 3) mode.
16 Ip, 27 Ip,
17} 28}
18 29
@@ -64,6 +75,10 @@ pub trait Driver {
64 fn capabilities(&self) -> Capabilities; 75 fn capabilities(&self) -> Capabilities;
65 76
66 /// Get the device's hardware address. 77 /// Get the device's hardware address.
78 ///
79 /// The returned hardware address also determines the "medium" of this driver. This indicates
80 /// what kind of packet the sent/received bytes are, and determines some behaviors of
81 /// the interface. For example, ARP/NDISC address resolution is only done for Ethernet mediums.
67 fn hardware_address(&self) -> HardwareAddress; 82 fn hardware_address(&self) -> HardwareAddress;
68} 83}
69 84
@@ -124,13 +139,6 @@ pub trait TxToken {
124#[cfg_attr(feature = "defmt", derive(defmt::Format))] 139#[cfg_attr(feature = "defmt", derive(defmt::Format))]
125#[non_exhaustive] 140#[non_exhaustive]
126pub struct Capabilities { 141pub struct Capabilities {
127 /// Medium of the device.
128 ///
129 /// This indicates what kind of packet the sent/received bytes are, and determines
130 /// some behaviors of Interface. For example, ARP/NDISC address resolution is only done
131 /// for Ethernet mediums.
132 pub medium: Medium,
133
134 /// Maximum transmission unit. 142 /// Maximum transmission unit.
135 /// 143 ///
136 /// The network device is unable to send or receive frames larger than the value returned 144 /// The network device is unable to send or receive frames larger than the value returned
@@ -161,32 +169,6 @@ pub struct Capabilities {
161 pub checksum: ChecksumCapabilities, 169 pub checksum: ChecksumCapabilities,
162} 170}
163 171
164/// Type of medium of a device.
165#[derive(Debug, Eq, PartialEq, Copy, Clone)]
166#[cfg_attr(feature = "defmt", derive(defmt::Format))]
167pub enum Medium {
168 /// Ethernet medium. Devices of this type send and receive Ethernet frames,
169 /// and interfaces using it must do neighbor discovery via ARP or NDISC.
170 ///
171 /// Examples of devices of this type are Ethernet, WiFi (802.11), Linux `tap`, and VPNs in tap (layer 2) mode.
172 Ethernet,
173
174 /// IP medium. Devices of this type send and receive IP frames, without an
175 /// Ethernet header. MAC addresses are not used, and no neighbor discovery (ARP, NDISC) is done.
176 ///
177 /// Examples of devices of this type are the Linux `tun`, PPP interfaces, VPNs in tun (layer 3) mode.
178 Ip,
179
180 /// IEEE 802_15_4 medium
181 Ieee802154,
182}
183
184impl Default for Medium {
185 fn default() -> Medium {
186 Medium::Ethernet
187 }
188}
189
190/// A description of checksum behavior for every supported protocol. 172/// A description of checksum behavior for every supported protocol.
191#[derive(Debug, Clone, Default)] 173#[derive(Debug, Clone, Default)]
192#[cfg_attr(feature = "defmt", derive(defmt::Format))] 174#[cfg_attr(feature = "defmt", derive(defmt::Format))]
diff --git a/embassy-net-enc28j60/src/lib.rs b/embassy-net-enc28j60/src/lib.rs
index f96a6ff14..f18134927 100644
--- a/embassy-net-enc28j60/src/lib.rs
+++ b/embassy-net-enc28j60/src/lib.rs
@@ -19,7 +19,7 @@ mod traits;
19use core::cmp; 19use core::cmp;
20use core::convert::TryInto; 20use core::convert::TryInto;
21 21
22use embassy_net_driver::{Capabilities, HardwareAddress, LinkState, Medium}; 22use embassy_net_driver::{Capabilities, HardwareAddress, LinkState};
23use embassy_time::Duration; 23use embassy_time::Duration;
24use embedded_hal::digital::OutputPin; 24use embedded_hal::digital::OutputPin;
25use embedded_hal::spi::{Operation, SpiDevice}; 25use embedded_hal::spi::{Operation, SpiDevice};
@@ -671,7 +671,6 @@ where
671 fn capabilities(&self) -> Capabilities { 671 fn capabilities(&self) -> Capabilities {
672 let mut caps = Capabilities::default(); 672 let mut caps = Capabilities::default();
673 caps.max_transmission_unit = MTU; 673 caps.max_transmission_unit = MTU;
674 caps.medium = Medium::Ethernet;
675 caps 674 caps
676 } 675 }
677 676
diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs
index a4996b584..50030f431 100644
--- a/embassy-net-esp-hosted/src/control.rs
+++ b/embassy-net-esp-hosted/src/control.rs
@@ -1,5 +1,5 @@
1use ch::driver::LinkState;
2use embassy_net_driver_channel as ch; 1use embassy_net_driver_channel as ch;
2use embassy_net_driver_channel::driver::{HardwareAddress, LinkState};
3use heapless::String; 3use heapless::String;
4 4
5use crate::ioctl::Shared; 5use crate::ioctl::Shared;
@@ -77,7 +77,7 @@ impl<'a> Control<'a> {
77 77
78 let mac_addr = self.get_mac_addr().await?; 78 let mac_addr = self.get_mac_addr().await?;
79 debug!("mac addr: {:02x}", mac_addr); 79 debug!("mac addr: {:02x}", mac_addr);
80 self.state_ch.set_ethernet_address(mac_addr); 80 self.state_ch.set_hardware_address(HardwareAddress::Ethernet(mac_addr));
81 81
82 Ok(()) 82 Ok(())
83 } 83 }
diff --git a/embassy-net/CHANGELOG.md b/embassy-net/CHANGELOG.md
index 3e7c28772..7b91b844b 100644
--- a/embassy-net/CHANGELOG.md
+++ b/embassy-net/CHANGELOG.md
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 7
8## 0.2.0 - 2023-10-15 8## 0.2.0 - 2023-10-18
9 9
10- Re-export `smoltcp::wire::IpEndpoint` 10- Re-export `smoltcp::wire::IpEndpoint`
11- Add poll functions on UdpSocket 11- Add poll functions on UdpSocket
@@ -27,5 +27,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27## 0.1.0 - 2023-06-29 27## 0.1.0 - 2023-06-29
28 28
29- First release 29- First release
30
31
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs
index 8c2b7d31a..54a0c47e8 100644
--- a/embassy-net/src/device.rs
+++ b/embassy-net/src/device.rs
@@ -1,7 +1,7 @@
1use core::task::Context; 1use core::task::Context;
2 2
3use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken}; 3use embassy_net_driver::{Capabilities, Checksum, Driver, RxToken, TxToken};
4use smoltcp::phy; 4use smoltcp::phy::{self, Medium};
5use smoltcp::time::Instant; 5use smoltcp::time::Instant;
6 6
7pub(crate) struct DriverAdapter<'d, 'c, T> 7pub(crate) struct DriverAdapter<'d, 'c, T>
@@ -11,6 +11,7 @@ where
11 // must be Some when actually using this to rx/tx 11 // must be Some when actually using this to rx/tx
12 pub cx: Option<&'d mut Context<'c>>, 12 pub cx: Option<&'d mut Context<'c>>,
13 pub inner: &'d mut T, 13 pub inner: &'d mut T,
14 pub medium: Medium,
14} 15}
15 16
16impl<'d, 'c, T> phy::Device for DriverAdapter<'d, 'c, T> 17impl<'d, 'c, T> phy::Device for DriverAdapter<'d, 'c, T>
@@ -46,19 +47,7 @@ where
46 47
47 smolcaps.max_transmission_unit = caps.max_transmission_unit; 48 smolcaps.max_transmission_unit = caps.max_transmission_unit;
48 smolcaps.max_burst_size = caps.max_burst_size; 49 smolcaps.max_burst_size = caps.max_burst_size;
49 smolcaps.medium = match caps.medium { 50 smolcaps.medium = self.medium;
50 #[cfg(feature = "medium-ethernet")]
51 Medium::Ethernet => phy::Medium::Ethernet,
52 #[cfg(feature = "medium-ip")]
53 Medium::Ip => phy::Medium::Ip,
54 #[cfg(feature = "medium-ieee802154")]
55 Medium::Ieee802154 => phy::Medium::Ieee802154,
56 #[allow(unreachable_patterns)]
57 _ => panic!(
58 "Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.",
59 caps.medium
60 ),
61 };
62 smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4); 51 smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4);
63 smolcaps.checksum.tcp = convert(caps.checksum.tcp); 52 smolcaps.checksum.tcp = convert(caps.checksum.tcp);
64 smolcaps.checksum.udp = convert(caps.checksum.udp); 53 smolcaps.checksum.udp = convert(caps.checksum.udp);
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index a0ad33c6b..c41faee2f 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -33,6 +33,7 @@ use heapless::Vec;
33pub use smoltcp::iface::MulticastError; 33pub use smoltcp::iface::MulticastError;
34#[allow(unused_imports)] 34#[allow(unused_imports)]
35use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage}; 35use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage};
36use smoltcp::phy::Medium;
36#[cfg(feature = "dhcpv4")] 37#[cfg(feature = "dhcpv4")]
37use smoltcp::socket::dhcpv4::{self, RetryConfig}; 38use smoltcp::socket::dhcpv4::{self, RetryConfig};
38#[cfg(feature = "medium-ethernet")] 39#[cfg(feature = "medium-ethernet")]
@@ -264,14 +265,17 @@ pub(crate) struct SocketStack {
264 next_local_port: u16, 265 next_local_port: u16,
265} 266}
266 267
267fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> HardwareAddress { 268fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> (HardwareAddress, Medium) {
268 match addr { 269 match addr {
269 #[cfg(feature = "medium-ethernet")] 270 #[cfg(feature = "medium-ethernet")]
270 driver::HardwareAddress::Ethernet(eth) => HardwareAddress::Ethernet(EthernetAddress(eth)), 271 driver::HardwareAddress::Ethernet(eth) => (HardwareAddress::Ethernet(EthernetAddress(eth)), Medium::Ethernet),
271 #[cfg(feature = "medium-ieee802154")] 272 #[cfg(feature = "medium-ieee802154")]
272 driver::HardwareAddress::Ieee802154(ieee) => HardwareAddress::Ieee802154(Ieee802154Address::Extended(ieee)), 273 driver::HardwareAddress::Ieee802154(ieee) => (
274 HardwareAddress::Ieee802154(Ieee802154Address::Extended(ieee)),
275 Medium::Ieee802154,
276 ),
273 #[cfg(feature = "medium-ip")] 277 #[cfg(feature = "medium-ip")]
274 driver::HardwareAddress::Ip => HardwareAddress::Ip, 278 driver::HardwareAddress::Ip => (HardwareAddress::Ip, Medium::Ip),
275 279
276 #[allow(unreachable_patterns)] 280 #[allow(unreachable_patterns)]
277 _ => panic!( 281 _ => panic!(
@@ -289,7 +293,8 @@ impl<D: Driver> Stack<D> {
289 resources: &'static mut StackResources<SOCK>, 293 resources: &'static mut StackResources<SOCK>,
290 random_seed: u64, 294 random_seed: u64,
291 ) -> Self { 295 ) -> Self {
292 let mut iface_cfg = smoltcp::iface::Config::new(to_smoltcp_hardware_address(device.hardware_address())); 296 let (hardware_addr, medium) = to_smoltcp_hardware_address(device.hardware_address());
297 let mut iface_cfg = smoltcp::iface::Config::new(hardware_addr);
293 iface_cfg.random_seed = random_seed; 298 iface_cfg.random_seed = random_seed;
294 299
295 let iface = Interface::new( 300 let iface = Interface::new(
@@ -297,6 +302,7 @@ impl<D: Driver> Stack<D> {
297 &mut DriverAdapter { 302 &mut DriverAdapter {
298 inner: &mut device, 303 inner: &mut device,
299 cx: None, 304 cx: None,
305 medium,
300 }, 306 },
301 instant_to_smoltcp(Instant::now()), 307 instant_to_smoltcp(Instant::now()),
302 ); 308 );
@@ -356,7 +362,7 @@ impl<D: Driver> Stack<D> {
356 362
357 /// Get the hardware address of the network interface. 363 /// Get the hardware address of the network interface.
358 pub fn hardware_address(&self) -> HardwareAddress { 364 pub fn hardware_address(&self) -> HardwareAddress {
359 self.with(|_s, i| to_smoltcp_hardware_address(i.device.hardware_address())) 365 self.with(|_s, i| to_smoltcp_hardware_address(i.device.hardware_address()).0)
360 } 366 }
361 367
362 /// Get whether the link is up. 368 /// Get whether the link is up.
@@ -812,18 +818,28 @@ impl<D: Driver> Inner<D> {
812 fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) { 818 fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
813 s.waker.register(cx.waker()); 819 s.waker.register(cx.waker());
814 820
821 let (_hardware_addr, medium) = to_smoltcp_hardware_address(self.device.hardware_address());
822
815 #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))] 823 #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
816 if self.device.capabilities().medium == embassy_net_driver::Medium::Ethernet
817 || self.device.capabilities().medium == embassy_net_driver::Medium::Ieee802154
818 { 824 {
819 s.iface 825 let do_set = match medium {
820 .set_hardware_addr(to_smoltcp_hardware_address(self.device.hardware_address())); 826 #[cfg(feature = "medium-ethernet")]
827 Medium::Ethernet => true,
828 #[cfg(feature = "medium-ieee802154")]
829 Medium::Ieee802154 => true,
830 #[allow(unreachable_patterns)]
831 _ => false,
832 };
833 if do_set {
834 s.iface.set_hardware_addr(_hardware_addr);
835 }
821 } 836 }
822 837
823 let timestamp = instant_to_smoltcp(Instant::now()); 838 let timestamp = instant_to_smoltcp(Instant::now());
824 let mut smoldev = DriverAdapter { 839 let mut smoldev = DriverAdapter {
825 cx: Some(cx), 840 cx: Some(cx),
826 inner: &mut self.device, 841 inner: &mut self.device,
842 medium,
827 }; 843 };
828 s.iface.poll(timestamp, &mut smoldev, &mut s.sockets); 844 s.iface.poll(timestamp, &mut smoldev, &mut s.sockets);
829 845
diff --git a/embassy-stm32-wpan/src/mac/driver.rs b/embassy-stm32-wpan/src/mac/driver.rs
index bfc4f1ee8..ffba6e5e8 100644
--- a/embassy-stm32-wpan/src/mac/driver.rs
+++ b/embassy-stm32-wpan/src/mac/driver.rs
@@ -3,7 +3,7 @@
3 3
4use core::task::Context; 4use core::task::Context;
5 5
6use embassy_net_driver::{Capabilities, HardwareAddress, LinkState, Medium}; 6use embassy_net_driver::{Capabilities, HardwareAddress, LinkState};
7use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 7use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
8use embassy_sync::channel::Channel; 8use embassy_sync::channel::Channel;
9 9
@@ -60,24 +60,15 @@ impl<'d> embassy_net_driver::Driver for Driver<'d> {
60 let mut caps = Capabilities::default(); 60 let mut caps = Capabilities::default();
61 caps.max_transmission_unit = MTU; 61 caps.max_transmission_unit = MTU;
62 // caps.max_burst_size = Some(self.tx.len()); 62 // caps.max_burst_size = Some(self.tx.len());
63
64 caps.medium = Medium::Ieee802154;
65 caps 63 caps
66 } 64 }
67 65
68 fn link_state(&mut self, _cx: &mut Context) -> LinkState { 66 fn link_state(&mut self, _cx: &mut Context) -> LinkState {
69 // if self.phy.poll_link(&mut self.station_management, cx) {
70 // LinkState::Up
71 // } else {
72 // LinkState::Down
73 // }
74
75 LinkState::Down 67 LinkState::Down
76 } 68 }
77 69
78 fn hardware_address(&self) -> HardwareAddress { 70 fn hardware_address(&self) -> HardwareAddress {
79 // self.mac_addr 71 // self.mac_addr
80
81 HardwareAddress::Ieee802154([0; 8]) 72 HardwareAddress::Ieee802154([0; 8])
82 } 73 }
83} 74}