[mle] update discover scan filtering

This commit makes improvements to MLE Discover Scan implementation,
mainly the steering data filtering logic:
- The SHA-256 of EUI64 (Joiner ID) and then the related bloom filter
  CRC-CCIT and CRC-ANSI indexes are calculated and saved at start of
  scan operation (removing the need to re-calculate them on every scan
  result).
- When filtering is enabled, a Discover Scan result with no Steering
  Data is now rejected.
- `Mle` class member variables related to discover scan operation
  are renamed to start with `mDisocver` prefix.
This commit is contained in:
Abtin Keshavarzian
2019-04-04 09:14:30 -07:00
committed by Jonathan Hui
parent c02a985609
commit 873a710a1a
2 changed files with 45 additions and 39 deletions
+38 -34
View File
@@ -92,8 +92,10 @@ Mle::Mle(Instance &aInstance)
, mTimeout(kMleEndDeviceTimeout)
, mDiscoverHandler(NULL)
, mDiscoverContext(NULL)
, mIsDiscoverInProgress(false)
, mEnableEui64Filtering(false)
, mDiscoverCcittIndex(0)
, mDiscoverAnsiIndex(0)
, mDiscoverInProgress(false)
, mDiscoverEnableFiltering(false)
#if OPENTHREAD_CONFIG_INFORM_PREVIOUS_PARENT_ON_REATTACH
, mPreviousParentRloc(Mac::kShortAddrInvalid)
#endif
@@ -483,7 +485,7 @@ exit:
otError Mle::Discover(const Mac::ChannelMask &aScanChannels,
uint16_t aPanId,
bool aJoiner,
bool aEnableEui64Filtering,
bool aEnableFiltering,
DiscoverHandler aCallback,
void * aContext)
{
@@ -494,9 +496,29 @@ otError Mle::Discover(const Mac::ChannelMask &aScanChannels,
MeshCoP::DiscoveryRequestTlv discoveryRequest;
uint16_t startOffset;
VerifyOrExit(!mIsDiscoverInProgress, error = OT_ERROR_BUSY);
VerifyOrExit(!mDiscoverInProgress, error = OT_ERROR_BUSY);
mEnableEui64Filtering = aEnableEui64Filtering;
mDiscoverEnableFiltering = aEnableFiltering;
if (mDiscoverEnableFiltering)
{
Mac::ExtAddress extAddress;
Crc16 ccitt(Crc16::kCcitt);
Crc16 ansi(Crc16::kAnsi);
otPlatRadioGetIeeeEui64(&GetInstance(), extAddress.m8);
MeshCoP::ComputeJoinerId(extAddress, extAddress);
// Compute bloom filter (for steering data)
for (size_t i = 0; i < sizeof(extAddress.m8); i++)
{
ccitt.Update(extAddress.m8[i]);
ansi.Update(extAddress.m8[i]);
}
mDiscoverCcittIndex = ccitt.Get();
mDiscoverAnsiIndex = ansi.Get();
}
mDiscoverHandler = aCallback;
mDiscoverContext = aContext;
@@ -527,7 +549,7 @@ otError Mle::Discover(const Mac::ChannelMask &aScanChannels,
destination.mFields.m16[7] = HostSwap16(0x0002);
SuccessOrExit(error = SendMessage(*message, destination));
mIsDiscoverInProgress = true;
mDiscoverInProgress = true;
LogMleMessage("Send Discovery Request", destination);
@@ -543,8 +565,8 @@ exit:
void Mle::HandleDiscoverComplete(void)
{
mIsDiscoverInProgress = false;
mEnableEui64Filtering = false;
mDiscoverInProgress = false;
mDiscoverEnableFiltering = false;
mDiscoverHandler(NULL, mDiscoverContext);
}
@@ -3633,10 +3655,11 @@ otError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Message
otActiveScanResult result;
uint16_t offset;
uint16_t end;
bool didCheckSteeringData = false;
LogMleMessage("Receive Discovery Response", aMessageInfo.GetPeerAddr());
VerifyOrExit(mIsDiscoverInProgress, error = OT_ERROR_DROP);
VerifyOrExit(mDiscoverInProgress, error = OT_ERROR_DROP);
// find MLE Discovery TLV
VerifyOrExit(Tlv::GetOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
@@ -3683,33 +3706,13 @@ otError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Message
aMessage.Read(offset, sizeof(steeringData), &steeringData);
VerifyOrExit(steeringData.IsValid(), error = OT_ERROR_PARSE);
// Pass up MLE discovery responses only if the steering data is set to all 0xFFs,
// or if it matches the factory set EUI64.
if (mEnableEui64Filtering)
if (mDiscoverEnableFiltering)
{
Mac::ExtAddress extaddr;
Crc16 ccitt(Crc16::kCcitt);
Crc16 ansi(Crc16::kAnsi);
otPlatRadioGetIeeeEui64(&GetInstance(), extaddr.m8);
MeshCoP::ComputeJoinerId(extaddr, extaddr);
// Compute bloom filter
for (size_t i = 0; i < sizeof(extaddr.m8); i++)
{
ccitt.Update(extaddr.m8[i]);
ansi.Update(extaddr.m8[i]);
}
// Drop responses that don't match the bloom filter
if (!steeringData.GetBit(ccitt.Get() % steeringData.GetNumBits()) ||
!steeringData.GetBit(ansi.Get() % steeringData.GetNumBits()))
{
ExitNow(error = OT_ERROR_NONE);
}
VerifyOrExit((steeringData.GetBit(mDiscoverCcittIndex % steeringData.GetNumBits()) &&
steeringData.GetBit(mDiscoverAnsiIndex % steeringData.GetNumBits())));
}
didCheckSteeringData = true;
result.mSteeringData.mLength = steeringData.GetLength();
memcpy(result.mSteeringData.m8, steeringData.GetValue(), result.mSteeringData.mLength);
@@ -3728,7 +3731,8 @@ otError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Message
offset += sizeof(meshcopTlv) + meshcopTlv.GetLength();
}
// signal callback
VerifyOrExit(!mDiscoverEnableFiltering || didCheckSteeringData);
mDiscoverHandler(&result, mDiscoverContext);
exit:
+7 -5
View File
@@ -545,7 +545,7 @@ public:
* @param[in] aScanChannels A bit vector indicating which channels to scan.
* @param[in] aPanId The PAN ID filter (set to Broadcast PAN to disable filter).
* @param[in] aJoiner Value of the Joiner Flag in the Discovery Request TLV.
* @param[in] aEnableEui64Filtering Enable filtering out MLE discovery responses that don't match our factory
* @param[in] aEnableFiltering Enable filtering out MLE discovery responses that don't match our factory
* assigned EUI64.
* @param[in] aHandler A pointer to a function that is called on receiving an MLE Discovery Response.
* @param[in] aContext A pointer to arbitrary context information.
@@ -557,7 +557,7 @@ public:
otError Discover(const Mac::ChannelMask &aScanChannels,
uint16_t aPanId,
bool aJoiner,
bool aEnableEui64Filtering,
bool aEnableFiltering,
DiscoverHandler aCallback,
void * aContext);
@@ -567,7 +567,7 @@ public:
* @returns true if an MLE Thread Discovery is in progress, false otherwise.
*
*/
bool IsDiscoverInProgress(void) const { return mIsDiscoverInProgress; }
bool IsDiscoverInProgress(void) const { return mDiscoverInProgress; }
/**
* This method is called by the MeshForwarder to indicate that discovery is complete.
@@ -1767,8 +1767,10 @@ private:
DiscoverHandler mDiscoverHandler;
void * mDiscoverContext;
bool mIsDiscoverInProgress;
bool mEnableEui64Filtering;
uint16_t mDiscoverCcittIndex;
uint16_t mDiscoverAnsiIndex;
bool mDiscoverInProgress;
bool mDiscoverEnableFiltering;
#if OPENTHREAD_CONFIG_INFORM_PREVIOUS_PARENT_ON_REATTACH
uint16_t mPreviousParentRloc;