From b06707fc95e59d32989f9e9ab870e14be5f96a25 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 27 Apr 2017 10:19:47 -0700 Subject: [PATCH] Implement MLE Discovery Request Joiner flag filter. (#1665) --- src/core/thread/mle_router.cpp | 6 ++++++ src/core/thread/network_data_leader.cpp | 22 ++++++++++++++++++++++ src/core/thread/network_data_leader.hpp | 10 ++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 06b6b244e..290ca7113 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -2493,6 +2493,12 @@ ThreadError MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6 case MeshCoP::Tlv::kDiscoveryRequest: aMessage.Read(offset, sizeof(discoveryRequest), &discoveryRequest); VerifyOrExit(discoveryRequest.IsValid(), error = kThreadError_Parse); + + if (discoveryRequest.IsJoiner()) + { + VerifyOrExit(mNetif.GetNetworkDataLeader().IsJoiningEnabled()); + } + break; case MeshCoP::Tlv::kExtendedPanId: diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 2a9670b61..05c55c6c8 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -494,6 +494,28 @@ exit: return rval; } +bool LeaderBase::IsJoiningEnabled(void) +{ + MeshCoP::Tlv *steeringData; + bool rval = false; + + VerifyOrExit(GetCommissioningDataSubTlv(MeshCoP::Tlv::kBorderAgentLocator) != NULL); + + steeringData = GetCommissioningDataSubTlv(MeshCoP::Tlv::kSteeringData); + VerifyOrExit(steeringData != NULL); + + for (int i = 0; i < steeringData->GetLength(); i++) + { + if (steeringData->GetValue()[i] != 0) + { + ExitNow(rval = true); + } + } + +exit: + return rval; +} + ThreadError LeaderBase::RemoveCommissioningData(void) { ThreadError error = kThreadError_NotFound; diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index 61f6d4656..92597aef0 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -187,6 +187,16 @@ public: */ MeshCoP::Tlv *GetCommissioningDataSubTlv(MeshCoP::Tlv::Type aType); + /** + * This method indicates whether or not the Commissioning Data TLV indicates Joining is enabled. + * + * Joining is enabled if a Border Agent Locator TLV exist and the Steering Data TLV is non-zero. + * + * @returns TRUE if the Commissioning Data TLV says Joining is enabled, FALSE otherwise. + * + */ + bool IsJoiningEnabled(void); + /** * This method adds Commissioning Data to the Thread Network Data. *