diff --git a/Android.mk b/Android.mk index b144b5402..d32e86b5f 100644 --- a/Android.mk +++ b/Android.mk @@ -280,6 +280,7 @@ LOCAL_SRC_FILES := \ src/core/meshcop/dataset_updater.cpp \ src/core/meshcop/dtls.cpp \ src/core/meshcop/energy_scan_client.cpp \ + src/core/meshcop/extended_panid.cpp \ src/core/meshcop/joiner.cpp \ src/core/meshcop/joiner_router.cpp \ src/core/meshcop/meshcop.cpp \ diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index e5527a627..66075c74b 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -509,6 +509,8 @@ openthread_core_files = [ "meshcop/dtls.hpp", "meshcop/energy_scan_client.cpp", "meshcop/energy_scan_client.hpp", + "meshcop/extended_panid.cpp", + "meshcop/extended_panid.hpp", "meshcop/joiner.cpp", "meshcop/joiner.hpp", "meshcop/joiner_router.cpp", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d1b1d71ae..5d2251148 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -146,6 +146,7 @@ set(COMMON_SOURCES meshcop/dataset_updater.cpp meshcop/dtls.cpp meshcop/energy_scan_client.cpp + meshcop/extended_panid.cpp meshcop/joiner.cpp meshcop/joiner_router.cpp meshcop/meshcop.cpp diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2d1e77618..cfeeae7ca 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -236,6 +236,7 @@ SOURCES_COMMON = \ meshcop/dataset_updater.cpp \ meshcop/dtls.cpp \ meshcop/energy_scan_client.cpp \ + meshcop/extended_panid.cpp \ meshcop/joiner.cpp \ meshcop/joiner_router.cpp \ meshcop/meshcop.cpp \ @@ -536,6 +537,7 @@ HEADERS_COMMON = \ meshcop/dataset_updater.hpp \ meshcop/dtls.hpp \ meshcop/energy_scan_client.hpp \ + meshcop/extended_panid.hpp \ meshcop/joiner.hpp \ meshcop/joiner_router.hpp \ meshcop/meshcop.hpp \ diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 8ec7a6bf7..cd440dc87 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -55,19 +55,19 @@ void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout) const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetExtendedPanId(); + return &AsCoreType(aInstance).Get().GetExtPanId(); } otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *aExtendedPanId) { - Error error = kErrorNone; - Instance & instance = AsCoreType(aInstance); - const Mac::ExtendedPanId &extPanId = AsCoreType(aExtendedPanId); - Mle::MeshLocalPrefix prefix; + Error error = kErrorNone; + Instance & instance = AsCoreType(aInstance); + const MeshCoP::ExtendedPanId &extPanId = AsCoreType(aExtendedPanId); + Mle::MeshLocalPrefix prefix; VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); - instance.Get().SetExtendedPanId(extPanId); + instance.Get().SetExtPanId(extPanId); prefix.SetFromExtendedPanId(extPanId); instance.Get().SetMeshLocalPrefix(prefix); diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index d49b6c063..f71230d0a 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -71,6 +71,7 @@ #include "crypto/mbedtls.hpp" #include "meshcop/border_agent.hpp" #include "meshcop/dataset_updater.hpp" +#include "meshcop/extended_panid.hpp" #include "net/ip6.hpp" #include "thread/announce_sender.hpp" #include "thread/link_metrics.hpp" @@ -701,6 +702,11 @@ template <> inline Coap::CoapSecure &Instance::Get(void) } #endif +template <> inline MeshCoP::ExtendedPanIdManager &Instance::Get(void) +{ + return mThreadNetif.mExtendedPanIdManager; +} + template <> inline MeshCoP::ActiveDataset &Instance::Get(void) { return mThreadNetif.mActiveDataset; diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index b3edb5a40..054a50a31 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -63,10 +63,6 @@ const otExtAddress Mac::sMode2ExtAddress = { {0x35, 0x06, 0xfe, 0xb8, 0x23, 0xd4, 0x87, 0x12}, }; -const otExtendedPanId Mac::sExtendedPanidInit = { - {0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0xca, 0xfe}, -}; - const char Mac::sNetworkNameInit[] = "OpenThread"; #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) @@ -123,13 +119,11 @@ Mac::Mac(Instance &aInstance) mCcaSuccessRateTracker.Clear(); ResetCounters(); - mExtendedPanId.Clear(); SetEnabled(true); mLinks.Enable(); Get().UpdateKeyMaterial(); - SetExtendedPanId(AsCoreType(&sExtendedPanidInit)); IgnoreError(SetNetworkName(sNetworkNameInit)); #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) IgnoreError(SetDomainName(sDomainNameInit)); @@ -501,11 +495,6 @@ exit: return; } -void Mac::SetExtendedPanId(const ExtendedPanId &aExtendedPanId) -{ - IgnoreError(Get().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged)); -} - void Mac::RequestDirectFrameTransmission(void) { VerifyOrExit(IsEnabled()); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 34cc36e54..6a5ed7fd4 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -401,22 +401,6 @@ public: */ void SetPanId(PanId aPanId); - /** - * This method returns the IEEE 802.15.4 Extended PAN Identifier. - * - * @returns The IEEE 802.15.4 Extended PAN Identifier. - * - */ - const ExtendedPanId &GetExtendedPanId(void) const { return mExtendedPanId; } - - /** - * This method sets the IEEE 802.15.4 Extended PAN Identifier. - * - * @param[in] aExtendedPanId The IEEE 802.15.4 Extended PAN Identifier. - * - */ - void SetExtendedPanId(const ExtendedPanId &aExtendedPanId); - /** * This method returns the maximum number of frame retries during direct transmission. * @@ -870,10 +854,9 @@ private: #endif static const char *OperationToString(Operation aOperation); - static const otExtAddress sMode2ExtAddress; - static const otExtendedPanId sExtendedPanidInit; - static const char sNetworkNameInit[]; - static const char sDomainNameInit[]; + static const otExtAddress sMode2ExtAddress; + static const char sNetworkNameInit[]; + static const char sDomainNameInit[]; bool mEnabled : 1; bool mShouldTxPollBeforeData : 1; @@ -885,17 +868,16 @@ private: bool mShouldDelaySleep : 1; bool mDelayingSleep : 1; #endif - Operation mOperation; - uint16_t mPendingOperations; - uint8_t mBeaconSequence; - uint8_t mDataSequence; - uint8_t mBroadcastTransmitCount; - PanId mPanId; - uint8_t mPanChannel; - uint8_t mRadioChannel; - ChannelMask mSupportedChannelMask; - ExtendedPanId mExtendedPanId; - NetworkName mNetworkName; + Operation mOperation; + uint16_t mPendingOperations; + uint8_t mBeaconSequence; + uint8_t mDataSequence; + uint8_t mBroadcastTransmitCount; + PanId mPanId; + uint8_t mPanChannel; + uint8_t mRadioChannel; + ChannelMask mSupportedChannelMask; + NetworkName mNetworkName; #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) DomainName mDomainName; #endif diff --git a/src/core/mac/mac_types.cpp b/src/core/mac/mac_types.cpp index af1a68099..a0d484781 100644 --- a/src/core/mac/mac_types.cpp +++ b/src/core/mac/mac_types.cpp @@ -28,7 +28,7 @@ /** * @file - * This file implements MAC types such as Address, Extended PAN Identifier, Network Name, etc. + * This file implements MAC types. */ #include "mac_types.hpp" @@ -110,15 +110,6 @@ Address::InfoString Address::ToString(void) const return string; } -ExtendedPanId::InfoString ExtendedPanId::ToString(void) const -{ - InfoString string; - - string.AppendHexBytes(m8, sizeof(ExtendedPanId)); - - return string; -} - uint8_t NameData::CopyTo(char *aBuffer, uint8_t aMaxSize) const { MutableData destData; diff --git a/src/core/mac/mac_types.hpp b/src/core/mac/mac_types.hpp index 6e8ba3792..3456521d8 100644 --- a/src/core/mac/mac_types.hpp +++ b/src/core/mac/mac_types.hpp @@ -28,7 +28,7 @@ /** * @file - * This file includes definitions for MAC types such as Address, Extended PAN Identifier, Network Name, etc. + * This file includes definitions for MAC types. */ #ifndef MAC_TYPES_HPP_ @@ -552,32 +552,6 @@ private: void SetKey(const Key &aKey) { mKeyMaterial.mKey = aKey; } }; -/** - * This structure represents an IEEE 802.15.4 Extended PAN Identifier. - * - */ -OT_TOOL_PACKED_BEGIN -class ExtendedPanId : public otExtendedPanId, public Equatable, public Clearable -{ -public: - static constexpr uint16_t kInfoStringSize = 17; ///< Max chars for the info string (`ToString()`). - - /** - * This type defines the fixed-length `String` object returned from `ToString()`. - * - */ - typedef String InfoString; - - /** - * This method converts an address to a string. - * - * @returns An `InfoString` containing the string representation of the Extended PAN Identifier. - * - */ - InfoString ToString(void) const; - -} OT_TOOL_PACKED_END; - /** * This class represents a name string as data (pointer to a char buffer along with a length). * @@ -1024,7 +998,6 @@ private: DefineCoreType(otExtAddress, Mac::ExtAddress); DefineCoreType(otMacKey, Mac::Key); -DefineCoreType(otExtendedPanId, Mac::ExtendedPanId); DefineCoreType(otNetworkName, Mac::NetworkName); } // namespace ot diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index b6496f2ff..4280d65d6 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -555,7 +555,7 @@ Error Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsNetworkKeyUpdate break; case Tlv::kExtendedPanId: - mac.SetExtendedPanId(As(cur)->GetExtendedPanId()); + aInstance.Get().SetExtPanId(As(cur)->GetExtendedPanId()); break; case Tlv::kNetworkName: diff --git a/src/core/meshcop/dataset.hpp b/src/core/meshcop/dataset.hpp index 353f1af15..c40aac559 100644 --- a/src/core/meshcop/dataset.hpp +++ b/src/core/meshcop/dataset.hpp @@ -339,7 +339,7 @@ public: * @returns The Extended PAN ID in the Dataset. * */ - const Mac::ExtendedPanId &GetExtendedPanId(void) const { return AsCoreType(&mExtendedPanId); } + const MeshCoP::ExtendedPanId &GetExtendedPanId(void) const { return AsCoreType(&mExtendedPanId); } /** * This method sets the Extended PAN ID in the Dataset. @@ -347,7 +347,7 @@ public: * @param[in] aExtendedPanId An Extended PAN ID. * */ - void SetExtendedPanId(const Mac::ExtendedPanId &aExtendedPanId) + void SetExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId) { mExtendedPanId = aExtendedPanId; mComponents.mIsExtendedPanIdPresent = true; diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 2e5b58ce4..59d2b96e8 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -334,7 +334,7 @@ Error ActiveDataset::GenerateLocal(void) if (dataset.GetTlv() == nullptr) { - IgnoreError(dataset.SetTlv(Tlv::kExtendedPanId, Get().GetExtendedPanId())); + IgnoreError(dataset.SetTlv(Tlv::kExtendedPanId, Get().GetExtPanId())); } if (dataset.GetTlv() == nullptr) diff --git a/src/core/meshcop/extended_panid.cpp b/src/core/meshcop/extended_panid.cpp new file mode 100644 index 000000000..b90301aa7 --- /dev/null +++ b/src/core/meshcop/extended_panid.cpp @@ -0,0 +1,69 @@ +/* + * 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 Extended PAN ID management. + * + */ + +#include "extended_panid.hpp" + +#include "common/locator_getters.hpp" +#include "common/notifier.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; + + string.AppendHexBytes(m8, sizeof(ExtendedPanId)); + + return string; +} + +ExtendedPanIdManager::ExtendedPanIdManager(Instance &aInstance) + : InstanceLocator(aInstance) +{ + mExtendedPanId.Clear(); + SetExtPanId(AsCoreType(&sExtendedPanidInit)); +} + +void ExtendedPanIdManager::SetExtPanId(const ExtendedPanId &aExtendedPanId) +{ + IgnoreError(Get().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged)); +} + +} // namespace MeshCoP +} // namespace ot diff --git a/src/core/meshcop/extended_panid.hpp b/src/core/meshcop/extended_panid.hpp new file mode 100644 index 000000000..9bf5cf91a --- /dev/null +++ b/src/core/meshcop/extended_panid.hpp @@ -0,0 +1,117 @@ +/* + * 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 includes definitions for managing the Extended PAN ID. + * + */ + +#ifndef MESHCOP_EXTENDED_PANID_HPP_ +#define MESHCOP_EXTENDED_PANID_HPP_ + +#include "openthread-core-config.h" + +#include + +#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 { +namespace MeshCoP { + +/** + * This class represents an Extended PAN Identifier. + * + */ +OT_TOOL_PACKED_BEGIN +class ExtendedPanId : public otExtendedPanId, public Equatable, public Clearable +{ +public: + static constexpr uint16_t kInfoStringSize = 17; ///< Max chars for the info string (`ToString()`). + + /** + * This type defines the fixed-length `String` object returned from `ToString()`. + * + */ + typedef String InfoString; + + /** + * This method converts an address to a string. + * + * @returns An `InfoString` containing the string representation of the Extended PAN Identifier. + * + */ + InfoString ToString(void) const; + +} 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); + + /** + * This method returns the Extended PAN Identifier. + * + * @returns The Extended PAN Identifier. + * + */ + const ExtendedPanId &GetExtPanId(void) const { return mExtendedPanId; } + + /** + * This method 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); + +} // namespace ot + +#endif // MESHCOP_EXTENDED_PANID_HPP_ diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index a298b7e42..d817b1da5 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -325,7 +325,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) Get().GetNetworkKey(networkKey); SuccessOrExit(error = Tlv::Append(*message, networkKey)); SuccessOrExit(error = Tlv::Append(*message, Get().GetMeshLocalPrefix())); - SuccessOrExit(error = Tlv::Append(*message, Get().GetExtendedPanId())); + SuccessOrExit(error = Tlv::Append(*message, Get().GetExtPanId())); networkName.Init(); networkName.SetNetworkName(Get().GetNetworkName().GetAsData()); diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index 36bd685fc..3aecc085c 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -316,10 +316,10 @@ exit: } #if OPENTHREAD_FTD -Error GeneratePskc(const char * aPassPhrase, - const Mac::NetworkName & aNetworkName, - const Mac::ExtendedPanId &aExtPanId, - Pskc & aPskc) +Error GeneratePskc(const char * aPassPhrase, + const Mac::NetworkName & aNetworkName, + const MeshCoP::ExtendedPanId &aExtPanId, + Pskc & aPskc) { Error error = kErrorNone; const char saltPrefix[] = "Thread"; diff --git a/src/core/meshcop/meshcop.hpp b/src/core/meshcop/meshcop.hpp index 508ec738c..c90b42a88 100644 --- a/src/core/meshcop/meshcop.hpp +++ b/src/core/meshcop/meshcop.hpp @@ -420,10 +420,10 @@ private: * @retval kErrorInvalidArgs If the length of passphrase is out of range. * */ -Error GeneratePskc(const char * aPassPhrase, - const Mac::NetworkName & aNetworkName, - const Mac::ExtendedPanId &aExtPanId, - Pskc & aPskc); +Error GeneratePskc(const char * aPassPhrase, + const Mac::NetworkName & aNetworkName, + const MeshCoP::ExtendedPanId &aExtPanId, + Pskc & aPskc); /** * This function computes the Joiner ID from a factory-assigned IEEE EUI-64. diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 3056aed9a..f701d0c2d 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -47,6 +47,7 @@ #include "common/string.hpp" #include "common/tlvs.hpp" #include "mac/mac_types.hpp" +#include "meshcop/extended_panid.hpp" #include "meshcop/timestamp.hpp" #include "net/ip6_address.hpp" #include "radio/radio.hpp" @@ -445,7 +446,7 @@ private: * */ OT_TOOL_PACKED_BEGIN -class ExtendedPanIdTlv : public Tlv, public SimpleTlvInfo +class ExtendedPanIdTlv : public Tlv, public SimpleTlvInfo { public: /** @@ -473,7 +474,7 @@ public: * @returns The Extended PAN ID value. * */ - const Mac::ExtendedPanId &GetExtendedPanId(void) const { return mExtendedPanId; } + const MeshCoP::ExtendedPanId &GetExtendedPanId(void) const { return mExtendedPanId; } /** * This method sets the Extended PAN ID value. @@ -481,10 +482,10 @@ public: * @param[in] aExtendedPanId An Extended PAN ID value. * */ - void SetExtendedPanId(const Mac::ExtendedPanId &aExtendedPanId) { mExtendedPanId = aExtendedPanId; } + void SetExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId) { mExtendedPanId = aExtendedPanId; } private: - Mac::ExtendedPanId mExtendedPanId; + MeshCoP::ExtendedPanId mExtendedPanId; } OT_TOOL_PACKED_END; /** diff --git a/src/core/radio/trel_interface.cpp b/src/core/radio/trel_interface.cpp index 24fac85b9..68825e9c4 100644 --- a/src/core/radio/trel_interface.cpp +++ b/src/core/radio/trel_interface.cpp @@ -139,7 +139,8 @@ void Interface::RegisterService(void) // or Extended PAN ID values. static constexpr uint8_t kTxtDataSize = /* ExtAddr */ sizeof(uint8_t) + sizeof(kTxtRecordExtAddressKey) - 1 + sizeof(char) + sizeof(Mac::ExtAddress) + - /* ExtPanId */ sizeof(uint8_t) + sizeof(kTxtRecordExtPanIdKey) - 1 + sizeof(char) + sizeof(Mac::ExtendedPanId); + /* ExtPanId */ sizeof(uint8_t) + sizeof(kTxtRecordExtPanIdKey) - 1 + sizeof(char) + + sizeof(MeshCoP::ExtendedPanId); uint8_t txtDataBuffer[kTxtDataSize]; MutableData txtData; @@ -148,14 +149,15 @@ void Interface::RegisterService(void) VerifyOrExit(mInitialized && mEnabled); txtEntries[0].Init(kTxtRecordExtAddressKey, Get().GetExtAddress().m8, sizeof(Mac::ExtAddress)); - txtEntries[1].Init(kTxtRecordExtPanIdKey, Get().GetExtendedPanId().m8, sizeof(Mac::ExtendedPanId)); + txtEntries[1].Init(kTxtRecordExtPanIdKey, Get().GetExtPanId().m8, + sizeof(MeshCoP::ExtendedPanId)); txtData.Init(txtDataBuffer, sizeof(txtDataBuffer)); SuccessOrAssert(Dns::TxtEntry::AppendEntries(txtEntries, GetArrayLength(txtEntries), txtData)); LogInfo("Registering DNS-SD service: port:%u, txt:\"%s=%s, %s=%s\"", mUdpPort, kTxtRecordExtAddressKey, Get().GetExtAddress().ToString().AsCString(), kTxtRecordExtPanIdKey, - Get().GetExtendedPanId().ToString().AsCString()); + Get().GetExtPanId().ToString().AsCString()); otPlatTrelRegisterService(&GetInstance(), mUdpPort, txtData.GetBytes(), static_cast(txtData.GetLength())); @@ -176,10 +178,10 @@ exit: void Interface::HandleDiscoveredPeerInfo(const Peer::Info &aInfo) { - Peer * entry; - Mac::ExtAddress extAddress; - Mac::ExtendedPanId extPanId; - bool isNew = false; + Peer * entry; + Mac::ExtAddress extAddress; + MeshCoP::ExtendedPanId extPanId; + bool isNew = false; VerifyOrExit(mInitialized && mEnabled); @@ -237,9 +239,9 @@ exit: return; } -Error Interface::ParsePeerInfoTxtData(const Peer::Info & aInfo, - Mac::ExtAddress & aExtAddress, - Mac::ExtendedPanId &aExtPanId) const +Error Interface::ParsePeerInfoTxtData(const Peer::Info & aInfo, + Mac::ExtAddress & aExtAddress, + MeshCoP::ExtendedPanId &aExtPanId) const { Error error; Dns::TxtEntry entry; @@ -263,8 +265,8 @@ Error Interface::ParsePeerInfoTxtData(const Peer::Info & aInfo, else if (strcmp(entry.mKey, kTxtRecordExtPanIdKey) == 0) { VerifyOrExit(!parsedExtPanId, error = kErrorParse); - VerifyOrExit(entry.mValueLength == sizeof(Mac::ExtendedPanId), error = kErrorParse); - memcpy(aExtPanId.m8, entry.mValue, sizeof(Mac::ExtendedPanId)); + VerifyOrExit(entry.mValueLength == sizeof(MeshCoP::ExtendedPanId), error = kErrorParse); + memcpy(aExtPanId.m8, entry.mValue, sizeof(MeshCoP::ExtendedPanId)); parsedExtPanId = true; } @@ -289,7 +291,7 @@ Interface::Peer *Interface::GetNewPeerEntry(void) for (Peer &entry : mPeerTable) { - if (entry.GetExtPanId() != Get().GetExtendedPanId()) + if (entry.GetExtPanId() != Get().GetExtPanId()) { ExitNow(peerEntry = &entry); } @@ -353,7 +355,7 @@ Error Interface::Send(const Packet &aPacket, bool aIsDiscovery) case Header::kTypeBroadcast: for (Peer &entry : mPeerTable) { - if (!aIsDiscovery && (entry.GetExtPanId() != Get().GetExtendedPanId())) + if (!aIsDiscovery && (entry.GetExtPanId() != Get().GetExtPanId())) { continue; } diff --git a/src/core/radio/trel_interface.hpp b/src/core/radio/trel_interface.hpp index 93a1eab40..b80bf1b78 100644 --- a/src/core/radio/trel_interface.hpp +++ b/src/core/radio/trel_interface.hpp @@ -94,7 +94,10 @@ public: * @returns The Extended PAN Identifier of the TREL peer. * */ - const Mac::ExtendedPanId &GetExtPanId(void) const { return static_cast(mExtPanId); } + const MeshCoP::ExtendedPanId &GetExtPanId(void) const + { + return static_cast(mExtPanId); + } /** * This method returns the IPv6 socket address of the discovered TREL peer. @@ -137,7 +140,7 @@ public: }; void SetExtAddress(const Mac::ExtAddress &aExtAddress) { mExtAddress = aExtAddress; } - void SetExtPanId(const Mac::ExtendedPanId &aExtPanId) { mExtPanId = aExtPanId; } + void SetExtPanId(const MeshCoP::ExtendedPanId &aExtPanId) { mExtPanId = aExtPanId; } void SetSockAddr(const Ip6::SockAddr &aSockAddr) { mSockAddr = aSockAddr; } void Log(const char *aAction) const; }; @@ -241,9 +244,9 @@ private: static void HandleRegisterServiceTask(Tasklet &aTasklet); void RegisterService(void); - Error ParsePeerInfoTxtData(const Peer::Info & aInfo, - Mac::ExtAddress & aExtAddress, - Mac::ExtendedPanId &aExtPanId) const; + Error ParsePeerInfoTxtData(const Peer::Info & aInfo, + Mac::ExtAddress & aExtAddress, + MeshCoP::ExtendedPanId &aExtPanId) const; Peer * GetNewPeerEntry(void); void RemovePeerEntry(Peer &aEntry); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 467328e59..543c234db 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -131,7 +131,7 @@ Mle::Mle(Instance &aInstance) mLeaderAloc.InitAsThreadOriginRealmLocalScope(); - meshLocalPrefix.SetFromExtendedPanId(Get().GetExtendedPanId()); + meshLocalPrefix.SetFromExtendedPanId(Get().GetExtPanId()); mMeshLocal64.InitAsThreadOriginRealmLocalScope(); mMeshLocal64.GetAddress().GetIid().GenerateRandom(); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 6056a219e..a6f0d3046 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -2889,7 +2889,7 @@ void MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6::Messa Tlv tlv; MeshCoP::Tlv meshcopTlv; MeshCoP::DiscoveryRequestTlv discoveryRequest; - Mac::ExtendedPanId extPanId; + MeshCoP::ExtendedPanId extPanId; uint16_t offset; uint16_t end; @@ -2921,7 +2921,7 @@ void MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6::Messa case MeshCoP::Tlv::kExtendedPanId: SuccessOrExit(error = Tlv::Read(aMessage, offset, extPanId)); - VerifyOrExit(Get().GetExtendedPanId() != extPanId, error = kErrorDrop); + VerifyOrExit(Get().GetExtPanId() != extPanId, error = kErrorDrop); break; @@ -3018,7 +3018,8 @@ Error MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, const M SuccessOrExit(error = discoveryResponse.AppendTo(*message)); // Extended PAN ID TLV - SuccessOrExit(error = Tlv::Append(*message, Get().GetExtendedPanId())); + SuccessOrExit( + error = Tlv::Append(*message, Get().GetExtPanId())); // Network Name TLV networkName.Init(); diff --git a/src/core/thread/mle_types.cpp b/src/core/thread/mle_types.cpp index 68feab7f2..ccdf2a6f5 100644 --- a/src/core/thread/mle_types.cpp +++ b/src/core/thread/mle_types.cpp @@ -63,7 +63,7 @@ DeviceMode::InfoString DeviceMode::ToString(void) const return string; } -void MeshLocalPrefix::SetFromExtendedPanId(const Mac::ExtendedPanId &aExtendedPanId) +void MeshLocalPrefix::SetFromExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId) { m8[0] = 0xfd; memcpy(&m8[1], aExtendedPanId.m8, 5); diff --git a/src/core/thread/mle_types.hpp b/src/core/thread/mle_types.hpp index be080a61b..59efaec4b 100644 --- a/src/core/thread/mle_types.hpp +++ b/src/core/thread/mle_types.hpp @@ -49,6 +49,7 @@ #include "common/equatable.hpp" #include "common/string.hpp" #include "mac/mac_types.hpp" +#include "meshcop/extended_panid.hpp" #include "net/ip6_address.hpp" #include "thread/network_data_types.hpp" @@ -428,7 +429,7 @@ public: * @param[in] aExtendedPanId An Extended PAN ID. * */ - void SetFromExtendedPanId(const Mac::ExtendedPanId &aExtendedPanId); + void SetFromExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId); } OT_TOOL_PACKED_END; diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index f36469a05..8ecbd4a0d 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -82,6 +82,7 @@ ThreadNetif::ThreadNetif(Instance &aInstance) #endif , mActiveDataset(aInstance) , mPendingDataset(aInstance) + , mExtendedPanIdManager(aInstance) , mIp6Filter(aInstance) , mKeyManager(aInstance) , mLowpan(aInstance) diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 77496b4fc..8f28b7bee 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -45,6 +45,7 @@ #include "meshcop/border_agent.hpp" #include "meshcop/commissioner.hpp" #include "meshcop/dataset_manager.hpp" +#include "meshcop/extended_panid.hpp" #include "meshcop/joiner.hpp" #include "meshcop/joiner_router.hpp" #include "meshcop/meshcop_leader.hpp" @@ -197,15 +198,16 @@ private: #if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE Sntp::Client mSntpClient; #endif - MeshCoP::ActiveDataset mActiveDataset; - MeshCoP::PendingDataset mPendingDataset; - Ip6::Filter mIp6Filter; - KeyManager mKeyManager; - Lowpan::Lowpan mLowpan; - Mac::Mac mMac; - MeshForwarder mMeshForwarder; - Mle::MleRouter mMleRouter; - Mle::DiscoverScanner mDiscoverScanner; + MeshCoP::ActiveDataset mActiveDataset; + MeshCoP::PendingDataset mPendingDataset; + MeshCoP::ExtendedPanIdManager mExtendedPanIdManager; + Ip6::Filter mIp6Filter; + KeyManager mKeyManager; + Lowpan::Lowpan mLowpan; + Mac::Mac mMac; + MeshForwarder mMeshForwarder; + Mle::MleRouter mMleRouter; + Mle::DiscoverScanner mDiscoverScanner; #if OPENTHREAD_CONFIG_MULTI_RADIO RadioSelector mRadioSelector; #endif diff --git a/tests/unit/test_pskc.cpp b/tests/unit/test_pskc.cpp index d7121f2ff..f7a536479 100644 --- a/tests/unit/test_pskc.cpp +++ b/tests/unit/test_pskc.cpp @@ -44,7 +44,7 @@ void TestMinimumPassphrase(void) const char passphrase[] = "123456"; otInstance * instance = testInitInstance(); SuccessOrQuit(ot::MeshCoP::GeneratePskc(passphrase, *reinterpret_cast("OpenThread"), - static_cast(xpanid), pskc)); + static_cast(xpanid), pskc)); VerifyOrQuit(memcmp(pskc.m8, expectedPskc, OT_PSKC_MAX_SIZE) == 0); testFreeInstance(instance); } @@ -74,7 +74,7 @@ void TestMaximumPassphrase(void) otInstance *instance = testInitInstance(); SuccessOrQuit(ot::MeshCoP::GeneratePskc(passphrase, *reinterpret_cast("OpenThread"), - static_cast(xpanid), pskc)); + static_cast(xpanid), pskc)); VerifyOrQuit(memcmp(pskc.m8, expectedPskc, sizeof(pskc.m8)) == 0); testFreeInstance(instance); } @@ -89,7 +89,7 @@ void TestExampleInSpec(void) otInstance *instance = testInitInstance(); SuccessOrQuit(ot::MeshCoP::GeneratePskc(passphrase, *reinterpret_cast("Test Network"), - static_cast(xpanid), pskc)); + static_cast(xpanid), pskc)); VerifyOrQuit(memcmp(pskc.m8, expectedPskc, sizeof(pskc.m8)) == 0); testFreeInstance(instance); }