mirror of
https://github.com/espressif/openthread.git
synced 2026-09-13 20:50:05 +00:00
[mac filter] add rssfilter support and integrate whitelist/blacklist to AddressFilter (#1967)
* [mac filter] add rssfilter support and integrate whitelist/blacklist - provide RssIn filter function to fix the received signal strength for test purpose. - provide Address filter function which integrates whitelist and blacklist, save (~300B) RAM. - update cli and spinel-cli to reflect new otLinkFilterX() APIs. - keep whitelist/blacklist spinel properties the same as before while implemented with new otLinkFilterX() APIs. - THCI: add setOutBoundLinkQuality() API for DEV-1530 - THCI: update Allow/Block relative APIs - update some test scripts due to new OT_ERROR_ALEADY when adding duplicate address to whitelist * update for comments * add MAC_FIXED_RSS spinel property * rebase and apply new OutboundFrameBegin(aHeader) * update OpenThread.py
This commit is contained in:
+117
-121
@@ -355,73 +355,21 @@ class OpenThread(IThci):
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("setRouterSelectionJitter() Error: " + str(e))
|
||||
|
||||
def __enableWhiteList(self):
|
||||
"""enable white list filter
|
||||
def __setAddressfilterMode(self, mode):
|
||||
"""set address filter mode
|
||||
|
||||
Returns:
|
||||
True: successful to enable white list filter
|
||||
False: fail to enable white list filter
|
||||
True: successful to set address filter mode.
|
||||
False: fail to set address filter mode.
|
||||
"""
|
||||
print 'call enableWhiteList'
|
||||
print 'call setAddressFilterMode() ' + mode
|
||||
try:
|
||||
if self.__sendCommand('whitelist enable')[0] == 'Done':
|
||||
self.isWhiteListEnabled = True
|
||||
cmd = 'macfilter addr ' + mode
|
||||
if self.__sendCommand(cmd)[0] == 'Done':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("enableWhiteList() Error: " + str(e))
|
||||
|
||||
def __enableBlackList(self):
|
||||
"""enable black list filter
|
||||
|
||||
Returns:
|
||||
True: successful to enable black list filter
|
||||
False: fail to enable black list filter
|
||||
"""
|
||||
print 'call enableBlackList'
|
||||
try:
|
||||
if self.__sendCommand('blacklist enable')[0] == 'Done':
|
||||
self.isBlackListEnabled = True
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("enableBlackList() Error: " + str(e))
|
||||
|
||||
def __disableWhiteList(self):
|
||||
"""disable white list filter
|
||||
|
||||
Returns:
|
||||
True: successful to disable white list filter
|
||||
False: fail to disable white list filter
|
||||
"""
|
||||
print 'call disableWhiteList'
|
||||
try:
|
||||
if self.__sendCommand('whitelist disable')[0] == 'Done':
|
||||
self.isWhiteListEnabled = False
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("disableWhiteList() Error: " + str(e))
|
||||
|
||||
def __disableBlackList(self):
|
||||
"""disable black list filter
|
||||
|
||||
Returns:
|
||||
True: successful to disable black list filter
|
||||
False: fail to disable black list filter
|
||||
"""
|
||||
print 'call disableBlackList'
|
||||
try:
|
||||
if self.__sendCommand('blacklist disable')[0] == 'Done':
|
||||
self.isBlackListEnabled = False
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("disableBlackList() Error: " + str(e))
|
||||
ModuleHelper.WriteIntoDebugLogger("__setAddressFilterMode() Error: " + str(e))
|
||||
|
||||
def __startOpenThread(self):
|
||||
"""start OpenThread stack
|
||||
@@ -438,17 +386,16 @@ class OpenThread(IThci):
|
||||
else:
|
||||
self.hasActiveDatasetToCommit = False
|
||||
|
||||
# restore whitelist if rejoin after reset
|
||||
if self.isPowerDown and self.isWhiteListEnabled:
|
||||
self.__enableWhiteList()
|
||||
for addr in self._whiteList:
|
||||
self.addAllowMAC(addr)
|
||||
|
||||
# restore blacklist if rejoin after reset
|
||||
if self.isPowerDown and self.isBlackListEnabled:
|
||||
self.__enableBlackList()
|
||||
for addr in self._blackList:
|
||||
self.addBlockedMAC(addr)
|
||||
# restore whitelist/blacklist address filter mode if rejoin after reset
|
||||
if self.isPowerDown:
|
||||
if self._addressfilterMode == 'whitelist':
|
||||
if self.__setAddressfilterMode('whitelist'):
|
||||
for addr in self._addressfilterSet:
|
||||
self.addAllowMAC(addr)
|
||||
elif self._addressfilterMode == 'blacklist':
|
||||
if self.__setAddressfilterMode('blacklist'):
|
||||
for addr in self._addressfilterSet:
|
||||
self.addBlockedMAC(addr)
|
||||
|
||||
if self.__sendCommand('ifconfig up')[0] == 'Done':
|
||||
self.__setRouterSelectionJitter(1)
|
||||
@@ -882,14 +829,14 @@ class OpenThread(IThci):
|
||||
return self.networkKey
|
||||
|
||||
def addBlockedMAC(self, xEUI):
|
||||
"""add a given extended address to the black list entry
|
||||
"""add a given extended address to the blacklist entry
|
||||
|
||||
Args:
|
||||
xEUI: extended address in hex format
|
||||
|
||||
Returns:
|
||||
True: successful to add a given extended address to the black list entry
|
||||
False: fail to add a given extended address to the black list entry
|
||||
True: successful to add a given extended address to the blacklist entry
|
||||
False: fail to add a given extended address to the blacklist entry
|
||||
"""
|
||||
print '%s call addBlockedMAC' % self.port
|
||||
print xEUI
|
||||
@@ -904,25 +851,32 @@ class OpenThread(IThci):
|
||||
print 'block device itself'
|
||||
return True
|
||||
|
||||
if not self.isBlackListEnabled:
|
||||
self.__enableBlackList()
|
||||
if self._addressfilterMode != 'blacklist':
|
||||
if self.__setAddressfilterMode('blacklist'):
|
||||
self._addressfilterMode = 'blacklist'
|
||||
|
||||
cmd = 'blacklist add %s' % macAddr
|
||||
cmd = 'macfilter addr add %s' % macAddr
|
||||
print cmd
|
||||
self._blackList.add(macAddr)
|
||||
return self.__sendCommand(cmd)[0] == 'Done'
|
||||
ret = self.__sendCommand(cmd)[0] == 'Done'
|
||||
|
||||
self._addressfilterSet.add(macAddr)
|
||||
print 'current blacklist entries:'
|
||||
for addr in self._addressfilterSet:
|
||||
print addr
|
||||
|
||||
return ret
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("addBlockedMAC() Error: " + str(e))
|
||||
|
||||
def addAllowMAC(self, xEUI):
|
||||
"""add a given extended address to the white list entry
|
||||
"""add a given extended address to the whitelist addressfilter
|
||||
|
||||
Args:
|
||||
xEUI: a given extended address in hex format
|
||||
|
||||
Returns:
|
||||
True: successful to add a given extended address to the white list entry
|
||||
False: fail to add a given extended address to the white list entry
|
||||
True: successful to add a given extended address to the whitelist entry
|
||||
False: fail to add a given extended address to the whitelist entry
|
||||
"""
|
||||
print '%s call addAllowMAC' % self.port
|
||||
print xEUI
|
||||
@@ -932,54 +886,75 @@ class OpenThread(IThci):
|
||||
macAddr = self.__convertLongToString(xEUI)
|
||||
|
||||
try:
|
||||
if not self.isWhiteListEnabled:
|
||||
self.__enableWhiteList()
|
||||
if self._addressfilterMode != 'whitelist':
|
||||
if self.__setAddressfilterMode('whitelist'):
|
||||
self._addressfilterMode = 'whitelist'
|
||||
|
||||
cmd = 'whitelist add %s' % macAddr
|
||||
cmd = 'macfilter addr add %s' % macAddr
|
||||
print cmd
|
||||
self._whiteList.add(macAddr)
|
||||
return self.__sendCommand(cmd)[0] == 'Done'
|
||||
ret = self.__sendCommand(cmd)[0] == 'Done'
|
||||
|
||||
self._addressfilterSet.add(macAddr)
|
||||
print 'current whitelist entries:'
|
||||
for addr in self._addressfilterSet:
|
||||
print addr
|
||||
return ret
|
||||
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("addAllowMAC() Error: " + str(e))
|
||||
|
||||
def clearBlockList(self):
|
||||
"""clear all entries in black list table
|
||||
"""clear all entries in blacklist table
|
||||
|
||||
Returns:
|
||||
True: successful to clear the black list
|
||||
False: fail to clear the black list
|
||||
True: successful to clear the blacklist
|
||||
False: fail to clear the blacklist
|
||||
"""
|
||||
print '%s call clearBlockList' % self.port
|
||||
|
||||
# remove all entries in black list
|
||||
# remove all entries in blacklist
|
||||
try:
|
||||
if self.__sendCommand('blacklist clear')[0] == 'Done':
|
||||
self.__disableBlackList()
|
||||
self._blackList.clear()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
print 'clearing blacklist entries:'
|
||||
for addr in self._addressfilterSet:
|
||||
print addr
|
||||
|
||||
|
||||
# disable blacklist
|
||||
if self.__setAddressfilterMode('disable'):
|
||||
self._addressfilterMode = 'disable'
|
||||
# clear ops
|
||||
cmd = 'macfilter addr clear'
|
||||
if self.__sendCommand(cmd)[0] == 'Done':
|
||||
self._addressfilterSet.clear()
|
||||
return True
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("clearBlockList() Error: " + str(e))
|
||||
|
||||
def clearAllowList(self):
|
||||
"""clear all entries in white list table
|
||||
"""clear all entries in whitelist table
|
||||
|
||||
Returns:
|
||||
True: successful to clear the white list
|
||||
False: fail to clear the white list
|
||||
True: successful to clear the whitelist
|
||||
False: fail to clear the whitelist
|
||||
"""
|
||||
print '%s call clearAllowList' % self.port
|
||||
|
||||
# remove all entries in white list as well as in black list
|
||||
# remove all entries in whitelist
|
||||
try:
|
||||
if self.__sendCommand('whitelist clear')[0] == 'Done':
|
||||
self.__disableWhiteList()
|
||||
self._whiteList.clear()
|
||||
self.clearBlockList()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
print 'clearing whitelist entries:'
|
||||
for addr in self._addressfilterSet:
|
||||
print addr
|
||||
|
||||
# disable whitelist
|
||||
if self.__setAddressfilterMode('disable'):
|
||||
self._addressfilterMode = 'disable'
|
||||
# clear ops
|
||||
cmd = 'macfilter addr clear'
|
||||
if self.__sendCommand(cmd)[0] == 'Done':
|
||||
self._addressfilterSet.clear()
|
||||
return True
|
||||
return False
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("clearAllowList() Error: " + str(e))
|
||||
|
||||
@@ -1273,10 +1248,8 @@ class OpenThread(IThci):
|
||||
self.joinCommissionedStatus = self.joinStatus['notstart']
|
||||
self.networkDataRequirement = '' # indicate Thread device requests full or stable network data
|
||||
self.isPowerDown = False # indicate if Thread device experiences a power down event
|
||||
self.isWhiteListEnabled = False # indicate if Thread device enables white list filter
|
||||
self.isBlackListEnabled = False # indicate if Thread device enables black list filter
|
||||
self._whiteList = set() # cache whitelist devices when white list filter is enabled
|
||||
self._blackList = set() # cache blacklist devices when black list filter is enabled
|
||||
self._addressfilterMode = 'disable' # indicate AddressFilter mode ['disable', 'whitelist', 'blacklist']
|
||||
self._addressfilterSet = set() # cache filter entries
|
||||
self.isActiveCommissioner = False # indicate if Thread device is an active commissioner
|
||||
self._lines = None # buffered lines read from device
|
||||
|
||||
@@ -1326,11 +1299,11 @@ class OpenThread(IThci):
|
||||
ModuleHelper.WriteIntoDebugLogger("setPollingRate() Error: " + str(e))
|
||||
|
||||
def setLinkQuality(self, EUIadr, LinkQuality):
|
||||
"""set custom link quality on a link to Thread device with a given extended address
|
||||
"""set custom LinkQualityIn for all receiving messages from the specified EUIadr
|
||||
|
||||
Args:
|
||||
EUIadr: a given extended address
|
||||
LinkQuality: a given custom link quality for child devices
|
||||
LinkQuality: a given custom link quality
|
||||
link quality/link margin mapping table
|
||||
3: 21 - 255 (dB)
|
||||
2: 11 - 20 (dB)
|
||||
@@ -1338,8 +1311,8 @@ class OpenThread(IThci):
|
||||
0: 0 - 2 (dB)
|
||||
|
||||
Returns:
|
||||
True: successful to set the link quality on a link to a Thread device
|
||||
False: fail to set the link quality on a link to a Thread device
|
||||
True: successful to set the link quality
|
||||
False: fail to set the link quality
|
||||
"""
|
||||
print '%s call setLinkQuality' % self.port
|
||||
print EUIadr
|
||||
@@ -1352,18 +1325,41 @@ class OpenThread(IThci):
|
||||
address64 = ''
|
||||
if '0x' in euiStr:
|
||||
address64 = euiStr.lstrip('0x')
|
||||
|
||||
# prepend 0 at the beginning
|
||||
if len(address64) < 16:
|
||||
address64 = address64.zfill(16)
|
||||
print address64
|
||||
address64 = address64.zfill(16)
|
||||
print address64
|
||||
|
||||
cmd = 'linkquality %s %s' % (address64, str(LinkQuality))
|
||||
cmd = 'macfilter rss add-lqi %s %s' % (address64, str(LinkQuality))
|
||||
print cmd
|
||||
return self.__sendCommand(cmd)[0] == 'Done'
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("setLinkQuality() Error: " + str(e))
|
||||
|
||||
def setOutBoundLinkQuality(self, LinkQuality):
|
||||
"""set custom LinkQualityIn for all receiving messages from the any address
|
||||
|
||||
Args:
|
||||
LinkQuality: a given custom link quality
|
||||
link quality/link margin mapping table
|
||||
3: 21 - 255 (dB)
|
||||
2: 11 - 20 (dB)
|
||||
1: 3 - 9 (dB)
|
||||
0: 0 - 2 (dB)
|
||||
|
||||
Returns:
|
||||
True: successful to set the link quality
|
||||
False: fail to set the link quality
|
||||
"""
|
||||
print '%s call setOutBoundLinkQuality' % self.port
|
||||
print LinkQuality
|
||||
try:
|
||||
cmd = 'macfilter rss add-lqi * %s' % str(LinkQuality)
|
||||
print cmd
|
||||
return self.__sendCommand(cmd)[0] == 'Done'
|
||||
except Exception, e:
|
||||
ModuleHelper.WriteIntoDebugLogger("setOutBoundLinkQuality() Error: " + str(e))
|
||||
|
||||
def removeRouterPrefix(self, prefixEntry):
|
||||
"""remove the configured prefix on a border router
|
||||
|
||||
|
||||
Reference in New Issue
Block a user