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