def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" change = False # enabled, ssid, freq, mode, ieee80211n if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config["ieee80211n"]: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # bitrate & txpower if config['bitrate'] != self.current_config['bitrate']: self.set_wireless_advanced(config["bitrate"]) change = True for prop in [ 'txpower', 'txpower_auto' ]: if config[prop] != self.current_config[prop]: self.current_config['status'] = "FAIL" self.current_config['errmsg'] = "WRT310N does not support TX power control" # wmm if config['wmm'] != self.current_config['wmm']: self.set_wmm(config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config
def gen_accesspoint_msg(iface): msg = AccessPoint() msg.essid = iface.essid msg.macaddr = iface.bssid msg.signal = iface.wifi_signal msg.noise = iface.wifi_noise msg.snr = msg.signal - msg.noise msg.quality = iface.wifi_quality msg.rate = iface.wifi_rate msg.tx_power = iface.wifi_txpower msg.channel = IEEE80211_Channels.get_channel(iface.wifi_frequency * 1e6) return msg
def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" change = False # enabled, ssid, freq, mode, ieee80211n if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config["ieee80211n"]: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # bitrate & txpower if config['txpower'] != self.current_config['txpower'] or \ config['bitrate'] != self.current_config['bitrate']: # find closest available tx power min_abs_diff = abs(config['txpower'] - self.avail_txpower_list[0][0]) for i in range(0, len(self.avail_txpower_list)): avail_power_dbm = self.avail_txpower_list[i][0] if abs(config['txpower'] - avail_power_dbm) <= min_abs_diff: min_abs_diff = abs(config['txpower'] - avail_power_dbm) closest_power_idx = i config['txpower'] = self.avail_txpower_list[closest_power_idx][0] self.set_wireless_advanced(config["bitrate"], self.avail_txpower_list[closest_power_idx][1]) change = True # wmm if config['wmm'] != self.current_config['wmm']: self.set_wmm(config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config
def generate_conf(self): # create hostapd.conf f = open(self.conffile, 'w') channel = IEEE80211_Channels.get_channel(self.config['freq']) if channel < 0: raise ValueError(-1, "Frequency not a valid IEEE 802.11 channel") if (self.config['mode'] == 'a' and \ IEEE80211_Channels.get_band_from_freq(self.config['freq']) != IEEE80211_Channels.BAND_5000_MHz) or \ ((self.config['mode'] == 'b' or self.config['mode'] =='g') and \ IEEE80211_Channels.get_band_from_freq(self.config['freq']) != IEEE80211_Channels.BAND_2400_MHz): raise ValueError("Requested frequency is not valid for 802.11" + self.config['mode'] + " mode") f.write(""" driver=nl80211 logger_syslog=-1 logger_syslog_level=2 logger_stdout=-1 logger_stdout_level=0 ctrl_interface=/var/run/hostapd ignore_broadcast_ssid=0 own_ip_addr=127.0.0.1 country_code=""" + self.config['country_code'] + """ interface=""" + self.interface + """ ssid=""" + self.config['ssid'] + """ hw_mode=""" + self.config['mode'] + """ channel=""" + str(channel) + """ ieee80211n=""" + str(int(self.config['ieee80211n'])) + """ dump_file=""" + self.dumpfile) if self.config['encryption_mode'] == ApControlConfig.ApControl_open: f.write(""" auth_algs=1""") elif self.config['encryption_mode'] == ApControlConfig.ApControl_wep: f.write(""" auth_algs=1 wep_default_key=0 wep_key0=""" + self.config['encryption_pass']) elif self.config['encryption_mode'] in \ [ ApControlConfig.ApControl_wpa, ApControlConfig.ApControl_wpa2, ApControlConfig.ApControl_wpa_wpa2]: wpa_flag = self.get_wpa_flag() f.write(""" auth_algs=3 wpa=""" + str(wpa_flag) + """ wpa_passphrase=""" + self.config['encryption_pass'] + """ wpa_pairwise=CCMP TKIP""") if self.config['wmm']: f.write(""" wmm_enabled=1 wmm_ac_bk_cwmax=10 wmm_ac_bk_aifs=7 wmm_ac_bk_txop_limit=0 wmm_ac_bk_acm=0 wmm_ac_be_aifs=3 wmm_ac_be_txop_limit=0 wmm_ac_be_acm=0 wmm_ac_vi_aifs=2 wmm_ac_vi_acm=0 wmm_ac_vo_aifs=2 wmm_ac_vo_acm=0 """) if self.config['mode'] != "b": f.write(""" wmm_ac_bk_cwmin=4 wmm_ac_be_cwmin=4 wmm_ac_be_cwmax=10 wmm_ac_vi_cwmin=3 wmm_ac_vi_cwmax=4 wmm_ac_vi_txop_limit=94 wmm_ac_vo_cwmin=2 wmm_ac_vo_cwmax=3 wmm_ac_vo_txop_limit=47 """) else: f.write(""" wmm_ac_bk_cwmin=5 wmm_ac_be_cwmin=5 wmm_ac_be_cwmax=7 wmm_ac_vi_cwmin=4 wmm_ac_vi_cwmax=5 wmm_ac_vi_txop_limit=188 wmm_ac_vo_cwmin=3 wmm_ac_vo_cwmax=4 wmm_ac_vo_txop_limit=102 """) f.write("\n") f.close()
def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" change = False # enabled, ssid, freq, mode, ieee80211n if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config["ieee80211n"]: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # bitrate & txpower if config['txpower'] != self.current_config['txpower'] or \ config['bitrate'] != self.current_config['bitrate']: # find closest available tx power min_abs_diff = abs(config['txpower'] - self.avail_txpower_list[0][0]) for i in range(0, len(self.avail_txpower_list)): avail_power_dbm = self.avail_txpower_list[i][0] if abs(config['txpower'] - avail_power_dbm) <= min_abs_diff: min_abs_diff = abs(config['txpower'] - avail_power_dbm) closest_power_idx = i config['txpower'] = self.avail_txpower_list[closest_power_idx][ 0] self.set_wireless_advanced( config["bitrate"], self.avail_txpower_list[closest_power_idx][1]) change = True # wmm if config['wmm'] != self.current_config['wmm']: self.set_wmm(config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config
def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" change = False # enabled, ssid, freq, mode, ieee80211n if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config["ieee80211n"]: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # bitrate & txpower if config['bitrate'] != self.current_config['bitrate']: self.set_wireless_advanced(config["bitrate"]) change = True for prop in ['txpower', 'txpower_auto']: if config[prop] != self.current_config[prop]: self.current_config['status'] = "FAIL" self.current_config[ 'errmsg'] = "WRT310N does not support TX power control" # wmm if config['wmm'] != self.current_config['wmm']: self.set_wmm(config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config
def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" if config['enabled'] and \ ((config['mode'] == "a" and self.band != IEEE80211_Channels.BAND_5000_MHz) or \ ((config['mode'] == "b" or config['mode'] == "g") and self.band != IEEE80211_Channels.BAND_2400_MHz)): config['enabled'] = False self.current_config['status'] = "FAIL" self.current_config[ 'errmsg'] = "Cannot set 802.11%s mode for interface in %s" % ( config['mode'], self.band) change = False # enabled if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: # bitrate, txpower, wmm if config['txpower'] != self.current_config['txpower'] or \ config['bitrate'] != self.current_config['bitrate'] or \ config['wmm'] != self.current_config['wmm']: new_txpower_mw = self.dbm_to_mw(config['txpower']) if new_txpower_mw > self.max_txpower_mw: config['txpower'] = self.mw_to_dbm(self.max_txpower_mw) if new_txpower_mw < self.min_txpower_mw: config['txpower'] = self.mw_to_dbm(self.min_txpower_mw) self.set_wireless_advanced(config['bitrate'], self.dbm_to_mw(config['txpower']), config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and \ config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # ssid, freq, mode, ieee80211n if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config['ieee80211n']: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config
def reconfigure(self, config, level): self.current_config['status'] = "OK" self.current_config['errmsg'] = "" if config['enabled'] and \ ((config['mode'] == "a" and self.band != IEEE80211_Channels.BAND_5000_MHz) or \ ((config['mode'] == "b" or config['mode'] == "g") and self.band != IEEE80211_Channels.BAND_2400_MHz)): config['enabled'] = False self.current_config['status'] = "FAIL" self.current_config['errmsg'] = "Cannot set 802.11%s mode for interface in %s"%(config['mode'], self.band) change = False # enabled if not config['enabled']: if self.current_config['enabled']: self.set_wireless_basic(None, "disabled", None) change = True else: # bitrate, txpower, wmm if config['txpower'] != self.current_config['txpower'] or \ config['bitrate'] != self.current_config['bitrate'] or \ config['wmm'] != self.current_config['wmm']: new_txpower_mw = self.dbm_to_mw(config['txpower']) if new_txpower_mw > self.max_txpower_mw: config['txpower'] = self.mw_to_dbm(self.max_txpower_mw) if new_txpower_mw < self.min_txpower_mw: config['txpower'] = self.mw_to_dbm(self.min_txpower_mw) self.set_wireless_advanced(config['bitrate'], self.dbm_to_mw(config['txpower']), config['wmm']) change = True # security params: if config['encryption_mode'] != self.current_config['encryption_mode'] or \ (config['encryption_mode'] != "open" and \ config['encryption_pass'] != self.current_config['encryption_pass']): self.set_wireless_security(config['encryption_mode'], config['encryption_pass']) change = True # ssid, freq, mode, ieee80211n if config['enabled'] != self.current_config['enabled'] or \ config['ssid'] != self.current_config['ssid'] or \ config['freq'] != self.current_config['freq'] or \ config['mode'] != self.current_config['mode'] or \ config['ieee80211n'] != self.current_config['ieee80211n']: new_channel = IEEE80211_Channels.get_channel(config['freq']) if not config['enabled']: new_mode = "disabled" elif config['ieee80211n']: new_mode = "mixed" else: new_mode = config['mode'] + "-only" self.set_wireless_basic(config['ssid'], new_mode, new_channel) change = True # verify config if change: self.get_current_config() self.compare_configs(config, self.current_config) if self.current_config['enabled']: return self.current_config else: config['status'] = self.current_config['status'] config['errmsg'] = self.current_config['errmsg'] config['enabled'] = False return config