mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[multi-radio] adding new public OT APIs for multi radio link config (#4440)
This commit adds new public OT definitions and API for radio link configuration in `openthread/multi_radio.h`. Mainly the function `otMultiRadioGetNeighborInfo()` is added which allows info about a neighbor to be retrieved (e.g., which radio links are supported by the neighbor and their preference value).
This commit is contained in:
committed by
Jonathan Hui
parent
925f75cf06
commit
3da1c540e9
@@ -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 \
|
||||
|
||||
@@ -79,6 +79,8 @@
|
||||
*
|
||||
* @defgroup api-message Message
|
||||
*
|
||||
* @defgroup api-multi-radio Multi Radio Link
|
||||
*
|
||||
* @defgroup api-thread Thread
|
||||
*
|
||||
* @{
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -85,6 +85,7 @@ source_set("openthread") {
|
||||
"link_raw.h",
|
||||
"logging.h",
|
||||
"message.h",
|
||||
"multi_radio.h",
|
||||
"ncp.h",
|
||||
"netdata.h",
|
||||
"netdiag.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
|
||||
|
||||
@@ -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 <openthread/platform/radio.h>
|
||||
|
||||
#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_
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 <openthread/multi_radio.h>
|
||||
|
||||
#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<Instance *>(aInstance);
|
||||
Neighbor *neighbor;
|
||||
|
||||
neighbor = instance.Get<NeighborTable>().FindNeighbor(*static_cast<const Mac::ExtAddress *>(aExtAddress),
|
||||
Neighbor::kInStateAnyExceptInvalid);
|
||||
VerifyOrExit(neighbor != NULL, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
neighbor->PopulateMultiRadioInfo(*aInfo);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
@@ -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);
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include <openthread/multi_radio.h>
|
||||
|
||||
#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); }
|
||||
|
||||
Reference in New Issue
Block a user