def serialize(self): # Convert bssid to byte string for transmit bssid_tmp = self['bssid'] self['bssid'] = util.str_to_mac_addr(self['bssid']) self['bssid'] = util.mac_addr_to_byte_str(self['bssid']) ret_val = super(BSSConfig, self).serialize() # Revert bssid to colon delimited string self['bssid'] = bssid_tmp return ret_val
def __init__(self, mac_address, name=None, ht_capable=False): self.name = name self.ht_capable = ht_capable if mac_address is not None: if type(mac_address) in [int, long]: self.wlan_mac_address = mac_address elif type(mac_address) is str: try: import wlan_exp.util as util self.wlan_mac_address = util.str_to_mac_addr(mac_address) except TypeError: raise TypeError("MAC address is not valid") else: raise TypeError("MAC address is not valid") else: raise TypeError("MAC address is not valid") self.description = self.__repr__()
def configure_bss(self, bssid=False, ssid=None, channel=None, beacon_interval=False, ht_capable=None): """Configure the BSS information of the node Each node is either a member of no BSS (colloquially "unassociated") or a member of one BSS. A node requires a minimum valid set of BSS information to be a member of a BSS. The minimum valid set of BSS information for an AP is: #. BSSID: 48-bit MAC address #. Channel: Logical channel for Tx/Rx by BSS members #. SSID: Variable length string (ie the name of the network) #. Beacon Interval: Interval (in TUs) for beacons If a node is not a member of a BSS (i.e. ``n.get_bss_info()`` returns ``None``), then the node requires all parameters of a minimum valid set of BSS information be specified (i.e. Channel, SSID, and Beacon Interval). For an AP, if BSSID is not specified, then it is assumed to be the wlan_mac_address of the node. See https://warpproject.org/trac/wiki/802.11/wlan_exp/bss for more documentation on BSS information / configuration. Args: bssid (int, str): 48-bit ID of the BSS either None or the wlan_mac_address of the node. If not specified, it is by default the wlan_mac_address of the node. ssid (str): SSID string (Must be 32 characters or less) channel (int): Channel number on which the BSS operates beacon_interval (int): Integer number of beacon Time Units in [10, 65534] (http://en.wikipedia.org/wiki/TU_(Time_Unit); a TU is 1024 microseconds); A value of None will disable beacons; A value of False will not update the current beacon interval. ht_capable (bool): Is the PHY mode HTMF (True) or NONHT (False)? """ if bssid is not None: if bssid is not False: # User supplied a not-None BSSID argument error = False if type(bssid) in [int, long]: if (bssid != self.wlan_mac_address): error = True elif type(bssid) is str: import wlan_exp.util as util try: if (util.str_to_mac_addr(bssid) != self.wlan_mac_address): error = True except: error = True if (error): raise AttributeError("BSSID must be either None or the wlan_mac_address of the node.") else: # User did not provide a BSSID argument - use the AP's MAC address bssid = self.wlan_mac_address resp_args = self.send_cmd(cmds.NodeConfigBSS(bssid=bssid, ssid=ssid, channel=channel, beacon_interval=beacon_interval, ht_capable=ht_capable)) # Process response arguments if (resp_args is not False): status = resp_args[0] msg = "ERROR: Invalid response from node:\n" ret_val = True # Check status if (status & cmds.ERROR_CONFIG_BSS_BSSID_INVALID): if type(self.bssid) in [int, long]: import wlan_exp.util as util self.bssid = util.mac_addr_to_str(self.bssid) msg += " BSSID {0} was invalid.\n".format(self.bssid) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_BSSID_INSUFFICIENT_ARGUMENTS): msg += " Insufficient arguments to create BSS. Must provide:\n" if (bssid is False): msg += " BSSID\n" if (ssid is None): msg += " SSID\n" if (channel is None): msg += " CHANNEL\n" if (beacon_interval is False): msg += " BEACON_INTERVAL\n" ret_val = False if (status & cmds.ERROR_CONFIG_BSS_CHANNEL_INVALID): msg += " Channel {0} was invalid.\n".format(self.channel) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_BEACON_INTERVAL_INVALID): msg += " Beacon interval {0} was invalid.\n".format(self.beacon_interval) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_HT_CAPABLE_INVALID): msg += " HT capable {0} was invalid.\n".format(self.ht_capable) ret_val = False if not ret_val: print(msg)
def set_authentication_address_filter(self, allow): """Command to set the authentication address filter on the node. This command will reset the current address filter and then set the address filter to the values in the allow list. The filter only affects over-the-air associations. Assocaitions created by wlan_exp will bypass any filters configured by this method. Clients will be allowed to associate if they pass any of the filters that are set. Args: allow (list of tuple): List of (address, mask) tuples that will be used to filter addresses on the node. A tuple can be substituted with a predefined string: "NONE", "ALL", or "MANGO-W3" For the mask, bits that are 0 are treated as "any" and bits that are 1 are treated as "must equal". For the address, locations of one bits in the mask must match the incoming addresses to pass the filter. Examples: * Only allow client with MAC address ``01:23:45:67:89:AB``: >>> n_ap.set_authentication_address_filter(allow=(0x0123456789AB, 0xFFFFFFFFFFFF)) * Only allow clients with MAC addresses starting with ``01:23:45``: >>> n_ap.set_authentication_address_filter(allow=(0x012345000000, 0xFFFFFF000000)) * Allow clients with MAC addresses starting with ``01:23:45`` or ``40:`` >>> n_ap.set_authentication_address_filter(allow=[(0x012345000000, 0xFFFFFF000000), (0x400000000000, 0xFF0000000000)]) * Use one of the pre-defined address filter configurations: >>> n_ap.set_authentication_address_filter(allow='NONE') # Same as allow=(0x000000000000, 0xFFFFFFFFFFFF) >>> n_ap.set_authentication_address_filter(allow='ALL') # Same as allow=(0x000000000000, 0x000000000000) >>> n_ap.set_authentication_address_filter(allow='MANGO-W3') # Same as allow=(0x40d855042000, 0xFFFFFFFFF000) """ filters = [] if (type(allow) is not list): allow = [allow] for value in allow: # Process pre-defined strings if type(value) is str: if (value == 'NONE'): filters.append((0x000000000000, 0xFFFFFFFFFFFF)) elif (value == 'ALL'): filters.append((0x000000000000, 0x000000000000)) elif (value == 'MANGO-W3'): filters.append((0x40d855042000, 0xFFFFFFFFF000)) else: msg = "\n String '{0}' not recognized.".format(value) msg += "\n Please use 'NONE', 'ALL', 'MANGO-W3' or a (address, mask) tuple" raise AttributeError(msg) elif type(value) is tuple: import wlan_exp.util as util # Process address if type(value[0]) in [int, long]: address = value[0] elif type(value[0]) is str: try: address = util.str_to_mac_addr(value[0]) except: raise AttributeError("Address {0} is not valid".format(value[0])) else: raise AttributeError("Address type {0} is not valid".format(type(value[0]))) # Process mask if type(value[1]) in [int, long]: mask = value[1] elif type(value[1]) is str: try: mask = util.str_to_mac_addr(value[1]) except: raise AttributeError("Mask {0} is not valid".format(value[1])) else: raise AttributeError("Mask type {0} is not valid".format(type(value[1]))) filters.append((address, mask)) else: msg = "\n Value {0} with type {1} not recognized.".format(value, type(value)) msg += "\n Please use 'NONE', 'ALL', 'MANGO-W3' or a (address, mask) tuple" raise AttributeError(msg) self.send_cmd(cmds.NodeAPSetAuthAddrFilter(filters))
def configure_bss(self, bssid=False, ssid=None, channel=None, beacon_interval=False, ht_capable=None): """Configure the BSS information of the node Each node is either a member of no BSS (colloquially "unassociated") or a member of one BSS. A node requires a minimum valid set of BSS information to be a member of a BSS. The minimum valid set of BSS information for an AP is: #. BSSID: 48-bit MAC address #. Channel: Logical channel for Tx/Rx by BSS members #. SSID: Variable length string (ie the name of the network) #. Beacon Interval: Interval (in TUs) for beacons If a node is not a member of a BSS (i.e. ``n.get_bss_info()`` returns ``None``), then the node requires all parameters of a minimum valid set of BSS information be specified (i.e. Channel, SSID, and Beacon Interval). For an AP, if BSSID is not specified, then it is assumed to be the wlan_mac_address of the node. See https://warpproject.org/trac/wiki/802.11/wlan_exp/bss for more documentation on BSS information / configuration. Args: bssid (int, str): 48-bit ID of the BSS either None or the wlan_mac_address of the node. If not specified, it is by default the wlan_mac_address of the node. ssid (str): SSID string (Must be 32 characters or less) channel (int): Channel number on which the BSS operates beacon_interval (int): Integer number of beacon Time Units in [10, 65534] (http://en.wikipedia.org/wiki/TU_(Time_Unit); a TU is 1024 microseconds); A value of None will disable beacons; A value of False will not update the current beacon interval. ht_capable (bool): Is the PHY mode HTMF (True) or NONHT (False)? """ if bssid is not None: if bssid is not False: # User supplied a not-None BSSID argument error = False if type(bssid) in [int, long]: if (bssid != self.wlan_mac_address): error = True elif type(bssid) is str: import wlan_exp.util as util try: if (util.str_to_mac_addr(bssid) != self.wlan_mac_address): error = True except: error = True if (error): raise AttributeError( "BSSID must be either None or the wlan_mac_address of the node." ) else: # User did not provide a BSSID argument - use the AP's MAC address bssid = self.wlan_mac_address resp_args = self.send_cmd( cmds.NodeConfigBSS(bssid=bssid, ssid=ssid, channel=channel, beacon_interval=beacon_interval, ht_capable=ht_capable)) # Process response arguments if (resp_args is not False): status = resp_args[0] msg = "ERROR: Invalid response from node:\n" ret_val = True # Check status if (status & cmds.ERROR_CONFIG_BSS_BSSID_INVALID): if type(self.bssid) in [int, long]: import wlan_exp.util as util self.bssid = util.mac_addr_to_str(self.bssid) msg += " BSSID {0} was invalid.\n".format(self.bssid) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_BSSID_INSUFFICIENT_ARGUMENTS): msg += " Insufficient arguments to create BSS. Must provide:\n" if (bssid is False): msg += " BSSID\n" if (ssid is None): msg += " SSID\n" if (channel is None): msg += " CHANNEL\n" if (beacon_interval is False): msg += " BEACON_INTERVAL\n" ret_val = False if (status & cmds.ERROR_CONFIG_BSS_CHANNEL_INVALID): msg += " Channel {0} was invalid.\n".format(self.channel) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_BEACON_INTERVAL_INVALID): msg += " Beacon interval {0} was invalid.\n".format( self.beacon_interval) ret_val = False if (status & cmds.ERROR_CONFIG_BSS_HT_CAPABLE_INVALID): msg += " HT capable {0} was invalid.\n".format( self.ht_capable) ret_val = False if not ret_val: print(msg)
def set_authentication_address_filter(self, allow): """Command to set the authentication address filter on the node. This command will reset the current address filter and then set the address filter to the values in the allow list. The filter only affects over-the-air associations. Assocaitions created by wlan_exp will bypass any filters configured by this method. Clients will be allowed to associate if they pass any of the filters that are set. Args: allow (list of tuple): List of (address, mask) tuples that will be used to filter addresses on the node. A tuple can be substituted with a predefined string: "NONE", "ALL", or "MANGO-W3" For the mask, bits that are 0 are treated as "any" and bits that are 1 are treated as "must equal". For the address, locations of one bits in the mask must match the incoming addresses to pass the filter. Examples: * Only allow client with MAC address ``01:23:45:67:89:AB``: >>> n_ap.set_authentication_address_filter(allow=(0x0123456789AB, 0xFFFFFFFFFFFF)) * Only allow clients with MAC addresses starting with ``01:23:45``: >>> n_ap.set_authentication_address_filter(allow=(0x012345000000, 0xFFFFFF000000)) * Allow clients with MAC addresses starting with ``01:23:45`` or ``40:`` >>> n_ap.set_authentication_address_filter(allow=[(0x012345000000, 0xFFFFFF000000), (0x400000000000, 0xFF0000000000)]) * Use one of the pre-defined address filter configurations: >>> n_ap.set_authentication_address_filter(allow='NONE') # Same as allow=(0x000000000000, 0xFFFFFFFFFFFF) >>> n_ap.set_authentication_address_filter(allow='ALL') # Same as allow=(0x000000000000, 0x000000000000) >>> n_ap.set_authentication_address_filter(allow='MANGO-W3') # Same as allow=(0x40d855042000, 0xFFFFFFFFF000) """ filters = [] if (type(allow) is not list): allow = [allow] for value in allow: # Process pre-defined strings if type(value) is str: if (value == 'NONE'): filters.append((0x000000000000, 0xFFFFFFFFFFFF)) elif (value == 'ALL'): filters.append((0x000000000000, 0x000000000000)) elif (value == 'MANGO-W3'): filters.append((0x40d855042000, 0xFFFFFFFFF000)) else: msg = "\n String '{0}' not recognized.".format(value) msg += "\n Please use 'NONE', 'ALL', 'MANGO-W3' or a (address, mask) tuple" raise AttributeError(msg) elif type(value) is tuple: import wlan_exp.util as util # Process address if type(value[0]) in [int, long]: address = value[0] elif type(value[0]) is str: try: address = util.str_to_mac_addr(value[0]) except: raise AttributeError("Address {0} is not valid".format( value[0])) else: raise AttributeError( "Address type {0} is not valid".format(type(value[0]))) # Process mask if type(value[1]) in [int, long]: mask = value[1] elif type(value[1]) is str: try: mask = util.str_to_mac_addr(value[1]) except: raise AttributeError("Mask {0} is not valid".format( value[1])) else: raise AttributeError("Mask type {0} is not valid".format( type(value[1]))) filters.append((address, mask)) else: msg = "\n Value {0} with type {1} not recognized.".format( value, type(value)) msg += "\n Please use 'NONE', 'ALL', 'MANGO-W3' or a (address, mask) tuple" raise AttributeError(msg) self.send_cmd(cmds.NodeAPSetAuthAddrFilter(filters))