def test_connect_cmd_concurrent_grpform_while_connecting(dev, apdev): """Concurrent P2P group formation while connecting to an AP using cfg80211 connect command""" logger.info("Start connection to an infrastructure AP") hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("test-open", key_mgmt="NONE", wait_connect=False) wpas.dump_monitor() logger.info("Form a P2P group while connecting to an AP") wpas.request("SET p2p_no_group_iface 0") [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412, r_dev=wpas, r_freq=2412) check_grpform_results(i_res, r_res) remove_group(dev[0], wpas) wpas.dump_monitor() logger.info("Confirm AP connection after P2P group removal") hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_ext_password_psk_not_found(dev, apdev): """External password storage for PSK and PSK not found""" params = hostapd.wpa2_params(ssid="ext-pw-psk", passphrase="12345678") hostapd.add_ap(apdev[0]['ifname'], params) dev[0].request("SET ext_password_backend test:psk1=12345678") dev[0].connect("ext-pw-psk", raw_psk="ext:psk2", scan_freq="2412", wait_connect=False) dev[1].request("SET ext_password_backend test:psk1=1234567") dev[1].connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412", wait_connect=False) dev[2].request("SET ext_password_backend test:psk1=1234567890123456789012345678901234567890123456789012345678901234567890") dev[2].connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412", wait_connect=False) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.request("SET ext_password_backend test:psk1=123456789012345678901234567890123456789012345678901234567890123q") wpas.connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412", wait_connect=False) ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected association") ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected association") ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected association") ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected association")
def test_connect_cmd_disconnect_event(dev, apdev): """Connection using cfg80211 connect command getting disconnected by the AP""" params = {"ssid": "sta-connect"} hapd = hostapd.add_ap(apdev[0], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") if "OK" not in hapd.request("DEAUTHENTICATE " + wpas.p2p_interface_addr()): raise Exception("DEAUTHENTICATE command failed") ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5) if ev is None: raise Exception("Disconnection event timed out") # This event was actually based on deauthenticate event since we force # connect command to be used with a driver that supports auth+assoc for # testing purposes. Anyway, wait some time to allow the debug log to capture # the following NL80211_CMD_DISCONNECT event. time.sleep(0.1) wpas.dump_monitor() # Clean up to avoid causing issue for following test cases wpas.request("REMOVE_NETWORK all") wpas.wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=2) wpas.flush_scan_cache() wpas.dump_monitor() wpas.interface_remove("wlan5") del wpas
def test_connect_cmd_wep_shared(dev, apdev): """WEP Shared key using cfg80211 connect command""" params = { "ssid": "sta-connect-wep", "wep_key0": '"hello"', "auth_algs": "2" } hapd = hostapd.add_ap(apdev[0], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") id = wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", auth_alg="SHARED", wep_key0='"hello"') wpas.dump_monitor() hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT") wpas.remove_network(id) wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", auth_alg="OPEN SHARED", wep_key0='"hello"') wpas.dump_monitor() hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_autogo_with_bss_on_disallowed_chan(dev, apdev): """P2P channel selection: Autonomous GO with BSS on a disallowed channel""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.request("SET p2p_no_group_iface 0") if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") try: hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz', "channel": '1' }) wpas.request("P2P_SET disallow_freq 2412") wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") res = autogo(wpas) if res['freq'] == "2412": raise Exception("GO set on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) finally: wpas.request("P2P_SET disallow_freq ")
def test_sta_dynamic_ext_mac_addr_change(dev, apdev): """Dynamically added wpa_supplicant interface with external MAC address change""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412") hwsim_utils.test_connectivity(wpas, hapd) subprocess.call(['ifconfig', wpas.ifname, 'down']) wpas.wait_disconnected(timeout=10) if wpas.get_status_field("wpa_state") != "INTERFACE_DISABLED": raise Exception("Unexpected wpa_state") prev_addr = wpas.p2p_interface_addr() new_addr = '02:11:22:33:44:55' try: subprocess.call( ['ip', 'link', 'set', 'dev', wpas.ifname, 'address', new_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up']) wpas.wait_connected(timeout=15, error="Reconnection not reported") if wpas.get_driver_status_field('addr') != new_addr: raise Exception("Address change not reported") hwsim_utils.test_connectivity(wpas, hapd) sta = hapd.get_sta(new_addr) if sta['addr'] != new_addr: raise Exception("STA association with new address not found") finally: subprocess.call(['ifconfig', wpas.ifname, 'down']) subprocess.call( ['ip', 'link', 'set', 'dev', wpas.ifname, 'address', prev_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up'])
def _test_ap_open_wpas_in_bridge(dev, apdev): hapd = hostapd.add_ap(apdev[0], {"ssid": "open"}) br_ifname = 'sta-br0' ifname = 'wlan5' wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') # First, try a failure case of adding an interface try: wpas.interface_add(ifname, br_ifname=br_ifname) raise Exception("Interface addition succeeded unexpectedly") except Exception as e: if "Failed to add" in str(e): logger.info( "Ignore expected interface_add failure due to missing bridge interface: " + str(e)) else: raise # Next, add the bridge interface and add the interface again subprocess.call(['brctl', 'addbr', br_ifname]) subprocess.call(['brctl', 'setfd', br_ifname, '0']) subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) subprocess.call(['iw', ifname, 'set', '4addr', 'on']) subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) wpas.interface_add(ifname, br_ifname=br_ifname) wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
def test_go_neg_with_bss_on_disallowed_chan(dev, apdev): """P2P channel selection: GO negotiation with station interface on a disallowed channel""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.request("SET p2p_no_group_iface 0") if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") try: hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz', "channel": '1' }) # make sure PBC overlap from old test cases is not maintained dev[1].flush_scan_cache() wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") wpas.request("P2P_SET disallow_freq 2412") #wpas as GO [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1], r_intent=1) check_grpform_results(i_res, r_res) if i_res['role'] != "GO": raise Exception("GO not selected according to go_intent") if i_res['freq'] == "2412": raise Exception("Group formed on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) wpas.remove_group(i_res['ifname']) dev[1].wait_go_ending_session() dev[1].flush_scan_cache() wpas.dump_monitor() dev[1].dump_monitor() #wpas as client [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1], r_intent=10) check_grpform_results(i_res2, r_res2) if i_res2['role'] != "client": raise Exception("GO not selected according to go_intent") if i_res2['freq'] == "2412": raise Exception("Group formed on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) dev[1].remove_group(r_res2['ifname']) wpas.wait_go_ending_session() ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5) if ev is None: raise Exception("Group removal not indicated") wpas.request("DISCONNECT") hapd.disable() finally: wpas.request("P2P_SET disallow_freq ")
def test_pasn_sae_while_connected_diff_channel(dev, apdev): """PASN SAE authentication while connected diff channel""" check_pasn_capab(dev[0]) check_sae_capab(dev[0]) with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise HwsimSkip("PASN: New radio does not support MCC") params = hostapd.wpa2_params(ssid="test-pasn-wpa2-psk", passphrase="12345678") params['channel'] = "6" hapd = hostapd.add_ap(apdev[0], params) wpas.connect("test-pasn-wpa2-psk", psk="12345678", scan_freq="2437") params = hostapd.wpa2_params(ssid="test-pasn-sae", passphrase="12345678") params['wpa_key_mgmt'] = 'SAE PASN' hapd = start_pasn_ap(apdev[1], params) wpas.connect("test-pasn-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412", only_add_network=True) check_pasn_akmp_cipher(wpas, hapd, "SAE", "CCMP", nid="1")
def test_autogo_force_diff_channel(dev, apdev): """P2P autonomous GO and station interface operate on different channels""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") wpas.request("SET p2p_no_group_iface 0") hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'ap-test', "channel": '1' }) wpas.connect("ap-test", key_mgmt="NONE", scan_freq="2412") wpas.dump_monitor() channels = {2: 2417, 5: 2432, 9: 2452} for key in channels: res_go = autogo(wpas, channels[key]) wpas.dump_monitor() hwsim_utils.test_connectivity(wpas, hapd) if int(res_go['freq']) == 2412: raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq']) wpas.remove_group(res_go['ifname']) wpas.dump_monitor()
def _test_ap_open_wpas_in_bridge(dev, apdev): hapd = hostapd.add_ap(apdev[0], {"ssid": "open"}) br_ifname = 'sta-br0' ifname = 'wlan5' wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') # First, try a failure case of adding an interface try: wpas.interface_add(ifname, br_ifname=br_ifname) raise Exception("Interface addition succeeded unexpectedly") except Exception as e: if "Failed to add" in str(e): logger.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e)) else: raise # Next, add the bridge interface and add the interface again subprocess.call(['brctl', 'addbr', br_ifname]) subprocess.call(['brctl', 'setfd', br_ifname, '0']) subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) subprocess.call(['iw', ifname, 'set', '4addr', 'on']) subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) wpas.interface_add(ifname, br_ifname=br_ifname) wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
def run_multi_ap_backhaul_roam_with_bridge(dev, apdev): br_ifname = 'sta-br0' ifname = 'wlan5' wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') subprocess.call(['brctl', 'addbr', br_ifname]) subprocess.call(['brctl', 'setfd', br_ifname, '0']) subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) subprocess.call(['iw', ifname, 'set', '4addr', 'on']) subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) wpas.interface_add(ifname, br_ifname=br_ifname) wpas.flush_scan_cache() params = hostapd.wpa2_params(ssid="multi-ap", passphrase="12345678") params["multi_ap"] = "1" hapd = hostapd.add_ap(apdev[0], params) wpas.connect("multi-ap", psk="12345678", scan_freq="2412", multi_ap_backhaul_sta="1") hapd2 = hostapd.add_ap(apdev[1], params) bssid2 = hapd2.own_addr() wpas.scan_for_bss(bssid2, freq="2412", force_scan=True) wpas.roam(bssid2)
def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev): """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") wpas.request("SET p2p_no_group_iface 0") try: hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz', "channel": '1' }) wpas.request("P2P_SET disallow_freq 2412") wpas.request("SET p2p_pref_chan 81:2") wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") res2 = autogo(wpas) if res2['freq'] != "2417": raise Exception( "GO channel did not follow pref_chan configuration") hwsim_utils.test_connectivity(wpas, hapd) finally: wpas.request("P2P_SET disallow_freq ") wpas.request("SET p2p_pref_chan ")
def test_sta_dynamic_ext_mac_addr_change(dev, apdev): """Dynamically added wpa_supplicant interface with external MAC address change""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412") hwsim_utils.test_connectivity(wpas, hapd) subprocess.call(['ifconfig', wpas.ifname, 'down']) wpas.wait_disconnected(timeout=10) if wpas.get_status_field("wpa_state") != "INTERFACE_DISABLED": raise Exception("Unexpected wpa_state") prev_addr = wpas.p2p_interface_addr() new_addr = '02:11:22:33:44:55' try: subprocess.call(['ip', 'link', 'set', 'dev', wpas.ifname, 'address', new_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up']) wpas.wait_connected(timeout=15, error="Reconnection not reported") if wpas.get_driver_status_field('addr') != new_addr: raise Exception("Address change not reported") hwsim_utils.test_connectivity(wpas, hapd) sta = hapd.get_sta(new_addr) if sta['addr'] != new_addr: raise Exception("STA association with new address not found") finally: subprocess.call(['ifconfig', wpas.ifname, 'down']) subprocess.call(['ip', 'link', 'set', 'dev', wpas.ifname, 'address', prev_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up'])
def test_connect_cmd_concurrent_grpform_while_connecting(dev, apdev): """Concurrent P2P group formation while connecting to an AP using cfg80211 connect command""" logger.info("Start connection to an infrastructure AP") hapd = hostapd.add_ap(apdev[0], {"ssid": "test-open"}) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("test-open", key_mgmt="NONE", wait_connect=False) wpas.dump_monitor() logger.info("Form a P2P group while connecting to an AP") wpas.request("SET p2p_no_group_iface 0") [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412, r_dev=wpas, r_freq=2412) check_grpform_results(i_res, r_res) remove_group(dev[0], wpas) wpas.dump_monitor() logger.info("Confirm AP connection after P2P group removal") hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_connect_cmd_open(dev, apdev): """Open connection using cfg80211 connect command""" params = { "ssid": "sta-connect" } hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.request("DISCONNECT")
def test_connect_cmd_wpa2_psk(dev, apdev): """WPA2-PSK connection using cfg80211 connect command""" params = hostapd.wpa2_params(ssid="sta-connect", passphrase="12345678") hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", psk="12345678", scan_freq="2412") wpas.request("DISCONNECT")
def test_connect_cmd_open(dev, apdev): """Open connection using cfg80211 connect command""" params = {"ssid": "sta-connect"} hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.request("DISCONNECT")
def test_pmksa_cache_multiple_sta(dev, apdev): """PMKSA cache with multiple stations""" params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") hostapd.add_ap(apdev[0]['ifname'], params) bssid = apdev[0]['bssid'] dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk-user-session-timeout", password="******", scan_freq="2412") dev[1].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk user", password="******", scan_freq="2412") dev[2].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk-user-session-timeout", password="******", scan_freq="2412") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk user", password="******", scan_freq="2412") hostapd.add_ap(apdev[1]['ifname'], params) bssid2 = apdev[1]['bssid'] logger.info("Roam to AP2") for sta in [ dev[1], dev[0], dev[2], wpas ]: sta.dump_monitor() sta.scan_for_bss(bssid2, freq="2412") sta.request("ROAM " + bssid2) ev = sta.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10) if ev is None: raise Exception("EAP success timed out") sta.wait_connected(timeout=10, error="Roaming timed out") logger.info("Roam back to AP1") for sta in [ dev[1], wpas, dev[0], dev[2] ]: sta.dump_monitor() sta.scan(freq="2412") sta.dump_monitor() sta.request("ROAM " + bssid) sta.wait_connected(timeout=10, error="Roaming timed out") sta.dump_monitor() time.sleep(4) logger.info("Roam back to AP2") for sta in [ dev[1], wpas, dev[0], dev[2] ]: sta.dump_monitor() sta.scan(freq="2412") sta.dump_monitor() sta.request("ROAM " + bssid2) sta.wait_connected(timeout=10, error="Roaming timed out") sta.dump_monitor()
def test_p2p_device_misuses(dev, apdev): """cfg80211 P2P Device misuses""" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }) with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) # Add a normal network profile to the P2P Device management only # interface to verify that it does not get used. id = int(wpas.global_request('IFNAME=p2p-dev-%s ADD_NETWORK' % iface).strip()) wpas.global_request('IFNAME=p2p-dev-%s SET_NETWORK %d ssid "open"' % (iface, id)) wpas.global_request('IFNAME=p2p-dev-%s SET_NETWORK %d key_mgmt NONE' % (iface, id)) wpas.global_request('IFNAME=p2p-dev-%s ENABLE_NETWORK %d' % (iface, id)) # Scan requests get ignored on p2p-dev wpas.global_request('IFNAME=p2p-dev-%s SCAN' % iface) dev[0].p2p_start_go(freq=2412) addr = dev[0].p2p_interface_addr() wpas.scan_for_bss(addr, freq=2412) wpas.connect("open", key_mgmt="NONE", scan_freq="2412") hwsim_utils.test_connectivity(wpas, hapd) pin = wpas.wps_read_pin() dev[0].p2p_go_authorize_client(pin) res = wpas.p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60, social=True, freq=2412) hwsim_utils.test_connectivity_p2p(dev[0], wpas) # Optimize scan-after-disconnect wpas.group_request("SET_NETWORK 0 scan_freq 2412") dev[0].request("DISASSOCIATE " + wpas.p2p_interface_addr()) ev = wpas.wait_group_event(["CTRL-EVENT-DISCONNECT"]) if ev is None: raise Exception("Did not see disconnect event on P2P group interface") dev[0].remove_group() ev = wpas.wait_group_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5) if ev is None: raise Exception("Scan not started") ev = wpas.wait_group_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=15) if ev is None: raise Exception("Scan not completed") time.sleep(1) hwsim_utils.test_connectivity(wpas, hapd) ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=0.1) if ev is not None: raise Exception("Unexpected disconnection event received from hostapd") ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected disconnection event received from wpa_supplicant") wpas.request("DISCONNECT") wpas.wait_disconnected()
def test_sta_dynamic(dev, apdev): """Dynamically added wpa_supplicant interface""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hostapd.add_ap(apdev[0]['ifname'], params) logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412")
def test_pmksa_cache_opportunistic_connect(dev, apdev): """Opportunistic PMKSA caching with connect API""" params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") params['okc'] = "1" hostapd.add_ap(apdev[0], params) bssid = apdev[0]['bssid'] wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk user", password="******", okc=True, scan_freq="2412") pmksa = wpas.get_pmksa(bssid) if pmksa is None: raise Exception("No PMKSA cache entry created") if pmksa['opportunistic'] != '0': raise Exception("Unexpected opportunistic PMKSA cache entry") hostapd.add_ap(apdev[1], params) bssid2 = apdev[1]['bssid'] wpas.dump_monitor() logger.info("Roam to AP2") wpas.scan_for_bss(bssid2, freq="2412", force_scan=True) wpas.request("ROAM " + bssid2) ev = wpas.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 = wpas.get_pmksa(bssid2) if pmksa2 is None: raise Exception("No PMKSA cache entry created") wpas.dump_monitor() logger.info("Roam back to AP1") wpas.scan(freq="2412") wpas.request("ROAM " + bssid) ev = wpas.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") pmksa1b = wpas.get_pmksa(bssid) if pmksa1b is None: raise Exception("No PMKSA cache entry found") if pmksa['pmkid'] != pmksa1b['pmkid']: raise Exception("Unexpected PMKID change for AP1")
def test_go_neg_with_bss_on_disallowed_chan(dev, apdev): """P2P channel selection: GO negotiation with station interface on a disallowed channel""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.global_request("SET p2p_no_group_iface 0") if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") try: hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz', "channel": '1' }) # make sure PBC overlap from old test cases is not maintained dev[1].flush_scan_cache() wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") wpas.global_request("P2P_SET disallow_freq 2412") #wpas as GO [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1], r_intent=1) check_grpform_results(i_res, r_res) if i_res['role'] != "GO": raise Exception("GO not selected according to go_intent") if i_res['freq'] == "2412": raise Exception("Group formed on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) wpas.remove_group(i_res['ifname']) dev[1].wait_go_ending_session() dev[1].flush_scan_cache() wpas.dump_monitor() dev[1].dump_monitor() #wpas as client [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1], r_intent=10) check_grpform_results(i_res2, r_res2) if i_res2['role'] != "client": raise Exception("GO not selected according to go_intent") if i_res2['freq'] == "2412": raise Exception("Group formed on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) dev[1].remove_group(r_res2['ifname']) wpas.wait_go_ending_session() ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5) if ev is None: raise Exception("Group removal not indicated") wpas.request("DISCONNECT") hapd.disable() finally: wpas.global_request("P2P_SET disallow_freq ")
def test_connect_cmd_wep(dev, apdev): """WEP Open System using cfg80211 connect command""" params = { "ssid": "sta-connect-wep", "wep_key0": '"hello"' } hapd = hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", wep_key0='"hello"') hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT")
def test_sta_dynamic_ext_mac_addr_change_for_connection(dev, apdev): """Dynamically added wpa_supplicant interface with external MAC address change for connection""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) bssid = apdev[0]['ifname'] wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.scan_for_bss(bssid, freq=2412) subprocess.call(['ifconfig', wpas.ifname, 'down']) if wpas.get_status_field("wpa_state") != "INTERFACE_DISABLED": raise Exception("Unexpected wpa_state") prev_addr = wpas.own_addr() new_addr = '02:11:22:33:44:55' try: subprocess.call( ['ip', 'link', 'set', 'dev', wpas.ifname, 'address', new_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up']) wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412", wait_connect=False) ev = wpas.wait_event( ["CTRL-EVENT-CONNECTED", "CTRL-EVENT-SCAN-RESULTS"], timeout=10) if "CTRL-EVENT-SCAN-RESULTS" in ev: raise Exception("Unexpected scan after MAC address change") hapd.wait_sta() hwsim_utils.test_connectivity(wpas, hapd) sta = hapd.get_sta(new_addr) if sta['addr'] != new_addr: raise Exception("STA association with new address not found") wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor() subprocess.call(['ifconfig', wpas.ifname, 'down']) time.sleep(0.1) res = wpas.get_bss(bssid) if res is None: raise Exception( "BSS entry not maintained after interface disabling") ev = wpas.wait_event(["CTRL-EVENT-BSS-REMOVED"], timeout=5.5) if ev is None: raise Exception( "BSS entry not removed after interface has been disabled for a while" ) res2 = wpas.get_bss(bssid) if res2 is not None: raise Exception( "Unexpected BSS entry found on a disabled interface") finally: subprocess.call(['ifconfig', wpas.ifname, 'down']) subprocess.call( ['ip', 'link', 'set', 'dev', wpas.ifname, 'address', prev_addr]) subprocess.call(['ifconfig', wpas.ifname, 'up'])
def test_connect_cmd_roam(dev, apdev): """cfg80211 connect command to trigger roam""" params = {"ssid": "sta-connect"} hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") hostapd.add_ap(apdev[1]['ifname'], params) wpas.scan_for_bss(apdev[1]['bssid'], freq=2412) wpas.roam(apdev[1]['bssid'])
def test_connect_cmd_roam(dev, apdev): """cfg80211 connect command to trigger roam""" params = { "ssid": "sta-connect" } hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") hostapd.add_ap(apdev[1]['ifname'], params) wpas.scan_for_bss(apdev[1]['bssid'], freq=2412) wpas.roam(apdev[1]['bssid'])
def test_he_wifi_generation(dev, apdev): """HE and wifi_generation""" try: hapd = None params = { "ssid": "he", "country_code": "FI", "hw_mode": "a", "channel": "36", "ht_capab": "[HT40+]", "ieee80211n": "1", "ieee80211ac": "1", "ieee80211ax": "1", "vht_oper_chwidth": "1", "vht_capab": "[MAX-MPDU-11454]", "vht_oper_centr_freq_seg0_idx": "42", "he_oper_chwidth": "1", "he_oper_centr_freq_seg0_idx": "42" } hapd = hostapd.add_ap(apdev[0], params) bssid = apdev[0]['bssid'] dev[0].connect("he", key_mgmt="NONE", scan_freq="5180") status = dev[0].get_status() if 'wifi_generation' not in status: # For now, assume this is because of missing kernel support raise HwsimSkip("Association Request IE reporting not supported") #raise Exception("Missing wifi_generation information") if status['wifi_generation'] != "6": raise Exception("Unexpected wifi_generation value: " + status['wifi_generation']) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("he", key_mgmt="NONE", scan_freq="5180") status = wpas.get_status() if 'wifi_generation' not in status: # For now, assume this is because of missing kernel support raise HwsimSkip("Association Request IE reporting not supported") #raise Exception("Missing wifi_generation information (connect)") if status['wifi_generation'] != "6": raise Exception("Unexpected wifi_generation value (connect): " + status['wifi_generation']) except Exception as e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not he_supported(): raise HwsimSkip( "80 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") clear_regdom(hapd, dev)
def test_connect_cmd_wep(dev, apdev): """WEP Open System using cfg80211 connect command""" params = {"ssid": "sta-connect-wep", "wep_key0": '"hello"'} hapd = hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", wep_key0='"hello"') hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT")
def test_pmksa_cache_opportunistic_connect(dev, apdev): """Opportunistic PMKSA caching with connect API""" params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") params['okc'] = "1" hostapd.add_ap(apdev[0]['ifname'], params) bssid = apdev[0]['bssid'] wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", eap="GPSK", identity="gpsk user", password="******", okc=True, scan_freq="2412") pmksa = wpas.get_pmksa(bssid) if pmksa is None: raise Exception("No PMKSA cache entry created") if pmksa['opportunistic'] != '0': raise Exception("Unexpected opportunistic PMKSA cache entry") hostapd.add_ap(apdev[1]['ifname'], params) bssid2 = apdev[1]['bssid'] wpas.dump_monitor() logger.info("Roam to AP2") wpas.scan(freq="2412") wpas.request("ROAM " + bssid2) ev = wpas.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 = wpas.get_pmksa(bssid2) if pmksa2 is None: raise Exception("No PMKSA cache entry created") wpas.dump_monitor() logger.info("Roam back to AP1") wpas.scan(freq="2412") wpas.request("ROAM " + bssid) ev = wpas.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") pmksa1b = wpas.get_pmksa(bssid) if pmksa1b is None: raise Exception("No PMKSA cache entry found") if pmksa['pmkid'] != pmksa1b['pmkid']: raise Exception("Unexpected PMKID change for AP1")
def test_connect_cmd_p2p_management(dev, apdev): """Open connection using cfg80211 connect command and AP using P2P management""" params = {"ssid": "sta-connect", "manage_p2p": "1", "allow_cross_connection": "0"} hostapd.add_ap(apdev[0], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.dump_monitor() wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_connect_cmd_p2p_management(dev, apdev): """Open connection using cfg80211 connect command and AP using P2P management""" params = { "ssid": "sta-connect", "manage_p2p": "1", "allow_cross_connection": "0" } hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.dump_monitor() wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev): """P2P channel selection: GO negotiation with forced freq different than station interface""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") # Clear possible PBC session overlap from previous test case dev[1].flush_scan_cache() wpas.request("SET p2p_no_group_iface 0") hapd = hostapd.add_ap(apdev[0]['ifname'], { "country_code": 'US', "ssid": 'bss-5ghz', "hw_mode": 'a', "channel": '40' }) wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200") # GO and peer force the same freq, different than BSS freq, # wpas to become GO [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180, r_dev=wpas, r_intent=14, r_freq=5180) check_grpform_results(i_res, r_res) if i_res['freq'] != "5180": raise Exception("P2P group formed on unexpected frequency: " + i_res['freq']) if r_res['role'] != "GO": raise Exception("GO not selected according to go_intent") hwsim_utils.test_connectivity(wpas, hapd) wpas.remove_group(r_res['ifname']) dev[1].wait_go_ending_session() dev[1].flush_scan_cache() # GO and peer force the same freq, different than BSS freq, wpas to # become client [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422, r_dev=wpas, r_intent=1, r_freq=2422) check_grpform_results(i_res2, r_res2) if i_res2['freq'] != "2422": raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq']) if r_res2['role'] != "client": 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_neg_forced_freq_diff_than_bss_freq(dev, apdev): """P2P channel selection: GO negotiation with forced freq different than station interface""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") # Clear possible PBC session overlap from previous test case dev[1].flush_scan_cache() wpas.global_request("SET p2p_no_group_iface 0") hapd = hostapd.add_ap(apdev[0], { "country_code": 'US', "ssid": 'bss-5ghz', "hw_mode": 'a', "channel": '40' }) wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200") # GO and peer force the same freq, different than BSS freq, # wpas to become GO [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180, r_dev=wpas, r_intent=14, r_freq=5180) check_grpform_results(i_res, r_res) if i_res['freq'] != "5180": raise Exception("P2P group formed on unexpected frequency: " + i_res['freq']) if r_res['role'] != "GO": raise Exception("GO not selected according to go_intent") hwsim_utils.test_connectivity(wpas, hapd) wpas.remove_group(r_res['ifname']) dev[1].wait_go_ending_session() dev[1].flush_scan_cache() # GO and peer force the same freq, different than BSS freq, wpas to # become client [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422, r_dev=wpas, r_intent=1, r_freq=2422) check_grpform_results(i_res2, r_res2) if i_res2['freq'] != "2422": raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq']) if r_res2['role'] != "client": 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_ap_roam_with_reassoc_auth_timeout(dev, apdev, params): """Roam using reassoc between two APs and authentication times out""" wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1,force_bss_selection=1") params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() id = wpas.connect("test-wpa2-psk", psk="12345678", scan_freq="2412") hapd0.wait_sta() hwsim_utils.test_connectivity(wpas, hapd0) hapd1 = hostapd.add_ap(apdev[1], params) bssid1 = hapd1.own_addr() wpas.scan_for_bss(bssid1, freq=2412) if "OK" not in wpas.request("SET_NETWORK " + str(id) + " bssid " + bssid1): raise Exception("SET_NETWORK failed") if "OK" not in wpas.request("SET ignore_auth_resp 1"): raise Exception("SET ignore_auth_resp failed") if "OK" not in wpas.request("REASSOCIATE"): raise Exception("REASSOCIATE failed") logger.info("Wait ~10s for auth timeout...") time.sleep(10) ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12) if not ev: raise Exception("CTRL-EVENT-SCAN-STARTED not seen") b = get_bssid_ignore_list(wpas) if bssid0 in b: raise Exception("Unexpected ignore list contents: " + str(b))
def test_sta_ap_scan_2(dev, apdev): """Dynamically added wpa_supplicant interface with AP_SCAN 2 connection""" hostapd.add_ap(apdev[0]['ifname'], {"ssid": "test"}) bssid = apdev[0]['bssid'] logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") if "FAIL" not in wpas.request("AP_SCAN -1"): raise Exception("Invalid AP_SCAN -1 accepted") if "FAIL" not in wpas.request("AP_SCAN 3"): raise Exception("Invalid AP_SCAN 3 accepted") if "OK" not in wpas.request("AP_SCAN 2"): raise Exception("Failed to set AP_SCAN 2") id = wpas.connect("", key_mgmt="NONE", bssid=bssid, only_add_network=True) wpas.request("ENABLE_NETWORK " + str(id) + " no-connect") subprocess.call( ['sudo', 'iw', wpas.ifname, 'scan', 'trigger', 'freq', '2412']) time.sleep(1) subprocess.call(['sudo', 'iw', wpas.ifname, 'connect', 'test', '2412']) ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) if ev is None: raise Exception("Connection not reported") wpas.request("SET disallow_aps bssid " + bssid) ev = wpas.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) if ev is None: raise Exception("Disconnection not reported") subprocess.call(['sudo', 'iw', wpas.ifname, 'connect', 'test', '2412']) ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected connection reported")
def test_sta_ap_scan_2(dev, apdev): """Dynamically added wpa_supplicant interface with AP_SCAN 2 connection""" hostapd.add_ap(apdev[0], {"ssid": "test"}) bssid = apdev[0]['bssid'] logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") if "FAIL" not in wpas.request("AP_SCAN -1"): raise Exception("Invalid AP_SCAN -1 accepted") if "FAIL" not in wpas.request("AP_SCAN 3"): raise Exception("Invalid AP_SCAN 3 accepted") if "OK" not in wpas.request("AP_SCAN 2"): raise Exception("Failed to set AP_SCAN 2") id = wpas.connect("", key_mgmt="NONE", bssid=bssid, only_add_network=True) wpas.request("ENABLE_NETWORK " + str(id) + " no-connect") subprocess.call(['iw', wpas.ifname, 'scan', 'trigger', 'freq', '2412']) time.sleep(1) subprocess.call(['iw', wpas.ifname, 'connect', 'test', '2412']) wpas.wait_connected(timeout=10) wpas.request("SET disallow_aps bssid " + bssid) wpas.wait_disconnected(timeout=10) subprocess.call(['iw', wpas.ifname, 'connect', 'test', '2412']) ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected connection reported")
def test_sta_ap_scan_2b(dev, apdev): """Dynamically added wpa_supplicant interface with AP_SCAN 2 operation""" hapd = hostapd.add_ap(apdev[0], {"ssid": "test"}) bssid = apdev[0]['bssid'] logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") if "OK" not in wpas.request("AP_SCAN 2"): raise Exception("Failed to set AP_SCAN 2") id = wpas.connect("test", key_mgmt="NONE", bssid=bssid) wpas.request("DISCONNECT") wpas.set_network(id, "disabled", "1") id2 = wpas.add_network() wpas.set_network_quoted(id2, "ssid", "test2") wpas.set_network(id2, "key_mgmt", "NONE") wpas.set_network(id2, "disabled", "0") wpas.request("REASSOCIATE") ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15) if ev is None: raise Exception("Association rejection not reported") hapd.disable() wpas.set_network(id, "disabled", "0") wpas.set_network(id2, "disabled", "1") for i in range(3): ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15) if ev is None: raise Exception("Association rejection not reported") wpas.request("DISCONNECT")
def test_ap_roam_with_reassoc_auth_timeout(dev, apdev, params): """Roam using reassoc between two APs and authentication times out""" wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1,force_bss_selection=1") params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() id = wpas.connect("test-wpa2-psk", psk="12345678", scan_freq="2412") hwsim_utils.test_connectivity(wpas, hapd0) hapd1 = hostapd.add_ap(apdev[1], params) bssid1 = hapd1.own_addr() wpas.scan_for_bss(bssid1, freq=2412) if "OK" not in wpas.request("SET_NETWORK " + str(id) + " bssid " + bssid1): raise Exception("SET_NETWORK failed") if "OK" not in wpas.request("SET ignore_auth_resp 1"): raise Exception("SET ignore_auth_resp failed") if "OK" not in wpas.request("REASSOCIATE"): raise Exception("REASSOCIATE failed") logger.info("Wait ~10s for auth timeout...") time.sleep(10) ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12) if not ev: raise Exception("CTRL-EVENT-SCAN-STARTED not seen") b = get_blacklist(wpas) if bssid0 in b: raise Exception("Unexpected blacklist contents: " + str(b))
def test_sta_ap_scan_0(dev, apdev): """Dynamically added wpa_supplicant interface with AP_SCAN 0 connection""" hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test" }) bssid = apdev[0]['bssid'] logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") if "OK" not in wpas.request("AP_SCAN 0"): raise Exception("Failed to set AP_SCAN 2") id = wpas.connect("", key_mgmt="NONE", bssid=bssid, only_add_network=True) wpas.request("ENABLE_NETWORK " + str(id) + " no-connect") wpas.request("SCAN") time.sleep(0.5) subprocess.call(['sudo', 'iw', wpas.ifname, 'connect', 'test', '2412']) ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) if ev is None: raise Exception("Connection not reported") wpas.request("SCAN") ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=5) if ev is None: raise Exception("Connection not reported")
def _test_ap_wpa2_psk_wpas_in_bridge(dev, apdev): ssid = "test-wpa2-psk" passphrase = 'qwertyuiop' params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) hapd = hostapd.add_ap(apdev[0]['ifname'], params) br_ifname='sta-br0' ifname='wlan5' wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') subprocess.call(['brctl', 'addbr', br_ifname]) subprocess.call(['brctl', 'setfd', br_ifname, '0']) subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) subprocess.call(['iw', ifname, 'set', '4addr', 'on']) subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) wpas.interface_add(ifname, br_ifname=br_ifname) wpas.connect(ssid, psk=passphrase, scan_freq="2412")
def _test_ap_wpa2_psk_wpas_in_bridge(dev, apdev): ssid = "test-wpa2-psk" passphrase = 'qwertyuiop' params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) hapd = hostapd.add_ap(apdev[0]['ifname'], params) br_ifname = 'sta-br0' ifname = 'wlan5' wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') subprocess.call(['brctl', 'addbr', br_ifname]) subprocess.call(['brctl', 'setfd', br_ifname, '0']) subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) subprocess.call(['iw', ifname, 'set', '4addr', 'on']) subprocess.check_call(['brctl', 'addif', br_ifname, ifname]) wpas.interface_add(ifname, br_ifname=br_ifname) wpas.connect(ssid, psk=passphrase, scan_freq="2412")
def test_sta_dynamic_down_up(dev, apdev): """Dynamically added wpa_supplicant interface down/up""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0], params) logger.info("Create a dynamic wpa_supplicant interface and connect") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") wpas.connect("sta-dynamic", psk="12345678", scan_freq="2412") hwsim_utils.test_connectivity(wpas, hapd) subprocess.call(['ifconfig', wpas.ifname, 'down']) wpas.wait_disconnected(timeout=10) if wpas.get_status_field("wpa_state") != "INTERFACE_DISABLED": raise Exception("Unexpected wpa_state") subprocess.call(['ifconfig', wpas.ifname, 'up']) wpas.wait_connected(timeout=15, error="Reconnection not reported") hwsim_utils.test_connectivity(wpas, hapd)
def test_connect_cmd_roam(dev, apdev): """cfg80211 connect command to trigger roam""" params = {"ssid": "sta-connect"} hostapd.add_ap(apdev[0], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.dump_monitor() hostapd.add_ap(apdev[1], params) wpas.scan_for_bss(apdev[1]['bssid'], freq=2412, force_scan=True) wpas.roam(apdev[1]['bssid']) time.sleep(0.1) wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_ap_vht_wifi_generation(dev, apdev): """VHT and wifi_generation""" try: hapd = None params = {"ssid": "vht", "country_code": "FI", "hw_mode": "a", "channel": "36", "ht_capab": "[HT40+]", "ieee80211n": "1", "ieee80211ac": "1", "vht_oper_chwidth": "1", "vht_oper_centr_freq_seg0_idx": "42"} hapd = hostapd.add_ap(apdev[0], params) bssid = apdev[0]['bssid'] dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180") status = dev[0].get_status() if 'wifi_generation' not in status: # For now, assume this is because of missing kernel support raise HwsimSkip("Association Request IE reporting not supported") #raise Exception("Missing wifi_generation information") if status['wifi_generation'] != "5": raise Exception("Unexpected wifi_generation value: " + status['wifi_generation']) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("vht", key_mgmt="NONE", scan_freq="5180") status = wpas.get_status() if 'wifi_generation' not in status: # For now, assume this is because of missing kernel support raise HwsimSkip("Association Request IE reporting not supported") #raise Exception("Missing wifi_generation information (connect)") if status['wifi_generation'] != "5": raise Exception("Unexpected wifi_generation value (connect): " + status['wifi_generation']) except Exception as e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): raise HwsimSkip("80 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") if hapd: hapd.request("DISABLE") subprocess.call(['iw', 'reg', 'set', '00']) dev[0].flush_scan_cache()
def test_connect_cmd_wep_shared(dev, apdev): """WEP Shared key using cfg80211 connect command""" params = { "ssid": "sta-connect-wep", "wep_key0": '"hello"', "auth_algs": "2" } hapd = hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") id = wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", auth_alg="SHARED", wep_key0='"hello"') hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT") wpas.remove_network(id) wpas.connect("sta-connect-wep", key_mgmt="NONE", scan_freq="2412", auth_alg="OPEN SHARED", wep_key0='"hello"') hwsim_utils.test_connectivity(wpas, hapd) wpas.request("DISCONNECT")
def test_connect_cmd_roam(dev, apdev): """cfg80211 connect command to trigger roam""" params = { "ssid": "sta-connect" } hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412") wpas.dump_monitor() hostapd.add_ap(apdev[1]['ifname'], params) wpas.scan_for_bss(apdev[1]['bssid'], freq=2412, force_scan=True) wpas.roam(apdev[1]['bssid']) time.sleep(0.1) wpas.request("DISCONNECT") wpas.wait_disconnected() wpas.dump_monitor()
def test_connect_cmd_reject_assoc(dev, apdev): """Connection using cfg80211 connect command getting rejected""" params = {"ssid": "sta-connect", "require_ht": "1"} hostapd.add_ap(apdev[0], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412", disable_ht="1", wait_connect=False) ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15) if ev is None: raise Exception("Association rejection timed out") if "status_code=27" not in ev: raise Exception("Unexpected rejection status code") wpas.request("DISCONNECT") wpas.dump_monitor()
def test_connect_cmd_reject_assoc(dev, apdev): """Connection using cfg80211 connect command getting rejected""" params = { "ssid": "sta-connect", "require_ht": "1" } hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") wpas.connect("sta-connect", key_mgmt="NONE", scan_freq="2412", disable_ht="1", wait_connect=False) # Reject event gets reported twice since we force connect command to be used # with a driver that supports auth+assoc for testing purposes. for i in range(0, 2): ev = wpas.wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=15) if ev is None: raise Exception("Association rejection timed out") if "status_code=27" not in ev: raise Exception("Unexpected rejection status code")
def test_sta_dynamic_random_mac_addr_keep_oui(dev, apdev): """Dynamically added wpa_supplicant interface and random MAC address (keep OUI)""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") addr0 = wpas.get_driver_status_field("addr") wpas.request("SET preassoc_mac_addr 2") wpas.request("SET rand_addr_lifetime 0") id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="2", scan_freq="2412") addr1 = wpas.get_driver_status_field("addr") if addr0 == addr1: raise Exception("Random MAC address not used") if addr1[3:8] != addr0[3:8]: raise Exception("OUI was not kept") sta = hapd.get_sta(addr0) if sta['addr'] != "FAIL": raise Exception("Unexpected STA association with permanent address") sta = hapd.get_sta(addr1) if sta['addr'] != addr1: raise Exception("STA association with random address not found") wpas.request("DISCONNECT") wpas.connect_network(id) addr2 = wpas.get_driver_status_field("addr") if addr1 != addr2: raise Exception("Random MAC address changed unexpectedly") wpas.remove_network(id) id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="2", scan_freq="2412") addr2 = wpas.get_driver_status_field("addr") if addr1 == addr2: raise Exception("Random MAC address did not change") if addr2[3:8] != addr0[3:8]: raise Exception("OUI was not kept")
def test_autogo_force_diff_channel(dev, apdev): """P2P autonomous GO and station interface operate on different channels""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") wpas.request("SET p2p_no_group_iface 0") hapd = hostapd.add_ap(apdev[0]['ifname'], {"ssid" : 'ap-test', "channel" : '1'}) wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412") channels = { 2 : 2417, 5 : 2432, 9 : 2452 } for key in channels: res_go = autogo(wpas, channels[key]) hwsim_utils.test_connectivity(wpas, hapd) if int(res_go['freq']) == 2412: raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq']) wpas.remove_group(res_go['ifname'])
def test_autogo_with_bss_on_disallowed_chan(dev, apdev): """P2P channel selection: Autonomous GO with BSS on a disallowed channel""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface="/tmp/wpas-wlan5") wpas.interface_add(iface) wpas.request("SET p2p_no_group_iface 0") if wpas.get_mcc() < 2: raise Exception("New radio does not support MCC") try: hapd = hostapd.add_ap(apdev[0]["ifname"], {"ssid": "bss-2.4ghz", "channel": "1"}) wpas.request("P2P_SET disallow_freq 2412") wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") res = autogo(wpas) if res["freq"] == "2412": raise Exception("GO set on a disallowed channel") hwsim_utils.test_connectivity(wpas, hapd) finally: wpas.request("P2P_SET disallow_freq ")