aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoueslati <[email protected]>2023-07-13 15:20:50 +0100
committergoueslati <[email protected]>2023-07-13 15:20:50 +0100
commit3f0c8bafb060fdf81a677f0ec37d4db11e732266 (patch)
treed8d17b9b141cbb2dc17fc8e14920d28fb42bc0ad
parenteccd2ecebf01753e70705a6ca1e21bc83b2c204c (diff)
make it work, disgustingly
-rw-r--r--embassy-stm32-wpan/src/sub/mac/commands.rs42
-rw-r--r--embassy-stm32-wpan/src/sub/mac/consts.rs2
-rw-r--r--embassy-stm32-wpan/src/sub/mac/indications.rs27
-rw-r--r--embassy-stm32-wpan/src/sub/mac/opcodes.rs2
-rw-r--r--embassy-stm32-wpan/src/sub/mac/responses.rs7
-rw-r--r--embassy-stm32-wpan/src/sub/mac/typedefs.rs26
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs30
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs38
8 files changed, 133 insertions, 41 deletions
diff --git a/embassy-stm32-wpan/src/sub/mac/commands.rs b/embassy-stm32-wpan/src/sub/mac/commands.rs
index 7ccf10026..8cfa0a054 100644
--- a/embassy-stm32-wpan/src/sub/mac/commands.rs
+++ b/embassy-stm32-wpan/src/sub/mac/commands.rs
@@ -1,7 +1,7 @@
1use super::opcodes::OpcodeM4ToM0; 1use super::opcodes::OpcodeM4ToM0;
2use super::typedefs::{ 2use super::typedefs::{
3 AddressMode, Capabilities, DisassociationReason, GtsCharacteristics, KeyIdMode, MacAddress, MacChannel, PibId, 3 AddressMode, Capabilities, DisassociationReason, GtsCharacteristics, KeyIdMode, MacAddress, MacChannel, MacStatus,
4 ScanType, SecurityLevel, 4 PanId, PibId, ScanType, SecurityLevel,
5}; 5};
6 6
7pub trait MacCommand { 7pub trait MacCommand {
@@ -26,7 +26,7 @@ pub struct AssociateRequest {
26 /// operational capabilities of the associating device 26 /// operational capabilities of the associating device
27 pub capability_information: Capabilities, 27 pub capability_information: Capabilities,
28 /// the identifier of the PAN with which to associate 28 /// the identifier of the PAN with which to associate
29 pub coord_pan_id: [u8; 2], 29 pub coord_pan_id: PanId,
30 /// the security level to be used 30 /// the security level to be used
31 pub security_level: SecurityLevel, 31 pub security_level: SecurityLevel,
32 /// the mode used to identify the key to be used 32 /// the mode used to identify the key to be used
@@ -51,7 +51,7 @@ pub struct DisassociateRequest {
51 /// device addressing mode used 51 /// device addressing mode used
52 pub device_addr_mode: AddressMode, 52 pub device_addr_mode: AddressMode,
53 /// the identifier of the PAN of the device 53 /// the identifier of the PAN of the device
54 pub device_pan_id: [u8; 2], 54 pub device_pan_id: PanId,
55 /// the reason for the disassociation 55 /// the reason for the disassociation
56 pub disassociation_reason: DisassociationReason, 56 pub disassociation_reason: DisassociationReason,
57 /// device address 57 /// device address
@@ -201,7 +201,7 @@ impl MacCommand for SetRequest {
201#[cfg_attr(feature = "defmt", derive(defmt::Format))] 201#[cfg_attr(feature = "defmt", derive(defmt::Format))]
202pub struct StartRequest { 202pub struct StartRequest {
203 /// PAN indentifier to used by the device 203 /// PAN indentifier to used by the device
204 pub pan_id: [u8; 2], 204 pub pan_id: PanId,
205 /// logical channel on which to begin 205 /// logical channel on which to begin
206 pub channel_number: MacChannel, 206 pub channel_number: MacChannel,
207 /// channel page on which to begin 207 /// channel page on which to begin
@@ -277,7 +277,7 @@ pub struct PollRequest {
277 /// originator of the key to be used 277 /// originator of the key to be used
278 pub key_source: [u8; 8], 278 pub key_source: [u8; 8],
279 /// PAN identifier of the coordinator 279 /// PAN identifier of the coordinator
280 pub coord_pan_id: [u8; 2], 280 pub coord_pan_id: PanId,
281} 281}
282 282
283impl MacCommand for PollRequest { 283impl MacCommand for PollRequest {
@@ -337,7 +337,7 @@ pub struct DataRequest {
337 /// destination addressing mode used 337 /// destination addressing mode used
338 pub dst_addr_mode: AddressMode, 338 pub dst_addr_mode: AddressMode,
339 /// destination PAN Id 339 /// destination PAN Id
340 pub dst_pan_id: [u8; 2], 340 pub dst_pan_id: PanId,
341 /// destination address 341 /// destination address
342 pub dst_address: MacAddress, 342 pub dst_address: MacAddress,
343 /// the number of octets contained in the MSDU 343 /// the number of octets contained in the MSDU
@@ -370,6 +370,31 @@ pub struct DataRequest {
370 pub datrate: u8, 370 pub datrate: u8,
371} 371}
372 372
373impl Default for DataRequest {
374 fn default() -> Self {
375 Self {
376 msdu_ptr: 0 as *const u8,
377 src_addr_mode: AddressMode::NoAddress,
378 dst_addr_mode: AddressMode::NoAddress,
379 dst_pan_id: PanId([0, 0]),
380 dst_address: MacAddress { short: [0, 0] },
381 msdu_length: 0,
382 msdu_handle: 0,
383 ack_tx: 0,
384 gts_tx: false,
385 indirect_tx: 0,
386 security_level: SecurityLevel::Unsecure,
387 key_id_mode: KeyIdMode::Implicite,
388 key_index: 0,
389 key_source: [0u8; 8],
390 uwbprf: 0,
391 ranging: 0,
392 uwb_preamble_symbol_repetitions: 0,
393 datrate: 0,
394 }
395 }
396}
397
373impl MacCommand for DataRequest { 398impl MacCommand for DataRequest {
374 const OPCODE: OpcodeM4ToM0 = OpcodeM4ToM0::McpsDataReq; 399 const OPCODE: OpcodeM4ToM0 = OpcodeM4ToM0::McpsDataReq;
375 const SIZE: usize = 40; 400 const SIZE: usize = 40;
@@ -391,6 +416,7 @@ impl MacCommand for PurgeRequest {
391 416
392/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication 417/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication
393#[repr(C)] 418#[repr(C)]
419#[derive(Default)]
394#[cfg_attr(feature = "defmt", derive(defmt::Format))] 420#[cfg_attr(feature = "defmt", derive(defmt::Format))]
395pub struct AssociateResponse { 421pub struct AssociateResponse {
396 /// extended address of the device requesting association 422 /// extended address of the device requesting association
@@ -399,7 +425,7 @@ pub struct AssociateResponse {
399 /// association 425 /// association
400 pub assoc_short_address: [u8; 2], 426 pub assoc_short_address: [u8; 2],
401 /// status of the association attempt 427 /// status of the association attempt
402 pub status: u8, 428 pub status: MacStatus,
403 /// security level to be used 429 /// security level to be used
404 pub security_level: SecurityLevel, 430 pub security_level: SecurityLevel,
405 /// the originator of the key to be used 431 /// the originator of the key to be used
diff --git a/embassy-stm32-wpan/src/sub/mac/consts.rs b/embassy-stm32-wpan/src/sub/mac/consts.rs
index 892d533b4..56903d980 100644
--- a/embassy-stm32-wpan/src/sub/mac/consts.rs
+++ b/embassy-stm32-wpan/src/sub/mac/consts.rs
@@ -1,4 +1,4 @@
1pub const MAX_ED_SCAN_RESULTS_SUPPORTED: usize = 16;
2pub const MAX_PAN_DESC_SUPPORTED: usize = 6; 1pub const MAX_PAN_DESC_SUPPORTED: usize = 6;
3pub const MAX_SOUNDING_LIST_SUPPORTED: usize = 6; 2pub const MAX_SOUNDING_LIST_SUPPORTED: usize = 6;
4pub const MAX_PENDING_ADDRESS: usize = 7; 3pub const MAX_PENDING_ADDRESS: usize = 7;
4pub const MAX_ED_SCAN_RESULTS_SUPPORTED: usize = 16;
diff --git a/embassy-stm32-wpan/src/sub/mac/indications.rs b/embassy-stm32-wpan/src/sub/mac/indications.rs
index 4695f24ef..b67f0a686 100644
--- a/embassy-stm32-wpan/src/sub/mac/indications.rs
+++ b/embassy-stm32-wpan/src/sub/mac/indications.rs
@@ -3,7 +3,7 @@ use super::event::ParseableMacEvent;
3use super::helpers::to_u32; 3use super::helpers::to_u32;
4use super::typedefs::{ 4use super::typedefs::{
5 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor, 5 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor,
6 SecurityLevel, 6 PanId, SecurityLevel,
7}; 7};
8 8
9/// MLME ASSOCIATE Indication which will be used by the MAC 9/// MLME ASSOCIATE Indication which will be used by the MAC
@@ -110,7 +110,7 @@ impl ParseableMacEvent for BeaconNotifyIndication {
110pub struct CommStatusIndication { 110pub struct CommStatusIndication {
111 /// The 16-bit PAN identifier of the device from which the frame 111 /// The 16-bit PAN identifier of the device from which the frame
112 /// was received or to which the frame was being sent 112 /// was received or to which the frame was being sent
113 pub pan_id: [u8; 2], 113 pub pan_id: PanId,
114 /// Source addressing mode 114 /// Source addressing mode
115 pub src_addr_mode: AddressMode, 115 pub src_addr_mode: AddressMode,
116 /// Destination addressing mode 116 /// Destination addressing mode
@@ -163,7 +163,7 @@ impl ParseableMacEvent for CommStatusIndication {
163 }; 163 };
164 164
165 Ok(Self { 165 Ok(Self {
166 pan_id: [buf[0], buf[1]], 166 pan_id: PanId([buf[0], buf[1]]),
167 src_addr_mode, 167 src_addr_mode,
168 dst_addr_mode, 168 dst_addr_mode,
169 src_address, 169 src_address,
@@ -251,7 +251,7 @@ impl ParseableMacEvent for OrphanIndication {
251#[cfg_attr(feature = "defmt", derive(defmt::Format))] 251#[cfg_attr(feature = "defmt", derive(defmt::Format))]
252pub struct SyncLossIndication { 252pub struct SyncLossIndication {
253 /// The PAN identifier with which the device lost synchronization or to which it was realigned 253 /// The PAN identifier with which the device lost synchronization or to which it was realigned
254 pub pan_id: [u8; 2], 254 pub pan_id: PanId,
255 /// The reason that synchronization was lost 255 /// The reason that synchronization was lost
256 pub loss_reason: u8, 256 pub loss_reason: u8,
257 /// The logical channel on which the device lost synchronization or to whi 257 /// The logical channel on which the device lost synchronization or to whi
@@ -275,7 +275,7 @@ impl ParseableMacEvent for SyncLossIndication {
275 Self::validate(buf)?; 275 Self::validate(buf)?;
276 276
277 Ok(Self { 277 Ok(Self {
278 pan_id: [buf[0], buf[1]], 278 pan_id: PanId([buf[0], buf[1]]),
279 loss_reason: buf[2], 279 loss_reason: buf[2],
280 channel_number: MacChannel::try_from(buf[3])?, 280 channel_number: MacChannel::try_from(buf[3])?,
281 channel_page: buf[4], 281 channel_page: buf[4],
@@ -303,19 +303,20 @@ impl ParseableMacEvent for DpsIndication {
303} 303}
304 304
305#[cfg_attr(feature = "defmt", derive(defmt::Format))] 305#[cfg_attr(feature = "defmt", derive(defmt::Format))]
306#[repr(C, align(8))]
306pub struct DataIndication { 307pub struct DataIndication {
307 /// Pointer to the set of octets forming the MSDU being indicated 308 /// Pointer to the set of octets forming the MSDU being indicated
308 pub msdu_ptr: *const u8, 309 pub msdu_ptr: *const u8,
309 /// Source addressing mode used 310 /// Source addressing mode used
310 pub src_addr_mode: AddressMode, 311 pub src_addr_mode: AddressMode,
311 /// Source PAN ID 312 /// Source PAN ID
312 pub src_pan_id: [u8; 2], 313 pub src_pan_id: PanId,
313 /// Source address 314 /// Source address
314 pub src_address: MacAddress, 315 pub src_address: MacAddress,
315 /// Destination addressing mode used 316 /// Destination addressing mode used
316 pub dst_addr_mode: AddressMode, 317 pub dst_addr_mode: AddressMode,
317 /// Destination PAN ID 318 /// Destination PAN ID
318 pub dst_pan_id: [u8; 2], 319 pub dst_pan_id: PanId,
319 /// Destination address 320 /// Destination address
320 pub dst_address: MacAddress, 321 pub dst_address: MacAddress,
321 /// The number of octets contained in the MSDU being indicated 322 /// The number of octets contained in the MSDU being indicated
@@ -355,7 +356,7 @@ pub struct DataIndication {
355} 356}
356 357
357impl ParseableMacEvent for DataIndication { 358impl ParseableMacEvent for DataIndication {
358 const SIZE: usize = 72; 359 const SIZE: usize = 68;
359 360
360 fn try_parse(buf: &[u8]) -> Result<Self, ()> { 361 fn try_parse(buf: &[u8]) -> Result<Self, ()> {
361 Self::validate(buf)?; 362 Self::validate(buf)?;
@@ -387,24 +388,24 @@ impl ParseableMacEvent for DataIndication {
387 Ok(Self { 388 Ok(Self {
388 msdu_ptr: to_u32(&buf[0..4]) as *const u8, 389 msdu_ptr: to_u32(&buf[0..4]) as *const u8,
389 src_addr_mode, 390 src_addr_mode,
390 src_pan_id: [buf[5], buf[6]], 391 src_pan_id: PanId([buf[5], buf[6]]),
391 src_address, 392 src_address,
392 dst_addr_mode, 393 dst_addr_mode,
393 dst_pan_id: [buf[16], buf[17]], 394 dst_pan_id: PanId([buf[16], buf[17]]),
394 dst_address, 395 dst_address,
395 msdu_length: buf[26], 396 msdu_length: buf[26],
396 mpdu_link_quality: buf[27], 397 mpdu_link_quality: buf[27],
397 dsn: buf[28], 398 dsn: buf[28],
398 time_stamp: [buf[29], buf[30], buf[31], buf[32]], 399 time_stamp: [buf[29], buf[30], buf[31], buf[32]],
399 security_level: SecurityLevel::try_from(buf[33])?, 400 security_level: SecurityLevel::try_from(buf[33]).unwrap_or(SecurityLevel::Unsecure), // TODO: this is totaly wrong, but I'm too smol brain to fix it
400 key_id_mode: KeyIdMode::try_from(buf[34])?, 401 key_id_mode: KeyIdMode::try_from(buf[34]).unwrap_or(KeyIdMode::Implicite), // TODO: this is totaly wrong, but I'm too smol brain to fix it
401 key_source: [buf[35], buf[36], buf[37], buf[38], buf[39], buf[40], buf[41], buf[42]], 402 key_source: [buf[35], buf[36], buf[37], buf[38], buf[39], buf[40], buf[41], buf[42]],
402 key_index: buf[43], 403 key_index: buf[43],
403 uwbprf: buf[44], 404 uwbprf: buf[44],
404 uwn_preamble_symbol_repetitions: buf[45], 405 uwn_preamble_symbol_repetitions: buf[45],
405 datrate: buf[46], 406 datrate: buf[46],
406 ranging_received: buf[47], 407 ranging_received: buf[47],
407 ranging_counter_start: to_u32(&buf[58..52]), 408 ranging_counter_start: to_u32(&buf[48..52]),
408 ranging_counter_stop: to_u32(&buf[52..56]), 409 ranging_counter_stop: to_u32(&buf[52..56]),
409 ranging_tracking_interval: to_u32(&buf[56..60]), 410 ranging_tracking_interval: to_u32(&buf[56..60]),
410 ranging_offset: to_u32(&buf[60..64]), 411 ranging_offset: to_u32(&buf[60..64]),
diff --git a/embassy-stm32-wpan/src/sub/mac/opcodes.rs b/embassy-stm32-wpan/src/sub/mac/opcodes.rs
index c9a07d6af..fd7011873 100644
--- a/embassy-stm32-wpan/src/sub/mac/opcodes.rs
+++ b/embassy-stm32-wpan/src/sub/mac/opcodes.rs
@@ -5,6 +5,7 @@ const fn opcode(ocf: u16) -> isize {
5 ((ST_VENDOR_OGF << 9) | (MAC_802_15_4_CMD_OPCODE_OFFSET + ocf)) as isize 5 ((ST_VENDOR_OGF << 9) | (MAC_802_15_4_CMD_OPCODE_OFFSET + ocf)) as isize
6} 6}
7 7
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8pub enum OpcodeM4ToM0 { 9pub enum OpcodeM4ToM0 {
9 MlmeAssociateReq = opcode(0x00), 10 MlmeAssociateReq = opcode(0x00),
10 MlmeAssociateRes = opcode(0x01), 11 MlmeAssociateRes = opcode(0x01),
@@ -26,6 +27,7 @@ pub enum OpcodeM4ToM0 {
26 McpsPurgeReq = opcode(0x11), 27 McpsPurgeReq = opcode(0x11),
27} 28}
28 29
30#[cfg_attr(feature = "defmt", derive(defmt::Format))]
29pub enum OpcodeM0ToM4 { 31pub enum OpcodeM0ToM4 {
30 MlmeAssociateCnf = 0x00, 32 MlmeAssociateCnf = 0x00,
31 MlmeDisassociateCnf, 33 MlmeDisassociateCnf,
diff --git a/embassy-stm32-wpan/src/sub/mac/responses.rs b/embassy-stm32-wpan/src/sub/mac/responses.rs
index 37271ec28..2b90ccdc6 100644
--- a/embassy-stm32-wpan/src/sub/mac/responses.rs
+++ b/embassy-stm32-wpan/src/sub/mac/responses.rs
@@ -2,7 +2,8 @@ use super::consts::{MAX_ED_SCAN_RESULTS_SUPPORTED, MAX_PAN_DESC_SUPPORTED, MAX_S
2use super::event::ParseableMacEvent; 2use super::event::ParseableMacEvent;
3use super::helpers::to_u32; 3use super::helpers::to_u32;
4use super::typedefs::{ 4use super::typedefs::{
5 AddressMode, AssociationStatus, KeyIdMode, MacAddress, MacStatus, PanDescriptor, PibId, ScanType, SecurityLevel, 5 AddressMode, AssociationStatus, KeyIdMode, MacAddress, MacStatus, PanDescriptor, PanId, PibId, ScanType,
6 SecurityLevel,
6}; 7};
7 8
8/// MLME ASSOCIATE Confirm used to inform of the initiating device whether 9/// MLME ASSOCIATE Confirm used to inform of the initiating device whether
@@ -50,7 +51,7 @@ pub struct DisassociateConfirm {
50 /// device addressing mode used 51 /// device addressing mode used
51 pub device_addr_mode: AddressMode, 52 pub device_addr_mode: AddressMode,
52 /// the identifier of the PAN of the device 53 /// the identifier of the PAN of the device
53 pub device_pan_id: [u8; 2], 54 pub device_pan_id: PanId,
54 /// device address 55 /// device address
55 pub device_address: MacAddress, 56 pub device_address: MacAddress,
56} 57}
@@ -76,7 +77,7 @@ impl ParseableMacEvent for DisassociateConfirm {
76 Ok(Self { 77 Ok(Self {
77 status: MacStatus::try_from(buf[0])?, 78 status: MacStatus::try_from(buf[0])?,
78 device_addr_mode, 79 device_addr_mode,
79 device_pan_id: [buf[2], buf[3]], 80 device_pan_id: PanId([buf[2], buf[3]]),
80 device_address, 81 device_address,
81 }) 82 })
82 } 83 }
diff --git a/embassy-stm32-wpan/src/sub/mac/typedefs.rs b/embassy-stm32-wpan/src/sub/mac/typedefs.rs
index 1a4c30cbc..5ff051c97 100644
--- a/embassy-stm32-wpan/src/sub/mac/typedefs.rs
+++ b/embassy-stm32-wpan/src/sub/mac/typedefs.rs
@@ -25,15 +25,12 @@ impl From<u8> for MacError {
25 25
26numeric_enum! { 26numeric_enum! {
27 #[repr(u8)] 27 #[repr(u8)]
28 #[derive(Debug)] 28 #[derive(Debug, Default)]
29 #[cfg_attr(feature = "defmt", derive(defmt::Format))] 29 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
30 pub enum MacStatus { 30 pub enum MacStatus {
31 #[default]
31 Success = 0x00, 32 Success = 0x00,
32 Error = 0x01, 33 Failure = 0xFF
33 NotImplemented = 0x02,
34 NotSupported = 0x03,
35 HardwareNotSupported = 0x04,
36 Undefined = 0x05,
37 } 34 }
38} 35}
39 36
@@ -134,6 +131,10 @@ impl Default for MacAddress {
134 } 131 }
135} 132}
136 133
134impl MacAddress {
135 pub const BROADCAST: Self = Self { short: [0xFF, 0xFF] };
136}
137
137#[cfg_attr(feature = "defmt", derive(defmt::Format))] 138#[cfg_attr(feature = "defmt", derive(defmt::Format))]
138pub struct GtsCharacteristics { 139pub struct GtsCharacteristics {
139 pub fields: u8, 140 pub fields: u8,
@@ -145,7 +146,7 @@ pub struct GtsCharacteristics {
145#[cfg_attr(feature = "defmt", derive(defmt::Format))] 146#[cfg_attr(feature = "defmt", derive(defmt::Format))]
146pub struct PanDescriptor { 147pub struct PanDescriptor {
147 /// PAN identifier of the coordinator 148 /// PAN identifier of the coordinator
148 pub coord_pan_id: [u8; 2], 149 pub coord_pan_id: PanId,
149 /// Coordinator addressing mode 150 /// Coordinator addressing mode
150 pub coord_addr_mode: AddressMode, 151 pub coord_addr_mode: AddressMode,
151 /// The current logical channel occupied by the network 152 /// The current logical channel occupied by the network
@@ -188,7 +189,7 @@ impl TryFrom<&[u8]> for PanDescriptor {
188 }; 189 };
189 190
190 Ok(Self { 191 Ok(Self {
191 coord_pan_id: [buf[0], buf[1]], 192 coord_pan_id: PanId([buf[0], buf[1]]),
192 coord_addr_mode, 193 coord_addr_mode,
193 logical_channel: MacChannel::try_from(buf[3])?, 194 logical_channel: MacChannel::try_from(buf[3])?,
194 coord_addr, 195 coord_addr,
@@ -336,3 +337,12 @@ numeric_enum! {
336 Orphan = 0x03 337 Orphan = 0x03
337 } 338 }
338} 339}
340
341/// newtype for Pan Id
342#[derive(Default, Clone, Copy)]
343#[cfg_attr(feature = "defmt", derive(defmt::Format))]
344pub struct PanId(pub [u8; 2]);
345
346impl PanId {
347 pub const BROADCAST: Self = Self([0xFF, 0xFF]);
348}
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs
index 4e2578a21..37d36fcdd 100644
--- a/examples/stm32wb/src/bin/mac_ffd.rs
+++ b/examples/stm32wb/src/bin/mac_ffd.rs
@@ -6,8 +6,9 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::sub::mac::commands::{ResetRequest, SetRequest, StartRequest}; 9use embassy_stm32_wpan::sub::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::sub::mac::typedefs::{MacChannel, PibId}; 10use embassy_stm32_wpan::sub::mac::event::MacEvent;
11use embassy_stm32_wpan::sub::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel};
11use embassy_stm32_wpan::sub::mm; 12use embassy_stm32_wpan::sub::mm;
12use embassy_stm32_wpan::TlMbox; 13use embassy_stm32_wpan::TlMbox;
13use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
@@ -123,7 +124,7 @@ async fn main(spawner: Spawner) {
123 info!("starting FFD device"); 124 info!("starting FFD device");
124 mbox.mac_subsystem 125 mbox.mac_subsystem
125 .send_command(&StartRequest { 126 .send_command(&StartRequest {
126 pan_id: [0xAA, 0x1A], 127 pan_id: PanId([0x1A, 0xAA]),
127 channel_number: MacChannel::Channel16, 128 channel_number: MacChannel::Channel16,
128 beacon_order: 0x0F, 129 beacon_order: 0x0F,
129 superframe_order: 0x0F, 130 superframe_order: 0x0F,
@@ -151,5 +152,28 @@ async fn main(spawner: Spawner) {
151 loop { 152 loop {
152 let evt = mbox.mac_subsystem.read().await; 153 let evt = mbox.mac_subsystem.read().await;
153 defmt::info!("{:#x}", evt); 154 defmt::info!("{:#x}", evt);
155
156 if let Ok(evt) = evt {
157 match evt {
158 MacEvent::MlmeAssociateInd(association) => mbox
159 .mac_subsystem
160 .send_command(&AssociateResponse {
161 device_address: association.device_address,
162 assoc_short_address: [0x33, 0x44],
163 status: MacStatus::Success,
164 security_level: SecurityLevel::Unsecure,
165 ..Default::default()
166 })
167 .await
168 .unwrap(),
169 MacEvent::McpsDataInd(data_ind) => {
170 let data_addr = data_ind.msdu_ptr;
171 let mut a = [0u8; 256];
172 unsafe { data_addr.copy_to(&mut a as *mut _, data_ind.msdu_length as usize) }
173 info!("{}", a[..data_ind.msdu_length as usize])
174 }
175 _ => {}
176 }
177 }
154 } 178 }
155} 179}
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs
index e5f8d54c9..756709132 100644
--- a/examples/stm32wb/src/bin/mac_rfd.rs
+++ b/examples/stm32wb/src/bin/mac_rfd.rs
@@ -6,10 +6,10 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest}; 9use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest};
10use embassy_stm32_wpan::sub::mac::event::MacEvent; 10use embassy_stm32_wpan::sub::mac::event::MacEvent;
11use embassy_stm32_wpan::sub::mac::typedefs::{ 11use embassy_stm32_wpan::sub::mac::typedefs::{
12 AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel, 12 AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
13}; 13};
14use embassy_stm32_wpan::sub::mm; 14use embassy_stm32_wpan::sub::mm;
15use embassy_stm32_wpan::TlMbox; 15use embassy_stm32_wpan::TlMbox;
@@ -112,7 +112,7 @@ async fn main(spawner: Spawner) {
112 coord_addr_mode: AddressMode::Short, 112 coord_addr_mode: AddressMode::Short,
113 coord_address: MacAddress { short: [34, 17] }, 113 coord_address: MacAddress { short: [34, 17] },
114 capability_information: Capabilities::ALLOCATE_ADDRESS, 114 capability_information: Capabilities::ALLOCATE_ADDRESS,
115 coord_pan_id: [0xAA, 0x1A], 115 coord_pan_id: PanId([0x1A, 0xAA]),
116 security_level: SecurityLevel::Unsecure, 116 security_level: SecurityLevel::Unsecure,
117 key_id_mode: KeyIdMode::Implicite, 117 key_id_mode: KeyIdMode::Implicite,
118 key_source: [0; 8], 118 key_source: [0; 8],
@@ -123,11 +123,16 @@ async fn main(spawner: Spawner) {
123 let evt = mbox.mac_subsystem.read().await; 123 let evt = mbox.mac_subsystem.read().await;
124 info!("{:#x}", evt); 124 info!("{:#x}", evt);
125 125
126 let short_addr = if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt {
127 conf.assoc_short_address
128 } else {
129 defmt::panic!()
130 };
131
126 info!("setting short address"); 132 info!("setting short address");
127 let short: u64 = 0xACDE480000000002;
128 mbox.mac_subsystem 133 mbox.mac_subsystem
129 .send_command(&SetRequest { 134 .send_command(&SetRequest {
130 pib_attribute_ptr: &short as *const _ as *const u8, 135 pib_attribute_ptr: &short_addr as *const _ as *const u8,
131 pib_attribute: PibId::ShortAddress, 136 pib_attribute: PibId::ShortAddress,
132 }) 137 })
133 .await 138 .await
@@ -135,6 +140,29 @@ async fn main(spawner: Spawner) {
135 let evt = mbox.mac_subsystem.read().await; 140 let evt = mbox.mac_subsystem.read().await;
136 info!("{:#x}", evt); 141 info!("{:#x}", evt);
137 142
143 info!("sending data");
144 let mut data_buffer = [0u8; 256];
145 let data = b"Hello from embassy!";
146 data_buffer[..data.len()].copy_from_slice(data);
147 mbox.mac_subsystem
148 .send_command(&DataRequest {
149 src_addr_mode: AddressMode::Short,
150 dst_addr_mode: AddressMode::Short,
151 dst_pan_id: PanId::BROADCAST,
152 dst_address: MacAddress::BROADCAST,
153 msdu_handle: 0x02,
154 ack_tx: 0x00,
155 gts_tx: false,
156 msdu_ptr: &data_buffer as *const _ as *const u8,
157 msdu_length: data.len() as u8,
158 security_level: SecurityLevel::Unsecure,
159 ..Default::default()
160 })
161 .await
162 .unwrap();
163 let evt = mbox.mac_subsystem.read().await;
164 info!("{:#x}", evt);
165
138 loop { 166 loop {
139 let evt = mbox.mac_subsystem.read().await; 167 let evt = mbox.mac_subsystem.read().await;
140 info!("{:#x}", evt); 168 info!("{:#x}", evt);