From bc3f5c88521f2b11c8cc2557fcee7b564e06ac8b Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 4 May 2017 09:55:48 +0800 Subject: [PATCH] Ensure to set Extended Address's local bit (#1711) * Create a new `GenerateExtAddress()` method; * Fix the issue that the extended address U/L bit may not be set, which is generated after join success. --- src/core/mac/mac.cpp | 19 ++++++++++++------- src/core/mac/mac.hpp | 8 ++++++++ src/core/meshcop/joiner.cpp | 6 +----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index bb5426f78..a16eada01 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -154,13 +154,7 @@ Mac::Mac(ThreadNetif &aThreadNetif): mTxFrame(static_cast(otPlatRadioGetTransmitBuffer(aThreadNetif.GetInstance()))), mKeyIdMode2FrameCounter(0) { - for (size_t i = 0; i < sizeof(mExtAddress); i++) - { - mExtAddress.m8[i] = static_cast(otPlatRandomGet()); - } - - mExtAddress.SetGroup(false); - mExtAddress.SetLocal(true); + GenerateExtAddress(&mExtAddress); ClearNoiseFloorAverage(mNoiseFloor); @@ -434,6 +428,17 @@ void Mac::SetRxOnWhenIdle(bool aRxOnWhenIdle) } } +void Mac::GenerateExtAddress(ExtAddress *aExtAddress) +{ + for (size_t i = 0; i < sizeof(ExtAddress); i++) + { + aExtAddress->m8[i] = static_cast(otPlatRandomGet()); + } + + aExtAddress->SetGroup(false); + aExtAddress->SetLocal(true); +} + void Mac::SetExtAddress(const ExtAddress &aExtAddress) { uint8_t buf[sizeof(aExtAddress)]; diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index a3d29b6dc..c09c5f2ee 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -348,6 +348,14 @@ public: */ ThreadError SendFrameRequest(Sender &aSender); + /** + * This method generates a random IEEE 802.15.4 Extended Address. + * + * @param[out] aExtAddress A pointer to where the generated Extended Address is placed. + * + */ + void GenerateExtAddress(ExtAddress *aExtAddress); + /** * This method returns a pointer to the IEEE 802.15.4 Extended Address. * diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index a92efa337..d74ceca76 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -508,11 +508,7 @@ void Joiner::HandleTimer(void) case kStateJoined: Mac::ExtAddress extAddress; - for (size_t i = 0; i < sizeof(extAddress); i++) - { - extAddress.m8[i] = static_cast(otPlatRandomGet()); - } - + mNetif.GetMac().GenerateExtAddress(&extAddress); mNetif.GetMac().SetExtAddress(extAddress); mNetif.GetMle().UpdateLinkLocalAddress();