diff options
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/commands.rs | 20 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/indications.rs | 70 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/mod.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/responses.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/typedefs.rs | 43 | ||||
| -rw-r--r-- | examples/stm32wb/src/bin/mac_ffd.rs | 18 | ||||
| -rw-r--r-- | examples/stm32wb/src/bin/mac_rfd.rs | 94 |
7 files changed, 169 insertions, 97 deletions
diff --git a/embassy-stm32-wpan/src/sub/mac/commands.rs b/embassy-stm32-wpan/src/sub/mac/commands.rs index d8a4e3ee1..7ccf10026 100644 --- a/embassy-stm32-wpan/src/sub/mac/commands.rs +++ b/embassy-stm32-wpan/src/sub/mac/commands.rs | |||
| @@ -9,12 +9,13 @@ pub trait MacCommand { | |||
| 9 | const SIZE: usize; | 9 | const SIZE: usize; |
| 10 | 10 | ||
| 11 | fn copy_into_slice(&self, buf: &mut [u8]) { | 11 | fn copy_into_slice(&self, buf: &mut [u8]) { |
| 12 | unsafe { core::ptr::copy(self as *const _ as *const u8, buf as *mut _ as *mut u8, 8) }; | 12 | unsafe { core::ptr::copy(self as *const _ as *const u8, buf as *mut _ as *mut u8, Self::SIZE) }; |
| 13 | } | 13 | } |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | /// MLME ASSOCIATE Request used to request an association | 16 | /// MLME ASSOCIATE Request used to request an association |
| 17 | #[repr(C)] | 17 | #[repr(C)] |
| 18 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 18 | pub struct AssociateRequest { | 19 | pub struct AssociateRequest { |
| 19 | /// the logical channel on which to attempt association | 20 | /// the logical channel on which to attempt association |
| 20 | pub channel_number: MacChannel, | 21 | pub channel_number: MacChannel, |
| @@ -45,6 +46,7 @@ impl MacCommand for AssociateRequest { | |||
| 45 | 46 | ||
| 46 | /// MLME DISASSOCIATE Request sed to request a disassociation | 47 | /// MLME DISASSOCIATE Request sed to request a disassociation |
| 47 | #[repr(C)] | 48 | #[repr(C)] |
| 49 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 48 | pub struct DisassociateRequest { | 50 | pub struct DisassociateRequest { |
| 49 | /// device addressing mode used | 51 | /// device addressing mode used |
| 50 | pub device_addr_mode: AddressMode, | 52 | pub device_addr_mode: AddressMode, |
| @@ -73,6 +75,7 @@ impl MacCommand for DisassociateRequest { | |||
| 73 | 75 | ||
| 74 | /// MLME GET Request used to request a PIB value | 76 | /// MLME GET Request used to request a PIB value |
| 75 | #[repr(C)] | 77 | #[repr(C)] |
| 78 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 76 | pub struct GetRequest { | 79 | pub struct GetRequest { |
| 77 | /// the name of the PIB attribute to read | 80 | /// the name of the PIB attribute to read |
| 78 | pub pib_attribute: PibId, | 81 | pub pib_attribute: PibId, |
| @@ -85,6 +88,7 @@ impl MacCommand for GetRequest { | |||
| 85 | 88 | ||
| 86 | /// MLME GTS Request used to request and maintain GTSs | 89 | /// MLME GTS Request used to request and maintain GTSs |
| 87 | #[repr(C)] | 90 | #[repr(C)] |
| 91 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 88 | pub struct GtsRequest { | 92 | pub struct GtsRequest { |
| 89 | /// the characteristics of the GTS | 93 | /// the characteristics of the GTS |
| 90 | pub characteristics: GtsCharacteristics, | 94 | pub characteristics: GtsCharacteristics, |
| @@ -104,6 +108,7 @@ impl MacCommand for GtsRequest { | |||
| 104 | } | 108 | } |
| 105 | 109 | ||
| 106 | #[repr(C)] | 110 | #[repr(C)] |
| 111 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 107 | pub struct ResetRequest { | 112 | pub struct ResetRequest { |
| 108 | /// MAC PIB attributes are set to their default values or not during reset | 113 | /// MAC PIB attributes are set to their default values or not during reset |
| 109 | pub set_default_pib: bool, | 114 | pub set_default_pib: bool, |
| @@ -117,6 +122,7 @@ impl MacCommand for ResetRequest { | |||
| 117 | /// MLME RX ENABLE Request used to request that the receiver is either enabled | 122 | /// MLME RX ENABLE Request used to request that the receiver is either enabled |
| 118 | /// for a finite period of time or disabled | 123 | /// for a finite period of time or disabled |
| 119 | #[repr(C)] | 124 | #[repr(C)] |
| 125 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 120 | pub struct RxEnableRequest { | 126 | pub struct RxEnableRequest { |
| 121 | /// the request operation can be deferred or not | 127 | /// the request operation can be deferred or not |
| 122 | pub defer_permit: bool, | 128 | pub defer_permit: bool, |
| @@ -148,6 +154,7 @@ impl MacCommand for RxEnableRequest { | |||
| 148 | 154 | ||
| 149 | /// MLME SCAN Request used to initiate a channel scan over a given list of channels | 155 | /// MLME SCAN Request used to initiate a channel scan over a given list of channels |
| 150 | #[repr(C)] | 156 | #[repr(C)] |
| 157 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 151 | pub struct ScanRequest { | 158 | pub struct ScanRequest { |
| 152 | /// the type of scan to be performed | 159 | /// the type of scan to be performed |
| 153 | pub scan_type: ScanType, | 160 | pub scan_type: ScanType, |
| @@ -174,6 +181,7 @@ impl MacCommand for ScanRequest { | |||
| 174 | 181 | ||
| 175 | /// MLME SET Request used to attempt to write the given value to the indicated PIB attribute | 182 | /// MLME SET Request used to attempt to write the given value to the indicated PIB attribute |
| 176 | #[repr(C)] | 183 | #[repr(C)] |
| 184 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 177 | pub struct SetRequest { | 185 | pub struct SetRequest { |
| 178 | /// the pointer to the value of the PIB attribute to set | 186 | /// the pointer to the value of the PIB attribute to set |
| 179 | pub pib_attribute_ptr: *const u8, | 187 | pub pib_attribute_ptr: *const u8, |
| @@ -190,6 +198,7 @@ impl MacCommand for SetRequest { | |||
| 190 | /// configuration | 198 | /// configuration |
| 191 | #[derive(Default)] | 199 | #[derive(Default)] |
| 192 | #[repr(C)] | 200 | #[repr(C)] |
| 201 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 193 | pub struct StartRequest { | 202 | pub struct StartRequest { |
| 194 | /// PAN indentifier to used by the device | 203 | /// PAN indentifier to used by the device |
| 195 | pub pan_id: [u8; 2], | 204 | pub pan_id: [u8; 2], |
| @@ -233,6 +242,7 @@ impl MacCommand for StartRequest { | |||
| 233 | /// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if | 242 | /// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if |
| 234 | /// specified, tracking its beacons | 243 | /// specified, tracking its beacons |
| 235 | #[repr(C)] | 244 | #[repr(C)] |
| 245 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 236 | pub struct SyncRequest { | 246 | pub struct SyncRequest { |
| 237 | /// the channel number on which to attempt coordinator synchronization | 247 | /// the channel number on which to attempt coordinator synchronization |
| 238 | pub channel_number: MacChannel, | 248 | pub channel_number: MacChannel, |
| @@ -252,6 +262,7 @@ impl MacCommand for SyncRequest { | |||
| 252 | 262 | ||
| 253 | /// MLME POLL Request propmts the device to request data from the coordinator | 263 | /// MLME POLL Request propmts the device to request data from the coordinator |
| 254 | #[repr(C)] | 264 | #[repr(C)] |
| 265 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 255 | pub struct PollRequest { | 266 | pub struct PollRequest { |
| 256 | /// addressing mode of the coordinator | 267 | /// addressing mode of the coordinator |
| 257 | pub coord_addr_mode: AddressMode, | 268 | pub coord_addr_mode: AddressMode, |
| @@ -277,6 +288,7 @@ impl MacCommand for PollRequest { | |||
| 277 | /// MLME DPS Request allows the next higher layer to request that the PHY utilize a | 288 | /// MLME DPS Request allows the next higher layer to request that the PHY utilize a |
| 278 | /// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration | 289 | /// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration |
| 279 | #[repr(C)] | 290 | #[repr(C)] |
| 291 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 280 | pub struct DpsRequest { | 292 | pub struct DpsRequest { |
| 281 | /// the index value for the transmitter | 293 | /// the index value for the transmitter |
| 282 | tx_dps_index: u8, | 294 | tx_dps_index: u8, |
| @@ -295,6 +307,7 @@ impl MacCommand for DpsRequest { | |||
| 295 | /// MLME SOUNDING request primitive which is used by the next higher layer to request that | 307 | /// MLME SOUNDING request primitive which is used by the next higher layer to request that |
| 296 | /// the PHY respond with channel sounding information | 308 | /// the PHY respond with channel sounding information |
| 297 | #[repr(C)] | 309 | #[repr(C)] |
| 310 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 298 | pub struct SoundingRequest; | 311 | pub struct SoundingRequest; |
| 299 | 312 | ||
| 300 | impl MacCommand for SoundingRequest { | 313 | impl MacCommand for SoundingRequest { |
| @@ -305,6 +318,7 @@ impl MacCommand for SoundingRequest { | |||
| 305 | /// MLME CALIBRATE request primitive which used to obtain the results of a ranging | 318 | /// MLME CALIBRATE request primitive which used to obtain the results of a ranging |
| 306 | /// calibration request from an RDEV | 319 | /// calibration request from an RDEV |
| 307 | #[repr(C)] | 320 | #[repr(C)] |
| 321 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 308 | pub struct CalibrateRequest; | 322 | pub struct CalibrateRequest; |
| 309 | 323 | ||
| 310 | impl MacCommand for CalibrateRequest { | 324 | impl MacCommand for CalibrateRequest { |
| @@ -314,6 +328,7 @@ impl MacCommand for CalibrateRequest { | |||
| 314 | 328 | ||
| 315 | /// MCPS DATA Request used for MAC data related requests from the application | 329 | /// MCPS DATA Request used for MAC data related requests from the application |
| 316 | #[repr(C)] | 330 | #[repr(C)] |
| 331 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 317 | pub struct DataRequest { | 332 | pub struct DataRequest { |
| 318 | /// the handle assocated with the MSDU to be transmitted | 333 | /// the handle assocated with the MSDU to be transmitted |
| 319 | pub msdu_ptr: *const u8, | 334 | pub msdu_ptr: *const u8, |
| @@ -362,6 +377,7 @@ impl MacCommand for DataRequest { | |||
| 362 | 377 | ||
| 363 | /// for MCPS PURGE Request used to purge an MSDU from the transaction queue | 378 | /// for MCPS PURGE Request used to purge an MSDU from the transaction queue |
| 364 | #[repr(C)] | 379 | #[repr(C)] |
| 380 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 365 | pub struct PurgeRequest { | 381 | pub struct PurgeRequest { |
| 366 | /// the handle associated with the MSDU to be purged from the transaction | 382 | /// the handle associated with the MSDU to be purged from the transaction |
| 367 | /// queue | 383 | /// queue |
| @@ -375,6 +391,7 @@ impl MacCommand for PurgeRequest { | |||
| 375 | 391 | ||
| 376 | /// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication | 392 | /// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication |
| 377 | #[repr(C)] | 393 | #[repr(C)] |
| 394 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 378 | pub struct AssociateResponse { | 395 | pub struct AssociateResponse { |
| 379 | /// extended address of the device requesting association | 396 | /// extended address of the device requesting association |
| 380 | pub device_address: [u8; 8], | 397 | pub device_address: [u8; 8], |
| @@ -400,6 +417,7 @@ impl MacCommand for AssociateResponse { | |||
| 400 | 417 | ||
| 401 | /// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication | 418 | /// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication |
| 402 | #[repr(C)] | 419 | #[repr(C)] |
| 420 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 403 | pub struct OrphanResponse { | 421 | pub struct OrphanResponse { |
| 404 | /// extended address of the orphaned device | 422 | /// extended address of the orphaned device |
| 405 | pub orphan_address: [u8; 8], | 423 | pub orphan_address: [u8; 8], |
diff --git a/embassy-stm32-wpan/src/sub/mac/indications.rs b/embassy-stm32-wpan/src/sub/mac/indications.rs index dc5ae4c44..4695f24ef 100644 --- a/embassy-stm32-wpan/src/sub/mac/indications.rs +++ b/embassy-stm32-wpan/src/sub/mac/indications.rs | |||
| @@ -141,21 +141,25 @@ impl ParseableMacEvent for CommStatusIndication { | |||
| 141 | let dst_addr_mode = AddressMode::try_from(buf[3])?; | 141 | let dst_addr_mode = AddressMode::try_from(buf[3])?; |
| 142 | 142 | ||
| 143 | let src_address = match src_addr_mode { | 143 | let src_address = match src_addr_mode { |
| 144 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 144 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 145 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 145 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 146 | AddressMode::Short => MacAddress::Short([buf[4], buf[5]]), | 146 | AddressMode::Short => MacAddress { |
| 147 | AddressMode::Extended => { | 147 | short: [buf[4], buf[5]], |
| 148 | MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]]) | 148 | }, |
| 149 | } | 149 | AddressMode::Extended => MacAddress { |
| 150 | extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]], | ||
| 151 | }, | ||
| 150 | }; | 152 | }; |
| 151 | 153 | ||
| 152 | let dst_address = match dst_addr_mode { | 154 | let dst_address = match dst_addr_mode { |
| 153 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 155 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 154 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 156 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 155 | AddressMode::Short => MacAddress::Short([buf[12], buf[13]]), | 157 | AddressMode::Short => MacAddress { |
| 156 | AddressMode::Extended => { | 158 | short: [buf[12], buf[13]], |
| 157 | MacAddress::Extended([buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]]) | 159 | }, |
| 158 | } | 160 | AddressMode::Extended => MacAddress { |
| 161 | extended: [buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]], | ||
| 162 | }, | ||
| 159 | }; | 163 | }; |
| 160 | 164 | ||
| 161 | Ok(Self { | 165 | Ok(Self { |
| @@ -358,22 +362,26 @@ impl ParseableMacEvent for DataIndication { | |||
| 358 | 362 | ||
| 359 | let src_addr_mode = AddressMode::try_from(buf[4])?; | 363 | let src_addr_mode = AddressMode::try_from(buf[4])?; |
| 360 | let src_address = match src_addr_mode { | 364 | let src_address = match src_addr_mode { |
| 361 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 365 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 362 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 366 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 363 | AddressMode::Short => MacAddress::Short([buf[7], buf[8]]), | 367 | AddressMode::Short => MacAddress { |
| 364 | AddressMode::Extended => { | 368 | short: [buf[7], buf[8]], |
| 365 | MacAddress::Extended([buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14]]) | 369 | }, |
| 366 | } | 370 | AddressMode::Extended => MacAddress { |
| 371 | extended: [buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14]], | ||
| 372 | }, | ||
| 367 | }; | 373 | }; |
| 368 | 374 | ||
| 369 | let dst_addr_mode = AddressMode::try_from(buf[15])?; | 375 | let dst_addr_mode = AddressMode::try_from(buf[15])?; |
| 370 | let dst_address = match dst_addr_mode { | 376 | let dst_address = match dst_addr_mode { |
| 371 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 377 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 372 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 378 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 373 | AddressMode::Short => MacAddress::Short([buf[18], buf[19]]), | 379 | AddressMode::Short => MacAddress { |
| 374 | AddressMode::Extended => { | 380 | short: [buf[18], buf[19]], |
| 375 | MacAddress::Extended([buf[18], buf[19], buf[20], buf[21], buf[22], buf[23], buf[24], buf[25]]) | 381 | }, |
| 376 | } | 382 | AddressMode::Extended => MacAddress { |
| 383 | extended: [buf[18], buf[19], buf[20], buf[21], buf[22], buf[23], buf[24], buf[25]], | ||
| 384 | }, | ||
| 377 | }; | 385 | }; |
| 378 | 386 | ||
| 379 | Ok(Self { | 387 | Ok(Self { |
| @@ -424,12 +432,14 @@ impl ParseableMacEvent for PollIndication { | |||
| 424 | 432 | ||
| 425 | let addr_mode = AddressMode::try_from(buf[0])?; | 433 | let addr_mode = AddressMode::try_from(buf[0])?; |
| 426 | let request_address = match addr_mode { | 434 | let request_address = match addr_mode { |
| 427 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 435 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 428 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 436 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 429 | AddressMode::Short => MacAddress::Short([buf[1], buf[2]]), | 437 | AddressMode::Short => MacAddress { |
| 430 | AddressMode::Extended => { | 438 | short: [buf[1], buf[2]], |
| 431 | MacAddress::Extended([buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]]) | 439 | }, |
| 432 | } | 440 | AddressMode::Extended => MacAddress { |
| 441 | extended: [buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]], | ||
| 442 | }, | ||
| 433 | }; | 443 | }; |
| 434 | 444 | ||
| 435 | Ok(Self { | 445 | Ok(Self { |
diff --git a/embassy-stm32-wpan/src/sub/mac/mod.rs b/embassy-stm32-wpan/src/sub/mac/mod.rs index 0524f135a..26358bf81 100644 --- a/embassy-stm32-wpan/src/sub/mac/mod.rs +++ b/embassy-stm32-wpan/src/sub/mac/mod.rs | |||
| @@ -91,13 +91,15 @@ impl Mac { | |||
| 91 | .await; | 91 | .await; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | pub async fn send_command<T>(&self, cmd: T) -> Result<(), MacError> | 94 | pub async fn send_command<T>(&self, cmd: &T) -> Result<(), MacError> |
| 95 | where | 95 | where |
| 96 | T: MacCommand, | 96 | T: MacCommand, |
| 97 | { | 97 | { |
| 98 | let mut payload = [0u8; MAX_PACKET_SIZE]; | 98 | let mut payload = [0u8; MAX_PACKET_SIZE]; |
| 99 | cmd.copy_into_slice(&mut payload); | 99 | cmd.copy_into_slice(&mut payload); |
| 100 | 100 | ||
| 101 | debug!("sending {}", &payload[..T::SIZE]); | ||
| 102 | |||
| 101 | let response = self | 103 | let response = self |
| 102 | .tl_write_and_get_response(T::OPCODE as u16, &payload[..T::SIZE]) | 104 | .tl_write_and_get_response(T::OPCODE as u16, &payload[..T::SIZE]) |
| 103 | .await; | 105 | .await; |
diff --git a/embassy-stm32-wpan/src/sub/mac/responses.rs b/embassy-stm32-wpan/src/sub/mac/responses.rs index ce2ca2fb2..37271ec28 100644 --- a/embassy-stm32-wpan/src/sub/mac/responses.rs +++ b/embassy-stm32-wpan/src/sub/mac/responses.rs | |||
| @@ -27,6 +27,8 @@ impl ParseableMacEvent for AssociateConfirm { | |||
| 27 | const SIZE: usize = 16; | 27 | const SIZE: usize = 16; |
| 28 | 28 | ||
| 29 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { | 29 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { |
| 30 | debug!("{}", buf); | ||
| 31 | |||
| 30 | Self::validate(buf)?; | 32 | Self::validate(buf)?; |
| 31 | 33 | ||
| 32 | Ok(Self { | 34 | Ok(Self { |
| @@ -61,12 +63,14 @@ impl ParseableMacEvent for DisassociateConfirm { | |||
| 61 | 63 | ||
| 62 | let device_addr_mode = AddressMode::try_from(buf[1])?; | 64 | let device_addr_mode = AddressMode::try_from(buf[1])?; |
| 63 | let device_address = match device_addr_mode { | 65 | let device_address = match device_addr_mode { |
| 64 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 66 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 65 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 67 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 66 | AddressMode::Short => MacAddress::Short([buf[4], buf[5]]), | 68 | AddressMode::Short => MacAddress { |
| 67 | AddressMode::Extended => { | 69 | short: [buf[4], buf[5]], |
| 68 | MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]]) | 70 | }, |
| 69 | } | 71 | AddressMode::Extended => MacAddress { |
| 72 | extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]], | ||
| 73 | }, | ||
| 70 | }; | 74 | }; |
| 71 | 75 | ||
| 72 | Ok(Self { | 76 | Ok(Self { |
| @@ -238,7 +242,6 @@ impl ParseableMacEvent for StartConfirm { | |||
| 238 | 242 | ||
| 239 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { | 243 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { |
| 240 | Self::validate(buf)?; | 244 | Self::validate(buf)?; |
| 241 | debug!("{:#x}", buf); | ||
| 242 | 245 | ||
| 243 | Ok(Self { | 246 | Ok(Self { |
| 244 | status: MacStatus::try_from(buf[0])?, | 247 | status: MacStatus::try_from(buf[0])?, |
diff --git a/embassy-stm32-wpan/src/sub/mac/typedefs.rs b/embassy-stm32-wpan/src/sub/mac/typedefs.rs index fe79b3a79..1a4c30cbc 100644 --- a/embassy-stm32-wpan/src/sub/mac/typedefs.rs +++ b/embassy-stm32-wpan/src/sub/mac/typedefs.rs | |||
| @@ -109,18 +109,32 @@ numeric_enum! { | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | #[derive(Clone, Copy)] | 111 | #[derive(Clone, Copy)] |
| 112 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 112 | pub union MacAddress { |
| 113 | pub enum MacAddress { | 113 | pub short: [u8; 2], |
| 114 | Short([u8; 2]), | 114 | pub extended: [u8; 8], |
| 115 | Extended([u8; 8]), | 115 | } |
| 116 | |||
| 117 | #[cfg(feature = "defmt")] | ||
| 118 | impl defmt::Format for MacAddress { | ||
| 119 | fn format(&self, fmt: defmt::Formatter) { | ||
| 120 | unsafe { | ||
| 121 | defmt::write!( | ||
| 122 | fmt, | ||
| 123 | "MacAddress {{ short: {}, extended: {} }}", | ||
| 124 | self.short, | ||
| 125 | self.extended | ||
| 126 | ) | ||
| 127 | } | ||
| 128 | } | ||
| 116 | } | 129 | } |
| 117 | 130 | ||
| 118 | impl Default for MacAddress { | 131 | impl Default for MacAddress { |
| 119 | fn default() -> Self { | 132 | fn default() -> Self { |
| 120 | Self::Short([0, 0]) | 133 | Self { short: [0, 0] } |
| 121 | } | 134 | } |
| 122 | } | 135 | } |
| 123 | 136 | ||
| 137 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 124 | pub struct GtsCharacteristics { | 138 | pub struct GtsCharacteristics { |
| 125 | pub fields: u8, | 139 | pub fields: u8, |
| 126 | } | 140 | } |
| @@ -163,12 +177,14 @@ impl TryFrom<&[u8]> for PanDescriptor { | |||
| 163 | 177 | ||
| 164 | let coord_addr_mode = AddressMode::try_from(buf[2])?; | 178 | let coord_addr_mode = AddressMode::try_from(buf[2])?; |
| 165 | let coord_addr = match coord_addr_mode { | 179 | let coord_addr = match coord_addr_mode { |
| 166 | AddressMode::NoAddress => MacAddress::Short([0, 0]), | 180 | AddressMode::NoAddress => MacAddress { short: [0, 0] }, |
| 167 | AddressMode::Reserved => MacAddress::Short([0, 0]), | 181 | AddressMode::Reserved => MacAddress { short: [0, 0] }, |
| 168 | AddressMode::Short => MacAddress::Short([buf[4], buf[5]]), | 182 | AddressMode::Short => MacAddress { |
| 169 | AddressMode::Extended => { | 183 | short: [buf[4], buf[5]], |
| 170 | MacAddress::Extended([buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]]) | 184 | }, |
| 171 | } | 185 | AddressMode::Extended => MacAddress { |
| 186 | extended: [buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]], | ||
| 187 | }, | ||
| 172 | }; | 188 | }; |
| 173 | 189 | ||
| 174 | Ok(Self { | 190 | Ok(Self { |
| @@ -255,7 +271,7 @@ defmt::bitflags! { | |||
| 255 | 271 | ||
| 256 | numeric_enum! { | 272 | numeric_enum! { |
| 257 | #[repr(u8)] | 273 | #[repr(u8)] |
| 258 | #[derive(Default)] | 274 | #[derive(Default, Clone, Copy)] |
| 259 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 275 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 260 | pub enum KeyIdMode { | 276 | pub enum KeyIdMode { |
| 261 | #[default] | 277 | #[default] |
| @@ -285,6 +301,7 @@ numeric_enum! { | |||
| 285 | 301 | ||
| 286 | numeric_enum! { | 302 | numeric_enum! { |
| 287 | #[repr(u8)] | 303 | #[repr(u8)] |
| 304 | #[derive(Clone, Copy)] | ||
| 288 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 305 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 289 | pub enum DisassociationReason { | 306 | pub enum DisassociationReason { |
| 290 | /// The coordinator wishes the device to leave the PAN. | 307 | /// The coordinator wishes the device to leave the PAN. |
| @@ -296,7 +313,7 @@ numeric_enum! { | |||
| 296 | 313 | ||
| 297 | numeric_enum! { | 314 | numeric_enum! { |
| 298 | #[repr(u8)] | 315 | #[repr(u8)] |
| 299 | #[derive(Default)] | 316 | #[derive(Default, Clone, Copy)] |
| 300 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 317 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 301 | pub enum SecurityLevel { | 318 | pub enum SecurityLevel { |
| 302 | /// MAC Unsecured Mode Security | 319 | /// MAC Unsecured Mode Security |
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index 18b29362b..4e2578a21 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs | |||
| @@ -66,7 +66,7 @@ async fn main(spawner: Spawner) { | |||
| 66 | 66 | ||
| 67 | info!("resetting"); | 67 | info!("resetting"); |
| 68 | mbox.mac_subsystem | 68 | mbox.mac_subsystem |
| 69 | .send_command(ResetRequest { set_default_pib: true }) | 69 | .send_command(&ResetRequest { set_default_pib: true }) |
| 70 | .await | 70 | .await |
| 71 | .unwrap(); | 71 | .unwrap(); |
| 72 | let evt = mbox.mac_subsystem.read().await; | 72 | let evt = mbox.mac_subsystem.read().await; |
| @@ -75,7 +75,7 @@ async fn main(spawner: Spawner) { | |||
| 75 | info!("setting extended address"); | 75 | info!("setting extended address"); |
| 76 | let extended_address: u64 = 0xACDE480000000001; | 76 | let extended_address: u64 = 0xACDE480000000001; |
| 77 | mbox.mac_subsystem | 77 | mbox.mac_subsystem |
| 78 | .send_command(SetRequest { | 78 | .send_command(&SetRequest { |
| 79 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | 79 | pib_attribute_ptr: &extended_address as *const _ as *const u8, |
| 80 | pib_attribute: PibId::ExtendedAddress, | 80 | pib_attribute: PibId::ExtendedAddress, |
| 81 | }) | 81 | }) |
| @@ -87,7 +87,7 @@ async fn main(spawner: Spawner) { | |||
| 87 | info!("setting short address"); | 87 | info!("setting short address"); |
| 88 | let short_address: u16 = 0x1122; | 88 | let short_address: u16 = 0x1122; |
| 89 | mbox.mac_subsystem | 89 | mbox.mac_subsystem |
| 90 | .send_command(SetRequest { | 90 | .send_command(&SetRequest { |
| 91 | pib_attribute_ptr: &short_address as *const _ as *const u8, | 91 | pib_attribute_ptr: &short_address as *const _ as *const u8, |
| 92 | pib_attribute: PibId::ShortAddress, | 92 | pib_attribute: PibId::ShortAddress, |
| 93 | }) | 93 | }) |
| @@ -99,7 +99,7 @@ async fn main(spawner: Spawner) { | |||
| 99 | info!("setting association permit"); | 99 | info!("setting association permit"); |
| 100 | let association_permit: bool = true; | 100 | let association_permit: bool = true; |
| 101 | mbox.mac_subsystem | 101 | mbox.mac_subsystem |
| 102 | .send_command(SetRequest { | 102 | .send_command(&SetRequest { |
| 103 | pib_attribute_ptr: &association_permit as *const _ as *const u8, | 103 | pib_attribute_ptr: &association_permit as *const _ as *const u8, |
| 104 | pib_attribute: PibId::AssociationPermit, | 104 | pib_attribute: PibId::AssociationPermit, |
| 105 | }) | 105 | }) |
| @@ -111,7 +111,7 @@ async fn main(spawner: Spawner) { | |||
| 111 | info!("setting TX power"); | 111 | info!("setting TX power"); |
| 112 | let transmit_power: i8 = 2; | 112 | let transmit_power: i8 = 2; |
| 113 | mbox.mac_subsystem | 113 | mbox.mac_subsystem |
| 114 | .send_command(SetRequest { | 114 | .send_command(&SetRequest { |
| 115 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, | 115 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, |
| 116 | pib_attribute: PibId::TransmitPower, | 116 | pib_attribute: PibId::TransmitPower, |
| 117 | }) | 117 | }) |
| @@ -122,7 +122,8 @@ async fn main(spawner: Spawner) { | |||
| 122 | 122 | ||
| 123 | info!("starting FFD device"); | 123 | info!("starting FFD device"); |
| 124 | mbox.mac_subsystem | 124 | mbox.mac_subsystem |
| 125 | .send_command(StartRequest { | 125 | .send_command(&StartRequest { |
| 126 | pan_id: [0xAA, 0x1A], | ||
| 126 | channel_number: MacChannel::Channel16, | 127 | channel_number: MacChannel::Channel16, |
| 127 | beacon_order: 0x0F, | 128 | beacon_order: 0x0F, |
| 128 | superframe_order: 0x0F, | 129 | superframe_order: 0x0F, |
| @@ -138,7 +139,7 @@ async fn main(spawner: Spawner) { | |||
| 138 | info!("setting RX on when idle"); | 139 | info!("setting RX on when idle"); |
| 139 | let rx_on_while_idle: bool = true; | 140 | let rx_on_while_idle: bool = true; |
| 140 | mbox.mac_subsystem | 141 | mbox.mac_subsystem |
| 141 | .send_command(SetRequest { | 142 | .send_command(&SetRequest { |
| 142 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, | 143 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, |
| 143 | pib_attribute: PibId::RxOnWhenIdle, | 144 | pib_attribute: PibId::RxOnWhenIdle, |
| 144 | }) | 145 | }) |
| @@ -151,7 +152,4 @@ async fn main(spawner: Spawner) { | |||
| 151 | let evt = mbox.mac_subsystem.read().await; | 152 | let evt = mbox.mac_subsystem.read().await; |
| 152 | defmt::info!("{:#x}", evt); | 153 | defmt::info!("{:#x}", evt); |
| 153 | } | 154 | } |
| 154 | |||
| 155 | info!("Test OK"); | ||
| 156 | cortex_m::asm::bkpt(); | ||
| 157 | } | 155 | } |
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs index 8042a3704..e5f8d54c9 100644 --- a/examples/stm32wb/src/bin/mac_rfd.rs +++ b/examples/stm32wb/src/bin/mac_rfd.rs | |||
| @@ -6,7 +6,8 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::bind_interrupts; | 7 | use embassy_stm32::bind_interrupts; |
| 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 9 | use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, ResetRequest, SetRequest, StartRequest}; | 9 | use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest}; |
| 10 | use embassy_stm32_wpan::sub::mac::event::MacEvent; | ||
| 10 | use embassy_stm32_wpan::sub::mac::typedefs::{ | 11 | use embassy_stm32_wpan::sub::mac::typedefs::{ |
| 11 | AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel, | 12 | AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel, |
| 12 | }; | 13 | }; |
| @@ -67,52 +68,75 @@ async fn main(spawner: Spawner) { | |||
| 67 | info!("initialized mac: {}", result); | 68 | info!("initialized mac: {}", result); |
| 68 | 69 | ||
| 69 | info!("resetting"); | 70 | info!("resetting"); |
| 70 | let response = mbox | 71 | mbox.mac_subsystem |
| 71 | .mac_subsystem | 72 | .send_command(&ResetRequest { set_default_pib: true }) |
| 72 | .send_command(ResetRequest { set_default_pib: true }) | 73 | .await |
| 73 | .await; | 74 | .unwrap(); |
| 74 | info!("{}", response); | 75 | let evt = mbox.mac_subsystem.read().await; |
| 76 | info!("{:#x}", evt); | ||
| 75 | 77 | ||
| 76 | info!("setting extended address"); | 78 | info!("setting extended address"); |
| 77 | let extended_address: u64 = 0xACDE480000000002; | 79 | let extended_address: u64 = 0xACDE480000000002; |
| 78 | let response = mbox | 80 | mbox.mac_subsystem |
| 79 | .mac_subsystem | 81 | .send_command(&SetRequest { |
| 80 | .send_command(SetRequest { | ||
| 81 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | 82 | pib_attribute_ptr: &extended_address as *const _ as *const u8, |
| 82 | pib_attribute: PibId::ExtendedAddress, | 83 | pib_attribute: PibId::ExtendedAddress, |
| 83 | }) | 84 | }) |
| 84 | .await; | 85 | .await |
| 85 | info!("{}", response); | 86 | .unwrap(); |
| 87 | let evt = mbox.mac_subsystem.read().await; | ||
| 88 | info!("{:#x}", evt); | ||
| 89 | |||
| 90 | info!("getting extended address"); | ||
| 91 | mbox.mac_subsystem | ||
| 92 | .send_command(&GetRequest { | ||
| 93 | pib_attribute: PibId::ExtendedAddress, | ||
| 94 | }) | ||
| 95 | .await | ||
| 96 | .unwrap(); | ||
| 97 | let evt = mbox.mac_subsystem.read().await; | ||
| 98 | info!("{:#x}", evt); | ||
| 99 | |||
| 100 | if let Ok(MacEvent::MlmeGetCnf(evt)) = evt { | ||
| 101 | if evt.pib_attribute_value_len == 8 { | ||
| 102 | let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; | ||
| 103 | |||
| 104 | info!("value {:#x}", value) | ||
| 105 | } | ||
| 106 | } | ||
| 86 | 107 | ||
| 87 | info!("assocation request"); | 108 | info!("assocation request"); |
| 88 | let response = mbox | 109 | let a = AssociateRequest { |
| 89 | .mac_subsystem | 110 | channel_number: MacChannel::Channel16, |
| 90 | .send_command(AssociateRequest { | 111 | channel_page: 0, |
| 91 | channel_number: MacChannel::Channel16, | 112 | coord_addr_mode: AddressMode::Short, |
| 92 | channel_page: 0, | 113 | coord_address: MacAddress { short: [34, 17] }, |
| 93 | coord_addr_mode: AddressMode::Short, | 114 | capability_information: Capabilities::ALLOCATE_ADDRESS, |
| 94 | coord_address: MacAddress::Short([0x22, 0x11]), | 115 | coord_pan_id: [0xAA, 0x1A], |
| 95 | capability_information: Capabilities::ALLOCATE_ADDRESS, | 116 | security_level: SecurityLevel::Unsecure, |
| 96 | coord_pan_id: [0xAA, 0x1A], | 117 | key_id_mode: KeyIdMode::Implicite, |
| 97 | security_level: SecurityLevel::Unsecure, | 118 | key_source: [0; 8], |
| 98 | key_id_mode: KeyIdMode::Implicite, | 119 | key_index: 152, |
| 99 | key_source: [0; 8], | 120 | }; |
| 100 | key_index: 0, | 121 | info!("{}", a); |
| 101 | }) | 122 | mbox.mac_subsystem.send_command(&a).await.unwrap(); |
| 102 | .await; | 123 | let evt = mbox.mac_subsystem.read().await; |
| 103 | info!("{}", response); | 124 | info!("{:#x}", evt); |
| 104 | 125 | ||
| 105 | info!("setting short address"); | 126 | info!("setting short address"); |
| 106 | let short: u64 = 0xACDE480000000002; | 127 | let short: u64 = 0xACDE480000000002; |
| 107 | let response = mbox | 128 | mbox.mac_subsystem |
| 108 | .mac_subsystem | 129 | .send_command(&SetRequest { |
| 109 | .send_command(SetRequest { | ||
| 110 | pib_attribute_ptr: &short as *const _ as *const u8, | 130 | pib_attribute_ptr: &short as *const _ as *const u8, |
| 111 | pib_attribute: PibId::ShortAddress, | 131 | pib_attribute: PibId::ShortAddress, |
| 112 | }) | 132 | }) |
| 113 | .await; | 133 | .await |
| 114 | info!("{}", response); | 134 | .unwrap(); |
| 115 | 135 | let evt = mbox.mac_subsystem.read().await; | |
| 116 | info!("Test OK"); | 136 | info!("{:#x}", evt); |
| 117 | cortex_m::asm::bkpt(); | 137 | |
| 138 | loop { | ||
| 139 | let evt = mbox.mac_subsystem.read().await; | ||
| 140 | info!("{:#x}", evt); | ||
| 141 | } | ||
| 118 | } | 142 | } |
