diff --git a/tests/hwsim/test_ap_acs.py b/tests/hwsim/test_ap_acs.py index dd506c130..c0b559bdb 100644 --- a/tests/hwsim/test_ap_acs.py +++ b/tests/hwsim/test_ap_acs.py @@ -98,6 +98,7 @@ def test_ap_acs_40mhz(dev, apdev): def test_ap_acs_5ghz(dev, apdev): """Automatic channel selection on 5 GHz""" try: + hapd = None params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' @@ -120,11 +121,16 @@ def test_ap_acs_5ghz(dev, apdev): dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + 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 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' @@ -152,11 +158,16 @@ def test_ap_acs_5ghz_40mhz(dev, apdev): dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_acs_vht(dev, apdev): """Automatic channel selection for VHT""" try: + hapd = None params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") params['hw_mode'] = 'a' params['channel'] = '0' @@ -186,4 +197,8 @@ def test_ap_acs_vht(dev, apdev): dev[0].connect("test-acs", psk="12345678", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() diff --git a/tests/hwsim/test_ap_ht.py b/tests/hwsim/test_ap_ht.py index 310001f00..fea1a78c3 100644 --- a/tests/hwsim/test_ap_ht.py +++ b/tests/hwsim/test_ap_ht.py @@ -178,12 +178,14 @@ def test_ap_ht40_5ghz_match(dev, apdev): """HT40 co-ex scan on 5 GHz with matching pri/sec channel""" clear_scan_cache(apdev[0]['ifname']) try: + hapd = None + hapd2 = None params = { "ssid": "test-ht40", "hw_mode": "a", "channel": "36", "country_code": "US", "ht_capab": "[HT40+]"} - hostapd.add_ap(apdev[1]['ifname'], params) + hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) params = { "ssid": "test-ht40", "hw_mode": "a", @@ -218,18 +220,26 @@ def test_ap_ht40_5ghz_match(dev, apdev): dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_ht40_5ghz_switch(dev, apdev): """HT40 co-ex scan on 5 GHz switching pri/sec channel""" clear_scan_cache(apdev[0]['ifname']) try: + hapd = None + hapd2 = None params = { "ssid": "test-ht40", "hw_mode": "a", "channel": "36", "country_code": "US", "ht_capab": "[HT40+]"} - hostapd.add_ap(apdev[1]['ifname'], params) + hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) params = { "ssid": "test-ht40", "hw_mode": "a", @@ -264,18 +274,25 @@ def test_ap_ht40_5ghz_switch(dev, apdev): dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) def test_ap_ht40_5ghz_switch2(dev, apdev): """HT40 co-ex scan on 5 GHz switching pri/sec channel (2)""" clear_scan_cache(apdev[0]['ifname']) try: + hapd = None + hapd2 = None params = { "ssid": "test-ht40", "hw_mode": "a", "channel": "36", "country_code": "US", "ht_capab": "[HT40+]"} - hostapd.add_ap(apdev[1]['ifname'], params) + hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) id = dev[0].add_network() dev[0].set_network(id, "mode", "2") @@ -319,7 +336,13 @@ def test_ap_ht40_5ghz_switch2(dev, apdev): dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_obss_scan(dev, apdev): """Overlapping BSS scan request""" @@ -447,6 +470,8 @@ def test_olbc(dev, apdev): def test_olbc_5ghz(dev, apdev): """OLBC detection on 5 GHz""" try: + hapd = None + hapd2 = None params = { "ssid": "test-olbc", "country_code": "FI", "hw_mode": "a", @@ -463,12 +488,16 @@ def test_olbc_5ghz(dev, apdev): "channel": "36", "ieee80211n": "0", "wmm_enabled": "0" } - hostapd.add_ap(apdev[1]['ifname'], params) + hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) time.sleep(0.5) status = hapd.get_status() if status['olbc_ht'] != '1': raise Exception("Missing OLBC information") finally: + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) def test_ap_require_ht(dev, apdev): @@ -601,6 +630,7 @@ def test_ap_ht40_csa(dev, apdev): if not csa_supported(dev[0]): return "skip" try: + hapd = None params = { "ssid": "ht", "country_code": "US", "hw_mode": "a", @@ -634,13 +664,18 @@ def test_ap_ht40_csa(dev, apdev): raise Exception("Unexpected STA disconnection during CSA") hwsim_utils.test_connectivity(dev[0], hapd) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_ht40_csa2(dev, apdev): """HT with 40 MHz channel width and CSA""" if not csa_supported(dev[0]): return "skip" try: + hapd = None params = { "ssid": "ht", "country_code": "US", "hw_mode": "a", @@ -674,13 +709,18 @@ def test_ap_ht40_csa2(dev, apdev): raise Exception("Unexpected STA disconnection during CSA") hwsim_utils.test_connectivity(dev[0], hapd) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_ht40_csa3(dev, apdev): """HT with 40 MHz channel width and CSA""" if not csa_supported(dev[0]): return "skip" try: + hapd = None params = { "ssid": "ht", "country_code": "US", "hw_mode": "a", @@ -714,4 +754,8 @@ def test_ap_ht40_csa3(dev, apdev): raise Exception("Unexpected STA disconnection during CSA") hwsim_utils.test_connectivity(dev[0], hapd) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() diff --git a/tests/hwsim/test_ap_params.py b/tests/hwsim/test_ap_params.py index 6658ec1db..5558ccf64 100644 --- a/tests/hwsim/test_ap_params.py +++ b/tests/hwsim/test_ap_params.py @@ -58,6 +58,7 @@ def test_ap_vendor_elements(dev, apdev): 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' @@ -70,7 +71,11 @@ def test_ap_country(dev, apdev): 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") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_acl_accept(dev, apdev): """MAC ACL accept list""" @@ -197,10 +202,15 @@ def test_ap_spectrum_management_required(dev, apdev): params["local_pwr_constraint"] = "3" params['spectrum_mgmt_required'] = "1" try: - hostapd.add_ap(apdev[0]['ifname'], params) + hapd = None + hapd = hostapd.add_ap(apdev[0]['ifname'], params) dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_max_listen_interval(dev, apdev): """Open AP with maximum listen interval limit""" diff --git a/tests/hwsim/test_ap_vht.py b/tests/hwsim/test_ap_vht.py index 41d64d237..a14f4e478 100644 --- a/tests/hwsim/test_ap_vht.py +++ b/tests/hwsim/test_ap_vht.py @@ -25,6 +25,7 @@ def vht_supported(): def test_ap_vht80(dev, apdev): """VHT with 80 MHz channel width""" try: + hapd = None params = { "ssid": "vht", "country_code": "FI", "hw_mode": "a", @@ -45,11 +46,16 @@ def test_ap_vht80(dev, apdev): return "skip" raise finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_vht80_params(dev, apdev): """VHT with 80 MHz channel width and number of optional features enabled""" try: + hapd = None params = { "ssid": "vht", "country_code": "FI", "hw_mode": "a", @@ -80,13 +86,20 @@ def test_ap_vht80_params(dev, apdev): return "skip" raise finally: + dev[0].request("DISCONNECT") + dev[1].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() + dev[1].flush_scan_cache() def test_ap_vht_20(devs, apdevs): """VHT and 20 MHz channel""" dev = devs[0] ap = apdevs[0] try: + hapd = None params = { "ssid": "test-vht20", "country_code": "DE", "hw_mode": "a", @@ -104,7 +117,11 @@ def test_ap_vht_20(devs, apdevs): dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE") hwsim_utils.test_connectivity(dev, hapd) finally: + dev.request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev.flush_scan_cache() def test_ap_vht_capab_not_supported(dev, apdev): """VHT configuration with driver not supporting all vht_capab entries""" @@ -133,6 +150,8 @@ def test_ap_vht_capab_not_supported(dev, apdev): def test_ap_vht160(dev, apdev): """VHT with 160 MHz channel width""" try: + hapd = None + hapd2 = None params = { "ssid": "vht", "country_code": "FI", "hw_mode": "a", @@ -235,11 +254,21 @@ def test_ap_vht160(dev, apdev): return "skip" raise finally: + dev[0].request("DISCONNECT") + dev[1].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() + dev[1].flush_scan_cache() def test_ap_vht80plus80(dev, apdev): """VHT with 80+80 MHz channel width""" try: + hapd = None + hapd2 = None params = { "ssid": "vht", "country_code": "US", "hw_mode": "a", @@ -295,13 +324,22 @@ def test_ap_vht80plus80(dev, apdev): return "skip" raise finally: + dev[0].request("DISCONNECT") + dev[1].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() + dev[1].flush_scan_cache() def test_ap_vht80_csa(dev, apdev): """VHT with 80 MHz channel width and CSA""" if not csa_supported(dev[0]): return "skip" try: + hapd = None params = { "ssid": "vht", "country_code": "US", "hw_mode": "a", @@ -345,4 +383,8 @@ def test_ap_vht80_csa(dev, apdev): return "skip" raise finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index 7a24ba291..60a830082 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -203,6 +203,7 @@ def test_ap_wps_conf(dev, apdev): def test_ap_wps_conf_5ghz(dev, apdev): """WPS PBC provisioning with configured AP on 5 GHz band""" try: + hapd = None ssid = "test-wps-conf" params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", @@ -221,11 +222,16 @@ def test_ap_wps_conf_5ghz(dev, apdev): if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": raise Exception("Device name not available in STA command") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_wps_conf_chan14(dev, apdev): """WPS PBC provisioning with configured AP on channel 14""" try: + hapd = None ssid = "test-wps-conf" params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", "wpa_passphrase": "12345678", "wpa": "2", @@ -243,7 +249,11 @@ def test_ap_wps_conf_chan14(dev, apdev): if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": raise Exception("Device name not available in STA command") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_ap_wps_twice(dev, apdev): """WPS provisioning with twice to change passphrase""" diff --git a/tests/hwsim/test_dfs.py b/tests/hwsim/test_dfs.py index 790baeb99..b51e10213 100644 --- a/tests/hwsim/test_dfs.py +++ b/tests/hwsim/test_dfs.py @@ -124,11 +124,16 @@ def test_dfs(dev, apdev): time.sleep(1) hwsim_utils.test_connectivity(dev[0], hapd) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_dfs_radar(dev, apdev): """DFS CAC functionality with radar detected""" try: + hapd2 = None hapd = start_dfs_ap(apdev[0]) if hapd is None: if not os.path.exists("dfs"): @@ -200,7 +205,13 @@ def test_dfs_radar(dev, apdev): wait_dfs_event(hapd2, None, 5) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_dfs_radar_on_non_dfs_channel(dev, apdev): """DFS radar detection test code on non-DFS channel""" @@ -241,7 +252,11 @@ def test_dfs_radar_chanlist(dev, apdev): raise Exception("Unexpected DFS event") dev[0].connect("dfs", key_mgmt="NONE") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_dfs_radar_chanlist_vht80(dev, apdev): """DFS chanlist when radar is detected and VHT80 configured""" @@ -277,7 +292,11 @@ def test_dfs_radar_chanlist_vht80(dev, apdev): if hapd.get_status_field('vht_oper_centr_freq_seg0_idx') != "42": raise Exception("Unexpected seg0 idx") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_dfs_radar_chanlist_vht20(dev, apdev): """DFS chanlist when radar is detected and VHT40 configured""" @@ -310,4 +329,8 @@ def test_dfs_radar_chanlist_vht20(dev, apdev): raise Exception("Unexpected DFS event") dev[0].connect("dfs", key_mgmt="NONE") finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() diff --git a/tests/hwsim/test_nfc_wps.py b/tests/hwsim/test_nfc_wps.py index 926dbe202..f39ea17c7 100644 --- a/tests/hwsim/test_nfc_wps.py +++ b/tests/hwsim/test_nfc_wps.py @@ -258,7 +258,11 @@ def test_nfc_wps_handover_5ghz(dev, apdev): raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], hapd, ssid) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_nfc_wps_handover_chan14(dev, apdev): """Connect to WPS AP with NFC connection handover on channel 14""" @@ -288,7 +292,11 @@ def test_nfc_wps_handover_chan14(dev, apdev): raise Exception("Association with the AP timed out") check_wpa2_connection(dev[0], apdev[0], hapd, ssid) finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache() def test_nfc_wps_handover_with_pw_token_set(dev, apdev): """Connect to WPS AP with NFC connection handover (wps_nfc_* set)""" diff --git a/tests/hwsim/test_p2p_channel.py b/tests/hwsim/test_p2p_channel.py index 2138d89d9..79cadddd6 100644 --- a/tests/hwsim/test_p2p_channel.py +++ b/tests/hwsim/test_p2p_channel.py @@ -38,6 +38,7 @@ def test_p2p_channel_5ghz(dev): remove_group(dev[0], dev[1]) finally: set_country("00") + dev[1].flush_scan_cache() def test_p2p_channel_5ghz_no_vht(dev): """P2P group formation with 5 GHz preference when VHT channels are disallowed""" @@ -55,6 +56,7 @@ def test_p2p_channel_5ghz_no_vht(dev): finally: set_country("00") dev[0].request("P2P_SET disallow_freq ") + dev[1].flush_scan_cache() def test_p2p_channel_random_social(dev): """P2P group formation with 5 GHz preference but all 5 GHz channels disabled""" @@ -73,6 +75,7 @@ def test_p2p_channel_random_social(dev): finally: set_country("00") dev[0].request("P2P_SET disallow_freq ") + dev[1].flush_scan_cache() def test_p2p_channel_random(dev): """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled""" @@ -91,6 +94,7 @@ def test_p2p_channel_random(dev): finally: set_country("00") dev[0].request("P2P_SET disallow_freq ") + dev[1].flush_scan_cache() def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params): """P2P group formation using random social channel with oper class change needed""" @@ -146,6 +150,7 @@ def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params): dev[0].request("P2P_SET disallow_freq ") dev[0].request("SET p2p_oper_reg_class 0") dev[0].request("SET p2p_oper_channel 0") + dev[1].flush_scan_cache() def test_p2p_channel_avoid(dev): """P2P and avoid frequencies driver event""" @@ -184,6 +189,7 @@ def test_p2p_channel_avoid(dev): finally: set_country("00") dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES") + dev[1].flush_scan_cache() def test_autogo_following_bss(dev, apdev): """P2P autonomous GO operate on the same channel as station interface""" @@ -372,6 +378,11 @@ def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev): raise Exception("GO not selected according to go_intent") hwsim_utils.test_connectivity(wpas, hapd) + wpas.request("DISCONNECT") + hapd.request("DISABLE") + subprocess.call(['iw', 'reg', 'set', '00']) + wpas.flush_scan_cache() + def test_go_pref_chan_bss_on_diff_chan(dev, apdev): """P2P channel selection: Station on different channel than GO configured pref channel""" diff --git a/tests/hwsim/test_wnm.py b/tests/hwsim/test_wnm.py index d18e1ac30..1e87d411d 100644 --- a/tests/hwsim/test_wnm.py +++ b/tests/hwsim/test_wnm.py @@ -397,6 +397,8 @@ def test_wnm_bss_keep_alive(dev, apdev): def test_wnm_bss_tm(dev, apdev): """WNM BSS Transition Management""" try: + hapd = None + hapd2 = None params = { "ssid": "test-wnm", "country_code": "FI", "ieee80211d": "1", @@ -491,4 +493,10 @@ def test_wnm_bss_tm(dev, apdev): if ev is not None: raise Exception("Unexpected reassociation"); finally: + dev[0].request("DISCONNECT") + if hapd: + hapd.request("DISABLE") + if hapd2: + hapd2.request("DISABLE") subprocess.call(['iw', 'reg', 'set', '00']) + dev[0].flush_scan_cache()