From 9a10e22e91405f585144a175da1bdd7dd093b3c6 Mon Sep 17 00:00:00 2001 From: Yang Song Date: Thu, 27 Nov 2025 01:38:17 +0800 Subject: [PATCH] [border-agent] meshcop to advertise multi-AIL state in state bitmap (#12157) This change introduces the Multi-AIL (Adjacent Infrastructure Link) detection state into the Border Agent's state bitmap, which is advertised in the MeshCoP service TXT data. The new state is encoded in the `sb` (state bitmap) key and has the following values: 0: Multi-AIL detection is disabled. 1: Multi-AIL detection is enabled, but not detected. 2: Multi-AIL detection is enabled, and is detected. --- include/openthread/border_agent_txt_data.h | 11 +++++++++ include/openthread/instance.h | 2 +- src/core/border_router/multi_ail_detector.cpp | 4 ++++ src/core/meshcop/border_agent_txt_data.cpp | 24 +++++++++++++++---- src/core/meshcop/border_agent_txt_data.hpp | 19 +++++++++++---- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/include/openthread/border_agent_txt_data.h b/include/openthread/border_agent_txt_data.h index a0766c4ca..8738132e6 100644 --- a/include/openthread/border_agent_txt_data.h +++ b/include/openthread/border_agent_txt_data.h @@ -104,6 +104,16 @@ typedef enum otBorderAgentThreadRole OT_BORDER_AGENT_THREAD_ROLE_LEADER = 3, ///< Leader. } otBorderAgentThreadRole; +/** + * Represents the Multi-AIL (Adjacent Infrastructure Link) detection state in a Border Agent State Bitmap. + */ +typedef enum otBorderAgentMultiAilState +{ + OT_BORDER_AGENT_MULTI_AIL_STATE_DISABLED = 0, ///< Multi-AIL detection is disabled. + OT_BORDER_AGENT_MULTI_AIL_STATE_NOT_DETECTED = 1, ///< Multi-AIL detection is enabled, not detected. + OT_BORDER_AGENT_MULTI_AIL_STATE_DETECTED = 2, ///< Multi-AIL detection is enabled, detected. +} otBorderAgentMultiAilState; + /** * Represents Border Agent State Bitmap information. */ @@ -116,6 +126,7 @@ typedef struct otBorderAgentStateBitmap bool mBbrIsActive; ///< Backbone Router function is active. bool mBbrIsPrimary; ///< Device is the Primary Backbone Router. bool mEpskcSupported; ///< ePSKc Mode is supported. + otBorderAgentMultiAilState mMultiAilState; ///< Multi-AIL detection state. } otBorderAgentStateBitmap; /** diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 0e92d9387..d2dbb44bf 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (553) +#define OPENTHREAD_API_VERSION (554) /** * @addtogroup api-instance diff --git a/src/core/border_router/multi_ail_detector.cpp b/src/core/border_router/multi_ail_detector.cpp index ce6db2a16..b47b6c871 100644 --- a/src/core/border_router/multi_ail_detector.cpp +++ b/src/core/border_router/multi_ail_detector.cpp @@ -204,6 +204,10 @@ void MultiAilDetector::HandleTimer(void) } mCallback.InvokeIfSet(mDetected); + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE + Get().Refresh(); +#endif } #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) diff --git a/src/core/meshcop/border_agent_txt_data.cpp b/src/core/meshcop/border_agent_txt_data.cpp index 9ae6824d6..daa207a2e 100644 --- a/src/core/meshcop/border_agent_txt_data.cpp +++ b/src/core/meshcop/border_agent_txt_data.cpp @@ -233,6 +233,20 @@ uint32_t TxtData::StateBitmap::Determine(Instance &aInstance) break; } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_MULTI_AIL_DETECTION_ENABLE + { + MultiAilState state = kMultiAilDisabled; + + if (aInstance.Get().IsEnabled()) + { + state = + aInstance.Get().IsDetected() ? kMultiAilDetected : kMultiAilNotDetected; + } + + bitmap |= (static_cast(state) << kOffsetMultiAilState); + } +#endif + #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE if (aInstance.Get().IsAttached()) { @@ -411,10 +425,12 @@ void TxtData::StateBitmap::Parse(uint32_t aBitmap, Info &aInfo) { ClearAllBytes(aInfo); - aInfo.mConnMode = static_cast((aBitmap & kMaskConnMode) >> kOffsetConnMode); - aInfo.mThreadIfState = static_cast((aBitmap & kMaskIfState) >> kOffsetIfState); - aInfo.mAvailability = static_cast((aBitmap & kMaskAvailability) >> kOffsetAvailability); - aInfo.mThreadRole = static_cast((aBitmap & kMaskRole) >> kOffsetRole); + aInfo.mConnMode = static_cast((aBitmap & kMaskConnMode) >> kOffsetConnMode); + aInfo.mThreadIfState = static_cast((aBitmap & kMaskIfState) >> kOffsetIfState); + aInfo.mAvailability = static_cast((aBitmap & kMaskAvailability) >> kOffsetAvailability); + aInfo.mThreadRole = static_cast((aBitmap & kMaskRole) >> kOffsetRole); + aInfo.mMultiAilState = + static_cast((aBitmap & kMaskMultiAilState) >> kOffsetMultiAilState); aInfo.mBbrIsActive = aBitmap & kFlagBbrIsActive; aInfo.mBbrIsPrimary = aBitmap & kFlagBbrIsPrimary; aInfo.mEpskcSupported = aBitmap & kFlagEpskcSupported; diff --git a/src/core/meshcop/border_agent_txt_data.hpp b/src/core/meshcop/border_agent_txt_data.hpp index e08f75c09..83fe926e4 100644 --- a/src/core/meshcop/border_agent_txt_data.hpp +++ b/src/core/meshcop/border_agent_txt_data.hpp @@ -63,10 +63,11 @@ class TxtData : public InstanceLocator friend class ot::Notifier; public: - typedef otBorderAgentConnMode ConnMode; ///< Connection Mode in a Border Agent State Bitmap. - typedef otBorderAgentThreadIfState IfState; ///< Thread Interface State in a Border Agent State Bitmap. - typedef otBorderAgentAvailability Availability; ///< Availability Status in a Border Agent State Bitmap. - typedef otBorderAgentThreadRole Role; ///< Thread Role in a Border Agent State Bitmap. + typedef otBorderAgentConnMode ConnMode; ///< Connection Mode in a Border Agent State Bitmap. + typedef otBorderAgentThreadIfState IfState; ///< Thread Interface State in a Border Agent State Bitmap. + typedef otBorderAgentAvailability Availability; ///< Availability Status in a Border Agent State Bitmap. + typedef otBorderAgentThreadRole Role; ///< Thread Role in a Border Agent State Bitmap. + typedef otBorderAgentMultiAilState MultiAilState; ///< Multi-AIL detection state in a Border Agent State Bitmap. static constexpr ConnMode kConnModeDisabled = OT_BORDER_AGENT_CONN_MODE_DISABLED; ///< Not allowed. static constexpr ConnMode kConnModePskc = OT_BORDER_AGENT_CONN_MODE_PSKC; ///< DTLS with PSKc. @@ -86,6 +87,10 @@ public: static constexpr Role kRoleRouter = OT_BORDER_AGENT_THREAD_ROLE_ROUTER; ///< Router. static constexpr Role kRoleLeader = OT_BORDER_AGENT_THREAD_ROLE_LEADER; ///< Leader. + static constexpr MultiAilState kMultiAilDisabled = OT_BORDER_AGENT_MULTI_AIL_STATE_DISABLED; ///< Disabled. + static constexpr MultiAilState kMultiAilNotDetected = OT_BORDER_AGENT_MULTI_AIL_STATE_NOT_DETECTED; ///< Not det. + static constexpr MultiAilState kMultiAilDetected = OT_BORDER_AGENT_MULTI_AIL_STATE_DETECTED; ///< Detected. + /** * Initializes the `TxtData` object. * @@ -267,6 +272,7 @@ private: static constexpr uint8_t kOffsetBbrIsPrimary = 8; static constexpr uint8_t kOffsetRole = 9; static constexpr uint8_t kOffsetEpskcSupported = 11; + static constexpr uint8_t kOffsetMultiAilState = 12; static constexpr uint32_t kMaskConnMode = 7 << kOffsetConnMode; static constexpr uint32_t kMaskIfState = 3 << kOffsetIfState; @@ -275,6 +281,7 @@ private: static constexpr uint32_t kFlagBbrIsPrimary = 1 << kOffsetBbrIsPrimary; static constexpr uint32_t kMaskRole = 3 << kOffsetRole; static constexpr uint32_t kFlagEpskcSupported = 1 << kOffsetEpskcSupported; + static constexpr uint32_t kMaskMultiAilState = 3 << kOffsetMultiAilState; static_assert(kConnModeDisabled == 0, "kConnModeDisabled is incorrect"); static_assert(kConnModePskc == 1, "kConnModePskc is incorrect"); @@ -294,6 +301,10 @@ private: static_assert(kRoleRouter == 2, "kRoleRouter is incorrect"); static_assert(kRoleLeader == 3, "kRoleLeader is incorrect"); + static_assert(kMultiAilDisabled == 0, "kMultiAilDisabled is incorrect"); + static_assert(kMultiAilNotDetected == 1, "kMultiAilNotDetected is incorrect"); + static_assert(kMultiAilDetected == 2, "kMultiAilDetected is incorrect"); + #if OPENTHREAD_CONFIG_BORDER_AGENT_TXT_DATA_PARSER_ENABLE typedef otBorderAgentStateBitmap Info;