[meshcop] introduce NetworkIdentity class (#12343)

This commit introduces `NetworkIdentity` class to track the network
identity parameters, specifically Extended PAN ID, Network Name and
Domain Name.

The new class replaces the `ExtendedPanIdManager` and
`NetworkNameManager` which are removed by this commit.

This change simplifies `extended_panid.hpp` and `network_name.hpp`.
They now contain only basic type definitions (`ExtendedPanId` and
`NetworkName`). This allows these headers to be included in other
modules without pulling in unnecessary header dependencies.
This commit is contained in:
Abtin Keshavarzian
2026-01-30 10:55:41 -08:00
committed by GitHub
parent 78cf6967bc
commit 266fa62c91
25 changed files with 329 additions and 260 deletions
+2
View File
@@ -418,6 +418,8 @@ openthread_core_files = [
"meshcop/meshcop_leader.hpp",
"meshcop/meshcop_tlvs.cpp",
"meshcop/meshcop_tlvs.hpp",
"meshcop/network_identity.cpp",
"meshcop/network_identity.hpp",
"meshcop/network_name.cpp",
"meshcop/network_name.hpp",
"meshcop/panid_query_client.cpp",
+1
View File
@@ -178,6 +178,7 @@ set(COMMON_SOURCES
meshcop/meshcop.cpp
meshcop/meshcop_leader.cpp
meshcop/meshcop_tlvs.cpp
meshcop/network_identity.cpp
meshcop/network_name.cpp
meshcop/panid_query_client.cpp
meshcop/secure_transport.cpp
+6 -6
View File
@@ -48,7 +48,7 @@ void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout)
const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance)
{
return &AsCoreType(aInstance).Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId();
return &AsCoreType(aInstance).Get<MeshCoP::NetworkIdentity>().GetExtPanId();
}
otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *aExtendedPanId)
@@ -59,7 +59,7 @@ otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *a
VerifyOrExit(instance.Get<Mle::Mle>().IsDisabled(), error = kErrorInvalidState);
instance.Get<MeshCoP::ExtendedPanIdManager>().SetExtPanId(extPanId);
instance.Get<MeshCoP::NetworkIdentity>().SetExtPanId(extPanId);
instance.Get<MeshCoP::ActiveDatasetManager>().Clear();
instance.Get<MeshCoP::PendingDatasetManager>().Clear();
@@ -197,7 +197,7 @@ exit:
const char *otThreadGetNetworkName(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsCString();
return AsCoreType(aInstance).Get<MeshCoP::NetworkIdentity>().GetNetworkName().GetAsCString();
}
otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
@@ -212,7 +212,7 @@ otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
VerifyOrExit(nullptr != aNetworkName && aNetworkName[0] != kNullChar, error = kErrorInvalidArgs);
#endif
error = AsCoreType(aInstance).Get<MeshCoP::NetworkNameManager>().SetNetworkName(aNetworkName);
error = AsCoreType(aInstance).Get<MeshCoP::NetworkIdentity>().SetNetworkName(aNetworkName);
AsCoreType(aInstance).Get<MeshCoP::ActiveDatasetManager>().Clear();
AsCoreType(aInstance).Get<MeshCoP::PendingDatasetManager>().Clear();
@@ -223,7 +223,7 @@ exit:
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
const char *otThreadGetDomainName(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<MeshCoP::NetworkNameManager>().GetDomainName().GetAsCString();
return AsCoreType(aInstance).Get<MeshCoP::NetworkIdentity>().GetDomainName().GetAsCString();
}
otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName)
@@ -232,7 +232,7 @@ otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName)
VerifyOrExit(AsCoreType(aInstance).Get<Mle::Mle>().IsDisabled(), error = kErrorInvalidState);
error = AsCoreType(aInstance).Get<MeshCoP::NetworkNameManager>().SetDomainName(aDomainName);
error = AsCoreType(aInstance).Get<MeshCoP::NetworkIdentity>().SetDomainName(aDomainName);
exit:
return error;
+1 -1
View File
@@ -646,7 +646,7 @@ Error Manager::SendBackboneAnswer(const Ip6::Address &aDstAddr,
SuccessOrExit(error = Tlv::Append<ThreadLastTransactionTimeTlv>(*message, aTimeSinceLastTransaction));
SuccessOrExit(error = Tlv::Append<ThreadNetworkNameTlv>(
*message, Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsCString()));
*message, Get<MeshCoP::NetworkIdentity>().GetNetworkName().GetAsCString()));
if (aSrcRloc16 != Mle::kInvalidRloc16)
{
+1 -1
View File
@@ -1190,7 +1190,7 @@ void RoutingManager::OnLinkPrefixManager::Init(void)
void RoutingManager::OnLinkPrefixManager::GenerateLocalPrefix(void)
{
const MeshCoP::ExtendedPanId &extPanId = Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId();
const MeshCoP::ExtendedPanId &extPanId = Get<MeshCoP::NetworkIdentity>().GetExtPanId();
OldPrefix *entry;
Ip6::Prefix oldLocalPrefix = mLocalPrefix;
+1 -2
View File
@@ -142,8 +142,7 @@ Instance::Instance(void)
#endif
, mActiveDataset(*this)
, mPendingDataset(*this)
, mExtendedPanIdManager(*this)
, mNetworkNameManager(*this)
, mNetworkIdentity(*this)
, mIp6Filter(*this)
, mKeyManager(*this)
, mLowpan(*this)
+4 -8
View File
@@ -95,11 +95,10 @@
#include "meshcop/commissioner.hpp"
#include "meshcop/dataset_manager.hpp"
#include "meshcop/dataset_updater.hpp"
#include "meshcop/extended_panid.hpp"
#include "meshcop/joiner.hpp"
#include "meshcop/joiner_router.hpp"
#include "meshcop/meshcop_leader.hpp"
#include "meshcop/network_name.hpp"
#include "meshcop/network_identity.hpp"
#include "net/dhcp6_client.hpp"
#include "net/dhcp6_server.hpp"
#include "net/dhcp6_types.hpp"
@@ -559,8 +558,7 @@ private:
MeshCoP::ActiveDatasetManager mActiveDataset;
MeshCoP::PendingDatasetManager mPendingDataset;
MeshCoP::ExtendedPanIdManager mExtendedPanIdManager;
MeshCoP::NetworkNameManager mNetworkNameManager;
MeshCoP::NetworkIdentity mNetworkIdentity;
Ip6::Filter mIp6Filter;
KeyManager mKeyManager;
Lowpan::Lowpan mLowpan;
@@ -935,14 +933,12 @@ template <> inline Tmf::Agent &Instance::Get(void) { return mTmfAgent; }
template <> inline Tmf::SecureAgent &Instance::Get(void) { return mTmfSecureAgent; }
#endif
template <> inline MeshCoP::ExtendedPanIdManager &Instance::Get(void) { return mExtendedPanIdManager; }
template <> inline MeshCoP::NetworkNameManager &Instance::Get(void) { return mNetworkNameManager; }
template <> inline MeshCoP::ActiveDatasetManager &Instance::Get(void) { return mActiveDataset; }
template <> inline MeshCoP::PendingDatasetManager &Instance::Get(void) { return mPendingDataset; }
template <> inline MeshCoP::NetworkIdentity &Instance::Get(void) { return mNetworkIdentity; }
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
template <> inline TimeSync &Instance::Get(void) { return mTimeSync; }
#endif
+2 -2
View File
@@ -823,8 +823,8 @@ TxFrame *Mac::PrepareBeacon(void)
beaconPayload->ClearJoiningPermitted();
}
beaconPayload->SetNetworkName(Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsData());
beaconPayload->SetExtendedPanId(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
beaconPayload->SetNetworkName(Get<MeshCoP::NetworkIdentity>().GetNetworkName().GetAsData());
beaconPayload->SetExtendedPanId(Get<MeshCoP::NetworkIdentity>().GetExtPanId());
beaconLength += sizeof(*beaconPayload);
+2 -2
View File
@@ -130,8 +130,8 @@ Error TxtData::Prepare(uint8_t *aBuffer, uint16_t aBufferSize, uint16_t &aLength
SuccessOrExit(error = encoder.AppendBigEndianUintEntry(Key::kBbrPort, BackboneRouter::kBackboneUdpPort));
}
SuccessOrExit(error = encoder.AppendNameEntry(Key::kDomainName,
Get<MeshCoP::NetworkNameManager>().GetDomainName().GetAsData()));
SuccessOrExit(
error = encoder.AppendNameEntry(Key::kDomainName, Get<MeshCoP::NetworkIdentity>().GetDomainName().GetAsData()));
#endif
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
+1 -1
View File
@@ -74,7 +74,7 @@ Error Dataset::Info::GenerateRandom(Instance &aInstance)
SuccessOrExit(error = AsCoreType(&mExtendedPanId).GenerateRandom());
SuccessOrExit(error = AsCoreType(&mMeshLocalPrefix).GenerateRandomUla());
nameWriter.Append("%s-%04x", NetworkName::kNetworkNameInit, mPanId);
nameWriter.Append("%s-%04x", NetworkIdentity::kDefaultNetworkName, mPanId);
mComponents.mIsActiveTimestampPresent = true;
mComponents.mIsNetworkKeyPresent = true;
+2 -2
View File
@@ -211,11 +211,11 @@ Error DatasetManager::ApplyConfiguration(const Dataset &aDataset) const
break;
case Tlv::kExtendedPanId:
Get<ExtendedPanIdManager>().SetExtPanId(cur->ReadValueAs<ExtendedPanIdTlv>());
Get<NetworkIdentity>().SetExtPanId(cur->ReadValueAs<ExtendedPanIdTlv>());
break;
case Tlv::kNetworkName:
IgnoreError(Get<NetworkNameManager>().SetNetworkName(As<NetworkNameTlv>(cur)->GetNetworkName()));
IgnoreError(Get<NetworkIdentity>().SetNetworkName(As<NetworkNameTlv>(cur)->GetNetworkName()));
break;
case Tlv::kNetworkKey:
+2 -2
View File
@@ -297,7 +297,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
if (!dataset.Contains<ExtendedPanIdTlv>())
{
IgnoreError(dataset.Write<ExtendedPanIdTlv>(Get<ExtendedPanIdManager>().GetExtPanId()));
IgnoreError(dataset.Write<ExtendedPanIdTlv>(Get<NetworkIdentity>().GetExtPanId()));
}
if (!dataset.Contains<MeshLocalPrefixTlv>())
@@ -315,7 +315,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
if (!dataset.Contains<NetworkNameTlv>())
{
NameData nameData = Get<NetworkNameManager>().GetNetworkName().GetAsData();
NameData nameData = Get<NetworkIdentity>().GetNetworkName().GetAsData();
IgnoreError(dataset.WriteTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength()));
}
+1 -17
View File
@@ -33,15 +33,11 @@
#include "extended_panid.hpp"
#include "instance/instance.hpp"
#include "common/random.hpp"
namespace ot {
namespace MeshCoP {
const otExtendedPanId ExtendedPanIdManager::sExtendedPanidInit = {
{0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0xca, 0xfe},
};
ExtendedPanId::InfoString ExtendedPanId::ToString(void) const
{
InfoString string;
@@ -53,17 +49,5 @@ ExtendedPanId::InfoString ExtendedPanId::ToString(void) const
Error ExtendedPanId::GenerateRandom(void) { return Random::Crypto::Fill(*this); }
ExtendedPanIdManager::ExtendedPanIdManager(Instance &aInstance)
: InstanceLocator(aInstance)
{
mExtendedPanId.Clear();
SetExtPanId(AsCoreType(&sExtendedPanidInit));
}
void ExtendedPanIdManager::SetExtPanId(const ExtendedPanId &aExtendedPanId)
{
IgnoreError(Get<Notifier>().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged));
}
} // namespace MeshCoP
} // namespace ot
+1 -33
View File
@@ -28,7 +28,7 @@
/**
* @file
* This file includes definitions for managing the Extended PAN ID.
* This file includes definitions for Extended PAN ID.
*/
#ifndef OT_CORE_MESHCOP_EXTENDED_PANID_HPP_
@@ -41,8 +41,6 @@
#include "common/as_core_type.hpp"
#include "common/clearable.hpp"
#include "common/equatable.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/string.hpp"
namespace ot {
@@ -79,36 +77,6 @@ public:
} OT_TOOL_PACKED_END;
class ExtendedPanIdManager : public InstanceLocator, private NonCopyable
{
public:
/**
* Constructor.
*
* @param[in] aInstance A reference to the OpenThread instance.
*/
explicit ExtendedPanIdManager(Instance &aInstance);
/**
* Returns the Extended PAN Identifier.
*
* @returns The Extended PAN Identifier.
*/
const ExtendedPanId &GetExtPanId(void) const { return mExtendedPanId; }
/**
* Sets the Extended PAN Identifier.
*
* @param[in] aExtendedPanId The Extended PAN Identifier.
*/
void SetExtPanId(const ExtendedPanId &aExtendedPanId);
private:
static const otExtendedPanId sExtendedPanidInit;
ExtendedPanId mExtendedPanId;
};
} // namespace MeshCoP
DefineCoreType(otExtendedPanId, MeshCoP::ExtendedPanId);
+118
View File
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2022, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements Network Identity tracker.
*/
#include "network_identity.hpp"
#include "instance/instance.hpp"
namespace ot {
namespace MeshCoP {
const otExtendedPanId NetworkIdentity::sExtendedPanidInit = {
{0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0xca, 0xfe},
};
const char NetworkIdentity::kDefaultNetworkName[] = "OpenThread";
const char NetworkIdentity::kDefaultDomainName[] = "DefaultDomain"; // Section 5.22 Thread spec, MUST NOT change.
NetworkIdentity::NetworkIdentity(Instance &aInstance)
: InstanceLocator(aInstance)
{
mExtendedPanId.Clear();
SetExtPanId(AsCoreType(&sExtendedPanidInit));
IgnoreError(SetNetworkName(kDefaultNetworkName));
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
IgnoreError(SetDomainName(kDefaultDomainName));
#endif
}
void NetworkIdentity::SetExtPanId(const ExtendedPanId &aExtendedPanId)
{
IgnoreError(Get<Notifier>().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged));
}
Error NetworkIdentity::SetNetworkName(const char *aNameString)
{
return SignalNetworkNameChange(mNetworkName.Set(aNameString));
}
Error NetworkIdentity::SetNetworkName(const NameData &aNameData)
{
return SignalNetworkNameChange(mNetworkName.Set(aNameData));
}
Error NetworkIdentity::SignalNetworkNameChange(Error aError)
{
switch (aError)
{
case kErrorNone:
Get<Notifier>().Signal(kEventThreadNetworkNameChanged);
break;
case kErrorAlready:
Get<Notifier>().SignalIfFirst(kEventThreadNetworkNameChanged);
aError = kErrorNone;
break;
default:
break;
}
return aError;
}
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
Error NetworkIdentity::SetDomainName(const char *aNameString)
{
Error error = mDomainName.Set(aNameString);
return (error == kErrorAlready) ? kErrorNone : error;
}
Error NetworkIdentity::SetDomainName(const NameData &aNameData)
{
Error error = mDomainName.Set(aNameData);
return (error == kErrorAlready) ? kErrorNone : error;
}
bool NetworkIdentity::IsDefaultDomainNameSet(void) const
{
return StringMatch(mDomainName.GetAsCString(), kDefaultDomainName);
}
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
} // namespace MeshCoP
} // namespace ot
+156
View File
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2026, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for Network Identity tracker.
*/
#ifndef OT_CORE_MESHCOP_NETWORK_IDENTITY_HPP_
#define OT_CORE_MESHCOP_NETWORK_IDENTITY_HPP_
#include "openthread-core-config.h"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "meshcop/extended_panid.hpp"
#include "meshcop/network_name.hpp"
namespace ot {
namespace MeshCoP {
/**
* Tracks the Network Identify related parameters such as Extended PAN ID and Network Name.
*/
class NetworkIdentity : public InstanceLocator, private NonCopyable
{
public:
static const char kDefaultNetworkName[]; ///< Default Network Name ("OpenThread")
static const char kDefaultDomainName[]; ///< Default Domain Name ("DefaultDomain")
/**
* Initializes the `NetworkIdentity`.
*
* @param[in] aInstance The OpenThread instance.
*/
explicit NetworkIdentity(Instance &aInstance);
/**
* Returns the Extended PAN Identifier.
*
* @returns The Extended PAN Identifier.
*/
const ExtendedPanId &GetExtPanId(void) const { return mExtendedPanId; }
/**
* Sets the Extended PAN Identifier.
*
* @param[in] aExtendedPanId The Extended PAN Identifier.
*/
void SetExtPanId(const ExtendedPanId &aExtendedPanId);
/**
* Returns the Network Name.
*
* @returns The Network Name.
*/
const NetworkName &GetNetworkName(void) const { return mNetworkName; }
/**
* Sets the Network Name.
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval kErrorNone Successfully set the Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetNetworkName(const char *aNameString);
/**
* Sets the Network Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval kErrorNone Successfully set the Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetNetworkName(const NameData &aNameData);
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
/**
* Returns the Thread Domain Name.
*
* @returns The Thread Domain Name.
*/
const DomainName &GetDomainName(void) const { return mDomainName; }
/**
* Sets the Thread Domain Name.
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetDomainName(const char *aNameString);
/**
* Sets the Thread Domain Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetDomainName(const NameData &aNameData);
/**
* Checks whether the Thread Domain Name is currently set to the default name.
*
* @returns true if Thread Domain Name equals "DefaultDomain", false otherwise.
*/
bool IsDefaultDomainNameSet(void) const;
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
private:
static const otExtendedPanId sExtendedPanidInit;
Error SignalNetworkNameChange(Error aError);
ExtendedPanId mExtendedPanId;
NetworkName mNetworkName;
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
DomainName mDomainName;
#endif
};
} // namespace MeshCoP
} // namespace ot
#endif // OT_CORE_MESHCOP_NETWORK_IDENTITY_HPP_
-63
View File
@@ -33,8 +33,6 @@
#include "network_name.hpp"
#include "instance/instance.hpp"
namespace ot {
namespace MeshCoP {
@@ -103,66 +101,5 @@ exit:
bool NetworkName::operator==(const NetworkName &aOther) const { return GetAsData() == aOther.GetAsData(); }
NetworkNameManager::NetworkNameManager(Instance &aInstance)
: InstanceLocator(aInstance)
{
IgnoreError(SetNetworkName(NetworkName::kNetworkNameInit));
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
IgnoreError(SetDomainName(NetworkName::kDomainNameInit));
#endif
}
Error NetworkNameManager::SetNetworkName(const char *aNameString)
{
return SignalNetworkNameChange(mNetworkName.Set(aNameString));
}
Error NetworkNameManager::SetNetworkName(const NameData &aNameData)
{
return SignalNetworkNameChange(mNetworkName.Set(aNameData));
}
Error NetworkNameManager::SignalNetworkNameChange(Error aError)
{
switch (aError)
{
case kErrorNone:
Get<Notifier>().Signal(kEventThreadNetworkNameChanged);
break;
case kErrorAlready:
Get<Notifier>().SignalIfFirst(kEventThreadNetworkNameChanged);
aError = kErrorNone;
break;
default:
break;
}
return aError;
}
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
Error NetworkNameManager::SetDomainName(const char *aNameString)
{
Error error = mDomainName.Set(aNameString);
return (error == kErrorAlready) ? kErrorNone : error;
}
Error NetworkNameManager::SetDomainName(const NameData &aNameData)
{
Error error = mDomainName.Set(aNameData);
return (error == kErrorAlready) ? kErrorNone : error;
}
bool NetworkNameManager::IsDefaultDomainNameSet(void) const
{
return StringMatch(mDomainName.GetAsCString(), NetworkName::kDomainNameInit);
}
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
} // namespace MeshCoP
} // namespace ot
-91
View File
@@ -41,7 +41,6 @@
#include "common/as_core_type.hpp"
#include "common/data.hpp"
#include "common/equatable.hpp"
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/string.hpp"
@@ -100,9 +99,6 @@ public:
class NetworkName : public otNetworkName, public Unequatable<NetworkName>
{
public:
static constexpr const char *kNetworkNameInit = "OpenThread";
static constexpr const char *kDomainNameInit = "DefaultDomain"; // Section 5.22 Thread spec, MUST NOT change.
/**
* This constant specified the maximum number of chars in Network Name (excludes null char).
*/
@@ -170,93 +166,6 @@ public:
typedef NetworkName DomainName;
#endif
/**
* Manages the Network Name value.
*/
class NetworkNameManager : public InstanceLocator, private NonCopyable
{
public:
/**
* Constructor.
*
* @param[in] aInstance A reference to the OpenThread instance.
*/
explicit NetworkNameManager(Instance &aInstance);
/**
* Returns the Network Name.
*
* @returns The Network Name.
*/
const NetworkName &GetNetworkName(void) const { return mNetworkName; }
/**
* Sets the Network Name.
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval kErrorNone Successfully set the Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetNetworkName(const char *aNameString);
/**
* Sets the Network Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval kErrorNone Successfully set the Network Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetNetworkName(const NameData &aNameData);
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
/**
* Returns the Thread Domain Name.
*
* @returns The Thread Domain Name.
*/
const DomainName &GetDomainName(void) const { return mDomainName; }
/**
* Sets the Thread Domain Name.
*
* @param[in] aNameString A pointer to a string character array. Must be null terminated.
*
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetDomainName(const char *aNameString);
/**
* Sets the Thread Domain Name.
*
* @param[in] aNameData A name data (pointer to char buffer and length).
*
* @retval kErrorNone Successfully set the Thread Domain Name.
* @retval kErrorInvalidArgs Given name is too long.
*/
Error SetDomainName(const NameData &aNameData);
/**
* Checks whether the Thread Domain Name is currently set to the default name.
*
* @returns true if Thread Domain Name equals "DefaultDomain", false otherwise.
*/
bool IsDefaultDomainNameSet(void) const;
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
private:
Error SignalNetworkNameChange(Error aError);
NetworkName mNetworkName;
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
DomainName mDomainName;
#endif
};
} // namespace MeshCoP
DefineCoreType(otNetworkName, MeshCoP::NetworkName);
+4 -4
View File
@@ -286,9 +286,9 @@ uint8_t TcatAgent::CheckAuthorizationRequirements(CommandClassFlags aFlagsRequir
if (mCommissionerHasDomainName)
{
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_4)
if (Get<MeshCoP::NetworkNameManager>().GetDomainName() == mCommissionerDomainName)
if (Get<MeshCoP::NetworkIdentity>().GetDomainName() == mCommissionerDomainName)
#else
if (StringMatch(mCommissionerDomainName.GetAsCString(), NetworkName::kDomainNameInit))
if (StringMatch(mCommissionerDomainName.GetAsCString(), NetworkIdentity::kDefaultDomainName))
#endif
{
res |= flag;
@@ -759,7 +759,7 @@ exit:
Error TcatAgent::HandleGetNetworkName(Message &aOutgoingMessage, bool &aResponse)
{
Error error = kErrorNone;
MeshCoP::NameData nameData = Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsData();
MeshCoP::NameData nameData = Get<MeshCoP::NetworkIdentity>().GetNetworkName().GetAsData();
VerifyOrExit(Get<ActiveDatasetManager>().IsCommissioned(), error = kErrorNotFound);
#if !OPENTHREAD_CONFIG_ALLOW_EMPTY_NETWORK_NAME
@@ -812,7 +812,7 @@ Error TcatAgent::HandleGetExtPanId(Message &aOutgoingMessage, bool &aResponse)
VerifyOrExit(Get<ActiveDatasetManager>().IsCommissioned(), error = kErrorNotFound);
SuccessOrExit(error = Tlv::AppendTlv(aOutgoingMessage, kTlvResponseWithPayload,
&Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId(), sizeof(ExtendedPanId)));
&Get<MeshCoP::NetworkIdentity>().GetExtPanId(), sizeof(ExtendedPanId)));
aResponse = true;
exit:
+1 -1
View File
@@ -137,7 +137,7 @@ Error Interface::Send(Packet &aPacket, bool aIsDiscovery)
continue;
}
if (!aIsDiscovery && (peer.GetExtPanId() != Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()))
if (!aIsDiscovery && (peer.GetExtPanId() != Get<MeshCoP::NetworkIdentity>().GetExtPanId()))
{
continue;
}
+1 -1
View File
@@ -396,7 +396,7 @@ Error PeerTable::EvictPeer(void)
Error error = kErrorNotFound;
OwnedPtr<Peer> peerToEvict;
peerToEvict = RemoveMatching(Peer::OtherExtPanIdMatcher(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
peerToEvict = RemoveMatching(Peer::OtherExtPanIdMatcher(Get<MeshCoP::NetworkIdentity>().GetExtPanId()));
if (peerToEvict == nullptr)
{
+2 -2
View File
@@ -283,7 +283,7 @@ void PeerDiscoverer::RegisterService(uint16_t aPort, const TxtData &aTxtData)
LogInfo("Registering service %s.%s", service.mServiceInstance, kTrelServiceType);
LogInfo(" port:%u, ext-addr:%s, ext-panid:%s", aPort, Get<Mac::Mac>().GetExtAddress().ToString().AsCString(),
Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId().ToString().AsCString());
Get<MeshCoP::NetworkIdentity>().GetExtPanId().ToString().AsCString());
Get<Dnssd>().RegisterService(service, /* aRequestId */ 0, HandleRegisterDone);
}
@@ -800,7 +800,7 @@ void PeerDiscoverer::TxtDataEncoder::Encode(void)
Dns::TxtDataEncoder encoder(mBuffer, sizeof(mBuffer));
SuccessOrAssert(encoder.AppendEntry(kExtAddressKey, Get<Mac::Mac>().GetExtAddress()));
SuccessOrAssert(encoder.AppendEntry(kExtPanIdKey, Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
SuccessOrAssert(encoder.AppendEntry(kExtPanIdKey, Get<MeshCoP::NetworkIdentity>().GetExtPanId()));
mData = mBuffer;
mLength = encoder.GetLength();
+6 -6
View File
@@ -2738,7 +2738,7 @@ void Mle::HandleDiscoveryRequest(RxInfo &aRxInfo)
case MeshCoP::Tlv::kExtendedPanId:
SuccessOrExit(error = tlvInfo.Read<MeshCoP::ExtendedPanIdTlv>(aRxInfo.mMessage, extPanId));
VerifyOrExit(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId() != extPanId, error = kErrorDrop);
VerifyOrExit(Get<MeshCoP::NetworkIdentity>().GetExtPanId() != extPanId, error = kErrorDrop);
break;
@@ -2825,11 +2825,11 @@ Error Mle::SendDiscoveryResponse(const Ip6::Address &aDestination, const Discove
SuccessOrExit(error = Tlv::Append<MeshCoP::DiscoveryResponseTlv>(*message, discoveryResponseTlvValue));
SuccessOrExit(
error = Tlv::Append<MeshCoP::ExtendedPanIdTlv>(*message, Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
SuccessOrExit(error =
Tlv::Append<MeshCoP::ExtendedPanIdTlv>(*message, Get<MeshCoP::NetworkIdentity>().GetExtPanId()));
SuccessOrExit(error = Tlv::Append<MeshCoP::NetworkNameTlv>(
*message, Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsCString()));
*message, Get<MeshCoP::NetworkIdentity>().GetNetworkName().GetAsCString()));
SuccessOrExit(error = message->AppendSteeringDataTlv());
@@ -2837,10 +2837,10 @@ Error Mle::SendDiscoveryResponse(const Ip6::Address &aDestination, const Discove
error = Tlv::Append<MeshCoP::JoinerUdpPortTlv>(*message, Get<MeshCoP::JoinerRouter>().GetJoinerUdpPort()));
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_4)
if (!Get<MeshCoP::NetworkNameManager>().IsDefaultDomainNameSet())
if (!Get<MeshCoP::NetworkIdentity>().IsDefaultDomainNameSet())
{
SuccessOrExit(error = Tlv::Append<MeshCoP::ThreadDomainNameTlv>(
*message, Get<MeshCoP::NetworkNameManager>().GetDomainName().GetAsCString()));
*message, Get<MeshCoP::NetworkIdentity>().GetDomainName().GetAsCString()));
}
#endif
+3 -4
View File
@@ -42,9 +42,8 @@ using BaTxtData = MeshCoP::BorderAgent::TxtData;
using EphemeralKeyManager = MeshCoP::BorderAgent::EphemeralKeyManager;
using EpskcEvent = HistoryTracker::EpskcEvent;
using Iterator = HistoryTracker::Iterator;
using ExtendedPanIdManager = MeshCoP::ExtendedPanIdManager;
using NetworkIdentity = MeshCoP::NetworkIdentity;
using NameData = MeshCoP::NameData;
using NetworkNameManager = MeshCoP::NetworkNameManager;
using TxtEntry = Dns::TxtEntry;
void TestBorderAgent(void)
@@ -1342,8 +1341,8 @@ void ValidateMeshCoPTxtData(TxtData &aTxtData, Node &aNode)
if (aNode.Get<MeshCoP::ActiveDatasetManager>().IsComplete())
{
const char *networkName = aNode.Get<NetworkNameManager>().GetNetworkName().GetAsCString();
const MeshCoP::ExtendedPanId &extPanId = aNode.Get<ExtendedPanIdManager>().GetExtPanId();
const char *networkName = aNode.Get<NetworkIdentity>().GetNetworkName().GetAsCString();
const MeshCoP::ExtendedPanId &extPanId = aNode.Get<NetworkIdentity>().GetExtPanId();
aTxtData.ValidateKey("nn", networkName);
VerifyOrQuit(info.mHasNetworkName);
+11 -11
View File
@@ -125,7 +125,7 @@ void TestTrelBasic(void)
bool found = false;
VerifyOrQuit(peer.GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
VerifyOrQuit(peer.GetExtPanId() == node.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer.GetExtPanId() == node.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
for (Node &otherNode : nexus.GetNodes())
{
@@ -283,7 +283,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer->GetServiceName(), node2.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -301,7 +301,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer->GetServiceName(), node1.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -328,7 +328,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdRemoved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer->GetServiceName(), node2.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -353,7 +353,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer->GetServiceName(), node2.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -371,7 +371,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node1.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer->GetServiceName(), node1.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -405,7 +405,7 @@ void TestTrelDelayedMdnsStartAndPeerRemovalDelay(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == ot::Trel::Peer::kDnssdRemoved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetSockAddr().GetAddress() == node2.mMdns.mIfAddresses[0]);
@@ -496,7 +496,7 @@ void TestServiceNameConflict(void)
{
if (peer.GetDnssdState() == ot::Trel::Peer::kDnssdResolved)
{
VerifyOrQuit(peer.GetExtPanId() == node1.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer.GetExtPanId() == node1.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer.GetExtAddress() == node1.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer.GetServiceName() != nullptr);
VerifyOrQuit(StringMatch(peer.GetServiceName(), node1.Get<ot::Trel::PeerDiscoverer>().GetServiceName()));
@@ -542,7 +542,7 @@ void TestHostAddressChange(void)
Log("Manually register a TREL service on `node2` with proper TXT data");
SuccessOrQuit(encoder.AppendEntry("xa", node2.Get<Mac::Mac>().GetExtAddress()));
SuccessOrQuit(encoder.AppendEntry("xp", node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
SuccessOrQuit(encoder.AppendEntry("xp", node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId()));
ClearAllBytes(service);
service.mServiceType = "_trel._udp";
@@ -570,7 +570,7 @@ void TestHostAddressChange(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);
@@ -611,7 +611,7 @@ void TestHostAddressChange(void)
VerifyOrQuit(peer != nullptr);
VerifyOrQuit(peer->GetDnssdState() == kDnssdResolved);
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
VerifyOrQuit(peer->GetExtPanId() == node2.Get<MeshCoP::NetworkIdentity>().GetExtPanId());
VerifyOrQuit(peer->GetExtAddress() == node2.Get<Mac::Mac>().GetExtAddress());
VerifyOrQuit(peer->GetServiceName() != nullptr);