def test_linksys_security(self): config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", "ieee80211n": False, "bitrate": 0, "wmm": False, "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz), "encryption_mode": "open", "encryption_pass": ""}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap24.update_configuration({"enabled": True, "mode": "g", "ieee80211n": False, "bitrate": 0, "wmm": False, "freq": IEEE80211_Channels.get_freq(9, IEEE80211_Channels.BAND_2400_MHz), "encryption_mode": "open", "encryption_pass": ""}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap24.update_configuration({"encryption_mode": "wpa2", "encryption_pass": "******"}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap5.update_configuration({"encryption_mode": "wep", "encryption_pass": "******"}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap5.update_configuration({"wmm": True}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) self.assertTrue(config['encryption_mode'] == "wep", "Wrong encryption mode: " + config['encryption_mode']) config = self.dyn_ap24.update_configuration({"wmm": True}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) self.assertTrue(config['encryption_mode'] == "wpa2", "Wrong encryption mode: " + config['encryption_mode'])
def test_freq(self): freq = IEEE80211_Channels.get_freq(5, IEEE80211_Channels.BAND_2400_MHz) config = self.dyn_ap1.update_configuration({ "enabled": True, "ssid": "testnet1", "mode": 'b', "freq": freq }) self.assertEqual(config['status'], "OK", "Operation failed: " + config['errmsg']) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual( ap1_info.freq(), freq, "Expected freq to be %ld, but instead it was %ld" % (freq, ap1_info.freq())) freq = IEEE80211_Channels.get_freq(44, IEEE80211_Channels.BAND_5000_MHz) config = self.dyn_ap1.update_configuration({"freq": freq}) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual( config['status'], "FAIL", "Expected setting an 802.11a freq when in 802.11b mode to fail: %s" % (ap1_info.out)) config = self.dyn_ap1.update_configuration({ "freq": freq, "mode": "a", "enabled": True }) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual( ap1_info.freq(), freq, "Expected freq to be %ld, but instead it was %ld" % (freq, ap1_info.freq()))
def test_linksys_both(self): config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", "bitrate": 0, "wmm": False, "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz)}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap24.update_configuration({"enabled": True, "mode": "g", "ieee80211n": True, "bitrate": 0, "wmm": False, "freq": IEEE80211_Channels.get_freq(9, IEEE80211_Channels.BAND_2400_MHz)}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap24.update_configuration({"ssid": "myssid24"}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap5.update_configuration({"ssid": "myssid5"}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) config = self.dyn_ap24.update_configuration({"txpower": 30}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) rospy.loginfo("Max txpower level on 2.4GHz is: %d dbm", config['txpower']) config = self.dyn_ap5.update_configuration({"txpower": -1}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) rospy.loginfo("Min txpower level on 5GHz is: %d dbm", config['txpower'])
def get_current_config(self): mode, ssid, channel = self.get_wireless_basic_params() if mode is None: raise Exception("Could not read interface %s mode"%(self.interface)) if mode != "disabled" and ssid is None: raise Exception("Could not read interface %s ssid"%(self.interface)) if mode != "disabled" and channel is None: raise Exception("Could not read interface %s channel"%(self.interface)) # enabled if mode == "disabled": self.current_config['enabled'] = False else: self.current_config['enabled'] = True # mode if mode in ["a-only", "b-only", "g-only"]: self.current_config['mode'] = mode[0] self.current_config['ieee80211n'] = False elif mode == "bg-mixed": self.current_config['mode'] = "g" self.current_config['ieee80211n'] = False elif mode == "mixed" and self.band == IEEE80211_Channels.BAND_2400_MHz: self.current_config['mode'] = "g" self.current_config['ieee80211n'] = True elif mode == "mixed" and self.band == IEEE80211_Channels.BAND_5000_MHz: self.current_config['mode'] = "a" self.current_config['ieee80211n'] = True elif mode == "n-only": self.current_config['ieee80211n'] = True else: self.current_config['mode'] = "unknown" self.current_config['ieee80211n'] = False #ssid self.current_config['ssid'] = ssid #freq self.current_config['freq'] = float(IEEE80211_Channels.get_freq(channel, self.band)) bitrate, txpower_mw, wmm = self.get_wireless_advanced_params() if mode != "disabled" and (bitrate is None or txpower_mw is None or wmm is None): raise Exception("Could not read bitrate or txpower_mw or wmm: %s, %s, %s"% (str(bitrate), str(txpower_mw), str(wmm))) #bitrate self.current_config['bitrate'] = bitrate #txpower self.current_config['txpower_auto'] = False self.current_config['txpower'] = self.mw_to_dbm(txpower_mw) #wmm self.current_config['wmm'] = wmm enc_mode, enc_pass = self.get_wireless_security_params() if mode != "disabled" and (enc_mode is None or enc_pass is None): raise Exception("Could not read encryption mode") self.current_config['encryption_mode'] = enc_mode self.current_config['encryption_pass'] = enc_pass
def test_linksys_5(self): config = self.dyn_ap5.update_configuration({"enabled": False, "mode": "b", "ieee80211n": False, "freq": 0, "bitrate": 0}) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) start_time = time.time() config = self.dyn_ap5.update_configuration({"enabled": True}) rospy.loginfo("Failed enable executed in: %.2fs", time.time() - start_time) self.assertTrue(config['status'] == "FAIL", "Expected enabling 5GHz interface while in default mode 'b' to fail" + ", returned config: " + str(config)) self.assertFalse(config['enabled'], "Expected AP to be stopped") start_time = time.time() config = self.dyn_ap5.update_configuration({"enabled": True, "mode": "a", "freq": IEEE80211_Channels.get_freq(153, IEEE80211_Channels.BAND_5000_MHz)}) rospy.loginfo("Enabling 5GHz executed in: %.2fs", time.time() - start_time) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) self.assertTrue(config['enabled'], "Expected AP to be running") start_time = time.time() config = self.dyn_ap5.update_configuration({"freq": IEEE80211_Channels.get_freq(161, IEEE80211_Channels.BAND_5000_MHz)}) rospy.loginfo("Change channel 5GHz executed in: %.2fs", time.time() - start_time) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) start_time = time.time() config = self.dyn_ap5.update_configuration({"ieee80211n": True, "bitrate": 0}) rospy.loginfo("Enabling 802.11n executed in: %.2fs", time.time() - start_time) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) start_time = time.time() config = self.dyn_ap5.update_configuration({"enabled": False}) rospy.loginfo("Disabling 5GHz executed in: %.2fs", time.time() - start_time) self.assertTrue(config['status'] == "OK", "Operation failed: " + config['errmsg']) self.assertFalse(config['enabled'], "Expected AP to be stopped")
def test_freq(self): freq = IEEE80211_Channels.get_freq(5, IEEE80211_Channels.BAND_2400_MHz) config = self.dyn_ap1.update_configuration({"enabled": True, "ssid": "testnet1", "mode": 'b', "freq": freq}) self.assertEqual(config['status'], "OK", "Operation failed: " + config['errmsg']) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual(ap1_info.freq(), freq, "Expected freq to be %ld, but instead it was %ld"%(freq, ap1_info.freq())) freq = IEEE80211_Channels.get_freq(44, IEEE80211_Channels.BAND_5000_MHz) config = self.dyn_ap1.update_configuration({"freq": freq}) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual(config['status'], "FAIL", "Expected setting an 802.11a freq when in 802.11b mode to fail: %s"% (ap1_info.out)) config = self.dyn_ap1.update_configuration({"freq": freq, "mode": "a", "enabled": True}) ap1_info = IwconfigInfo(self.ap1_iface) self.assertEqual(ap1_info.freq(), freq, "Expected freq to be %ld, but instead it was %ld"%(freq, ap1_info.freq()))
def get_current_config(self): mode, ssid, channel = self.get_wireless_basic_params() if self.interface == "wl0": band = IEEE80211_Channels.BAND_2400_MHz else: band = IEEE80211_Channels.BAND_5000_MHz self.current_config['ssid'] = ssid self.current_config['freq'] = float( IEEE80211_Channels.get_freq(channel, band)) if mode == "disabled": self.current_config['enabled'] = False else: self.current_config['enabled'] = True if mode in ["a-only", "b-only", "g-only"]: self.current_config['mode'] = mode[0] self.current_config['ieee80211n'] = False elif mode == "bg-mixed": self.current_config['mode'] = "g" self.current_config['ieee80211n'] = False elif mode == "mixed" and band == IEEE80211_Channels.BAND_2400_MHz: self.current_config['mode'] = "g" self.current_config['ieee80211n'] = True elif mode == "mixed" and band == IEEE80211_Channels.BAND_5000_MHz: self.current_config['mode'] = "a" self.current_config['ieee80211n'] = True elif mode == "n-only": self.current_config['ieee80211n'] = True else: self.current_config['mode'] = "unknown" self.current_config['ieee80211n'] = False self.current_config[ 'bitrate'], txpower = self.get_wireless_advanced_params() self.current_config['txpower_auto'] = False self.current_config['txpower'] = self.mw_to_dbm(txpower) self.current_config['encryption_mode'], self.current_config['encryption_pass'] = \ self.get_wireless_security_params() self.current_config['wmm'] = self.get_qos_params()
def get_current_config(self): mode, ssid, channel = self.get_wireless_basic_params() if self.interface == "wl0": band = IEEE80211_Channels.BAND_2400_MHz else: band = IEEE80211_Channels.BAND_5000_MHz self.current_config['ssid'] = ssid self.current_config['freq'] = float(IEEE80211_Channels.get_freq(channel, band)) if mode == "disabled": self.current_config['enabled'] = False else: self.current_config['enabled'] = True if mode in ["a-only", "b-only", "g-only"]: self.current_config['mode'] = mode[0] self.current_config['ieee80211n'] = False elif mode == "bg-mixed": self.current_config['mode'] = "g" self.current_config['ieee80211n'] = False elif mode == "mixed" and band == IEEE80211_Channels.BAND_2400_MHz: self.current_config['mode'] = "g" self.current_config['ieee80211n'] = True elif mode == "mixed" and band == IEEE80211_Channels.BAND_5000_MHz: self.current_config['mode'] = "a" self.current_config['ieee80211n'] = True elif mode == "n-only": self.current_config['ieee80211n'] = True else: self.current_config['mode'] = "unknown" self.current_config['ieee80211n'] = False self.current_config['bitrate'], txpower = self.get_wireless_advanced_params() self.current_config['txpower_auto'] = False self.current_config['txpower'] = self.mw_to_dbm(txpower) self.current_config['encryption_mode'], self.current_config['encryption_pass'] = \ self.get_wireless_security_params() self.current_config['wmm'] = self.get_qos_params()
def get_current_config(self): mode, ssid, channel = self.get_wireless_basic_params() if mode is None: raise Exception("Could not read interface %s mode" % (self.interface)) if mode != "disabled" and ssid is None: raise Exception("Could not read interface %s ssid" % (self.interface)) if mode != "disabled" and channel is None: raise Exception("Could not read interface %s channel" % (self.interface)) # enabled if mode == "disabled": self.current_config['enabled'] = False else: self.current_config['enabled'] = True # mode if mode in ["a-only", "b-only", "g-only"]: self.current_config['mode'] = mode[0] self.current_config['ieee80211n'] = False elif mode == "bg-mixed": self.current_config['mode'] = "g" self.current_config['ieee80211n'] = False elif mode == "mixed" and self.band == IEEE80211_Channels.BAND_2400_MHz: self.current_config['mode'] = "g" self.current_config['ieee80211n'] = True elif mode == "mixed" and self.band == IEEE80211_Channels.BAND_5000_MHz: self.current_config['mode'] = "a" self.current_config['ieee80211n'] = True elif mode == "n-only": self.current_config['ieee80211n'] = True else: self.current_config['mode'] = "unknown" self.current_config['ieee80211n'] = False #ssid self.current_config['ssid'] = ssid #freq self.current_config['freq'] = float( IEEE80211_Channels.get_freq(channel, self.band)) bitrate, txpower_mw, wmm = self.get_wireless_advanced_params() if mode != "disabled" and (bitrate is None or txpower_mw is None or wmm is None): raise Exception( "Could not read bitrate or txpower_mw or wmm: %s, %s, %s" % (str(bitrate), str(txpower_mw), str(wmm))) #bitrate self.current_config['bitrate'] = bitrate #txpower self.current_config['txpower_auto'] = False self.current_config['txpower'] = self.mw_to_dbm(txpower_mw) #wmm self.current_config['wmm'] = wmm enc_mode, enc_pass = self.get_wireless_security_params() if mode != "disabled" and (enc_mode is None or enc_pass is None): raise Exception("Could not read encryption mode") self.current_config['encryption_mode'] = enc_mode self.current_config['encryption_pass'] = enc_pass