mirror of
https://github.com/espressif/openthread.git
synced 2026-08-01 16:47:47 +00:00
[meshcop] separate Extended PAN ID from Mac (#7609)
With the removal of Thread payload from IEEE 802.15.4 Beacons, the MAC layer no longer needs to maintain the Extended PAN ID.
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -55,19 +55,19 @@ void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout)
|
||||
|
||||
const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance)
|
||||
{
|
||||
return &AsCoreType(aInstance).Get<Mac::Mac>().GetExtendedPanId();
|
||||
return &AsCoreType(aInstance).Get<MeshCoP::ExtendedPanIdManager>().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<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
|
||||
|
||||
instance.Get<Mac::Mac>().SetExtendedPanId(extPanId);
|
||||
instance.Get<MeshCoP::ExtendedPanIdManager>().SetExtPanId(extPanId);
|
||||
|
||||
prefix.SetFromExtendedPanId(extPanId);
|
||||
instance.Get<Mle::MleRouter>().SetMeshLocalPrefix(prefix);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<KeyManager>().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<Notifier>().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged));
|
||||
}
|
||||
|
||||
void Mac::RequestDirectFrameTransmission(void)
|
||||
{
|
||||
VerifyOrExit(IsEnabled());
|
||||
|
||||
+13
-31
@@ -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
|
||||
|
||||
@@ -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<kWithUint8Length> destData;
|
||||
|
||||
@@ -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<ExtendedPanId>, public Clearable<ExtendedPanId>
|
||||
{
|
||||
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<kInfoStringSize> 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
|
||||
|
||||
@@ -555,7 +555,7 @@ Error Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsNetworkKeyUpdate
|
||||
break;
|
||||
|
||||
case Tlv::kExtendedPanId:
|
||||
mac.SetExtendedPanId(As<ExtendedPanIdTlv>(cur)->GetExtendedPanId());
|
||||
aInstance.Get<MeshCoP::ExtendedPanIdManager>().SetExtPanId(As<ExtendedPanIdTlv>(cur)->GetExtendedPanId());
|
||||
break;
|
||||
|
||||
case Tlv::kNetworkName:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -334,7 +334,7 @@ Error ActiveDataset::GenerateLocal(void)
|
||||
|
||||
if (dataset.GetTlv<ExtendedPanIdTlv>() == nullptr)
|
||||
{
|
||||
IgnoreError(dataset.SetTlv(Tlv::kExtendedPanId, Get<Mac::Mac>().GetExtendedPanId()));
|
||||
IgnoreError(dataset.SetTlv(Tlv::kExtendedPanId, Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
|
||||
}
|
||||
|
||||
if (dataset.GetTlv<MeshLocalPrefixTlv>() == nullptr)
|
||||
|
||||
@@ -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<Notifier>().Update(mExtendedPanId, aExtendedPanId, kEventThreadExtPanIdChanged));
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
@@ -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 <openthread/dataset.h>
|
||||
|
||||
#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<ExtendedPanId>, public Clearable<ExtendedPanId>
|
||||
{
|
||||
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<kInfoStringSize> 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_
|
||||
@@ -325,7 +325,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
|
||||
Get<KeyManager>().GetNetworkKey(networkKey);
|
||||
SuccessOrExit(error = Tlv::Append<NetworkKeyTlv>(*message, networkKey));
|
||||
SuccessOrExit(error = Tlv::Append<MeshLocalPrefixTlv>(*message, Get<Mle::MleRouter>().GetMeshLocalPrefix()));
|
||||
SuccessOrExit(error = Tlv::Append<ExtendedPanIdTlv>(*message, Get<Mac::Mac>().GetExtendedPanId()));
|
||||
SuccessOrExit(error = Tlv::Append<ExtendedPanIdTlv>(*message, Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
|
||||
|
||||
networkName.Init();
|
||||
networkName.SetNetworkName(Get<Mac::Mac>().GetNetworkName().GetAsData());
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Tlv::kExtendedPanId, Mac::ExtendedPanId>
|
||||
class ExtendedPanIdTlv : public Tlv, public SimpleTlvInfo<Tlv::kExtendedPanId, MeshCoP::ExtendedPanId>
|
||||
{
|
||||
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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<kWithUint16Length> txtData;
|
||||
@@ -148,14 +149,15 @@ void Interface::RegisterService(void)
|
||||
VerifyOrExit(mInitialized && mEnabled);
|
||||
|
||||
txtEntries[0].Init(kTxtRecordExtAddressKey, Get<Mac::Mac>().GetExtAddress().m8, sizeof(Mac::ExtAddress));
|
||||
txtEntries[1].Init(kTxtRecordExtPanIdKey, Get<Mac::Mac>().GetExtendedPanId().m8, sizeof(Mac::ExtendedPanId));
|
||||
txtEntries[1].Init(kTxtRecordExtPanIdKey, Get<MeshCoP::ExtendedPanIdManager>().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<Mac::Mac>().GetExtAddress().ToString().AsCString(), kTxtRecordExtPanIdKey,
|
||||
Get<Mac::Mac>().GetExtendedPanId().ToString().AsCString());
|
||||
Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId().ToString().AsCString());
|
||||
|
||||
otPlatTrelRegisterService(&GetInstance(), mUdpPort, txtData.GetBytes(), static_cast<uint8_t>(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<Mac::Mac>().GetExtendedPanId())
|
||||
if (entry.GetExtPanId() != Get<MeshCoP::ExtendedPanIdManager>().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<Mac::Mac>().GetExtendedPanId()))
|
||||
if (!aIsDiscovery && (entry.GetExtPanId() != Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,10 @@ public:
|
||||
* @returns The Extended PAN Identifier of the TREL peer.
|
||||
*
|
||||
*/
|
||||
const Mac::ExtendedPanId &GetExtPanId(void) const { return static_cast<const Mac::ExtendedPanId &>(mExtPanId); }
|
||||
const MeshCoP::ExtendedPanId &GetExtPanId(void) const
|
||||
{
|
||||
return static_cast<const MeshCoP::ExtendedPanId &>(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);
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ Mle::Mle(Instance &aInstance)
|
||||
|
||||
mLeaderAloc.InitAsThreadOriginRealmLocalScope();
|
||||
|
||||
meshLocalPrefix.SetFromExtendedPanId(Get<Mac::Mac>().GetExtendedPanId());
|
||||
meshLocalPrefix.SetFromExtendedPanId(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
|
||||
mMeshLocal64.InitAsThreadOriginRealmLocalScope();
|
||||
mMeshLocal64.GetAddress().GetIid().GenerateRandom();
|
||||
|
||||
@@ -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<MeshCoP::ExtendedPanIdTlv>(aMessage, offset, extPanId));
|
||||
VerifyOrExit(Get<Mac::Mac>().GetExtendedPanId() != extPanId, error = kErrorDrop);
|
||||
VerifyOrExit(Get<MeshCoP::ExtendedPanIdManager>().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<MeshCoP::ExtendedPanIdTlv>(*message, Get<Mac::Mac>().GetExtendedPanId()));
|
||||
SuccessOrExit(
|
||||
error = Tlv::Append<MeshCoP::ExtendedPanIdTlv>(*message, Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId()));
|
||||
|
||||
// Network Name TLV
|
||||
networkName.Init();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ ThreadNetif::ThreadNetif(Instance &aInstance)
|
||||
#endif
|
||||
, mActiveDataset(aInstance)
|
||||
, mPendingDataset(aInstance)
|
||||
, mExtendedPanIdManager(aInstance)
|
||||
, mIp6Filter(aInstance)
|
||||
, mKeyManager(aInstance)
|
||||
, mLowpan(aInstance)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -44,7 +44,7 @@ void TestMinimumPassphrase(void)
|
||||
const char passphrase[] = "123456";
|
||||
otInstance * instance = testInitInstance();
|
||||
SuccessOrQuit(ot::MeshCoP::GeneratePskc(passphrase, *reinterpret_cast<const ot::Mac::NetworkName *>("OpenThread"),
|
||||
static_cast<const ot::Mac::ExtendedPanId &>(xpanid), pskc));
|
||||
static_cast<const ot::MeshCoP::ExtendedPanId &>(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<const ot::Mac::NetworkName *>("OpenThread"),
|
||||
static_cast<const ot::Mac::ExtendedPanId &>(xpanid), pskc));
|
||||
static_cast<const ot::MeshCoP::ExtendedPanId &>(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<const ot::Mac::NetworkName *>("Test Network"),
|
||||
static_cast<const ot::Mac::ExtendedPanId &>(xpanid), pskc));
|
||||
static_cast<const ot::MeshCoP::ExtendedPanId &>(xpanid), pskc));
|
||||
VerifyOrQuit(memcmp(pskc.m8, expectedPskc, sizeof(pskc.m8)) == 0);
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user