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()
Beispiel #2
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()