aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-11-17 19:25:27 +0000
committerGitHub <[email protected]>2025-11-17 19:25:27 +0000
commitaad02db7c59467374526ffbb484dbacf2a7b6e5e (patch)
tree696de655b1cd1d76eed4c751e85d5505a73c6ff2
parent45797ecb8501d7a22c53967fad45ee7490424991 (diff)
parent50501e0f49e5c2ae939ef0e231d1d3cf319b0a76 (diff)
Merge pull request #4906 from xoviat/wpan
wpan: fix src/dst address
-rw-r--r--embassy-stm32-wpan/src/mac/driver.rs3
-rw-r--r--embassy-stm32-wpan/src/mac/indications.rs23
-rw-r--r--embassy-stm32-wpan/src/mac/typedefs.rs18
3 files changed, 36 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;
11use embassy_sync::waitqueue::AtomicWaker; 11use embassy_sync::waitqueue::AtomicWaker;
12 12
13use crate::mac::event::MacEvent; 13use crate::mac::event::MacEvent;
14use crate::mac::indications::write_frame_from_data_indication; 14use crate::mac::indications::{write_frame_from_beacon_indication, write_frame_from_data_indication};
15use crate::mac::runner::{BUF_SIZE, ZeroCopyPubSub}; 15use crate::mac::runner::{BUF_SIZE, ZeroCopyPubSub};
16use crate::mac::{Control, MTU, Runner}; 16use crate::mac::{Control, MTU, Runner};
17use crate::sub::mac::{Mac, MacRx, MacTx}; 17use 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..5673514c9 100644
--- a/embassy-stm32-wpan/src/mac/indications.rs
+++ b/embassy-stm32-wpan/src/mac/indications.rs
@@ -9,6 +9,7 @@ use super::typedefs::{
9 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor, 9 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor,
10 PanId, SecurityLevel, 10 PanId, SecurityLevel,
11}; 11};
12use crate::mac::typedefs::MacAddressAndMode;
12 13
13/// MLME ASSOCIATE Indication which will be used by the MAC 14/// MLME ASSOCIATE Indication which will be used by the MAC
14/// to indicate the reception of an association request command 15/// to indicate the reception of an association request command
@@ -77,6 +78,22 @@ pub struct BeaconNotifyIndication {
77 78
78impl ParseableMacEvent for BeaconNotifyIndication {} 79impl ParseableMacEvent for BeaconNotifyIndication {}
79 80
81impl BeaconNotifyIndication {
82 pub fn payload<'a>(&'a self) -> &'a mut [u8] {
83 unsafe { slice::from_raw_parts_mut(self.sdu_ptr as *mut _, self.sdu_length as usize) }
84 }
85}
86
87pub fn write_frame_from_beacon_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>(
88 data: &'a BeaconNotifyIndication,
89 buffer: &'a mut T,
90) {
91 let mut frame = Frame::new_unchecked(buffer);
92
93 frame.set_frame_type(Ieee802154FrameType::Beacon);
94 frame.set_sequence_number(data.bsn);
95}
96
80/// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status 97/// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status
81#[repr(C)] 98#[repr(C)]
82#[derive(Debug)] 99#[derive(Debug)]
@@ -256,13 +273,13 @@ impl DataIndication {
256pub fn write_frame_from_data_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>(data: &'a DataIndication, buffer: &'a mut T) { 273pub 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); 274 let mut frame = Frame::new_unchecked(buffer);
258 275
259 // TODO: complete frame creation
260 frame.set_frame_type(Ieee802154FrameType::Data); 276 frame.set_frame_type(Ieee802154FrameType::Data);
261 frame.set_dst_addr(data.dst_address.into()); 277 frame.set_src_addr(MacAddressAndMode(data.src_address, data.src_addr_mode).into());
262 frame.set_src_addr(data.src_address.into()); 278 frame.set_dst_addr(MacAddressAndMode(data.dst_address, data.dst_addr_mode).into());
263 frame.set_dst_pan_id(data.dst_pan_id.into()); 279 frame.set_dst_pan_id(data.dst_pan_id.into());
264 frame.set_src_pan_id(data.src_pan_id.into()); 280 frame.set_src_pan_id(data.src_pan_id.into());
265 frame.set_sequence_number(data.dsn); 281 frame.set_sequence_number(data.dsn);
282 frame.set_security_enabled(data.security_level == SecurityLevel::Secured);
266 283
267 // No way around the copy with the current API 284 // No way around the copy with the current API
268 frame.payload_mut().unwrap().copy_from_slice(data.payload()); 285 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
143impl From<MacAddress> for Address { 143pub struct MacAddressAndMode(pub MacAddress, pub AddressMode);
144 fn from(_value: MacAddress) -> Self { 144
145 todo!() 145impl 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
378numeric_enum! { 388numeric_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