Esempio n. 1
0
    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'])
Esempio n. 2
0
 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'])
Esempio n. 3
0
    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 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 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
Esempio n. 6
0
    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")
Esempio n. 7
0
 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
Esempio n. 8
0
    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()))
Esempio n. 9
0
    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()
Esempio n. 11
0
    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'] = ""

        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
Esempio n. 13
0
    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()
Esempio n. 14
0
    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
Esempio n. 15
0
    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
Esempio n. 16
0
    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 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 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