From e08f5aebd93e7c7ef5f9a257cfa3c5885cf76e42 Mon Sep 17 00:00:00 2001 From: kangping Date: Tue, 5 May 2020 02:04:05 +0800 Subject: [PATCH] [joiner] use random extended address for discovery request (#4920) Thread specification requires the source address of Discovery Request to be random value. While for subsequent messages, the joiner should use hash of EUI-64 (joiner ID) value. --- src/core/meshcop/joiner.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 49747f68c..74c3d6024 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -96,15 +96,15 @@ otError Joiner::Start(const char * aPskd, void * aContext) { otError error; - Mac::ExtAddress joinerId; + Mac::ExtAddress randomAddress; otLogInfoMeshCoP("Joiner starting"); VerifyOrExit(mState == OT_JOINER_STATE_IDLE, error = OT_ERROR_BUSY); - // Use extended address based on factory-assigned IEEE EUI-64 - GetJoinerId(joinerId); - Get().SetExtAddress(joinerId); + // Use random-generated extended address. + randomAddress.GenerateRandom(); + Get().SetExtAddress(randomAddress); Get().UpdateLinkLocalAddress(); SuccessOrExit(error = Get().Start(kJoinerUdpPort)); @@ -222,6 +222,8 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult, void *aContext) void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) { + Mac::ExtAddress joinerId; + VerifyOrExit(mState == OT_JOINER_STATE_DISCOVER, OT_NOOP); if (aResult != NULL) @@ -230,6 +232,11 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) } else { + // Use extended address based on factory-assigned IEEE EUI-64 + GetJoinerId(joinerId); + Get().SetExtAddress(joinerId); + Get().UpdateLinkLocalAddress(); + mJoinerRouterIndex = 0; TryNextJoinerRouter(OT_ERROR_NONE); }