diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 67d73287c..5fa7d6f93 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -162,6 +162,13 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) { otLogFuncEntryMsg("aResult = %llX", HostSwap64(*reinterpret_cast(&aResult->mExtAddress))); + // Joining is disabled if the Steering Data is not included + if (aResult->mSteeringData.mLength == 0) + { + otLogDebgMeshCoP("No steering data, joining disabled"); + ExitNow(); + } + SteeringDataTlv steeringData; Mac::ExtAddress extAddress; Crc16 ccitt(Crc16::kCcitt); @@ -178,8 +185,9 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) steeringData.SetLength(aResult->mSteeringData.mLength); memcpy(steeringData.GetValue(), aResult->mSteeringData.m8, steeringData.GetLength()); - if (steeringData.GetBit(ccitt.Get() % steeringData.GetNumBits()) && - steeringData.GetBit(ansi.Get() % steeringData.GetNumBits())) + if (steeringData.DoesAllowAny() || + (steeringData.GetBit(ccitt.Get() % steeringData.GetNumBits()) && + steeringData.GetBit(ansi.Get() % steeringData.GetNumBits()))) { mJoinerUdpPort = aResult->mJoinerUdpPort; mJoinerRouterPanId = aResult->mPanId; @@ -188,7 +196,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) } else { - otLogDebgMeshCoP("Steering data not set"); + otLogDebgMeshCoP("Steering data does not include this device"); } } else if (mJoinerRouterPanId != Mac::kPanIdBroadcast) @@ -213,6 +221,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) Complete(kThreadError_NotFound); } +exit: otLogFuncExit(); } diff --git a/src/core/meshcop/tlvs.hpp b/src/core/meshcop/tlvs.hpp index a6db54a0a..5bc5b239f 100644 --- a/src/core/meshcop/tlvs.hpp +++ b/src/core/meshcop/tlvs.hpp @@ -574,6 +574,26 @@ public: */ void Set(void) { memset(mSteeringData, 0xff, GetLength()); } + /** + * Ths method indicates whether or not the SteeringData allows all Joiners. + * + * @retval TRUE If the SteeringData allows all Joiners. + * @retval FALSE If the SteeringData doesn't allow any Joiner. + * + */ + bool DoesAllowAny(void) { + bool rval = true; + + for (uint8_t i = 0; i < GetLength(); i++) { + if (mSteeringData[i] != 0xff) { + rval = false; + break; + } + } + + return rval; + } + /** * This method returns the number of bits in the Bloom Filter. *