def snr_threshold_interval_reached(server, id=0, sta_ip=None, sta_port=0, intf_name=None, interval=10): """ set the time between SNR scans in the station. @param server: tuple (ip, port_num) @param id: message id @param interval: interval in miliseconds @type interval: int """ if interval <= 0: interval = -1 # disable msg_struct = Container( m_type=MSG_TYPE.MSG_SET_SNR_INTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, intf_name_size=len_of_string(intf_name), intf_name=intf_name, interval=interval, ) send_and_receive_msg(server, msg_struct, msg_snr_threshold_reached.build, msg_snr_threshold_reached.parse, only_send=True)
def changed_ap(server, id=0, status=0, current_ap=None, intf_name=None): """ verify is the interface is broadcasting the SSID @param server: tuple (ip, port_num) @param id: message id @param intf_name: names of the wireless interface @type intf_name: list of str @param status: inform the status of the operation (result from change ap operation) @type status: int @param current_ap: MAC address of the ap @type current_ap: str """ if (intf_name is None) or (current_ap is None): return # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_CHANGED_AP, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, current_ap_size=len_of_string(current_ap), current_ap=current_ap, status=status, ) error, msg = send_and_receive_msg(server, msg_struct, msg_changed_ap.build, msg_changed_ap.parse, only_send=True)
def set_ap_guardinterval(server, id=0, intf_name=None, guard_interval=100): """ set the guard interval of the interface intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param guard_interval: time used as guard interval between transmissions @type guard_interval: int """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_AP_GUARDINTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, guard_interval=guard_interval, ) send_and_receive_msg(server, msg_struct, msg_ap_guardinterval.build, msg_ap_guardinterval.parse, only_send=True)
def set_ap_rtsthreshold(server, id=0, intf_name=None, rts_threshold=0): """ enable or disable the broadcasting of the SSID @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_AP_RTSTHRESHOLD, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, rts_threshold=rts_threshold, ) send_and_receive_msg(server, msg_struct, msg_ap_rtsthreshold.build, msg_ap_rtsthreshold.parse, only_send=True)
def get_ap_rtsthreshold(server, id=0, intf_name=None): """ verify is the interface is broadcasting the SSID @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return: msg, value """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_AP_RTSTHRESHOLD, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, rts_threshold=0, ) error, msg = send_and_receive_msg(server, msg_struct, msg_ap_rtsthreshold.build, msg_ap_rtsthreshold.parse) if not error: value = msg['enabled'] if 'enabled' in msg else None else: value = None return msg, value
def set_hostapd_conf(server, id=0, intf_name=None, conf_param=None, conf_value=None): """ set the beacon interval (in ms) default = 100ms different brands and models offer different allowable beacon interval ranges @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str """ # create message container msg_struct = Container( m_type=MSG_TYPE.MSG_SET_HOSTAPD_CONF, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, param_name_size=len_of_string(conf_param), param_name=conf_param, param_name_value_size=len_of_string(conf_value), param_value_name=conf_value, ) send_and_receive_msg(server, msg_struct, msg_hostapd_conf.build, msg_hostapd_conf.parse, only_send=True)
def set_snr_threshold(server, id=0, sta_ip=None, sta_port=0, intf_name=None, threshold=10): """ set the SNR threshold in dBm. Send message to a station. @param server: tuple (ip, port_num) @param id: message id @param threshold: SNR threshold in dBm """ msg_struct = Container( m_type=MSG_TYPE.MSG_SET_SNR_THRESHOLD, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, intf_name_size=len_of_string(intf_name), intf_name=intf_name, threshold=threshold, ) send_and_receive_msg(server, msg_struct, msg_snr_threshold.build, msg_snr_threshold.parse, only_send=True)
def set_ap_frameburstenabled(server, id=0, intf_name=None, enabled=False): """ @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param enabled: enables or disables frame burst @type enabled: bool """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_AP_FRAMEBURSTENABLED, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, enabled=enabled, ) error, msg = send_and_receive_msg(server, msg_struct, msg_ap_frameburstenabled.build, msg_ap_frameburstenabled.parse, only_send=True)
def get_association(server, id=0, association_type=None, mac_sta=None, mac_ap=None): """ only for tests. the controller don't use this!!! """ if (association_type is None) or (mac_sta is None) or (mac_ap is None): return None msg_struct = Container( m_type=association_type, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, mac_ap_size=len_of_string(mac_ap), mac_ap=mac_ap, mac_sta_size=len_of_string(mac_sta), mac_sta=mac_sta, allowed=True, response=0, ) error, msg = send_and_receive_msg(server, msg_struct, msg_association.build, msg_association.parse) if not error and 'allowed' in msg and 'response' in msg: allowed = tri_boolean('allowed', msg) response = msg['response'] else: allowed = True response = 0 return msg, allowed, response
def send_msg_mean_sta_statistics(server, id=0, sta_ip=None, sta_port=0): """ @param server: tuple (ip, port_num) @param id: message id @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @return: msg - received message """ # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_GET, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, num=0, intf=[], mean_net_statistics=[], ) error, msg = send_and_receive_msg(server, msg_struct, msg_mean_statistics.build, msg_mean_statistics.parse) value = {} if not error: for i in range(msg['num']): intf = msg['intf'][i] stats = msg['mean_net_statistics'][i] value[intf] = stats return msg, value
def get_ctsprotection_enabled(server, id=0, intf_name=None): """ Verify if RTS/CTS mechanism is activated @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface. @type intf_name: str @return msg: received message @return value: """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_AP_BROADCASTSSID, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, enabled=False, ) error, msg = send_and_receive_msg(server, msg_struct, msg_ctsprotection_enabled.build, msg_ctsprotection_enabled.parse) if not error: value = tri_boolean('enabled', msg) else: value = False return msg, value
def send_msg_mean_sta_statistics_alpha(server, id=0, sta_ip=None, sta_port=0, alpha=0.1): """ @param server: tuple (ip, port_num) @param id: message id @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @param alpha: alpha from EWMA @type alpha: float @return: msg - received message """ if not (isinstance(alpha, float) or isinstance(alpha, int)): return msg_struct = Container( m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_SET_ALPHA, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, alpha=alpha, ) send_and_receive_msg(server, msg_struct, msg_mean_sta_statistics_alpha.build, msg_mean_sta_statistics_alpha.parse, only_send=True)
def send_msg_mean_sta_statistics_time(server, id=0, sta_ip=None, sta_port=0, msec=100): """ @param server: tuple (ip, port_num) @param id: message id @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @param msec: statistics are collected during "msec" interval @type msec: int @return: msg - received message """ if not isinstance(msec, int): return msg_struct = Container( m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_SET_TIME, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, msec=msec, ) send_and_receive_msg(server, msg_struct, msg_mean_sta_statistics_time.build, msg_mean_sta_statistics_time.parse, only_send=True)
def get_beacon_interval(server, id=0, intf_name=None): """ get beacon interval in miliseconds for the interface intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return: -1 if an error occurs """ if intf_name is None: return None, ERROR # 1) create message msg_struct = Container(m_type=MSG_TYPE.MSG_GET_BEACON_INTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, beacon_interval=0) error, msg = send_and_receive_msg(server, msg_struct, msg_beacon_interval.build, msg_beacon_interval.parse) if not error: value = msg['beacon_interval'] if 'beacon_interval' in msg else [] else: value = [] return msg, value
def get_preamble(server, id=0, intf_name=None): """ gets if the configured preamble is long or short @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return: msg - received message """ # 1) create message if intf_name is None: return msg_struct = Container(m_type=MSG_TYPE.MSG_GET_PREAMBLE, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, preamble=0) error, msg = send_and_receive_msg(server, msg_struct, msg_preamble.build, msg_preamble.parse) if not error: value = msg['preamble'] if 'preamble' in msg else -1 else: value = -1 return msg, value
def get_powersave_mode(server, id=0, intf_name=None, sta_ip=None, sta_port=0): """ get if the powersave is set or not @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @return: msg - received message """ # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_POWERSAVEMODE, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, value=0, ) error, msg = send_and_receive_msg(server, msg_struct, msg_powersave.build, msg_powersave.parse) if not error: value = True if ('value' in msg) and (msg['value'] == 1) else False else: value = False return msg, value
def set_ap_dtiminterval(server, id=0, intf_name=None, dtim_interval=100): """ set the DTIM interval of the interface intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param dtim_interval: DTIM interval @type dtim_interval: int @note: https://routerguide.net/dtim-interval-period-best-setting/ """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_AP_DTIMINTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, dtim_interval=dtim_interval, ) send_and_receive_msg(server, msg_struct, msg_ap_dtiminterval.build, msg_ap_dtiminterval.parse, only_send=True)
def set_beacon_interval(server, id=0, intf_name=None, beacon_interval=100): """ set the beacon interval (in ms) default = 100ms different brands and models offer different allowable beacon interval ranges @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param beacon_interval: @type beacon_interval: int """ # create message container msg_struct = Container( m_type=MSG_TYPE.MSG_SET_BEACON_INTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, beacon_interval=beacon_interval, ) send_and_receive_msg(server, msg_struct, msg_beacon_interval.build, msg_beacon_interval.parse, only_send=True)
def get_hostapd_conf(server, id=0, intf_name=None, conf_param=None): """ get beacon interval in miliseconds for the interface intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return: -1 if an error occurs """ if intf_name is None or conf_param is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_HOSTAPD_CONF, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, param_name_size=len_of_string(conf_param), param_name=conf_param, param_name_value_size=0, param_value_name=None, ) error, msg = send_and_receive_msg(server, msg_struct, msg_hostapd_conf.build, msg_hostapd_conf.parse) if not error: value = msg['param_value_name'] if 'param_value_name' in msg else None else: value = None return msg, value
def set_broadcastssid(server, id=0, intf_name=None, enable=False, ssid=None): """ enable or disable the broadcasting of the SSID @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param enable: set if the SSID should be broadcasted or if it is a hidden SSID @param enable: bool """ if intf_name is None or ssid is None: return None, None # 1) create message msg_struct = Container(m_type=MSG_TYPE.MSG_SET_AP_BROADCASTSSID, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, ssid_size=len_of_string(ssid), ssid=ssid, enabled=enable, ) send_and_receive_msg(server, msg_struct, msg_ap_broadcastssid.build, msg_ap_broadcastssid.parse, only_send=True)
def get_broadcastssid(server, id=0, intf_name=None, ssid=None): """ verify is the interface is broadcasting the SSID @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return msg: received message @return value: """ if intf_name is None or ssid is None: return None, None # 1) create message msg_struct = Container(m_type=MSG_TYPE.MSG_GET_AP_BROADCASTSSID, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, ssid_size=len_of_string(ssid), ssid=ssid, enabled=False, ) error, msg = send_and_receive_msg(server, msg_struct, msg_ap_broadcastssid.build, msg_ap_broadcastssid.parse) if not error: value = tri_boolean('enabled', msg) else: value = None return msg, value
def set_preamble(server, id=0, intf_name=None, preamble=0): """ set the preamble used in some interface 0 = preamble LONG | 1 = preamble SHORT @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param preamble: @type sta_ip: bool @return: msg - received message """ if intf_name is None: return if preamble != 1: preamble = 0 # default equals LONG # create message container msg_struct = Container(m_type=MSG_TYPE.MSG_SET_PREAMBLE, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, preamble=preamble) send_and_receive_msg(server, msg_struct, msg_preamble.build, msg_preamble.parse, only_send=True)
def set_ctsprotection_enabled(server, id=0, intf_name=None, enable=False): """ enable or disable RTS/CTS mechanism @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface. @type intf_name: str @param enable: true activates RTS/CTS mechanism @param enable: bool @return msg: received message @return value: """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_AP_BROADCASTSSID, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, enabled=enable, ) send_and_receive_msg(server, msg_struct, msg_ctsprotection_enabled.build, msg_ctsprotection_enabled.parse, only_send=True)
def set_powersave_mode(server, id=0, powersave=True, intf_name=None, sta_ip=None, sta_port=0): """ @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int """ if intf_name is None: return """ set the powersave mode """ # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_SET_POWERSAVEMODE, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, value=powersave, ) send_and_receive_msg(server, msg_struct, msg_powersave.build, msg_powersave.parse, only_send=True)
def get_ap_dtiminterval(server, id=0, intf_name=None): """ get the DTIM interval set in the interface intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @return msg: received message @return value: """ if intf_name is None: return None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_AP_DTIMINTERVAL, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, dtim_interval=-1, ) error, msg = send_and_receive_msg(server, msg_struct, msg_ap_dtiminterval.build, msg_ap_dtiminterval.parse) if not error: value = msg['dtim_interval'] if 'dtim_interval' in msg else None else: value = None return msg, value
def station_trigger_transition(server, id=0, sta_ip=None, sta_port=0, sta_mac=None, intf_name=None, mac_new_ap=None): """ sendo command to station to change to a new ap @param server: tuple (ip, port_num) @param id: message id """ msg_struct = Container(m_type=MSG_TYPE.MSG_TRIGGER_TRANSITION, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, mac_addr_size=len_of_string(sta_mac), mac_addr=sta_mac, intf_name_size=len_of_string(intf_name), intf_name=intf_name, mac_new_ap_size=len_of_string(mac_new_ap), mac_new_ap=mac_new_ap, ) error, msg = send_and_receive_msg(server, msg_struct, msg_station_trigger_transition.build, msg_station_trigger_transition.parse, only_send=True)
def get_channelinfo(server, id=0, intf_name=None, channel=0, only_channel_in_use=False): """ get the channels the interface inff_name supports, this function applies to access points @param server: tuple (ip, port_num) @param id: message id @param intf_name: names of the wireless interface @type intf_name: list of str @param channel: specify a channel to scan @type channel: int @param only_channel_in_use: return only the channel in use @type only_channel_in_use: bool @return: msg - received message a list """ if intf_name is None: raise ValueError("intf_name must have a valid value!") # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_CHANNELINFO, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, channel=channel, num_freqs=0, # don´t know how many bands are in the AP channel_info=[], # field will be filled by the AP ) error, msg = send_and_receive_msg(server, msg_struct, msg_channelinfo.build, msg_channelinfo.parse) # print msg if error: return msg, [] value = msg['channel_info'] if 'channel_info' in msg else [] if (value != []) and only_channel_in_use: for i in range(len(value)): if value[i]['in_use'] == 1: d = dict(value[i]) if '__recursion_lock__' in d: del d['__recursion_lock__'] value = [d] break for c in value: v = tri_boolean('in_use', c) c['in_use'] = v """ returns the value, note: {} equals an error has occured or no band found """ return msg, value
def get_acs(server, id=0, intf_name=None, sta_ip=None, sta_port=0, num_tests=1): """ request the ap to provide ACS information @param server: tuple (ip, port_num) @param id: message id @param intf_name: name of the wireless interface @type intf_name: str @param sta_ip: ip address of a station to which this message should be relayed. If None don't relay message, server should process the request @param sta_port: socket port of the station @param num_tests: number of tests (greater than or equal to 1) that should be executed @param num_tests: int @return msg: received message @return num_chan: number of channels scanned by the device @return acs: list of acs factor for each channels """ if intf_name is None: return None, 0, [] if num_tests < 1: num_tests = 1 # at least one test # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_ACS, m_id=id, p_version_length=len(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, num_tests=num_tests, num_chan=0, # don´t know how many channels yet freq=[], # field will be filled by the AP factor=[], # field will be filled by the AP ) error, msg = send_and_receive_msg(server, msg_struct, msg_acs.build, msg_acs.parse) acs = {} if not error: num_chan = msg['num_chan'] if 'num_chan' in msg else 0 for i in range(len(msg['freq'])): freq = msg['freq'][i] factor = msg['factor'][i] / ACS_SCALE_FACTOR acs[freq] = factor else: num_chan = 0 return msg, num_chan, acs
def __get_enabled(server, id=0, intf_name=None, sta_ip=None, sta_port=0, m_type=None): """ internal function: provides suporte to get_interfaces and get_one_intf @param server: tuple (ip, port_num) @param id: message id @param intf_name: names of the wireless interface @type intf_name: list of str @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @param m_type: message type @type m_type: int @return: msg - received message """ if intf_name is None or m_type in [ MSG_TYPE.MSG_GET_802_11E_ENABLED, MSG_TYPE.MSG_GET_FASTBSSTRANSITION_COMPATIBLE ]: return None, None """ returns the value None equals an error has occured (or no interface found) """ value = None # 1) create message msg_struct = Container( m_type=m_type, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, value=False, ) error, msg = send_and_receive_msg(server, msg_struct, msg_enabled.build, msg_enabled.parse) if not error: value = tri_boolean('value', msg) else: value = [] return msg, value
def get_sta_link_info(server, id=0, sta_ip=None, sta_port=0, intf_name=None): """ returns three values: mac_addr, ssid, frequency None equals an error has occured (or no interface found) @todo: Nao eh necessario retornar intf_name @param server: tuple (ip, port_num) @param id: message id @param intf_name: names of the wireless interface @type intf_name: list of str @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None @type sta_ip: str @param sta_port: socket port number of the station @type sta_port: int @return: msg - received message """ if intf_name is None: return None, None, None, None, None # 1) create message msg_struct = Container( m_type=MSG_TYPE.MSG_GET_LINK_INFO, m_id=id, p_version_length=len_of_string(VERSION), p_version=VERSION, m_size=0, intf_name_size=len_of_string(intf_name), intf_name=intf_name, ssid=None, ssid_size=0, mac_addr=None, mac_addr_size=0, sta_ip_size=len_of_string(sta_ip), sta_ip=sta_ip, sta_port=sta_port, frequency=0, ) error, msg = send_and_receive_msg(server, msg_struct, msg_sta_link_info.build, msg_sta_link_info.parse) if not error: mac_addr = msg['mac_addr'] if 'mac_addr' in msg else None ssid = msg['ssid'] if 'ssid' in msg else None freq = msg['frequency'] if 'frequency' in msg else -1 intf_name = msg['intf_name'] if 'intf_name' in msg else None else: mac_addr = None ssid = None freq = -1 intf_name = None return msg, mac_addr, ssid, freq, intf_name