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.
This commit is contained in:
Shu Chen
2017-05-03 18:55:48 -07:00
committed by Jonathan Hui
parent bd6e072647
commit bc3f5c8852
3 changed files with 21 additions and 12 deletions
+12 -7
View File
@@ -154,13 +154,7 @@ Mac::Mac(ThreadNetif &aThreadNetif):
mTxFrame(static_cast<Frame *>(otPlatRadioGetTransmitBuffer(aThreadNetif.GetInstance()))),
mKeyIdMode2FrameCounter(0)
{
for (size_t i = 0; i < sizeof(mExtAddress); i++)
{
mExtAddress.m8[i] = static_cast<uint8_t>(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<uint8_t>(otPlatRandomGet());
}
aExtAddress->SetGroup(false);
aExtAddress->SetLocal(true);
}
void Mac::SetExtAddress(const ExtAddress &aExtAddress)
{
uint8_t buf[sizeof(aExtAddress)];
+8
View File
@@ -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.
*
+1 -5
View File
@@ -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<uint8_t>(otPlatRandomGet());
}
mNetif.GetMac().GenerateExtAddress(&extAddress);
mNetif.GetMac().SetExtAddress(extAddress);
mNetif.GetMle().UpdateLinkLocalAddress();