def dfs_chan_switch_precac(dev, apdev, country): """DFS channel switch pre CAC""" try: hapd = None # Toggle regulatory - clean all preCAC hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', 'US']) hapd = start_dfs_ap(apdev[0], country=country) ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) if "success=1" not in ev: raise Exception("CAC failed") if "freq=5260" not in ev: raise Exception("Unexpected DFS freq result") ev = hapd.wait_event(["AP-ENABLED"], timeout=5) if not ev: raise Exception("AP setup timed out") freq = hapd.get_status_field("freq") if freq != "5260": raise Exception("Unexpected frequency") # TODO add/connect station here # Today skip this step while dev[0].connect() # for some reason toggle regulatory to US # and clean preCAC # Back to non DFS channel if "OK" not in hapd.request("CHAN_SWITCH 5 5180 ht"): raise Exception("CHAN_SWITCH 5180 failed") ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=5) if not ev: raise Exception("No CSA finished event - 5180") freq = hapd.get_status_field("freq") if freq != "5180": raise Exception("Unexpected frequency") # Today cfg80211 first send AP-CSA-FINISHED and next # DFS-PRE-CAC-EXPIRED ev = hapd.wait_event(["DFS-PRE-CAC-EXPIRED"], timeout=3) if not ev and country == 'US': raise Exception("US - no CAC-EXPIRED event") # Back again to DFS channel (CAC passed) if "OK" not in hapd.request("CHAN_SWITCH 5 5260 ht"): raise Exception("CHAN_SWITCH 5260 failed") if country == 'US': # For non EU we should start CAC again ev = wait_dfs_event(hapd, "DFS-CAC-START", 5) if not ev: raise Exception("No DFS CAC start event") else: # For EU preCAC should be used ev = wait_dfs_event(hapd, "AP-CSA-FINISHED", 5) if not ev: raise Exception("No CSA finished event - 5260") finally: clear_regdom(hapd, dev)
def set_reg(country_code, apdev0=None, apdev1=None, dev0=None): if apdev0: hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', country_code]) if apdev1: hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', country_code]) if dev0: dev0.cmd_execute(['iw', 'reg', 'set', country_code])
def test_ap_acs_vht40(dev, apdev): """Automatic channel selection for VHT40""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '0' params['acs_num_scans'] = '1' params['chanlist'] = '36 149' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") sec = hapd.get_status_field("secondary_channel") if int(sec) == 0: raise Exception("Secondary channel not set") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_acs_vht160(dev, apdev): """Automatic channel selection for VHT160""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'ZA' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '2' params["vht_oper_centr_freq_seg0_idx"] = "114" params['ieee80211d'] = '1' params['ieee80211h'] = '1' params['chanlist'] = '100' params['acs_num_scans'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) if not ev: raise Exception("ACS start timed out") # VHT160 is not currently supported in hostapd ACS, so do not try to # enforce successful AP start. if "AP-ENABLED" in ev: freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
def test_ap_acs_vht160(dev, apdev): """Automatic channel selection for VHT160""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'ZA' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '2' params["vht_oper_centr_freq_seg0_idx"] = "114" params['ieee80211d'] = '1' params['ieee80211h'] = '1' params['chanlist'] = '100' params['acs_num_scans'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) if not ev: raise Exception("ACS start timed out") # VHT160 is not currently supported in hostapd ACS, so do not try to # enforce successful AP start. if "AP-ENABLED" in ev: freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
def test_ap_acs_exclude_dfs(dev, apdev, params): """Automatic channel selection, exclude DFS""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211d'] = '1' params['ieee80211h'] = '1' params['acs_num_scans'] = '1' params['acs_exclude_dfs'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) state = hapd.get_status_field("state") if state != "ENABLED": raise Exception("Unexpected interface state") freq = int(hapd.get_status_field("freq")) if freq in [5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680]: raise Exception("Unexpected frequency: %d" % freq) dev[0].connect("test-acs", psk="12345678", scan_freq=str(freq)) dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].disconnect_and_stop_scan() hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def test_ap_acs_vht40(dev, apdev): """Automatic channel selection for VHT40""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '0' params['acs_num_scans'] = '1' params['chanlist'] = '36 149' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") sec = hapd.get_status_field("secondary_channel") if int(sec) == 0: raise Exception("Secondary channel not set") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].disconnect_and_stop_scan() hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def set_reg(country_code, apdev0=None, apdev1=None, dev0=None): if apdev0: hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', country_code]) if apdev1: hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', country_code]) if dev0: dev0.cmd_execute(['iw', 'reg', 'set', country_code])
def set_world_reg(apdev0=None, apdev1=None, dev0=None): if apdev0: hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', '00']) if apdev1: hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', '00']) if dev0: dev0.cmd_execute(['iw', 'reg', 'set', '00'])
def test_ap_acs_vht(dev, apdev): """Automatic channel selection for VHT""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") sec = hapd.get_status_field("secondary_channel") if int(sec) == 0: raise Exception("Secondary channel not set") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def set_world_reg(apdev0=None, apdev1=None, dev0=None): if apdev0: hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', '00']) if apdev1: hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', '00']) if dev0: dev0.cmd_execute(['iw', 'reg', 'set', '00'])
def test_ap_spectrum_management_required(dev, apdev): """Open AP with spectrum management required""" ssid = "spectrum mgmt" params = {} params['ssid'] = ssid params["country_code"] = "JP" params["hw_mode"] = "a" params["channel"] = "36" params["ieee80211d"] = "1" params["local_pwr_constraint"] = "3" params['spectrum_mgmt_required'] = "1" try: hapd = None hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180") dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].request("DISCONNECT") dev[0].request("ABORT_SCAN") dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def test_ap_acs_5ghz_40mhz(dev, apdev): """Automatic channel selection on 5 GHz for 40 MHz channel""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") sec = hapd.get_status_field("secondary_channel") if int(sec) == 0: raise Exception("Secondary channel not set") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].request("DISCONNECT") dev[0].request("ABORT_SCAN") dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def test_pmksa_cache_preauth_oom(dev, apdev): """RSN pre-authentication to generate PMKSA cache entry and OOM""" try: _test_pmksa_cache_preauth_oom(dev, apdev) finally: hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'down']) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0'])
def test_pmksa_cache_preauth_oom(dev, apdev): """RSN pre-authentication to generate PMKSA cache entry and OOM""" try: _test_pmksa_cache_preauth_oom(dev, apdev) finally: hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'down']) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0'])
def test_pmksa_cache_preauth_auto(dev, apdev): """RSN pre-authentication based on pre-connection scan results""" try: run_pmksa_cache_preauth_auto(dev, apdev) finally: hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'down', '2>', '/dev/null'], shell=True) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0', '2>', '/dev/null'], shell=True)
def _test_pmksa_cache_preauth_oom(dev, apdev): params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' hapd = hostapd.add_ap(apdev[0], params) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', 'ap-br0', '0']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) eap_connect(dev[0], hapd, "PAX", "*****@*****.**", password_hex="0123456789abcdef0123456789abcdef", bssid=apdev[0]['bssid']) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' params['rsn_preauth'] = '1' params['rsn_preauth_interfaces'] = 'ap-br0' hapd = hostapd.add_ap(apdev[1], params) bssid1 = apdev[1]['bssid'] tests = [(1, "rsn_preauth_receive"), (2, "rsn_preauth_receive"), (1, "rsn_preauth_send"), (1, "wpa_auth_pmksa_add_preauth;rsn_preauth_finished")] for test in tests: hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff") with alloc_fail(hapd, test[0], test[1]): dev[0].scan_for_bss(bssid1, freq="2412") if "OK" not in dev[0].request("PREAUTH " + bssid1): raise Exception("PREAUTH failed") success = False count = 0 for i in range(50): time.sleep(0.1) pmksa = dev[0].get_pmksa(bssid1) if pmksa: success = True break state = hapd.request('GET_ALLOC_FAIL') if state.startswith('0:'): count += 1 if count > 2: break logger.info("PMKSA cache success: " + str(success)) dev[0].request("PMKSA_FLUSH") dev[0].wait_disconnected() dev[0].wait_connected() dev[0].dump_monitor()
def test_ap_acs_vht160_dfs(dev, apdev, params): """Automatic channel selection 160 MHz, HT scan, and DFS [long]""" if not params['long']: raise HwsimSkip( "Skip test case with long duration due to --long not specified") try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '2' params['ieee80211d'] = '1' params['ieee80211h'] = '1' params['acs_num_scans'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd, return_after_acs=True) wait_dfs_event(hapd, "DFS-CAC-START", 5) ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) if "success=1" not in ev: raise Exception("CAC failed") ev = hapd.wait_event(["AP-ENABLED"], timeout=5) if not ev: raise Exception("AP setup timed out") state = hapd.get_status_field("state") if state != "ENABLED": raise Exception("Unexpected interface state") freq = int(hapd.get_status_field("freq")) if freq not in [5180, 5500]: raise Exception("Unexpected frequency: %d" % freq) dev[0].connect("test-acs", psk="12345678", scan_freq=str(freq)) dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].request("DISCONNECT") dev[0].request("ABORT_SCAN") dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def _test_pmksa_cache_preauth_oom(dev, apdev): params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' hapd = hostapd.add_ap(apdev[0], params) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', 'ap-br0', '0']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) eap_connect(dev[0], hapd, "PAX", "*****@*****.**", password_hex="0123456789abcdef0123456789abcdef", bssid=apdev[0]['bssid']) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' params['rsn_preauth'] = '1' params['rsn_preauth_interfaces'] = 'ap-br0' hapd = hostapd.add_ap(apdev[1], params) bssid1 = apdev[1]['bssid'] tests = [(1, "rsn_preauth_receive"), (2, "rsn_preauth_receive"), (1, "rsn_preauth_send"), (1, "wpa_auth_pmksa_add_preauth;rsn_preauth_finished")] for test in tests: hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff") with alloc_fail(hapd, test[0], test[1]): dev[0].scan_for_bss(bssid1, freq="2412") if "OK" not in dev[0].request("PREAUTH " + bssid1): raise Exception("PREAUTH failed") success = False count = 0 for i in range(50): time.sleep(0.1) pmksa = dev[0].get_pmksa(bssid1) if pmksa: success = True break state = hapd.request('GET_ALLOC_FAIL') if state.startswith('0:'): count += 1 if count > 2: break logger.info("PMKSA cache success: " + str(success)) dev[0].request("PMKSA_FLUSH") dev[0].wait_disconnected() dev[0].wait_connected() dev[0].dump_monitor()
def test_ap_acs_vht160_scan_disable(dev, apdev): """Automatic channel selection for VHT160 and DISABLE during scan""" force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'ZA' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '2' params["vht_oper_centr_freq_seg0_idx"] = "114" params['ieee80211d'] = '1' params['ieee80211h'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) time.sleep(3) hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
def test_ap_acs_vht160_scan_disable(dev, apdev): """Automatic channel selection for VHT160 and DISABLE during scan""" force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'ZA' params['ieee80211ac'] = '1' params['vht_oper_chwidth'] = '2' params["vht_oper_centr_freq_seg0_idx"] = "114" params['ieee80211d'] = '1' params['ieee80211h'] = '1' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) time.sleep(3) hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
def test_ap_acs_dfs(dev, apdev): """Automatic channel selection, HT scan, and DFS""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['ht_capab'] = '[HT40+]' params['country_code'] = 'US' params['ieee80211d'] = '1' params['ieee80211h'] = '1' params['acs_num_scans'] = '1' params['chanlist'] = '52 56 60 64' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd, return_after_acs=True) wait_dfs_event(hapd, "DFS-CAC-START", 5) ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) if "success=1" not in ev: raise Exception("CAC failed") ev = hapd.wait_event(["AP-ENABLED"], timeout=5) if not ev: raise Exception("AP setup timed out") state = hapd.get_status_field("state") if state != "ENABLED": raise Exception("Unexpected interface state") freq = int(hapd.get_status_field("freq")) if freq not in [5260, 5280, 5300, 5320]: raise Exception("Unexpected frequency: %d" % freq) dev[0].connect("test-acs", psk="12345678", scan_freq=str(freq)) dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].disconnect_and_stop_scan() hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def test_ap_spectrum_management_required(dev, apdev): """Open AP with spectrum management required""" ssid = "spectrum mgmt" params = {} params['ssid'] = ssid params["country_code"] = "JP" params["hw_mode"] = "a" params["channel"] = "36" params["ieee80211d"] = "1" params["local_pwr_constraint"] = "3" params['spectrum_mgmt_required'] = "1" try: hapd = None hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180") finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_spectrum_management_required(dev, apdev): """Open AP with spectrum management required""" ssid = "spectrum mgmt" params = {} params['ssid'] = ssid params["country_code"] = "JP" params["hw_mode"] = "a" params["channel"] = "36" params["ieee80211d"] = "1" params["local_pwr_constraint"] = "3" params['spectrum_mgmt_required'] = "1" try: hapd = None hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180") finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_country(dev, apdev): """WPA2-PSK AP setting country code and using 5 GHz band""" try: hapd = None bssid = apdev[0]['bssid'] ssid = "test-wpa2-psk" passphrase = 'qwertyuiop' params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params['country_code'] = 'FI' params['ieee80211d'] = '1' params['hw_mode'] = 'a' params['channel'] = '36' hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, psk=passphrase, scan_freq="5180") hwsim_utils.test_connectivity(dev[0], hapd) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_country(dev, apdev): """WPA2-PSK AP setting country code and using 5 GHz band""" try: hapd = None bssid = apdev[0]['bssid'] ssid = "test-wpa2-psk" passphrase = 'qwertyuiop' params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params['country_code'] = 'FI' params['ieee80211d'] = '1' params['hw_mode'] = 'a' params['channel'] = '36' hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, psk=passphrase, scan_freq="5180") hwsim_utils.test_connectivity(dev[0], hapd) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def clear_scan_cache(apdev): ifname = apdev['ifname'] hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'up']) hostapd.cmd_execute(apdev, ['iw', ifname, 'scan', 'trigger', 'freq', '2412', 'flush']) time.sleep(0.1) hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'down'])
def clear_scan_cache(apdev): ifname = apdev['ifname'] hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'up']) hostapd.cmd_execute( apdev, ['iw', ifname, 'scan', 'trigger', 'freq', '2412', 'flush']) time.sleep(0.1) hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'down'])
def test_ap_acs_5ghz(dev, apdev): """Automatic channel selection on 5 GHz""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['country_code'] = 'US' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_acs_5ghz(dev, apdev): """Automatic channel selection on 5 GHz""" try: hapd = None force_prev_ap_on_5g(apdev[0]) params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' params['country_code'] = 'US' hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) wait_acs(hapd) freq = hapd.get_status_field("freq") if int(freq) < 5000: raise Exception("Unexpected frequency") dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_ap_spectrum_management_required(dev, apdev): """Open AP with spectrum management required""" ssid = "spectrum mgmt" params = {} params['ssid'] = ssid params["country_code"] = "JP" params["hw_mode"] = "a" params["channel"] = "36" params["ieee80211d"] = "1" params["local_pwr_constraint"] = "3" params['spectrum_mgmt_required'] = "1" try: hapd = None hapd = hostapd.add_ap(apdev[0], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180") dev[0].wait_regdom(country_ie=True) finally: if hapd: hapd.request("DISABLE") dev[0].disconnect_and_stop_scan() hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00']) dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) dev[0].flush_scan_cache()
def test_ap_ht40_scan_not_affected(dev, apdev): """HT40 co-ex scan and other BSS not affected""" clear_scan_cache(apdev[0]) params = { "ssid": "test-ht20", "channel": "11" } hostapd.add_ap(apdev[1], params) hostapd.cmd_execute(apdev[0], ['ifconfig', apdev[0]['ifname'], 'up']) hostapd.cmd_execute(apdev[0], ['iw', apdev[0]['ifname'], 'scan', 'trigger', 'freq', '2462']) time.sleep(0.5) hostapd.cmd_execute(apdev[0], ['iw', apdev[0]['ifname'], 'scan', 'dump']) time.sleep(0.1) hostapd.cmd_execute(apdev[0], ['ifconfig', apdev[0]['ifname'], 'down']) params = { "ssid": "test-ht40", "channel": "1", "ht_capab": "[HT40+]"} hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) state = hapd.get_status_field("state") if state != "HT_SCAN": time.sleep(0.1) state = hapd.get_status_field("state") if state != "HT_SCAN": raise Exception("Unexpected interface state - expected HT_SCAN") ev = hapd.wait_event(["AP-ENABLED"], timeout=10) if not ev: raise Exception("AP setup timed out") state = hapd.get_status_field("state") if state != "ENABLED": raise Exception("Unexpected interface state - expected ENABLED") freq = hapd.get_status_field("freq") if freq != "2412": raise Exception("Unexpected frequency") pri = hapd.get_status_field("channel") if pri != "1": raise Exception("Unexpected primary channel") sec = hapd.get_status_field("secondary_channel") if sec != "1": raise Exception("Unexpected secondary channel: " + sec) dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
def generic_pmksa_cache_preauth(dev, apdev, extraparams, identity, databridge, force_disconnect=False): if not extraparams: extraparams = [{}, {}] try: params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' for key, value in extraparams[0].iteritems(): params[key] = value hapd = hostapd.add_ap(apdev[0], params) hapd.cmd_execute(['brctl', 'setfd', 'ap-br0', '0']) hapd.cmd_execute(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) eap_connect(dev[0], hapd, "PAX", identity, password_hex="0123456789abcdef0123456789abcdef") # Verify connectivity in the correct VLAN hwsim_utils.test_connectivity_iface(dev[0], hapd, databridge) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' params['rsn_preauth'] = '1' params['rsn_preauth_interfaces'] = databridge for key, value in extraparams[1].iteritems(): params[key] = value hostapd.add_ap(apdev[1], params) bssid1 = apdev[1]['bssid'] dev[0].scan(freq="2412") success = False status_seen = False for i in range(0, 50): if not status_seen: status = dev[0].request("STATUS") if "Pre-authentication EAPOL state machines:" in status: status_seen = True time.sleep(0.1) pmksa = dev[0].get_pmksa(bssid1) if pmksa: success = True break if not success: raise Exception( "No PMKSA cache entry created from pre-authentication") if not status_seen: raise Exception( "Pre-authentication EAPOL status was not available") dev[0].scan(freq="2412") if "[WPA2-EAP-CCMP-preauth]" not in dev[0].request("SCAN_RESULTS"): raise Exception("Scan results missing RSN element info") dev[0].request("ROAM " + bssid1) ev = dev[0].wait_event( ["CTRL-EVENT-EAP-STARTED", "CTRL-EVENT-CONNECTED"], timeout=10) if ev is None: raise Exception("Roaming with the AP timed out") if "CTRL-EVENT-EAP-STARTED" in ev: raise Exception("Unexpected EAP exchange") pmksa2 = dev[0].get_pmksa(bssid1) if pmksa2 is None: raise Exception("No PMKSA cache entry") if pmksa['pmkid'] != pmksa2['pmkid']: raise Exception("Unexpected PMKID change") # Verify connectivity in the correct VLAN hwsim_utils.test_connectivity_iface(dev[0], hapd, databridge) if not force_disconnect: return # Disconnect the STA from both APs to avoid forceful ifdown by the # test script on a VLAN that this has an associated STA. That used to # trigger a mac80211 warning. dev[0].request("DISCONNECT") hapd.request("DISABLE") finally: hostapd.cmd_execute( apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'down', '2>', '/dev/null'], shell=True) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0', '2>', '/dev/null'], shell=True)
def generic_pmksa_cache_preauth(dev, apdev, extraparams, identity, databridge, force_disconnect=False): if not extraparams: extraparams = [{}, {}] try: params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' for key, value in extraparams[0].items(): params[key] = value hapd = hostapd.add_ap(apdev[0], params) hapd.cmd_execute(['brctl', 'setfd', 'ap-br0', '0']) hapd.cmd_execute(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) eap_connect(dev[0], hapd, "PAX", identity, password_hex="0123456789abcdef0123456789abcdef") # Verify connectivity in the correct VLAN hwsim_utils.test_connectivity_iface(dev[0], hapd, databridge) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['bridge'] = 'ap-br0' params['rsn_preauth'] = '1' params['rsn_preauth_interfaces'] = databridge for key, value in extraparams[1].items(): params[key] = value hostapd.add_ap(apdev[1], params) bssid1 = apdev[1]['bssid'] dev[0].scan(freq="2412") success = False status_seen = False for i in range(0, 50): if not status_seen: status = dev[0].request("STATUS") if "Pre-authentication EAPOL state machines:" in status: status_seen = True time.sleep(0.1) pmksa = dev[0].get_pmksa(bssid1) if pmksa: success = True break if not success: raise Exception("No PMKSA cache entry created from pre-authentication") if not status_seen: raise Exception("Pre-authentication EAPOL status was not available") dev[0].scan(freq="2412") if "[WPA2-EAP-CCMP-preauth]" not in dev[0].request("SCAN_RESULTS"): raise Exception("Scan results missing RSN element info") dev[0].request("ROAM " + bssid1) ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED", "CTRL-EVENT-CONNECTED"], timeout=10) if ev is None: raise Exception("Roaming with the AP timed out") if "CTRL-EVENT-EAP-STARTED" in ev: raise Exception("Unexpected EAP exchange") pmksa2 = dev[0].get_pmksa(bssid1) if pmksa2 is None: raise Exception("No PMKSA cache entry") if pmksa['pmkid'] != pmksa2['pmkid']: raise Exception("Unexpected PMKID change") # Verify connectivity in the correct VLAN hwsim_utils.test_connectivity_iface(dev[0], hapd, databridge) if not force_disconnect: return # Disconnect the STA from both APs to avoid forceful ifdown by the # test script on a VLAN that this has an associated STA. That used to # trigger a mac80211 warning. dev[0].request("DISCONNECT") hapd.request("DISABLE") finally: hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'down', '2>', '/dev/null'], shell=True) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0', '2>', '/dev/null'], shell=True)