def setup_and_connect(self, ap_settings): """Generates a hostapd config, setups up the AP with that config, then attempts to associate a DUT Args: ap_settings: A dictionary of hostapd constant n_capabilities. """ security_profile = None password = None temp_n_capabilities = list(ap_settings['n_capabilities']) n_capabilities = [] for n_capability in temp_n_capabilities: if n_capability in hostapd_constants.N_CAPABILITIES_MAPPING.keys(): n_capabilities.append(n_capability) if ap_settings['chbw'] == 'HT20' or ap_settings['chbw'] == 'HT40+': if ap_settings['frequency'] == '2.4GHz': channel = 1 elif ap_settings['frequency'] == '5GHz': channel = 36 else: raise ValueError('Invalid frequence: %s' % ap_settings['frequency']) if ap_settings['chbw'] == 'HT40-': if ap_settings['frequency'] == '2.4GHz': channel = 11 elif ap_settings['frequency'] == '5GHz': channel = 60 else: raise ValueError('Invalid frequency: %s' % ap_settings['frequency']) if ap_settings['chbw'] == 'HT40-' or ap_settings['chbw'] == 'HT40+': if hostapd_config.ht40_plus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_PLUS elif hostapd_config.ht40_minus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_MINUS else: raise ValueError('Invalid channel: %s' % channel) n_capabilities.append(extended_channel) if ap_settings['security'] == 'wpa2': security_profile = Security(security_mode=SECURITY_WPA2, password=rand_ascii_str(20), wpa_cipher='CCMP', wpa2_cipher='CCMP') password = security_profile.password validate_setup_ap_and_associate(access_point=self.access_point, client=self.dut, profile_name='whirlwind', mode=hostapd_constants.MODE_11N_MIXED, channel=channel, n_capabilities=n_capabilities, ac_capabilities=[], force_wmm=True, ssid=utils.rand_ascii_str(20), security=security_profile, password=password)
def create_ap_preset(profile_name='whirlwind', iface_wlan_2g=None, iface_wlan_5g=None, channel=None, mode=None, frequency=None, security=None, pmf_support=None, ssid=None, hidden=None, dtim_period=None, frag_threshold=None, rts_threshold=None, force_wmm=None, beacon_interval=None, short_preamble=None, n_capabilities=None, ac_capabilities=None, vht_bandwidth=None, bss_settings=[]): """AP preset config generator. This a wrapper for hostapd_config but but supplies the default settings for the preset that is selected. You may specify channel or frequency, but not both. Both options are checked for validity (i.e. you can't specify an invalid channel or a frequency that will not be accepted). Args: profile_name: The name of the device want the preset for. Options: whirlwind channel: int, channel number. dtim: int, DTIM value of the AP, default is 2. frequency: int, frequency of channel. security: Security, the secuirty settings to use. ssid: string, The name of the ssid to brodcast. pmf_support: int, whether pmf is disabled, enabled, or required vht_bandwidth: VHT bandwidth for 11ac operation. bss_settings: The settings for all bss. iface_wlan_2g: the wlan 2g interface name of the AP. iface_wlan_5g: the wlan 5g interface name of the AP. mode: The hostapd 802.11 mode of operation. ssid: The ssid for the wireless network. hidden: Whether to include the ssid in the beacons. dtim_period: The dtim period for the BSS frag_threshold: Max size of packet before fragmenting the packet. rts_threshold: Max size of packet before requiring protection for rts/cts or cts to self. n_capabilities: 802.11n capabilities for for BSS to advertise. ac_capabilities: 802.11ac capabilities for for BSS to advertise. Returns: A hostapd_config object that can be used by the hostapd object. """ # Verify interfaces hostapd_utils.verify_interface(iface_wlan_2g, hostapd_constants.INTERFACE_2G_LIST) hostapd_utils.verify_interface(iface_wlan_5g, hostapd_constants.INTERFACE_5G_LIST) if channel: frequency = hostapd_config.get_frequency_for_channel(channel) elif frequency: channel = hostapd_config.get_channel_for_frequency(frequency) else: raise ValueError('Specify either frequency or channel.') if profile_name == 'whirlwind': # profile indicates phy mode is 11bgn for 2.4Ghz or 11acn for 5Ghz hidden = _get_or_default(hidden, False) force_wmm = _get_or_default(force_wmm, True) beacon_interval = _get_or_default(beacon_interval, 100) short_preamble = _get_or_default(short_preamble, True) dtim_period = _get_or_default(dtim_period, 2) frag_threshold = _get_or_default(frag_threshold, 2346) rts_threshold = _get_or_default(rts_threshold, 2347) if frequency < 5000: interface = iface_wlan_2g mode = _get_or_default(mode, hostapd_constants.MODE_11N_MIXED) n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_DSSS_CCK_40 ]) config = hostapd_config.HostapdConfig( ssid=ssid, hidden=hidden, security=security, pmf_support=pmf_support, interface=interface, mode=mode, force_wmm=force_wmm, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, n_capabilities=n_capabilities, frag_threshold=frag_threshold, rts_threshold=rts_threshold, bss_settings=bss_settings) else: interface = iface_wlan_5g vht_bandwidth = _get_or_default(vht_bandwidth, 80) mode = _get_or_default(mode, hostapd_constants.MODE_11AC_MIXED) if hostapd_config.ht40_plus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_PLUS elif hostapd_config.ht40_minus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_MINUS # Channel 165 operates in 20MHz with n or ac modes. if channel == 165: mode = hostapd_constants.MODE_11N_MIXED extended_channel = hostapd_constants.N_CAPABILITY_HT20 # Define the n capability vector for 20 MHz and higher bandwidth if not vht_bandwidth: pass elif vht_bandwidth >= 40: n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, extended_channel, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1 ]) else: n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_HT20 ]) ac_capabilities = _get_or_default(ac_capabilities, [ hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, hostapd_constants.AC_CAPABILITY_RXLDPC, hostapd_constants.AC_CAPABILITY_SHORT_GI_80, hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, hostapd_constants.AC_CAPABILITY_RX_STBC_1, hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN, hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN ]) config = hostapd_config.HostapdConfig( ssid=ssid, hidden=hidden, security=security, pmf_support=pmf_support, interface=interface, mode=mode, force_wmm=force_wmm, vht_channel_width=vht_bandwidth, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, frag_threshold=frag_threshold, rts_threshold=rts_threshold, n_capabilities=n_capabilities, ac_capabilities=ac_capabilities, bss_settings=bss_settings) elif profile_name == 'whirlwind_11ab_legacy': if frequency < 5000: mode = hostapd_constants.MODE_11B else: mode = hostapd_constants.MODE_11A config = create_ap_preset(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, ssid=ssid, channel=channel, mode=mode, security=security, pmf_support=pmf_support, hidden=hidden, force_wmm=force_wmm, beacon_interval=beacon_interval, short_preamble=short_preamble, dtim_period=dtim_period, rts_threshold=rts_threshold, frag_threshold=frag_threshold, n_capabilities=[], ac_capabilities=[], vht_bandwidth=None) elif profile_name == 'whirlwind_11ag_legacy': if frequency < 5000: mode = hostapd_constants.MODE_11G else: mode = hostapd_constants.MODE_11A config = create_ap_preset(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, ssid=ssid, channel=channel, mode=mode, security=security, pmf_support=pmf_support, hidden=hidden, force_wmm=force_wmm, beacon_interval=beacon_interval, short_preamble=short_preamble, dtim_period=dtim_period, rts_threshold=rts_threshold, frag_threshold=frag_threshold, n_capabilities=[], ac_capabilities=[], vht_bandwidth=None) elif profile_name == 'mistral': hidden = _get_or_default(hidden, False) force_wmm = _get_or_default(force_wmm, True) beacon_interval = _get_or_default(beacon_interval, 100) short_preamble = _get_or_default(short_preamble, True) dtim_period = _get_or_default(dtim_period, 2) frag_threshold = None rts_threshold = None # Google IE # Country Code IE ('us' lowercase) vendor_elements = { 'vendor_elements': 'dd0cf4f5e80505ff0000ffffffff' '070a75732024041e95051e00' } default_configs = {'bridge': 'br-lan', 'iapp_interface': 'br-lan'} if frequency < 5000: interface = iface_wlan_2g mode = _get_or_default(mode, hostapd_constants.MODE_11N_MIXED) n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_DSSS_CCK_40 ]) additional_params = utils.merge_dicts( vendor_elements, hostapd_constants.ENABLE_RRM_BEACON_REPORT, hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT, default_configs) config = hostapd_config.HostapdConfig( ssid=ssid, hidden=hidden, security=security, pmf_support=pmf_support, interface=interface, mode=mode, force_wmm=force_wmm, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, n_capabilities=n_capabilities, frag_threshold=frag_threshold, rts_threshold=rts_threshold, bss_settings=bss_settings, additional_parameters=additional_params, set_ap_defaults_profile=profile_name) else: interface = iface_wlan_5g vht_bandwidth = _get_or_default(vht_bandwidth, 80) mode = _get_or_default(mode, hostapd_constants.MODE_11AC_MIXED) if hostapd_config.ht40_plus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_PLUS elif hostapd_config.ht40_minus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_MINUS # Channel 165 operates in 20MHz with n or ac modes. if channel == 165: mode = hostapd_constants.MODE_11N_MIXED extended_channel = hostapd_constants.N_CAPABILITY_HT20 if vht_bandwidth >= 40: n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, extended_channel, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1 ]) else: n_capabilities = _get_or_default(n_capabilities, [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_HT20 ]) ac_capabilities = _get_or_default(ac_capabilities, [ hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, hostapd_constants.AC_CAPABILITY_RXLDPC, hostapd_constants.AC_CAPABILITY_SHORT_GI_80, hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, hostapd_constants.AC_CAPABILITY_RX_STBC_1, hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN, hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN, hostapd_constants.AC_CAPABILITY_SU_BEAMFORMER, hostapd_constants.AC_CAPABILITY_SU_BEAMFORMEE, hostapd_constants.AC_CAPABILITY_MU_BEAMFORMER, hostapd_constants.AC_CAPABILITY_SOUNDING_DIMENSION_4, hostapd_constants.AC_CAPABILITY_BF_ANTENNA_4 ]) additional_params = utils.merge_dicts( vendor_elements, hostapd_constants.ENABLE_RRM_BEACON_REPORT, hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT, default_configs) config = hostapd_config.HostapdConfig( ssid=ssid, hidden=hidden, security=security, pmf_support=pmf_support, interface=interface, mode=mode, force_wmm=force_wmm, vht_channel_width=vht_bandwidth, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, frag_threshold=frag_threshold, rts_threshold=rts_threshold, n_capabilities=n_capabilities, ac_capabilities=ac_capabilities, bss_settings=bss_settings, additional_parameters=additional_params, set_ap_defaults_profile=profile_name) elif profile_name == 'actiontec_pk5000': config = actiontec.actiontec_pk5000(iface_wlan_2g=iface_wlan_2g, channel=channel, ssid=ssid, security=security) elif profile_name == 'actiontec_mi424wr': config = actiontec.actiontec_mi424wr(iface_wlan_2g=iface_wlan_2g, channel=channel, ssid=ssid, security=security) elif profile_name == 'asus_rtac66u': config = asus.asus_rtac66u(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'asus_rtac86u': config = asus.asus_rtac86u(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'asus_rtac5300': config = asus.asus_rtac5300(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'asus_rtn56u': config = asus.asus_rtn56u(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'asus_rtn66u': config = asus.asus_rtn66u(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'belkin_f9k1001v5': config = belkin.belkin_f9k1001v5(iface_wlan_2g=iface_wlan_2g, channel=channel, ssid=ssid, security=security) elif profile_name == 'linksys_ea4500': config = linksys.linksys_ea4500(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'linksys_ea9500': config = linksys.linksys_ea9500(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'linksys_wrt1900acv2': config = linksys.linksys_wrt1900acv2(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'netgear_r7000': config = netgear.netgear_r7000(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'netgear_wndr3400': config = netgear.netgear_wndr3400(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'securifi_almond': config = securifi.securifi_almond(iface_wlan_2g=iface_wlan_2g, channel=channel, ssid=ssid, security=security) elif profile_name == 'tplink_archerc5': config = tplink.tplink_archerc5(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'tplink_archerc7': config = tplink.tplink_archerc7(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'tplink_c1200': config = tplink.tplink_c1200(iface_wlan_2g=iface_wlan_2g, iface_wlan_5g=iface_wlan_5g, channel=channel, ssid=ssid, security=security) elif profile_name == 'tplink_tlwr940n': config = tplink.tplink_tlwr940n(iface_wlan_2g=iface_wlan_2g, channel=channel, ssid=ssid, security=security) else: raise ValueError('Invalid ap model specified (%s)' % profile_name) return config
def netgear_r7000(iface_wlan_2g=None, iface_wlan_5g=None, channel=None, security=None, ssid=None): # TODO(b/143104825): Permit RIFS once it is supported # TODO(b/144446076): Address non-whirlwind hardware capabilities. """A simulated implementation of what a Netgear R7000 AP Args: iface_wlan_2g: The 2.4Ghz interface of the test AP. iface_wlan_5g: The 5GHz interface of the test AP. channel: What channel to use. security: A security profile (None or WPA2). ssid: The network name. Returns: A hostapd config. Differences from real R7000: 2.4GHz: Rates: R7000: Supported: 1, 2, 5.5, 11, 18, 24, 36, 54 Extended: 6, 9, 12, 48 Simulated: Supported: 1, 2, 5.5, 11, 6, 9, 12, 18 Extended: 24, 36, 48, 5GHz: VHT Capab: R7000: SU Beamformer Supported, SU Beamformee Supported, Beamformee STS Capability: 3, Number of Sounding Dimensions: 3, VHT Link Adaptation: Both Simulated: Above are not supported on Whirlwind. VHT Operation Info: R7000: Basic MCS Map (0x0000) Simulated: Basic MCS Map (0xfffc) VHT Tx Power Envelope: R7000: Local Max Tx Pwr Constraint: 1.0 dBm Simulated: Local Max Tx Pwr Constraint: 23.0 dBm Both: HT Capab: A-MPDU R7000: MPDU Density 4 Simulated: MPDU Density 8 HT Info: R7000: RIFS Permitted Simulated: RIFS Prohibited RM Capabilities: R7000: Beacon Table Measurement: Not Supported Statistic Measurement: Enabled AP Channel Report Capability: Enabled Simulated: Beacon Table Measurement: Supported Statistic Measurement: Disabled AP Channel Report Capability: Disabled """ # Verify interface and security hostapd_utils.verify_interface(iface_wlan_2g, hostapd_constants.INTERFACE_2G_LIST) hostapd_utils.verify_interface(iface_wlan_5g, hostapd_constants.INTERFACE_5G_LIST) hostapd_utils.verify_security_mode(security, [None, hostapd_constants.WPA2]) if security: hostapd_utils.verify_cipher(security, [hostapd_constants.WPA2_DEFAULT_CIPER]) # Common Parameters rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES vht_channel_width = 80 n_capabilities = [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935, hostapd_constants.N_CAPABILITY_SGI20, ] # Netgear IE # WPS IE # Epigram, Inc. IE # Broadcom IE vendor_elements = { 'vendor_elements': 'dd0600146c000000' 'dd310050f204104a00011010440001021047001066189606f1e967f9c0102048817a7' '69e103c0001031049000600372a000120' 'dd1e00904c0408bf0cb259820feaff0000eaff0000c0050001000000c3020002' 'dd090010180200001c0000' } qbss = {'bss_load_update_period': 50, 'chan_util_avg_period': 600} # 2.4GHz if channel <= 11: interface = iface_wlan_2g rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES) mode = hostapd_constants.MODE_11N_MIXED obss_interval = 300 ac_capabilities = None # 5GHz else: interface = iface_wlan_5g rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES) mode = hostapd_constants.MODE_11AC_MIXED n_capabilities += [ hostapd_constants.N_CAPABILITY_SGI40, ] if hostapd_config.ht40_plus_allowed(channel): n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS) elif hostapd_config.ht40_minus_allowed(channel): n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS) obss_interval = None ac_capabilities = [ hostapd_constants.AC_CAPABILITY_RXLDPC, hostapd_constants.AC_CAPABILITY_SHORT_GI_80, hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, hostapd_constants.AC_CAPABILITY_RX_STBC_1, hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7 ] additional_params = utils.merge_dicts( rates, vendor_elements, qbss, hostapd_constants.ENABLE_RRM_BEACON_REPORT, hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT, hostapd_constants.UAPSD_ENABLED) config = hostapd_config.HostapdConfig( ssid=ssid, channel=channel, hidden=False, security=security, interface=interface, mode=mode, force_wmm=True, beacon_interval=100, dtim_period=2, short_preamble=False, obss_interval=obss_interval, n_capabilities=n_capabilities, ac_capabilities=ac_capabilities, vht_channel_width=vht_channel_width, additional_parameters=additional_params) return config
def tplink_archerc7(iface_wlan_2g=None, iface_wlan_5g=None, channel=None, security=None, ssid=None): # TODO(b/143104825): Permit RIFS once it is supported """A simulated implementation of an TPLink ArcherC7 AP. Args: iface_wlan_2g: The 2.4Ghz interface of the test AP. iface_wlan_5g: The 5GHz interface of the test AP. channel: What channel to use. security: A security profile (None or WPA2). ssid: The network name. Returns: A hostapd config. Differences from real ArcherC7: 5GHz: Country Code: Simulated: Has two country code IEs, one that matches the actual, and another explicit IE that was required for hostapd's 802.11d to work. Both: HT Info: ArcherC7: RIFS Permitted Simulated: RIFS Prohibited RSN Capabilities (w/ WPA2): ArcherC7: RSN PTKSA Replay Counter Capab: 1 Simulated: RSN PTKSA Replay Counter Capab: 16 """ # Verify interface and security hostapd_utils.verify_interface(iface_wlan_2g, hostapd_constants.INTERFACE_2G_LIST) hostapd_utils.verify_interface(iface_wlan_5g, hostapd_constants.INTERFACE_5G_LIST) hostapd_utils.verify_security_mode(security, [None, hostapd_constants.WPA2]) if security: hostapd_utils.verify_cipher(security, [hostapd_constants.WPA2_DEFAULT_CIPER]) # Common Parameters rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES vht_channel_width = 80 n_capabilities = [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1 ] # Atheros IE # WPS IE vendor_elements = { 'vendor_elements': 'dd0900037f01010000ff7f' 'dd180050f204104a00011010440001021049000600372a000120' } # 2.4GHz if channel <= 11: interface = iface_wlan_2g rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES) short_preamble = True mode = hostapd_constants.MODE_11N_MIXED spectrum_mgmt = False pwr_constraint = {} ac_capabilities = None vht_channel_width = None # 5GHz else: interface = iface_wlan_5g rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES) short_preamble = False mode = hostapd_constants.MODE_11AC_MIXED spectrum_mgmt = True # Country Information IE (w/ individual channel info) vendor_elements['vendor_elements'] += ( '074255532024011e28011e2c011e30' '011e3401173801173c01174001176401176801176c0117700117740117840117' '8801178c011795011e99011e9d011ea1011ea5011e') pwr_constraint = {'local_pwr_constraint': 3} n_capabilities += [ hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935 ] if hostapd_config.ht40_plus_allowed(channel): n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS) elif hostapd_config.ht40_minus_allowed(channel): n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS) ac_capabilities = [ hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, hostapd_constants.AC_CAPABILITY_RXLDPC, hostapd_constants.AC_CAPABILITY_SHORT_GI_80, hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, hostapd_constants.AC_CAPABILITY_RX_STBC_1, hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN, hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN ] additional_params = utils.merge_dicts(rates, vendor_elements, hostapd_constants.UAPSD_ENABLED, pwr_constraint) config = hostapd_config.HostapdConfig( ssid=ssid, channel=channel, hidden=False, security=security, interface=interface, mode=mode, force_wmm=True, beacon_interval=100, dtim_period=1, short_preamble=short_preamble, n_capabilities=n_capabilities, ac_capabilities=ac_capabilities, vht_channel_width=vht_channel_width, spectrum_mgmt_required=spectrum_mgmt, additional_parameters=additional_params) return config
def create_ap_preset(profile_name, channel=None, frequency=None, security=None, ssid=None, bss_settings=[]): """AP preset config generator. This a wrapper for hostapd_config but but supplies the default settings for the preset that is selected. You may specify channel or frequency, but not both. Both options are checked for validity (i.e. you can't specify an invalid channel or a frequency that will not be accepted). Args: profile_name: The name of the device want the preset for. Options: whirlwind channel: int, channel number. frequency: int, frequency of channel. security: Security, the secuirty settings to use. ssid: string, The name of the ssid to brodcast. bss_settings: The settings for all bss. Returns: A hostapd_config object that can be used by the hostapd object. """ force_wmm = None force_wmm = None beacon_interval = None dtim_period = None short_preamble = None interface = None mode = None n_capabilities = None ac_capabilities = None if channel: frequency = hostapd_config.get_frequency_for_channel(channel) elif frequency: channel = hostapd_config.get_channel_for_frequency(frequency) else: raise ValueError('Specify either frequency or channel.') if (profile_name == 'whirlwind'): force_wmm = True beacon_interval = 100 dtim_period = 2 short_preamble = True if frequency < 5000: interface = hostapd_constants.WLAN0_STRING mode = hostapd_constants.MODE_11N_MIXED n_capabilities = [ hostapd_constants.N_CAPABILITY_LDPC, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1, hostapd_constants.N_CAPABILITY_DSSS_CCK_40 ] config = hostapd_config.HostapdConfig( ssid=ssid, security=security, interface=interface, mode=mode, force_wmm=force_wmm, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, n_capabilities=n_capabilities, bss_settings=bss_settings) else: interface = hostapd_constants.WLAN1_STRING mode = hostapd_constants.MODE_11AC_MIXED if hostapd_config.ht40_plus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_PLUS elif hostapd_config.ht40_minus_allowed(channel): extended_channel = hostapd_constants.N_CAPABILITY_HT40_MINUS n_capabilities = [ hostapd_constants.N_CAPABILITY_LDPC, extended_channel, hostapd_constants.N_CAPABILITY_SGI20, hostapd_constants.N_CAPABILITY_SGI40, hostapd_constants.N_CAPABILITY_TX_STBC, hostapd_constants.N_CAPABILITY_RX_STBC1 ] ac_capabilities = [ hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454, hostapd_constants.AC_CAPABILITY_RXLDPC, hostapd_constants.AC_CAPABILITY_SHORT_GI_80, hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1, hostapd_constants.AC_CAPABILITY_RX_STBC_1, hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7, hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN, hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN ] config = hostapd_config.HostapdConfig( ssid=ssid, security=security, interface=interface, mode=mode, force_wmm=force_wmm, beacon_interval=beacon_interval, dtim_period=dtim_period, short_preamble=short_preamble, frequency=frequency, n_capabilities=n_capabilities, ac_capabilities=ac_capabilities, bss_settings=bss_settings) else: raise ValueError('Invalid ap model specified (%s)' % profile_name) return config