1 /*
2 * Copyright (c) 2016 Intel Corporation.
3 * Copyright (c) 2023 F. Grandel, Zephyr Project
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 /**
9 * @file
10 * @brief Public IEEE 802.15.4 Driver API
11 *
12 * @note All references to the standard in this file cite IEEE 802.15.4-2020.
13 */
14
15 #ifndef ZEPHYR_INCLUDE_NET_IEEE802154_RADIO_H_
16 #define ZEPHYR_INCLUDE_NET_IEEE802154_RADIO_H_
17
18 #include <zephyr/device.h>
19 #include <zephyr/net/net_if.h>
20 #include <zephyr/net/net_pkt.h>
21 #include <zephyr/net/net_time.h>
22 #include <zephyr/net/ieee802154.h>
23 #include <zephyr/net/ieee802154_ie.h>
24 #include <zephyr/sys/util.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31 * @defgroup ieee802154_driver IEEE 802.15.4 Drivers
32 * @since 1.0
33 * @version 0.8.0
34 * @ingroup ieee802154
35 *
36 * @brief IEEE 802.15.4 driver API
37 *
38 * @details This API provides a common representation of vendor-specific
39 * hardware and firmware to the native IEEE 802.15.4 L2 and OpenThread stacks.
40 * **Application developers should never interface directly with this API.** It
41 * is of interest to driver maintainers only.
42 *
43 * The IEEE 802.15.4 driver API consists of two separate parts:
44 * - a basic, mostly PHY-level driver API to be implemented by all drivers,
45 * - several optional MAC-level extension points to offload performance
46 * critical or timing sensitive aspects at MAC level to the driver hardware
47 * or firmware ("hard" MAC).
48 *
49 * Implementing the basic driver API will ensure integration with the native L2
50 * stack as well as basic support for OpenThread. Depending on the hardware,
51 * offloading to vendor-specific hardware or firmware features may be required
52 * to achieve full compliance with the Thread protocol or IEEE 802.15.4
53 * subprotocols (e.g. fast enough ACK packages, precise timing of timed TX/RX in
54 * the TSCH or CSL subprotocols).
55 *
56 * Whether or not MAC-level offloading extension points need to be implemented
57 * is to be decided by individual driver maintainers. Upper layers SHOULD
58 * provide a "soft" MAC fallback whenever possible.
59 *
60 * @note All section, table and figure references are to the IEEE 802.15.4-2020
61 * standard.
62 *
63 * @{
64 */
65
66 /**
67 * @name IEEE 802.15.4-2020, Section 6: MAC functional description
68 * @{
69 */
70
71 /**
72 * The symbol period (and therefore symbol rate) is defined in section 6.1: "Some
73 * of the timing parameters in definition of the MAC are in units of PHY symbols.
74 * For PHYs that have multiple symbol periods, the duration to be used for the
75 * MAC parameters is defined in that PHY clause."
76 *
77 * This is not necessarily the true physical symbol period, so take care to use
78 * this macro only when either the symbol period used for MAC timing is the same
79 * as the physical symbol period or if you actually mean the MAC timing symbol
80 * period.
81 *
82 * PHY specific symbol periods are defined in PHY specific sections below.
83 */
84 #define IEEE802154_PHY_SYMBOLS_PER_SECOND(symbol_period_ns) (NSEC_PER_SEC / symbol_period_ns)
85
86 /** @} */
87
88
89 /**
90 * @name IEEE 802.15.4-2020, Section 8: MAC services
91 * @{
92 */
93
94 /**
95 * The number of PHY symbols forming a superframe slot when the superframe order
96 * is equal to zero, see sections 8.4.2, table 8-93, aBaseSlotDuration and
97 * section 6.2.1.
98 */
99 #define IEEE802154_MAC_A_BASE_SLOT_DURATION 60U
100
101 /**
102 * The number of slots contained in any superframe, see section 8.4.2,
103 * table 8-93, aNumSuperframeSlots.
104 */
105 #define IEEE802154_MAC_A_NUM_SUPERFRAME_SLOTS 16U
106
107 /**
108 * The number of PHY symbols forming a superframe when the superframe order is
109 * equal to zero, see section 8.4.2, table 8-93, aBaseSuperframeDuration.
110 */
111 #define IEEE802154_MAC_A_BASE_SUPERFRAME_DURATION \
112 (IEEE802154_MAC_A_BASE_SLOT_DURATION * IEEE802154_MAC_A_NUM_SUPERFRAME_SLOTS)
113
114 /**
115 * MAC PIB attribute aUnitBackoffPeriod, see section 8.4.2, table 8-93, in symbol
116 * periods, valid for all PHYs except SUN PHY in the 920 MHz band.
117 */
118 #define IEEE802154_MAC_A_UNIT_BACKOFF_PERIOD(turnaround_time) \
119 (turnaround_time + IEEE802154_PHY_A_CCA_TIME)
120
121 /**
122 * Default macResponseWaitTime in multiples of aBaseSuperframeDuration as
123 * defined in section 8.4.3.1, table 8-94.
124 */
125 #define IEEE802154_MAC_RESPONSE_WAIT_TIME_DEFAULT 32U
126
127 /** @} */
128
129
130 /**
131 * @name IEEE 802.15.4-2020, Section 10: General PHY requirements
132 * @{
133 */
134
135 /**
136 * @brief PHY channel pages, see section 10.1.3
137 *
138 * @details A device driver must support the mandatory channel pages, frequency
139 * bands and channels of at least one IEEE 802.15.4 PHY.
140 *
141 * Channel page and number assignments have developed over several versions of
142 * the standard and are not particularly well documented. Therefore some notes
143 * about peculiarities of channel pages and channel numbering:
144 * - The 2006 version of the standard had a read-only phyChannelsSupported PHY
145 * PIB attribute that represented channel page/number combinations as a
146 * bitmap. This attribute was removed in later versions of the standard as the
147 * number of channels increased beyond what could be represented by a bit map.
148 * That's the reason why it was decided to represent supported channels as a
149 * combination of channel pages and ranges instead.
150 * - In the 2020 version of the standard, 13 channel pages are explicitly
151 * defined, but up to 32 pages could in principle be supported. This was a
152 * hard requirement in the 2006 standard. In later standards it is implicit
153 * from field specifications, e.g. the MAC PIB attribute macChannelPage
154 * (section 8.4.3.4, table 8-100) or channel page fields used in the SRM
155 * protocol (see section 8.2.26.5).
156 * - ASK PHY (channel page one) was deprecated in the 2015 version of the
157 * standard. The 2020 version of the standard is a bit ambivalent whether
158 * channel page one disappeared as well or should be interpreted as O-QPSK now
159 * (see section 10.1.3.3). In Zephyr this ambivalence is resolved by
160 * deprecating channel page one.
161 * - For some PHYs the standard doesn't clearly specify a channel page, namely
162 * the GFSK, RS-GFSK, CMB and TASK PHYs. These are all rather new and left out
163 * in our list as long as no driver wants to implement them.
164 *
165 * @warning The bit numbers are not arbitrary but represent the channel
166 * page numbers as defined by the standard. Therefore do not change the
167 * bit numbering.
168 */
169 enum ieee802154_phy_channel_page {
170 /**
171 * Channel page zero supports the 2.4G channels of the O-QPSK PHY and
172 * all channels from the BPSK PHYs initially defined in the 2003
173 * editions of the standard. For channel page zero, 16 channels are
174 * available in the 2450 MHz band (channels 11-26, O-QPSK), 10 in the
175 * 915 MHz band (channels 1-10, BPSK), and 1 in the 868 MHz band
176 * (channel 0, BPSK).
177 *
178 * You can retrieve the channels supported by a specific driver on this
179 * page via @ref IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_RANGES attribute.
180 *
181 * see section 10.1.3.3
182 */
183 IEEE802154_ATTR_PHY_CHANNEL_PAGE_ZERO_OQPSK_2450_BPSK_868_915 = BIT(0),
184
185 /** Formerly ASK PHY - deprecated in IEEE 802.15.4-2015 */
186 IEEE802154_ATTR_PHY_CHANNEL_PAGE_ONE_DEPRECATED = BIT(1),
187
188 /** O-QPSK PHY - 868 MHz and 915 MHz bands, see section 10.1.3.3 */
189 IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWO_OQPSK_868_915 = BIT(2),
190
191 /** CSS PHY - 2450 MHz band, see section 10.1.3.4 */
192 IEEE802154_ATTR_PHY_CHANNEL_PAGE_THREE_CSS = BIT(3),
193
194 /** UWB PHY - SubG, low and high bands, see section 10.1.3.5 */
195 IEEE802154_ATTR_PHY_CHANNEL_PAGE_FOUR_HRP_UWB = BIT(4),
196
197 /** O-QPSK PHY - 780 MHz band, see section 10.1.3.2 */
198 IEEE802154_ATTR_PHY_CHANNEL_PAGE_FIVE_OQPSK_780 = BIT(5),
199
200 /** reserved - not currently assigned */
201 IEEE802154_ATTR_PHY_CHANNEL_PAGE_SIX_RESERVED = BIT(6),
202
203 /** MSK PHY - 780 MHz and 2450 MHz bands, see sections 10.1.3.6, 10.1.3.7 */
204 IEEE802154_ATTR_PHY_CHANNEL_PAGE_SEVEN_MSK = BIT(7),
205
206 /** LRP UWB PHY, see sections 10.1.3.8 */
207 IEEE802154_ATTR_PHY_CHANNEL_PAGE_EIGHT_LRP_UWB = BIT(8),
208
209 /**
210 * SUN FSK/OFDM/O-QPSK PHYs - predefined bands, operating modes and
211 * channels, see sections 10.1.3.9
212 */
213 IEEE802154_ATTR_PHY_CHANNEL_PAGE_NINE_SUN_PREDEFINED = BIT(9),
214
215 /**
216 * SUN FSK/OFDM/O-QPSK PHYs - generic modulation and channel
217 * description, see sections 10.1.3.9, 7.4.4.11
218 */
219 IEEE802154_ATTR_PHY_CHANNEL_PAGE_TEN_SUN_FSK_GENERIC = BIT(10),
220
221 /** O-QPSK PHY - 2380 MHz band, see section 10.1.3.10 */
222 IEEE802154_ATTR_PHY_CHANNEL_PAGE_ELEVEN_OQPSK_2380 = BIT(11),
223
224 /** LECIM DSSS/FSK PHYs, see section 10.1.3.11 */
225 IEEE802154_ATTR_PHY_CHANNEL_PAGE_TWELVE_LECIM = BIT(12),
226
227 /** RCC PHY, see section 10.1.3.12 */
228 IEEE802154_ATTR_PHY_CHANNEL_PAGE_THIRTEEN_RCC = BIT(13),
229 };
230
231 /**
232 * Represents a supported channel range, see @ref
233 * ieee802154_phy_supported_channels.
234 */
235 struct ieee802154_phy_channel_range {
236 uint16_t from_channel; /**< From channel range */
237 uint16_t to_channel; /**< To channel range */
238 };
239
240 /**
241 * Represents a list channels supported by a driver for a given interface, see
242 * @ref IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_RANGES.
243 */
244 struct ieee802154_phy_supported_channels {
245 /**
246 * @brief Pointer to an array of channel range structures.
247 *
248 * @warning The pointer must be valid and constant throughout the life
249 * of the interface.
250 */
251 const struct ieee802154_phy_channel_range *const ranges;
252
253 /** @brief The number of currently available channel ranges. */
254 const uint8_t num_ranges;
255 };
256
257 /**
258 * @brief Allocate memory for the supported channels driver attribute with a
259 * single channel range constant across all driver instances. This is what most
260 * IEEE 802.15.4 drivers need.
261 *
262 * @details Example usage:
263 *
264 * @code{.c}
265 * IEEE802154_DEFINE_PHY_SUPPORTED_CHANNELS(drv_attr, 11, 26);
266 * @endcode
267 *
268 * The attribute may then be referenced like this:
269 *
270 * @code{.c}
271 * ... &drv_attr.phy_supported_channels ...
272 * @endcode
273 *
274 * See @ref ieee802154_attr_get_channel_page_and_range() for a further shortcut
275 * that can be combined with this macro.
276 *
277 * @param drv_attr name of the local static variable to be declared for the
278 * local attributes structure
279 * @param from the first channel to be supported
280 * @param to the last channel to be supported
281 */
282 #define IEEE802154_DEFINE_PHY_SUPPORTED_CHANNELS(drv_attr, from, to) \
283 static const struct { \
284 const struct ieee802154_phy_channel_range phy_channel_range; \
285 const struct ieee802154_phy_supported_channels phy_supported_channels; \
286 } drv_attr = { \
287 .phy_channel_range = {.from_channel = (from), .to_channel = (to)}, \
288 .phy_supported_channels = \
289 { \
290 .ranges = &drv_attr.phy_channel_range, \
291 .num_ranges = 1U, \
292 }, \
293 }
294
295 /** @} */
296
297
298 /**
299 * @name IEEE 802.15.4-2020, Section 11: PHY services
300 * @{
301 */
302
303 /**
304 * Default PHY PIB attribute aTurnaroundTime, in PHY symbols, see section 11.3,
305 * table 11-1.
306 */
307 #define IEEE802154_PHY_A_TURNAROUND_TIME_DEFAULT 12U
308
309 /**
310 * PHY PIB attribute aTurnaroundTime for SUN, RS-GFSK, TVWS, and LECIM FSK PHY,
311 * in PHY symbols, see section 11.3, table 11-1.
312 */
313 #define IEEE802154_PHY_A_TURNAROUND_TIME_1MS(symbol_period_ns) \
314 DIV_ROUND_UP(NSEC_PER_MSEC, symbol_period_ns)
315
316 /**
317 * PHY PIB attribute aCcaTime, in PHY symbols, all PHYs except for SUN O-QPSK,
318 * see section 11.3, table 11-1.
319 */
320 #define IEEE802154_PHY_A_CCA_TIME 8U
321
322 /** @} */
323
324
325
326 /**
327 * @name IEEE 802.15.4-2020, Section 12: O-QPSK PHY
328 * @{
329 */
330
331 /** O-QPSK 868Mhz band symbol period, see section 12.3.3 */
332 #define IEEE802154_PHY_OQPSK_868MHZ_SYMBOL_PERIOD_NS 40000LL
333
334 /**
335 * O-QPSK 780MHz, 915MHz, 2380MHz and 2450MHz bands symbol period,
336 * see section 12.3.3
337 */
338 #define IEEE802154_PHY_OQPSK_780_TO_2450MHZ_SYMBOL_PERIOD_NS 16000LL
339
340 /** @} */
341
342
343 /**
344 * @name IEEE 802.15.4-2020, Section 13: BPSK PHY
345 * @{
346 */
347
348 /** BPSK 868MHz band symbol period, see section 13.3.3 */
349 #define IEEE802154_PHY_BPSK_868MHZ_SYMBOL_PERIOD_NS 50000LL
350
351 /** BPSK 915MHz band symbol period, see section 13.3.3 */
352 #define IEEE802154_PHY_BPSK_915MHZ_SYMBOL_PERIOD_NS 25000LL
353
354 /** @} */
355
356
357 /**
358 * @name IEEE 802.15.4-2020, Section 15: HRP UWB PHY
359 *
360 * @details For HRP UWB the symbol period is derived from the preamble symbol period
361 * (T_psym), see section 11.3, table 11-1 and section 15.2.5, table 15-4
362 * (confirmed in IEEE 802.15.4z, section 15.1). Choosing among those periods
363 * cannot be done based on channel page and channel alone. The mean pulse
364 * repetition frequency must also be known, see the 'UwbPrf' parameter of the
365 * MCPS-DATA.request primitive (section 8.3.2, table 8-88) and the preamble
366 * parameters for HRP-ERDEV length 91 codes (IEEE 802.15.4z, section 15.2.6.2,
367 * table 15-7b).
368 * @{
369 */
370
371 /** Nominal PRF 4MHz symbol period */
372 #define IEEE802154_PHY_HRP_UWB_PRF4_TPSYM_SYMBOL_PERIOD_NS 3974.36F
373 /** Nominal PRF 16MHz symbol period */
374 #define IEEE802154_PHY_HRP_UWB_PRF16_TPSYM_SYMBOL_PERIOD_NS 993.59F
375 /** Nominal PRF 64MHz symbol period */
376 #define IEEE802154_PHY_HRP_UWB_PRF64_TPSYM_SYMBOL_PERIOD_NS 1017.63F
377 /** ERDEV symbol period */
378 #define IEEE802154_PHY_HRP_UWB_ERDEV_TPSYM_SYMBOL_PERIOD_NS 729.17F
379
380 /** @brief represents the nominal pulse rate frequency of an HRP UWB PHY */
381 enum ieee802154_phy_hrp_uwb_nominal_prf {
382 /** standard modes, see section 8.3.2, table 8-88. */
383 IEEE802154_PHY_HRP_UWB_PRF_OFF = 0,
384 IEEE802154_PHY_HRP_UWB_NOMINAL_4_M = BIT(0),
385 IEEE802154_PHY_HRP_UWB_NOMINAL_16_M = BIT(1),
386 IEEE802154_PHY_HRP_UWB_NOMINAL_64_M = BIT(2),
387
388 /**
389 * enhanced ranging device (ERDEV) modes not specified in table 8-88,
390 * see IEEE 802.15.4z, section 15.1, section 15.2.6.2, table 15-7b,
391 * section 15.3.4.2 and section 15.3.4.3.
392 */
393 IEEE802154_PHY_HRP_UWB_NOMINAL_64_M_BPRF = BIT(3),
394 IEEE802154_PHY_HRP_UWB_NOMINAL_128_M_HPRF = BIT(4),
395 IEEE802154_PHY_HRP_UWB_NOMINAL_256_M_HPRF = BIT(5),
396 };
397
398 /** RDEV device mask */
399 #define IEEE802154_PHY_HRP_UWB_RDEV \
400 (IEEE802154_PHY_HRP_UWB_NOMINAL_4_M | IEEE802154_PHY_HRP_UWB_NOMINAL_16_M | \
401 IEEE802154_PHY_HRP_UWB_NOMINAL_64_M)
402
403 /** ERDEV device mask */
404 #define IEEE802154_PHY_HRP_UWB_ERDEV \
405 (IEEE802154_PHY_HRP_UWB_NOMINAL_64_M_BPRF | IEEE802154_PHY_HRP_UWB_NOMINAL_128_M_HPRF | \
406 IEEE802154_PHY_HRP_UWB_NOMINAL_256_M_HPRF)
407
408 /** @} */
409
410
411 /**
412 * @name IEEE 802.15.4-2020, Section 19: SUN FSK PHY
413 * @{
414 */
415
416 /** SUN FSK 863Mhz and 915MHz band symbol periods, see section 19.1, table 19-1 */
417 #define IEEE802154_PHY_SUN_FSK_863MHZ_915MHZ_SYMBOL_PERIOD_NS 20000LL
418
419 /** SUN FSK PHY header length, in bytes, see section 19.2.4 */
420 #define IEEE802154_PHY_SUN_FSK_PHR_LEN 2
421
422 /** @} */
423
424 /**
425 * @name IEEE 802.15.4 Driver API
426 * @{
427 */
428
429 /**
430 * IEEE 802.15.4 driver capabilities
431 *
432 * Any driver properties that can be represented in binary form should be
433 * modeled as capabilities. These are called "hardware" capabilities for
434 * historical reasons but may also represent driver firmware capabilities (e.g.
435 * MAC offloading features).
436 */
437 enum ieee802154_hw_caps {
438
439 /*
440 * PHY capabilities
441 *
442 * The following capabilities describe features of the underlying radio
443 * hardware (PHY/L1).
444 */
445
446 /** Energy detection (ED) supported (optional) */
447 IEEE802154_HW_ENERGY_SCAN = BIT(0),
448
449 /*
450 * MAC offloading capabilities (optional)
451 *
452 * The following MAC/L2 features may optionally be offloaded to
453 * specialized hardware or proprietary driver firmware ("hard MAC").
454 *
455 * L2 implementations will have to provide a "soft MAC" fallback for
456 * these features in case the driver does not support them natively.
457 *
458 * Note: Some of these offloading capabilities may be mandatory in
459 * practice to stay within timing requirements of certain IEEE 802.15.4
460 * protocols, e.g. CPUs may not be fast enough to send ACKs within the
461 * required delays in the 2.4 GHz band without hard MAC support.
462 */
463
464 /** Frame checksum verification supported */
465 IEEE802154_HW_FCS = BIT(1),
466
467 /** Filtering of PAN ID, extended and short address supported */
468 IEEE802154_HW_FILTER = BIT(2),
469
470 /** Promiscuous mode supported */
471 IEEE802154_HW_PROMISC = BIT(3),
472
473 /** CSMA-CA procedure supported on TX */
474 IEEE802154_HW_CSMA = BIT(4),
475
476 /** Waits for ACK on TX if AR bit is set in TX pkt */
477 IEEE802154_HW_TX_RX_ACK = BIT(5),
478
479 /** Supports retransmission on TX ACK timeout */
480 IEEE802154_HW_RETRANSMISSION = BIT(6),
481
482 /** Sends ACK on RX if AR bit is set in RX pkt */
483 IEEE802154_HW_RX_TX_ACK = BIT(7),
484
485 /** TX at specified time supported */
486 IEEE802154_HW_TXTIME = BIT(8),
487
488 /** TX directly from sleep supported
489 *
490 * @note This HW capability does not conform to the requirements
491 * specified in #61227 as it closely couples the driver to OpenThread's
492 * capability and device model which is different from Zephyr's:
493 * - "Sleeping" is a well defined term in Zephyr related to internal
494 * power and thread management and different from "RX off" as
495 * defined in OT.
496 * - Currently all OT-capable drivers have the "sleep to TX"
497 * capability anyway plus we expect future drivers to implement it
498 * ootb as well, so no information is actually conveyed by this
499 * capability.
500 * - The `start()`/`stop()` API of a net device controls the
501 * interface's operational state. Drivers MUST respond with
502 * -ENETDOWN when calling `tx()` while their operational state is
503 * "DOWN", only devices in the "UP" state MAY transmit packets (RFC
504 * 2863).
505 * - A migration path has been defined in #63670 for actual removal of
506 * this capability in favor of a standard compliant
507 * `configure(rx_on/rx_off)` call, see there for details.
508 *
509 * @deprecated Drivers and L2 SHALL not introduce additional references
510 * to this capability and remove existing ones as outlined in #63670.
511 */
512 IEEE802154_HW_SLEEP_TO_TX = BIT(9),
513
514 /** Timed RX window scheduling supported */
515 IEEE802154_HW_RXTIME = BIT(10),
516
517 /** TX security supported (key management, encryption and authentication) */
518 IEEE802154_HW_TX_SEC = BIT(11),
519
520 /** RxOnWhenIdle handling supported */
521 IEEE802154_RX_ON_WHEN_IDLE = BIT(12),
522
523 /* Note: Update also IEEE802154_HW_CAPS_BITS_COMMON_COUNT when changing
524 * the ieee802154_hw_caps type.
525 */
526 };
527
528 /** @brief Number of bits used by ieee802154_hw_caps type. */
529 #define IEEE802154_HW_CAPS_BITS_COMMON_COUNT (13)
530
531 /** @brief This and higher values are specific to the protocol- or driver-specific extensions. */
532 #define IEEE802154_HW_CAPS_BITS_PRIV_START IEEE802154_HW_CAPS_BITS_COMMON_COUNT
533
534 /** Filter type, see @ref ieee802154_radio_api::filter */
535 enum ieee802154_filter_type {
536 IEEE802154_FILTER_TYPE_IEEE_ADDR, /**< Address type filter */
537 IEEE802154_FILTER_TYPE_SHORT_ADDR, /**< Short address type filter */
538 IEEE802154_FILTER_TYPE_PAN_ID, /**< PAN id type filter */
539 IEEE802154_FILTER_TYPE_SRC_IEEE_ADDR, /**< Source address type filter */
540 IEEE802154_FILTER_TYPE_SRC_SHORT_ADDR, /**< Source short address type filter */
541 };
542
543 /** Driver events, see @ref IEEE802154_CONFIG_EVENT_HANDLER */
544 enum ieee802154_event {
545 /** Data transmission started */
546 IEEE802154_EVENT_TX_STARTED,
547 /** Data reception failed */
548 IEEE802154_EVENT_RX_FAILED,
549 /**
550 * An RX slot ended, requires @ref IEEE802154_HW_RXTIME.
551 *
552 * @note This event SHALL not be triggered by drivers when RX is
553 * synchronously switched of due to a call to `stop()` or an RX slot
554 * being configured.
555 */
556 IEEE802154_EVENT_RX_OFF,
557 };
558
559 /** RX failed event reasons, see @ref IEEE802154_EVENT_RX_FAILED */
560 enum ieee802154_rx_fail_reason {
561 /** Nothing received */
562 IEEE802154_RX_FAIL_NOT_RECEIVED,
563 /** Frame had invalid checksum */
564 IEEE802154_RX_FAIL_INVALID_FCS,
565 /** Address did not match */
566 IEEE802154_RX_FAIL_ADDR_FILTERED,
567 /** General reason */
568 IEEE802154_RX_FAIL_OTHER
569 };
570
571 /** Energy scan callback */
572 typedef void (*energy_scan_done_cb_t)(const struct device *dev,
573 int16_t max_ed);
574
575 /** Driver event callback */
576 typedef void (*ieee802154_event_cb_t)(const struct device *dev,
577 enum ieee802154_event evt,
578 void *event_params);
579
580 /** Filter value, see @ref ieee802154_radio_api::filter */
581 struct ieee802154_filter {
582 union {
583 /** Extended address, in little endian */
584 uint8_t *ieee_addr;
585 /** Short address, in CPU byte order */
586 uint16_t short_addr;
587 /** PAN ID, in CPU byte order */
588 uint16_t pan_id;
589 };
590 };
591
592 /**
593 * Key configuration for transmit security offloading, see @ref
594 * IEEE802154_CONFIG_MAC_KEYS.
595 */
596 struct ieee802154_key {
597 /** Key material */
598 uint8_t *key_value;
599 /** Initial value of frame counter associated with the key, see section 9.4.3 */
600 uint32_t key_frame_counter;
601 /** Indicates if per-key frame counter should be used, see section 9.4.3 */
602 bool frame_counter_per_key;
603 /** Key Identifier Mode, see section 9.4.2.3, Table 9-7 */
604 uint8_t key_id_mode;
605 /** Key Identifier, see section 9.4.4 */
606 uint8_t *key_id;
607 };
608
609 /** IEEE 802.15.4 Transmission mode. */
610 enum ieee802154_tx_mode {
611 /** Transmit packet immediately, no CCA. */
612 IEEE802154_TX_MODE_DIRECT,
613
614 /** Perform CCA before packet transmission. */
615 IEEE802154_TX_MODE_CCA,
616
617 /**
618 * Perform full CSMA/CA procedure before packet transmission.
619 *
620 * @note requires IEEE802154_HW_CSMA capability.
621 */
622 IEEE802154_TX_MODE_CSMA_CA,
623
624 /**
625 * Transmit packet in the future, at the specified time, no CCA.
626 *
627 * @note requires IEEE802154_HW_TXTIME capability.
628 */
629 IEEE802154_TX_MODE_TXTIME,
630
631 /**
632 * Transmit packet in the future, perform CCA before transmission.
633 *
634 * @note requires IEEE802154_HW_TXTIME capability.
635 *
636 * @note Required for Thread 1.2 Coordinated Sampled Listening feature
637 * (see Thread specification 1.2.0, ch. 3.2.6.3).
638 */
639 IEEE802154_TX_MODE_TXTIME_CCA,
640
641 /** Number of modes defined in ieee802154_tx_mode. */
642 IEEE802154_TX_MODE_COMMON_COUNT,
643
644 /** This and higher values are specific to the protocol- or driver-specific extensions. */
645 IEEE802154_TX_MODE_PRIV_START = IEEE802154_TX_MODE_COMMON_COUNT,
646 };
647
648 /** IEEE 802.15.4 Frame Pending Bit table address matching mode. */
649 enum ieee802154_fpb_mode {
650 /** The pending bit shall be set only for addresses found in the list. */
651 IEEE802154_FPB_ADDR_MATCH_THREAD,
652
653 /** The pending bit shall be cleared for short addresses found in the
654 * list.
655 */
656 IEEE802154_FPB_ADDR_MATCH_ZIGBEE,
657 };
658
659 /** IEEE 802.15.4 driver configuration types. */
660 enum ieee802154_config_type {
661 /**
662 * Indicates how the driver should set the Frame Pending bit in ACK
663 * responses for Data Requests. If enabled, the driver should determine
664 * whether to set the bit or not based on the information provided with
665 * @ref IEEE802154_CONFIG_ACK_FPB config and FPB address matching mode
666 * specified. Otherwise, Frame Pending bit should be set to ``1`` (see
667 * section 6.7.3).
668 *
669 * @note requires @ref IEEE802154_HW_TX_RX_ACK capability and is
670 * available in any interface operational state.
671 */
672 IEEE802154_CONFIG_AUTO_ACK_FPB,
673
674 /**
675 * Indicates whether to set ACK Frame Pending bit for specific address
676 * or not. Disabling the Frame Pending bit with no address provided
677 * (NULL pointer) should disable it for all enabled addresses.
678 *
679 * @note requires @ref IEEE802154_HW_TX_RX_ACK capability and is
680 * available in any interface operational state.
681 */
682 IEEE802154_CONFIG_ACK_FPB,
683
684 /**
685 * Indicates whether the device is a PAN coordinator. This influences
686 * packet filtering.
687 *
688 * @note Available in any interface operational state.
689 */
690 IEEE802154_CONFIG_PAN_COORDINATOR,
691
692 /**
693 * Enable/disable promiscuous mode.
694 *
695 * @note Available in any interface operational state.
696 */
697 IEEE802154_CONFIG_PROMISCUOUS,
698
699 /**
700 * Specifies new IEEE 802.15.4 driver event handler. Specifying NULL as
701 * a handler will disable events notification.
702 *
703 * @note Available in any interface operational state.
704 */
705 IEEE802154_CONFIG_EVENT_HANDLER,
706
707 /**
708 * Updates MAC keys, key index and the per-key frame counter for drivers
709 * supporting transmit security offloading, see section 9.5, tables 9-9
710 * and 9-10. The key configuration SHALL NOT be accepted if the frame
711 * counter (in case frame counter per key is true) is not strictly
712 * larger than the current frame counter associated with the same key,
713 * see sections 8.2.2, 9.2.4 g/h) and 9.4.3.
714 *
715 * @note Requires @ref IEEE802154_HW_TX_SEC capability and is available
716 * in any interface operational state.
717 */
718 IEEE802154_CONFIG_MAC_KEYS,
719
720 /**
721 * Sets the current MAC frame counter value associated with the
722 * interface for drivers supporting transmit security offloading, see
723 * section 9.5, table 9-8, secFrameCounter.
724 *
725 * @warning The frame counter MUST NOT be accepted if it is not
726 * strictly greater than the current frame counter associated with the
727 * interface, see sections 8.2.2, 9.2.4 g/h) and 9.4.3. Otherwise the
728 * replay protection provided by the frame counter may be compromised.
729 * Drivers SHALL return -EINVAL in case the configured frame counter
730 * does not conform to this requirement.
731 *
732 * @note Requires @ref IEEE802154_HW_TX_SEC capability and is available
733 * in any interface operational state.
734 */
735 IEEE802154_CONFIG_FRAME_COUNTER,
736
737 /**
738 * Sets the current MAC frame counter value if the provided value is greater than
739 * the current one.
740 *
741 * @note Requires @ref IEEE802154_HW_TX_SEC capability and is available
742 * in any interface operational state.
743 *
744 * @warning This configuration option does not conform to the
745 * requirements specified in #61227 as it is redundant with @ref
746 * IEEE802154_CONFIG_FRAME_COUNTER, and will therefore be deprecated in
747 * the future.
748 */
749 IEEE802154_CONFIG_FRAME_COUNTER_IF_LARGER,
750
751 /**
752 * Set or unset a radio reception window (RX slot). This can be used for
753 * any scheduled reception, e.g.: Zigbee GP device, CSL, TSCH, etc.
754 *
755 * @details The start and duration parameters of the RX slot are
756 * relative to the network subsystem's local clock. If the start
757 * parameter of the RX slot is -1 then any previously configured RX
758 * slot SHALL be canceled immediately. If the start parameter is any
759 * value in the past (including 0) or the duration parameter is zero
760 * then the receiver SHALL remain off forever until the RX slot has
761 * either been removed or re-configured to point to a future start
762 * time. If an RX slot is configured while the previous RX slot is
763 * still scheduled, then the previous slot SHALL be cancelled and the
764 * new slot scheduled instead.
765 *
766 * RX slots MAY be programmed while the driver is "DOWN". If any past
767 * or future RX slot is configured when calling `start()` then the
768 * interface SHALL be placed in "UP" state but the receiver SHALL not
769 * be started.
770 *
771 * The driver SHALL take care to start/stop the receiver autonomously,
772 * asynchronously and automatically around the RX slot. The driver
773 * SHALL resume power just before the RX slot and suspend it again
774 * after the slot unless another programmed event forces the driver not
775 * to suspend. The driver SHALL switch to the programmed channel
776 * before the RX slot and back to the channel set with set_channel()
777 * after the RX slot. If the driver interface is "DOWN" when the start
778 * time of an RX slot arrives, then the RX slot SHALL not be observed
779 * and the receiver SHALL remain off.
780 *
781 * If the driver is "UP" while configuring an RX slot, the driver SHALL
782 * turn off the receiver immediately and (possibly asynchronously) put
783 * the driver into the lowest possible power saving mode until the
784 * start of the RX slot. If the driver is "UP" while the RX slot is
785 * deleted, then the driver SHALL enable the receiver immediately. The
786 * receiver MUST be ready to receive packets before returning from the
787 * `configure()` operation in this case.
788 *
789 * This behavior means that setting an RX slot implicitly sets the MAC
790 * PIB attribute macRxOnWhenIdle (see section 8.4.3.1, table 8-94) to
791 * "false" while deleting the RX slot implicitly sets macRxOnWhenIdle to
792 * "true".
793 *
794 * @note requires @ref IEEE802154_HW_RXTIME capability and is available
795 * in any interface operational state.
796 *
797 * @note Required for Thread 1.2 Coordinated Sampled Listening feature
798 * (see Thread specification 1.2.0, ch. 3.2.6.3).
799 */
800 IEEE802154_CONFIG_RX_SLOT,
801
802 /**
803 * Enables or disables a device as a CSL receiver and configures its CSL
804 * period.
805 *
806 * @details Configures the CSL period in units of 10 symbol periods.
807 * Values greater than zero enable CSL if the driver supports it and the
808 * device starts to operate as a CSL receiver. Setting this to zero
809 * disables CSL on the device. If the driver does not support CSL, the
810 * configuration call SHALL return -ENOTSUP.
811 *
812 * See section 7.4.2.3 and section 8.4.3.6, table 8-104, macCslPeriod.
813 *
814 * @note Confusingly the standard calls the CSL receiver "CSL
815 * coordinator" (i.e. "coordinating the CSL protocol timing", see
816 * section 6.12.2.2), although, typically, a CSL coordinator is NOT also
817 * an IEEE 802.15.4 FFD coordinator or PAN coordintor but a simple RFD
818 * end device (compare the device roles outlined in sections 5.1, 5.3,
819 * 5.5 and 6.1). To avoid confusion we therefore prefer calling CSL
820 * coordinators (typically an RFD end device) "CSL receivers" and CSL
821 * peer devices (typically FFD coordinators or PAN coordinators) "CSL
822 * transmitters". Also note that at this time, we do NOT support
823 * unsynchronized transmission with CSL wake up frames as specified in
824 * section 6.12.2.4.4.
825 *
826 * To offload CSL receiver timing to the driver the upper layer SHALL
827 * combine several configuration options in the following way:
828 *
829 * 1. Use @ref IEEE802154_CONFIG_ENH_ACK_HEADER_IE once with an
830 * appropriate pre-filled CSL IE and the CSL phase set to an
831 * arbitrary value or left uninitialized. The CSL phase SHALL be
832 * injected on-the-fly by the driver at runtime as outlined in 2.
833 * below. Adding a short and extended address will inform the driver
834 * of the specific CSL receiver to which it SHALL inject CSL IEs. If
835 * no addresses are given then the CSL IE will be injected into all
836 * enhanced ACK frames as soon as CSL is enabled. This configuration
837 * SHALL be done before enabling CSL by setting a CSL period greater
838 * than zero.
839 *
840 * 2. Configure @ref IEEE802154_CONFIG_EXPECTED_RX_TIME immediately
841 * followed by @ref IEEE802154_CONFIG_CSL_PERIOD. To prevent race
842 * conditions, the upper layer SHALL ensure that the receiver is not
843 * enabled during or between the two calls (e.g. by a previously
844 * configured RX slot) nor SHALL a frame be transmitted concurrently.
845 *
846 * The expected RX time SHALL point to the end of SFD of an ideally
847 * timed RX frame in an arbitrary past or future CSL channel sample,
848 * i.e. whose "end of SFD" arrives exactly at the locally predicted
849 * time inside the CSL channel sample.
850 *
851 * The driver SHALL derive CSL anchor points and the CSL phase from
852 * the given expected RX time as follows:
853 *
854 * cslAnchorPointNs = last expected RX time
855 * + PHY-specific PHR duration in ns
856 *
857 * startOfMhrNs = start of MHR of the frame containing the
858 * CSL IE relative to the local network clock
859 *
860 * cslPhase = (startOfMhrNs - cslAnchorPointNs)
861 * / (10 * PHY specific symbol period in ns)
862 * % cslPeriod
863 *
864 * The driver SHALL set the CSL phase in the IE configured in 1. and
865 * inject that IE on-the-fly into outgoing enhanced ACK frames if the
866 * destination address conforms to the IE's address filter.
867 *
868 * 3. Use @ref IEEE802154_CONFIG_RX_SLOT periodically to schedule
869 * each CSL channel sample early enough before its start time. The
870 * size of the CSL channel sample SHALL take relative clock drift and
871 * scheduling uncertainties with respect to CSL transmitters into
872 * account as specified by the standard such that at least the full
873 * SHR of a legitimate RX frame is guaranteed to land inside the
874 * channel sample.
875 *
876 * To this avail, the last configured expected RX time plus an
877 * integer number of CSL periods SHALL point to a fixed offset of the
878 * RX slot (not necessarily its center):
879 *
880 * expectedRxTimeNs_N = last expected RX time
881 * + N * (cslPeriod * 10 * PHY-specific symbol period in ns)
882 *
883 * expectedRxTimeNs_N - rxSlot_N.start == const for all N
884 *
885 * While the configured CSL period is greater than zero, drivers
886 * SHOULD validate the offset of the expected RX time inside each RX
887 * slot accordingly. If the driver finds that the offset varies from
888 * slot to slot, drivers SHOULD log the difference but SHALL
889 * nevertheless accept and schedule the RX slot with a zero success
890 * value to work around minor implementation or rounding errors in
891 * upper layers.
892 *
893 * Configure and start a CSL receiver:
894 *
895 * ENH_ACK_HEADER_IE
896 * |
897 * | EXPECTED_RX_TIME (end of SFD of a perfectly timed RX frame
898 * | | in any past or future channel sample)
899 * | |
900 * | | CSL_PERIOD (>0) RX_SLOT
901 * | | | |
902 * v v v v
903 * -----------------------------------------------[-CSL channel sample ]----+
904 * ^ |
905 * | |
906 * +--------------------- loop ---------+
907 *
908 * Disable CSL on the receiver:
909 *
910 * CSL_PERIOD (=0)
911 * |
912 * v
913 * ---------------------
914 *
915 * Update the CSL period to a new value:
916 *
917 * EXPECTED_RX_TIME (based on updated period)
918 * |
919 * | CSL_PERIOD (>0, updated) RX_SLOT
920 * | | |
921 * v v v
922 * -----------------------------------------------[-CSL channel sample ]----+
923 * ^ |
924 * | |
925 * +--------------------- loop ---------+
926 *
927 * @note Available in any interface operational state.
928 *
929 * @note Required for Thread 1.2 Coordinated Sampled Listening feature
930 * (see Thread specification 1.2.0, ch. 3.2.6.3).
931 */
932 IEEE802154_CONFIG_CSL_PERIOD,
933
934 /**
935 * Configure a timepoint at which an RX frame is expected to arrive.
936 *
937 * @details Configure the nanosecond resolution timepoint relative to
938 * the network subsystem's local clock at which an RX frame's end of SFD
939 * (i.e. equivalently its end of SHR, start of PHR, or in the case of
940 * PHYs with RDEV or ERDEV capability the RMARKER) is expected to arrive
941 * at the local antenna assuming perfectly synchronized local and remote
942 * network clocks and zero distance between antennas.
943 *
944 * This parameter MAY be used to offload parts of timing sensitive TDMA
945 * (e.g. TSCH, beacon-enabled PAN including DSME), low-energy (e.g.
946 * CSL, RIT) or ranging (TDoA) protocols to the driver. In these
947 * protocols, medium access is tightly controlled such that the expected
948 * arrival time of a frame can be predicted within a well-defined time
949 * window. This feature will typically be combined with @ref
950 * IEEE802154_CONFIG_RX_SLOT although this is not a hard requirement.
951 *
952 * The "expected RX time" MAY be interpreted slightly differently
953 * depending on the protocol context:
954 * - CSL phase (i.e. time to the next expected CSL transmission) or anchor
955 * time (i.e. any arbitrary timepoint with "zero CSL phase") SHALL be
956 * derived by adding the PHY header duration to the expected RX time
957 * to calculate the "start of MHR" ("first symbol of MAC", see section
958 * 6.12.2.1) required by the CSL protocol, compare @ref
959 * IEEE802154_CONFIG_CSL_PERIOD.
960 * - In TSCH the expected RX time MAY be set to macTsRxOffset +
961 * macTsRxWait / 2. Then the time correction SHALL be calculated as
962 * the expected RX time minus actual arrival timestamp, see section
963 * 6.5.4.3.
964 * - In ranging applications, time difference of arrival (TDOA) MAY be
965 * calculated inside the driver comparing actual RMARKER timestamps
966 * against the assumed synchronized time at which the ranging frame
967 * was sent, see IEEE 802.15.4z.
968 *
969 * In case of periodic protocols (e.g. CSL channel samples, periodic
970 * beacons of a single PAN, periodic ranging "blinks"), a single
971 * timestamp at any time in the past or in the future may be given from
972 * which other expected timestamps can be derived by adding or
973 * subtracting multiples of the RX period. See e.g. the CSL
974 * documentation in this API.
975 *
976 * Additionally this parameter MAY be used by drivers to discipline
977 * their local representation of a distributed network clock by deriving
978 * synchronization instants related to a remote representation of the
979 * same clock (as in PTP).
980 *
981 * @note Available in any interface operational state.
982 *
983 * @note Required for Thread 1.2 Coordinated Sampled Listening feature
984 * (see Thread specification 1.2.0, ch. 3.2.6.3).
985 */
986 IEEE802154_CONFIG_EXPECTED_RX_TIME,
987
988 /**
989 * Adds a header information element (IE) to be injected into enhanced
990 * ACK frames generated by the driver if the given destination address
991 * filter matches.
992 *
993 * @details Drivers implementing the @ref IEEE802154_HW_RX_TX_ACK
994 * capability generate ACK frames autonomously. Setting this
995 * configuration will ask the driver to inject the given preconfigured
996 * header IE when generating enhanced ACK frames where appropriate by
997 * the standard. IEs for all other frame types SHALL be provided by L2.
998 *
999 * The driver shall return -ENOTSUP in the following cases:
1000 * - It does not support the @ref IEEE802154_HW_RX_TX_ACK,
1001 * - It does not support header IE injection,
1002 * - It cannot inject the runtime fields on-the-fly required for the
1003 * given IE element ID (see list below).
1004 *
1005 * Enhanced ACK header IEs (element IDs in parentheses) that either
1006 * need to be rejected or explicitly supported and parsed by the driver
1007 * because they require on-the-fly timing information injection are:
1008 * - CSL IE (0x1a)
1009 * - Rendezvous Time IE (0x1d)
1010 * - Time Correction IE (0x1e)
1011 *
1012 * Drivers accepting this configuration option SHALL check the list of
1013 * configured IEs for each outgoing enhanced ACK frame, select the ones
1014 * appropriate for the received frame based on their element ID, inject
1015 * any required runtime information on-the-fly and include the selected
1016 * IEs into the enhanced ACK frame's MAC header.
1017 *
1018 * Drivers supporting enhanced ACK header IE injection SHALL
1019 * autonomously inject header termination IEs as required by the
1020 * standard.
1021 *
1022 * A destination short address and extended address MAY be given by L2
1023 * to filter the devices to which the given IE is included. Setting the
1024 * short address to the broadcast address and the extended address to
1025 * NULL will inject the given IE into all ACK frames unless a more
1026 * specific filter is also present for any given destination device
1027 * (fallback configuration). L2 SHALL take care to either set both
1028 * address fields to valid device addresses or none.
1029 *
1030 * This configuration type may be called several times with distinct
1031 * element IDs and/or addresses. The driver SHALL either store all
1032 * configured IE/address combinations or return -ENOMEM if no
1033 * additional configuration can be stored.
1034 *
1035 * Configuring a header IE with a previously configured element ID and
1036 * address filter SHALL override the previous configuration. This
1037 * implies that repetition of the same header IE/address combination is
1038 * NOT supported.
1039 *
1040 * Configuring an existing element ID/address filter combination with
1041 * the header IE's length field set to zero SHALL remove that
1042 * configuration. SHALL remove the fallback configuration if no address
1043 * is given.
1044 *
1045 * Configuring a header IE for an address filter with the header IE
1046 * pointer set to NULL SHALL remove all header IE's for that address
1047 * filter. SHALL remove ALL header IE configuration (including but not
1048 * limited to fallbacks) if no address is given.
1049 *
1050 * If any of the deleted configurations didn't previously exist, then
1051 * the call SHALL be ignored. Whenever the length field is set to zero,
1052 * the content fields MUST NOT be accessed by the driver.
1053 *
1054 * L2 SHALL minimize the space required to keep IE configuration inside
1055 * the driver by consolidating address filters and by removing
1056 * configuration that is no longer required.
1057 *
1058 * @note requires @ref IEEE802154_HW_RX_TX_ACK capability and is
1059 * available in any interface operational state. Currently we only
1060 * support header IEs but that may change in the future.
1061 *
1062 * @note Required for Thread 1.2 Coordinated Sampled Listening feature
1063 * (see Thread specification 1.2.0, ch. 3.2.6.3).
1064 *
1065 * @note Required for Thread 1.2 Link Metrics feature (see Thread
1066 * specification 1.2.0, ch. 4.11.3.3).
1067 */
1068 IEEE802154_CONFIG_ENH_ACK_HEADER_IE,
1069
1070 /**
1071 * Enable/disable RxOnWhenIdle MAC PIB attribute (Table 8-94).
1072 *
1073 * Since there is no clear guidance in IEEE 802.15.4 specification about the definition of
1074 * an "idle period", this implementation expects that drivers use the RxOnWhenIdle attribute
1075 * to determine next radio state (false --> off, true --> receive) in the following
1076 * scenarios:
1077 * - Finalization of a regular frame reception task, provided that:
1078 * - The frame is received without errors and passes the filtering and it's not an
1079 * spurious ACK.
1080 * - ACK is not requested or transmission of ACK is not possible due to internal
1081 * conditions.
1082 * - Finalization of a frame transmission or transmission of an ACK frame, when ACK is not
1083 * requested in the transmitted frame.
1084 * - Finalization of the reception operation of a requested ACK due to:
1085 * - ACK timeout expiration.
1086 * - Reception of an invalid ACK or not an ACK frame.
1087 * - Reception of the proper ACK, unless the transmitted frame was a Data Request Command
1088 * and the frame pending bit on the received ACK is set to true. In this case the radio
1089 * platform implementation SHOULD keep the receiver on until a determined timeout which
1090 * triggers an idle period start.
1091 * - Finalization of a stand alone CCA task.
1092 * - Finalization of a CCA operation with busy result during CSMA/CA procedure.
1093 * - Finalization of an Energy Detection task.
1094 * - Finalization of a scheduled radio reception window
1095 * (see @ref IEEE802154_CONFIG_RX_SLOT).
1096 */
1097 IEEE802154_CONFIG_RX_ON_WHEN_IDLE,
1098
1099 /** Number of types defined in ieee802154_config_type. */
1100 IEEE802154_CONFIG_COMMON_COUNT,
1101
1102 /** This and higher values are specific to the protocol- or driver-specific extensions. */
1103 IEEE802154_CONFIG_PRIV_START = IEEE802154_CONFIG_COMMON_COUNT,
1104 };
1105
1106 /**
1107 * Configuring an RX slot with the start parameter set to this value will cancel
1108 * and delete any previously configured RX slot.
1109 */
1110 #define IEEE802154_CONFIG_RX_SLOT_NONE -1LL
1111
1112 /**
1113 * Configuring an RX slot with this start parameter while the driver is "down",
1114 * will keep RX off when the driver is being started. Configuring an RX slot
1115 * with this start value while the driver is "up" will immediately switch RX off
1116 * until either the slot is deleted, see @ref IEEE802154_CONFIG_RX_SLOT_NONE or
1117 * a slot with a future start parameter is configured and that start time
1118 * arrives.
1119 */
1120 #define IEEE802154_CONFIG_RX_SLOT_OFF 0LL
1121
1122 /** IEEE 802.15.4 driver configuration data. */
1123 struct ieee802154_config {
1124 /** Configuration data. */
1125 union {
1126 /** see @ref IEEE802154_CONFIG_AUTO_ACK_FPB */
1127 struct {
1128 bool enabled; /**< Is auto ACK FPB enabled */
1129 enum ieee802154_fpb_mode mode; /**< Auto ACK FPB mode */
1130 } auto_ack_fpb;
1131
1132 /** see @ref IEEE802154_CONFIG_ACK_FPB */
1133 struct {
1134 uint8_t *addr; /**< little endian for both short and extended address */
1135 bool extended; /**< Is extended address */
1136 bool enabled; /**< Is enabled */
1137 } ack_fpb;
1138
1139 /** see @ref IEEE802154_CONFIG_PAN_COORDINATOR */
1140 bool pan_coordinator;
1141
1142 /** see @ref IEEE802154_CONFIG_PROMISCUOUS */
1143 bool promiscuous;
1144
1145 /** see @ref IEEE802154_CONFIG_RX_ON_WHEN_IDLE */
1146 bool rx_on_when_idle;
1147
1148 /** see @ref IEEE802154_CONFIG_EVENT_HANDLER */
1149 ieee802154_event_cb_t event_handler;
1150
1151 /**
1152 * @brief see @ref IEEE802154_CONFIG_MAC_KEYS
1153 *
1154 * @details Pointer to an array containing a list of keys used
1155 * for MAC encryption. Refer to secKeyIdLookupDescriptor and
1156 * secKeyDescriptor in IEEE 802.15.4
1157 *
1158 * The key_value field points to a buffer containing the 16 byte
1159 * key. The buffer SHALL be copied by the driver before
1160 * returning from the call.
1161 *
1162 * The variable length array is terminated by key_value field
1163 * set to NULL.
1164 */
1165 struct ieee802154_key *mac_keys;
1166
1167 /** see @ref IEEE802154_CONFIG_FRAME_COUNTER */
1168 uint32_t frame_counter;
1169
1170 /** see @ref IEEE802154_CONFIG_RX_SLOT */
1171 struct {
1172 /**
1173 * Nanosecond resolution timestamp relative to the
1174 * network subsystem's local clock defining the start of
1175 * the RX window during which the receiver is expected
1176 * to be listening (i.e. not including any driver
1177 * startup times).
1178 *
1179 * Configuring an rx_slot with the start attribute set
1180 * to -1 will cancel and delete any previously active rx
1181 * slot.
1182 */
1183 net_time_t start;
1184
1185 /**
1186 * Nanosecond resolution duration of the RX window
1187 * relative to the above RX window start time during
1188 * which the receiver is expected to be listening (i.e.
1189 * not including any shutdown times). Only positive
1190 * values larger than or equal zero are allowed.
1191 *
1192 * Setting the duration to zero will disable the
1193 * receiver, no matter what the start parameter.
1194 */
1195 net_time_t duration;
1196
1197 /**
1198 * Used channel
1199 */
1200 uint8_t channel;
1201 } rx_slot;
1202
1203 /**
1204 * see @ref IEEE802154_CONFIG_CSL_PERIOD
1205 *
1206 * in CPU byte order
1207 */
1208 uint32_t csl_period;
1209
1210 /**
1211 * see @ref IEEE802154_CONFIG_EXPECTED_RX_TIME
1212 */
1213 net_time_t expected_rx_time;
1214
1215 /** see @ref IEEE802154_CONFIG_ENH_ACK_HEADER_IE */
1216 struct {
1217 /**
1218 * Pointer to the header IE, see section 7.4.2.1,
1219 * figure 7-21
1220 *
1221 * Certain header IEs may be incomplete if they require
1222 * timing information to be injected at runtime
1223 * on-the-fly, see the list in @ref
1224 * IEEE802154_CONFIG_ENH_ACK_HEADER_IE.
1225 */
1226 struct ieee802154_header_ie *header_ie;
1227
1228 /**
1229 * Filters the devices that will receive this IE by
1230 * extended address. MAY be set to NULL to configure a
1231 * fallback for all devices (implies that short_addr
1232 * MUST also be set to @ref
1233 * IEEE802154_BROADCAST_ADDRESS).
1234 *
1235 * in big endian
1236 */
1237 const uint8_t *ext_addr;
1238
1239 /**
1240 * Filters the devices that will receive this IE by
1241 * short address. MAY be set to @ref
1242 * IEEE802154_BROADCAST_ADDRESS to configure a fallback
1243 * for all devices (implies that ext_addr MUST also set
1244 * to NULL in this case).
1245 *
1246 * in CPU byte order
1247 */
1248 uint16_t short_addr;
1249
1250 /**
1251 * Flag for purging enh ACK header IEs.
1252 * When flag is set to true, driver should remove all existing
1253 * header IEs, and all other entries in config should be ignored.
1254 * This means that purging current header IEs and
1255 * configuring a new one in the same call is not allowed.
1256 */
1257 bool purge_ie;
1258 } ack_ie;
1259 };
1260 };
1261
1262 /**
1263 * @brief IEEE 802.15.4 driver attributes.
1264 *
1265 * See @ref ieee802154_attr_value and @ref ieee802154_radio_api for usage
1266 * details.
1267 */
1268 enum ieee802154_attr {
1269 /**
1270 * Retrieves a bit field with supported channel pages. This attribute
1271 * SHALL be implemented by all drivers.
1272 */
1273 IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_PAGES,
1274
1275 /**
1276 * Retrieves a pointer to the array of supported channel ranges within
1277 * the currently configured channel page. This attribute SHALL be
1278 * implemented by all drivers.
1279 */
1280 IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_RANGES,
1281
1282 /**
1283 * Retrieves a bit field with supported HRP UWB nominal pulse repetition
1284 * frequencies. This attribute SHALL be implemented by all devices that
1285 * support channel page four (HRP UWB).
1286 */
1287 IEEE802154_ATTR_PHY_HRP_UWB_SUPPORTED_PRFS,
1288
1289 /** Number of attributes defined in ieee802154_attr. */
1290 IEEE802154_ATTR_COMMON_COUNT,
1291
1292 /** This and higher values are specific to the protocol- or
1293 * driver-specific extensions.
1294 */
1295 IEEE802154_ATTR_PRIV_START = IEEE802154_ATTR_COMMON_COUNT,
1296 };
1297
1298 /**
1299 * @brief IEEE 802.15.4 driver attribute values.
1300 *
1301 * @details This structure is reserved to scalar and structured attributes that
1302 * originate in the driver implementation and can neither be implemented as
1303 * boolean @ref ieee802154_hw_caps nor be derived directly or indirectly by the
1304 * MAC (L2) layer. In particular this structure MUST NOT be used to return
1305 * configuration data that originate from L2.
1306 *
1307 * @note To keep this union reasonably small, any attribute requiring a large
1308 * memory area, SHALL be provided pointing to static memory allocated by the
1309 * driver and valid throughout the lifetime of the driver instance.
1310 */
1311 struct ieee802154_attr_value {
1312 union {
1313 /* TODO: Implement configuration of phyCurrentPage once drivers
1314 * need to support channel page switching at runtime.
1315 */
1316 /**
1317 * @brief A bit field that represents the supported channel
1318 * pages, see @ref ieee802154_phy_channel_page.
1319 *
1320 * @note To keep the API extensible as required by the standard,
1321 * supported pages are modeled as a bitmap to support drivers
1322 * that implement runtime switching between multiple channel
1323 * pages.
1324 *
1325 * @note Currently none of the Zephyr drivers implements more
1326 * than one channel page at runtime, therefore only one bit will
1327 * be set and the current channel page (see the PHY PIB
1328 * attribute phyCurrentPage, section 11.3, table 11-2) is
1329 * considered to be read-only, fixed and "well known" via the
1330 * supported channel pages attribute.
1331 */
1332 uint32_t phy_supported_channel_pages;
1333
1334 /**
1335 * @brief Pointer to a structure representing channel ranges
1336 * currently available on the selected channel page.
1337 *
1338 * @warning The pointer must be valid and constant throughout
1339 * the life of the interface.
1340 *
1341 * @details The selected channel page corresponds to the
1342 * phyCurrentPage PHY PIB attribute, see the description of
1343 * phy_supported_channel_pages above. Currently it can be
1344 * retrieved via the @ref
1345 * IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_PAGES attribute.
1346 *
1347 * Most drivers will expose a single channel page with a single,
1348 * often zero-based, fixed channel range.
1349 *
1350 * Some notable exceptions:
1351 * * The legacy channel page (zero) exposes ranges in different
1352 * bands and even PHYs that are usually not implemented by a
1353 * single driver.
1354 * * SUN and LECIM PHYs specify a large number of bands and
1355 * operating modes on a single page with overlapping channel
1356 * ranges each. Some of these ranges are not zero-based or
1357 * contain "holes". This explains why several ranges may be
1358 * necessary to represent all available channels.
1359 * * UWB PHYs often support partial channel ranges on the same
1360 * channel page depending on the supported bands.
1361 *
1362 * In these cases, drivers may expose custom configuration
1363 * attributes (Kconfig, devicetree, runtime, ...) that allow
1364 * switching between sub-ranges within the same channel page
1365 * (e.g. switching between SubG and 2.4G bands on channel page
1366 * zero or switching between multiple operating modes in the SUN
1367 * or LECIM PHYs.
1368 */
1369 const struct ieee802154_phy_supported_channels *phy_supported_channels;
1370
1371 /* TODO: Allow the PRF to be configured for each TX call once
1372 * drivers need to support PRF switching at runtime.
1373 */
1374 /**
1375 * @brief A bit field representing supported HRP UWB pulse
1376 * repetition frequencies (PRF), see enum
1377 * ieee802154_phy_hrp_uwb_nominal_prf.
1378 *
1379 * @note Currently none of the Zephyr HRP UWB drivers implements
1380 * more than one nominal PRF at runtime, therefore only one bit
1381 * will be set and the current PRF (UwbPrf, MCPS-DATA.request,
1382 * section 8.3.2, table 8-88) is considered to be read-only,
1383 * fixed and "well known" via the supported PRF attribute.
1384 */
1385 uint32_t phy_hrp_uwb_supported_nominal_prfs;
1386 };
1387 };
1388
1389 /**
1390 * @brief Helper function to handle channel page and range to be called from
1391 * drivers' attr_get() implementation. This only applies to drivers with a
1392 * single channel page.
1393 *
1394 * @param attr The attribute to be retrieved.
1395 * @param phy_supported_channel_page The driver's unique channel page.
1396 * @param phy_supported_channels Pointer to the structure that contains the
1397 * driver's channel range or ranges.
1398 * @param value The pointer to the value struct provided by the user.
1399 *
1400 * @retval 0 if the attribute could be resolved
1401 * @retval -ENOENT if the attribute could not be resolved
1402 */
ieee802154_attr_get_channel_page_and_range(enum ieee802154_attr attr,const enum ieee802154_phy_channel_page phy_supported_channel_page,const struct ieee802154_phy_supported_channels * phy_supported_channels,struct ieee802154_attr_value * value)1403 static inline int ieee802154_attr_get_channel_page_and_range(
1404 enum ieee802154_attr attr,
1405 const enum ieee802154_phy_channel_page phy_supported_channel_page,
1406 const struct ieee802154_phy_supported_channels *phy_supported_channels,
1407 struct ieee802154_attr_value *value)
1408 {
1409 switch (attr) {
1410 case IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_PAGES:
1411 value->phy_supported_channel_pages = phy_supported_channel_page;
1412 return 0;
1413
1414 case IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_RANGES:
1415 value->phy_supported_channels = phy_supported_channels;
1416 return 0;
1417
1418 default:
1419 return -ENOENT;
1420 }
1421 }
1422
1423 /**
1424 * @brief IEEE 802.15.4 driver interface API.
1425 *
1426 * @note This structure is called "radio" API for backwards compatibility. A
1427 * better name would be "IEEE 802.15.4 driver API" as typical drivers will not
1428 * only implement L1/radio (PHY) features but also L2 (MAC) features if the
1429 * vendor-specific driver hardware or firmware offers offloading opportunities.
1430 *
1431 * @details While L1-level driver features are exclusively implemented by
1432 * drivers and MAY be mandatory to support certain application requirements, L2
1433 * features SHOULD be optional by default and only need to be implemented for
1434 * performance optimization or precise timing as deemed necessary by driver
1435 * maintainers. Fallback implementations ("Soft MAC") SHOULD be provided in the
1436 * driver-independent L2 layer for all L2/MAC features especially if these
1437 * features are not implemented in vendor hardware/firmware by a majority of
1438 * existing in-tree drivers. If, however, a driver offers offloading
1439 * opportunities then L2 implementations SHALL delegate performance critical or
1440 * resource intensive tasks to the driver.
1441 *
1442 * All drivers SHALL support two externally observable interface operational
1443 * states: "UP" and "DOWN". Drivers MAY additionally support a "TESTING"
1444 * interface state (see `continuous_carrier()`).
1445 *
1446 * The following rules apply:
1447 * * An interface is considered "UP" when it is able to transmit and receive
1448 * packets, "DOWN" otherwise (see precise definitions of the corresponding
1449 * ifOperStatus values in RFC 2863, section 3.1.14, @ref net_if_oper_state and
1450 * the `continuous_carrier()` exception below). A device that has its receiver
1451 * temporarily disabled during "UP" state due to an active receive window
1452 * configuration is still considered "UP".
1453 * * Upper layers will assume that the interface managed by the driver is "UP"
1454 * after a call to `start()` returned zero or `-EALREADY`. Upper layers assume
1455 * that the interface is "DOWN" after calling `stop()` returned zero or
1456 * `-EALREADY`.
1457 * * The driver SHALL block `start()`/`stop()` calls until the interface fully
1458 * transitioned to the new state (e.g. the receiver is operational, ongoing
1459 * transmissions were finished, etc.). Drivers SHOULD yield the calling thread
1460 * (i.e. "sleep") if waiting for the new state without CPU interaction is
1461 * possible.
1462 * * Drivers are responsible of guaranteeing atomicity of state changes.
1463 * Appropriate means of synchronization SHALL be implemented (locking, atomic
1464 * flags, ...).
1465 * * While the interface is "DOWN", the driver SHALL be placed in the lowest
1466 * possible power state. The driver MAY return from a call to `stop()` before
1467 * it reaches the lowest possible power state, i.e. manage power
1468 * asynchronously. While the interface is "UP", the driver SHOULD
1469 * autonomously and asynchronously transition to lower power states whenever
1470 * possible. If the driver claims to support timed RX/TX capabilities and the
1471 * upper layers configure an RX slot, then the driver SHALL immediately
1472 * transition (asynchronously) to the lowest possible power state until the
1473 * start of the RX slot or until a scheduled packet needs to be transmitted.
1474 * * The driver SHALL NOT change the interface's "UP"/"DOWN" state on its own.
1475 * Initially, the interface SHALL be in the "DOWN" state.
1476 * * Drivers that implement the optional `continuous_carrier()` operation will
1477 * be considered to be in the RFC 2863 "testing" ifOperStatus state if that
1478 * operation returns zero. This state is active until either `start()` or
1479 * `stop()` is called. If `continuous_carrier()` returns a non-zero value then
1480 * the previous state is assumed by upper layers.
1481 * * If calls to `start()`/`stop()` return any other value than zero or
1482 * `-EALREADY`, upper layers will consider the interface to be in a
1483 * "lowerLayerDown" state as defined in RFC 2863.
1484 * * The RFC 2863 "dormant", "unknown" and "notPresent" ifOperStatus states are
1485 * currently not supported. The "lowerLevelUp" state.
1486 * * The `ed_scan()`, `cca()` and `tx()` operations SHALL only be supported in
1487 * the "UP" state and return `-ENETDOWN` in any other state. See the
1488 * function-level API documentation below for further details.
1489 *
1490 * @note In case of devices that support timed RX/TX, the "UP" state is not
1491 * equal to "receiver enabled". If a receive window (i.e. RX slot, see @ref
1492 * IEEE802154_CONFIG_RX_SLOT) is configured before calling `start()` then the
1493 * receiver will not be enabled when transitioning to the "UP" state.
1494 * Configuring a receive window while the interface is "UP" will cause the
1495 * receiver to be disabled immediately until the configured reception time has
1496 * arrived.
1497 */
1498 struct ieee802154_radio_api {
1499 /**
1500 * @brief network interface API
1501 *
1502 * @note Network devices must extend the network interface API. It is
1503 * therefore mandatory to place it at the top of the driver API struct so
1504 * that it can be cast to a network interface.
1505 */
1506 struct net_if_api iface_api;
1507
1508 /**
1509 * @brief Get the device driver capabilities.
1510 *
1511 * @note Implementations SHALL be **isr-ok** and MUST NOT **sleep**. MAY
1512 * be called in any interface state once the driver is fully initialized
1513 * ("ready").
1514 *
1515 * @param dev pointer to IEEE 802.15.4 driver device
1516 *
1517 * @return Bit field with all supported device driver capabilities.
1518 */
1519 enum ieee802154_hw_caps (*get_capabilities)(const struct device *dev);
1520
1521 /**
1522 * @brief Clear Channel Assessment - Check channel's activity
1523 *
1524 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. SHALL
1525 * return -ENETDOWN unless the interface is "UP".
1526 *
1527 * @param dev pointer to IEEE 802.15.4 driver device
1528 *
1529 * @retval 0 the channel is available
1530 * @retval -EBUSY The channel is busy.
1531 * @retval -EWOULDBLOCK The operation is called from ISR context but
1532 * temporarily cannot be executed without blocking.
1533 * @retval -ENETDOWN The interface is not "UP".
1534 * @retval -ENOTSUP CCA is not supported by this driver.
1535 * @retval -EIO The CCA procedure could not be executed.
1536 */
1537 int (*cca)(const struct device *dev);
1538
1539 /**
1540 * @brief Set current channel
1541 *
1542 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. SHALL
1543 * return -EIO unless the interface is either "UP" or "DOWN".
1544 *
1545 * @param dev pointer to IEEE 802.15.4 driver device
1546 * @param channel the number of the channel to be set in CPU byte order
1547 *
1548 * @retval 0 channel was successfully set
1549 * @retval -EALREADY The previous channel is the same as the requested
1550 * channel.
1551 * @retval -EINVAL The given channel is not within the range of valid
1552 * channels of the driver's current channel page, see the
1553 * IEEE802154_ATTR_PHY_SUPPORTED_CHANNEL_RANGES driver attribute.
1554 * @retval -EWOULDBLOCK The operation is called from ISR context but
1555 * temporarily cannot be executed without blocking.
1556 * @retval -ENOTSUP The given channel is within the range of valid
1557 * channels of the driver's current channel page but unsupported by the
1558 * current driver.
1559 * @retval -EIO The channel could not be set.
1560 */
1561 int (*set_channel)(const struct device *dev, uint16_t channel);
1562
1563 /**
1564 * @brief Set/Unset PAN ID, extended or short address filters.
1565 *
1566 * @note requires IEEE802154_HW_FILTER capability.
1567 *
1568 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. SHALL
1569 * return -EIO unless the interface is either "UP" or "DOWN".
1570 *
1571 * @param dev pointer to IEEE 802.15.4 driver device
1572 * @param set true to set the filter, false to remove it
1573 * @param type the type of entity to be added/removed from the filter
1574 * list (a PAN ID or a source/destination address)
1575 * @param filter the entity to be added/removed from the filter list
1576 *
1577 * @retval 0 The filter was successfully added/removed.
1578 * @retval -EINVAL The given filter entity or filter entity type
1579 * was not valid.
1580 * @retval -EWOULDBLOCK The operation is called from ISR context but
1581 * temporarily cannot be executed without blocking.
1582 * @retval -ENOTSUP Setting/removing this filter or filter type
1583 * is not supported by this driver.
1584 * @retval -EIO Error while setting/removing the filter.
1585 */
1586 int (*filter)(const struct device *dev,
1587 bool set,
1588 enum ieee802154_filter_type type,
1589 const struct ieee802154_filter *filter);
1590
1591 /**
1592 * @brief Set TX power level in dbm
1593 *
1594 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. SHALL
1595 * return -EIO unless the interface is either "UP" or "DOWN".
1596 *
1597 * @param dev pointer to IEEE 802.15.4 driver device
1598 * @param dbm TX power in dbm
1599 *
1600 * @retval 0 The TX power was successfully set.
1601 * @retval -EINVAL The given dbm value is invalid or not supported by
1602 * the driver.
1603 * @retval -EWOULDBLOCK The operation is called from ISR context but
1604 * temporarily cannot be executed without blocking.
1605 * @retval -EIO The TX power could not be set.
1606 */
1607 int (*set_txpower)(const struct device *dev, int16_t dbm);
1608
1609 /**
1610 * @brief Transmit a packet fragment as a single frame
1611 *
1612 * @details Depending on the level of offloading features supported by
1613 * the driver, the frame MAY not be fully encrypted/authenticated or it
1614 * MAY not contain an FCS. It is the responsibility of L2
1615 * implementations to prepare the frame according to the offloading
1616 * capabilities announced by the driver and to decide whether CCA,
1617 * CSMA/CA, ACK or retransmission procedures need to be executed outside
1618 * ("soft MAC") or inside ("hard MAC") the driver .
1619 *
1620 * All frames originating from L2 SHALL have all required IEs
1621 * pre-allocated and pre-filled such that the driver does not have to
1622 * parse and manipulate IEs at all. This includes ACK packets if the
1623 * driver does not have the @ref IEEE802154_HW_RX_TX_ACK capability.
1624 * Also see @ref IEEE802154_CONFIG_ENH_ACK_HEADER_IE for drivers that
1625 * have the @ref IEEE802154_HW_RX_TX_ACK capability.
1626 *
1627 * IEs that cannot be prepared by L2 unless the TX time is known (e.g.
1628 * CSL IE, Rendezvous Time IE, Time Correction IE, ...) SHALL be sent in
1629 * any of the timed TX modes with appropriate timing information
1630 * pre-filled in the IE such that drivers do not have to parse and
1631 * manipulate IEs at all unless the frame is generated by the driver
1632 * itself.
1633 *
1634 * In case any of the timed TX modes is supported and used (see @ref
1635 * ieee802154_hw_caps and @ref ieee802154_tx_mode), the driver SHALL
1636 * take responsibility of scheduling and sending the packet at the
1637 * precise programmed time autonomously without further interaction by
1638 * upper layers. The call to `tx()` will block until the package has
1639 * either been sent successfully (possibly including channel acquisition
1640 * and packet acknowledgment) or a terminal transmission error occurred.
1641 * The driver SHALL sleep and keep power consumption to the lowest
1642 * possible level until the scheduled transmission time arrives or
1643 * during any other idle waiting time.
1644 *
1645 * @warning The driver SHALL NOT take ownership of the given network
1646 * packet and frame (fragment) buffer. Any data required by the driver
1647 * including the actual frame content must be read synchronously and
1648 * copied internally if needed at a later time (e.g. the contents of IEs
1649 * required for protocol configuration, states of frame counters,
1650 * sequence numbers, etc). Both, the packet and the buffer MAY be
1651 * re-used or released by upper layers immediately after the function
1652 * returns.
1653 *
1654 * @note Implementations MAY **sleep** and will usually NOT be
1655 * **isr-ok** - especially when timed TX, CSMA/CA, retransmissions,
1656 * auto-ACK or any other offloading feature is supported that implies
1657 * considerable idle waiting time. SHALL return `-ENETDOWN` unless the
1658 * interface is "UP".
1659 *
1660 * @param dev pointer to IEEE 802.15.4 driver device
1661 * @param mode the transmission mode, some of which require specific
1662 * offloading capabilities.
1663 * @param pkt pointer to the network packet to be transmitted.
1664 * @param frag pointer to a network buffer containing a single fragment
1665 * with the frame data to be transmitted
1666 *
1667 * @retval 0 The frame was successfully sent or scheduled. If the driver
1668 * supports ACK offloading and the frame requested acknowledgment (AR bit
1669 * set), this means that the packet was successfully acknowledged by its
1670 * peer.
1671 * @retval -EINVAL Invalid packet (e.g. an expected IE is missing or the
1672 * encryption/authentication state is not as expected).
1673 * @retval -EBUSY The frame could not be sent because the medium was
1674 * busy (CSMA/CA or CCA offloading feature only).
1675 * @retval -ENOMSG The frame was not confirmed by an ACK packet (TX ACK
1676 * offloading feature only) or the received ACK packet was invalid.
1677 * @retval -ENOBUFS The frame could not be scheduled due to missing
1678 * internal resources (timed TX offloading feature only).
1679 * @retval -ENETDOWN The interface is not "UP".
1680 * @retval -ENOTSUP The given TX mode is not supported.
1681 * @retval -EIO The frame could not be sent due to some unspecified
1682 * driver error (e.g. the driver being busy).
1683 */
1684 int (*tx)(const struct device *dev, enum ieee802154_tx_mode mode,
1685 struct net_pkt *pkt, struct net_buf *frag);
1686
1687 /**
1688 * @brief Start the device.
1689 *
1690 * @details Upper layers will assume the interface is "UP" if this
1691 * operation returns with zero or `-EALREADY`. The interface is placed
1692 * in receive mode before returning from this operation unless an RX
1693 * slot has been configured (even if it lies in the past, see @ref
1694 * IEEE802154_CONFIG_RX_SLOT).
1695 *
1696 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. MAY be
1697 * called in any interface state once the driver is fully initialized
1698 * ("ready").
1699 *
1700 * @param dev pointer to IEEE 802.15.4 driver device
1701 *
1702 * @retval 0 The driver was successfully started.
1703 * @retval -EALREADY The driver was already "UP".
1704 * @retval -EWOULDBLOCK The operation is called from ISR context but
1705 * temporarily cannot be executed without blocking.
1706 * @retval -EIO The driver could not be started.
1707 */
1708 int (*start)(const struct device *dev);
1709
1710 /**
1711 * @brief Stop the device.
1712 *
1713 * @details Upper layers will assume the interface is "DOWN" if this
1714 * operation returns with zero or `-EALREADY`. The driver switches off
1715 * the receiver before returning if it was previously on. The driver
1716 * enters the lowest possible power mode after this operation is called.
1717 * This MAY happen asynchronously (i.e. after the operation already
1718 * returned control).
1719 *
1720 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. MAY be
1721 * called in any interface state once the driver is fully initialized
1722 * ("ready").
1723 *
1724 * @param dev pointer to IEEE 802.15.4 driver device
1725 *
1726 * @retval 0 The driver was successfully stopped.
1727 * @retval -EWOULDBLOCK The operation is called from ISR context but
1728 * temporarily cannot be executed without blocking.
1729 * @retval -EALREADY The driver was already "DOWN".
1730 * @retval -EIO The driver could not be stopped.
1731 */
1732 int (*stop)(const struct device *dev);
1733
1734 /**
1735 * @brief Start continuous carrier wave transmission.
1736 *
1737 * @details The method blocks until the interface has started to emit a
1738 * continuous carrier. To leave this mode, `start()` or `stop()` should
1739 * be called, which will put the driver back into the "UP" or "DOWN"
1740 * states, respectively.
1741 *
1742 * @note Implementations MAY **sleep** and will usually NOT be
1743 * **isr-ok**. MAY be called in any interface state once the driver is
1744 * fully initialized ("ready").
1745 *
1746 * @param dev pointer to IEEE 802.15.4 driver device
1747 *
1748 * @retval 0 continuous carrier wave transmission started
1749 * @retval -EALREADY The driver was already in "TESTING" state and
1750 * emitting a continuous carrier.
1751 * @retval -EIO not started
1752 */
1753 int (*continuous_carrier)(const struct device *dev);
1754
1755 /**
1756 * @brief Set or update driver configuration.
1757 *
1758 * @details The method blocks until the interface has been reconfigured
1759 * atomically with respect to ongoing package reception, transmission or
1760 * any other ongoing driver operation.
1761 *
1762 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. MAY be
1763 * called in any interface state once the driver is fully initialized
1764 * ("ready"). Some configuration options may not be supported in all
1765 * interface operational states, see the detailed specifications in @ref
1766 * ieee802154_config_type. In this case the operation returns `-EACCES`.
1767 *
1768 * @param dev pointer to IEEE 802.15.4 driver device
1769 * @param type the configuration type to be set
1770 * @param config the configuration parameters to be set for the given
1771 * configuration type
1772 *
1773 * @retval 0 configuration successful
1774 * @retval -EINVAL The configuration parameters are invalid for the
1775 * given configuration type.
1776 * @retval -ENOTSUP The given configuration type is not supported by
1777 * this driver.
1778 * @retval -EACCES The given configuration type is supported by this
1779 * driver but cannot be configured in the current interface operational
1780 * state.
1781 * @retval -ENOMEM The configuration cannot be saved due to missing
1782 * memory resources.
1783 * @retval -ENOENT The resource referenced in the configuration
1784 * parameters cannot be found in the configuration.
1785 * @retval -EWOULDBLOCK The operation is called from ISR context but
1786 * temporarily cannot be executed without blocking.
1787 * @retval -EIO An internal error occurred while trying to configure the
1788 * given configuration parameter.
1789 */
1790 int (*configure)(const struct device *dev,
1791 enum ieee802154_config_type type,
1792 const struct ieee802154_config *config);
1793
1794 /**
1795 * @brief Run an energy detection scan.
1796 *
1797 * @note requires IEEE802154_HW_ENERGY_SCAN capability
1798 *
1799 * @note The radio channel must be set prior to calling this function.
1800 *
1801 * @note Implementations SHALL be **isr-ok** and MAY **sleep**. SHALL
1802 * return `-ENETDOWN` unless the interface is "UP".
1803 *
1804 * @param dev pointer to IEEE 802.15.4 driver device
1805 * @param duration duration of energy scan in ms
1806 * @param done_cb function called when the energy scan has finished
1807 *
1808 * @retval 0 the energy detection scan was successfully scheduled
1809 *
1810 * @retval -EBUSY the energy detection scan could not be scheduled at
1811 * this time
1812 * @retval -EALREADY a previous energy detection scan has not finished
1813 * yet.
1814 * @retval -ENETDOWN The interface is not "UP".
1815 * @retval -ENOTSUP This driver does not support energy scans.
1816 * @retval -EIO The energy detection procedure could not be executed.
1817 */
1818 int (*ed_scan)(const struct device *dev,
1819 uint16_t duration,
1820 energy_scan_done_cb_t done_cb);
1821
1822 /**
1823 * @brief Get the current time in nanoseconds relative to the network
1824 * subsystem's local uptime clock as represented by this network
1825 * interface.
1826 *
1827 * See @ref net_time_t for semantic details.
1828 *
1829 * @note requires IEEE802154_HW_TXTIME and/or IEEE802154_HW_RXTIME
1830 * capabilities. Implementations SHALL be **isr-ok** and MUST NOT
1831 * **sleep**. MAY be called in any interface state once the driver is
1832 * fully initialized ("ready").
1833 *
1834 * @param dev pointer to IEEE 802.15.4 driver device
1835 *
1836 * @return nanoseconds relative to the network subsystem's local clock,
1837 * -1 if an error occurred or the operation is not supported
1838 */
1839 net_time_t (*get_time)(const struct device *dev);
1840
1841 /**
1842 * @brief Get the current estimated worst case accuracy (maximum ±
1843 * deviation from the nominal frequency) of the network subsystem's
1844 * local clock used to calculate tolerances and guard times when
1845 * scheduling delayed receive or transmit radio operations.
1846 *
1847 * The deviation is given in units of PPM (parts per million).
1848 *
1849 * @note requires IEEE802154_HW_TXTIME and/or IEEE802154_HW_RXTIME
1850 * capabilities.
1851 *
1852 * @note Implementations may estimate this value based on current
1853 * operating conditions (e.g. temperature). Implementations SHALL be
1854 * **isr-ok** and MUST NOT **sleep**. MAY be called in any interface
1855 * state once the driver is fully initialized ("ready").
1856 *
1857 * @param dev pointer to IEEE 802.15.4 driver device
1858 *
1859 * @return current estimated clock accuracy in PPM
1860 */
1861 uint8_t (*get_sch_acc)(const struct device *dev);
1862
1863 /**
1864 * @brief Get the value of a driver specific attribute.
1865 *
1866 * @note This function SHALL NOT return any values configurable by the
1867 * MAC (L2) layer. It is reserved to non-boolean (i.e. scalar or
1868 * structured) attributes that originate from the driver implementation
1869 * and cannot be directly or indirectly derived by L2. Boolean
1870 * attributes SHALL be implemented as @ref ieee802154_hw_caps.
1871 *
1872 * @note Implementations SHALL be **isr-ok** and MUST NOT **sleep**. MAY
1873 * be called in any interface state once the driver is fully initialized
1874 * ("ready").
1875 *
1876 * @retval 0 The requested attribute is supported by the driver and the
1877 * value can be retrieved from the corresponding @ref ieee802154_attr_value
1878 * member.
1879 *
1880 * @retval -ENOENT The driver does not provide the requested attribute.
1881 * The value structure has not been updated with attribute data. The
1882 * content of the value attribute is undefined.
1883 */
1884 int (*attr_get)(const struct device *dev,
1885 enum ieee802154_attr attr,
1886 struct ieee802154_attr_value *value);
1887 };
1888
1889 /* Make sure that the network interface API is properly setup inside
1890 * IEEE 802.15.4 driver API struct (it is the first one).
1891 */
1892 BUILD_ASSERT(offsetof(struct ieee802154_radio_api, iface_api) == 0);
1893
1894 /** @} */
1895
1896 /**
1897 * @name IEEE 802.15.4 driver utils
1898 * @{
1899 */
1900
1901 /** @cond INTERNAL_HIDDEN */
1902 #define IEEE802154_AR_FLAG_SET (0x20)
1903 /** INTERNAL_HIDDEN @endcond */
1904
1905 /**
1906 * @brief Check if the AR flag is set on the frame inside the given @ref
1907 * net_pkt.
1908 *
1909 * @param frag A valid pointer on a net_buf structure, must not be NULL,
1910 * and its length should be at least 1 byte (ImmAck frames are the
1911 * shortest supported frames with 3 bytes excluding FCS).
1912 *
1913 * @return true if AR flag is set, false otherwise
1914 */
ieee802154_is_ar_flag_set(struct net_buf * frag)1915 static inline bool ieee802154_is_ar_flag_set(struct net_buf *frag)
1916 {
1917 return (*frag->data & IEEE802154_AR_FLAG_SET);
1918 }
1919
1920 /** @} */
1921
1922 /**
1923 * @name IEEE 802.15.4 driver callbacks
1924 * @{
1925 */
1926
1927 /* TODO: Fix drivers to either unref the packet before they return NET_OK or to
1928 * return NET_CONTINUE instead. See note below.
1929 */
1930 /**
1931 * @brief IEEE 802.15.4 driver ACK handling callback into L2 that drivers must
1932 * call when receiving an ACK package.
1933 *
1934 * @details The IEEE 802.15.4 standard prescribes generic procedures for ACK
1935 * handling on L2 (MAC) level. L2 stacks therefore have to provides a
1936 * fast and re-usable generic implementation of this callback for
1937 * drivers to call when receiving an ACK packet.
1938 *
1939 * Note: This function is part of Zephyr's 802.15.4 stack driver -> L2
1940 * "inversion-of-control" adaptation API and must be implemented by all
1941 * IEEE 802.15.4 L2 stacks.
1942 *
1943 * @param iface A valid pointer on a network interface that received the packet
1944 * @param pkt A valid pointer on a packet to check
1945 *
1946 * @return NET_OK if L2 handles the ACK package, NET_CONTINUE or NET_DROP otherwise.
1947 *
1948 * @warning Deviating from other functions in the net stack returning
1949 * net_verdict, this function will not unref the package even if it returns
1950 * NET_OK.
1951 */
1952 extern enum net_verdict ieee802154_handle_ack(struct net_if *iface, struct net_pkt *pkt);
1953
1954 /**
1955 * @brief IEEE 802.15.4 driver initialization callback into L2 called by drivers
1956 * to initialize the active L2 stack for a given interface.
1957 *
1958 * @details Drivers must call this function as part of their own initialization
1959 * routine.
1960 *
1961 * Note: This function is part of Zephyr's 802.15.4 stack driver -> L2
1962 * "inversion-of-control" adaptation API and must be implemented by all
1963 * IEEE 802.15.4 L2 stacks.
1964 *
1965 * @param iface A valid pointer on a network interface
1966 */
1967 #ifndef CONFIG_IEEE802154_RAW_MODE
1968 extern void ieee802154_init(struct net_if *iface);
1969 #else
1970 #define ieee802154_init(_iface_)
1971 #endif /* CONFIG_IEEE802154_RAW_MODE */
1972
1973 /** @} */
1974
1975 #ifdef __cplusplus
1976 }
1977 #endif
1978
1979 /**
1980 * @}
1981 */
1982
1983 #endif /* ZEPHYR_INCLUDE_NET_IEEE802154_RADIO_H_ */
1984