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