aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wb55/mac/indications.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32-wpan/src/wb55/mac/indications.rs')
-rw-r--r--embassy-stm32-wpan/src/wb55/mac/indications.rs300
1 files changed, 300 insertions, 0 deletions
diff --git a/embassy-stm32-wpan/src/wb55/mac/indications.rs b/embassy-stm32-wpan/src/wb55/mac/indications.rs
new file mode 100644
index 000000000..5673514c9
--- /dev/null
+++ b/embassy-stm32-wpan/src/wb55/mac/indications.rs
@@ -0,0 +1,300 @@
1use core::slice;
2
3use smoltcp::wire::Ieee802154FrameType;
4use smoltcp::wire::ieee802154::Frame;
5
6use super::consts::MAX_PENDING_ADDRESS;
7use super::event::ParseableMacEvent;
8use super::typedefs::{
9 AddressMode, Capabilities, DisassociationReason, KeyIdMode, MacAddress, MacChannel, MacStatus, PanDescriptor,
10 PanId, SecurityLevel,
11};
12use crate::mac::typedefs::MacAddressAndMode;
13
14/// MLME ASSOCIATE Indication which will be used by the MAC
15/// to indicate the reception of an association request command
16#[repr(C)]
17#[derive(Debug)]
18#[cfg_attr(feature = "defmt", derive(defmt::Format))]
19pub struct AssociateIndication {
20 /// Extended address of the device requesting association
21 pub device_address: [u8; 8],
22 /// Operational capabilities of the device requesting association
23 pub capability_information: Capabilities,
24 /// Security level purportedly used by the received MAC command frame
25 pub security_level: SecurityLevel,
26 /// The mode used to identify the key used by the originator of frame
27 pub key_id_mode: KeyIdMode,
28 /// Index of the key used by the originator of the received frame
29 pub key_index: u8,
30 /// The originator of the key used by the originator of the received frame
31 pub key_source: [u8; 8],
32}
33
34impl ParseableMacEvent for AssociateIndication {}
35
36/// MLME DISASSOCIATE indication which will be used to send
37/// disassociation indication to the application.
38#[repr(C)]
39#[derive(Debug)]
40#[cfg_attr(feature = "defmt", derive(defmt::Format))]
41pub struct DisassociateIndication {
42 /// Extended address of the device requesting association
43 pub device_address: [u8; 8],
44 /// The reason for the disassociation
45 pub disassociation_reason: DisassociationReason,
46 /// The security level to be used
47 pub security_level: SecurityLevel,
48 /// The mode used to identify the key to be used
49 pub key_id_mode: KeyIdMode,
50 /// The index of the key to be used
51 pub key_index: u8,
52 /// The originator of the key to be used
53 pub key_source: [u8; 8],
54}
55
56impl ParseableMacEvent for DisassociateIndication {}
57
58/// MLME BEACON NOTIIFY Indication which is used to send parameters contained
59/// within a beacon frame received by the MAC to the application
60#[repr(C)]
61#[derive(Debug)]
62#[cfg_attr(feature = "defmt", derive(defmt::Format))]
63pub struct BeaconNotifyIndication {
64 /// he set of octets comprising the beacon payload to be transferred
65 /// from the MAC sublayer entity to the next higher layer
66 pub sdu_ptr: *const u8,
67 /// The PAN Descriptor for the received beacon
68 pub pan_descriptor: PanDescriptor,
69 /// The list of addresses of the devices
70 pub addr_list: [MacAddress; MAX_PENDING_ADDRESS],
71 /// Beacon Sequence Number
72 pub bsn: u8,
73 /// The beacon pending address specification
74 pub pend_addr_spec: u8,
75 /// Number of octets contained in the beacon payload of the beacon frame
76 pub sdu_length: u8,
77}
78
79impl ParseableMacEvent for BeaconNotifyIndication {}
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
97/// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status
98#[repr(C)]
99#[derive(Debug)]
100#[cfg_attr(feature = "defmt", derive(defmt::Format))]
101pub struct CommStatusIndication {
102 /// The 16-bit PAN identifier of the device from which the frame
103 /// was received or to which the frame was being sent
104 pub pan_id: PanId,
105 /// Source addressing mode
106 pub src_addr_mode: AddressMode,
107 /// Destination addressing mode
108 pub dst_addr_mode: AddressMode,
109 /// Source address
110 pub src_address: MacAddress,
111 /// Destination address
112 pub dst_address: MacAddress,
113 /// The communications status
114 pub status: MacStatus,
115 /// Security level to be used
116 pub security_level: SecurityLevel,
117 /// Mode used to identify the key to be used
118 pub key_id_mode: KeyIdMode,
119 /// Index of the key to be used
120 pub key_index: u8,
121 /// Originator of the key to be used
122 pub key_source: [u8; 8],
123}
124
125impl ParseableMacEvent for CommStatusIndication {}
126
127/// MLME GTS Indication indicates that a GTS has been allocated or that a
128/// previously allocated GTS has been deallocated
129#[repr(C)]
130#[derive(Debug)]
131#[cfg_attr(feature = "defmt", derive(defmt::Format))]
132pub struct GtsIndication {
133 /// The short address of the device that has been allocated or deallocated a GTS
134 pub device_address: [u8; 2],
135 /// The characteristics of the GTS
136 pub gts_characteristics: u8,
137 /// Security level to be used
138 pub security_level: SecurityLevel,
139 /// Mode used to identify the key to be used
140 pub key_id_mode: KeyIdMode,
141 /// Index of the key to be used
142 pub key_index: u8,
143 /// byte stuffing to keep 32 bit alignment
144 a_stuffing: [u8; 2],
145 /// Originator of the key to be used
146 pub key_source: [u8; 8],
147}
148
149impl ParseableMacEvent for GtsIndication {}
150
151/// MLME ORPHAN Indication which is used by the coordinator to notify the
152/// application of the presence of an orphaned device
153#[repr(C)]
154#[derive(Debug)]
155#[cfg_attr(feature = "defmt", derive(defmt::Format))]
156pub struct OrphanIndication {
157 /// Extended address of the orphaned device
158 pub orphan_address: [u8; 8],
159 /// Originator of the key used by the originator of the received frame
160 pub key_source: [u8; 8],
161 /// Security level purportedly used by the received MAC command frame
162 pub security_level: SecurityLevel,
163 /// Mode used to identify the key used by originator of received frame
164 pub key_id_mode: KeyIdMode,
165 /// Index of the key used by the originator of the received frame
166 pub key_index: u8,
167 /// byte stuffing to keep 32 bit alignment
168 a_stuffing: [u8; 1],
169}
170
171impl ParseableMacEvent for OrphanIndication {}
172
173/// MLME SYNC LOSS Indication which is used by the MAC to indicate the loss
174/// of synchronization with the coordinator
175#[repr(C)]
176#[derive(Debug)]
177#[cfg_attr(feature = "defmt", derive(defmt::Format))]
178pub struct SyncLossIndication {
179 /// The PAN identifier with which the device lost synchronization or to which it was realigned
180 pub pan_id: PanId,
181 /// The reason that synchronization was lost
182 pub loss_reason: u8,
183 /// The logical channel on which the device lost synchronization or to whi
184 pub channel_number: MacChannel,
185 /// The channel page on which the device lost synchronization or to which
186 pub channel_page: u8,
187 /// The security level used by the received MAC frame
188 pub security_level: SecurityLevel,
189 /// Mode used to identify the key used by originator of received frame
190 pub key_id_mode: KeyIdMode,
191 /// Index of the key used by the originator of the received frame
192 pub key_index: u8,
193 /// Originator of the key used by the originator of the received frame
194 pub key_source: [u8; 8],
195}
196
197impl ParseableMacEvent for SyncLossIndication {}
198
199/// MLME DPS Indication which indicates the expiration of the DPSIndexDuration
200/// and the resetting of the DPS values in the PHY
201#[repr(C)]
202#[derive(Debug)]
203#[cfg_attr(feature = "defmt", derive(defmt::Format))]
204pub struct DpsIndication {
205 /// byte stuffing to keep 32 bit alignment
206 a_stuffing: [u8; 4],
207}
208
209impl ParseableMacEvent for DpsIndication {}
210
211#[repr(C)]
212#[derive(Debug)]
213#[cfg_attr(feature = "defmt", derive(defmt::Format))]
214pub struct DataIndication {
215 /// Pointer to the set of octets forming the MSDU being indicated
216 pub msdu_ptr: *const u8,
217 /// Source addressing mode used
218 pub src_addr_mode: AddressMode,
219 /// Source PAN ID
220 pub src_pan_id: PanId,
221 /// Source address
222 pub src_address: MacAddress,
223 /// Destination addressing mode used
224 pub dst_addr_mode: AddressMode,
225 /// Destination PAN ID
226 pub dst_pan_id: PanId,
227 /// Destination address
228 pub dst_address: MacAddress,
229 /// The number of octets contained in the MSDU being indicated
230 pub msdu_length: u8,
231 /// QI value measured during reception of the MPDU
232 pub mpdu_link_quality: u8,
233 /// The data sequence number of the received data frame
234 pub dsn: u8,
235 /// The time, in symbols, at which the data were received
236 pub time_stamp: [u8; 4],
237 /// The security level purportedly used by the received data frame
238 security_level: SecurityLevel,
239 /// Mode used to identify the key used by originator of received frame
240 key_id_mode: KeyIdMode,
241 /// The originator of the key
242 pub key_source: [u8; 8],
243 /// The index of the key
244 pub key_index: u8,
245 /// he pulse repetition value of the received PPDU
246 pub uwbprf: u8,
247 /// The preamble symbol repetitions of the UWB PHY frame
248 pub uwn_preamble_symbol_repetitions: u8,
249 /// Indicates the data rate
250 pub datrate: u8,
251 /// time units corresponding to an RMARKER at the antenna at the end of a ranging exchange,
252 pub ranging_received: u8,
253 pub ranging_counter_start: u32,
254 pub ranging_counter_stop: u32,
255 /// ime units in a message exchange over which the tracking offset was measured
256 pub ranging_tracking_interval: u32,
257 /// time units slipped or advanced by the radio tracking system
258 pub ranging_offset: u32,
259 /// The FoM characterizing the ranging measurement
260 pub ranging_fom: u8,
261 /// The Received Signal Strength Indicator measured
262 pub rssi: u8,
263}
264
265impl ParseableMacEvent for DataIndication {}
266
267impl DataIndication {
268 pub fn payload<'a>(&'a self) -> &'a mut [u8] {
269 unsafe { slice::from_raw_parts_mut(self.msdu_ptr as *mut _, self.msdu_length as usize) }
270 }
271}
272
273pub fn write_frame_from_data_indication<'a, T: AsRef<[u8]> + AsMut<[u8]>>(data: &'a DataIndication, buffer: &'a mut T) {
274 let mut frame = Frame::new_unchecked(buffer);
275
276 frame.set_frame_type(Ieee802154FrameType::Data);
277 frame.set_src_addr(MacAddressAndMode(data.src_address, data.src_addr_mode).into());
278 frame.set_dst_addr(MacAddressAndMode(data.dst_address, data.dst_addr_mode).into());
279 frame.set_dst_pan_id(data.dst_pan_id.into());
280 frame.set_src_pan_id(data.src_pan_id.into());
281 frame.set_sequence_number(data.dsn);
282 frame.set_security_enabled(data.security_level == SecurityLevel::Secured);
283
284 // No way around the copy with the current API
285 frame.payload_mut().unwrap().copy_from_slice(data.payload());
286}
287
288/// MLME POLL Indication which will be used for indicating the Data Request
289/// reception to upper layer as defined in Zigbee r22 - D.8.2
290#[repr(C)]
291#[derive(Debug)]
292#[cfg_attr(feature = "defmt", derive(defmt::Format))]
293pub struct PollIndication {
294 /// addressing mode used
295 pub addr_mode: AddressMode,
296 /// Poll requester address
297 pub request_address: MacAddress,
298}
299
300impl ParseableMacEvent for PollIndication {}