diff --git a/Android.mk b/Android.mk index 60348b113..69a14d981 100644 --- a/Android.mk +++ b/Android.mk @@ -170,6 +170,7 @@ LOCAL_SRC_FILES := \ src/core/api/link_raw_api.cpp \ src/core/api/logging_api.cpp \ src/core/api/message_api.cpp \ + src/core/api/multi_radio_api.cpp \ src/core/api/netdata_api.cpp \ src/core/api/netdiag_api.cpp \ src/core/api/random_crypto_api.cpp \ diff --git a/doc/ot_api_doc.h b/doc/ot_api_doc.h index 5f9f1444c..02af682d4 100644 --- a/doc/ot_api_doc.h +++ b/doc/ot_api_doc.h @@ -79,6 +79,8 @@ * * @defgroup api-message Message * + * @defgroup api-multi-radio Multi Radio Link + * * @defgroup api-thread Thread * * @{ diff --git a/include/Makefile.am b/include/Makefile.am index 460a1c6e5..e5554d3a9 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -65,6 +65,7 @@ openthread_headers = \ openthread/link_raw.h \ openthread/logging.h \ openthread/message.h \ + openthread/multi_radio.h \ openthread/ncp.h \ openthread/netdata.h \ openthread/netdiag.h \ diff --git a/include/openthread/BUILD.gn b/include/openthread/BUILD.gn index ae91fa73f..47b6b73f8 100644 --- a/include/openthread/BUILD.gn +++ b/include/openthread/BUILD.gn @@ -85,6 +85,7 @@ source_set("openthread") { "link_raw.h", "logging.h", "message.h", + "multi_radio.h", "ncp.h", "netdata.h", "netdiag.h", diff --git a/include/openthread/instance.h b/include/openthread/instance.h index aa726b0e4..a16ba7391 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (53) +#define OPENTHREAD_API_VERSION (54) /** * @addtogroup api-instance diff --git a/include/openthread/multi_radio.h b/include/openthread/multi_radio.h new file mode 100644 index 000000000..744b1c080 --- /dev/null +++ b/include/openthread/multi_radio.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020, 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 + * @brief + * This file defines the OpenThread Multi Radio Link APIs. + */ + +#ifndef OPENTHREAD_MULTI_RADIO_H_ +#define OPENTHREAD_MULTI_RADIO_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup api-multi-radio + * + * @brief + * This module includes definitions and functions for multi radio link. + * + * @{ + * + */ + +/** + * This type represents information associated with a radio link. + * + */ +typedef struct otRadioLinkInfo +{ + uint8_t mPreference; ///< Preference level of radio link +} otRadioLinkInfo; + +/** + * This type represents multi radio link information associated with a neighbor. + * + */ +typedef struct otMultiRadioNeighborInfo +{ + bool mSupportsIeee802154 : 1; ///< Neighbor supports IEEE 802.15.4 radio link + bool mSupportsTrelUdp6 : 1; ///< Neighbor supports Thread Radio Encapsulation Link (TREL) radio link. + otRadioLinkInfo mIeee802154Info; ///< Additional info for 15.4 radio link (applicable when supported). + otRadioLinkInfo mTrelUdp6Info; ///< Additional info for TREL radio link (applicable when supported). +} otMultiRadioNeighborInfo; + +/** + * This function gets the multi radio link information associated with a neighbor with a given Extended Address. + * + * This function requires the multi radio link feature to be enabled (please see `config/radio_link.h`). + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aExtAddress The Extended Address of neighbor. + * @param[out] aNeighborInfo A pointer to `otMultiRadioNeighborInfo` to output the neighbor info (on success). + * + * @retval OT_ERROR_NONE Neighbor was found and @p aNeighborInfo was updated successfully. + * @retval OT_ERROR_NOT_FOUND Could not find a neighbor with @p aExtAddress. + * + */ +otError otMultiRadioGetNeighborInfo(otInstance * aInstance, + const otExtAddress * aExtAddress, + otMultiRadioNeighborInfo *aNeighborInfo); + +/** + * @} + * + */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTHREAD_MULTI_RADIO_H_ diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index 14edd568b..7d0aa52b7 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -318,6 +318,7 @@ openthread_core_files = [ "api/link_raw_api.cpp", "api/logging_api.cpp", "api/message_api.cpp", + "api/multi_radio_api.cpp", "api/netdata_api.cpp", "api/netdiag_api.cpp", "api/network_time_api.cpp", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b9ea7c4b6..f1b945583 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -58,6 +58,7 @@ set(COMMON_SOURCES api/link_raw_api.cpp api/logging_api.cpp api/message_api.cpp + api/multi_radio_api.cpp api/netdata_api.cpp api/netdiag_api.cpp api/network_time_api.cpp diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 9670f0293..8daddd7e0 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -135,6 +135,7 @@ SOURCES_COMMON = \ api/link_raw_api.cpp \ api/logging_api.cpp \ api/message_api.cpp \ + api/multi_radio_api.cpp \ api/netdata_api.cpp \ api/netdiag_api.cpp \ api/network_time_api.cpp \ diff --git a/src/core/api/multi_radio_api.cpp b/src/core/api/multi_radio_api.cpp new file mode 100644 index 000000000..9be05c288 --- /dev/null +++ b/src/core/api/multi_radio_api.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020, 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 OpenThread Multi Radio Link APIs. + */ + +#include "openthread-core-config.h" + +#include + +#include "common/code_utils.hpp" +#include "common/debug.hpp" +#include "common/instance.hpp" +#include "common/locator-getters.hpp" +#include "thread/radio_selector.hpp" + +using namespace ot; + +#if OPENTHREAD_CONFIG_MULTI_RADIO + +otError otMultiRadioGetNeighborInfo(otInstance * aInstance, + const otExtAddress * aExtAddress, + otMultiRadioNeighborInfo *aInfo) +{ + otError error = OT_ERROR_NONE; + Instance &instance = *static_cast(aInstance); + Neighbor *neighbor; + + neighbor = instance.Get().FindNeighbor(*static_cast(aExtAddress), + Neighbor::kInStateAnyExceptInvalid); + VerifyOrExit(neighbor != NULL, error = OT_ERROR_NOT_FOUND); + + neighbor->PopulateMultiRadioInfo(*aInfo); + +exit: + return error; +} +#endif // OPENTHREAD_CONFIG_MULTI_RADIO diff --git a/src/core/thread/radio_selector.cpp b/src/core/thread/radio_selector.cpp index d743fdeb3..f630d89ce 100644 --- a/src/core/thread/radio_selector.cpp +++ b/src/core/thread/radio_selector.cpp @@ -59,6 +59,27 @@ RadioSelector::RadioSelector(Instance &aInstance) { } +void RadioSelector::NeighborInfo::PopulateMultiRadioInfo(MultiRadioInfo &aInfo) +{ + memset(&aInfo, 0, sizeof(MultiRadioInfo)); + +#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE + if (GetSupportedRadioTypes().Contains(Mac::kRadioTypeIeee802154)) + { + aInfo.mSupportsIeee802154 = true; + aInfo.mIeee802154Info.mPreference = GetRadioPreference(Mac::kRadioTypeIeee802154); + } +#endif + +#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE + if (GetSupportedRadioTypes().Contains(Mac::kRadioTypeTrel)) + { + aInfo.mSupportsTrelUdp6 = true; + aInfo.mTrelUdp6Info.mPreference = GetRadioPreference(Mac::kRadioTypeTrel); + } +#endif +} + otLogLevel RadioSelector::UpdatePreference(Neighbor &aNeighbor, Mac::RadioType aRadioType, int16_t aDifference) { uint8_t old = aNeighbor.GetRadioPreference(aRadioType); diff --git a/src/core/thread/radio_selector.hpp b/src/core/thread/radio_selector.hpp index d7adf3365..369f15b61 100644 --- a/src/core/thread/radio_selector.hpp +++ b/src/core/thread/radio_selector.hpp @@ -36,6 +36,8 @@ #include "openthread-core-config.h" +#include + #include "common/locator.hpp" #include "common/message.hpp" #include "mac/mac_frame.hpp" @@ -71,6 +73,13 @@ public: { friend class RadioSelector; + public: + /** + * This type represents multi radio information associated with a neighbor. + * + */ + typedef otMultiRadioNeighborInfo MultiRadioInfo; + /** * This method returns the supported radio types by the neighbor. * @@ -79,6 +88,14 @@ public: */ Mac::RadioTypes GetSupportedRadioTypes(void) const { return mSupportedRadioTypes; } + /** + * This method retrieves the multi radio information `otMultiRadioNeighborInfo` associated with the neighbor. + * + * @param[out] aInfo A reference to `MultiRadioInfo` to populate with neighbor info. + * + */ + void PopulateMultiRadioInfo(MultiRadioInfo &aInfo); + private: void AddSupportedRadioType(Mac::RadioType aType) { mSupportedRadioTypes.Add(aType); } void RemoveSupportedRadioType(Mac::RadioType aType) { mSupportedRadioTypes.Remove(aType); }