diff options
| author | xoviat <[email protected]> | 2025-11-17 13:18:06 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-17 13:18:06 -0600 |
| commit | 36d533c2de1db2a3b7ef265e22fb4481e046ef17 (patch) | |
| tree | f3e4d697a1b7bca23f71c96351caeab2cabe6ded | |
| parent | ca02cdf792d4aff16e2f265616bec5abdb3c7a1a (diff) | |
wpan: fix src/dst address
| -rw-r--r-- | embassy-stm32-wpan/src/mac/driver.rs | 3 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/mac/indications.rs | 24 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/mac/typedefs.rs | 18 |
3 files changed, 37 insertions, 8 deletions
diff --git a/embassy-stm32-wpan/src/mac/driver.rs b/embassy-stm32-wpan/src/mac/driver.rs index c71fabe09..c43d595b7 100644 --- a/embassy-stm32-wpan/src/mac/driver.rs +++ b/embassy-stm32-wpan/src/mac/driver.rs | |||
| @@ -11,7 +11,7 @@ use embassy_sync::mutex::Mutex; | |||
| 11 | use embassy_sync::waitqueue::AtomicWaker; | 11 | use embassy_sync::waitqueue::AtomicWaker; |
| 12 | 12 | ||
| 13 | use crate::mac::event::MacEvent; | 13 | use crate::mac::event::MacEvent; |
| 14 | use crate::mac::indications::write_frame_from_data_indication; | 14 | use crate::mac::indications::{write_frame_from_beacon_indication, write_frame_from_data_indication}; |
| 15 | use crate::mac::runner::{BUF_SIZE, ZeroCopyPubSub}; | 15 | use crate::mac::runner::{BUF_SIZE, ZeroCopyPubSub}; |
| 16 | use crate::mac::{Control, MTU, Runner}; | 16 | use crate::mac::{Control, MTU, Runner}; |
| 17 | use crate::sub::mac::{Mac, MacRx, MacTx}; | 17 | use crate::sub::mac::{Mac, MacRx, MacTx}; |
| @@ -183,6 +183,7 @@ impl<'d> embassy_net_driver::RxToken for RxToken<'d> { | |||
| 183 | let mut buffer = [0u8; MTU]; | 183 | let mut buffer = [0u8; MTU]; |
| 184 | match self.rx.try_receive().unwrap() { | 184 | match self.rx.try_receive().unwrap() { |
| 185 | MacEvent::McpsDataInd(data_event) => write_frame_from_data_indication(data_event, &mut buffer), | 185 | MacEvent::McpsDataInd(data_event) => write_frame_from_data_indication(data_event, &mut buffer), |
| 186 | MacEvent::MlmeBeaconNotifyInd(data_event) => write_frame_from_beacon_indication(data_event, &mut buffer), | ||
| 186 | _ => {} | 187 | _ => {} |
| 187 | }; | 188 | }; |
| 188 | 189 | ||
diff --git a/embassy-stm32-wpan/src/mac/indications.rs b/embassy-stm32-wpan/src/mac/indications.rs index 05869ba2a..a43777e75 100644 --- a/embassy-stm32-wpan/src/mac/indications.rs +++ b/embassy-stm32-wpan/src/mac/indications.rs | |||
| @@ -3,6 +3,8 @@ use core::slice; | |||
| 3 | use smoltcp::wire::Ieee802154FrameType; | 3 | use smoltcp::wire::Ieee802154FrameType; |
| 4 | use smoltcp::wire::ieee802154::Frame; | 4 | use smoltcp::wire::ieee802154::Frame; |
| 5 | 5 | ||
| 6 | use crate::mac::typedefs::MacAddressAndMode; | ||
| 7 | |||
| 6 | use super::consts::MAX_PENDING_ADDRESS; | 8 | use super::consts::MAX_PENDING_ADDRESS; |
| 7 | use super::event::ParseableMacEvent; | 9 | use super::event::ParseableMacEvent; |
| 8 | use super::typedefs::{ | 10 | use super::typedefs::{ |
| @@ -77,6 +79,22 @@ pub struct BeaconNotifyIndication { | |||
| 77 | 79 | ||
| 78 | impl ParseableMacEvent for BeaconNotifyIndication {} | 80 | impl ParseableMacEvent for BeaconNotifyIndication {} |
| 79 | 81 | ||
| 82 | impl BeaconNotifyIndication { | ||
| 83 | pub fn payload<'a>(&'a self) -> &'a mut [u8] { | ||
| 84 | unsafe { slice::from_raw_parts_mut(self.sdu_ptr as *mut _, self.sdu_length as usize) } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | pub fn write_frame_from_beacon_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>( | ||
| 89 | data: &'a BeaconNotifyIndication, | ||
| 90 | buffer: &'a mut T, | ||
| 91 | ) { | ||
| 92 | let mut frame = Frame::new_unchecked(buffer); | ||
| 93 | |||
| 94 | frame.set_frame_type(Ieee802154FrameType::Beacon); | ||
| 95 | frame.set_sequence_number(data.bsn); | ||
| 96 | } | ||
| 97 | |||
| 80 | /// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status | 98 | /// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status |
| 81 | #[repr(C)] | 99 | #[repr(C)] |
| 82 | #[derive(Debug)] | 100 | #[derive(Debug)] |
| @@ -256,13 +274,13 @@ impl DataIndication { | |||
| 256 | pub fn write_frame_from_data_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>(data: &'a DataIndication, buffer: &'a mut T) { | 274 | pub fn write_frame_from_data_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>(data: &'a DataIndication, buffer: &'a mut T) { |
| 257 | let mut frame = Frame::new_unchecked(buffer); | 275 | let mut frame = Frame::new_unchecked(buffer); |
| 258 | 276 | ||
| 259 | // TODO: complete frame creation | ||
| 260 | frame.set_frame_type(Ieee802154FrameType::Data); | 277 | frame.set_frame_type(Ieee802154FrameType::Data); |
| 261 | frame.set_dst_addr(data.dst_address.into()); | 278 | frame.set_src_addr(MacAddressAndMode(data.src_address, data.src_addr_mode).into()); |
| 262 | frame.set_src_addr(data.src_address.into()); | 279 | frame.set_dst_addr(MacAddressAndMode(data.dst_address, data.dst_addr_mode).into()); |
| 263 | frame.set_dst_pan_id(data.dst_pan_id.into()); | 280 | frame.set_dst_pan_id(data.dst_pan_id.into()); |
| 264 | frame.set_src_pan_id(data.src_pan_id.into()); | 281 | frame.set_src_pan_id(data.src_pan_id.into()); |
| 265 | frame.set_sequence_number(data.dsn); | 282 | frame.set_sequence_number(data.dsn); |
| 283 | frame.set_security_enabled(data.security_level == SecurityLevel::Secured); | ||
| 266 | 284 | ||
| 267 | // No way around the copy with the current API | 285 | // No way around the copy with the current API |
| 268 | frame.payload_mut().unwrap().copy_from_slice(data.payload()); | 286 | frame.payload_mut().unwrap().copy_from_slice(data.payload()); |
diff --git a/embassy-stm32-wpan/src/mac/typedefs.rs b/embassy-stm32-wpan/src/mac/typedefs.rs index 7e3ef4962..175d4a37d 100644 --- a/embassy-stm32-wpan/src/mac/typedefs.rs +++ b/embassy-stm32-wpan/src/mac/typedefs.rs | |||
| @@ -140,9 +140,19 @@ impl From<Address> for MacAddress { | |||
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | impl From<MacAddress> for Address { | 143 | pub struct MacAddressAndMode(pub MacAddress, pub AddressMode); |
| 144 | fn from(_value: MacAddress) -> Self { | 144 | |
| 145 | todo!() | 145 | impl From<MacAddressAndMode> for Address { |
| 146 | fn from(mac_address_and_mode: MacAddressAndMode) -> Self { | ||
| 147 | let address = mac_address_and_mode.0; | ||
| 148 | let mode = mac_address_and_mode.1; | ||
| 149 | |||
| 150 | match mode { | ||
| 151 | AddressMode::Short => Address::Short(unsafe { address.short }), | ||
| 152 | AddressMode::Extended => Address::Extended(unsafe { address.extended }), | ||
| 153 | AddressMode::NoAddress => Address::Absent, | ||
| 154 | AddressMode::Reserved => Address::Absent, | ||
| 155 | } | ||
| 146 | } | 156 | } |
| 147 | } | 157 | } |
| 148 | 158 | ||
| @@ -377,7 +387,7 @@ numeric_enum! { | |||
| 377 | 387 | ||
| 378 | numeric_enum! { | 388 | numeric_enum! { |
| 379 | #[repr(u8)] | 389 | #[repr(u8)] |
| 380 | #[derive(Default, Clone, Copy, Debug)] | 390 | #[derive(Default, Clone, Copy, Debug, PartialEq)] |
| 381 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 391 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 382 | pub enum SecurityLevel { | 392 | pub enum SecurityLevel { |
| 383 | /// MAC Unsecured Mode Security | 393 | /// MAC Unsecured Mode Security |
