From 55785040c968323713e1a85e9164cf62e0386503 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 11 Jun 2020 22:21:19 -0700 Subject: [PATCH] [discover-scanner] allow filtering based on a user given bloom filter indexes (#5075) This commit enhances the filtering behavior of Discover Scan. When filtering is enabled, MLE Discovery Responses with steering data (bloom filter) not containing a set of bloom filter indexes are filtered. This commit updates the `DiscoverScanner::Discover()` to allow filter indexes used for filtering to be optionally specified by the caller. It can be set to NULL (for default behavior) where the hash of factory-assigned EUI64 of the device would be used to derive the bloom filter indexes --- src/core/api/thread_api.cpp | 5 ++-- src/core/meshcop/joiner.cpp | 1 + src/core/thread/discover_scanner.cpp | 17 ++++++++++---- src/core/thread/discover_scanner.hpp | 34 ++++++++++++++++++++-------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 471864b86..649a3e96e 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -457,8 +457,9 @@ otError otThreadDiscover(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - return instance.Get().Discover(static_cast(aScanChannels), aPanId, aJoiner, - aEnableEui64Filtering, aCallback, aCallbackContext); + return instance.Get().Discover( + static_cast(aScanChannels), aPanId, aJoiner, aEnableEui64Filtering, + /* aFilterIndexes (use hash of factory EUI64) */ NULL, aCallback, aCallbackContext); } bool otThreadIsDiscoverInProgress(otInstance *aInstance) diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 7c587dd0a..0d2e41202 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -124,6 +124,7 @@ otError Joiner::Start(const char * aPskd, SuccessOrExit(error = Get().Discover(Mac::ChannelMask(0), Get().GetPanId(), /* aJoiner */ true, /* aEnableFiltering */ true, + /* aFilterIndexes (use hash of factory EUI64) */ NULL, HandleDiscoverResult, this)); mCallback = aCallback; mContext = aContext; diff --git a/src/core/thread/discover_scanner.cpp b/src/core/thread/discover_scanner.cpp index a5e91056f..827f9d8a1 100644 --- a/src/core/thread/discover_scanner.cpp +++ b/src/core/thread/discover_scanner.cpp @@ -62,6 +62,7 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, uint16_t aPanId, bool aJoiner, bool aEnableFiltering, + const FilterIndexes * aFilterIndexes, Handler aCallback, void * aContext) { @@ -76,12 +77,18 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, if (mEnableFiltering) { - Mac::ExtAddress extAddress; + if (aFilterIndexes == NULL) + { + Mac::ExtAddress extAddress; - Get().GetIeeeEui64(extAddress); - MeshCoP::ComputeJoinerId(extAddress, extAddress); - - MeshCoP::SteeringData::CalculateHashBitIndexes(extAddress, mFilterIndexes); + Get().GetIeeeEui64(extAddress); + MeshCoP::ComputeJoinerId(extAddress, extAddress); + MeshCoP::SteeringData::CalculateHashBitIndexes(extAddress, mFilterIndexes); + } + else + { + mFilterIndexes = *aFilterIndexes; + } } mHandler = aCallback; diff --git a/src/core/thread/discover_scanner.hpp b/src/core/thread/discover_scanner.hpp index ca14a1b64..0a578e9da 100644 --- a/src/core/thread/discover_scanner.hpp +++ b/src/core/thread/discover_scanner.hpp @@ -82,6 +82,16 @@ public: */ typedef otHandleActiveScanResult Handler; + /** + * This type represents the filter indexes, i.e., hash bit index values for the bloom filter (calculated from a + * Joiner ID). + * + * This is used when filtering is enabled during Discover Scan, i.e., received MLE Discovery Responses with steering + * data (bloom filter) not containing the given indexes are filtered. + * + */ + typedef MeshCoP::SteeringData::HashBitIndexes FilterIndexes; + /** * This constructor initializes the object. * @@ -96,7 +106,10 @@ public: * @param[in] aScanChannels Channel mask listing channels to scan (if empty, use all supported channels). * @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] aEnableFiltering Enable filtering MLE Discovery Responses that don't match our factory EUI64. + * @param[in] aEnableFiltering Enable filtering MLE Discovery Responses with steering data not containing a + * given filter indexes. + * @param[in] aFilterIndexes A pointer to `FilterIndexes` to use for filtering (when enabled). + * If set to NULL, filter indexes are derived from hash of 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. * @@ -109,6 +122,7 @@ public: Mac::PanId aPanId, bool aJoiner, bool aEnableFiltering, + const FilterIndexes * aFilterIndexes, Handler aHandler, void * aContext); @@ -140,15 +154,15 @@ private: static void HandleTimer(Timer &aTimer); void HandleTimer(void); - Handler mHandler; - void * mHandlerContext; - TimerMilli mTimer; - MeshCoP::SteeringData::HashBitIndexes mFilterIndexes; - Mac::ChannelMask mScanChannels; - State mState; - uint8_t mScanChannel; - bool mEnableFiltering : 1; - bool mShouldRestorePanId : 1; + Handler mHandler; + void * mHandlerContext; + TimerMilli mTimer; + FilterIndexes mFilterIndexes; + Mac::ChannelMask mScanChannels; + State mState; + uint8_t mScanChannel; + bool mEnableFiltering : 1; + bool mShouldRestorePanId : 1; }; } // namespace Mle