def test_p2p_device_group_remove(dev, apdev): """P2P group removal via the P2P ctrl interface with driver using cfg80211 P2P Device""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=wpas, r_intent=0) check_grpform_results(i_res, r_res) # Issue the remove request on the interface which will be removed p2p_iface_wpas = WpaSupplicant(ifname=r_res['ifname']) res = p2p_iface_wpas.request("P2P_GROUP_REMOVE *") if "OK" not in res: raise Exception("Failed to remove P2P group") ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10) if ev is None: raise Exception("Group removal event not received") if not wpas.global_ping(): raise Exception( "Could not ping global ctrl_iface after group removal")
def test_p2p_device_join_no_group_iface_cancel(dev, apdev): """P2P cancel join-group using cfg80211 P2P Device (no separate group interface)""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.global_request("SET p2p_no_group_iface 1") res = dev[0].p2p_start_go() bssid = dev[0].get_group_status_field('bssid') wpas.scan_for_bss(bssid, res['freq']) pin = wpas.wps_read_pin() dev[0].p2p_go_authorize_client(pin) cmd = "P2P_CONNECT %s %s join freq=%s" % (dev[0].p2p_dev_addr(), pin, res['freq']) if "OK" not in wpas.request(cmd): raise Exception("P2P_CONNECT(join) failed") ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=1) if "OK" not in wpas.request("P2P_CANCEL"): raise Exception("P2P_CANCEL failed") dev[0].remove_group()
def test_p2p_device_autogo_chan_switch(dev): """P2P autonomous GO switching channels with cfg80211 P2P Device""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.global_request("SET p2p_no_group_iface 1") autogo(wpas, freq=2417) connect_cli(wpas, dev[1]) res = wpas.group_request("CHAN_SWITCH 5 2422") if "FAIL" in res: # for now, skip test since mac80211_hwsim support is not yet widely # deployed raise HwsimSkip("Assume mac80211_hwsim did not support channel switching") ev = wpas.wait_group_event(["AP-CSA-FINISHED"], timeout=10) if ev is None: raise Exception("CSA finished event timed out") if "freq=2422" not in ev: raise Exception("Unexpected cahnnel in CSA finished event") wpas.dump_monitor() dev[1].dump_monitor() time.sleep(0.1) hwsim_utils.test_connectivity_p2p(wpas, dev[1])
def run_p2p_device_nfc_invite(dev, apdev, no_group_iface): with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) wpas.global_request("SET p2p_no_group_iface %d" % no_group_iface) set_ip_addr_info(dev[0]) logger.info("Start autonomous GO") dev[0].p2p_start_go() logger.info("Write NFC Tag on the P2P Client") res = wpas.global_request("P2P_LISTEN") if "FAIL" in res: raise Exception("Failed to start Listen mode") wpas.dump_monitor() pw = wpas.global_request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = wpas.global_request("P2P_SET nfc_tag 1").rstrip() if "FAIL" in res: raise Exception("Failed to enable NFC Tag for P2P static handover") sel = wpas.global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") wpas.dump_monitor() logger.info("Read NFC Tag on the GO to trigger invitation") res = dev[0].global_request("WPS_NFC_TAG_READ " + sel) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") ev = wpas.wait_global_event(grpform_events, timeout=20) if ev is None: raise Exception("Joining the group timed out") res = wpas.group_form_result(ev) wpas.dump_monitor() hwsim_utils.test_connectivity_p2p(dev[0], wpas) check_ip_addr(res) wpas.dump_monitor()
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) try: wpas.set("sae_pwe", "2") 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' params['sae_pwe'] = "2" 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") finally: wpas.set("sae_pwe", "0")
def test_p2p_device_incorrect_command_interface(dev, apdev): """cfg80211 P2P Device and P2P_* command on incorrect interface""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) dev[0].p2p_listen() wpas.request('P2P_FIND type=social') ev = wpas.wait_global_event(["P2P-DEVICE-FOUND"], timeout=10) if ev is None: raise Exception("Peer not found") ev = wpas.wait_event(["P2P-DEVICE-FOUND"], timeout=0.1) if ev is not None: raise Exception( "Unexpected P2P-DEVICE-FOUND event on station interface") pin = wpas.wps_read_pin() dev[0].p2p_go_neg_auth(wpas.p2p_dev_addr(), pin, "enter", go_intent=14, freq=2412) wpas.request('P2P_STOP_FIND') if "OK" not in wpas.request('P2P_CONNECT ' + dev[0].p2p_dev_addr() + ' ' + pin + ' display go_intent=1'): raise Exception("P2P_CONNECT failed") ev = wpas.wait_global_event(["P2P-GROUP-STARTED"], timeout=15) if ev is None: raise Exception("Group formation timed out") wpas.group_form_result(ev) ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) if ev is None: raise Exception("Group formation timed out(2)") dev[0].group_form_result(ev) dev[0].remove_group() wpas.wait_go_ending_session()
def check_pasn_fils_connected_diff_channel(dev, apdev, params, key_mgmt): check_pasn_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 Exception("New radio does not support MCC") hapd = pasn_fils_setup(wpas, apdev, params, key_mgmt) # Connect to another AP on a different channel hapd1 = hostapd.add_ap(apdev[1], {"ssid": "open", "channel": "6"}) wpas.connect("open", key_mgmt="NONE", scan_freq="2437", bg_scan_period="0") hwsim_utils.test_connectivity(wpas, hapd1) # And perform the PASN authentication with FILS check_pasn_akmp_cipher(wpas, hapd, key_mgmt, "CCMP", nid="0")
def test_sigma_dut_ap_psk_sae(dev, apdev): """sigma_dut controlled AP with PSK+SAE""" with HWSimRadio() as (radio, iface): sigma = start_sigma_dut(iface) try: sigma_dut_cmd_check("ap_reset_default") sigma_dut_cmd_check( "ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") sigma_dut_cmd_check( "ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678") sigma_dut_cmd_check("ap_config_commit,NAME,AP") dev[0].request("SET sae_groups ") dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", scan_freq="2412") dev[1].connect("test-sae", psk="12345678", scan_freq="2412") sigma_dut_cmd_check("ap_reset_default") finally: stop_sigma_dut(sigma)
def test_sigma_dut_ap_sae(dev, apdev): """sigma_dut controlled AP with SAE""" with HWSimRadio() as (radio, iface): sigma = start_sigma_dut(iface) try: sigma_dut_cmd_check("ap_reset_default") sigma_dut_cmd_check( "ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng") sigma_dut_cmd_check( "ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678") sigma_dut_cmd_check("ap_config_commit,NAME,AP") dev[0].request("SET sae_groups ") dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678", scan_freq="2412") if dev[0].get_status_field('sae_group') != '19': raise Exception("Expected default SAE group not used") sigma_dut_cmd_check("ap_reset_default") finally: stop_sigma_dut(sigma)
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_p2p_device_grpform(dev, apdev): """P2P group formation with driver using cfg80211 P2P Device""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=wpas, r_intent=0) check_grpform_results(i_res, r_res) remove_group(dev[0], wpas) res = wpas.global_request("IFNAME=p2p-dev-" + iface + " STATUS-DRIVER") lines = res.splitlines() found = False for l in lines: try: [name,value] = l.split('=', 1) if name == "wdev_id": found = True break except ValueError: pass if not found: raise Exception("wdev_id not found")
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_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_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_p2p_delay_go_csa(dev, apdev, params): """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group""" 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") addr0 = wpas.p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() try: dev[1].p2p_listen() if not wpas.discover_peer(addr1, social=True): raise Exception("Peer " + addr1 + " not found") wpas.p2p_stop_find() hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'bss-2.4ghz', "channel": '1' }) wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412") wpas.global_request("SET p2p_go_freq_change_policy 0") wpas.dump_monitor() logger.info("Start GO on channel 6") res = autogo(wpas, freq=2437) if res['freq'] != "2437": raise Exception("GO set on a freq=%s instead of 2437" % res['freq']) # Start find on dev[1] to run scans with dev[2] in parallel dev[1].p2p_find(social=True) # Use another client device to stop the initial client connection # timeout on the GO if not dev[2].discover_peer(addr0, social=True): raise Exception("Peer2 did not find the GO") dev[2].p2p_stop_find() pin = dev[2].wps_read_pin() wpas.p2p_go_authorize_client(pin) dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437") ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10) if ev is None: raise Exception("Peer2 did not get connected") if not dev[1].discover_peer(addr0, social=True): raise Exception("Peer did not find the GO") pin = dev[1].wps_read_pin() dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth") dev[1].p2p_listen() # Force P2P GO channel switch on successful invitation signaling wpas.group_request("SET p2p_go_csa_on_inv 1") logger.info("Starting invitation") wpas.p2p_go_authorize_client(pin) wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event( ["P2P-INVITATION-RECEIVED", "P2P-GROUP-STARTED"], timeout=10) if ev is None: raise Exception("Timeout on invitation on peer") if "P2P-INVITATION-RECEIVED" in ev: raise Exception( "Unexpected request to accept pre-authorized invitation") # A P2P GO move is not expected at this stage, as during the # invitation signaling, the P2P GO includes only its current # operating channel in the channel list, and as the invitation # response can only include channels that were also in the # invitation request channel list, the group common channels # includes only the current P2P GO operating channel. ev = wpas.wait_group_event( ["P2P-REMOVE-AND-REFORM-GROUP", "AP-CSA-FINISHED"], timeout=1) if ev is not None: raise Exception("Unexpected + " + ev + " event") finally: wpas.global_request("SET p2p_go_freq_change_policy 2")
def test_discovery_while_cli_p2p_dev(dev, apdev, params): """P2P provision discovery from CLI (using P2P Device interface)""" with HWSimRadio(use_p2p_device=True) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) run_discovery_while_cli(wpas, dev, params)
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].group_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_gas_fragment_mcc(dev, apdev): """GAS fragmentation with mac80211_hwsim MCC enabled""" with HWSimRadio(n_channels=2) as (radio, iface): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add(iface) gas_fragment_and_comeback(wpas, apdev[0], frag_limit=50)