[mac] add "Mac::ExtAddress::GenerateRandom()" to create random address (#3228)

This commit adds method `GenerateRandom()` to `Mac::ExtAddress` to
generate a random IEEE 802.15.4 Extended Address. This method
replaces the `Mac` class `GenerateExtAddress()` method.
This commit is contained in:
Abtin Keshavarzian
2018-10-30 12:23:32 -07:00
committed by Jonathan Hui
parent 014514442d
commit 13fb20ed26
5 changed files with 17 additions and 19 deletions
+1 -9
View File
@@ -197,7 +197,7 @@ Mac::Mac(Instance &aInstance)
, mCcaSampleCount(0)
, mEnabled(true)
{
GenerateExtAddress(&mExtAddress);
mExtAddress.GenerateRandom();
mCcaSuccessRateTracker.Reset();
memset(&mCounters, 0, sizeof(otMacCounters));
@@ -468,14 +468,6 @@ exit:
return;
}
void Mac::GenerateExtAddress(ExtAddress *aExtAddress)
{
Random::FillBuffer(aExtAddress->m8, sizeof(ExtAddress));
aExtAddress->SetGroup(false);
aExtAddress->SetLocal(true);
}
void Mac::SetExtAddress(const ExtAddress &aExtAddress)
{
otExtAddress address;
-8
View File
@@ -418,14 +418,6 @@ public:
*/
otError SendOutOfBandFrameRequest(otRadioFrame *aOobFrame);
/**
* 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 reference to the IEEE 802.15.4 Extended Address.
*
+8
View File
@@ -39,10 +39,18 @@
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/random.hpp"
namespace ot {
namespace Mac {
void ExtAddress::GenerateRandom(void)
{
Random::FillBuffer(m8, sizeof(ExtAddress));
SetGroup(false);
SetLocal(true);
}
bool ExtAddress::operator==(const ExtAddress &aOther) const
{
return memcmp(m8, aOther.m8, sizeof(ExtAddress)) == 0;
+7 -1
View File
@@ -95,6 +95,12 @@ public:
*/
typedef String<kInfoStringSize> InfoString;
/**
* This method generates a random IEEE 802.15.4 Extended Address.
*
*/
void GenerateRandom(void);
/**
* This method indicates whether or not the Group bit is set.
*
@@ -107,7 +113,7 @@ public:
/**
* This method sets the Group bit.
*
* @param[in] aLocal TRUE if group address, FALSE otherwise.
* @param[in] aGroup TRUE if group address, FALSE otherwise.
*
*/
void SetGroup(bool aGroup)
+1 -1
View File
@@ -582,7 +582,7 @@ void Joiner::HandleTimer(void)
case OT_JOINER_STATE_JOINED:
Mac::ExtAddress extAddress;
netif.GetMac().GenerateExtAddress(&extAddress);
extAddress.GenerateRandom();
netif.GetMac().SetExtAddress(extAddress);
netif.GetMle().UpdateLinkLocalAddress();