From 700bb6b5a810709e79eafb6f463544f34b27b21f Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 1 Aug 2019 15:01:19 -0700 Subject: [PATCH] [radio] adding Radio::Callback class (#4045) This commit adds a `Radio::Callback` class which provides all the callbacks (as C++ methods) mirroring the radio platform layer callbacks (including the diags related radio callbacks). --- Android.mk | 3 +- src/core/Makefile.am | 6 +- src/core/common/instance.hpp | 5 + src/core/diags/factory_diags.cpp | 28 ----- src/core/mac/sub_mac.cpp | 56 --------- src/core/mac/sub_mac.hpp | 71 ++--------- src/core/radio/radio.hpp | 106 +++++++++++++++++ src/core/radio/radio_callbacks.cpp | 91 ++++++++++++++ src/core/radio/radio_platform.cpp | 131 +++++++++++++++++++++ src/core/radio/radio_platform_defaults.cpp | 55 --------- 10 files changed, 349 insertions(+), 203 deletions(-) create mode 100644 src/core/radio/radio_callbacks.cpp create mode 100644 src/core/radio/radio_platform.cpp delete mode 100644 src/core/radio/radio_platform_defaults.cpp diff --git a/Android.mk b/Android.mk index dce2dd2c0..184c40f60 100644 --- a/Android.mk +++ b/Android.mk @@ -188,7 +188,8 @@ LOCAL_SRC_FILES := \ src/core/net/ip6_mpl.cpp \ src/core/net/netif.cpp \ src/core/net/udp6.cpp \ - src/core/radio/radio_platform_defaults.cpp \ + src/core/radio/radio_callbacks.cpp \ + src/core/radio/radio_platform.cpp \ src/core/thread/address_resolver.cpp \ src/core/thread/announce_begin_server.cpp \ src/core/thread/announce_sender.cpp \ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2be93abbb..982eba9d3 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -194,7 +194,8 @@ SOURCES_COMMON = \ net/netif.cpp \ net/sntp_client.cpp \ net/udp6.cpp \ - radio/radio_platform_defaults.cpp \ + radio/radio_callbacks.cpp \ + radio/radio_platform.cpp \ thread/address_resolver.cpp \ thread/announce_begin_server.cpp \ thread/announce_sender.cpp \ @@ -255,7 +256,8 @@ libopenthread_radio_a_SOURCES = \ mac/mac_frame.cpp \ mac/sub_mac.cpp \ mac/sub_mac_callbacks.cpp \ - radio/radio_platform_defaults.cpp \ + radio/radio_callbacks.cpp \ + radio/radio_platform.cpp \ thread/link_quality.cpp \ utils/missing_strlcat.c \ utils/missing_strlcpy.c \ diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index d78073bb2..1777a6262 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -388,6 +388,11 @@ template <> inline Radio &Instance::Get(void) return mRadio; } +template <> inline Radio::Callbacks &Instance::Get(void) +{ + return mRadio.mCallbacks; +} + #if OPENTHREAD_MTD || OPENTHREAD_FTD template <> inline Notifier &Instance::Get(void) { diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index fc7e84853..5cb0d9a69 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -122,18 +122,6 @@ extern "C" void otPlatDiagAlarmFired(otInstance *aInstance) otPlatDiagAlarmCallback(aInstance); } -extern "C" void otPlatDiagRadioTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - // notify OpenThread Diags module on host side - otPlatRadioTxDone(aInstance, aFrame, NULL, aError); -} - -extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - // notify OpenThread Diags module on host side - otPlatRadioReceiveDone(aInstance, aFrame, aError); -} - #else // OPENTHREAD_RADIO const struct Diags::Command Diags::sCommands[] = { @@ -408,13 +396,6 @@ void Diags::AlarmFired(void) } } -extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - Instance *instance = static_cast(aInstance); - - instance->Get().ReceiveDone(aFrame, aError); -} - void Diags::ReceiveDone(otRadioFrame *aFrame, otError aError) { if (aError == OT_ERROR_NONE) @@ -435,15 +416,6 @@ void Diags::ReceiveDone(otRadioFrame *aFrame, otError aError) otPlatDiagRadioReceived(&GetInstance(), aFrame, aError); } -extern "C" void otPlatDiagRadioTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - OT_UNUSED_VARIABLE(aFrame); - - Instance *instance = static_cast(aInstance); - - instance->Get().TransmitDone(aError); -} - void Diags::TransmitDone(otError aError) { if (aError == OT_ERROR_NONE) diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index 9d68a1d88..b6029352c 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -607,61 +607,5 @@ const char *SubMac::StateToString(State aState) // LCOV_EXCL_STOP -//--------------------------------------------------------------------------------------------------------------------- -// otPlatRadio callbacks - -extern "C" void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - Instance *instance = static_cast(aInstance); - - if (instance->IsInitialized()) - { - instance->Get().HandleReceiveDone(static_cast(aFrame), aError); - } -} - -extern "C" void otPlatRadioTxStarted(otInstance *aInstance, otRadioFrame *aFrame) -{ - Instance *instance = static_cast(aInstance); - - if (instance->IsInitialized()) - { - instance->Get().HandleTransmitStarted(*static_cast(aFrame)); - } -} - -extern "C" void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) -{ - Instance *instance = static_cast(aInstance); - - if (instance->IsInitialized()) - { - instance->Get().HandleTransmitDone(*static_cast(aFrame), static_cast(aAckFrame), - aError); - } -} - -extern "C" void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi) -{ - Instance *instance = static_cast(aInstance); - - if (instance->IsInitialized()) - { - instance->Get().HandleEnergyScanDone(aEnergyScanMaxRssi); - } -} - -#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT -extern "C" void otPlatRadioFrameUpdated(otInstance *aInstance, otRadioFrame *aFrame) -{ - Instance *instance = static_cast(aInstance); - - if (instance->IsInitialized()) - { - instance->Get().HandleFrameUpdated(*static_cast(aFrame)); - } -} -#endif - } // namespace Mac } // namespace ot diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index 71e5051d6..6cdfb4b8e 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -76,6 +76,8 @@ namespace Mac { */ class SubMac : public InstanceLocator { + friend class Radio::Callbacks; + public: enum { @@ -343,67 +345,6 @@ public: */ otError EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration); - /** - * This method handles a "Receive Done" event from radio platform. - * - * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. - * @param[in] aError OT_ERROR_NONE when successfully received a frame, - * OT_ERROR_ABORT when reception was aborted and a frame was not received, - * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. - * - */ - void HandleReceiveDone(RxFrame *aFrame, otError aError); - - /** - * This method handles a Transmit Started event from radio platform. - * - * @param[in] aFrame The frame that is being transmitted. - * - */ - void HandleTransmitStarted(TxFrame &aFrame); - - /** - * This method handles a "Transmit Done" event from radio platform. - * - * @param[in] aFrame The frame that was transmitted. - * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. - * @param[in] aError OT_ERROR_NONE when the frame was transmitted, - * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, - * OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on the channel, - * OT_ERROR_ABORT when transmission was aborted for other reasons. - * - */ - void HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError); - - /** - * This method handles "Energy Scan Done" event from radio platform. - * - * This method is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability. It is called from - * `otPlatRadioEnergyScanDone()`. - * - * @param[in] aInstance The OpenThread instance structure. - * @param[in] aEnergyScanMaxRssi The maximum RSSI encountered on the scanned channel. - * - */ - void HandleEnergyScanDone(int8_t aMaxRssi); - -#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT - /** - * This method handles a "Frame Updated" event from radio platform. - * - * This is called to notify OpenThread to process transmit security for the frame, this happens when the frame - * includes Header IE(s) that were updated before transmission. It is called from `otPlatRadioFrameUpdated()`. - * - * @note This method can be called from interrupt context and it would only read/write data passed in - * via @p aFrame, but would not read/write any state within OpenThread. - * - * @param[in] aFrame The frame which needs to process transmit security. - * - */ - void HandleFrameUpdated(TxFrame &aFrame); -#endif - private: enum { @@ -448,6 +389,14 @@ private: void BeginTransmit(void); void SampleRssi(void); + void HandleReceiveDone(RxFrame *aFrame, otError aError); + void HandleTransmitStarted(TxFrame &aFrame); + void HandleTransmitDone(TxFrame &aTxFrame, RxFrame *aAckFrame, otError aError); + void HandleEnergyScanDone(int8_t aMaxRssi); +#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT + void HandleFrameUpdated(TxFrame &aFrame); +#endif + static void HandleTimer(Timer &aTimer); void HandleTimer(void); diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 5d28a5011..cad96ae51 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -60,6 +60,8 @@ namespace ot { */ class Radio : public InstanceLocator { + friend class Instance; + public: /** * This enumeration defines the IEEE 802.15.4 channel related parameters. @@ -92,6 +94,107 @@ public: "OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT or OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT " "must be set to 1 to specify the radio mode"); + /** + * This class defines the callbacks from `Radio`. + * + */ + class Callbacks : public InstanceLocator + { + friend class Radio; + + public: + /** + * This callback method handles a "Receive Done" event from radio platform. + * + * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aError OT_ERROR_NONE when successfully received a frame, + * OT_ERROR_ABORT when reception was aborted and a frame was not received, + * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. + * + */ + void HandleReceiveDone(Mac::RxFrame *aFrame, otError aError); + + /** + * This callback method handles a "Transmit Started" event from radio platform. + * + * @param[in] aFrame The frame that is being transmitted. + * + */ + void HandleTransmitStarted(Mac::TxFrame &aFrame); + + /** + * This callback method handles a "Transmit Done" event from radio platform. + * + * @param[in] aFrame The frame that was transmitted. + * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. + * @param[in] aError OT_ERROR_NONE when the frame was transmitted, + * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, + * OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on the + * channel, OT_ERROR_ABORT when transmission was aborted for other reasons. + * + */ + void HandleTransmitDone(Mac::TxFrame &aFrame, Mac::RxFrame *aAckFrame, otError aError); + + /** + * This callback method handles "Energy Scan Done" event from radio platform. + * + * This method is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability. It is called from + * `otPlatRadioEnergyScanDone()`. + * + * @param[in] aInstance The OpenThread instance structure. + * @param[in] aEnergyScanMaxRssi The maximum RSSI encountered on the scanned channel. + * + */ + void HandleEnergyScanDone(int8_t aMaxRssi); + +#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT + /** + * This callback method handles a "Frame Updated" event from radio platform. + * + * This is called to notify OpenThread to process transmit security for the frame, this happens when the frame + * includes Header IE(s) that were updated before transmission. It is called from `otPlatRadioFrameUpdated()`. + * + * @note This method can be called from interrupt context and it would only read/write data passed in + * via @p aFrame, but would not read/write any state within OpenThread. + * + * @param[in] aFrame The frame which needs to process transmit security. + * + */ + void HandleFrameUpdated(Mac::TxFrame &aFrame); +#endif + +#if OPENTHREAD_CONFIG_DIAG_ENABLE + /** + * This callback method handles a "Receive Done" event from radio platform when diagnostics mode is enabled. + * + * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aError OT_ERROR_NONE when successfully received a frame, + * OT_ERROR_ABORT when reception was aborted and a frame was not received, + * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. + * + */ + void HandleDiagsReceiveDone(Mac::RxFrame *aFrame, otError aError); + + /** + * This callback method handles a "Transmit Done" event from radio platform when diagnostics mode is enabled. + * + * @param[in] aFrame The frame that was transmitted. + * @param[in] aError OT_ERROR_NONE when the frame was transmitted, + * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, + * OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on the + * channel, OT_ERROR_ABORT when transmission was aborted for other reasons. + * + */ + void HandleDiagsTransmitDone(Mac::TxFrame &aFrame, otError aError); +#endif + + private: + explicit Callbacks(Instance &aInstance) + : InstanceLocator(aInstance) + { + } + }; + /** * This constructor initializes the `Radio` object. * @@ -100,6 +203,7 @@ public: */ Radio(Instance &aInstance) : InstanceLocator(aInstance) + , mCallbacks(aInstance) { } @@ -405,6 +509,8 @@ public: private: otInstance *GetInstance(void) { return reinterpret_cast(&InstanceLocator::GetInstance()); } + + Callbacks mCallbacks; }; } // namespace ot diff --git a/src/core/radio/radio_callbacks.cpp b/src/core/radio/radio_callbacks.cpp new file mode 100644 index 000000000..9352be462 --- /dev/null +++ b/src/core/radio/radio_callbacks.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the radio callbacks. + */ + +#include "radio.hpp" + +#include "common/instance.hpp" +#include "common/locator-getters.hpp" + +namespace ot { + +void Radio::Callbacks::HandleReceiveDone(Mac::RxFrame *aFrame, otError aError) +{ + Get().HandleReceiveDone(aFrame, aError); +} + +void Radio::Callbacks::HandleTransmitStarted(Mac::TxFrame &aFrame) +{ + Get().HandleTransmitStarted(aFrame); +} + +void Radio::Callbacks::HandleTransmitDone(Mac::TxFrame &aFrame, Mac::RxFrame *aAckFrame, otError aError) +{ + Get().HandleTransmitDone(aFrame, aAckFrame, aError); +} + +void Radio::Callbacks::HandleEnergyScanDone(int8_t aMaxRssi) +{ + Get().HandleEnergyScanDone(aMaxRssi); +} + +#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT +void Radio::Callbacks::HandleFrameUpdated(Mac::TxFrame &aFrame) +{ + Get().HandleFrameUpdated(aFrame); +} +#endif + +#if OPENTHREAD_CONFIG_DIAG_ENABLE +void Radio::Callbacks::HandleDiagsReceiveDone(Mac::RxFrame *aFrame, otError aError) +{ +#if OPENTHREAD_RADIO + // Pass it to notify OpenThread `Diags` module on host side. + HandleReceiveDone(aFrame, aError); +#else + Get().ReceiveDone(aFrame, aError); +#endif +} + +void Radio::Callbacks::HandleDiagsTransmitDone(Mac::TxFrame &aFrame, otError aError) +{ +#if OPENTHREAD_RADIO + // Pass it to notify OpenThread `Diags` module on host side. + HandleTransmitDone(aFrame, NULL, aError); +#else + OT_UNUSED_VARIABLE(aFrame); + Get().TransmitDone(aError); +#endif +} +#endif // OPENTHREAD_CONFIG_DIAG_ENABLE + +} // namespace ot diff --git a/src/core/radio/radio_platform.cpp b/src/core/radio/radio_platform.cpp new file mode 100644 index 000000000..9d978ecf5 --- /dev/null +++ b/src/core/radio/radio_platform.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the radio platform callbacks into OpenThread and default/weak radio platform APIs. + */ + +#include + +#include "common/instance.hpp" +#include "radio/radio.hpp" + +using namespace ot; + +//--------------------------------------------------------------------------------------------------------------------- +// otPlatRadio callbacks + +extern "C" void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) +{ + Instance *instance = static_cast(aInstance); + + if (instance->IsInitialized()) + { + instance->Get().HandleReceiveDone(static_cast(aFrame), aError); + } +} + +extern "C" void otPlatRadioTxStarted(otInstance *aInstance, otRadioFrame *aFrame) +{ + Instance *instance = static_cast(aInstance); + + if (instance->IsInitialized()) + { + instance->Get().HandleTransmitStarted(*static_cast(aFrame)); + } +} + +extern "C" void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) +{ + Instance *instance = static_cast(aInstance); + + if (instance->IsInitialized()) + { + instance->Get().HandleTransmitDone(*static_cast(aFrame), + static_cast(aAckFrame), aError); + } +} + +extern "C" void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi) +{ + Instance *instance = static_cast(aInstance); + + if (instance->IsInitialized()) + { + instance->Get().HandleEnergyScanDone(aEnergyScanMaxRssi); + } +} + +#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT +extern "C" void otPlatRadioFrameUpdated(otInstance *aInstance, otRadioFrame *aFrame) +{ + Instance *instance = static_cast(aInstance); + + if (instance->IsInitialized()) + { + instance->Get().HandleFrameUpdated(*static_cast(aFrame)); + } +} +#endif + +#if OPENTHREAD_CONFIG_DIAG_ENABLE +extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) +{ + Instance *instance = static_cast(aInstance); + + instance->Get().HandleDiagsReceiveDone(static_cast(aFrame), aError); +} + +extern "C" void otPlatDiagRadioTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) +{ + Instance *instance = static_cast(aInstance); + + instance->Get().HandleDiagsTransmitDone(*static_cast(aFrame), aError); +} +#endif + +//--------------------------------------------------------------------------------------------------------------------- +// Default/weak implementation of radio platform APIs + +OT_TOOL_WEAK uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return Radio::kSupportedChannels; +} + +OT_TOOL_WEAK uint32_t otPlatRadioGetPreferredChannelMask(otInstance *aInstance) +{ + return otPlatRadioGetSupportedChannelMask(aInstance); +} + +OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + return otGetVersionString(); +} diff --git a/src/core/radio/radio_platform_defaults.cpp b/src/core/radio/radio_platform_defaults.cpp deleted file mode 100644 index ee35d14bf..000000000 --- a/src/core/radio/radio_platform_defaults.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file implements the default/weak radio platform APIs. - */ - -#include - -#include "radio/radio.hpp" - -using namespace ot; - -OT_TOOL_WEAK uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return Radio::kSupportedChannels; -} - -OT_TOOL_WEAK uint32_t otPlatRadioGetPreferredChannelMask(otInstance *aInstance) -{ - return otPlatRadioGetSupportedChannelMask(aInstance); -} - -OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - return otGetVersionString(); -}