aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32-wpan/src/mac/event.rs4
-rw-r--r--embassy-stm32-wpan/src/mac/helpers.rs7
-rw-r--r--embassy-stm32-wpan/src/mac/indications.rs13
-rw-r--r--embassy-stm32-wpan/src/mac/mod.rs1
-rw-r--r--embassy-stm32-wpan/src/mac/responses.rs15
5 files changed, 15 insertions, 25 deletions
diff --git a/embassy-stm32-wpan/src/mac/event.rs b/embassy-stm32-wpan/src/mac/event.rs
index dfce21fea..c2bdc7e11 100644
--- a/embassy-stm32-wpan/src/mac/event.rs
+++ b/embassy-stm32-wpan/src/mac/event.rs
@@ -1,4 +1,3 @@
1use super::helpers::to_u16;
2use super::indications::{ 1use super::indications::{
3 AssociateIndication, BeaconNotifyIndication, CommStatusIndication, DataIndication, DisassociateIndication, 2 AssociateIndication, BeaconNotifyIndication, CommStatusIndication, DataIndication, DisassociateIndication,
4 DpsIndication, GtsIndication, OrphanIndication, PollIndication, SyncLossIndication, 3 DpsIndication, GtsIndication, OrphanIndication, PollIndication, SyncLossIndication,
@@ -58,7 +57,8 @@ impl TryFrom<&[u8]> for MacEvent {
58 type Error = (); 57 type Error = ();
59 58
60 fn try_from(value: &[u8]) -> Result<Self, Self::Error> { 59 fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
61 let opcode = to_u16(&value[0..2]); 60 let opcode = u16::from_le_bytes(value[0..2].try_into().unwrap());
61
62 let opcode = OpcodeM0ToM4::try_from(opcode)?; 62 let opcode = OpcodeM0ToM4::try_from(opcode)?;
63 63
64 let buf = &value[2..]; 64 let buf = &value[2..];
diff --git a/embassy-stm32-wpan/src/mac/helpers.rs b/embassy-stm32-wpan/src/mac/helpers.rs
deleted file mode 100644
index 5a5bf8a85..000000000
--- a/embassy-stm32-wpan/src/mac/helpers.rs
+++ /dev/null
@@ -1,7 +0,0 @@
1pub fn to_u16(buf: &[u8]) -> u16 {
2 ((buf[1] as u16) << 8) | buf[0] as u16
3}
4
5pub fn to_u32(buf: &[u8]) -> u32 {
6 ((buf[0] as u32) << 0) + ((buf[1] as u32) << 8) + ((buf[2] as u32) << 16) + ((buf[3] as u32) << 24)
7}
diff --git a/embassy-stm32-wpan/src/mac/indications.rs b/embassy-stm32-wpan/src/mac/indications.rs
index 6df4aa23a..436b9ac9c 100644
--- a/embassy-stm32-wpan/src/mac/indications.rs
+++ b/embassy-stm32-wpan/src/mac/indications.rs
@@ -1,6 +1,5 @@
1use super::consts::MAX_PENDING_ADDRESS; 1use super::consts::MAX_PENDING_ADDRESS;
2use super::event::ParseableMacEvent; 2use super::event::ParseableMacEvent;
3use super::helpers::to_u32;
4use super::typedefs::{ 3use super::typedefs::{
5 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor, 4 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor,
6 PanId, SecurityLevel, 5 PanId, SecurityLevel,
@@ -114,7 +113,7 @@ impl ParseableMacEvent for BeaconNotifyIndication {
114 ]; 113 ];
115 114
116 Ok(Self { 115 Ok(Self {
117 sdu_ptr: to_u32(&buf[0..4]) as *const u8, 116 sdu_ptr: u32::from_le_bytes(buf[0..4].try_into().unwrap()) as *const u8,
118 pan_descriptor: PanDescriptor::try_from(&buf[4..26])?, 117 pan_descriptor: PanDescriptor::try_from(&buf[4..26])?,
119 addr_list, 118 addr_list,
120 bsn: buf[82], 119 bsn: buf[82],
@@ -405,7 +404,7 @@ impl ParseableMacEvent for DataIndication {
405 }; 404 };
406 405
407 Ok(Self { 406 Ok(Self {
408 msdu_ptr: to_u32(&buf[0..4]) as *const u8, 407 msdu_ptr: u32::from_le_bytes(buf[0..4].try_into().unwrap()) as *const u8,
409 src_addr_mode, 408 src_addr_mode,
410 src_pan_id: PanId([buf[5], buf[6]]), 409 src_pan_id: PanId([buf[5], buf[6]]),
411 src_address, 410 src_address,
@@ -424,10 +423,10 @@ impl ParseableMacEvent for DataIndication {
424 uwn_preamble_symbol_repetitions: buf[45], 423 uwn_preamble_symbol_repetitions: buf[45],
425 datrate: buf[46], 424 datrate: buf[46],
426 ranging_received: buf[47], 425 ranging_received: buf[47],
427 ranging_counter_start: to_u32(&buf[48..52]), 426 ranging_counter_start: u32::from_le_bytes(buf[48..52].try_into().unwrap()),
428 ranging_counter_stop: to_u32(&buf[52..56]), 427 ranging_counter_stop: u32::from_le_bytes(buf[52..56].try_into().unwrap()),
429 ranging_tracking_interval: to_u32(&buf[56..60]), 428 ranging_tracking_interval: u32::from_le_bytes(buf[56..60].try_into().unwrap()),
430 ranging_offset: to_u32(&buf[60..64]), 429 ranging_offset: u32::from_le_bytes(buf[60..64].try_into().unwrap()),
431 ranging_fom: buf[65], 430 ranging_fom: buf[65],
432 rssi: buf[66], 431 rssi: buf[66],
433 }) 432 })
diff --git a/embassy-stm32-wpan/src/mac/mod.rs b/embassy-stm32-wpan/src/mac/mod.rs
index 1af8fe6ba..8d5edad6b 100644
--- a/embassy-stm32-wpan/src/mac/mod.rs
+++ b/embassy-stm32-wpan/src/mac/mod.rs
@@ -1,7 +1,6 @@
1pub mod commands; 1pub mod commands;
2mod consts; 2mod consts;
3pub mod event; 3pub mod event;
4mod helpers;
5pub mod indications; 4pub mod indications;
6mod macros; 5mod macros;
7mod opcodes; 6mod opcodes;
diff --git a/embassy-stm32-wpan/src/mac/responses.rs b/embassy-stm32-wpan/src/mac/responses.rs
index 2f6f5bf58..d29257f84 100644
--- a/embassy-stm32-wpan/src/mac/responses.rs
+++ b/embassy-stm32-wpan/src/mac/responses.rs
@@ -1,6 +1,5 @@
1use super::consts::{MAX_ED_SCAN_RESULTS_SUPPORTED, MAX_PAN_DESC_SUPPORTED, MAX_SOUNDING_LIST_SUPPORTED}; 1use super::consts::{MAX_ED_SCAN_RESULTS_SUPPORTED, MAX_PAN_DESC_SUPPORTED, MAX_SOUNDING_LIST_SUPPORTED};
2use super::event::ParseableMacEvent; 2use super::event::ParseableMacEvent;
3use super::helpers::to_u32;
4use super::typedefs::{ 3use super::typedefs::{
5 AddressMode, AssociationStatus, KeyIdMode, MacAddress, MacStatus, PanDescriptor, PanId, PibId, ScanType, 4 AddressMode, AssociationStatus, KeyIdMode, MacAddress, MacStatus, PanDescriptor, PanId, PibId, ScanType,
6 SecurityLevel, 5 SecurityLevel,
@@ -100,7 +99,7 @@ impl ParseableMacEvent for GetConfirm {
100 fn try_parse(buf: &[u8]) -> Result<Self, ()> { 99 fn try_parse(buf: &[u8]) -> Result<Self, ()> {
101 Self::validate(buf)?; 100 Self::validate(buf)?;
102 101
103 let address = to_u32(&buf[0..4]); 102 let address = u32::from_le_bytes(buf[0..4].try_into().unwrap());
104 103
105 Ok(Self { 104 Ok(Self {
106 pib_attribute_value_ptr: address as *const u8, 105 pib_attribute_value_ptr: address as *const u8,
@@ -357,8 +356,8 @@ impl ParseableMacEvent for CalibrateConfirm {
357 Ok(Self { 356 Ok(Self {
358 status: MacStatus::try_from(buf[0])?, 357 status: MacStatus::try_from(buf[0])?,
359 // 3 byte stuffing 358 // 3 byte stuffing
360 cal_tx_rmaker_offset: to_u32(&buf[4..8]), 359 cal_tx_rmaker_offset: u32::from_le_bytes(buf[4..8].try_into().unwrap()),
361 cal_rx_rmaker_offset: to_u32(&buf[8..12]), 360 cal_rx_rmaker_offset: u32::from_le_bytes(buf[8..12].try_into().unwrap()),
362 }) 361 })
363 } 362 }
364} 363}
@@ -400,10 +399,10 @@ impl ParseableMacEvent for DataConfirm {
400 time_stamp: [buf[1], buf[2], buf[3], buf[4]], 399 time_stamp: [buf[1], buf[2], buf[3], buf[4]],
401 ranging_received: buf[5], 400 ranging_received: buf[5],
402 status: MacStatus::try_from(buf[6])?, 401 status: MacStatus::try_from(buf[6])?,
403 ranging_counter_start: to_u32(&buf[7..11]), 402 ranging_counter_start: u32::from_le_bytes(buf[7..11].try_into().unwrap()),
404 ranging_counter_stop: to_u32(&buf[11..15]), 403 ranging_counter_stop: u32::from_le_bytes(buf[11..15].try_into().unwrap()),
405 ranging_tracking_interval: to_u32(&buf[15..19]), 404 ranging_tracking_interval: u32::from_le_bytes(buf[15..19].try_into().unwrap()),
406 ranging_offset: to_u32(&buf[19..23]), 405 ranging_offset: u32::from_le_bytes(buf[19..23].try_into().unwrap()),
407 ranging_fom: buf[24], 406 ranging_fom: buf[24],
408 }) 407 })
409 } 408 }