aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32-wpan/src/sub/mac/commands.rs17
-rw-r--r--embassy-stm32-wpan/src/sub/mac/consts.rs3
-rw-r--r--embassy-stm32-wpan/src/sub/mac/mod.rs3
-rw-r--r--embassy-stm32-wpan/src/sub/mac/responses.rs168
-rw-r--r--embassy-stm32-wpan/src/sub/mac/typedefs.rs27
5 files changed, 217 insertions, 1 deletions
diff --git a/embassy-stm32-wpan/src/sub/mac/commands.rs b/embassy-stm32-wpan/src/sub/mac/commands.rs
index 3c234a3ce..4965a46eb 100644
--- a/embassy-stm32-wpan/src/sub/mac/commands.rs
+++ b/embassy-stm32-wpan/src/sub/mac/commands.rs
@@ -11,6 +11,7 @@ pub trait MacCommand {
11} 11}
12 12
13/// MLME ASSOCIATE Request used to request an association 13/// MLME ASSOCIATE Request used to request an association
14#[repr(C)]
14pub struct AssociateRequest { 15pub struct AssociateRequest {
15 /// the logical channel on which to attempt association 16 /// the logical channel on which to attempt association
16 pub channel_number: u8, 17 pub channel_number: u8,
@@ -40,6 +41,7 @@ impl MacCommand for AssociateRequest {
40} 41}
41 42
42/// MLME DISASSOCIATE Request sed to request a disassociation 43/// MLME DISASSOCIATE Request sed to request a disassociation
44#[repr(C)]
43pub struct DisassociateRequest { 45pub struct DisassociateRequest {
44 /// device addressing mode used 46 /// device addressing mode used
45 pub device_addr_mode: AddressMode, 47 pub device_addr_mode: AddressMode,
@@ -67,6 +69,7 @@ impl MacCommand for DisassociateRequest {
67} 69}
68 70
69/// MLME GET Request used to request a PIB value 71/// MLME GET Request used to request a PIB value
72#[repr(C)]
70pub struct GetRequest { 73pub struct GetRequest {
71 /// the name of the PIB attribute to read 74 /// the name of the PIB attribute to read
72 pub pib_attribute: PibId, 75 pub pib_attribute: PibId,
@@ -78,6 +81,7 @@ impl MacCommand for GetRequest {
78} 81}
79 82
80/// MLME GTS Request used to request and maintain GTSs 83/// MLME GTS Request used to request and maintain GTSs
84#[repr(C)]
81pub struct GtsRequest { 85pub struct GtsRequest {
82 /// the characteristics of the GTS 86 /// the characteristics of the GTS
83 pub characteristics: GtsCharacteristics, 87 pub characteristics: GtsCharacteristics,
@@ -96,6 +100,7 @@ impl MacCommand for GtsRequest {
96 const SIZE: usize = 12; 100 const SIZE: usize = 12;
97} 101}
98 102
103#[repr(C)]
99pub struct ResetRequest { 104pub struct ResetRequest {
100 /// MAC PIB attributes are set to their default values or not during reset 105 /// MAC PIB attributes are set to their default values or not during reset
101 pub set_default_pib: bool, 106 pub set_default_pib: bool,
@@ -108,6 +113,7 @@ impl MacCommand for ResetRequest {
108 113
109/// MLME RX ENABLE Request used to request that the receiver is either enabled 114/// MLME RX ENABLE Request used to request that the receiver is either enabled
110/// for a finite period of time or disabled 115/// for a finite period of time or disabled
116#[repr(C)]
111pub struct RxEnableRequest { 117pub struct RxEnableRequest {
112 /// the request operation can be deferred or not 118 /// the request operation can be deferred or not
113 pub defer_permit: bool, 119 pub defer_permit: bool,
@@ -138,6 +144,7 @@ impl MacCommand for RxEnableRequest {
138} 144}
139 145
140/// MLME SCAN Request used to initiate a channel scan over a given list of channels 146/// MLME SCAN Request used to initiate a channel scan over a given list of channels
147#[repr(C)]
141pub struct ScanRequest { 148pub struct ScanRequest {
142 /// the type of scan to be performed 149 /// the type of scan to be performed
143 pub scan_type: u8, 150 pub scan_type: u8,
@@ -179,6 +186,7 @@ impl MacCommand for SetRequest {
179/// MLME START Request used by the FFDs to intiate a new PAN or to begin using a new superframe 186/// MLME START Request used by the FFDs to intiate a new PAN or to begin using a new superframe
180/// configuration 187/// configuration
181#[derive(Default)] 188#[derive(Default)]
189#[repr(C)]
182pub struct StartRequest { 190pub struct StartRequest {
183 /// PAN indentifier to used by the device 191 /// PAN indentifier to used by the device
184 pub pan_id: [u8; 2], 192 pub pan_id: [u8; 2],
@@ -221,6 +229,7 @@ impl MacCommand for StartRequest {
221 229
222/// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if 230/// MLME SYNC Request used to synchronize with the coordinator by acquiring and, if
223/// specified, tracking its beacons 231/// specified, tracking its beacons
232#[repr(C)]
224pub struct SyncRequest { 233pub struct SyncRequest {
225 /// the channel number on which to attempt coordinator synchronization 234 /// the channel number on which to attempt coordinator synchronization
226 pub channel_number: u8, 235 pub channel_number: u8,
@@ -239,6 +248,7 @@ impl MacCommand for SyncRequest {
239} 248}
240 249
241/// MLME POLL Request propmts the device to request data from the coordinator 250/// MLME POLL Request propmts the device to request data from the coordinator
251#[repr(C)]
242pub struct PollRequest { 252pub struct PollRequest {
243 /// addressing mode of the coordinator 253 /// addressing mode of the coordinator
244 pub coord_addr_mode: AddressMode, 254 pub coord_addr_mode: AddressMode,
@@ -263,6 +273,7 @@ impl MacCommand for PollRequest {
263 273
264/// MLME DPS Request allows the next higher layer to request that the PHY utilize a 274/// MLME DPS Request allows the next higher layer to request that the PHY utilize a
265/// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration 275/// given pair of preamble codes for a single use pending expiration of the DPSIndexDuration
276#[repr(C)]
266pub struct DpsRequest { 277pub struct DpsRequest {
267 /// the index value for the transmitter 278 /// the index value for the transmitter
268 tx_dps_index: u8, 279 tx_dps_index: u8,
@@ -280,6 +291,7 @@ impl MacCommand for DpsRequest {
280 291
281/// MLME SOUNDING request primitive which is used by the next higher layer to request that 292/// MLME SOUNDING request primitive which is used by the next higher layer to request that
282/// the PHY respond with channel sounding information 293/// the PHY respond with channel sounding information
294#[repr(C)]
283pub struct SoundingRequest; 295pub struct SoundingRequest;
284 296
285impl MacCommand for SoundingRequest { 297impl MacCommand for SoundingRequest {
@@ -289,6 +301,7 @@ impl MacCommand for SoundingRequest {
289 301
290/// MLME CALIBRATE request primitive which used to obtain the results of a ranging 302/// MLME CALIBRATE request primitive which used to obtain the results of a ranging
291/// calibration request from an RDEV 303/// calibration request from an RDEV
304#[repr(C)]
292pub struct CalibrateRequest; 305pub struct CalibrateRequest;
293 306
294impl MacCommand for CalibrateRequest { 307impl MacCommand for CalibrateRequest {
@@ -297,6 +310,7 @@ impl MacCommand for CalibrateRequest {
297} 310}
298 311
299/// MCPS DATA Request used for MAC data related requests from the application 312/// MCPS DATA Request used for MAC data related requests from the application
313#[repr(C)]
300pub struct DataRequest { 314pub struct DataRequest {
301 /// the handle assocated with the MSDU to be transmitted 315 /// the handle assocated with the MSDU to be transmitted
302 pub msdu_ptr: *const u8, 316 pub msdu_ptr: *const u8,
@@ -344,6 +358,7 @@ impl MacCommand for DataRequest {
344} 358}
345 359
346/// for MCPS PURGE Request used to purge an MSDU from the transaction queue 360/// for MCPS PURGE Request used to purge an MSDU from the transaction queue
361#[repr(C)]
347pub struct PurgeRequest { 362pub struct PurgeRequest {
348 /// the handle associated with the MSDU to be purged from the transaction 363 /// the handle associated with the MSDU to be purged from the transaction
349 /// queue 364 /// queue
@@ -356,6 +371,7 @@ impl MacCommand for PurgeRequest {
356} 371}
357 372
358/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication 373/// MLME ASSOCIATE Response used to initiate a response to an MLME-ASSOCIATE.indication
374#[repr(C)]
359pub struct AssociateResponse { 375pub struct AssociateResponse {
360 /// extended address of the device requesting association 376 /// extended address of the device requesting association
361 pub device_address: [u8; 8], 377 pub device_address: [u8; 8],
@@ -380,6 +396,7 @@ impl MacCommand for AssociateResponse {
380} 396}
381 397
382/// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication 398/// MLME ORPHAN Response used to respond to the MLME ORPHAN Indication
399#[repr(C)]
383pub struct OrphanResponse { 400pub struct OrphanResponse {
384 /// extended address of the orphaned device 401 /// extended address of the orphaned device
385 pub orphan_address: [u8; 8], 402 pub orphan_address: [u8; 8],
diff --git a/embassy-stm32-wpan/src/sub/mac/consts.rs b/embassy-stm32-wpan/src/sub/mac/consts.rs
new file mode 100644
index 000000000..dfbbadc67
--- /dev/null
+++ b/embassy-stm32-wpan/src/sub/mac/consts.rs
@@ -0,0 +1,3 @@
1pub const MAX_ED_SCAN_RESULTS_SUPPORTED: usize = 16;
2pub const MAX_PAN_DESC_SUPPORTED: usize = 6;
3pub const MAX_SOUNDING_LIST_SUPPORTED: usize = 6;
diff --git a/embassy-stm32-wpan/src/sub/mac/mod.rs b/embassy-stm32-wpan/src/sub/mac/mod.rs
index 8e117d978..6a3a057f4 100644
--- a/embassy-stm32-wpan/src/sub/mac/mod.rs
+++ b/embassy-stm32-wpan/src/sub/mac/mod.rs
@@ -16,8 +16,9 @@ use crate::evt::{EvtBox, EvtPacket};
16use crate::tables::{MAC_802_15_4_CMD_BUFFER, MAC_802_15_4_NOTIF_RSP_EVT_BUFFER}; 16use crate::tables::{MAC_802_15_4_CMD_BUFFER, MAC_802_15_4_NOTIF_RSP_EVT_BUFFER};
17use crate::{channels, evt}; 17use crate::{channels, evt};
18 18
19mod opcodes;
20pub mod commands; 19pub mod commands;
20mod consts;
21mod opcodes;
21pub mod responses; 22pub mod responses;
22pub mod typedefs; 23pub mod typedefs;
23 24
diff --git a/embassy-stm32-wpan/src/sub/mac/responses.rs b/embassy-stm32-wpan/src/sub/mac/responses.rs
index e69de29bb..7b240f370 100644
--- a/embassy-stm32-wpan/src/sub/mac/responses.rs
+++ b/embassy-stm32-wpan/src/sub/mac/responses.rs
@@ -0,0 +1,168 @@
1use super::consts::{MAX_ED_SCAN_RESULTS_SUPPORTED, MAX_PAN_DESC_SUPPORTED, MAX_SOUNDING_LIST_SUPPORTED};
2use super::typedefs::{AddressMode, MacAddress, PanDescriptor};
3
4pub trait MacResponse {
5 const SIZE: usize;
6
7 fn parse(buf: &[u8]) -> Self;
8}
9
10/// MLME ASSOCIATE Confirm used to inform of the initiating device whether
11/// its request to associate was successful or unsuccessful
12pub struct AssociateConfirm {
13 /// short address allocated by the coordinator on successful association
14 pub assoc_short_address: [u8; 2],
15 /// status of the association request
16 pub status: u8,
17 /// security level to be used
18 pub security_level: u8,
19 /// the originator of the key to be used
20 pub key_source: [u8; 8],
21 /// the mode used to identify the key to be used
22 pub key_id_mode: u8,
23 /// the index of the key to be used
24 pub key_index: u8,
25}
26
27/// MLME DISASSOCIATE Confirm used to send disassociation Confirmation to the application.
28pub struct DisassociateConfirm {
29 /// status of the disassociation attempt
30 pub status: u8,
31 /// device addressing mode used
32 pub device_addr_mode: AddressMode,
33 /// the identifier of the PAN of the device
34 pub device_pan_id: [u8; 2],
35 /// device address
36 pub device_address: MacAddress,
37}
38
39/// MLME GET Confirm which requests information about a given PIB attribute
40pub struct GetConfirm {
41 /// The pointer to the value of the PIB attribute attempted to read
42 pub pib_attribute_value_ptr: *const u8,
43 /// Status of the GET attempt
44 pub status: u8,
45 /// The name of the PIB attribute attempted to read
46 pub pib_attribute: u8,
47 /// The lenght of the PIB attribute Value return
48 pub pib_attribute_value_len: u8,
49}
50
51/// MLME GTS Confirm which eports the results of a request to allocate a new GTS
52/// or to deallocate an existing GTS
53pub struct GtsConfirm {
54 /// The characteristics of the GTS
55 pub gts_characteristics: u8,
56 /// The status of the GTS reques
57 pub status: u8,
58}
59
60/// MLME RESET Confirm which is used to report the results of the reset operation
61pub struct ResetConfirm {
62 /// The result of the reset operation
63 status: u8,
64}
65
66/// MLME RX ENABLE Confirm which is used to report the results of the attempt
67/// to enable or disable the receiver
68pub struct RxEnableConfirm {
69 /// Result of the request to enable or disable the receiver
70 status: u8,
71}
72
73/// MLME SCAN Confirm which is used to report the result of the channel scan request
74pub struct ScanConfirm {
75 /// Status of the scan request
76 pub status: u8,
77 /// The type of scan performed
78 pub scan_type: u8,
79 /// Channel page on which the scan was performed
80 pub channel_page: u8,
81 /// Channels given in the request which were not scanned
82 pub unscanned_channels: [u8; 4],
83 /// Number of elements returned in the appropriate result lists
84 pub result_list_size: u8,
85 /// List of energy measurements
86 pub energy_detect_list: [u8; MAX_ED_SCAN_RESULTS_SUPPORTED],
87 /// List of PAN descriptors
88 pub pan_descriptor_list: [PanDescriptor; MAX_PAN_DESC_SUPPORTED],
89 /// Categorization of energy detected in channel
90 pub detected_category: u8,
91 /// For UWB PHYs, the list of energy measurements taken
92 pub uwb_energy_detect_list: [u8; MAX_ED_SCAN_RESULTS_SUPPORTED],
93}
94
95/// MLME SET Confirm which reports the result of an attempt to write a value to a PIB attribute
96pub struct SetConfirm {
97 /// The result of the set operation
98 pub status: u8,
99 /// The name of the PIB attribute that was written
100 pub pin_attribute: u8,
101}
102
103/// MLME START Confirm which is used to report the results of the attempt to
104/// start using a new superframe configuration
105pub struct StartConfirm {
106 /// Result of the attempt to start using an updated superframe configuration
107 pub status: u8,
108}
109
110/// MLME POLL Confirm which is used to report the result of a request to poll the coordinator for data
111pub struct PollConfirm {
112 /// The status of the data request
113 pub status: u8,
114}
115
116/// MLME SOUNDING Confirm which reports the result of a request to the PHY to provide
117/// channel sounding information
118pub struct SoundingConfirm {
119 /// Results of the sounding measurement
120 sounding_list: [u8; MAX_SOUNDING_LIST_SUPPORTED],
121}
122
123/// MLME CALIBRATE Confirm which reports the result of a request to the PHY
124/// to provide internal propagation path information
125pub struct CalibrateConfirm {
126 /// The status of the attempt to return sounding data
127 pub status: u8,
128 /// A count of the propagation time from the ranging counter
129 /// to the transmit antenna
130 pub cal_tx_rmaker_offset: u32,
131 /// A count of the propagation time from the receive antenna
132 /// to the ranging counter
133 pub cal_rx_rmaker_offset: u32,
134}
135
136/// MCPS DATA Confirm which will be used for reporting the results of
137/// MAC data related requests from the application
138pub struct DataConfirm {
139 /// The handle associated with the MSDU being confirmed
140 pub msdu_handle: u8,
141 /// The time, in symbols, at which the data were transmitted
142 pub a_time_stamp: [u8; 4],
143 /// ranging status
144 pub ranging_received: u8,
145 /// The status of the last MSDU transmission
146 pub status: u8,
147 /// time units corresponding to an RMARKER at the antenna at
148 /// the beginning of a ranging exchange
149 pub ranging_counter_start: u32,
150 /// time units corresponding to an RMARKER at the antenna
151 /// at the end of a ranging exchange
152 pub ranging_counter_stop: u32,
153 /// time units in a message exchange over which the tracking offset was measured
154 pub ranging_tracking_interval: u32,
155 /// time units slipped or advanced by the radio tracking system
156 pub ranging_offset: u32,
157 /// The FoM characterizing the ranging measurement
158 pub ranging_fom: u8,
159}
160
161/// MCPS PURGE Confirm which will be used by the MAC to notify the application of
162/// the status of its request to purge an MSDU from the transaction queue
163pub struct PurgeConfirm {
164 /// Handle associated with the MSDU requested to be purged from the transaction queue
165 pub msdu_handle: u8,
166 /// The status of the request
167 pub status: u8,
168}
diff --git a/embassy-stm32-wpan/src/sub/mac/typedefs.rs b/embassy-stm32-wpan/src/sub/mac/typedefs.rs
index d43d6e0cf..7f0dd75c0 100644
--- a/embassy-stm32-wpan/src/sub/mac/typedefs.rs
+++ b/embassy-stm32-wpan/src/sub/mac/typedefs.rs
@@ -95,3 +95,30 @@ pub union MacAddress {
95pub struct GtsCharacteristics { 95pub struct GtsCharacteristics {
96 pub fields: u8, 96 pub fields: u8,
97} 97}
98
99/// MAC PAN Descriptor which contains the network details of the device from
100/// which the beacon is received
101pub struct PanDescriptor {
102 /// PAN identifier of the coordinator
103 pub a_coord_pan_id: [u8; 2],
104 /// Coordinator addressing mode
105 pub coord_addr_mode: AddressMode,
106 /// The current logical channel occupied by the network
107 pub logical_channel: u8,
108 /// Coordinator address
109 pub coord_addr: MacAddress,
110 /// The current channel page occupied by the network
111 pub channel_page: u8,
112 /// PAN coordinator is accepting GTS requests or not
113 pub gts_permit: bool,
114 /// Superframe specification as specified in the received beacon frame
115 pub a_superframe_spec: [u8; 2],
116 /// The time at which the beacon frame was received, in symbols
117 pub a_time_stamp: [u8; 4],
118 /// The LQI at which the network beacon was received
119 pub link_quality: u8,
120 /// Security level purportedly used by the received beacon frame
121 pub security_level: u8,
122 /// Byte Stuffing to keep 32 bit alignment
123 pub a_stuffing: [u8; 2],
124}