Add configure option for MAC whitelist and blacklist. (#997)

This commit is contained in:
Jonathan Hui
2016-11-21 19:03:51 +00:00
committed by GitHub
parent 7c8d784f5b
commit f37e413c7b
14 changed files with 623 additions and 296 deletions
+32
View File
@@ -563,6 +563,37 @@ AC_SUBST(OPENTHREAD_ENABLE_JAM_DETECTION)
AM_CONDITIONAL([OPENTHREAD_ENABLE_JAM_DETECTION], [test "${enable_jam_detection}" = "yes"])
AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_JAM_DETECTION],[${OPENTHREAD_ENABLE_JAM_DETECTION}],[Define to 1 if you want to use jam detection feature])
#
# MAC Whitelist and Blacklist
#
AC_ARG_ENABLE(mac_whitelist,
[AS_HELP_STRING([--enable-mac-whitelist],[Enable MAC whitelist/blacklist support @<:@default=yes@:>@.])],
[
case "${enableval}" in
no|yes)
enable_mac_whitelist=${enableval}
;;
*)
AC_MSG_ERROR([Invalid value ${enable_mac_whitelist} for --enable-mac-whitelist])
;;
esac
],
[enable_mac_whitelist=yes])
if test "$enable_mac_whitelist" = "yes"; then
OPENTHREAD_ENABLE_MAC_WHITELIST=1
else
OPENTHREAD_ENABLE_MAC_WHITELIST=0
fi
AC_MSG_RESULT(${enable_mac_whitelist})
AC_SUBST(OPENTHREAD_ENABLE_MAC_WHITELIST)
AM_CONDITIONAL([OPENTHREAD_ENABLE_MAC_WHITELIST], [test "${enable_mac_whitelist}" = "yes"])
AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_MAC_WHITELIST],[${OPENTHREAD_ENABLE_MAC_WHITELIST}],[Define to 1 if you want to use MAC whitelist/blacklist feature])
#
# Diagnostics Library
#
@@ -1031,6 +1062,7 @@ AC_MSG_NOTICE([
OpenThread Joiner support : ${enable_joiner}
OpenThread DTLS support : ${enable_dtls}
OpenThread Jam Detection support : ${enable_jam_detection}
OpenThread MAC Whitelist support : ${enable_mac_whitelist}
OpenThread Diagnostics support : ${enable_diag}
OpenThread Legacy network support : ${enable_legacy}
OpenThread Cli logging support : ${enable_cli_logging}
+4
View File
@@ -143,8 +143,12 @@
<ClInclude Include="..\..\src\core\crypto\sha256.hpp" />
<ClInclude Include="..\..\src\core\mac\mac.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist_impl.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist_stub.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_frame.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist_impl.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist_stub.hpp" />
<ClInclude Include="..\..\src\core\meshcop\announce_begin_client.hpp" />
<ClInclude Include="..\..\src\core\meshcop\commissioner.hpp" />
<ClInclude Include="..\..\src\core\meshcop\dataset.hpp" />
@@ -314,6 +314,12 @@
<ClInclude Include="..\..\src\core\mac\mac_whitelist.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_whitelist_impl.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_whitelist_stub.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\net\dhcp6.hpp">
<Filter>Header Files\net</Filter>
</ClInclude>
@@ -419,6 +425,12 @@
<ClInclude Include="..\..\src\core\mac\mac_blacklist.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_blacklist_impl.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_blacklist_stub.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\meshcop\announce_begin_client.hpp">
<Filter>Header Files\meshcop</Filter>
</ClInclude>
@@ -155,8 +155,12 @@
<ClInclude Include="..\..\src\core\crypto\sha256.hpp" />
<ClInclude Include="..\..\src\core\mac\mac.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist_impl.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_blacklist_stub.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_frame.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist_impl.hpp" />
<ClInclude Include="..\..\src\core\mac\mac_whitelist_stub.hpp" />
<ClInclude Include="..\..\src\core\meshcop\announce_begin_client.hpp" />
<ClInclude Include="..\..\src\core\meshcop\commissioner.hpp" />
<ClInclude Include="..\..\src\core\meshcop\dataset.hpp" />
@@ -308,6 +308,12 @@
<ClInclude Include="..\..\src\core\mac\mac_whitelist.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_whitelist_impl.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_whitelist_stub.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\net\dhcp6.hpp">
<Filter>Header Files\net</Filter>
</ClInclude>
@@ -410,6 +416,12 @@
<ClInclude Include="..\..\src\core\mac\mac_blacklist.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_blacklist_impl.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\mac\mac_blacklist_stub.hpp">
<Filter>Header Files\mac</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\meshcop\commissioner.hpp">
<Filter>Header Files\meshcop</Filter>
</ClInclude>
+3
View File
@@ -50,6 +50,9 @@
/* Define to 1 to enable DHCPv6 SERVER. */
#define OPENTHREAD_ENABLE_DHCP6_SERVER 0
/* Define to 1 to enable MAC whitelist/blacklist feature. */
#define OPENTHREAD_ENABLE_MAC_WHITELIST 1
/* Name of package */
#define PACKAGE "openthread"
+12 -3
View File
@@ -58,8 +58,6 @@ SOURCES_COMMON = \
crypto/sha256.cpp \
mac/mac.cpp \
mac/mac_frame.cpp \
mac/mac_whitelist.cpp \
mac/mac_blacklist.cpp \
meshcop/dataset.cpp \
meshcop/dataset_manager.cpp \
meshcop/tlvs.cpp \
@@ -89,6 +87,13 @@ SOURCES_COMMON = \
utils/slaac_address.cpp \
$(NULL)
if OPENTHREAD_ENABLE_MAC_WHITELIST
SOURCES_COMMON += \
mac/mac_blacklist.cpp \
mac/mac_whitelist.cpp \
$(NULL)
endif # OPENTHREAD_ENABLE_MAC_WHITELIST
if OPENTHREAD_ENABLE_COMMISSIONER
SOURCES_COMMON += \
coap/secure_coap_server.cpp \
@@ -180,9 +185,13 @@ noinst_HEADERS = \
crypto/mbedtls.hpp \
crypto/sha256.hpp \
mac/mac.hpp \
mac/mac_blacklist.hpp \
mac/mac_blacklist_impl.hpp \
mac/mac_blacklist_stub.hpp \
mac/mac_frame.hpp \
mac/mac_whitelist.hpp \
mac/mac_blacklist.hpp \
mac/mac_whitelist_impl.hpp \
mac/mac_whitelist_stub.hpp \
meshcop/announce_begin_client.hpp \
meshcop/commissioner.hpp \
meshcop/dataset.hpp \
+10 -132
View File
@@ -26,136 +26,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifdef OPENTHREAD_CONFIG_FILE
#include OPENTHREAD_CONFIG_FILE
#else
#include <openthread-config.h>
#endif
#ifndef MAC_BLACKLIST_HPP_
#define MAC_BLACKLIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
/**
* @addtogroup core-mac
*
* @{
*
*/
/**
* This class implements blacklist filtering on IEEE 802.15.4 frames.
*
*/
class Blacklist
{
public:
typedef otMacBlacklistEntry Entry;
enum
{
kMaxEntries = 32,
};
/**
* This constructor initializes the blacklist filter.
*
*/
Blacklist(void);
/**
* This method enables the blacklist filter.
*
*/
void Enable(void);
/**
* This method disables the blacklist filter.
*
*/
void Disable(void);
/**
* This method indicates whether or not the blacklist filter is enabled.
*
* @retval TRUE If the blacklist filter is enabled.
* @retval FALSE If the blacklist filter is disabled.
*
*/
bool IsEnabled(void) const;
/**
* This method returns the maximum number of blacklist entries.
*
* @returns The maximum number of blacklist entries.
*
*/
int GetMaxEntries(void) const;
/**
* This method gets a blacklist entry.
*
* @param[in] aIndex An index into the MAC blacklist table.
* @param[out] aEntry A reference to where the information is placed.
*
* @retval kThreadError_None Successfully retrieved the MAC blacklist entry.
* @retval kThreadError_InvalidArgs @p aIndex is out of bounds or @p aEntry is NULL.
*
*/
ThreadError GetEntry(uint8_t aIndex, Entry &aEntry) const;
/**
* This method adds an Extended Address to the blacklist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the blacklist entry or NULL if there are no available entries.
*
*/
Entry *Add(const ExtAddress &aAddress);
/**
* This method removes an Extended Address to the blacklist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
*/
void Remove(const ExtAddress &aAddress);
/**
* This method removes all entries from the blacklist filter.
*
*/
void Clear(void);
/**
* This method finds a blacklist entry.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the blacklist entry or NULL if the entry could not be found.
*
*/
Entry *Find(const ExtAddress &aAddress);
private:
Entry mBlacklist[kMaxEntries];
bool mEnabled;
};
/**
* @}
*
*/
} // namespace Mac
} // namespace Thread
#endif // MAC_BLACKLIST_HPP_
#if OPENTHREAD_ENABLE_MAC_WHITELIST
#include "mac_blacklist_impl.hpp"
#else
#include "mac_blacklist_stub.hpp"
#endif
+161
View File
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifndef MAC_BLACKLIST_HPP_
#define MAC_BLACKLIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
/**
* @addtogroup core-mac
*
* @{
*
*/
/**
* This class implements blacklist filtering on IEEE 802.15.4 frames.
*
*/
class Blacklist
{
public:
typedef otMacBlacklistEntry Entry;
enum
{
kMaxEntries = OPENTHREAD_CONFIG_MAC_BLACKLIST_SIZE,
};
/**
* This constructor initializes the blacklist filter.
*
*/
Blacklist(void);
/**
* This method enables the blacklist filter.
*
*/
void Enable(void);
/**
* This method disables the blacklist filter.
*
*/
void Disable(void);
/**
* This method indicates whether or not the blacklist filter is enabled.
*
* @retval TRUE If the blacklist filter is enabled.
* @retval FALSE If the blacklist filter is disabled.
*
*/
bool IsEnabled(void) const;
/**
* This method returns the maximum number of blacklist entries.
*
* @returns The maximum number of blacklist entries.
*
*/
int GetMaxEntries(void) const;
/**
* This method gets a blacklist entry.
*
* @param[in] aIndex An index into the MAC blacklist table.
* @param[out] aEntry A reference to where the information is placed.
*
* @retval kThreadError_None Successfully retrieved the MAC blacklist entry.
* @retval kThreadError_InvalidArgs @p aIndex is out of bounds or @p aEntry is NULL.
*
*/
ThreadError GetEntry(uint8_t aIndex, Entry &aEntry) const;
/**
* This method adds an Extended Address to the blacklist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the blacklist entry or NULL if there are no available entries.
*
*/
Entry *Add(const ExtAddress &aAddress);
/**
* This method removes an Extended Address to the blacklist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
*/
void Remove(const ExtAddress &aAddress);
/**
* This method removes all entries from the blacklist filter.
*
*/
void Clear(void);
/**
* This method finds a blacklist entry.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the blacklist entry or NULL if the entry could not be found.
*
*/
Entry *Find(const ExtAddress &aAddress);
private:
Entry mBlacklist[kMaxEntries];
bool mEnabled;
};
/**
* @}
*
*/
} // namespace Mac
} // namespace Thread
#endif // MAC_BLACKLIST_HPP_
+74
View File
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifndef MAC_BLACKLIST_HPP_
#define MAC_BLACKLIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
class Blacklist
{
public:
typedef otMacBlacklistEntry Entry;
Blacklist(void) { }
void Enable(void) { }
void Disable(void) { }
bool IsEnabled(void) const { return false; }
int GetMaxEntries(void) const { return 0; }
ThreadError GetEntry(uint8_t, Entry &) const { return kThreadError_NotImplemented; }
Entry *Add(const ExtAddress &) { return NULL; }
void Remove(const ExtAddress &) { }
void Clear(void) { }
Entry *Find(const ExtAddress &) { return NULL; }
};
} // namespace Mac
} // namespace Thread
#endif // MAC_BLACKLIST_HPP_
+10 -161
View File
@@ -26,165 +26,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifdef OPENTHREAD_CONFIG_FILE
#include OPENTHREAD_CONFIG_FILE
#else
#include <openthread-config.h>
#endif
#ifndef MAC_WHITELIST_HPP_
#define MAC_WHITELIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
/**
* @addtogroup core-mac
*
* @{
*
*/
/**
* This class implements whitelist filtering on IEEE 802.15.4 frames.
*
*/
class Whitelist
{
public:
typedef otMacWhitelistEntry Entry;
enum
{
kMaxEntries = 32,
};
/**
* This constructor initializes the whitelist filter.
*
*/
Whitelist(void);
/**
* This method enables the whitelist filter.
*
*/
void Enable(void);
/**
* This method disables the whitelist filter.
*
*/
void Disable(void);
/**
* This method indicates whether or not the whitelist filter is enabled.
*
* @retval TRUE If the whitelist filter is enabled.
* @retval FALSE If the whitelist filter is disabled.
*
*/
bool IsEnabled(void) const;
/**
* This method returns the maximum number of whitelist entries.
*
* @returns The maximum number of whitelist entries.
*
*/
int GetMaxEntries(void) const;
/**
* This method gets a whitelist entry.
*
* @param[in] aIndex An index into the MAC whitelist table.
* @param[out] aEntry A reference to where the information is placed.
*
* @retval kThreadError_None Successfully retrieved the MAC whitelist entry.
* @retval kThreadError_InvalidArgs @p aIndex is out of bounds or @p aEntry is NULL.
*
*/
ThreadError GetEntry(uint8_t aIndex, Entry &aEntry) const;
/**
* This method adds an Extended Address to the whitelist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the whitelist entry or NULL if there are no available entries.
*
*/
Entry *Add(const ExtAddress &aAddress);
/**
* This method removes an Extended Address to the whitelist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
*/
void Remove(const ExtAddress &aAddress);
/**
* This method removes all entries from the whitelist filter.
*
*/
void Clear(void);
/**
* This method finds a whitelist entry.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the whitelist entry or NULL if the entry could not be found.
*
*/
Entry *Find(const ExtAddress &aAddress);
/**
* This method clears the fixed RSSI value and uses the measured value provided by the radio instead.
*
* @param[in] aEntry A reference to the whitelist entry.
*
*/
void ClearFixedRssi(Entry &aEntry);
/**
* This method indicates whether or not the fixed RSSI is set.
*
* @param[in] aEntry A reference to the whitelist entry.
* @param[out] aRssi A reference to the RSSI variable.
*
* @retval kThreadError_None A fixed RSSI is set and written to @p aRssi.
* @retval kThreadError_InvalidArg A fixed RSSI was not set.
*
*/
ThreadError GetFixedRssi(Entry &aEntry, int8_t &aRssi) const;
/**
* This method sets a fixed RSSI value for all received messages matching @p aEntry.
*
* @param[in] aEntry A reference to the whitelist entry.
* @param[in] aRssi An RSSI value in dBm.
*
*/
void SetFixedRssi(Entry &aEntry, int8_t aRssi);
private:
Entry mWhitelist[kMaxEntries];
bool mEnabled;
};
/**
* @}
*
*/
} // namespace Mac
} // namespace Thread
#endif // MAC_WHITELIST_HPP_
#if OPENTHREAD_ENABLE_MAC_WHITELIST
#include "mac_whitelist_impl.hpp"
#else
#include "mac_whitelist_stub.hpp"
#endif
+190
View File
@@ -0,0 +1,190 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifndef MAC_WHITELIST_HPP_
#define MAC_WHITELIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
/**
* @addtogroup core-mac
*
* @{
*
*/
/**
* This class implements whitelist filtering on IEEE 802.15.4 frames.
*
*/
class Whitelist
{
public:
typedef otMacWhitelistEntry Entry;
enum
{
kMaxEntries = OPENTHREAD_CONFIG_MAC_WHITELIST_SIZE,
};
/**
* This constructor initializes the whitelist filter.
*
*/
Whitelist(void);
/**
* This method enables the whitelist filter.
*
*/
void Enable(void);
/**
* This method disables the whitelist filter.
*
*/
void Disable(void);
/**
* This method indicates whether or not the whitelist filter is enabled.
*
* @retval TRUE If the whitelist filter is enabled.
* @retval FALSE If the whitelist filter is disabled.
*
*/
bool IsEnabled(void) const;
/**
* This method returns the maximum number of whitelist entries.
*
* @returns The maximum number of whitelist entries.
*
*/
int GetMaxEntries(void) const;
/**
* This method gets a whitelist entry.
*
* @param[in] aIndex An index into the MAC whitelist table.
* @param[out] aEntry A reference to where the information is placed.
*
* @retval kThreadError_None Successfully retrieved the MAC whitelist entry.
* @retval kThreadError_InvalidArgs @p aIndex is out of bounds or @p aEntry is NULL.
*
*/
ThreadError GetEntry(uint8_t aIndex, Entry &aEntry) const;
/**
* This method adds an Extended Address to the whitelist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the whitelist entry or NULL if there are no available entries.
*
*/
Entry *Add(const ExtAddress &aAddress);
/**
* This method removes an Extended Address to the whitelist filter.
*
* @param[in] aAddress A reference to the Extended Address.
*
*/
void Remove(const ExtAddress &aAddress);
/**
* This method removes all entries from the whitelist filter.
*
*/
void Clear(void);
/**
* This method finds a whitelist entry.
*
* @param[in] aAddress A reference to the Extended Address.
*
* @returns A pointer to the whitelist entry or NULL if the entry could not be found.
*
*/
Entry *Find(const ExtAddress &aAddress);
/**
* This method clears the fixed RSSI value and uses the measured value provided by the radio instead.
*
* @param[in] aEntry A reference to the whitelist entry.
*
*/
void ClearFixedRssi(Entry &aEntry);
/**
* This method indicates whether or not the fixed RSSI is set.
*
* @param[in] aEntry A reference to the whitelist entry.
* @param[out] aRssi A reference to the RSSI variable.
*
* @retval kThreadError_None A fixed RSSI is set and written to @p aRssi.
* @retval kThreadError_InvalidArg A fixed RSSI was not set.
*
*/
ThreadError GetFixedRssi(Entry &aEntry, int8_t &aRssi) const;
/**
* This method sets a fixed RSSI value for all received messages matching @p aEntry.
*
* @param[in] aEntry A reference to the whitelist entry.
* @param[in] aRssi An RSSI value in dBm.
*
*/
void SetFixedRssi(Entry &aEntry, int8_t aRssi);
private:
Entry mWhitelist[kMaxEntries];
bool mEnabled;
};
/**
* @}
*
*/
} // namespace Mac
} // namespace Thread
#endif // MAC_WHITELIST_HPP_
+80
View File
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for IEEE 802.15.4 frame filtering based on MAC address.
*/
#ifndef MAC_WHITELIST_HPP_
#define MAC_WHITELIST_HPP_
#include <stdint.h>
#include <openthread-types.h>
#include <mac/mac_frame.hpp>
namespace Thread {
namespace Mac {
class Whitelist
{
public:
typedef otMacWhitelistEntry Entry;
Whitelist(void) { }
void Enable(void) { }
void Disable(void) { }
bool IsEnabled(void) const { return false; }
int GetMaxEntries(void) const { return 0; }
ThreadError GetEntry(uint8_t, Entry &) const { return kThreadError_NotImplemented; }
Entry *Add(const ExtAddress &) { return NULL; }
void Remove(const ExtAddress &) { }
void Clear(void) { }
Entry *Find(const ExtAddress &) { return NULL; }
void ClearFixedRssi(Entry &) { }
ThreadError GetFixedRssi(Entry &, int8_t &) const { return kThreadError_NotImplemented; }
void SetFixedRssi(Entry &, int8_t) { }
};
} // namespace Mac
} // namespace Thread
#endif // MAC_WHITELIST_HPP_
+19
View File
@@ -269,6 +269,25 @@
#define OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT 0
#endif // OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
/**
* @def OPENTHREAD_CONFIG_MAC_BLACKLIST_SIZE
*
* THe number if MAC blacklist entries.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_BLACKLIST_SIZE
#define OPENTHREAD_CONFIG_MAC_BLACKLIST_SIZE 32
#endif // OPENTHREAD_CONFIG_MAC_BLACKLIST_SIZE
/**
* @def OPENTHREAD_CONFIG_MAC_WHITELIST_SIZE
*
* THe number if MAC whitelist entries.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_WHITELIST_SIZE
#define OPENTHREAD_CONFIG_MAC_WHITELIST_SIZE 32
#endif // OPENTHREAD_CONFIG_MAC_WHITELIST_SIZE
/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL