From c52d1d11f92d58eaafada26a11ae9b4402e129a6 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Fri, 28 Jul 2023 15:54:31 +0200 Subject: [PATCH] Expose IEEE802.15.4 address in Driver --- embassy-net-driver-channel/src/lib.rs | 15 +++++++++++++++ embassy-net-driver/src/lib.rs | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/embassy-net-driver-channel/src/lib.rs b/embassy-net-driver-channel/src/lib.rs index 02a4c00d6..e101bf38a 100644 --- a/embassy-net-driver-channel/src/lib.rs +++ b/embassy-net-driver-channel/src/lib.rs @@ -43,6 +43,7 @@ struct Shared { link_state: LinkState, waker: WakerRegistration, ethernet_address: [u8; 6], + ieee802154_address: [u8; 8], } pub struct Runner<'d, const MTU: usize> { @@ -93,6 +94,14 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { }); } + pub fn set_ieee802154_address(&mut self, address: [u8; 8]) { + self.shared.lock(|s| { + let s = &mut *s.borrow_mut(); + s.ieee802154_address = address; + s.waker.wake(); + }); + } + pub async fn rx_buf(&mut self) -> &mut [u8] { let p = self.rx_chan.send().await; &mut p.buf @@ -207,6 +216,7 @@ impl<'d, const MTU: usize> TxRunner<'d, MTU> { pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>( state: &'d mut State, ethernet_address: [u8; 6], + ieee802154_address: [u8; 8], ) -> (Runner<'d, MTU>, Device<'d, MTU>) { let mut caps = Capabilities::default(); caps.max_transmission_unit = MTU; @@ -223,6 +233,7 @@ pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>( shared: Mutex::new(RefCell::new(Shared { link_state: LinkState::Down, ethernet_address, + ieee802154_address, waker: WakerRegistration::new(), })), }); @@ -293,6 +304,10 @@ impl<'d, const MTU: usize> embassy_net_driver::Driver for Device<'d, MTU> { self.shared.lock(|s| s.borrow().ethernet_address) } + fn ieee802154_address(&self) -> [u8; 8] { + self.shared.lock(|s| s.borrow().ieee802154_address) + } + fn link_state(&mut self, cx: &mut Context) -> LinkState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); diff --git a/embassy-net-driver/src/lib.rs b/embassy-net-driver/src/lib.rs index 09def20c4..beb1a1c79 100644 --- a/embassy-net-driver/src/lib.rs +++ b/embassy-net-driver/src/lib.rs @@ -53,6 +53,9 @@ pub trait Driver { /// Get the device's Ethernet address. fn ethernet_address(&self) -> [u8; 6]; + + /// Get the device's IEEE 802.15.4 address. + fn ieee802154_address(&self) -> [u8; 8]; } impl Driver for &mut T { @@ -78,6 +81,9 @@ impl Driver for &mut T { fn ethernet_address(&self) -> [u8; 6] { T::ethernet_address(self) } + fn ieee802154_address(&self) -> [u8; 8] { + T::ieee802154_address(self) + } } /// A token to receive a single network packet.