1 /*
2 * Copyright (c) 2019, The OpenThread Authors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /**
30 * @file
31 * This file includes definitions for OpenThread radio abstraction.
32 */
33
34 #ifndef RADIO_HPP_
35 #define RADIO_HPP_
36
37 #include "openthread-core-config.h"
38
39 #include <openthread/radio_stats.h>
40 #include <openthread/platform/crypto.h>
41 #include <openthread/platform/radio.h>
42
43 #include "common/locator.hpp"
44 #include "common/non_copyable.hpp"
45 #include "common/numeric_limits.hpp"
46 #include "common/time.hpp"
47 #include "mac/mac_frame.hpp"
48
49 namespace ot {
50
51 static constexpr uint32_t kUsPerTenSymbols = OT_US_PER_TEN_SYMBOLS; ///< Time for 10 symbols in units of microseconds
52 static constexpr uint32_t kRadioHeaderShrDuration = 160; ///< Duration of SHR in us
53 static constexpr uint32_t kRadioHeaderPhrDuration = 32; ///< Duration of PHR in us
54
55 static constexpr int8_t kRadioPowerInvalid = OT_RADIO_POWER_INVALID; ///< Invalid TX power value
56
57 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
58 /**
59 * Minimum CSL period supported in units of 10 symbols.
60 *
61 */
62 static constexpr uint64_t kMinCslPeriod = OPENTHREAD_CONFIG_MAC_CSL_MIN_PERIOD * 1000 / kUsPerTenSymbols;
63 static constexpr uint64_t kMaxCslTimeout = OPENTHREAD_CONFIG_MAC_CSL_MAX_TIMEOUT;
64 #endif
65
66 /**
67 * @addtogroup core-radio
68 *
69 * @brief
70 * This module includes definitions for OpenThread radio abstraction.
71 *
72 * @{
73 *
74 */
75
76 /**
77 * Implements the radio statistics logic.
78 *
79 * The radio statistics are the time when the radio in TX/RX/radio state.
80 * Since this class collects these statistics from pure software level and no platform API is involved, a simplified
81 * model is used to calculate the time of different radio states. The data may not be very accurate, but it's
82 * sufficient to provide a general understanding of the proportion of time a device is in different radio states.
83 *
84 * The simplified model is:
85 * - The RadioStats is only aware of 2 states: RX and sleep.
86 * - Each time `Radio::Receive` or `Radio::Sleep` is called, it will check the current state and add the time since
87 * last time the methods were called. For example, `Sleep` is first called and `Receive` is called after 1 second,
88 * then 1 second will be added to SleepTime and the current state switches to `Receive`.
89 * - The time of TX will be calculated from the callback of TransmitDone. If TX returns OT_ERROR_NONE or
90 * OT_ERROR_NO_ACK, the tx time will be added according to the number of bytes sent. And the SleepTime or RxTime
91 * will be reduced accordingly.
92 * - When `GetStats` is called, an operation will be executed to calcute the time for the last state. And the result
93 * will be returned.
94 *
95 */
96 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
97
98 #if !OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
99 #error "OPENTHREAD_CONFIG_RADIO_STATS_ENABLE requires OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE".
100 #endif
101
102 class RadioStatistics
103 {
104 public:
105 enum Status : uint8_t
106 {
107 kDisabled,
108 kSleep,
109 kReceive,
110 };
111
112 explicit RadioStatistics(void);
113
114 void RecordStateChange(Status aStatus);
115 void HandleReceiveAt(uint32_t aDurationUs);
116 void RecordTxDone(otError aError, uint16_t aPsduLength);
117 void RecordRxDone(otError aError);
118 const otRadioTimeStats &GetStats(void);
119 void ResetTime(void);
120
121 private:
122 void UpdateTime(void);
123
124 Status mStatus;
125 otRadioTimeStats mTimeStats;
126 TimeMicro mLastUpdateTime;
127 };
128 #endif // OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
129
130 /**
131 * Represents an OpenThread radio abstraction.
132 *
133 */
134 class Radio : public InstanceLocator, private NonCopyable
135 {
136 friend class Instance;
137
138 public:
139 static constexpr uint32_t kSymbolTime = OT_RADIO_SYMBOL_TIME;
140 static constexpr uint8_t kSymbolsPerOctet = OT_RADIO_SYMBOLS_PER_OCTET;
141 static constexpr uint32_t kPhyUsPerByte = kSymbolsPerOctet * kSymbolTime;
142 static constexpr uint8_t kChannelPage0 = OT_RADIO_CHANNEL_PAGE_0;
143 static constexpr uint8_t kChannelPage2 = OT_RADIO_CHANNEL_PAGE_2;
144 #if (OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT && OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT)
145 static constexpr uint16_t kNumChannelPages = 2;
146 static constexpr uint32_t kSupportedChannels =
147 OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK | OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK;
148 static constexpr uint8_t kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN;
149 static constexpr uint8_t kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX;
150 #elif OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
151 static constexpr uint16_t kNumChannelPages = 1;
152 static constexpr uint32_t kSupportedChannels = OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK;
153 static constexpr uint8_t kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN;
154 static constexpr uint8_t kChannelMax = OT_RADIO_915MHZ_OQPSK_CHANNEL_MAX;
155 #elif OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
156 static constexpr uint16_t kNumChannelPages = 1;
157 static constexpr uint32_t kSupportedChannels = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK;
158 static constexpr uint8_t kChannelMin = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN;
159 static constexpr uint8_t kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX;
160 #elif OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
161 static constexpr uint16_t kNumChannelPages = 1;
162 static constexpr uint32_t kSupportedChannels = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK;
163 static constexpr uint8_t kChannelMin = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN;
164 static constexpr uint8_t kChannelMax = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX;
165 #endif
166
167 static const uint8_t kSupportedChannelPages[kNumChannelPages];
168
169 static constexpr int8_t kInvalidRssi = OT_RADIO_RSSI_INVALID; ///< Invalid RSSI value.
170
171 static constexpr int8_t kDefaultReceiveSensitivity = -110; ///< Default receive sensitivity (in dBm).
172
173 static_assert((OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT || OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT ||
174 OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT),
175 "OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT "
176 "or OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT "
177 "or OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT "
178 "must be set to 1 to specify the radio mode");
179
180 /**
181 * Defines the callbacks from `Radio`.
182 *
183 */
184 class Callbacks : public InstanceLocator
185 {
186 friend class Radio;
187
188 public:
189 /**
190 * This callback method handles a "Receive Done" event from radio platform.
191 *
192 * @param[in] aFrame A pointer to the received frame or `nullptr` if the receive operation failed.
193 * @param[in] aError kErrorNone when successfully received a frame,
194 * kErrorAbort when reception was aborted and a frame was not received,
195 * kErrorNoBufs when a frame could not be received due to lack of rx buffer space.
196 *
197 */
198 void HandleReceiveDone(Mac::RxFrame *aFrame, Error aError);
199
200 /**
201 * This callback method handles a "Transmit Started" event from radio platform.
202 *
203 * @param[in] aFrame The frame that is being transmitted.
204 *
205 */
206 void HandleTransmitStarted(Mac::TxFrame &aFrame);
207
208 /**
209 * This callback method handles a "Transmit Done" event from radio platform.
210 *
211 * @param[in] aFrame The frame that was transmitted.
212 * @param[in] aAckFrame A pointer to the ACK frame, `nullptr` if no ACK was received.
213 * @param[in] aError kErrorNone when the frame was transmitted,
214 * kErrorNoAck when the frame was transmitted but no ACK was received,
215 * kErrorChannelAccessFailure tx could not take place due to activity on the
216 * channel, kErrorAbort when transmission was aborted for other reasons.
217 *
218 */
219 void HandleTransmitDone(Mac::TxFrame &aFrame, Mac::RxFrame *aAckFrame, Error aError);
220
221 /**
222 * This callback method handles "Energy Scan Done" event from radio platform.
223 *
224 * Is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability. It is called from
225 * `otPlatRadioEnergyScanDone()`.
226 *
227 * @param[in] aMaxRssi The maximum RSSI encountered on the scanned channel.
228 *
229 */
230 void HandleEnergyScanDone(int8_t aMaxRssi);
231
232 /**
233 * This callback method handles "Bus Latency Changed" event from radio platform.
234 *
235 */
236 void HandleBusLatencyChanged(void);
237
238 #if OPENTHREAD_CONFIG_DIAG_ENABLE
239 /**
240 * This callback method handles a "Receive Done" event from radio platform when diagnostics mode is enabled.
241 *
242 * @param[in] aFrame A pointer to the received frame or `nullptr` if the receive operation failed.
243 * @param[in] aError kErrorNone when successfully received a frame,
244 * kErrorAbort when reception was aborted and a frame was not received,
245 * kErrorNoBufs when a frame could not be received due to lack of rx buffer space.
246 *
247 */
248 void HandleDiagsReceiveDone(Mac::RxFrame *aFrame, Error aError);
249
250 /**
251 * This callback method handles a "Transmit Done" event from radio platform when diagnostics mode is enabled.
252 *
253 * @param[in] aFrame The frame that was transmitted.
254 * @param[in] aError kErrorNone when the frame was transmitted,
255 * kErrorNoAck when the frame was transmitted but no ACK was received,
256 * kErrorChannelAccessFailure tx could not take place due to activity on the
257 * channel, kErrorAbort when transmission was aborted for other reasons.
258 *
259 */
260 void HandleDiagsTransmitDone(Mac::TxFrame &aFrame, Error aError);
261 #endif
262
263 private:
Callbacks(Instance & aInstance)264 explicit Callbacks(Instance &aInstance)
265 : InstanceLocator(aInstance)
266 {
267 }
268 };
269
270 /**
271 * Initializes the `Radio` object.
272 *
273 * @param[in] aInstance A reference to the OpenThread instance.
274 *
275 */
Radio(Instance & aInstance)276 explicit Radio(Instance &aInstance)
277 : InstanceLocator(aInstance)
278 , mCallbacks(aInstance)
279 {
280 }
281
282 /**
283 * Gets the radio version string.
284 *
285 * @returns A pointer to the OpenThread radio version.
286 *
287 */
288 const char *GetVersionString(void);
289
290 /**
291 * Gets the factory-assigned IEEE EUI-64 for the device.
292 *
293 * @param[out] aIeeeEui64 A reference to `Mac::ExtAddress` to place the factory-assigned IEEE EUI-64.
294 *
295 */
296 void GetIeeeEui64(Mac::ExtAddress &aIeeeEui64);
297
298 /**
299 * Gets the radio capabilities.
300 *
301 * @returns The radio capability bit vector (see `OT_RADIO_CAP_*` definitions).
302 *
303 */
304 otRadioCaps GetCaps(void);
305
306 /**
307 * Gets the radio receive sensitivity value.
308 *
309 * @returns The radio receive sensitivity value in dBm.
310 *
311 */
312 int8_t GetReceiveSensitivity(void) const;
313
314 #if OPENTHREAD_RADIO
315 /**
316 * Initializes the states of the Thread radio.
317 *
318 */
319 void Init(void);
320 #endif
321
322 /**
323 * Sets the PAN ID for address filtering.
324 *
325 * @param[in] aPanId The IEEE 802.15.4 PAN ID.
326 *
327 */
328 void SetPanId(Mac::PanId aPanId);
329
330 /**
331 * Sets the Extended Address for address filtering.
332 *
333 * @param[in] aExtAddress The IEEE 802.15.4 Extended Address stored in little-endian byte order.
334 *
335 */
336 void SetExtendedAddress(const Mac::ExtAddress &aExtAddress);
337
338 /**
339 * Sets the Short Address for address filtering.
340 *
341 * @param[in] aShortAddress The IEEE 802.15.4 Short Address.
342 *
343 */
344 void SetShortAddress(Mac::ShortAddress aShortAddress);
345
346 /**
347 * Sets MAC key and key ID.
348 *
349 * @param[in] aKeyIdMode MAC key ID mode.
350 * @param[in] aKeyId Current MAC key index.
351 * @param[in] aPrevKey The previous MAC key.
352 * @param[in] aCurrKey The current MAC key.
353 * @param[in] aNextKey The next MAC key.
354 *
355 */
356 void SetMacKey(uint8_t aKeyIdMode,
357 uint8_t aKeyId,
358 const Mac::KeyMaterial &aPrevKey,
359 const Mac::KeyMaterial &aCurrKey,
360 const Mac::KeyMaterial &aNextKey);
361
362 /**
363 * Sets the current MAC Frame Counter value.
364 *
365 * @param[in] aMacFrameCounter The MAC Frame Counter value.
366 *
367 */
SetMacFrameCounter(uint32_t aMacFrameCounter)368 void SetMacFrameCounter(uint32_t aMacFrameCounter)
369 {
370 otPlatRadioSetMacFrameCounter(GetInstancePtr(), aMacFrameCounter);
371 }
372
373 /**
374 * Sets the current MAC Frame Counter value only if the new given value is larger than the current
375 * value.
376 *
377 * @param[in] aMacFrameCounter The MAC Frame Counter value.
378 *
379 */
SetMacFrameCounterIfLarger(uint32_t aMacFrameCounter)380 void SetMacFrameCounterIfLarger(uint32_t aMacFrameCounter)
381 {
382 otPlatRadioSetMacFrameCounterIfLarger(GetInstancePtr(), aMacFrameCounter);
383 }
384
385 /**
386 * Gets the radio's transmit power in dBm.
387 *
388 * @param[out] aPower A reference to output the transmit power in dBm.
389 *
390 * @retval kErrorNone Successfully retrieved the transmit power.
391 * @retval kErrorNotImplemented Transmit power configuration via dBm is not implemented.
392 *
393 */
394 Error GetTransmitPower(int8_t &aPower);
395
396 /**
397 * Sets the radio's transmit power in dBm.
398 *
399 * @param[in] aPower The transmit power in dBm.
400 *
401 * @retval kErrorNone Successfully set the transmit power.
402 * @retval kErrorNotImplemented Transmit power configuration via dBm is not implemented.
403 *
404 */
405 Error SetTransmitPower(int8_t aPower);
406
407 /**
408 * Gets the radio's CCA ED threshold in dBm.
409 *
410 * @param[in] aThreshold The CCA ED threshold in dBm.
411 *
412 * @retval kErrorNone A reference to output the CCA ED threshold in dBm.
413 * @retval kErrorNotImplemented CCA ED threshold configuration via dBm is not implemented.
414 *
415 */
416 Error GetCcaEnergyDetectThreshold(int8_t &aThreshold);
417
418 /**
419 * Sets the radio's CCA ED threshold in dBm.
420 *
421 * @param[in] aThreshold The CCA ED threshold in dBm.
422 *
423 * @retval kErrorNone Successfully set the CCA ED threshold.
424 * @retval kErrorNotImplemented CCA ED threshold configuration via dBm is not implemented.
425 *
426 */
427 Error SetCcaEnergyDetectThreshold(int8_t aThreshold);
428
429 /**
430 * Gets the status of promiscuous mode.
431 *
432 * @retval TRUE Promiscuous mode is enabled.
433 * @retval FALSE Promiscuous mode is disabled.
434 *
435 */
436 bool GetPromiscuous(void);
437
438 /**
439 * Enables or disables promiscuous mode.
440 *
441 * @param[in] aEnable TRUE to enable or FALSE to disable promiscuous mode.
442 *
443 */
444 void SetPromiscuous(bool aEnable);
445
446 /**
447 * Indicates whether radio should stay in Receive or Sleep during idle periods.
448 *
449 * @param[in] aEnable TRUE to keep radio in Receive, FALSE to put to Sleep during idle periods.
450 *
451 */
452 void SetRxOnWhenIdle(bool aEnable);
453
454 /**
455 * Returns the current state of the radio.
456 *
457 * Is not required by OpenThread. It may be used for debugging and/or application-specific purposes.
458 *
459 * @note This function may be not implemented. In this case it always returns OT_RADIO_STATE_INVALID state.
460 *
461 * @return Current state of the radio.
462 *
463 */
464 otRadioState GetState(void);
465
466 /**
467 * Enables the radio.
468 *
469 * @retval kErrorNone Successfully enabled.
470 * @retval kErrorFailed The radio could not be enabled.
471 *
472 */
473 Error Enable(void);
474
475 /**
476 * Disables the radio.
477 *
478 * @retval kErrorNone Successfully transitioned to Disabled.
479 * @retval kErrorInvalidState The radio was not in sleep state.
480 *
481 */
482 Error Disable(void);
483
484 /**
485 * Indicates whether radio is enabled or not.
486 *
487 * @returns TRUE if the radio is enabled, FALSE otherwise.
488 *
489 */
490 bool IsEnabled(void);
491
492 /**
493 * Transitions the radio from Receive to Sleep (turn off the radio).
494 *
495 * @retval kErrorNone Successfully transitioned to Sleep.
496 * @retval kErrorBusy The radio was transmitting.
497 * @retval kErrorInvalidState The radio was disabled.
498 *
499 */
500 Error Sleep(void);
501
502 /**
503 * Transitions the radio from Sleep to Receive (turn on the radio).
504 *
505 * @param[in] aChannel The channel to use for receiving.
506 *
507 * @retval kErrorNone Successfully transitioned to Receive.
508 * @retval kErrorInvalidState The radio was disabled or transmitting.
509 *
510 */
511 Error Receive(uint8_t aChannel);
512
513 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
514 /**
515 * Updates the CSL sample time in radio.
516 *
517 * @param[in] aCslSampleTime The CSL sample time.
518 *
519 */
520 void UpdateCslSampleTime(uint32_t aCslSampleTime);
521
522 /**
523 * Schedules a radio reception window at a specific time and duration.
524 *
525 * @param[in] aChannel The radio channel on which to receive.
526 * @param[in] aStart The receive window start time, in microseconds.
527 * @param[in] aDuration The receive window duration, in microseconds.
528 *
529 * @retval kErrorNone Successfully scheduled receive window.
530 * @retval kErrorFailed The receive window could not be scheduled.
531 *
532 */
533 Error ReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuration);
534
535 /**
536 * Enables CSL sampling in radio.
537 *
538 * @param[in] aCslPeriod CSL period, 0 for disabling CSL.
539 * @param[in] aShortAddr The short source address of CSL receiver's peer.
540 * @param[in] aExtAddr The extended source address of CSL receiver's peer.
541 *
542 * @note Platforms should use CSL peer addresses to include CSL IE when generating enhanced acks.
543 *
544 * @retval kErrorNotImplemented Radio driver doesn't support CSL.
545 * @retval kErrorFailed Other platform specific errors.
546 * @retval kErrorNone Successfully enabled or disabled CSL.
547 *
548 */
549 Error EnableCsl(uint32_t aCslPeriod, otShortAddress aShortAddr, const otExtAddress *aExtAddr);
550
551 /**
552 * Resets CSL receiver in radio.
553 *
554 * @retval kErrorNotImplemented Radio driver doesn't support CSL.
555 * @retval kErrorFailed Other platform specific errors.
556 * @retval kErrorNone Successfully disabled CSL.
557 *
558 */
559 Error ResetCsl(void);
560 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
561
562 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
563 /**
564 * Get the current accuracy, in units of ± ppm, of the clock used for scheduling CSL operations.
565 *
566 * @note Platforms may optimize this value based on operational conditions (i.e.: temperature).
567 *
568 * @returns The current CSL rx/tx scheduling drift, in units of ± ppm.
569 *
570 */
571 uint8_t GetCslAccuracy(void);
572
573 /**
574 * Get the fixed uncertainty of the Device for scheduling CSL operations in units of 10 microseconds.
575 *
576 * @returns The CSL Uncertainty in units of 10 us.
577 *
578 */
579 uint8_t GetCslUncertainty(void);
580 #endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
581
582 /**
583 * Gets the radio transmit frame buffer.
584 *
585 * OpenThread forms the IEEE 802.15.4 frame in this buffer then calls `Transmit()` to request transmission.
586 *
587 * @returns A reference to the transmit frame buffer.
588 *
589 */
590 Mac::TxFrame &GetTransmitBuffer(void);
591
592 /**
593 * Starts the transmit sequence on the radio.
594 *
595 * The caller must form the IEEE 802.15.4 frame in the buffer provided by `GetTransmitBuffer()` before
596 * requesting transmission. The channel and transmit power are also included in the frame.
597 *
598 * @param[in] aFrame A reference to the frame to be transmitted.
599 *
600 * @retval kErrorNone Successfully transitioned to Transmit.
601 * @retval kErrorInvalidState The radio was not in the Receive state.
602 *
603 */
604 Error Transmit(Mac::TxFrame &aFrame);
605
606 /**
607 * Gets the most recent RSSI measurement.
608 *
609 * @returns The RSSI in dBm when it is valid. 127 when RSSI is invalid.
610 *
611 */
612 int8_t GetRssi(void);
613
614 /**
615 * Begins the energy scan sequence on the radio.
616 *
617 * Is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability.
618 *
619 * @param[in] aScanChannel The channel to perform the energy scan on.
620 * @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
621 *
622 * @retval kErrorNone Successfully started scanning the channel.
623 * @retval kErrorBusy The radio is performing energy scanning.
624 * @retval kErrorNotImplemented The radio doesn't support energy scanning.
625 *
626 */
627 Error EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration);
628
629 /**
630 * Enables/disables source address match feature.
631 *
632 * The source address match feature controls how the radio layer decides the "frame pending" bit for acks sent in
633 * response to data request commands from children.
634 *
635 * If disabled, the radio layer must set the "frame pending" on all acks to data request commands.
636 *
637 * If enabled, the radio layer uses the source address match table to determine whether to set or clear the "frame
638 * pending" bit in an ack to a data request command.
639 *
640 * The source address match table provides the list of children for which there is a pending frame. Either a short
641 * address or an extended/long address can be added to the source address match table.
642 *
643 * @param[in] aEnable Enable/disable source address match feature.
644 *
645 */
646 void EnableSrcMatch(bool aEnable);
647
648 /**
649 * Adds a short address to the source address match table.
650 *
651 * @param[in] aShortAddress The short address to be added.
652 *
653 * @retval kErrorNone Successfully added short address to the source match table.
654 * @retval kErrorNoBufs No available entry in the source match table.
655 *
656 */
657 Error AddSrcMatchShortEntry(Mac::ShortAddress aShortAddress);
658
659 /**
660 * Adds an extended address to the source address match table.
661 *
662 * @param[in] aExtAddress The extended address to be added stored in little-endian byte order.
663 *
664 * @retval kErrorNone Successfully added extended address to the source match table.
665 * @retval kErrorNoBufs No available entry in the source match table.
666 *
667 */
668 Error AddSrcMatchExtEntry(const Mac::ExtAddress &aExtAddress);
669
670 /**
671 * Removes a short address from the source address match table.
672 *
673 * @param[in] aShortAddress The short address to be removed.
674 *
675 * @retval kErrorNone Successfully removed short address from the source match table.
676 * @retval kErrorNoAddress The short address is not in source address match table.
677 *
678 */
679 Error ClearSrcMatchShortEntry(Mac::ShortAddress aShortAddress);
680
681 /**
682 * Removes an extended address from the source address match table.
683 *
684 * @param[in] aExtAddress The extended address to be removed stored in little-endian byte order.
685 *
686 * @retval kErrorNone Successfully removed the extended address from the source match table.
687 * @retval kErrorNoAddress The extended address is not in source address match table.
688 *
689 */
690 Error ClearSrcMatchExtEntry(const Mac::ExtAddress &aExtAddress);
691
692 /**
693 * Clears all short addresses from the source address match table.
694 *
695 */
696 void ClearSrcMatchShortEntries(void);
697
698 /**
699 * Clears all the extended/long addresses from source address match table.
700 *
701 */
702 void ClearSrcMatchExtEntries(void);
703
704 /**
705 * Gets the radio supported channel mask that the device is allowed to be on.
706 *
707 * @returns The radio supported channel mask.
708 *
709 */
710 uint32_t GetSupportedChannelMask(void);
711
712 /**
713 * Gets the radio preferred channel mask that the device prefers to form on.
714 *
715 * @returns The radio preferred channel mask.
716 *
717 */
718 uint32_t GetPreferredChannelMask(void);
719
720 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
721 /**
722 * Enables/disables or updates Enhanced-ACK Based Probing in radio for a specific Initiator.
723 *
724 * After Enhanced-ACK Based Probing is configured by a specific Probing Initiator, the Enhanced-ACK sent to that
725 * node should include Vendor-Specific IE containing Link Metrics data. This method informs the radio to
726 * starts/stops to collect Link Metrics data and include Vendor-Specific IE that containing the data
727 * in Enhanced-ACK sent to that Probing Initiator.
728 *
729 * @param[in] aLinkMetrics This parameter specifies what metrics to query. Per spec 4.11.3.4.4.6, at most 2
730 * metrics can be specified. The probing would be disabled if @p `aLinkMetrics` is
731 * bitwise 0.
732 * @param[in] aShortAddress The short address of the the probing Initiator.
733 * @param[in] aExtAddress The extended source address of the probing Initiator.
734 *
735 * @retval kErrorNone Successfully enable/disable or update Enhanced-ACK Based Probing for a specific
736 * Initiator.
737 * @retval kErrorInvalidArgs @p aDataLength or @p aExtAddr is not valid.
738 * @retval kErrorNotFound The Initiator indicated by @p aShortAddress is not found when trying to clear.
739 * @retval kErrorNoBufs No more Initiator can be supported.
740 * @retval kErrorNotImplemented Radio driver doesn't support Enhanced-ACK Probing.
741 *
742 */
ConfigureEnhAckProbing(otLinkMetrics aLinkMetrics,const Mac::ShortAddress & aShortAddress,const Mac::ExtAddress & aExtAddress)743 Error ConfigureEnhAckProbing(otLinkMetrics aLinkMetrics,
744 const Mac::ShortAddress &aShortAddress,
745 const Mac::ExtAddress &aExtAddress)
746 {
747 return otPlatRadioConfigureEnhAckProbing(GetInstancePtr(), aLinkMetrics, aShortAddress, &aExtAddress);
748 }
749 #endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
750
751 /**
752 * Checks if a given channel is valid as a CSL channel.
753 *
754 * @retval true The channel is valid.
755 * @retval false The channel is invalid.
756 *
757 */
IsCslChannelValid(uint8_t aCslChannel)758 static bool IsCslChannelValid(uint8_t aCslChannel)
759 {
760 return ((aCslChannel == 0) ||
761 ((kChannelMin == aCslChannel) || ((kChannelMin < aCslChannel) && (aCslChannel <= kChannelMax))));
762 }
763
764 /**
765 * Sets the region code.
766 *
767 * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code.
768 *
769 * @param[in] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char
770 * and the `aRegionCode & 0xff` is the second ascii char.
771 *
772 * @retval kErrorFailed Other platform specific errors.
773 * @retval kErrorNone Successfully set region code.
774 * @retval kErrorNotImplemented The feature is not implemented.
775 *
776 */
SetRegion(uint16_t aRegionCode)777 Error SetRegion(uint16_t aRegionCode) { return otPlatRadioSetRegion(GetInstancePtr(), aRegionCode); }
778
779 /**
780 * Get the region code.
781 *
782 * The radio region format is the 2-bytes ascii representation of the ISO 3166 alpha-2 code.
783 *
784 * @param[out] aRegionCode The radio region code. The `aRegionCode >> 8` is first ascii char
785 * and the `aRegionCode & 0xff` is the second ascii char.
786 *
787 * @retval kErrorFailed Other platform specific errors.
788 * @retval kErrorNone Successfully set region code.
789 * @retval kErrorNotImplemented The feature is not implemented.
790 *
791 */
GetRegion(uint16_t & aRegionCode) const792 Error GetRegion(uint16_t &aRegionCode) const { return otPlatRadioGetRegion(GetInstancePtr(), &aRegionCode); }
793
794 /**
795 * Indicates whether a given channel page is supported based on the current configurations.
796 *
797 * @param[in] aChannelPage The channel page to check.
798 *
799 * @retval TRUE The @p aChannelPage is supported by radio.
800 * @retval FALASE The @p aChannelPage is not supported by radio.
801 *
802 */
SupportsChannelPage(uint8_t aChannelPage)803 static constexpr bool SupportsChannelPage(uint8_t aChannelPage)
804 {
805 #if OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT && OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
806 return (aChannelPage == kChannelPage0) || (aChannelPage == kChannelPage2);
807 #elif OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
808 return (aChannelPage == kChannelPage0);
809 #elif OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
810 return (aChannelPage == kChannelPage2);
811 #elif OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
812 return (aChannelPage == OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE);
813 #endif
814 }
815
816 /**
817 * Returns the channel mask for a given channel page if supported by the radio.
818 *
819 * @param[in] aChannelPage The channel page.
820 *
821 * @returns The channel mask for @p aChannelPage if page is supported by the radio, otherwise zero.
822 *
823 */
ChannelMaskForPage(uint8_t aChannelPage)824 static uint32_t ChannelMaskForPage(uint8_t aChannelPage)
825 {
826 uint32_t mask = 0;
827
828 #if OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
829 if (aChannelPage == kChannelPage0)
830 {
831 mask = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK;
832 }
833 #endif
834
835 #if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
836 if (aChannelPage == kChannelPage1)
837 {
838 mask = OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK;
839 }
840 #endif
841
842 #if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
843 if (aChannelPage == OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE)
844 {
845 mask = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK;
846 }
847 #endif
848 return mask;
849 }
850
851 private:
GetInstancePtr(void) const852 otInstance *GetInstancePtr(void) const { return reinterpret_cast<otInstance *>(&InstanceLocator::GetInstance()); }
853
854 Callbacks mCallbacks;
855 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
856 RadioStatistics mRadioStatistics;
857 #endif
858 };
859
860 //---------------------------------------------------------------------------------------------------------------------
861 // Radio APIs that are always mapped to the same `otPlatRadio` function (independent of the link type)
862
GetVersionString(void)863 inline const char *Radio::GetVersionString(void) { return otPlatRadioGetVersionString(GetInstancePtr()); }
864
GetIeeeEui64(Mac::ExtAddress & aIeeeEui64)865 inline void Radio::GetIeeeEui64(Mac::ExtAddress &aIeeeEui64)
866 {
867 otPlatRadioGetIeeeEui64(GetInstancePtr(), aIeeeEui64.m8);
868 }
869
GetSupportedChannelMask(void)870 inline uint32_t Radio::GetSupportedChannelMask(void) { return otPlatRadioGetSupportedChannelMask(GetInstancePtr()); }
871
GetPreferredChannelMask(void)872 inline uint32_t Radio::GetPreferredChannelMask(void) { return otPlatRadioGetPreferredChannelMask(GetInstancePtr()); }
873
874 //---------------------------------------------------------------------------------------------------------------------
875 // If IEEE 802.15.4 is among supported radio links, provide inline
876 // mapping of `Radio` method to related `otPlatRadio` functions.
877
878 #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
879
GetCaps(void)880 inline otRadioCaps Radio::GetCaps(void) { return otPlatRadioGetCaps(GetInstancePtr()); }
881
GetReceiveSensitivity(void) const882 inline int8_t Radio::GetReceiveSensitivity(void) const { return otPlatRadioGetReceiveSensitivity(GetInstancePtr()); }
883
SetPanId(Mac::PanId aPanId)884 inline void Radio::SetPanId(Mac::PanId aPanId) { otPlatRadioSetPanId(GetInstancePtr(), aPanId); }
885
SetMacKey(uint8_t aKeyIdMode,uint8_t aKeyId,const Mac::KeyMaterial & aPrevKey,const Mac::KeyMaterial & aCurrKey,const Mac::KeyMaterial & aNextKey)886 inline void Radio::SetMacKey(uint8_t aKeyIdMode,
887 uint8_t aKeyId,
888 const Mac::KeyMaterial &aPrevKey,
889 const Mac::KeyMaterial &aCurrKey,
890 const Mac::KeyMaterial &aNextKey)
891 {
892 otRadioKeyType aKeyType;
893
894 #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
895 aKeyType = OT_KEY_TYPE_KEY_REF;
896 #else
897 aKeyType = OT_KEY_TYPE_LITERAL_KEY;
898 #endif
899
900 otPlatRadioSetMacKey(GetInstancePtr(), aKeyIdMode, aKeyId, &aPrevKey, &aCurrKey, &aNextKey, aKeyType);
901 }
902
GetTransmitPower(int8_t & aPower)903 inline Error Radio::GetTransmitPower(int8_t &aPower) { return otPlatRadioGetTransmitPower(GetInstancePtr(), &aPower); }
904
SetTransmitPower(int8_t aPower)905 inline Error Radio::SetTransmitPower(int8_t aPower) { return otPlatRadioSetTransmitPower(GetInstancePtr(), aPower); }
906
GetCcaEnergyDetectThreshold(int8_t & aThreshold)907 inline Error Radio::GetCcaEnergyDetectThreshold(int8_t &aThreshold)
908 {
909 return otPlatRadioGetCcaEnergyDetectThreshold(GetInstancePtr(), &aThreshold);
910 }
911
SetCcaEnergyDetectThreshold(int8_t aThreshold)912 inline Error Radio::SetCcaEnergyDetectThreshold(int8_t aThreshold)
913 {
914 return otPlatRadioSetCcaEnergyDetectThreshold(GetInstancePtr(), aThreshold);
915 }
916
GetPromiscuous(void)917 inline bool Radio::GetPromiscuous(void) { return otPlatRadioGetPromiscuous(GetInstancePtr()); }
918
SetPromiscuous(bool aEnable)919 inline void Radio::SetPromiscuous(bool aEnable) { otPlatRadioSetPromiscuous(GetInstancePtr(), aEnable); }
920
SetRxOnWhenIdle(bool aEnable)921 inline void Radio::SetRxOnWhenIdle(bool aEnable) { otPlatRadioSetRxOnWhenIdle(GetInstancePtr(), aEnable); }
922
GetState(void)923 inline otRadioState Radio::GetState(void) { return otPlatRadioGetState(GetInstancePtr()); }
924
Enable(void)925 inline Error Radio::Enable(void)
926 {
927 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
928 mRadioStatistics.RecordStateChange(RadioStatistics::kSleep);
929 #endif
930 return otPlatRadioEnable(GetInstancePtr());
931 }
932
Disable(void)933 inline Error Radio::Disable(void)
934 {
935 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
936 mRadioStatistics.RecordStateChange(RadioStatistics::kDisabled);
937 #endif
938 return otPlatRadioDisable(GetInstancePtr());
939 }
940
IsEnabled(void)941 inline bool Radio::IsEnabled(void) { return otPlatRadioIsEnabled(GetInstancePtr()); }
942
Sleep(void)943 inline Error Radio::Sleep(void)
944 {
945 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
946 mRadioStatistics.RecordStateChange(RadioStatistics::kSleep);
947 #endif
948 return otPlatRadioSleep(GetInstancePtr());
949 }
950
Receive(uint8_t aChannel)951 inline Error Radio::Receive(uint8_t aChannel)
952 {
953 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
954 mRadioStatistics.RecordStateChange(RadioStatistics::kReceive);
955 #endif
956 return otPlatRadioReceive(GetInstancePtr(), aChannel);
957 }
958
959 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
UpdateCslSampleTime(uint32_t aCslSampleTime)960 inline void Radio::UpdateCslSampleTime(uint32_t aCslSampleTime)
961 {
962 otPlatRadioUpdateCslSampleTime(GetInstancePtr(), aCslSampleTime);
963 }
964
ReceiveAt(uint8_t aChannel,uint32_t aStart,uint32_t aDuration)965 inline Error Radio::ReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuration)
966 {
967 Error error = otPlatRadioReceiveAt(GetInstancePtr(), aChannel, aStart, aDuration);
968 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
969 if (error == kErrorNone)
970 {
971 mRadioStatistics.HandleReceiveAt(aDuration);
972 }
973 #endif
974 return error;
975 }
976
EnableCsl(uint32_t aCslPeriod,otShortAddress aShortAddr,const otExtAddress * aExtAddr)977 inline Error Radio::EnableCsl(uint32_t aCslPeriod, otShortAddress aShortAddr, const otExtAddress *aExtAddr)
978 {
979 return otPlatRadioEnableCsl(GetInstancePtr(), aCslPeriod, aShortAddr, aExtAddr);
980 }
981
ResetCsl(void)982 inline Error Radio::ResetCsl(void) { return otPlatRadioResetCsl(GetInstancePtr()); }
983 #endif
984
985 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
GetCslAccuracy(void)986 inline uint8_t Radio::GetCslAccuracy(void) { return otPlatRadioGetCslAccuracy(GetInstancePtr()); }
987 #endif
988
989 #if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
GetCslUncertainty(void)990 inline uint8_t Radio::GetCslUncertainty(void) { return otPlatRadioGetCslUncertainty(GetInstancePtr()); }
991 #endif
992
GetTransmitBuffer(void)993 inline Mac::TxFrame &Radio::GetTransmitBuffer(void)
994 {
995 return *static_cast<Mac::TxFrame *>(otPlatRadioGetTransmitBuffer(GetInstancePtr()));
996 }
997
GetRssi(void)998 inline int8_t Radio::GetRssi(void) { return otPlatRadioGetRssi(GetInstancePtr()); }
999
EnergyScan(uint8_t aScanChannel,uint16_t aScanDuration)1000 inline Error Radio::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
1001 {
1002 return otPlatRadioEnergyScan(GetInstancePtr(), aScanChannel, aScanDuration);
1003 }
1004
EnableSrcMatch(bool aEnable)1005 inline void Radio::EnableSrcMatch(bool aEnable) { otPlatRadioEnableSrcMatch(GetInstancePtr(), aEnable); }
1006
AddSrcMatchShortEntry(Mac::ShortAddress aShortAddress)1007 inline Error Radio::AddSrcMatchShortEntry(Mac::ShortAddress aShortAddress)
1008 {
1009 return otPlatRadioAddSrcMatchShortEntry(GetInstancePtr(), aShortAddress);
1010 }
1011
AddSrcMatchExtEntry(const Mac::ExtAddress & aExtAddress)1012 inline Error Radio::AddSrcMatchExtEntry(const Mac::ExtAddress &aExtAddress)
1013 {
1014 return otPlatRadioAddSrcMatchExtEntry(GetInstancePtr(), &aExtAddress);
1015 }
1016
ClearSrcMatchShortEntry(Mac::ShortAddress aShortAddress)1017 inline Error Radio::ClearSrcMatchShortEntry(Mac::ShortAddress aShortAddress)
1018 {
1019 return otPlatRadioClearSrcMatchShortEntry(GetInstancePtr(), aShortAddress);
1020 }
1021
ClearSrcMatchExtEntry(const Mac::ExtAddress & aExtAddress)1022 inline Error Radio::ClearSrcMatchExtEntry(const Mac::ExtAddress &aExtAddress)
1023 {
1024 return otPlatRadioClearSrcMatchExtEntry(GetInstancePtr(), &aExtAddress);
1025 }
1026
ClearSrcMatchShortEntries(void)1027 inline void Radio::ClearSrcMatchShortEntries(void) { otPlatRadioClearSrcMatchShortEntries(GetInstancePtr()); }
1028
ClearSrcMatchExtEntries(void)1029 inline void Radio::ClearSrcMatchExtEntries(void) { otPlatRadioClearSrcMatchExtEntries(GetInstancePtr()); }
1030
1031 #else //----------------------------------------------------------------------------------------------------------------
1032
GetCaps(void)1033 inline otRadioCaps Radio::GetCaps(void)
1034 {
1035 return OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF | OT_RADIO_CAPS_TRANSMIT_RETRIES;
1036 }
1037
GetReceiveSensitivity(void) const1038 inline int8_t Radio::GetReceiveSensitivity(void) const { return kDefaultReceiveSensitivity; }
1039
SetPanId(Mac::PanId)1040 inline void Radio::SetPanId(Mac::PanId) {}
1041
SetExtendedAddress(const Mac::ExtAddress &)1042 inline void Radio::SetExtendedAddress(const Mac::ExtAddress &) {}
1043
SetShortAddress(Mac::ShortAddress)1044 inline void Radio::SetShortAddress(Mac::ShortAddress) {}
1045
SetMacKey(uint8_t,uint8_t,const Mac::KeyMaterial &,const Mac::KeyMaterial &,const Mac::KeyMaterial &)1046 inline void Radio::SetMacKey(uint8_t,
1047 uint8_t,
1048 const Mac::KeyMaterial &,
1049 const Mac::KeyMaterial &,
1050 const Mac::KeyMaterial &)
1051 {
1052 }
1053
GetTransmitPower(int8_t &)1054 inline Error Radio::GetTransmitPower(int8_t &) { return kErrorNotImplemented; }
1055
SetTransmitPower(int8_t)1056 inline Error Radio::SetTransmitPower(int8_t) { return kErrorNotImplemented; }
1057
GetCcaEnergyDetectThreshold(int8_t &)1058 inline Error Radio::GetCcaEnergyDetectThreshold(int8_t &) { return kErrorNotImplemented; }
1059
SetCcaEnergyDetectThreshold(int8_t)1060 inline Error Radio::SetCcaEnergyDetectThreshold(int8_t) { return kErrorNotImplemented; }
1061
GetPromiscuous(void)1062 inline bool Radio::GetPromiscuous(void) { return false; }
1063
SetPromiscuous(bool)1064 inline void Radio::SetPromiscuous(bool) {}
1065
SetRxOnWhenIdle(bool)1066 inline void Radio::SetRxOnWhenIdle(bool) {}
1067
GetState(void)1068 inline otRadioState Radio::GetState(void) { return OT_RADIO_STATE_DISABLED; }
1069
Enable(void)1070 inline Error Radio::Enable(void) { return kErrorNone; }
1071
Disable(void)1072 inline Error Radio::Disable(void) { return kErrorInvalidState; }
1073
IsEnabled(void)1074 inline bool Radio::IsEnabled(void) { return true; }
1075
Sleep(void)1076 inline Error Radio::Sleep(void) { return kErrorNone; }
1077
Receive(uint8_t)1078 inline Error Radio::Receive(uint8_t) { return kErrorNone; }
1079
1080 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
UpdateCslSampleTime(uint32_t)1081 inline void Radio::UpdateCslSampleTime(uint32_t) {}
1082
ReceiveAt(uint8_t,uint32_t,uint32_t)1083 inline Error Radio::ReceiveAt(uint8_t, uint32_t, uint32_t) { return kErrorNone; }
1084
EnableCsl(uint32_t,otShortAddress aShortAddr,const otExtAddress *)1085 inline Error Radio::EnableCsl(uint32_t, otShortAddress aShortAddr, const otExtAddress *)
1086 {
1087 return kErrorNotImplemented;
1088 }
1089
ResetCsl(void)1090 inline Error Radio::ResetCsl(void) { return kErrorNotImplemented; }
1091 #endif
1092
1093 #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
GetCslAccuracy(void)1094 inline uint8_t Radio::GetCslAccuracy(void) { return NumericLimits<uint8_t>::kMax; }
1095
GetCslUncertainty(void)1096 inline uint8_t Radio::GetCslUncertainty(void) { return NumericLimits<uint8_t>::kMax; }
1097 #endif
1098
GetTransmitBuffer(void)1099 inline Mac::TxFrame &Radio::GetTransmitBuffer(void)
1100 {
1101 return *static_cast<Mac::TxFrame *>(otPlatRadioGetTransmitBuffer(GetInstancePtr()));
1102 }
1103
Transmit(Mac::TxFrame &)1104 inline Error Radio::Transmit(Mac::TxFrame &) { return kErrorAbort; }
1105
GetRssi(void)1106 inline int8_t Radio::GetRssi(void) { return kInvalidRssi; }
1107
EnergyScan(uint8_t,uint16_t)1108 inline Error Radio::EnergyScan(uint8_t, uint16_t) { return kErrorNotImplemented; }
1109
EnableSrcMatch(bool)1110 inline void Radio::EnableSrcMatch(bool) {}
1111
AddSrcMatchShortEntry(Mac::ShortAddress)1112 inline Error Radio::AddSrcMatchShortEntry(Mac::ShortAddress) { return kErrorNone; }
1113
AddSrcMatchExtEntry(const Mac::ExtAddress &)1114 inline Error Radio::AddSrcMatchExtEntry(const Mac::ExtAddress &) { return kErrorNone; }
1115
ClearSrcMatchShortEntry(Mac::ShortAddress)1116 inline Error Radio::ClearSrcMatchShortEntry(Mac::ShortAddress) { return kErrorNone; }
1117
ClearSrcMatchExtEntry(const Mac::ExtAddress &)1118 inline Error Radio::ClearSrcMatchExtEntry(const Mac::ExtAddress &) { return kErrorNone; }
1119
ClearSrcMatchShortEntries(void)1120 inline void Radio::ClearSrcMatchShortEntries(void) {}
1121
ClearSrcMatchExtEntries(void)1122 inline void Radio::ClearSrcMatchExtEntries(void) {}
1123
1124 #endif // #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
1125
1126 } // namespace ot
1127
1128 #endif // RADIO_HPP_
1129