[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.
This commit is contained in:
Abtin Keshavarzian
2025-10-08 12:47:30 -07:00
committed by GitHub
parent e18a5a9cd7
commit af6279f606
19 changed files with 596 additions and 584 deletions
+11 -11
View File
@@ -44,17 +44,17 @@ using namespace ot;
void otBorderAgentSetEnabled(otInstance *aInstance, bool aEnabled)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetEnabled(aEnabled);
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().SetEnabled(aEnabled);
}
bool otBorderAgentIsEnabled(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().IsEnabled();
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().IsEnabled();
}
bool otBorderAgentIsActive(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().IsRunning();
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().SetServiceBaseName(aBaseName);
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().SetServiceBaseName(aBaseName);
}
void otBorderAgentSetVendorTxtData(otInstance *aInstance, const uint8_t *aVendorData, uint16_t aVendorDataLength)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetVendorTxtData(aVendorData, aVendorDataLength);
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().SetVendorTxtData(aVendorData, aVendorDataLength);
}
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
otError otBorderAgentGetId(otInstance *aInstance, otBorderAgentId *aId)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().GetId(AsCoreType(aId));
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().GetId(AsCoreType(aId));
return kErrorNone;
}
otError otBorderAgentSetId(otInstance *aInstance, const otBorderAgentId *aId)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetId(AsCoreType(aId));
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().SetId(AsCoreType(aId));
return kErrorNone;
}
#endif
uint16_t otBorderAgentGetUdpPort(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().GetUdpPort();
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().GetUdpPort();
}
void otBorderAgentInitSessionIterator(otInstance *aInstance, otBorderAgentSessionIterator *aIterator)
@@ -106,17 +106,17 @@ void otBorderAgentSetMeshCoPServiceChangedCallback(otInstance
otBorderAgentMeshCoPServiceChangedCallback aCallback,
void *aContext)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetServiceChangedCallback(aCallback, aContext);
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().SetServiceChangedCallback(aCallback, aContext);
}
otError otBorderAgentGetMeshCoPServiceTxtData(otInstance *aInstance, otBorderAgentMeshCoPServiceTxtData *aTxtData)
{
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().PrepareServiceTxtData(*aTxtData);
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().PrepareServiceTxtData(*aTxtData);
}
const otBorderAgentCounters *otBorderAgentGetCounters(otInstance *aInstance)
{
return &AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().GetCounters();
return &AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Manager>().GetCounters();
}
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
+3 -3
View File
@@ -39,13 +39,13 @@ using namespace ot;
void otBorderAgentTrackerSetEnabled(otInstance *aInstance, bool aEnable)
{
AsCoreType(aInstance).Get<MeshCoP::BorderAgentTracker>().SetEnabled(aEnable,
MeshCoP::BorderAgentTracker::kRequesterUser);
AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Tracker>().SetEnabled(
aEnable, MeshCoP::BorderAgent::Tracker::kRequesterUser);
}
bool otBorderAgentTrackerIsRunning(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::BorderAgentTracker>().IsRunning();
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent::Tracker>().IsRunning();
}
void otBorderAgentTrackerInitIterator(otInstance *aInstance, otBorderAgentTrackerIterator *aIterator)
+1 -1
View File
@@ -1045,7 +1045,7 @@ void RoutingManager::OmrPrefixManager::SetFavoredPrefix(const OmrPrefix &aOmrPre
if (oldFavoredPrefix != mFavoredPrefix)
{
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Get<MeshCoP::BorderAgent>().HandleFavoredOmrPrefixChanged();
Get<MeshCoP::BorderAgent::Manager>().HandleFavoredOmrPrefixChanged();
#endif
LogInfo("Favored OMR prefix: %s -> %s", FavoredToString(oldFavoredPrefix).AsCString(),
FavoredToString(mFavoredPrefix).AsCString());
+1 -1
View File
@@ -131,7 +131,7 @@ void Notifier::EmitEvents(void)
Get<AnnounceSender>().HandleNotifierEvents(events);
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Get<MeshCoP::BorderAgent>().HandleNotifierEvents(events);
Get<MeshCoP::BorderAgent::Manager>().HandleNotifierEvents(events);
#endif
#if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE)
Get<MlrManager>().HandleNotifierEvents(events);
+4 -1
View File
@@ -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)
+12 -8
View File
@@ -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
+136 -142
View File
@@ -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<Mle::Mle>().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<BorderAgent *>(aContext)->HandleAcceptSession();
return static_cast<Manager *>(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<BorderAgent *>(aContext)->HandleRemoveSession(aSession);
static_cast<Manager *>(aContext)->HandleRemoveSession(aSession);
}
void BorderAgent::HandleRemoveSession(SecureSession &aSession)
void Manager::HandleRemoveSession(SecureSession &aSession)
{
CoapDtlsSession &coapSession = static_cast<CoapDtlsSession &>(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<EphemeralKeyManager>().OwnsSession(aSession))
{
mEphemeralKeyManager.HandleSessionConnected();
Get<EphemeralKeyManager>().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<EphemeralKeyManager>().OwnsSession(aSession))
{
mEphemeralKeyManager.HandleSessionDisconnected(aEvent);
Get<EphemeralKeyManager>().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<EphemeralKeyManager>().OwnsSession(aSession))
{
mEphemeralKeyManager.HandleCommissionerPetitionAccepted();
Get<EphemeralKeyManager>().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<EphemeralKeyManager>().mCoapDtlsSession != nullptr) &&
Get<EphemeralKeyManager>().mCoapDtlsSession->IsActiveCommissioner())
{
commissionerSession = mEphemeralKeyManager.mCoapDtlsSession;
commissionerSession = Get<EphemeralKeyManager>().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<kUriRelayRx>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
template <> void Manager::HandleTmf<kUriRelayRx>(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<Mac::Mac>().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<EphemeralKeyManager>().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<CoapDtlsSession *>(aInstance.Get<BorderAgent>().mDtlsTransport.GetSessions().GetHead()));
SetSession(static_cast<CoapDtlsSession *>(aInstance.Get<Manager>().mDtlsTransport.GetSessions().GetHead()));
SetInitTime(aInstance.Get<Uptime>().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<BorderAgent>().PostServiceTask();
Get<Manager>().PostServiceTask();
}
else
{
VerifyOrExit(mState != kStateDisabled);
Stop();
SetState(kStateDisabled);
Get<BorderAgent>().PostServiceTask();
Get<Manager>().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<BorderAgent>().mCounters.mEpskcActivations++;
Get<Manager>().mCounters.mEpskcActivations++;
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
Get<HistoryTracker::Local>().RecordEpskcEvent(HistoryTracker::Local::kEpskcActivated);
#endif
break;
case kErrorInvalidState:
Get<BorderAgent>().mCounters.mEpskcInvalidBaStateErrors++;
Get<Manager>().mCounters.mEpskcInvalidBaStateErrors++;
break;
case kErrorInvalidArgs:
Get<BorderAgent>().mCounters.mEpskcInvalidArgsErrors++;
Get<Manager>().mCounters.mEpskcInvalidArgsErrors++;
break;
default:
Get<BorderAgent>().mCounters.mEpskcStartSecureSessionErrors++;
Get<Manager>().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<BorderAgent>().mCounters.*(entry.mCounterPtr))++;
(Get<Manager>().mCounters.*(entry.mCounterPtr))++;
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
event = static_cast<HistoryTracker::EpskcEvent>(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<EphemeralKeyManager *>(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<EphemeralKeyManager *>(aContext)->HandleRemoveSession(aSession);
}
void BorderAgent::EphemeralKeyManager::HandleRemoveSession(SecureSession &aSession)
void EphemeralKeyManager::HandleRemoveSession(SecureSession &aSession)
{
CoapDtlsSession &coapSession = static_cast<CoapDtlsSession &>(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<BorderAgent>().mCounters.mEpskcSecureSessionSuccesses++;
Get<Manager>().mCounters.mEpskcSecureSessionSuccesses++;
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
Get<HistoryTracker::Local>().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<BorderAgent>().mCounters.mEpskcCommissionerPetitions++;
Get<Manager>().mCounters.mEpskcCommissionerPetitions++;
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
Get<HistoryTracker::Local>().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<EphemeralKeyManager *>(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<Dnssd>().IsReady());
service.Clear();
service.mServiceInstance = Get<BorderAgent>().GetServiceName();
service.mServiceInstance = Get<Manager>().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<CoapDtlsSession &>(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<CoapDtlsSession *>(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<BorderAgent>().HandleSessionConnected(*this);
Get<Manager>().HandleSessionConnected(*this);
}
else
{
@@ -1168,12 +1161,12 @@ void BorderAgent::CoapDtlsSession::HandleConnected(ConnectEvent aEvent)
IgnoreError(Get<Ip6::Udp>().RemoveReceiver(mUdpReceiver));
Get<ThreadNetif>().RemoveUnicastAddress(mCommissionerAloc);
Get<BorderAgent>().HandleSessionDisconnected(*this, aEvent);
Get<Manager>().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> 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<ThreadNetif>().AddUnicastAddress(mCommissionerAloc);
IgnoreError(Get<Ip6::Udp>().AddReceiver(mUdpReceiver));
mIsActiveCommissioner = true;
Get<BorderAgent>().HandleCommissionerPetitionAccepted(*this);
Get<Manager>().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<CoapDtlsSession *>(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<ActiveDatasetManager>().ProcessGetRequest(aMessage, DatasetManager::kIgnoreSecurityPolicyFlags);
Get<BorderAgent>().mCounters.mMgmtActiveGets++;
Get<Manager>().mCounters.mMgmtActiveGets++;
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE && OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
if (Get<EphemeralKeyManager>().OwnsSession(*this))
{
@@ -1524,7 +1517,7 @@ void BorderAgent::CoapDtlsSession::HandleTmfDatasetGet(Coap::Message &aMessage,
case kUriPendingGet:
response = Get<PendingDatasetManager>().ProcessGetRequest(aMessage, DatasetManager::kIgnoreSecurityPolicyFlags);
Get<BorderAgent>().mCounters.mMgmtPendingGets++;
Get<Manager>().mCounters.mMgmtPendingGets++;
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE && OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
if (Get<EphemeralKeyManager>().OwnsSession(*this))
{
@@ -1552,12 +1545,12 @@ exit:
FreeMessageOnError(response, error);
}
void BorderAgent::CoapDtlsSession::HandleTimer(Timer &aTimer)
void Manager::CoapDtlsSession::HandleTimer(Timer &aTimer)
{
static_cast<CoapDtlsSession *>(static_cast<TimerMilliContext &>(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
+204 -196
View File
@@ -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<Id>, public Equatable<Id>
{
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<Id>, public Equatable<Id>
{
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<EphemeralKeyManager, &EphemeralKeyManager::HandleTimer>;
using CallbackTask = TaskletIn<EphemeralKeyManager, &EphemeralKeyManager::HandleTask>;
State mState;
Dtls::Transport mDtlsTransport;
CoapDtlsSession *mCoapDtlsSession;
TimeoutTimer mTimer;
CallbackTask mCallbackTask;
Callback<CallbackHandler> 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<BorderAgent, &BorderAgent::HandleServiceTask>;
using ServiceTask = TaskletIn<Manager, &Manager::HandleServiceTask>;
static const char kTxtDataRecordVersion[];
#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
@@ -632,9 +468,6 @@ private:
#endif
Callback<ServiceChangedCallback> 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<EphemeralKeyManager, &EphemeralKeyManager::HandleTimer>;
using CallbackTask = TaskletIn<EphemeralKeyManager, &EphemeralKeyManager::HandleTask>;
State mState;
Dtls::Transport mDtlsTransport;
CoapDtlsSession *mCoapDtlsSession;
TimeoutTimer mTimer;
CallbackTask mCallbackTask;
Callback<CallbackHandler> 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);
+58 -56
View File
@@ -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<BorderAgentTracker>().HandleBrowseResult(*aResult);
AsCoreType(aInstance).Get<Tracker>().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<BorderAgentTracker>().HandleSrvResult(*aResult);
AsCoreType(aInstance).Get<Tracker>().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<BorderAgentTracker>().HandleTxtResult(*aResult);
AsCoreType(aInstance).Get<Tracker>().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<BorderAgentTracker>().HandleAddressResult(*aResult);
AsCoreType(aInstance).Get<Tracker>().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<BorderAgentTracker>().mAgents.GetHead());
SetAgentEntry(aInstance.Get<Tracker>().mAgents.GetHead());
SetInitUptime(aInstance.Get<Uptime>().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<Dnssd>().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<Uptime>().GetUptime())
@@ -369,7 +370,7 @@ BorderAgentTracker::Agent::Agent(Instance &aInstance)
{
}
BorderAgentTracker::Agent::~Agent(void)
Tracker::Agent::~Agent(void)
{
VerifyOrExit(mServiceName != nullptr);
Get<Dnssd>().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<BorderAgentTracker>().mAgents.FindMatching(kMatchHostName, aHostName);
matchingHostAgent = Get<Tracker>().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<Uptime>().GetUptime(); }
void Tracker::Agent::SetUpdateTimeToNow(void) { mLastUpdateUptime = Get<Uptime>().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
+5 -3
View File
@@ -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<Agent> mAgents;
};
} // namespace BorderAgent
} // namespace MeshCoP
DefineCoreType(otBorderAgentTrackerIterator, MeshCoP::BorderAgentTracker::Iterator);
DefineCoreType(otBorderAgentTrackerIterator, MeshCoP::BorderAgent::Tracker::Iterator);
} // namespace ot
+2 -2
View File
@@ -528,11 +528,11 @@ void Dnssd::HandleStateChange(void)
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
Get<MeshCoP::BorderAgent>().HandleDnssdPlatformStateChange();
Get<MeshCoP::BorderAgent::Manager>().HandleDnssdPlatformStateChange();
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_TRACKER_ENABLE
Get<MeshCoP::BorderAgentTracker>().HandleDnssdPlatformStateChange();
Get<MeshCoP::BorderAgent::Tracker>().HandleDnssdPlatformStateChange();
#endif
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE && OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE
+1 -1
View File
@@ -76,7 +76,7 @@ Error Filter::Apply(const Message &aMessage) const
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
// Allow native commissioner traffic
if (Get<KeyManager>().GetSecurityPolicy().mNativeCommissioningEnabled &&
dstPort == Get<MeshCoP::BorderAgent>().GetUdpPort())
dstPort == Get<MeshCoP::BorderAgent::Manager>().GetUdpPort())
{
ExitNow(error = kErrorNone);
}
+2 -2
View File
@@ -2817,8 +2817,8 @@ Error Mle::SendDiscoveryResponse(const Ip6::Address &aDestination, const Discove
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
if (Get<KeyManager>().GetSecurityPolicy().mNativeCommissioningEnabled)
{
SuccessOrExit(
error = Tlv::Append<MeshCoP::CommissionerUdpPortTlv>(*message, Get<MeshCoP::BorderAgent>().GetUdpPort()));
SuccessOrExit(error = Tlv::Append<MeshCoP::CommissionerUdpPortTlv>(
*message, Get<MeshCoP::BorderAgent::Manager>().GetUdpPort()));
discoveryResponseTlv.SetNativeCommissioner(true);
}
+1 -1
View File
@@ -94,7 +94,7 @@ template <> void Agent::HandleTmf<kUriRelayRx>(Message &aMessage, const Ip6::Mes
Get<MeshCoP::Commissioner>().HandleTmf<kUriRelayRx>(aMessage, aMessageInfo);
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Get<MeshCoP::BorderAgent>().HandleTmf<kUriRelayRx>(aMessage, aMessageInfo);
Get<MeshCoP::BorderAgent::Manager>().HandleTmf<kUriRelayRx>(aMessage, aMessageInfo);
#endif
}
+1 -1
View File
@@ -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
+133 -134
View File
@@ -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<BorderAgent>().IsEnabled());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().IsEnabled());
VerifyOrQuit(node0.Get<Manager>().IsRunning());
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Check disabling and re-enabling of Border Agent");
node0.Get<BorderAgent>().SetEnabled(false);
VerifyOrQuit(!node0.Get<BorderAgent>().IsEnabled());
VerifyOrQuit(!node0.Get<BorderAgent>().IsRunning());
node0.Get<Manager>().SetEnabled(false);
VerifyOrQuit(!node0.Get<Manager>().IsEnabled());
VerifyOrQuit(!node0.Get<Manager>().IsRunning());
node0.Get<BorderAgent>().SetEnabled(true);
VerifyOrQuit(node0.Get<BorderAgent>().IsEnabled());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
node0.Get<Manager>().SetEnabled(true);
VerifyOrQuit(node0.Get<Manager>().IsEnabled());
VerifyOrQuit(node0.Get<Manager>().IsRunning());
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(node0.Get<BorderAgent>().GetUdpPort()));
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(node0.Get<Manager>().GetUdpPort()));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Establish a DTLS connection to Border Agent");
sockAddr.SetAddress(node0.Get<Mle::Mle>().GetLinkLocalAddress());
sockAddr.SetPort(node0.Get<BorderAgent>().GetUdpPort());
sockAddr.SetPort(node0.Get<Manager>().GetUdpPort());
node0.Get<KeyManager>().GetPskc(pskc);
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
@@ -119,7 +119,7 @@ void TestBorderAgent(void)
VerifyOrQuit(node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcSecureSessionSuccesses == 1);
VerifyOrQuit(node0.Get<Manager>().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<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().IsRunning());
iter.Init(node0.GetInstance());
VerifyOrQuit(iter.GetNextSessionInfo(sessionInfo) == kErrorNotFound);
@@ -151,7 +151,7 @@ void TestBorderAgent(void)
VerifyOrQuit(node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().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<BorderAgent>().GetCounters().mPskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcCommissionerPetitions == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mPskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().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<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().IsRunning());
VerifyOrQuit(!node1.Get<Tmf::SecureAgent>().IsConnected());
iter.Init(node0.GetInstance());
@@ -230,8 +230,8 @@ void TestBorderAgent(void)
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcSecureSessionSuccesses == 3);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcCommissionerPetitions == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mPskcSecureSessionSuccesses == 3);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mPskcCommissionerPetitions == 2);
iter.Init(node0.GetInstance());
SuccessOrQuit(iter.GetNextSessionInfo(sessionInfo));
@@ -257,8 +257,8 @@ void TestBorderAgent(void)
VerifyOrQuit(node2.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node3.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcSecureSessionSuccesses == 5);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mPskcCommissionerPetitions == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mPskcSecureSessionSuccesses == 5);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mPskcCommissionerPetitions == 2);
iter.Init(node0.GetInstance());
@@ -289,7 +289,7 @@ void TestBorderAgent(void)
nexus.AdvanceTime(3 * Time::kOneSecondInMsec);
VerifyOrQuit(!node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().IsRunning());
VerifyOrQuit(node2.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node3.Get<Tmf::SecureAgent>().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<BorderAgent>().GetCounters().mEpskcActivations == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationMaxAttempts == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationClears == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcInvalidArgsErrors == 0);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcInvalidBaStateErrors == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationMaxAttempts == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationClears == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcInvalidArgsErrors == 0);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcInvalidBaStateErrors == 0);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Check Border Agent ephemeral key feature enabled");
@@ -443,7 +443,7 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().Start(kEphemeralKey, /* aTimeout */ 0, kUdpPort) ==
kErrorInvalidState);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcInvalidBaStateErrors == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcInvalidBaStateErrors == 1);
node0.Get<EphemeralKeyManager>().SetEnabled(true);
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
@@ -463,7 +463,7 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStarted);
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetUdpPort() == kUdpPort);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 1);
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(kUdpPort));
@@ -488,8 +488,8 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateConnected);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 1);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
@@ -506,9 +506,9 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
nexus.AdvanceTime(10 * Time::kOneSecondInMsec);
@@ -528,9 +528,9 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateConnected);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
Log(" Check the ephemeral key timeout behavior");
@@ -541,10 +541,10 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Start using ephemeral key without any candidate connecting, check timeout");
@@ -561,10 +561,10 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 3);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 3);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<Manager>().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<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 4);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 4);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
node1.Get<Tmf::SecureAgent>().Close();
@@ -641,18 +641,18 @@ void TestBorderAgentEphemeralKey(void)
nexus.AdvanceTime(3 * Time::kOneSecondInMsec);
VerifyOrQuit(!node1.Get<Tmf::SecureAgent>().IsConnected());
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 5);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 3);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationClears == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 5);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 3);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationClears == 1);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Check ephemeral key can be used along with PSKc");
VerifyOrQuit(node0.Get<BorderAgent>().IsRunning());
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(node0.Get<BorderAgent>().GetUdpPort()));
VerifyOrQuit(node0.Get<Manager>().IsRunning());
SuccessOrQuit(node0.Get<Ip6::Filter>().AddUnsecurePort(node0.Get<Manager>().GetUdpPort()));
node0.Get<EphemeralKeyManager>().SetEnabled(true);
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
@@ -665,7 +665,7 @@ void TestBorderAgentEphemeralKey(void)
Log(" Establish a secure session using PSKc (from node2)");
baSockAddr.SetAddress(node0.Get<Mle::Mle>().GetLinkLocalAddress());
baSockAddr.SetPort(node0.Get<BorderAgent>().GetUdpPort());
baSockAddr.SetPort(node0.Get<Manager>().GetUdpPort());
node0.Get<KeyManager>().GetPskc(pskc);
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
@@ -709,12 +709,12 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStopped);
VerifyOrQuit(sEphemeralKeyCallbackCalled);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcSecureSessionSuccesses == 4);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcDeactivationClears == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcSecureSessionSuccesses == 4);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationTimeouts == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationDisconnects == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationMaxAttempts == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcDeactivationClears == 2);
Log(" Check the BA session using PSKc is still connected");
@@ -747,13 +747,13 @@ void TestBorderAgentEphemeralKey(void)
VerifyOrQuit(node0.Get<EphemeralKeyManager>().Start(kTooShortEphemeralKey, /* aTimeout */ 0, kUdpPort) ==
kErrorInvalidArgs);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcInvalidArgsErrors == 1);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcInvalidArgsErrors == 1);
VerifyOrQuit(node0.Get<EphemeralKeyManager>().Start(kTooLongEphemeralKey, /* aTimeout */ 0, kUdpPort) ==
kErrorInvalidArgs);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<BorderAgent>().GetCounters().mEpskcInvalidArgsErrors == 2);
VerifyOrQuit(node0.Get<Manager>().GetCounters().mEpskcActivations == 6);
VerifyOrQuit(node0.Get<Manager>().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<BorderAgent>().GetId(id);
aNode.Get<Manager>().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<BorderAgent>().IsRunning() ? kConnectionModePskc
: kConnectionModeDisabled);
VerifyOrQuit((stateBitmap & kMaskConnectionMode) == aNode.Get<Manager>().IsRunning() ? kConnectionModePskc
: kConnectionModeDisabled);
switch (aNode.Get<Mle::Mle>().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<BorderAgent>().Get<EphemeralKeyManager>().GetState() !=
BorderAgent::EphemeralKeyManager::kStateDisabled)
if (aNode.Get<EphemeralKeyManager>().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<BorderAgent>().PrepareServiceTxtData(serviceTxtData));
SuccessOrQuit(aNode.Get<Manager>().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<BorderAgent>().SetServiceChangedCallback(HandleServiceChanged, &callbackInvoked);
node0.Get<Manager>().SetServiceChangedCallback(HandleServiceChanged, &callbackInvoked);
nexus.AdvanceTime(1);
// Check the initial TXT entries
ReadAndValidateMeshCoPTxtData(node0);
// Check the Border Agent state
VerifyOrQuit(!node0.Get<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<BorderAgent>().GetUdpPort() == 0);
VerifyOrQuit(!node0.Get<Manager>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().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<BorderAgent>().IsRunning());
VerifyOrQuit(node0.Get<BorderAgent>().GetUdpPort() != 0);
VerifyOrQuit(node0.Get<Manager>().IsRunning());
VerifyOrQuit(node0.Get<Manager>().GetUdpPort() != 0);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -1378,7 +1377,7 @@ void TestBorderAgentTxtDataCallback(void)
newId.GenerateRandom();
callbackInvoked = false;
node0.Get<BorderAgent>().SetId(newId);
node0.Get<Manager>().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<BorderAgent>().SetId(newId);
node0.Get<Manager>().SetId(newId);
nexus.AdvanceTime(1);
VerifyOrQuit(!callbackInvoked);
@@ -1527,7 +1526,7 @@ void TestBorderAgentServiceRegistration(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Disable Border Agent function on node1
node1.Get<MeshCoP::BorderAgent>().SetEnabled(false);
node1.Get<MeshCoP::BorderAgent::Manager>().SetEnabled(false);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Enable mDNS
@@ -1543,7 +1542,7 @@ void TestBorderAgentServiceRegistration(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent>().IsEnabled());
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(sSrvOutcomes[0].mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().SetServiceBaseName("OpenThreadAgent"));
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().SetEnabled(false);
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent>().IsEnabled());
node0.Get<MeshCoP::BorderAgent::Manager>().SetEnabled(false);
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().SetServiceBaseName("NewName"));
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent::Manager>().SetServiceBaseName("NewName"));
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent>().IsEnabled());
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent::Manager>().IsEnabled());
nexus.AdvanceTime(30 * Time::kOneSecondInMsec);
@@ -1804,13 +1803,13 @@ void TestBorderAgentServiceRegistration(void)
VerifyOrQuit(sBrowseOutcomes.IsEmpty());
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent>().SetServiceBaseName("OpenThreadAgent"));
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent::Manager>().SetServiceBaseName("OpenThreadAgent"));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Re-enable Border Agent and validate that service is registered again");
node0.Get<MeshCoP::BorderAgent>().SetEnabled(true);
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent>().IsEnabled());
node0.Get<MeshCoP::BorderAgent::Manager>().SetEnabled(true);
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<BorderAgent>().SetVendorTxtData(kVendorTxtData, sizeof(kVendorTxtData));
node0.Get<Manager>().SetVendorTxtData(kVendorTxtData, sizeof(kVendorTxtData));
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
iterator = node0.Get<Dns::Multicast::Core>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().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<BorderAgent>().SetVendorTxtData(nullptr, 0);
node0.Get<Manager>().SetVendorTxtData(nullptr, 0);
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
iterator = node0.Get<Dns::Multicast::Core>().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<MeshCoP::BorderAgent>().GetUdpPort());
VerifyOrQuit(service.mPort == node0.Get<MeshCoP::BorderAgent::Manager>().GetUdpPort());
VerifyOrQuit(service.mTtl > 0);
VerifyOrQuit(service.mInfraIfIndex == kInfraIfIndex);
VerifyOrQuit(entryState == OT_MDNS_ENTRY_STATE_REGISTERED);
+19 -19
View File
@@ -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<MeshCoP::BorderAgentTracker>().IsRunning());
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent::Tracker>().IsRunning());
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Enable Border Agent Tracker");
node0.Get<MeshCoP::BorderAgentTracker>().SetEnabled(true, MeshCoP::BorderAgentTracker::kRequesterUser);
node0.Get<MeshCoP::BorderAgent::Tracker>().SetEnabled(true, MeshCoP::BorderAgent::Tracker::kRequesterUser);
nexus.AdvanceTime(10);
VerifyOrQuit(node0.Get<MeshCoP::BorderAgentTracker>().IsRunning());
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent::Tracker>().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<MeshCoP::BorderAgent>().SetEnabled(false);
node0.Get<MeshCoP::BorderAgent::Manager>().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<MeshCoP::BorderAgent>().SetEnabled(true);
node0.Get<MeshCoP::BorderAgent::Manager>().SetEnabled(true);
nexus.AdvanceTime(5000);
iterator.Init(node0.GetInstance());
@@ -153,10 +153,10 @@ void TestBorderAgentTracker(void)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Disable Border Agent Tracker");
node0.Get<MeshCoP::BorderAgentTracker>().SetEnabled(false, MeshCoP::BorderAgentTracker::kRequesterUser);
node0.Get<MeshCoP::BorderAgent::Tracker>().SetEnabled(false, MeshCoP::BorderAgent::Tracker::kRequesterUser);
nexus.AdvanceTime(10);
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgentTracker>().IsRunning());
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent::Tracker>().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<MeshCoP::BorderAgentTracker>().SetEnabled(true, MeshCoP::BorderAgentTracker::kRequesterUser);
node0.Get<MeshCoP::BorderAgent::Tracker>().SetEnabled(true, MeshCoP::BorderAgent::Tracker::kRequesterUser);
nexus.AdvanceTime(10);
VerifyOrQuit(node0.Get<MeshCoP::BorderAgentTracker>().IsRunning());
VerifyOrQuit(node0.Get<MeshCoP::BorderAgent::Tracker>().IsRunning());
nexus.AdvanceTime(5000);
+1 -1
View File
@@ -1854,7 +1854,7 @@ Core *InitTest(void)
// register the `_meshcop._udp` service from
// interfering with this test.
sInstance->Get<MeshCoP::BorderAgent>().SetEnabled(false);
sInstance->Get<MeshCoP::BorderAgent::Manager>().SetEnabled(false);
#endif
return &sInstance->Get<Core>();
+1 -1
View File
@@ -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<MeshCoP::BorderAgent>().SetEnabled(false);
sInstance->Get<MeshCoP::BorderAgent::Manager>().SetEnabled(false);
#endif
// Configure the `Dnssd` module to use `otPlatDnssd` APIs.