From 2aed617140acfc4e3df1c39894d1bef486d5ff27 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Fri, 2 Nov 2018 12:35:53 +0800 Subject: [PATCH] [tlv] update channel related TLVs to process channel page (#3240) --- include/openthread/platform/radio.h | 3 ++- src/core/meshcop/announce_begin_client.cpp | 3 ++- src/core/meshcop/dataset.cpp | 9 ++++--- src/core/meshcop/dataset_manager_ftd.cpp | 14 +++++----- src/core/meshcop/energy_scan_client.cpp | 11 ++++---- src/core/meshcop/joiner_router.cpp | 2 +- src/core/meshcop/meshcop_tlvs.cpp | 30 +++++++++++----------- src/core/meshcop/meshcop_tlvs.hpp | 30 ++++++++++++---------- src/core/meshcop/panid_query_client.cpp | 13 +++++----- src/core/thread/announce_begin_server.cpp | 10 ++++---- src/core/thread/announce_sender.cpp | 11 ++++---- src/core/thread/energy_scan_server.cpp | 17 ++++++------ src/core/thread/mle.cpp | 30 +++++++++++----------- src/core/thread/network_diagnostic.cpp | 2 +- src/core/thread/panid_query_server.cpp | 23 +++++++++-------- 15 files changed, 110 insertions(+), 98 deletions(-) diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index e9d9a43d3..b4434988d 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -68,11 +68,12 @@ extern "C" { enum { OT_RADIO_FRAME_MAX_SIZE = 127, ///< aMaxPHYPacketSize (IEEE 802.15.4-2006) + OT_RADIO_CHANNEL_PAGE = 0, ///< 2.4 GHz IEEE 802.15.4-2006 OT_RADIO_CHANNEL_MIN = 11, ///< 2.4 GHz IEEE 802.15.4-2006 OT_RADIO_CHANNEL_MAX = 26, ///< 2.4 GHz IEEE 802.15.4-2006 OT_RADIO_SUPPORTED_CHANNELS = 0xffff << OT_RADIO_CHANNEL_MIN, ///< 2.4 GHz IEEE 802.15.4-2006 OT_RADIO_SYMBOLS_PER_OCTET = 2, ///< 2.4 GHz IEEE 802.15.4-2006 - OT_RADIO_BIT_RATE = 250000, ///< 2.4 GHz IEEE 802.15.4 (kilobits per second) + OT_RADIO_BIT_RATE = 250000, ///< 2.4 GHz IEEE 802.15.4 (bits per second) OT_RADIO_BITS_PER_OCTET = 8, ///< Number of bits per octet OT_RADIO_SYMBOL_TIME = ((OT_RADIO_BITS_PER_OCTET / OT_RADIO_SYMBOLS_PER_OCTET) * 1000000) / OT_RADIO_BIT_RATE, diff --git a/src/core/meshcop/announce_begin_client.cpp b/src/core/meshcop/announce_begin_client.cpp index 0024faa75..e3a6d7e28 100644 --- a/src/core/meshcop/announce_begin_client.cpp +++ b/src/core/meshcop/announce_begin_client.cpp @@ -64,7 +64,7 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, otError error = OT_ERROR_NONE; Coap::Header header; MeshCoP::CommissionerSessionIdTlv sessionId; - MeshCoP::ChannelMask0Tlv channelMask; + MeshCoP::ChannelMaskTlv channelMask; MeshCoP::CountTlv count; MeshCoP::PeriodTlv period; @@ -86,6 +86,7 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId))); channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(aChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index c987700a4..a49c7f94e 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -144,8 +144,8 @@ void Dataset::Get(otOperationalDataset &aDataset) const case Tlv::kChannelMask: { - const ChannelMaskTlv * tlv = static_cast(cur); - const ChannelMask0Entry *entry = tlv->GetMask0Entry(); + const ChannelMaskBaseTlv *tlv = static_cast(cur); + const ChannelMaskEntry * entry = tlv->GetMaskEntry(OT_RADIO_CHANNEL_PAGE); if (entry != NULL) { @@ -293,15 +293,16 @@ otError Dataset::Set(const otOperationalDataset &aDataset) { MeshCoP::ChannelTlv tlv; tlv.Init(); - tlv.SetChannelPage(0); + tlv.SetChannelPage(OT_RADIO_CHANNEL_PAGE); tlv.SetChannel(aDataset.mChannel); Set(tlv); } if (aDataset.mComponents.mIsChannelMaskPage0Present) { - MeshCoP::ChannelMask0Tlv tlv; + MeshCoP::ChannelMaskTlv tlv; tlv.Init(); + tlv.SetChannelPage(OT_RADIO_CHANNEL_PAGE); tlv.SetMask(aDataset.mChannelMaskPage0); Set(tlv); } diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 75a4f882b..b79103e72 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -156,8 +156,8 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6: // check channel if (Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channel), channel) == OT_ERROR_NONE) { - VerifyOrExit(channel.IsValid() && channel.GetChannel() >= OT_RADIO_CHANNEL_MIN && - channel.GetChannel() <= OT_RADIO_CHANNEL_MAX, + VerifyOrExit(channel.IsValid() && channel.GetChannelPage() == OT_RADIO_CHANNEL_PAGE && + channel.GetChannel() >= OT_RADIO_CHANNEL_MIN && channel.GetChannel() <= OT_RADIO_CHANNEL_MAX, state = StateTlv::kReject); if (channel.GetChannel() != netif.GetMac().GetPanChannel()) @@ -430,15 +430,16 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con { ChannelTlv channel; channel.Init(); - channel.SetChannelPage(0); + channel.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channel.SetChannel(aDataset.mChannel); SuccessOrExit(error = message->Append(&channel, sizeof(channel))); } if (aDataset.mComponents.mIsChannelMaskPage0Present) { - ChannelMask0Tlv channelMask; + ChannelMaskTlv channelMask; channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(aDataset.mChannelMaskPage0); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); } @@ -661,7 +662,7 @@ otError ActiveDataset::GenerateLocal(void) { ChannelTlv tlv; tlv.Init(); - tlv.SetChannelPage(0); + tlv.SetChannelPage(OT_RADIO_CHANNEL_PAGE); tlv.SetChannel(netif.GetMac().GetPanChannel()); dataset.Set(tlv); } @@ -669,8 +670,9 @@ otError ActiveDataset::GenerateLocal(void) // channelMask if (dataset.Get(Tlv::kChannelMask) == NULL) { - ChannelMask0Tlv tlv; + ChannelMaskTlv tlv; tlv.Init(); + tlv.SetChannelPage(OT_RADIO_CHANNEL_PAGE); tlv.SetMask(netif.GetMac().GetSupportedChannelMask().GetMask()); dataset.Set(tlv); } diff --git a/src/core/meshcop/energy_scan_client.cpp b/src/core/meshcop/energy_scan_client.cpp index 0df0d7b65..60680b790 100644 --- a/src/core/meshcop/energy_scan_client.cpp +++ b/src/core/meshcop/energy_scan_client.cpp @@ -76,7 +76,7 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM otError error = OT_ERROR_NONE; Coap::Header header; MeshCoP::CommissionerSessionIdTlv sessionId; - MeshCoP::ChannelMask0Tlv channelMask; + MeshCoP::ChannelMaskTlv channelMask; MeshCoP::CountTlv count; MeshCoP::PeriodTlv period; MeshCoP::ScanDurationTlv scanDuration; @@ -97,6 +97,7 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId))); channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(aChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); @@ -145,9 +146,9 @@ void EnergyScanClient::HandleReport(void * aContext, void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - ThreadNetif & netif = GetNetif(); - MeshCoP::ChannelMask0Tlv channelMask; - Ip6::MessageInfo responseInfo(aMessageInfo); + ThreadNetif & netif = GetNetif(); + MeshCoP::ChannelMaskTlv channelMask; + Ip6::MessageInfo responseInfo(aMessageInfo); OT_TOOL_PACKED_BEGIN struct @@ -161,7 +162,7 @@ void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, co otLogInfoMeshCoP("received energy scan report"); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); - VerifyOrExit(channelMask.IsValid()); + VerifyOrExit(channelMask.IsValid() && channelMask.GetChannelPage() == OT_RADIO_CHANNEL_PAGE); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kEnergyList, sizeof(energyList), energyList.tlv)); VerifyOrExit(energyList.tlv.IsValid()); diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index a851a9dd6..20d6b328f 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -347,7 +347,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage } else { - ChannelMaskTlv channelMask; + ChannelMaskBaseTlv channelMask; channelMask.Init(); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); } diff --git a/src/core/meshcop/meshcop_tlvs.cpp b/src/core/meshcop/meshcop_tlvs.cpp index 75a36b8cf..0cad86164 100644 --- a/src/core/meshcop/meshcop_tlvs.cpp +++ b/src/core/meshcop/meshcop_tlvs.cpp @@ -113,48 +113,48 @@ void SteeringDataTlv::ComputeBloomFilter(const otExtAddress &aJoinerId) SetBit(ansi.Get() % GetNumBits()); } -const ChannelMaskEntry *ChannelMaskEntry::GetNext(const Tlv *aChannelMaskTlv) const +const ChannelMaskEntryBase *ChannelMaskEntryBase::GetNext(const Tlv *aChannelMaskBaseTlv) const { const uint8_t *entry = reinterpret_cast(this) + GetSize(); - const uint8_t *end = aChannelMaskTlv->GetValue() + aChannelMaskTlv->GetSize(); + const uint8_t *end = aChannelMaskBaseTlv->GetValue() + aChannelMaskBaseTlv->GetSize(); - return (entry < end) ? reinterpret_cast(entry) : NULL; + return (entry < end) ? reinterpret_cast(entry) : NULL; } -const ChannelMaskEntry *ChannelMaskTlv::GetFirstEntry(void) const +const ChannelMaskEntryBase *ChannelMaskBaseTlv::GetFirstEntry(void) const { - const ChannelMaskEntry *entry = NULL; + const ChannelMaskEntryBase *entry = NULL; - VerifyOrExit(GetLength() >= sizeof(ChannelMaskEntry)); + VerifyOrExit(GetLength() >= sizeof(ChannelMaskEntryBase)); - entry = reinterpret_cast(GetValue()); + entry = reinterpret_cast(GetValue()); VerifyOrExit(GetLength() >= entry->GetSize(), entry = NULL); exit: return entry; } -const ChannelMask0Entry *ChannelMaskTlv::GetMask0Entry(void) const +const ChannelMaskEntry *ChannelMaskBaseTlv::GetMaskEntry(uint8_t aChannelPage) const { - const ChannelMask0Entry *page0Entry = NULL; + const ChannelMaskEntry *pageEntry = NULL; - for (const ChannelMaskEntry *entry = GetFirstEntry(); entry != NULL; entry = entry->GetNext(this)) + for (const ChannelMaskEntryBase *entry = GetFirstEntry(); entry != NULL; entry = entry->GetNext(this)) { - if (entry->GetChannelPage() == 0) + if (entry->GetChannelPage() == aChannelPage) { - page0Entry = static_cast(entry); + pageEntry = static_cast(entry); - if (page0Entry->IsValid()) + if (pageEntry->IsValid()) { ExitNow(); } } } - page0Entry = NULL; + pageEntry = NULL; exit: - return page0Entry; + return pageEntry; } } // namespace MeshCoP diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 27b81fa02..8193a34d2 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -1321,7 +1321,7 @@ private: * */ OT_TOOL_PACKED_BEGIN -class ChannelMaskEntry +class ChannelMaskEntryBase { public: /** @@ -1362,7 +1362,7 @@ public: * @returns The total size of this entry (number of bytes). * */ - uint16_t GetSize(void) const { return sizeof(ChannelMaskEntry) + mMaskLength; } + uint16_t GetSize(void) const { return sizeof(ChannelMaskEntryBase) + mMaskLength; } /** * This method clears the bit corresponding to @p aChannel in ChannelMask. @@ -1403,12 +1403,12 @@ public: /** * This method gets the next Channel Mask Entry in a Channel Mask TLV. * - * @param[in] aChannelMaskTlv A pointer to the Channel Mask TLV to which this entry belongs. + * @param[in] aChannelMaskBaseTlv A pointer to the Channel Mask TLV to which this entry belongs. * * @returns A pointer to next Channel Mask Entry or NULL if none found. * */ - const ChannelMaskEntry *GetNext(const Tlv *aChannelMaskTlv) const; + const ChannelMaskEntryBase *GetNext(const Tlv *aChannelMaskBaseTlv) const; private: uint8_t mChannelPage; @@ -1420,7 +1420,7 @@ private: * */ OT_TOOL_PACKED_BEGIN -class ChannelMask0Entry : public ChannelMaskEntry +class ChannelMaskEntry : public ChannelMaskEntryBase { public: /** @@ -1440,7 +1440,7 @@ public: * @retval FALSE If the entry does not appear to be well-formed. * */ - bool IsValid(void) const { return GetChannelPage() == 0 && GetMaskLength() == sizeof(mMask); } + bool IsValid(void) const { return GetMaskLength() == sizeof(mMask); } /** * This method returns the Channel Mask value as a `uint32_t` bit mask. @@ -1467,7 +1467,7 @@ private: * */ OT_TOOL_PACKED_BEGIN -class ChannelMaskTlv : public Tlv +class ChannelMaskBaseTlv : public Tlv { public: /** @@ -1495,15 +1495,17 @@ public: * @returns A pointer to first Channel Mask Entry or NULL if not found. * */ - const ChannelMaskEntry *GetFirstEntry(void) const; + const ChannelMaskEntryBase *GetFirstEntry(void) const; /** - * This method gets the Page 0 Channel Mask Entry in the Channel Mask TLV. + * This method gets the Channel Mask Entry in the Channel Mask TLV. * - * @returns A pointer to Page 0 Channel Mask Entry or NULL if not found. + * @param[in] aChannelPage The ChannelPage value. + * + * @returns A pointer to Channel Mask Entry or NULL if not found. * */ - const ChannelMask0Entry *GetMask0Entry(void) const; + const ChannelMaskEntry *GetMaskEntry(uint8_t aChannelPage) const; } OT_TOOL_PACKED_END; @@ -1512,7 +1514,7 @@ public: * */ OT_TOOL_PACKED_BEGIN -class ChannelMask0Tlv : public ChannelMaskTlv, public ChannelMask0Entry +class ChannelMaskTlv : public ChannelMaskBaseTlv, public ChannelMaskEntry { public: /** @@ -1523,7 +1525,7 @@ public: { SetType(kChannelMask); SetLength(sizeof(*this) - sizeof(Tlv)); - ChannelMask0Entry::Init(); + ChannelMaskEntry::Init(); } /** @@ -1533,7 +1535,7 @@ public: * @retval FALSE If the TLV does not appear to be well-formed. * */ - bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv) && ChannelMask0Entry::IsValid(); } + bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv) && ChannelMaskEntry::IsValid(); } } OT_TOOL_PACKED_END; /** diff --git a/src/core/meshcop/panid_query_client.cpp b/src/core/meshcop/panid_query_client.cpp index 4ae28feb0..5bbd21704 100644 --- a/src/core/meshcop/panid_query_client.cpp +++ b/src/core/meshcop/panid_query_client.cpp @@ -70,7 +70,7 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, otError error = OT_ERROR_NONE; Coap::Header header; MeshCoP::CommissionerSessionIdTlv sessionId; - MeshCoP::ChannelMask0Tlv channelMask; + MeshCoP::ChannelMaskTlv channelMask; MeshCoP::PanIdTlv panId; Ip6::MessageInfo messageInfo; Message * message = NULL; @@ -89,6 +89,7 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId))); channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(aChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); @@ -129,10 +130,10 @@ void PanIdQueryClient::HandleConflict(void * aContext, void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - ThreadNetif & netif = GetNetif(); - MeshCoP::PanIdTlv panId; - MeshCoP::ChannelMask0Tlv channelMask; - Ip6::MessageInfo responseInfo(aMessageInfo); + ThreadNetif & netif = GetNetif(); + MeshCoP::PanIdTlv panId; + MeshCoP::ChannelMaskTlv channelMask; + Ip6::MessageInfo responseInfo(aMessageInfo); VerifyOrExit(aHeader.GetType() == OT_COAP_TYPE_CONFIRMABLE && aHeader.GetCode() == OT_COAP_CODE_POST); @@ -142,7 +143,7 @@ void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage, VerifyOrExit(panId.IsValid()); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); - VerifyOrExit(channelMask.IsValid()); + VerifyOrExit(channelMask.IsValid() && (channelMask.GetChannelPage() == OT_RADIO_CHANNEL_PAGE)); if (mCallback != NULL) { diff --git a/src/core/thread/announce_begin_server.cpp b/src/core/thread/announce_begin_server.cpp index 86fde9da4..f3303fd57 100644 --- a/src/core/thread/announce_begin_server.cpp +++ b/src/core/thread/announce_begin_server.cpp @@ -80,15 +80,15 @@ void AnnounceBeginServer::HandleRequest(void * aContext, void AnnounceBeginServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - MeshCoP::ChannelMask0Tlv channelMask; - MeshCoP::CountTlv count; - MeshCoP::PeriodTlv period; - Ip6::MessageInfo responseInfo(aMessageInfo); + MeshCoP::ChannelMaskTlv channelMask; + MeshCoP::CountTlv count; + MeshCoP::PeriodTlv period; + Ip6::MessageInfo responseInfo(aMessageInfo); VerifyOrExit(aHeader.GetCode() == OT_COAP_CODE_POST); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); - VerifyOrExit(channelMask.IsValid()); + VerifyOrExit(channelMask.IsValid() && (channelMask.GetChannelPage() == OT_RADIO_CHANNEL_PAGE)); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kCount, sizeof(count), count)); VerifyOrExit(count.IsValid()); diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index e26ec5da4..7757df28e 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -124,14 +124,15 @@ void AnnounceSender::HandleTimer(Timer &aTimer) otError AnnounceSender::GetActiveDatasetChannelMask(Mac::ChannelMask &aMask) const { - otError error = OT_ERROR_NONE; - const MeshCoP::ChannelMask0Tlv *channelMaskTlv; - MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); + otError error = OT_ERROR_NONE; + const MeshCoP::ChannelMaskTlv *channelMaskTlv; + MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); SuccessOrExit(error = GetNetif().GetActiveDataset().Get(dataset)); - channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); - VerifyOrExit(channelMaskTlv != NULL, error = OT_ERROR_NOT_FOUND); + channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); + VerifyOrExit(channelMaskTlv != NULL && channelMaskTlv->GetChannelPage() == OT_RADIO_CHANNEL_PAGE, + error = OT_ERROR_NOT_FOUND); aMask.SetMask(channelMaskTlv->GetMask()); diff --git a/src/core/thread/energy_scan_server.cpp b/src/core/thread/energy_scan_server.cpp index ec976defe..08099fb9a 100644 --- a/src/core/thread/energy_scan_server.cpp +++ b/src/core/thread/energy_scan_server.cpp @@ -82,7 +82,7 @@ void EnergyScanServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, c MeshCoP::CountTlv count; MeshCoP::PeriodTlv period; MeshCoP::ScanDurationTlv scanDuration; - MeshCoP::ChannelMask0Tlv channelMask; + MeshCoP::ChannelMaskTlv channelMask; Ip6::MessageInfo responseInfo(aMessageInfo); VerifyOrExit(aHeader.GetCode() == OT_COAP_CODE_POST); @@ -97,7 +97,7 @@ void EnergyScanServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, c VerifyOrExit(scanDuration.IsValid()); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); - VerifyOrExit(channelMask.IsValid()); + VerifyOrExit(channelMask.IsValid() && channelMask.GetChannelPage() == OT_RADIO_CHANNEL_PAGE); mChannelMask = channelMask.GetMask(); mChannelMaskCurrent = mChannelMask; @@ -184,12 +184,12 @@ exit: otError EnergyScanServer::SendReport(void) { - otError error = OT_ERROR_NONE; - Coap::Header header; - MeshCoP::ChannelMask0Tlv channelMask; - MeshCoP::EnergyListTlv energyList; - Ip6::MessageInfo messageInfo; - Message * message; + otError error = OT_ERROR_NONE; + Coap::Header header; + MeshCoP::ChannelMaskTlv channelMask; + MeshCoP::EnergyListTlv energyList; + Ip6::MessageInfo messageInfo; + Message * message; header.Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); header.SetToken(Coap::Header::kDefaultTokenLength); @@ -200,6 +200,7 @@ otError EnergyScanServer::SendReport(void) error = OT_ERROR_NO_BUFS); channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(mChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 186f271d2..030649f3d 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1689,20 +1689,20 @@ exit: bool Mle::PrepareAnnounceState(void) { - bool shouldAnnounce = false; - uint16_t numChannels = 0; - const MeshCoP::ChannelMaskTlv * channelMaskTlv; - const MeshCoP::ChannelMask0Entry *channelMaskEntry; - MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); + bool shouldAnnounce = false; + uint16_t numChannels = 0; + const MeshCoP::ChannelMaskBaseTlv *channelMaskTlv; + const MeshCoP::ChannelMaskEntry * channelMaskEntry; + MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); VerifyOrExit((mRole != OT_DEVICE_ROLE_CHILD) && !IsFullThreadDevice() && (mReattachState == kReattachStop)); SuccessOrExit(GetNetif().GetActiveDataset().Get(dataset)); - channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); + channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); VerifyOrExit(channelMaskTlv != NULL); - channelMaskEntry = channelMaskTlv->GetMask0Entry(); + channelMaskEntry = channelMaskTlv->GetMaskEntry(OT_RADIO_CHANNEL_PAGE); VerifyOrExit(channelMaskEntry != NULL); for (uint8_t channel = OT_RADIO_CHANNEL_MIN; channel <= OT_RADIO_CHANNEL_MAX; channel++) @@ -2324,7 +2324,7 @@ otError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Add SuccessOrExit(error = AppendHeader(*message, Header::kCommandAnnounce)); channel.Init(); - channel.SetChannelPage(0); + channel.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channel.SetChannel(netif.GetMac().GetPanChannel()); SuccessOrExit(error = message->Append(&channel, sizeof(channel))); @@ -2361,17 +2361,17 @@ exit: otError Mle::SendOrphanAnnounce(void) { - otError error = OT_ERROR_NONE; - const MeshCoP::ChannelMaskTlv * channelMaskTlv; - const MeshCoP::ChannelMask0Entry *channelMaskEntry; - MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); + otError error = OT_ERROR_NONE; + const MeshCoP::ChannelMaskBaseTlv *channelMaskTlv; + const MeshCoP::ChannelMaskEntry * channelMaskEntry; + MeshCoP::Dataset dataset(MeshCoP::Tlv::kActiveTimestamp); SuccessOrExit(error = GetNetif().GetActiveDataset().Get(dataset)); - channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); + channelMaskTlv = static_cast(dataset.Get(MeshCoP::Tlv::kChannelMask)); VerifyOrExit(channelMaskTlv != NULL, error = OT_ERROR_NOT_FOUND); - channelMaskEntry = channelMaskTlv->GetMask0Entry(); + channelMaskEntry = channelMaskTlv->GetMaskEntry(OT_RADIO_CHANNEL_PAGE); VerifyOrExit(channelMaskEntry != NULL, error = OT_ERROR_NOT_FOUND); VerifyOrExit(mAnnounceChannel <= OT_RADIO_CHANNEL_MAX, error = OT_ERROR_NOT_FOUND); @@ -3584,7 +3584,7 @@ otError Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMe LogMleMessage("Receive Announce", aMessageInfo.GetPeerAddr()); SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channelTlv), channelTlv)); - VerifyOrExit(channelTlv.IsValid(), error = OT_ERROR_PARSE); + VerifyOrExit(channelTlv.IsValid() && channelTlv.GetChannelPage() == OT_RADIO_CHANNEL_PAGE, error = OT_ERROR_PARSE); channel = static_cast(channelTlv.GetChannel()); SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(timestamp), timestamp)); diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 618259360..70ed3b8ce 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -413,7 +413,7 @@ otError NetworkDiagnostic::FillRequestedTlvs(Message & aRequest, { ChannelPagesTlv tlv; tlv.Init(); - tlv.GetChannelPages()[0] = 0; + tlv.GetChannelPages()[0] = OT_RADIO_CHANNEL_PAGE; tlv.SetLength(1); SuccessOrExit(error = aResponse.Append(&tlv, tlv.GetSize())); break; diff --git a/src/core/thread/panid_query_server.cpp b/src/core/thread/panid_query_server.cpp index 5fa1ec3bc..62241662e 100644 --- a/src/core/thread/panid_query_server.cpp +++ b/src/core/thread/panid_query_server.cpp @@ -72,14 +72,14 @@ void PanIdQueryServer::HandleQuery(void * aContext, void PanIdQueryServer::HandleQuery(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - MeshCoP::PanIdTlv panId; - MeshCoP::ChannelMask0Tlv channelMask; - Ip6::MessageInfo responseInfo(aMessageInfo); + MeshCoP::PanIdTlv panId; + MeshCoP::ChannelMaskTlv channelMask; + Ip6::MessageInfo responseInfo(aMessageInfo); VerifyOrExit(aHeader.GetCode() == OT_COAP_CODE_POST); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); - VerifyOrExit(channelMask.IsValid()); + VerifyOrExit(channelMask.IsValid() && channelMask.GetChannelPage() == OT_RADIO_CHANNEL_PAGE); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kPanId, sizeof(panId), panId)); VerifyOrExit(panId.IsValid()); @@ -125,13 +125,13 @@ void PanIdQueryServer::HandleScanResult(Mac::Frame *aFrame) otError PanIdQueryServer::SendConflict(void) { - ThreadNetif & netif = GetNetif(); - otError error = OT_ERROR_NONE; - Coap::Header header; - MeshCoP::ChannelMask0Tlv channelMask; - MeshCoP::PanIdTlv panId; - Ip6::MessageInfo messageInfo; - Message * message; + ThreadNetif & netif = GetNetif(); + otError error = OT_ERROR_NONE; + Coap::Header header; + MeshCoP::ChannelMaskTlv channelMask; + MeshCoP::PanIdTlv panId; + Ip6::MessageInfo messageInfo; + Message * message; header.Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); header.SetToken(Coap::Header::kDefaultTokenLength); @@ -141,6 +141,7 @@ otError PanIdQueryServer::SendConflict(void) VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS); channelMask.Init(); + channelMask.SetChannelPage(OT_RADIO_CHANNEL_PAGE); channelMask.SetMask(mChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));