From af6279f606b1ee8d71fc7dfa4eaa1136481d3a85 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 8 Oct 2025 12:47:30 -0700 Subject: [PATCH] [border-agent] introduce `BorderAgent` namespace (#12002) This change reorganizes the `BorderAgent` related classes into a new `MeshCoP::BorderAgent` namespace to improve code structure and clarity. The following changes are included: - `MeshCoP::BorderAgent` class is renamed to `Manager` and placed within the new `MeshCoP::BorderAgent` namespace. - `MeshCoP::BorderAgentTracker` is renamed to `Tracker` under the new namespace. - `EphemeralKeyManager` is moved from being a nested class in `BorderAgent` to `MeshCoP::BorderAgent::EphemeralKeyManager`. - `EphemeralKeyManager` is now a direct member of the `Instance` class, simplifying accessing it. All related calls and test files are updated to reflect these changes. --- src/core/api/border_agent_api.cpp | 22 +- src/core/api/border_agent_tracker_api.cpp | 6 +- src/core/border_router/routing_manager.cpp | 2 +- src/core/common/notifier.cpp | 2 +- src/core/instance/instance.cpp | 5 +- src/core/instance/instance.hpp | 20 +- src/core/meshcop/border_agent.cpp | 278 +++++++------- src/core/meshcop/border_agent.hpp | 400 +++++++++++---------- src/core/meshcop/border_agent_tracker.cpp | 114 +++--- src/core/meshcop/border_agent_tracker.hpp | 8 +- src/core/net/dnssd.cpp | 4 +- src/core/net/ip6_filter.cpp | 2 +- src/core/thread/mle_ftd.cpp | 4 +- src/core/thread/tmf.cpp | 2 +- src/core/utils/history_tracker.hpp | 2 +- tests/nexus/test_border_agent.cpp | 267 +++++++------- tests/nexus/test_border_agent_tracker.cpp | 38 +- tests/unit/test_mdns.cpp | 2 +- tests/unit/test_srp_adv_proxy.cpp | 2 +- 19 files changed, 596 insertions(+), 584 deletions(-) diff --git a/src/core/api/border_agent_api.cpp b/src/core/api/border_agent_api.cpp index f823262ae..36fc45f35 100644 --- a/src/core/api/border_agent_api.cpp +++ b/src/core/api/border_agent_api.cpp @@ -44,17 +44,17 @@ using namespace ot; void otBorderAgentSetEnabled(otInstance *aInstance, bool aEnabled) { - AsCoreType(aInstance).Get().SetEnabled(aEnabled); + AsCoreType(aInstance).Get().SetEnabled(aEnabled); } bool otBorderAgentIsEnabled(otInstance *aInstance) { - return AsCoreType(aInstance).Get().IsEnabled(); + return AsCoreType(aInstance).Get().IsEnabled(); } bool otBorderAgentIsActive(otInstance *aInstance) { - return AsCoreType(aInstance).Get().IsRunning(); + return AsCoreType(aInstance).Get().IsRunning(); } #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE @@ -62,32 +62,32 @@ otError otBorderAgentSetMeshCoPServiceBaseName(otInstance *aInstance, const char { AssertPointerIsNotNull(aBaseName); - return AsCoreType(aInstance).Get().SetServiceBaseName(aBaseName); + return AsCoreType(aInstance).Get().SetServiceBaseName(aBaseName); } void otBorderAgentSetVendorTxtData(otInstance *aInstance, const uint8_t *aVendorData, uint16_t aVendorDataLength) { - AsCoreType(aInstance).Get().SetVendorTxtData(aVendorData, aVendorDataLength); + AsCoreType(aInstance).Get().SetVendorTxtData(aVendorData, aVendorDataLength); } #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE otError otBorderAgentGetId(otInstance *aInstance, otBorderAgentId *aId) { - AsCoreType(aInstance).Get().GetId(AsCoreType(aId)); + AsCoreType(aInstance).Get().GetId(AsCoreType(aId)); return kErrorNone; } otError otBorderAgentSetId(otInstance *aInstance, const otBorderAgentId *aId) { - AsCoreType(aInstance).Get().SetId(AsCoreType(aId)); + AsCoreType(aInstance).Get().SetId(AsCoreType(aId)); return kErrorNone; } #endif uint16_t otBorderAgentGetUdpPort(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetUdpPort(); + return AsCoreType(aInstance).Get().GetUdpPort(); } void otBorderAgentInitSessionIterator(otInstance *aInstance, otBorderAgentSessionIterator *aIterator) @@ -106,17 +106,17 @@ void otBorderAgentSetMeshCoPServiceChangedCallback(otInstance otBorderAgentMeshCoPServiceChangedCallback aCallback, void *aContext) { - AsCoreType(aInstance).Get().SetServiceChangedCallback(aCallback, aContext); + AsCoreType(aInstance).Get().SetServiceChangedCallback(aCallback, aContext); } otError otBorderAgentGetMeshCoPServiceTxtData(otInstance *aInstance, otBorderAgentMeshCoPServiceTxtData *aTxtData) { - return AsCoreType(aInstance).Get().PrepareServiceTxtData(*aTxtData); + return AsCoreType(aInstance).Get().PrepareServiceTxtData(*aTxtData); } const otBorderAgentCounters *otBorderAgentGetCounters(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetCounters(); + return &AsCoreType(aInstance).Get().GetCounters(); } #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE diff --git a/src/core/api/border_agent_tracker_api.cpp b/src/core/api/border_agent_tracker_api.cpp index 6f90acc1b..e79936e95 100644 --- a/src/core/api/border_agent_tracker_api.cpp +++ b/src/core/api/border_agent_tracker_api.cpp @@ -39,13 +39,13 @@ using namespace ot; void otBorderAgentTrackerSetEnabled(otInstance *aInstance, bool aEnable) { - AsCoreType(aInstance).Get().SetEnabled(aEnable, - MeshCoP::BorderAgentTracker::kRequesterUser); + AsCoreType(aInstance).Get().SetEnabled( + aEnable, MeshCoP::BorderAgent::Tracker::kRequesterUser); } bool otBorderAgentTrackerIsRunning(otInstance *aInstance) { - return AsCoreType(aInstance).Get().IsRunning(); + return AsCoreType(aInstance).Get().IsRunning(); } void otBorderAgentTrackerInitIterator(otInstance *aInstance, otBorderAgentTrackerIterator *aIterator) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 33039c715..40ed432c0 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1045,7 +1045,7 @@ void RoutingManager::OmrPrefixManager::SetFavoredPrefix(const OmrPrefix &aOmrPre if (oldFavoredPrefix != mFavoredPrefix) { #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - Get().HandleFavoredOmrPrefixChanged(); + Get().HandleFavoredOmrPrefixChanged(); #endif LogInfo("Favored OMR prefix: %s -> %s", FavoredToString(oldFavoredPrefix).AsCString(), FavoredToString(mFavoredPrefix).AsCString()); diff --git a/src/core/common/notifier.cpp b/src/core/common/notifier.cpp index b89d7a2a3..527d648a1 100644 --- a/src/core/common/notifier.cpp +++ b/src/core/common/notifier.cpp @@ -131,7 +131,7 @@ void Notifier::EmitEvents(void) Get().HandleNotifierEvents(events); #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - Get().HandleNotifierEvents(events); + Get().HandleNotifierEvents(events); #endif #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE) Get().HandleNotifierEvents(events); diff --git a/src/core/instance/instance.cpp b/src/core/instance/instance.cpp index e7324bac0..ebd359490 100644 --- a/src/core/instance/instance.cpp +++ b/src/core/instance/instance.cpp @@ -172,7 +172,10 @@ Instance::Instance(void) , mNetworkDiagnosticClient(*this) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - , mBorderAgent(*this) + , mBorderAgentManager(*this) +#endif +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE + , mBorderAgentEphemeralKeyManager(*this) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE , mBorderAgentTracker(*this) diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index cd3a001f1..c2750da59 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -588,11 +588,15 @@ private: #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - MeshCoP::BorderAgent mBorderAgent; + MeshCoP::BorderAgent::Manager mBorderAgentManager; +#endif + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE + MeshCoP::BorderAgent::EphemeralKeyManager mBorderAgentEphemeralKeyManager; #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE - MeshCoP::BorderAgentTracker mBorderAgentTracker; + MeshCoP::BorderAgent::Tracker mBorderAgentTracker; #endif #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD @@ -1028,20 +1032,20 @@ template <> inline MeshCoP::DatasetUpdater &Instance::Get(void) { return mDatase #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE -template <> inline MeshCoP::BorderAgent &Instance::Get(void) { return mBorderAgent; } -#endif - -#if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE -template <> inline MeshCoP::BorderAgentTracker &Instance::Get(void) { return mBorderAgentTracker; } +template <> inline MeshCoP::BorderAgent::Manager &Instance::Get(void) { return mBorderAgentManager; } #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE template <> inline MeshCoP::BorderAgent::EphemeralKeyManager &Instance::Get(void) { - return mBorderAgent.GetEphemeralKeyManager(); + return mBorderAgentEphemeralKeyManager; } #endif +#if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE +template <> inline MeshCoP::BorderAgent::Tracker &Instance::Get(void) { return mBorderAgentTracker; } +#endif + #if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE template <> inline AnnounceSender &Instance::Get(void) { return mAnnounceSender; } #endif diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index 2f14be12f..eebd7d67f 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -39,19 +39,20 @@ namespace ot { namespace MeshCoP { +namespace BorderAgent { RegisterLogModule("BorderAgent"); //---------------------------------------------------------------------------------------------------------------------- -// `BorderAgent` +// `Manager` -const char BorderAgent::kTxtDataRecordVersion[] = "1"; +const char Manager::kTxtDataRecordVersion[] = "1"; #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -const char BorderAgent::kServiceType[] = "_meshcop._udp"; -const char BorderAgent::kDefaultBaseServiceName[] = OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME; +const char Manager::kServiceType[] = "_meshcop._udp"; +const char Manager::kDefaultBaseServiceName[] = OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME; #endif -BorderAgent::BorderAgent(Instance &aInstance) +Manager::Manager(Instance &aInstance) : InstanceLocator(aInstance) , mEnabled(true) , mIsRunning(false) @@ -60,9 +61,6 @@ BorderAgent::BorderAgent(Instance &aInstance) , mIdInitialized(false) #endif , mServiceTask(aInstance) -#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - , mEphemeralKeyManager(aInstance) -#endif { ClearAllBytes(mCounters); @@ -76,7 +74,7 @@ BorderAgent::BorderAgent(Instance &aInstance) } #if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE -void BorderAgent::GetId(Id &aId) +void Manager::GetId(Id &aId) { if (mIdInitialized) { @@ -97,7 +95,7 @@ exit: return; } -void BorderAgent::SetId(const Id &aId) +void Manager::SetId(const Id &aId) { if (mIdInitialized) { @@ -114,7 +112,7 @@ exit: } #endif // OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE -void BorderAgent::SetEnabled(bool aEnabled) +void Manager::SetEnabled(bool aEnabled) { VerifyOrExit(mEnabled != aEnabled); mEnabled = aEnabled; @@ -132,7 +130,7 @@ exit: return; } -void BorderAgent::UpdateState(void) +void Manager::UpdateState(void) { if (mEnabled && Get().IsAttached()) { @@ -144,15 +142,15 @@ void BorderAgent::UpdateState(void) } } -void BorderAgent::Start(void) +void Manager::Start(void) { Error error = kErrorNone; Pskc pskc; VerifyOrExit(!mIsRunning); - mDtlsTransport.SetAcceptCallback(BorderAgent::HandleAcceptSession, this); - mDtlsTransport.SetRemoveSessionCallback(BorderAgent::HandleRemoveSession, this); + mDtlsTransport.SetAcceptCallback(Manager::HandleAcceptSession, this); + mDtlsTransport.SetRemoveSessionCallback(Manager::HandleRemoveSession, this); SuccessOrExit(error = mDtlsTransport.Open()); SuccessOrExit(error = mDtlsTransport.Bind(kUdpPort)); @@ -175,7 +173,7 @@ exit: LogWarnOnError(error, "start agent"); } -void BorderAgent::Stop(void) +void Manager::Stop(void) { VerifyOrExit(mIsRunning); @@ -189,16 +187,16 @@ exit: return; } -uint16_t BorderAgent::GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); } +uint16_t Manager::GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); } -void BorderAgent::SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext) +void Manager::SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext) { mServiceChangedCallback.Set(aCallback, aContext); PostServiceTask(); } -void BorderAgent::HandleNotifierEvents(Events aEvents) +void Manager::HandleNotifierEvents(Events aEvents) { if (aEvents.Contains(kEventThreadRoleChanged)) { @@ -231,24 +229,24 @@ exit: return; } -SecureSession *BorderAgent::HandleAcceptSession(void *aContext, const Ip6::MessageInfo &aMessageInfo) +SecureSession *Manager::HandleAcceptSession(void *aContext, const Ip6::MessageInfo &aMessageInfo) { OT_UNUSED_VARIABLE(aMessageInfo); - return static_cast(aContext)->HandleAcceptSession(); + return static_cast(aContext)->HandleAcceptSession(); } -BorderAgent::CoapDtlsSession *BorderAgent::HandleAcceptSession(void) +Manager::CoapDtlsSession *Manager::HandleAcceptSession(void) { return CoapDtlsSession::Allocate(GetInstance(), mDtlsTransport); } -void BorderAgent::HandleRemoveSession(void *aContext, SecureSession &aSession) +void Manager::HandleRemoveSession(void *aContext, SecureSession &aSession) { - static_cast(aContext)->HandleRemoveSession(aSession); + static_cast(aContext)->HandleRemoveSession(aSession); } -void BorderAgent::HandleRemoveSession(SecureSession &aSession) +void Manager::HandleRemoveSession(SecureSession &aSession) { CoapDtlsSession &coapSession = static_cast(aSession); @@ -256,14 +254,14 @@ void BorderAgent::HandleRemoveSession(SecureSession &aSession) coapSession.Free(); } -void BorderAgent::HandleSessionConnected(CoapDtlsSession &aSession) +void Manager::HandleSessionConnected(CoapDtlsSession &aSession) { OT_UNUSED_VARIABLE(aSession); #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - if (mEphemeralKeyManager.OwnsSession(aSession)) + if (Get().OwnsSession(aSession)) { - mEphemeralKeyManager.HandleSessionConnected(); + Get().HandleSessionConnected(); } else #endif @@ -272,14 +270,14 @@ void BorderAgent::HandleSessionConnected(CoapDtlsSession &aSession) } } -void BorderAgent::HandleSessionDisconnected(CoapDtlsSession &aSession, CoapDtlsSession::ConnectEvent aEvent) +void Manager::HandleSessionDisconnected(CoapDtlsSession &aSession, CoapDtlsSession::ConnectEvent aEvent) { OT_UNUSED_VARIABLE(aSession); #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - if (mEphemeralKeyManager.OwnsSession(aSession)) + if (Get().OwnsSession(aSession)) { - mEphemeralKeyManager.HandleSessionDisconnected(aEvent); + Get().HandleSessionDisconnected(aEvent); } else #endif @@ -291,14 +289,14 @@ void BorderAgent::HandleSessionDisconnected(CoapDtlsSession &aSession, CoapDtlsS } } -void BorderAgent::HandleCommissionerPetitionAccepted(CoapDtlsSession &aSession) +void Manager::HandleCommissionerPetitionAccepted(CoapDtlsSession &aSession) { OT_UNUSED_VARIABLE(aSession); #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - if (mEphemeralKeyManager.OwnsSession(aSession)) + if (Get().OwnsSession(aSession)) { - mEphemeralKeyManager.HandleCommissionerPetitionAccepted(); + Get().HandleCommissionerPetitionAccepted(); } else #endif @@ -307,7 +305,7 @@ void BorderAgent::HandleCommissionerPetitionAccepted(CoapDtlsSession &aSession) } } -BorderAgent::CoapDtlsSession *BorderAgent::FindActiveCommissionerSession(void) +Manager::CoapDtlsSession *Manager::FindActiveCommissionerSession(void) { CoapDtlsSession *commissionerSession = nullptr; @@ -323,17 +321,17 @@ BorderAgent::CoapDtlsSession *BorderAgent::FindActiveCommissionerSession(void) } #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - if ((mEphemeralKeyManager.mCoapDtlsSession != nullptr) && - mEphemeralKeyManager.mCoapDtlsSession->IsActiveCommissioner()) + if ((Get().mCoapDtlsSession != nullptr) && + Get().mCoapDtlsSession->IsActiveCommissioner()) { - commissionerSession = mEphemeralKeyManager.mCoapDtlsSession; + commissionerSession = Get().mCoapDtlsSession; } #endif return commissionerSession; } -Coap::Message::Code BorderAgent::CoapCodeFromError(Error aError) +Coap::Message::Code Manager::CoapCodeFromError(Error aError) { Coap::Message::Code code; @@ -355,7 +353,7 @@ Coap::Message::Code BorderAgent::CoapCodeFromError(Error aError) return code; } -template <> void BorderAgent::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) +template <> void Manager::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { // This is from TMF agent. @@ -382,7 +380,7 @@ exit: FreeMessageOnError(message, error); } -void BorderAgent::PostServiceTask(void) +void Manager::PostServiceTask(void) { VerifyOrExit(mEnabled); @@ -396,7 +394,7 @@ exit: return; } -void BorderAgent::HandleServiceTask(void) +void Manager::HandleServiceTask(void) { VerifyOrExit(mEnabled); @@ -411,7 +409,7 @@ exit: #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -Error BorderAgent::SetServiceBaseName(const char *aBaseName) +Error Manager::SetServiceBaseName(const char *aBaseName) { Error error = kErrorNone; Dns::Name::LabelBuffer newName; @@ -431,7 +429,7 @@ exit: return error; } -void BorderAgent::SetVendorTxtData(const uint8_t *aVendorData, uint16_t aVendorDataLength) +void Manager::SetVendorTxtData(const uint8_t *aVendorData, uint16_t aVendorDataLength) { VerifyOrExit(!mVendorTxtData.Matches(aVendorData, aVendorDataLength)); @@ -442,7 +440,7 @@ exit: return; } -const char *BorderAgent::GetServiceName(void) +const char *Manager::GetServiceName(void) { if (IsServiceNameEmpty()) { @@ -452,14 +450,14 @@ const char *BorderAgent::GetServiceName(void) return mServiceName; } -void BorderAgent::ConstrcutServiceName(const char *aBaseName, Dns::Name::LabelBuffer &aNameBuffer) +void Manager::ConstrcutServiceName(const char *aBaseName, Dns::Name::LabelBuffer &aNameBuffer) { StringWriter writer(aNameBuffer, sizeof(Dns::Name::LabelBuffer)); writer.Append("%.*s%s", kBaseServiceNameMaxLen, aBaseName, Get().GetExtAddress().ToString().AsCString()); } -void BorderAgent::RegisterService(void) +void Manager::RegisterService(void) { Dnssd::Service service; uint8_t *txtDataBuffer; @@ -501,7 +499,7 @@ exit: return; } -void BorderAgent::UnregisterService(void) +void Manager::UnregisterService(void) { Dnssd::Service service; @@ -520,12 +518,12 @@ exit: #endif // OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -Error BorderAgent::PrepareServiceTxtData(ServiceTxtData &aTxtData) +Error Manager::PrepareServiceTxtData(ServiceTxtData &aTxtData) { return PrepareServiceTxtData(aTxtData.mData, sizeof(aTxtData.mData), aTxtData.mLength); } -Error BorderAgent::PrepareServiceTxtData(uint8_t *aBuffer, uint16_t aBufferSize, uint16_t &aLength) +Error Manager::PrepareServiceTxtData(uint8_t *aBuffer, uint16_t aBufferSize, uint16_t &aLength) { Error error = kErrorNone; Dns::TxtDataEncoder encoder(aBuffer, aBufferSize); @@ -606,7 +604,7 @@ exit: return error; } -uint32_t BorderAgent::DetermineStateBitmap(void) const +uint32_t Manager::DetermineStateBitmap(void) const { uint32_t bitmap = 0; @@ -641,7 +639,7 @@ uint32_t BorderAgent::DetermineStateBitmap(void) const #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - if (mEphemeralKeyManager.GetState() != EphemeralKeyManager::kStateDisabled) + if (Get().GetState() != EphemeralKeyManager::kStateDisabled) { bitmap |= StateBitmap::kFlagEpskcSupported; } @@ -651,15 +649,15 @@ uint32_t BorderAgent::DetermineStateBitmap(void) const } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgent::SessionIterator +// Manager::SessionIterator -void BorderAgent::SessionIterator::Init(Instance &aInstance) +void Manager::SessionIterator::Init(Instance &aInstance) { - SetSession(static_cast(aInstance.Get().mDtlsTransport.GetSessions().GetHead())); + SetSession(static_cast(aInstance.Get().mDtlsTransport.GetSessions().GetHead())); SetInitTime(aInstance.Get().GetUptime()); } -Error BorderAgent::SessionIterator::GetNextSessionInfo(SessionInfo &aSessionInfo) +Error Manager::SessionIterator::GetNextSessionInfo(SessionInfo &aSessionInfo) { Error error = kErrorNone; CoapDtlsSession *session = GetSession(); @@ -679,15 +677,15 @@ exit: } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgent::EphemeralKeyManager +// EphemeralKeyManager #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -const char BorderAgent::EphemeralKeyManager::kServiceType[] = "_meshcop-e._udp"; +const char EphemeralKeyManager::kServiceType[] = "_meshcop-e._udp"; #endif -BorderAgent::EphemeralKeyManager::EphemeralKeyManager(Instance &aInstance) +EphemeralKeyManager::EphemeralKeyManager(Instance &aInstance) : InstanceLocator(aInstance) #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_FEATURE_ENABLED_BY_DEFAULT , mState(kStateStopped) @@ -701,27 +699,27 @@ BorderAgent::EphemeralKeyManager::EphemeralKeyManager(Instance &aInstance) { } -void BorderAgent::EphemeralKeyManager::SetEnabled(bool aEnabled) +void EphemeralKeyManager::SetEnabled(bool aEnabled) { if (aEnabled) { VerifyOrExit(mState == kStateDisabled); SetState(kStateStopped); - Get().PostServiceTask(); + Get().PostServiceTask(); } else { VerifyOrExit(mState != kStateDisabled); Stop(); SetState(kStateDisabled); - Get().PostServiceTask(); + Get().PostServiceTask(); } exit: return; } -Error BorderAgent::EphemeralKeyManager::Start(const char *aKeyString, uint32_t aTimeout, uint16_t aUdpPort) +Error EphemeralKeyManager::Start(const char *aKeyString, uint32_t aTimeout, uint16_t aUdpPort) { Error error = kErrorNone; uint16_t length; @@ -753,28 +751,28 @@ exit: switch (error) { case kErrorNone: - Get().mCounters.mEpskcActivations++; + Get().mCounters.mEpskcActivations++; #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE Get().RecordEpskcEvent(HistoryTracker::Local::kEpskcActivated); #endif break; case kErrorInvalidState: - Get().mCounters.mEpskcInvalidBaStateErrors++; + Get().mCounters.mEpskcInvalidBaStateErrors++; break; case kErrorInvalidArgs: - Get().mCounters.mEpskcInvalidArgsErrors++; + Get().mCounters.mEpskcInvalidArgsErrors++; break; default: - Get().mCounters.mEpskcStartSecureSessionErrors++; + Get().mCounters.mEpskcStartSecureSessionErrors++; break; } return error; } -void BorderAgent::EphemeralKeyManager::Stop(void) { Stop(kReasonLocalDisconnect); } +void EphemeralKeyManager::Stop(void) { Stop(kReasonLocalDisconnect); } -void BorderAgent::EphemeralKeyManager::Stop(DeactivationReason aReason) +void EphemeralKeyManager::Stop(DeactivationReason aReason) { switch (mState) { @@ -799,7 +797,7 @@ exit: return; } -void BorderAgent::EphemeralKeyManager::UpdateCountersAndRecordEvent(DeactivationReason aReason) +void EphemeralKeyManager::UpdateCountersAndRecordEvent(DeactivationReason aReason) { struct ReasonToCounterEventEntry { @@ -838,7 +836,7 @@ void BorderAgent::EphemeralKeyManager::UpdateCountersAndRecordEvent(Deactivation { if (aReason == entry.mReason) { - (Get().mCounters.*(entry.mCounterPtr))++; + (Get().mCounters.*(entry.mCounterPtr))++; #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE event = static_cast(entry.mEvent); #endif @@ -851,7 +849,7 @@ void BorderAgent::EphemeralKeyManager::UpdateCountersAndRecordEvent(Deactivation #endif } -void BorderAgent::EphemeralKeyManager::SetState(State aState) +void EphemeralKeyManager::SetState(State aState) { #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE bool isServiceRegistered = ShouldRegisterService(); @@ -871,15 +869,14 @@ exit: return; } -SecureSession *BorderAgent::EphemeralKeyManager::HandleAcceptSession(void *aContext, - const Ip6::MessageInfo &aMessageInfo) +SecureSession *EphemeralKeyManager::HandleAcceptSession(void *aContext, const Ip6::MessageInfo &aMessageInfo) { OT_UNUSED_VARIABLE(aMessageInfo); return static_cast(aContext)->HandleAcceptSession(); } -BorderAgent::CoapDtlsSession *BorderAgent::EphemeralKeyManager::HandleAcceptSession(void) +Manager::CoapDtlsSession *EphemeralKeyManager::HandleAcceptSession(void) { CoapDtlsSession *session = nullptr; @@ -894,12 +891,12 @@ exit: return session; } -void BorderAgent::EphemeralKeyManager::HandleRemoveSession(void *aContext, SecureSession &aSession) +void EphemeralKeyManager::HandleRemoveSession(void *aContext, SecureSession &aSession) { static_cast(aContext)->HandleRemoveSession(aSession); } -void BorderAgent::EphemeralKeyManager::HandleRemoveSession(SecureSession &aSession) +void EphemeralKeyManager::HandleRemoveSession(SecureSession &aSession) { CoapDtlsSession &coapSession = static_cast(aSession); @@ -908,16 +905,16 @@ void BorderAgent::EphemeralKeyManager::HandleRemoveSession(SecureSession &aSessi mCoapDtlsSession = nullptr; } -void BorderAgent::EphemeralKeyManager::HandleSessionConnected(void) +void EphemeralKeyManager::HandleSessionConnected(void) { SetState(kStateConnected); - Get().mCounters.mEpskcSecureSessionSuccesses++; + Get().mCounters.mEpskcSecureSessionSuccesses++; #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE Get().RecordEpskcEvent(HistoryTracker::Local::kEpskcConnected); #endif } -void BorderAgent::EphemeralKeyManager::HandleSessionDisconnected(SecureSession::ConnectEvent aEvent) +void EphemeralKeyManager::HandleSessionDisconnected(SecureSession::ConnectEvent aEvent) { DeactivationReason reason = kReasonUnknown; @@ -948,33 +945,29 @@ exit: return; } -void BorderAgent::EphemeralKeyManager::HandleCommissionerPetitionAccepted(void) +void EphemeralKeyManager::HandleCommissionerPetitionAccepted(void) { SetState(kStateAccepted); - Get().mCounters.mEpskcCommissionerPetitions++; + Get().mCounters.mEpskcCommissionerPetitions++; #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE Get().RecordEpskcEvent(HistoryTracker::Local::kEpskcPetitioned); #endif } -void BorderAgent::EphemeralKeyManager::HandleTimer(void) { Stop(kReasonEpskcTimeout); } +void EphemeralKeyManager::HandleTimer(void) { Stop(kReasonEpskcTimeout); } -void BorderAgent::EphemeralKeyManager::HandleTask(void) { mCallback.InvokeIfSet(); } +void EphemeralKeyManager::HandleTask(void) { mCallback.InvokeIfSet(); } -void BorderAgent::EphemeralKeyManager::HandleTransportClosed(void *aContext) +void EphemeralKeyManager::HandleTransportClosed(void *aContext) { reinterpret_cast(aContext)->HandleTransportClosed(); } -void BorderAgent::EphemeralKeyManager::HandleTransportClosed(void) -{ - Stop(kReasonMaxFailedAttempts); - ; -} +void EphemeralKeyManager::HandleTransportClosed(void) { Stop(kReasonMaxFailedAttempts); } #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -bool BorderAgent::EphemeralKeyManager::ShouldRegisterService(void) const +bool EphemeralKeyManager::ShouldRegisterService(void) const { bool shouldRegister = false; @@ -993,14 +986,14 @@ bool BorderAgent::EphemeralKeyManager::ShouldRegisterService(void) const return shouldRegister; } -void BorderAgent::EphemeralKeyManager::RegisterOrUnregisterService(void) +void EphemeralKeyManager::RegisterOrUnregisterService(void) { Dnssd::Service service; VerifyOrExit(Get().IsReady()); service.Clear(); - service.mServiceInstance = Get().GetServiceName(); + service.mServiceInstance = Get().GetServiceName(); service.mServiceType = kServiceType; service.mPort = GetUdpPort(); @@ -1019,7 +1012,7 @@ exit: #endif // OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE -const char *BorderAgent::EphemeralKeyManager::StateToString(State aState) +const char *EphemeralKeyManager::StateToString(State aState) { static const char *const kStateStrings[] = { "Disabled", // (0) kStateDisabled @@ -1044,7 +1037,7 @@ const char *BorderAgent::EphemeralKeyManager::StateToString(State aState) #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) -const char *BorderAgent::EphemeralKeyManager::DeactivationReasonToString(DeactivationReason aReason) +const char *EphemeralKeyManager::DeactivationReasonToString(DeactivationReason aReason) { static const char *const kReasonStrings[] = { "LocalDisconnect", // (0) kReasonLocalDisconnect @@ -1076,9 +1069,9 @@ const char *BorderAgent::EphemeralKeyManager::DeactivationReasonToString(Deactiv #endif // OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE //---------------------------------------------------------------------------------------------------------------------- -// `BorderAgent::CoapDtlsSession +// `Manager::CoapDtlsSession -BorderAgent::CoapDtlsSession::CoapDtlsSession(Instance &aInstance, Dtls::Transport &aDtlsTransport) +Manager::CoapDtlsSession::CoapDtlsSession(Instance &aInstance, Dtls::Transport &aDtlsTransport) : Coap::SecureSession(aInstance, aDtlsTransport) , mIsActiveCommissioner(false) , mTimer(aInstance, HandleTimer, this) @@ -1091,7 +1084,7 @@ BorderAgent::CoapDtlsSession::CoapDtlsSession(Instance &aInstance, Dtls::Transpo SetConnectCallback(&HandleConnected, this); } -void BorderAgent::CoapDtlsSession::Cleanup(void) +void Manager::CoapDtlsSession::Cleanup(void) { while (!mForwardContexts.IsEmpty()) { @@ -1107,17 +1100,17 @@ void BorderAgent::CoapDtlsSession::Cleanup(void) Coap::SecureSession::Cleanup(); } -bool BorderAgent::CoapDtlsSession::HandleResource(CoapBase &aCoapBase, - const char *aUriPath, - Coap::Message &aMessage, - const Ip6::MessageInfo &aMessageInfo) +bool Manager::CoapDtlsSession::HandleResource(CoapBase &aCoapBase, + const char *aUriPath, + Coap::Message &aMessage, + const Ip6::MessageInfo &aMessageInfo) { return static_cast(aCoapBase).HandleResource(aUriPath, aMessage, aMessageInfo); } -bool BorderAgent::CoapDtlsSession::HandleResource(const char *aUriPath, - Coap::Message &aMessage, - const Ip6::MessageInfo &aMessageInfo) +bool Manager::CoapDtlsSession::HandleResource(const char *aUriPath, + Coap::Message &aMessage, + const Ip6::MessageInfo &aMessageInfo) { bool didHandle = true; Uri uri = UriFromPath(aUriPath); @@ -1149,18 +1142,18 @@ bool BorderAgent::CoapDtlsSession::HandleResource(const char *aUriPa return didHandle; } -void BorderAgent::CoapDtlsSession::HandleConnected(ConnectEvent aEvent, void *aContext) +void Manager::CoapDtlsSession::HandleConnected(ConnectEvent aEvent, void *aContext) { static_cast(aContext)->HandleConnected(aEvent); } -void BorderAgent::CoapDtlsSession::HandleConnected(ConnectEvent aEvent) +void Manager::CoapDtlsSession::HandleConnected(ConnectEvent aEvent) { if (aEvent == kConnected) { LogInfo("SecureSession connected"); mTimer.Start(kKeepAliveTimeout); - Get().HandleSessionConnected(*this); + Get().HandleSessionConnected(*this); } else { @@ -1168,12 +1161,12 @@ void BorderAgent::CoapDtlsSession::HandleConnected(ConnectEvent aEvent) IgnoreError(Get().RemoveReceiver(mUdpReceiver)); Get().RemoveUnicastAddress(mCommissionerAloc); - Get().HandleSessionDisconnected(*this, aEvent); + Get().HandleSessionDisconnected(*this, aEvent); } } -void BorderAgent::CoapDtlsSession::HandleTmfCommissionerKeepAlive(Coap::Message &aMessage, - const Ip6::MessageInfo &aMessageInfo) +void Manager::CoapDtlsSession::HandleTmfCommissionerKeepAlive(Coap::Message &aMessage, + const Ip6::MessageInfo &aMessageInfo) { VerifyOrExit(mIsActiveCommissioner); SuccessOrExit(ForwardToLeader(aMessage, aMessageInfo, kUriLeaderKeepAlive)); @@ -1189,9 +1182,9 @@ exit: return; } -Error BorderAgent::CoapDtlsSession::ForwardToLeader(const Coap::Message &aMessage, - const Ip6::MessageInfo &aMessageInfo, - Uri aUri) +Error Manager::CoapDtlsSession::ForwardToLeader(const Coap::Message &aMessage, + const Ip6::MessageInfo &aMessageInfo, + Uri aUri) { Error error = kErrorNone; OwnedPtr forwardContext; @@ -1254,10 +1247,10 @@ exit: return error; } -void BorderAgent::CoapDtlsSession::HandleCoapResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Manager::CoapDtlsSession::HandleCoapResponse(void *aContext, + otMessage *aMessage, + const otMessageInfo *aMessageInfo, + otError aResult) { OT_UNUSED_VARIABLE(aMessageInfo); @@ -1266,9 +1259,9 @@ void BorderAgent::CoapDtlsSession::HandleCoapResponse(void *aCont forwardContext->mSession.HandleCoapResponse(*forwardContext.Get(), AsCoapMessagePtr(aMessage), aResult); } -void BorderAgent::CoapDtlsSession::HandleCoapResponse(const ForwardContext &aForwardContext, - const Coap::Message *aResponse, - Error aResult) +void Manager::CoapDtlsSession::HandleCoapResponse(const ForwardContext &aForwardContext, + const Coap::Message *aResponse, + Error aResult) { Coap::Message *message = nullptr; Error error; @@ -1294,7 +1287,7 @@ void BorderAgent::CoapDtlsSession::HandleCoapResponse(const ForwardContext &aFor Get().AddUnicastAddress(mCommissionerAloc); IgnoreError(Get().AddReceiver(mUdpReceiver)); mIsActiveCommissioner = true; - Get().HandleCommissionerPetitionAccepted(*this); + Get().HandleCommissionerPetitionAccepted(*this); LogInfo("Commissioner accepted - SessionId:%u ALOC:%s", sessionId, mCommissionerAloc.GetAddress().ToString().AsCString()); @@ -1326,14 +1319,14 @@ exit: } } -bool BorderAgent::CoapDtlsSession::HandleUdpReceive(void *aContext, - const otMessage *aMessage, - const otMessageInfo *aMessageInfo) +bool Manager::CoapDtlsSession::HandleUdpReceive(void *aContext, + const otMessage *aMessage, + const otMessageInfo *aMessageInfo) { return static_cast(aContext)->HandleUdpReceive(AsCoreType(aMessage), AsCoreType(aMessageInfo)); } -bool BorderAgent::CoapDtlsSession::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) +bool Manager::CoapDtlsSession::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { Error error = kErrorNone; Coap::Message *message = nullptr; @@ -1376,7 +1369,7 @@ exit: return didHandle; } -Error BorderAgent::CoapDtlsSession::ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage) +Error Manager::CoapDtlsSession::ForwardToCommissioner(Coap::Message &aForwardMessage, const Message &aMessage) { Error error = kErrorNone; OffsetRange offsetRange; @@ -1393,7 +1386,7 @@ exit: return error; } -void BorderAgent::CoapDtlsSession::SendErrorMessage(const ForwardContext &aForwardContext, Error aError) +void Manager::CoapDtlsSession::SendErrorMessage(const ForwardContext &aForwardContext, Error aError) { Error error = kErrorNone; Coap::Message *message = nullptr; @@ -1407,7 +1400,7 @@ exit: LogWarnOnError(error, "send error CoAP message"); } -void BorderAgent::CoapDtlsSession::SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, Error aError) +void Manager::CoapDtlsSession::SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, Error aError) { Error error = kErrorNone; Coap::Message *message = nullptr; @@ -1437,7 +1430,7 @@ exit: LogWarnOnError(error, "send error CoAP message"); } -void BorderAgent::CoapDtlsSession::HandleTmfProxyTx(Coap::Message &aMessage) +void Manager::CoapDtlsSession::HandleTmfProxyTx(Coap::Message &aMessage) { Error error = kErrorNone; Message *message = nullptr; @@ -1470,7 +1463,7 @@ exit: LogWarnOnError(error, "send proxy stream"); } -void BorderAgent::CoapDtlsSession::HandleTmfRelayTx(Coap::Message &aMessage) +void Manager::CoapDtlsSession::HandleTmfRelayTx(Coap::Message &aMessage) { Error error = kErrorNone; uint16_t joinerRouterRloc; @@ -1500,7 +1493,7 @@ exit: LogWarnOnError(error, "send to joiner router request RelayTx (c/tx)"); } -void BorderAgent::CoapDtlsSession::HandleTmfDatasetGet(Coap::Message &aMessage, Uri aUri) +void Manager::CoapDtlsSession::HandleTmfDatasetGet(Coap::Message &aMessage, Uri aUri) { Error error = kErrorNone; Coap::Message *response = nullptr; @@ -1513,7 +1506,7 @@ void BorderAgent::CoapDtlsSession::HandleTmfDatasetGet(Coap::Message &aMessage, { case kUriActiveGet: response = Get().ProcessGetRequest(aMessage, DatasetManager::kIgnoreSecurityPolicyFlags); - Get().mCounters.mMgmtActiveGets++; + Get().mCounters.mMgmtActiveGets++; #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE && OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE if (Get().OwnsSession(*this)) { @@ -1524,7 +1517,7 @@ void BorderAgent::CoapDtlsSession::HandleTmfDatasetGet(Coap::Message &aMessage, case kUriPendingGet: response = Get().ProcessGetRequest(aMessage, DatasetManager::kIgnoreSecurityPolicyFlags); - Get().mCounters.mMgmtPendingGets++; + Get().mCounters.mMgmtPendingGets++; #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE && OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE if (Get().OwnsSession(*this)) { @@ -1552,12 +1545,12 @@ exit: FreeMessageOnError(response, error); } -void BorderAgent::CoapDtlsSession::HandleTimer(Timer &aTimer) +void Manager::CoapDtlsSession::HandleTimer(Timer &aTimer) { static_cast(static_cast(aTimer).GetContext())->HandleTimer(); } -void BorderAgent::CoapDtlsSession::HandleTimer(void) +void Manager::CoapDtlsSession::HandleTimer(void) { if (IsConnected()) { @@ -1567,12 +1560,12 @@ void BorderAgent::CoapDtlsSession::HandleTimer(void) } //---------------------------------------------------------------------------------------------------------------------- -// `BorderAgent::CoapDtlsSession::ForwardContext` +// `Manager::CoapDtlsSession::ForwardContext` -BorderAgent::CoapDtlsSession::ForwardContext::ForwardContext(CoapDtlsSession &aSession, - const Coap::Message &aMessage, - bool aPetition, - bool aSeparate) +Manager::CoapDtlsSession::ForwardContext::ForwardContext(CoapDtlsSession &aSession, + const Coap::Message &aMessage, + bool aPetition, + bool aSeparate) : mSession(aSession) , mMessageId(aMessage.GetMessageId()) , mPetition(aPetition) @@ -1583,7 +1576,7 @@ BorderAgent::CoapDtlsSession::ForwardContext::ForwardContext(CoapDtlsSession memcpy(mToken, aMessage.GetToken(), mTokenLength); } -Error BorderAgent::CoapDtlsSession::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t aCode) const +Error Manager::CoapDtlsSession::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t aCode) const { if ((mType == Coap::kTypeNonConfirmable) || mSeparate) { @@ -1602,6 +1595,7 @@ Error BorderAgent::CoapDtlsSession::ForwardContext::ToHeader(Coap::Message &aMes return aMessage.SetToken(mToken, mTokenLength); } +} // namespace BorderAgent } // namespace MeshCoP } // namespace ot diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index c8bfd8862..dc1b27bb8 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -62,8 +62,8 @@ #include "thread/uri_paths.hpp" namespace ot { - namespace MeshCoP { +namespace BorderAgent { #if !OPENTHREAD_CONFIG_SECURE_TRANSPORT_ENABLE #error "Border Agent feature requires `OPENTHREAD_CONFIG_SECURE_TRANSPORT_ENABLE`" @@ -81,13 +81,35 @@ namespace MeshCoP { #endif -class BorderAgent : public InstanceLocator, private NonCopyable +#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE +class EphemeralKeyManager; +#endif + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE +/** + * Represents a Border Agent Identifier. + */ +struct Id : public otBorderAgentId, public Clearable, public Equatable +{ + static constexpr uint16_t kLength = OT_BORDER_AGENT_ID_LENGTH; ///< The ID length (number of bytes). + + /** + * Generates a random ID. + */ + void GenerateRandom(void) { Random::NonCrypto::Fill(mId); } +}; +#endif + +class Manager : public InstanceLocator, private NonCopyable { #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE friend class ot::BorderRouter::RoutingManager; #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE friend ot::Dnssd; +#endif +#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE + friend class EphemeralKeyManager; #endif friend class ot::Notifier; friend class Tmf::Agent; @@ -131,11 +153,11 @@ public: }; /** - * Initializes the `BorderAgent` object. + * Initializes the `Manager` object. * * @param[in] aInstance A reference to the OpenThread instance. */ - explicit BorderAgent(Instance &aInstance); + explicit Manager(Instance &aInstance); /** * Enables or disables the Border Agent service. @@ -170,19 +192,6 @@ public: bool IsRunning(void) const { return mIsRunning; } #if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE - /** - * Represents a Border Agent Identifier. - */ - struct Id : public otBorderAgentId, public Clearable, public Equatable - { - static constexpr uint16_t kLength = OT_BORDER_AGENT_ID_LENGTH; ///< The ID length (number of bytes). - - /** - * Generates a random ID. - */ - void GenerateRandom(void) { Random::NonCrypto::Fill(mId); } - }; - static_assert(sizeof(Id) == Id::kLength, "sizeof(Id) is not valid"); /** @@ -274,179 +283,6 @@ public: void SetVendorTxtData(const uint8_t *aVendorData, uint16_t aVendorDataLength); #endif -#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - /** - * Manages the ephemeral key use by Border Agent. - */ - class EphemeralKeyManager : public InstanceLocator, private NonCopyable - { - friend class BorderAgent; - - public: - static constexpr uint16_t kMinKeyLength = OT_BORDER_AGENT_MIN_EPHEMERAL_KEY_LENGTH; ///< Min key len. - static constexpr uint16_t kMaxKeyLength = OT_BORDER_AGENT_MAX_EPHEMERAL_KEY_LENGTH; ///< Max key len. - static constexpr uint32_t kDefaultTimeout = OT_BORDER_AGENT_DEFAULT_EPHEMERAL_KEY_TIMEOUT; //< Default timeout. - static constexpr uint32_t kMaxTimeout = OT_BORDER_AGENT_MAX_EPHEMERAL_KEY_TIMEOUT; ///< Max timeout. - - typedef otBorderAgentEphemeralKeyCallback CallbackHandler; ///< Callback function pointer. - - /** - * Represents the state of the `EphemeralKeyManager`. - */ - enum State : uint8_t - { - kStateDisabled = OT_BORDER_AGENT_STATE_DISABLED, ///< Ephemeral key feature is disabled. - kStateStopped = OT_BORDER_AGENT_STATE_STOPPED, ///< Enabled, but the key is not set and started. - kStateStarted = OT_BORDER_AGENT_STATE_STARTED, ///< Key is set and listening to accept connection. - kStateConnected = OT_BORDER_AGENT_STATE_CONNECTED, ///< Session connected, not full commissioner. - kStateAccepted = OT_BORDER_AGENT_STATE_ACCEPTED, ///< Session connected and accepted as full commissioner. - }; - - /** - * Enables/disables Ephemeral Key Manager. - * - * If this method is called to disable, while an an ephemeral key is in use, the ephemeral key use will - * be stopped (as if `Stop()` is called). - * - * @param[in] aEnabled Whether to enable or disable. - */ - void SetEnabled(bool aEnabled); - - /** - * Starts using an ephemeral key for a given timeout duration. - * - * An ephemeral key can only be set when `GetState()` is `kStateStopped`. Otherwise, `kErrorInvalidState` is - * returned. This means that setting the ephemeral key again while a previously set key is still in use will - * fail. Callers can stop the previous key by calling `Stop()` before starting with a new key. - * - * The given @p aKeyString is used directly as the ephemeral PSK (excluding the trailing null `\0` character). - * Its length must be between `kMinKeyLength` and `kMaxKeyLength`, inclusive. - * - * The ephemeral key can be used only once by an external commissioner candidate to establish a secure session. - * After the commissioner candidate disconnects, the use of the ephemeral key is stopped. If the timeout - * expires, the use of the ephemeral key is also stopped, and any established session using the key is - * immediately disconnected. - * - * @param[in] aKeyString The ephemeral key. - * @param[in] aTimeout The timeout duration, in milliseconds, to use the ephemeral key. - * If zero, the default `kDefaultTimeout` value is used. If the timeout value is - * larger than `kMaxTimeout`, the maximum value is used instead. - * @param[in] aUdpPort The UDP port to use with the ephemeral key. If the UDP port is zero, an ephemeral - * port is used. `GetUdpPort()` returns the current UDP port being used. - * - * @retval kErrorNone Successfully started using the ephemeral key. - * @retval kErrorInvalidState A previously set ephemeral key is still in use or feature is disabled. - * @retval kErrorInvalidArgs The given @p aKeyString is not valid. - * @retval kErrorFailed Failed to start (e.g., it could not bind to the given UDP port). - */ - Error Start(const char *aKeyString, uint32_t aTimeout, uint16_t aUdpPort); - - /** - * Stops the ephemeral key use and disconnects any established secure session using it. - * - * If there is no ephemeral key in use, calling this method has no effect. - */ - void Stop(void); - - /** - * Gets the state of ephemeral key use and its session. - * - * @returns The `EmpheralKeyManager` state. - */ - State GetState(void) const { return mState; } - - /** - * Gets the UDP port used by ephemeral key DTLS secure transport. - * - * @returns UDP port number. - */ - uint16_t GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); } - - /** - * Sets the callback. - * - * @param[in] aCallback The callback function pointer. - * @param[in] aContext The context associated and used with callback handler. - */ - void SetCallback(CallbackHandler aCallback, void *aContext) { mCallback.Set(aCallback, aContext); } - - /** - * Converts a given `State` to human-readable string. - * - * @param[in] aState The state to convert. - * - * @returns The string corresponding to @p aState. - */ - static const char *StateToString(State aState); - - private: - static constexpr uint16_t kMaxConnectionAttempts = 10; - - static_assert(kMaxKeyLength <= Dtls::Transport::kPskMaxLength, "Max e-key len is larger than max PSK len"); - - enum DeactivationReason : uint8_t - { - kReasonLocalDisconnect, - kReasonPeerDisconnect, - kReasonSessionError, - kReasonSessionTimeout, - kReasonMaxFailedAttempts, - kReasonEpskcTimeout, - kReasonUnknown, - }; - - explicit EphemeralKeyManager(Instance &aInstance); - - void SetState(State aState); - void Stop(DeactivationReason aReason); - void HandleTimer(void); - void HandleTask(void); - bool OwnsSession(CoapDtlsSession &aSession) const { return mCoapDtlsSession == &aSession; } - void HandleSessionConnected(void); - void HandleSessionDisconnected(SecureSession::ConnectEvent aEvent); - void HandleCommissionerPetitionAccepted(void); - void UpdateCountersAndRecordEvent(DeactivationReason aReason); -#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE - bool ShouldRegisterService(void) const; - void RegisterOrUnregisterService(void); -#endif - - // Session or Transport callbacks - static SecureSession *HandleAcceptSession(void *aContext, const Ip6::MessageInfo &aMessageInfo); - CoapDtlsSession *HandleAcceptSession(void); - static void HandleRemoveSession(void *aContext, SecureSession &aSession); - void HandleRemoveSession(SecureSession &aSession); - static void HandleTransportClosed(void *aContext); - void HandleTransportClosed(void); - -#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) - static const char *DeactivationReasonToString(DeactivationReason aReason); -#endif - -#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE - static const char kServiceType[]; -#endif - - using TimeoutTimer = TimerMilliIn; - using CallbackTask = TaskletIn; - - State mState; - Dtls::Transport mDtlsTransport; - CoapDtlsSession *mCoapDtlsSession; - TimeoutTimer mTimer; - CallbackTask mCallbackTask; - Callback mCallback; - }; - - /** - * Gets the `EphemeralKeyManager` instance. - * - * @returns A reference to the `EphemeralKeyManager`. - */ - EphemeralKeyManager &GetEphemeralKeyManager(void) { return mEphemeralKeyManager; } - -#endif // OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - /** * Gets the set of border agent counters. * @@ -615,7 +451,7 @@ private: void HandleDnssdPlatformStateChange(void) { PostServiceTask(); } #endif - using ServiceTask = TaskletIn; + using ServiceTask = TaskletIn; static const char kTxtDataRecordVersion[]; #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE @@ -632,9 +468,6 @@ private: #endif Callback mServiceChangedCallback; ServiceTask mServiceTask; -#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - EphemeralKeyManager mEphemeralKeyManager; -#endif #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE Dns::Name::LabelBuffer mServiceName; Heap::Data mVendorTxtData; @@ -642,15 +475,190 @@ private: Counters mCounters; }; -DeclareTmfHandler(BorderAgent, kUriRelayRx); +DeclareTmfHandler(Manager, kUriRelayRx); +#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE +/** + * Manages the ephemeral key use by Border Agent. + */ +class EphemeralKeyManager : public InstanceLocator, private NonCopyable +{ + friend class Manager; + +public: + static constexpr uint16_t kMinKeyLength = OT_BORDER_AGENT_MIN_EPHEMERAL_KEY_LENGTH; ///< Min key len. + static constexpr uint16_t kMaxKeyLength = OT_BORDER_AGENT_MAX_EPHEMERAL_KEY_LENGTH; ///< Max key len. + static constexpr uint32_t kDefaultTimeout = OT_BORDER_AGENT_DEFAULT_EPHEMERAL_KEY_TIMEOUT; //< Default timeout. + static constexpr uint32_t kMaxTimeout = OT_BORDER_AGENT_MAX_EPHEMERAL_KEY_TIMEOUT; ///< Max timeout. + + typedef otBorderAgentEphemeralKeyCallback CallbackHandler; ///< Callback function pointer. + + /** + * Represents the state of the `EphemeralKeyManager`. + */ + enum State : uint8_t + { + kStateDisabled = OT_BORDER_AGENT_STATE_DISABLED, ///< Ephemeral key feature is disabled. + kStateStopped = OT_BORDER_AGENT_STATE_STOPPED, ///< Enabled, but the key is not set and started. + kStateStarted = OT_BORDER_AGENT_STATE_STARTED, ///< Key is set and listening to accept connection. + kStateConnected = OT_BORDER_AGENT_STATE_CONNECTED, ///< Session connected, not full commissioner. + kStateAccepted = OT_BORDER_AGENT_STATE_ACCEPTED, ///< Session connected and accepted as full commissioner. + }; + + /** + * Initializes the `EphemeralKeyManager`. + * + * @param[in] aInstance The OpenThread instance. + */ + explicit EphemeralKeyManager(Instance &aInstance); + + /** + * Enables/disables Ephemeral Key Manager. + * + * If this method is called to disable, while an an ephemeral key is in use, the ephemeral key use will + * be stopped (as if `Stop()` is called). + * + * @param[in] aEnabled Whether to enable or disable. + */ + void SetEnabled(bool aEnabled); + + /** + * Starts using an ephemeral key for a given timeout duration. + * + * An ephemeral key can only be set when `GetState()` is `kStateStopped`. Otherwise, `kErrorInvalidState` is + * returned. This means that setting the ephemeral key again while a previously set key is still in use will + * fail. Callers can stop the previous key by calling `Stop()` before starting with a new key. + * + * The given @p aKeyString is used directly as the ephemeral PSK (excluding the trailing null `\0` character). + * Its length must be between `kMinKeyLength` and `kMaxKeyLength`, inclusive. + * + * The ephemeral key can be used only once by an external commissioner candidate to establish a secure session. + * After the commissioner candidate disconnects, the use of the ephemeral key is stopped. If the timeout + * expires, the use of the ephemeral key is also stopped, and any established session using the key is + * immediately disconnected. + * + * @param[in] aKeyString The ephemeral key. + * @param[in] aTimeout The timeout duration, in milliseconds, to use the ephemeral key. + * If zero, the default `kDefaultTimeout` value is used. If the timeout value is + * larger than `kMaxTimeout`, the maximum value is used instead. + * @param[in] aUdpPort The UDP port to use with the ephemeral key. If the UDP port is zero, an ephemeral + * port is used. `GetUdpPort()` returns the current UDP port being used. + * + * @retval kErrorNone Successfully started using the ephemeral key. + * @retval kErrorInvalidState A previously set ephemeral key is still in use or feature is disabled. + * @retval kErrorInvalidArgs The given @p aKeyString is not valid. + * @retval kErrorFailed Failed to start (e.g., it could not bind to the given UDP port). + */ + Error Start(const char *aKeyString, uint32_t aTimeout, uint16_t aUdpPort); + + /** + * Stops the ephemeral key use and disconnects any established secure session using it. + * + * If there is no ephemeral key in use, calling this method has no effect. + */ + void Stop(void); + + /** + * Gets the state of ephemeral key use and its session. + * + * @returns The `EmpheralKeyManager` state. + */ + State GetState(void) const { return mState; } + + /** + * Gets the UDP port used by ephemeral key DTLS secure transport. + * + * @returns UDP port number. + */ + uint16_t GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); } + + /** + * Sets the callback. + * + * @param[in] aCallback The callback function pointer. + * @param[in] aContext The context associated and used with callback handler. + */ + void SetCallback(CallbackHandler aCallback, void *aContext) { mCallback.Set(aCallback, aContext); } + + /** + * Converts a given `State` to human-readable string. + * + * @param[in] aState The state to convert. + * + * @returns The string corresponding to @p aState. + */ + static const char *StateToString(State aState); + +private: + static constexpr uint16_t kMaxConnectionAttempts = 10; + + static_assert(kMaxKeyLength <= Dtls::Transport::kPskMaxLength, "Max e-key len is larger than max PSK len"); + + using CoapDtlsSession = Manager::CoapDtlsSession; + using Counters = Manager::Counters; + + enum DeactivationReason : uint8_t + { + kReasonLocalDisconnect, + kReasonPeerDisconnect, + kReasonSessionError, + kReasonSessionTimeout, + kReasonMaxFailedAttempts, + kReasonEpskcTimeout, + kReasonUnknown, + }; + + void SetState(State aState); + void Stop(DeactivationReason aReason); + void HandleTimer(void); + void HandleTask(void); + bool OwnsSession(CoapDtlsSession &aSession) const { return mCoapDtlsSession == &aSession; } + void HandleSessionConnected(void); + void HandleSessionDisconnected(SecureSession::ConnectEvent aEvent); + void HandleCommissionerPetitionAccepted(void); + void UpdateCountersAndRecordEvent(DeactivationReason aReason); +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + bool ShouldRegisterService(void) const; + void RegisterOrUnregisterService(void); +#endif + + // Session or Transport callbacks + static SecureSession *HandleAcceptSession(void *aContext, const Ip6::MessageInfo &aMessageInfo); + CoapDtlsSession *HandleAcceptSession(void); + static void HandleRemoveSession(void *aContext, SecureSession &aSession); + void HandleRemoveSession(SecureSession &aSession); + static void HandleTransportClosed(void *aContext); + void HandleTransportClosed(void); + +#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) + static const char *DeactivationReasonToString(DeactivationReason aReason); +#endif + +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + static const char kServiceType[]; +#endif + + using TimeoutTimer = TimerMilliIn; + using CallbackTask = TaskletIn; + + State mState; + Dtls::Transport mDtlsTransport; + CoapDtlsSession *mCoapDtlsSession; + TimeoutTimer mTimer; + CallbackTask mCallbackTask; + Callback mCallback; +}; + +#endif // OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE + +} // namespace BorderAgent } // namespace MeshCoP #if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE DefineCoreType(otBorderAgentId, MeshCoP::BorderAgent::Id); #endif -DefineCoreType(otBorderAgentSessionIterator, MeshCoP::BorderAgent::SessionIterator); +DefineCoreType(otBorderAgentSessionIterator, MeshCoP::BorderAgent::Manager::SessionIterator); #if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE DefineMapEnum(otBorderAgentEphemeralKeyState, MeshCoP::BorderAgent::EphemeralKeyManager::State); diff --git a/src/core/meshcop/border_agent_tracker.cpp b/src/core/meshcop/border_agent_tracker.cpp index fe4b30654..81ba3823b 100644 --- a/src/core/meshcop/border_agent_tracker.cpp +++ b/src/core/meshcop/border_agent_tracker.cpp @@ -39,15 +39,16 @@ namespace ot { namespace MeshCoP { +namespace BorderAgent { RegisterLogModule("BaTracker"); //--------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker +// Tracker -const char BorderAgentTracker::kServiceType[] = "_meshcop._udp"; +const char Tracker::kServiceType[] = "_meshcop._udp"; -BorderAgentTracker::BorderAgentTracker(Instance &aInstance) +Tracker::Tracker(Instance &aInstance) : InstanceLocator(aInstance) , mState(kStateStopped) , mUserEnabled(false) @@ -55,7 +56,7 @@ BorderAgentTracker::BorderAgentTracker(Instance &aInstance) { } -void BorderAgentTracker::SetEnabled(bool aEnable, Requester aRequester) +void Tracker::SetEnabled(bool aEnable, Requester aRequester) { switch (aRequester) { @@ -70,9 +71,9 @@ void BorderAgentTracker::SetEnabled(bool aEnable, Requester aRequester) UpdateState(); } -void BorderAgentTracker::HandleDnssdPlatformStateChange(void) { UpdateState(); } +void Tracker::HandleDnssdPlatformStateChange(void) { UpdateState(); } -void BorderAgentTracker::UpdateState(void) +void Tracker::UpdateState(void) { State newState; @@ -110,12 +111,12 @@ exit: return; } -void BorderAgentTracker::HandleBrowseResult(otInstance *aInstance, const otPlatDnssdBrowseResult *aResult) +void Tracker::HandleBrowseResult(otInstance *aInstance, const otPlatDnssdBrowseResult *aResult) { - AsCoreType(aInstance).Get().HandleBrowseResult(*aResult); + AsCoreType(aInstance).Get().HandleBrowseResult(*aResult); } -void BorderAgentTracker::HandleBrowseResult(const Dnssd::BrowseResult &aResult) +void Tracker::HandleBrowseResult(const Dnssd::BrowseResult &aResult) { Error error = kErrorNone; Agent *newAgent; @@ -158,12 +159,12 @@ exit: LogOnError(error, "add new agent", aResult.mServiceInstance); } -void BorderAgentTracker::HandleSrvResult(otInstance *aInstance, const otPlatDnssdSrvResult *aResult) +void Tracker::HandleSrvResult(otInstance *aInstance, const otPlatDnssdSrvResult *aResult) { - AsCoreType(aInstance).Get().HandleSrvResult(*aResult); + AsCoreType(aInstance).Get().HandleSrvResult(*aResult); } -void BorderAgentTracker::HandleSrvResult(const Dnssd::SrvResult &aResult) +void Tracker::HandleSrvResult(const Dnssd::SrvResult &aResult) { Agent *agent; @@ -188,12 +189,12 @@ exit: return; } -void BorderAgentTracker::HandleTxtResult(otInstance *aInstance, const otPlatDnssdTxtResult *aResult) +void Tracker::HandleTxtResult(otInstance *aInstance, const otPlatDnssdTxtResult *aResult) { - AsCoreType(aInstance).Get().HandleTxtResult(*aResult); + AsCoreType(aInstance).Get().HandleTxtResult(*aResult); } -void BorderAgentTracker::HandleTxtResult(const Dnssd::TxtResult &aResult) +void Tracker::HandleTxtResult(const Dnssd::TxtResult &aResult) { Agent *agent; @@ -215,12 +216,12 @@ exit: return; } -void BorderAgentTracker::HandleAddressResult(otInstance *aInstance, const otPlatDnssdAddressResult *aResult) +void Tracker::HandleAddressResult(otInstance *aInstance, const otPlatDnssdAddressResult *aResult) { - AsCoreType(aInstance).Get().HandleAddressResult(*aResult); + AsCoreType(aInstance).Get().HandleAddressResult(*aResult); } -void BorderAgentTracker::HandleAddressResult(const Dnssd::AddressResult &aResult) +void Tracker::HandleAddressResult(const Dnssd::AddressResult &aResult) { Agent *agent; @@ -235,14 +236,14 @@ exit: return; } -bool BorderAgentTracker::NameMatch(const Heap::String &aHeapString, const char *aName) +bool Tracker::NameMatch(const Heap::String &aHeapString, const char *aName) { return !aHeapString.IsNull() && StringMatch(aHeapString.AsCString(), aName, kStringCaseInsensitiveMatch); } #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_WARN) -void BorderAgentTracker::LogOnError(Error aError, const char *aText, const char *aName) +void Tracker::LogOnError(Error aError, const char *aText, const char *aName) { if (aError != kErrorNone) { @@ -252,11 +253,11 @@ void BorderAgentTracker::LogOnError(Error aError, const char *aText, const char #else -void BorderAgentTracker::LogOnError(Error, const char *, const char *) {} +void Tracker::LogOnError(Error, const char *, const char *) {} #endif -const char *BorderAgentTracker::StateToString(State aState) +const char *Tracker::StateToString(State aState) { static const char *const kStateStrings[] = { "Stopped", @@ -276,15 +277,15 @@ const char *BorderAgentTracker::StateToString(State aState) } //--------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::Iterator +// Tracker::Iterator -void BorderAgentTracker::Iterator::Init(Instance &aInstance) +void Tracker::Iterator::Init(Instance &aInstance) { - SetAgentEntry(aInstance.Get().mAgents.GetHead()); + SetAgentEntry(aInstance.Get().mAgents.GetHead()); SetInitUptime(aInstance.Get().GetUptime()); } -Error BorderAgentTracker::Iterator::GetNextAgentInfo(AgentInfo &aInfo) +Error Tracker::Iterator::GetNextAgentInfo(AgentInfo &aInfo) { Error error = kErrorNone; const Agent *agent = GetAgentEntry(); @@ -298,14 +299,14 @@ exit: } //--------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::Host +// Tracker::Host -BorderAgentTracker::Host::Host(Instance &aInstance) +Tracker::Host::Host(Instance &aInstance) : InstanceLocator(aInstance) { } -BorderAgentTracker::Host::~Host(void) +Tracker::Host::~Host(void) { VerifyOrExit(mName != nullptr); Get().StopIp6AddressResolver(AddressResolver(mName.AsCString())); @@ -314,7 +315,7 @@ exit: return; } -Error BorderAgentTracker::Host::SetNameAndStartAddrResolver(const char *aHostName) +Error Tracker::Host::SetNameAndStartAddrResolver(const char *aHostName) { Error error; @@ -326,7 +327,7 @@ exit: return error; } -void BorderAgentTracker::Host::SetAddresses(const Dnssd::AddressResult &aResult) +void Tracker::Host::SetAddresses(const Dnssd::AddressResult &aResult) { Error error = kErrorNone; uint16_t length; @@ -358,9 +359,9 @@ exit: } //--------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::Agent +// Tracker::Agent -BorderAgentTracker::Agent::Agent(Instance &aInstance) +Tracker::Agent::Agent(Instance &aInstance) : InstanceLocator(aInstance) , mNext(nullptr) , mDiscoverUptime(aInstance.Get().GetUptime()) @@ -369,7 +370,7 @@ BorderAgentTracker::Agent::Agent(Instance &aInstance) { } -BorderAgentTracker::Agent::~Agent(void) +Tracker::Agent::~Agent(void) { VerifyOrExit(mServiceName != nullptr); Get().StopSrvResolver(SrvResolver(mServiceName.AsCString())); @@ -379,7 +380,7 @@ exit: return; } -Error BorderAgentTracker::Agent::SetServiceNameAndStartSrvTxtResolvers(const char *aServiceName) +Error Tracker::Agent::SetServiceNameAndStartSrvTxtResolvers(const char *aServiceName) { Error error; @@ -394,7 +395,7 @@ exit: return error; } -void BorderAgentTracker::Agent::SetHost(const char *aHostName) +void Tracker::Agent::SetHost(const char *aHostName) { Agent *matchingHostAgent; @@ -413,7 +414,7 @@ void BorderAgentTracker::Agent::SetHost(const char *aHostName) // `Host` entry. Otherwise, we allocate a new one. Note that // `mHost` is defined as `RetainPtr` which does ref-counting. - matchingHostAgent = Get().mAgents.FindMatching(kMatchHostName, aHostName); + matchingHostAgent = Get().mAgents.FindMatching(kMatchHostName, aHostName); if (matchingHostAgent != nullptr) { @@ -434,7 +435,7 @@ exit: return; } -void BorderAgentTracker::Agent::ClearHost(void) +void Tracker::Agent::ClearHost(void) { VerifyOrExit(mHost != nullptr); @@ -445,7 +446,7 @@ exit: return; } -void BorderAgentTracker::Agent::SetPort(uint16_t aPort) +void Tracker::Agent::SetPort(uint16_t aPort) { VerifyOrExit(mPort != aPort); @@ -456,7 +457,7 @@ exit: return; } -void BorderAgentTracker::Agent::SetTxtData(const uint8_t *aData, uint16_t aDataLength) +void Tracker::Agent::SetTxtData(const uint8_t *aData, uint16_t aDataLength) { Error error = kErrorNone; @@ -469,7 +470,7 @@ exit: LogOnError(error, "set TXT data", mServiceName.AsCString()); } -void BorderAgentTracker::Agent::ClearTxtData(void) +void Tracker::Agent::ClearTxtData(void) { VerifyOrExit(!mTxtData.IsNull()); @@ -480,9 +481,9 @@ exit: return; } -void BorderAgentTracker::Agent::SetUpdateTimeToNow(void) { mLastUpdateUptime = Get().GetUptime(); } +void Tracker::Agent::SetUpdateTimeToNow(void) { mLastUpdateUptime = Get().GetUptime(); } -bool BorderAgentTracker::Agent::Matches(MatchType aType, const char *aName) const +bool Tracker::Agent::Matches(MatchType aType, const char *aName) const { bool matches = false; @@ -502,7 +503,7 @@ exit: return matches; } -void BorderAgentTracker::Agent::CopyInfoTo(AgentInfo &aInfo, uint64_t aUptimeNow) const +void Tracker::Agent::CopyInfoTo(AgentInfo &aInfo, uint64_t aUptimeNow) const { ClearAllBytes(aInfo); @@ -522,47 +523,48 @@ void BorderAgentTracker::Agent::CopyInfoTo(AgentInfo &aInfo, uint64_t aUptimeNow } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::Browser +// Tracker::Browser -BorderAgentTracker::Browser::Browser(void) +Tracker::Browser::Browser(void) { Clear(); mServiceType = kServiceType; - mCallback = BorderAgentTracker::HandleBrowseResult; + mCallback = Tracker::HandleBrowseResult; } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::SrvResolver +// Tracker::SrvResolver -BorderAgentTracker::SrvResolver::SrvResolver(const char *aServiceName) +Tracker::SrvResolver::SrvResolver(const char *aServiceName) { Clear(); mServiceInstance = aServiceName; mServiceType = kServiceType; - mCallback = BorderAgentTracker::HandleSrvResult; + mCallback = Tracker::HandleSrvResult; } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::TxtResolver +// Tracker::TxtResolver -BorderAgentTracker::TxtResolver::TxtResolver(const char *aServiceName) +Tracker::TxtResolver::TxtResolver(const char *aServiceName) { Clear(); mServiceInstance = aServiceName; mServiceType = kServiceType; - mCallback = BorderAgentTracker::HandleTxtResult; + mCallback = Tracker::HandleTxtResult; } //---------------------------------------------------------------------------------------------------------------------- -// BorderAgentTracker::AddressResolver +// Tracker::AddressResolver -BorderAgentTracker::AddressResolver::AddressResolver(const char *aHostName) +Tracker::AddressResolver::AddressResolver(const char *aHostName) { Clear(); mHostName = aHostName; - mCallback = BorderAgentTracker::HandleAddressResult; + mCallback = Tracker::HandleAddressResult; } +} // namespace BorderAgent } // namespace MeshCoP } // namespace ot diff --git a/src/core/meshcop/border_agent_tracker.hpp b/src/core/meshcop/border_agent_tracker.hpp index 087f6e02b..99dbf7412 100644 --- a/src/core/meshcop/border_agent_tracker.hpp +++ b/src/core/meshcop/border_agent_tracker.hpp @@ -57,11 +57,12 @@ namespace ot { namespace MeshCoP { +namespace BorderAgent { /** * Implements the Border Agent Tracker. */ -class BorderAgentTracker : public InstanceLocator +class Tracker : public InstanceLocator { friend class ot::Dnssd; @@ -113,7 +114,7 @@ public: * * @param[in] aInstance The OpenThread instance. */ - explicit BorderAgentTracker(Instance &aInstance); + explicit Tracker(Instance &aInstance); /** * Enables or disables the Border Agent Tracker. @@ -234,9 +235,10 @@ private: OwningList mAgents; }; +} // namespace BorderAgent } // namespace MeshCoP -DefineCoreType(otBorderAgentTrackerIterator, MeshCoP::BorderAgentTracker::Iterator); +DefineCoreType(otBorderAgentTrackerIterator, MeshCoP::BorderAgent::Tracker::Iterator); } // namespace ot diff --git a/src/core/net/dnssd.cpp b/src/core/net/dnssd.cpp index cd698296f..9a808e1a4 100644 --- a/src/core/net/dnssd.cpp +++ b/src/core/net/dnssd.cpp @@ -528,11 +528,11 @@ void Dnssd::HandleStateChange(void) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE - Get().HandleDnssdPlatformStateChange(); + Get().HandleDnssdPlatformStateChange(); #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE - Get().HandleDnssdPlatformStateChange(); + Get().HandleDnssdPlatformStateChange(); #endif #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE && OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE diff --git a/src/core/net/ip6_filter.cpp b/src/core/net/ip6_filter.cpp index b5d9ef903..c4f518b43 100644 --- a/src/core/net/ip6_filter.cpp +++ b/src/core/net/ip6_filter.cpp @@ -76,7 +76,7 @@ Error Filter::Apply(const Message &aMessage) const #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE // Allow native commissioner traffic if (Get().GetSecurityPolicy().mNativeCommissioningEnabled && - dstPort == Get().GetUdpPort()) + dstPort == Get().GetUdpPort()) { ExitNow(error = kErrorNone); } diff --git a/src/core/thread/mle_ftd.cpp b/src/core/thread/mle_ftd.cpp index a393c3a6a..1772f876f 100644 --- a/src/core/thread/mle_ftd.cpp +++ b/src/core/thread/mle_ftd.cpp @@ -2817,8 +2817,8 @@ Error Mle::SendDiscoveryResponse(const Ip6::Address &aDestination, const Discove #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE if (Get().GetSecurityPolicy().mNativeCommissioningEnabled) { - SuccessOrExit( - error = Tlv::Append(*message, Get().GetUdpPort())); + SuccessOrExit(error = Tlv::Append( + *message, Get().GetUdpPort())); discoveryResponseTlv.SetNativeCommissioner(true); } diff --git a/src/core/thread/tmf.cpp b/src/core/thread/tmf.cpp index 9d18cf27d..fdcbbd14d 100644 --- a/src/core/thread/tmf.cpp +++ b/src/core/thread/tmf.cpp @@ -94,7 +94,7 @@ template <> void Agent::HandleTmf(Message &aMessage, const Ip6::Mes Get().HandleTmf(aMessage, aMessageInfo); #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - Get().HandleTmf(aMessage, aMessageInfo); + Get().HandleTmf(aMessage, aMessageInfo); #endif } diff --git a/src/core/utils/history_tracker.hpp b/src/core/utils/history_tracker.hpp index 9489eb9fa..c6f50a696 100644 --- a/src/core/utils/history_tracker.hpp +++ b/src/core/utils/history_tracker.hpp @@ -154,7 +154,7 @@ class Local : public InstanceLocator, private NonCopyable friend class ot::RouterTable; #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE - friend class ot::MeshCoP::BorderAgent; + friend class ot::MeshCoP::BorderAgent::Manager; friend class ot::MeshCoP::BorderAgent::EphemeralKeyManager; #endif #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 08794d04c..2e8dfda7f 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -37,7 +37,7 @@ namespace ot { namespace Nexus { using ActiveDatasetManager = MeshCoP::ActiveDatasetManager; -using BorderAgent = MeshCoP::BorderAgent; +using Manager = MeshCoP::BorderAgent::Manager; using EphemeralKeyManager = MeshCoP::BorderAgent::EphemeralKeyManager; using EpskcEvent = HistoryTracker::EpskcEvent; using Iterator = HistoryTracker::Iterator; @@ -48,16 +48,16 @@ using TxtEntry = Dns::TxtEntry; void TestBorderAgent(void) { - Core nexus; - Node &node0 = nexus.CreateNode(); - Node &node1 = nexus.CreateNode(); - Node &node2 = nexus.CreateNode(); - Node &node3 = nexus.CreateNode(); - Ip6::SockAddr sockAddr; - Pskc pskc; - Coap::Message *message; - BorderAgent::SessionIterator iter; - BorderAgent::SessionInfo sessionInfo; + Core nexus; + Node &node0 = nexus.CreateNode(); + Node &node1 = nexus.CreateNode(); + Node &node2 = nexus.CreateNode(); + Node &node3 = nexus.CreateNode(); + Ip6::SockAddr sockAddr; + Pskc pskc; + Coap::Message *message; + Manager::SessionIterator iter; + Manager::SessionInfo sessionInfo; Log("------------------------------------------------------------------------------------------------------"); Log("TestBorderAgent"); @@ -87,27 +87,27 @@ void TestBorderAgent(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check Border Agent initial state"); - VerifyOrQuit(node0.Get().IsEnabled()); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsEnabled()); + VerifyOrQuit(node0.Get().IsRunning()); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check disabling and re-enabling of Border Agent"); - node0.Get().SetEnabled(false); - VerifyOrQuit(!node0.Get().IsEnabled()); - VerifyOrQuit(!node0.Get().IsRunning()); + node0.Get().SetEnabled(false); + VerifyOrQuit(!node0.Get().IsEnabled()); + VerifyOrQuit(!node0.Get().IsRunning()); - node0.Get().SetEnabled(true); - VerifyOrQuit(node0.Get().IsEnabled()); - VerifyOrQuit(node0.Get().IsRunning()); + node0.Get().SetEnabled(true); + VerifyOrQuit(node0.Get().IsEnabled()); + VerifyOrQuit(node0.Get().IsRunning()); - SuccessOrQuit(node0.Get().AddUnsecurePort(node0.Get().GetUdpPort())); + SuccessOrQuit(node0.Get().AddUnsecurePort(node0.Get().GetUdpPort())); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Establish a DTLS connection to Border Agent"); sockAddr.SetAddress(node0.Get().GetLinkLocalAddress()); - sockAddr.SetPort(node0.Get().GetUdpPort()); + sockAddr.SetPort(node0.Get().GetUdpPort()); node0.Get().GetPskc(pskc); SuccessOrQuit(node1.Get().SetPsk(pskc.m8, Pskc::kSize)); @@ -119,7 +119,7 @@ void TestBorderAgent(void) VerifyOrQuit(node1.Get().IsConnected()); - VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 1); + VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 1); iter.Init(node0.GetInstance()); SuccessOrQuit(iter.GetNextSessionInfo(sessionInfo)); @@ -136,7 +136,7 @@ void TestBorderAgent(void) nexus.AdvanceTime(3 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsRunning()); iter.Init(node0.GetInstance()); VerifyOrQuit(iter.GetNextSessionInfo(sessionInfo) == kErrorNotFound); @@ -151,7 +151,7 @@ void TestBorderAgent(void) VerifyOrQuit(node1.Get().IsConnected()); - VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 2); iter.Init(node0.GetInstance()); SuccessOrQuit(iter.GetNextSessionInfo(sessionInfo)); @@ -170,8 +170,8 @@ void TestBorderAgent(void) nexus.AdvanceTime(1 * Time::kOneSecondInMsec); - VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 2); - VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 1); + VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 1); iter.Init(node0.GetInstance()); SuccessOrQuit(iter.GetNextSessionInfo(sessionInfo)); @@ -209,7 +209,7 @@ void TestBorderAgent(void) nexus.AdvanceTime(5 * Time::kOneSecondInMsec); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsRunning()); VerifyOrQuit(!node1.Get().IsConnected()); iter.Init(node0.GetInstance()); @@ -230,8 +230,8 @@ void TestBorderAgent(void) nexus.AdvanceTime(1 * Time::kOneSecondInMsec); - VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 3); - VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 2); + VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 3); + VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 2); iter.Init(node0.GetInstance()); SuccessOrQuit(iter.GetNextSessionInfo(sessionInfo)); @@ -257,8 +257,8 @@ void TestBorderAgent(void) VerifyOrQuit(node2.Get().IsConnected()); VerifyOrQuit(node3.Get().IsConnected()); - VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 5); - VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 2); + VerifyOrQuit(node0.Get().GetCounters().mPskcSecureSessionSuccesses == 5); + VerifyOrQuit(node0.Get().GetCounters().mPskcCommissionerPetitions == 2); iter.Init(node0.GetInstance()); @@ -289,7 +289,7 @@ void TestBorderAgent(void) nexus.AdvanceTime(3 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsRunning()); VerifyOrQuit(node2.Get().IsConnected()); VerifyOrQuit(node3.Get().IsConnected()); @@ -392,15 +392,15 @@ void TestBorderAgentEphemeralKey(void) static constexpr uint16_t kEphemeralKeySize = sizeof(kEphemeralKey) - 1; static constexpr uint16_t kUdpPort = 49155; - Core nexus; - Node &node0 = nexus.CreateNode(); - Node &node1 = nexus.CreateNode(); - Node &node2 = nexus.CreateNode(); - Ip6::SockAddr sockAddr; - Ip6::SockAddr baSockAddr; - Pskc pskc; - BorderAgent::SessionIterator iter; - BorderAgent::SessionInfo sessionInfo; + Core nexus; + Node &node0 = nexus.CreateNode(); + Node &node1 = nexus.CreateNode(); + Node &node2 = nexus.CreateNode(); + Ip6::SockAddr sockAddr; + Ip6::SockAddr baSockAddr; + Pskc pskc; + Manager::SessionIterator iter; + Manager::SessionInfo sessionInfo; Log("------------------------------------------------------------------------------------------------------"); Log("TestBorderAgentEphemeralKey"); @@ -426,14 +426,14 @@ void TestBorderAgentEphemeralKey(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check Border Agent ephemeral key counter's initial value"); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 0); - VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidBaStateErrors == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 0); + VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidBaStateErrors == 0); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check Border Agent ephemeral key feature enabled"); @@ -443,7 +443,7 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().Start(kEphemeralKey, /* aTimeout */ 0, kUdpPort) == kErrorInvalidState); - VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidBaStateErrors == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidBaStateErrors == 1); node0.Get().SetEnabled(true); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); @@ -463,7 +463,7 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStarted); VerifyOrQuit(node0.Get().GetUdpPort() == kUdpPort); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); SuccessOrQuit(node0.Get().AddUnsecurePort(kUdpPort)); @@ -488,8 +488,8 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node1.Get().IsConnected()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateConnected); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 1); VerifyOrQuit(sEphemeralKeyCallbackCalled); @@ -506,9 +506,9 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); VerifyOrQuit(sEphemeralKeyCallbackCalled); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); nexus.AdvanceTime(10 * Time::kOneSecondInMsec); @@ -528,9 +528,9 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node1.Get().IsConnected()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateConnected); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); Log(" Check the ephemeral key timeout behavior"); @@ -541,10 +541,10 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); VerifyOrQuit(sEphemeralKeyCallbackCalled); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Start using ephemeral key without any candidate connecting, check timeout"); @@ -561,10 +561,10 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); VerifyOrQuit(sEphemeralKeyCallbackCalled); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 3); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 3); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check that ephemeral key use is stopped after max failed connection attempts"); @@ -599,11 +599,11 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); VerifyOrQuit(sEphemeralKeyCallbackCalled); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 4); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 4); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); node1.Get().Close(); @@ -641,18 +641,18 @@ void TestBorderAgentEphemeralKey(void) nexus.AdvanceTime(3 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 5); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 3); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 5); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 3); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 1); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check ephemeral key can be used along with PSKc"); - VerifyOrQuit(node0.Get().IsRunning()); - SuccessOrQuit(node0.Get().AddUnsecurePort(node0.Get().GetUdpPort())); + VerifyOrQuit(node0.Get().IsRunning()); + SuccessOrQuit(node0.Get().AddUnsecurePort(node0.Get().GetUdpPort())); node0.Get().SetEnabled(true); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); @@ -665,7 +665,7 @@ void TestBorderAgentEphemeralKey(void) Log(" Establish a secure session using PSKc (from node2)"); baSockAddr.SetAddress(node0.Get().GetLinkLocalAddress()); - baSockAddr.SetPort(node0.Get().GetUdpPort()); + baSockAddr.SetPort(node0.Get().GetUdpPort()); node0.Get().GetPskc(pskc); SuccessOrQuit(node2.Get().SetPsk(pskc.m8, Pskc::kSize)); @@ -709,12 +709,12 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); VerifyOrQuit(sEphemeralKeyCallbackCalled); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); - VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 4); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); - VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); + VerifyOrQuit(node0.Get().GetCounters().mEpskcSecureSessionSuccesses == 4); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationTimeouts == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationDisconnects == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationMaxAttempts == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcDeactivationClears == 2); Log(" Check the BA session using PSKc is still connected"); @@ -747,13 +747,13 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().Start(kTooShortEphemeralKey, /* aTimeout */ 0, kUdpPort) == kErrorInvalidArgs); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); - VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 1); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); + VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 1); VerifyOrQuit(node0.Get().Start(kTooLongEphemeralKey, /* aTimeout */ 0, kUdpPort) == kErrorInvalidArgs); - VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); - VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 2); + VerifyOrQuit(node0.Get().GetCounters().mEpskcActivations == 6); + VerifyOrQuit(node0.Get().GetCounters().mEpskcInvalidArgsErrors == 2); } EpskcEvent GetNewestEpskcEvent(Node &aNode) @@ -1240,15 +1240,15 @@ void ValidateMeshCoPTxtData(TxtData &aTxtData, Node &aNode) static constexpr uint32_t kThreadRoleLeader = 3 << 9; static constexpr uint32_t kFlagEpskcSupported = 1 << 11; - BorderAgent::Id id; - uint32_t stateBitmap; - uint32_t threadIfStatus; - uint32_t threadRole; + MeshCoP::BorderAgent::Id id; + uint32_t stateBitmap; + uint32_t threadIfStatus; + uint32_t threadRole; aTxtData.ValidateFormat(); aTxtData.LogAllTxtEntries(); - aNode.Get().GetId(id); + aNode.Get().GetId(id); aTxtData.ValidateKey("id", id); aTxtData.ValidateKey("rv", "1"); aTxtData.ValidateKey("tv", kThreadVersionString); @@ -1273,8 +1273,8 @@ void ValidateMeshCoPTxtData(TxtData &aTxtData, Node &aNode) stateBitmap = aTxtData.ReadUint32Key("sb"); - VerifyOrQuit((stateBitmap & kMaskConnectionMode) == aNode.Get().IsRunning() ? kConnectionModePskc - : kConnectionModeDisabled); + VerifyOrQuit((stateBitmap & kMaskConnectionMode) == aNode.Get().IsRunning() ? kConnectionModePskc + : kConnectionModeDisabled); switch (aNode.Get().GetRole()) { case Mle::DeviceRole::kRoleDisabled: @@ -1302,8 +1302,7 @@ void ValidateMeshCoPTxtData(TxtData &aTxtData, Node &aNode) VerifyOrQuit((stateBitmap & kMaskThreadIfStatus) == threadIfStatus); VerifyOrQuit((stateBitmap & kMaskThreadRole) == threadRole); - if (aNode.Get().Get().GetState() != - BorderAgent::EphemeralKeyManager::kStateDisabled) + if (aNode.Get().GetState() != EphemeralKeyManager::kStateDisabled) { VerifyOrQuit(stateBitmap & kFlagEpskcSupported); } @@ -1324,10 +1323,10 @@ void HandleServiceChanged(void *aContext) // Callback used in `TestBorderAgentTx void ReadAndValidateMeshCoPTxtData(Node &aNode) { - BorderAgent::ServiceTxtData serviceTxtData; - TxtData txtData; + Manager::ServiceTxtData serviceTxtData; + TxtData txtData; - SuccessOrQuit(aNode.Get().PrepareServiceTxtData(serviceTxtData)); + SuccessOrQuit(aNode.Get().PrepareServiceTxtData(serviceTxtData)); txtData.Init(serviceTxtData.mData, serviceTxtData.mLength); ValidateMeshCoPTxtData(txtData, aNode); @@ -1335,10 +1334,10 @@ void ReadAndValidateMeshCoPTxtData(Node &aNode) void TestBorderAgentTxtDataCallback(void) { - Core nexus; - Node &node0 = nexus.CreateNode(); - bool callbackInvoked = false; - BorderAgent::Id newId; + Core nexus; + Node &node0 = nexus.CreateNode(); + bool callbackInvoked = false; + MeshCoP::BorderAgent::Id newId; Log("------------------------------------------------------------------------------------------------------"); Log("TestBorderAgentTxtDataCallback"); @@ -1348,15 +1347,15 @@ void TestBorderAgentTxtDataCallback(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Set MeshCoP service change callback. Will get initial values. Log("Set MeshCoP service change callback and check initial values"); - node0.Get().SetServiceChangedCallback(HandleServiceChanged, &callbackInvoked); + node0.Get().SetServiceChangedCallback(HandleServiceChanged, &callbackInvoked); nexus.AdvanceTime(1); // Check the initial TXT entries ReadAndValidateMeshCoPTxtData(node0); // Check the Border Agent state - VerifyOrQuit(!node0.Get().IsRunning()); - VerifyOrQuit(node0.Get().GetUdpPort() == 0); + VerifyOrQuit(!node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().GetUdpPort() == 0); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Join Thread network and check updated values and states. @@ -1368,8 +1367,8 @@ void TestBorderAgentTxtDataCallback(void) VerifyOrQuit(callbackInvoked); ReadAndValidateMeshCoPTxtData(node0); - VerifyOrQuit(node0.Get().IsRunning()); - VerifyOrQuit(node0.Get().GetUdpPort() != 0); + VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().GetUdpPort() != 0); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1378,7 +1377,7 @@ void TestBorderAgentTxtDataCallback(void) newId.GenerateRandom(); callbackInvoked = false; - node0.Get().SetId(newId); + node0.Get().SetId(newId); nexus.AdvanceTime(1); ReadAndValidateMeshCoPTxtData(node0); @@ -1387,7 +1386,7 @@ void TestBorderAgentTxtDataCallback(void) // correctly detected and does not trigger the callback. callbackInvoked = false; - node0.Get().SetId(newId); + node0.Get().SetId(newId); nexus.AdvanceTime(1); VerifyOrQuit(!callbackInvoked); @@ -1527,7 +1526,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Disable Border Agent function on node1 - node1.Get().SetEnabled(false); + node1.Get().SetEnabled(false); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Enable mDNS @@ -1543,7 +1542,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VerifyOrQuit(node0.Get().IsEnabled()); + VerifyOrQuit(node0.Get().IsEnabled()); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Validate the registered mDNS MeshCop service by Border Agent"); @@ -1562,7 +1561,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringMatch(service.mServiceType, "_meshcop._udp")); VerifyOrQuit(StringStartsWith(service.mServiceInstance, kDefaultServiceBaseName)); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mSubTypeLabelsLength == 0); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); @@ -1608,7 +1607,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(sSrvOutcomes.GetLength() == 1); VerifyOrQuit(StringStartsWith(sSrvOutcomes[0].mHostName, "ot")); VerifyOrQuit(sSrvOutcomes[0].mTtl > 0); - VerifyOrQuit(sSrvOutcomes[0].mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(sSrvOutcomes[0].mPort == node0.Get().GetUdpPort()); VerifyOrQuit(sTxtOutcomes.GetLength() == 1); VerifyOrQuit(sTxtOutcomes[0].mTtl > 0); @@ -1658,7 +1657,7 @@ void TestBorderAgentServiceRegistration(void) if (StringMatch(service.mServiceType, "_meshcop._udp")) { - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); ValidateRegisteredServiceData(service, node0); } else if (StringMatch(service.mServiceType, "_meshcop-e._udp")) @@ -1701,7 +1700,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringStartsWith(service.mServiceInstance, kDefaultServiceBaseName)); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); VerifyOrQuit(service.mSubTypeLabelsLength == 0); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED); @@ -1715,7 +1714,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Change the base service name and validate the new service"); - SuccessOrQuit(node0.Get().SetServiceBaseName("OpenThreadAgent")); + SuccessOrQuit(node0.Get().SetServiceBaseName("OpenThreadAgent")); nexus.AdvanceTime(30 * Time::kOneSecondInMsec); @@ -1733,7 +1732,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringStartsWith(service.mServiceInstance, "OpenThreadAgent")); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); VerifyOrQuit(service.mSubTypeLabelsLength == 0); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED); @@ -1768,8 +1767,8 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Disable Border Agent and validate that registered service is removed"); - node0.Get().SetEnabled(false); - VerifyOrQuit(!node0.Get().IsEnabled()); + node0.Get().SetEnabled(false); + VerifyOrQuit(!node0.Get().IsEnabled()); nexus.AdvanceTime(30 * Time::kOneSecondInMsec); @@ -1789,9 +1788,9 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Change the base service name while agent is disabled and validate no service is registered"); - SuccessOrQuit(node0.Get().SetServiceBaseName("NewName")); + SuccessOrQuit(node0.Get().SetServiceBaseName("NewName")); - VerifyOrQuit(!node0.Get().IsEnabled()); + VerifyOrQuit(!node0.Get().IsEnabled()); nexus.AdvanceTime(30 * Time::kOneSecondInMsec); @@ -1804,13 +1803,13 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(sBrowseOutcomes.IsEmpty()); - SuccessOrQuit(node0.Get().SetServiceBaseName("OpenThreadAgent")); + SuccessOrQuit(node0.Get().SetServiceBaseName("OpenThreadAgent")); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Re-enable Border Agent and validate that service is registered again"); - node0.Get().SetEnabled(true); - VerifyOrQuit(node0.Get().IsEnabled()); + node0.Get().SetEnabled(true); + VerifyOrQuit(node0.Get().IsEnabled()); nexus.AdvanceTime(30 * Time::kOneSecondInMsec); @@ -1828,7 +1827,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringStartsWith(service.mServiceInstance, "OpenThreadAgent")); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); VerifyOrQuit(service.mSubTypeLabelsLength == 0); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED); @@ -1849,7 +1848,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Set vendor TXT data and validate that it is included in the registered mDNS service"); - node0.Get().SetVendorTxtData(kVendorTxtData, sizeof(kVendorTxtData)); + node0.Get().SetVendorTxtData(kVendorTxtData, sizeof(kVendorTxtData)); nexus.AdvanceTime(5 * Time::kOneSecondInMsec); iterator = node0.Get().AllocateIterator(); @@ -1866,7 +1865,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringStartsWith(service.mServiceInstance, "OpenThreadAgent")); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); VerifyOrQuit(service.mSubTypeLabelsLength == 0); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED); @@ -1887,7 +1886,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Clear vendor TXT data and validate that the registered mDNS service is updated accordingly"); - node0.Get().SetVendorTxtData(nullptr, 0); + node0.Get().SetVendorTxtData(nullptr, 0); nexus.AdvanceTime(5 * Time::kOneSecondInMsec); iterator = node0.Get().AllocateIterator(); @@ -1904,7 +1903,7 @@ void TestBorderAgentServiceRegistration(void) VerifyOrQuit(StringStartsWith(service.mServiceInstance, "OpenThreadAgent")); VerifyOrQuit(StringStartsWith(service.mHostName, "ot")); VerifyOrQuit(service.mSubTypeLabelsLength == 0); - VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); + VerifyOrQuit(service.mPort == node0.Get().GetUdpPort()); VerifyOrQuit(service.mTtl > 0); VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex); VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED); diff --git a/tests/nexus/test_border_agent_tracker.cpp b/tests/nexus/test_border_agent_tracker.cpp index f22084262..d208d56f9 100644 --- a/tests/nexus/test_border_agent_tracker.cpp +++ b/tests/nexus/test_border_agent_tracker.cpp @@ -40,16 +40,16 @@ void TestBorderAgentTracker(void) { static constexpr uint32_t kInfraIfIndex = 1; - Core nexus; - Node &node0 = nexus.CreateNode(); - Node &node1 = nexus.CreateNode(); - Node &node2 = nexus.CreateNode(); - Node &node3 = nexus.CreateNode(); - MeshCoP::BorderAgentTracker::Iterator iterator; - MeshCoP::BorderAgentTracker::AgentInfo agent; - Dns::Multicast::Core::Service service; - uint16_t count; - bool found; + Core nexus; + Node &node0 = nexus.CreateNode(); + Node &node1 = nexus.CreateNode(); + Node &node2 = nexus.CreateNode(); + Node &node3 = nexus.CreateNode(); + MeshCoP::BorderAgent::Tracker::Iterator iterator; + MeshCoP::BorderAgent::Tracker::AgentInfo agent; + Dns::Multicast::Core::Service service; + uint16_t count; + bool found; Log("------------------------------------------------------------------------------------------------------"); Log("TestBorderAgentTracker"); @@ -75,15 +75,15 @@ void TestBorderAgentTracker(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Check Border Agent Tracker's initial state"); - VerifyOrQuit(!node0.Get().IsRunning()); + VerifyOrQuit(!node0.Get().IsRunning()); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Enable Border Agent Tracker"); - node0.Get().SetEnabled(true, MeshCoP::BorderAgentTracker::kRequesterUser); + node0.Get().SetEnabled(true, MeshCoP::BorderAgent::Tracker::kRequesterUser); nexus.AdvanceTime(10); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsRunning()); nexus.AdvanceTime(5000); @@ -109,7 +109,7 @@ void TestBorderAgentTracker(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Disable BA function on node0, ensure that it is removed from the `BorderAgentTracker` list"); - node0.Get().SetEnabled(false); + node0.Get().SetEnabled(false); nexus.AdvanceTime(5000); iterator.Init(node0.GetInstance()); @@ -131,7 +131,7 @@ void TestBorderAgentTracker(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Re-enable BA function on node0, ensure that it is added again in the `BorderAgentTracker` list"); - node0.Get().SetEnabled(true); + node0.Get().SetEnabled(true); nexus.AdvanceTime(5000); iterator.Init(node0.GetInstance()); @@ -153,10 +153,10 @@ void TestBorderAgentTracker(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Disable Border Agent Tracker"); - node0.Get().SetEnabled(false, MeshCoP::BorderAgentTracker::kRequesterUser); + node0.Get().SetEnabled(false, MeshCoP::BorderAgent::Tracker::kRequesterUser); nexus.AdvanceTime(10); - VerifyOrQuit(!node0.Get().IsRunning()); + VerifyOrQuit(!node0.Get().IsRunning()); iterator.Init(node0.GetInstance()); VerifyOrQuit(iterator.GetNextAgentInfo(agent) == kErrorNotFound); @@ -164,10 +164,10 @@ void TestBorderAgentTracker(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Re-enable BA tracker and ensure all agents are discovered again"); - node0.Get().SetEnabled(true, MeshCoP::BorderAgentTracker::kRequesterUser); + node0.Get().SetEnabled(true, MeshCoP::BorderAgent::Tracker::kRequesterUser); nexus.AdvanceTime(10); - VerifyOrQuit(node0.Get().IsRunning()); + VerifyOrQuit(node0.Get().IsRunning()); nexus.AdvanceTime(5000); diff --git a/tests/unit/test_mdns.cpp b/tests/unit/test_mdns.cpp index 56918dd26..8d63536a0 100644 --- a/tests/unit/test_mdns.cpp +++ b/tests/unit/test_mdns.cpp @@ -1854,7 +1854,7 @@ Core *InitTest(void) // register the `_meshcop._udp` service from // interfering with this test. - sInstance->Get().SetEnabled(false); + sInstance->Get().SetEnabled(false); #endif return &sInstance->Get(); diff --git a/tests/unit/test_srp_adv_proxy.cpp b/tests/unit/test_srp_adv_proxy.cpp index 49d65e507..1794a3923 100644 --- a/tests/unit/test_srp_adv_proxy.cpp +++ b/tests/unit/test_srp_adv_proxy.cpp @@ -547,7 +547,7 @@ void InitTest(void) // Disable the Border Agent to prevent its attempt to // register the `_meshcop._udp` service from // interfering with this test. - sInstance->Get().SetEnabled(false); + sInstance->Get().SetEnabled(false); #endif // Configure the `Dnssd` module to use `otPlatDnssd` APIs.