def go_neg_pin_authorized_persistent(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display', test_data=True, r_listen=True): if r_listen: r_dev.p2p_listen() i_dev.p2p_listen() pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, persistent=True) if r_listen: r_dev.p2p_listen() i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, persistent=True) r_res = r_dev.p2p_go_neg_auth_result() logger.debug("i_res: " + str(i_res)) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() i_dev.dump_monitor() logger.info("Group formed") if test_data: hwsim_utils.test_connectivity_p2p(r_dev, i_dev) return [i_res, r_res]
def test_nfc_p2p_static_handover_join_tagdev_client(dev): """NFC static handover to join a P2P group (NFC Tag device is the P2P Client)""" set_ip_addr_info(dev[0]) logger.info("Start autonomous GO") dev[0].p2p_start_go() dev[1].request("SET ignore_old_scan_res 1") dev[2].request("SET ignore_old_scan_res 1") logger.info("Write NFC Tag on the P2P Client") res = dev[1].request("P2P_LISTEN") if "FAIL" in res: raise Exception("Failed to start Listen mode") pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = dev[1].request("P2P_SET nfc_tag 1").rstrip() if "FAIL" in res: raise Exception("Failed to enable NFC Tag for P2P static handover") sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") logger.info("Read NFC Tag on the GO to trigger invitation") res = dev[0].request("WPS_NFC_TAG_READ " + sel) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") ev = dev[1].wait_event(grpform_events, timeout=30) if ev is None: raise Exception("Joining the group timed out") res = dev[1].group_form_result(ev) hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res) logger.info("Write NFC Tag on another P2P Client") res = dev[2].request("P2P_LISTEN") if "FAIL" in res: raise Exception("Failed to start Listen mode") pw = dev[2].request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") res = dev[2].request("P2P_SET nfc_tag 1").rstrip() if "FAIL" in res: raise Exception("Failed to enable NFC Tag for P2P static handover") sel = dev[2].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") logger.info("Read NFC Tag on the GO to trigger invitation") res = dev[0].request("WPS_NFC_TAG_READ " + sel) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") ev = dev[2].wait_event(grpform_events, timeout=30) if ev is None: raise Exception("Joining the group timed out") res = dev[2].group_form_result(ev) hwsim_utils.test_connectivity_p2p(dev[0], dev[2]) check_ip_addr(res)
def invite_from_go(go, cli): logger.info("Re-invoke persistent group from GO") invite(go, cli) [go_res, cli_res] = check_result(go, cli) hwsim_utils.test_connectivity_p2p(go, cli) terminate_group(go, cli) return [go_res, cli_res]
def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'): r_dev.p2p_listen() i_dev.p2p_listen() pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() res = Queue.Queue() t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) if ev is None: raise Exception("GO Negotiation timed out") r_dev.dump_monitor() logger.debug("Re-initiate GO Negotiation from r_dev") r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join() i_res = res.get() if i_res is None: raise Exception("go_neg_init thread failed") logger.debug("i_res: " + str(i_res)) logger.info("Group formed") hwsim_utils.test_connectivity_p2p(r_dev, i_dev) i_dev.dump_monitor() return [i_res, r_res]
def connect_cli(go, client): logger.info("Try to connect the client to the GO") pin = client.wps_read_pin() go.p2p_go_authorize_client(pin) client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(go, client)
def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None): r_dev.p2p_find(social=True) i_dev.p2p_find(social=True) logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() res = Queue.Queue() t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) if ev is None: raise Exception("GO Negotiation timed out") r_dev.dump_monitor() logger.debug("Re-initiate GO Negotiation from r_dev") r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", go_intent=r_intent, timeout=20, freq=r_freq) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join() i_res = res.get() if i_res is None: raise Exception("go_neg_init_pbc thread failed") logger.debug("i_res: " + str(i_res)) logger.info("Group formed") hwsim_utils.test_connectivity_p2p(r_dev, i_dev) i_dev.dump_monitor() return [i_res, r_res]
def invite_from_cli(go, cli): logger.info("Re-invoke persistent group from client") invite(cli, go) [go_res, cli_res] = check_result(go, cli) hwsim_utils.test_connectivity_p2p(go, cli) terminate_group(go, cli) return [go_res, cli_res]
def test_nfc_p2p_responder_go(dev): """NFC connection handover with responder already GO""" set_ip_addr_info(dev[1]) logger.info("Start autonomous GO") dev[1].p2p_start_go() logger.info("Perform NFC connection handover") req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_event(["P2P-GROUP-STARTED"], timeout=15) if ev is None: raise Exception("Connection to the group timed out") res0 = dev[0].group_form_result(ev) if res0['result'] != 'success': raise Exception("Unexpected connection failure") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res0)
def test_nfc_p2p_responder_go(dev): """NFC connection handover with responder already GO""" set_ip_addr_info(dev[1]) logger.info("Start autonomous GO") dev[1].p2p_start_go() logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) if ev is None: raise Exception("Connection to the group timed out") res0 = dev[0].group_form_result(ev) if res0['result'] != 'success': raise Exception("Unexpected connection failure") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res0)
def test_p2p_device_nfc_invite(dev, apdev): """P2P NFC invitiation 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) 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") 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") logger.info("Read NFC Tag on the GO to trigger invitation") res = dev[0].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) hwsim_utils.test_connectivity_p2p(dev[0], wpas) check_ip_addr(res)
def test_nfc_p2p_go_legacy_handover(dev): """NFC token from legacy WPS STA to P2P GO""" logger.info("Start autonomous GOs") dev[0].p2p_start_go() logger.info("Connect legacy WPS STA with connection handover") req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[0].group_request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") res = dev[0].group_request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant (GO)") dev[1].dump_monitor() res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant (legacy STA)" ) dev[1].wait_connected(timeout=15, error="Joining the group timed out") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) dev[1].request("DISCONNECT") dev[0].remove_group()
def test_persistent_group_invite_removed_client(dev): """P2P persistent group client removal and re-invitation""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() dev[0].request("P2P_SET per_sta_psk 1") logger.info("Form a persistent group") [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) if not i_res['persistent'] or not r_res['persistent']: raise Exception("Formed group was not persistent") logger.info("Remove client from the group") dev[0].global_request("P2P_REMOVE_CLIENT " + addr1) dev[1].wait_go_ending_session() logger.info("Re-invite the removed client to join the group") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + peer + " not found") dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10) if ev is None: raise Exception("Timeout on invitation") if "sa=" + addr0 + " persistent=" not in ev: raise Exception("Unexpected invitation event") [event,addr,persistent] = ev.split(' ', 2) dev[1].global_request("P2P_GROUP_ADD " + persistent) ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30) if ev is None: raise Exception("Did not receive PSK failure report") [tmp,id] = ev.split('=', 1) ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10) if ev is None: raise Exception("Group removal event timed out") if "reason=PSK_FAILURE" not in ev: raise Exception("Unexpected group removal reason") dev[1].request("REMOVE_NETWORK " + id) logger.info("Re-invite after client removed persistent group info") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + peer + " not found") dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10) if ev is None: raise Exception("Timeout on invitation") if " persistent=" in ev: raise Exception("Unexpected invitation event") pin = dev[1].wps_read_pin() dev[0].p2p_go_authorize_client(pin) c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True, freq=i_res['freq']) if not c_res['persistent']: raise Exception("Joining client did not recognize persistent group") if r_res['psk'] == c_res['psk']: raise Exception("Same PSK assigned on both times") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) terminate_group(dev[0], dev[1])
def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display', test_data=True, i_freq=None, r_freq=None, i_freq2=None, r_freq2=None, i_max_oper_chwidth=None, r_max_oper_chwidth=None, i_ht40=False, i_vht=False, r_ht40=False, r_vht=False): i_dev.p2p_listen() pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq, freq2=r_freq2, max_oper_chwidth=r_max_oper_chwidth, ht40=r_ht40, vht=r_vht) r_dev.p2p_listen() i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, expect_failure=expect_failure, freq=i_freq, freq2=i_freq2, max_oper_chwidth=i_max_oper_chwidth, ht40=i_ht40, vht=i_vht) r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure) logger.debug("i_res: " + str(i_res)) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() i_dev.dump_monitor() if i_go_neg_status: if i_res['result'] != 'go-neg-failed': raise Exception("Expected GO Negotiation failure not reported") if i_res['status'] != i_go_neg_status: raise Exception("Expected GO Negotiation status not seen") if expect_failure: return logger.info("Group formed") if test_data: hwsim_utils.test_connectivity_p2p(r_dev, i_dev) return [i_res, r_res]
def test_persistent_group_invite_removed_client(dev): """P2P persistent group client removal and re-invitation""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() dev[0].request("P2P_SET per_sta_psk 1") logger.info("Form a persistent group") [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) if not i_res['persistent'] or not r_res['persistent']: raise Exception("Formed group was not persistent") logger.info("Remove client from the group") dev[0].global_request("P2P_REMOVE_CLIENT " + addr1) dev[1].wait_go_ending_session() logger.info("Re-invite the removed client to join the group") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + peer + " not found") dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10) if ev is None: raise Exception("Timeout on invitation") if "sa=" + addr0 + " persistent=" not in ev: raise Exception("Unexpected invitation event") [event, addr, persistent] = ev.split(' ', 2) dev[1].global_request("P2P_GROUP_ADD " + persistent) ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30) if ev is None: raise Exception("Did not receive PSK failure report") [tmp, id] = ev.split('=', 1) ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10) if ev is None: raise Exception("Group removal event timed out") if "reason=PSK_FAILURE" not in ev: raise Exception("Unexpected group removal reason") dev[1].global_request("REMOVE_NETWORK " + id) logger.info("Re-invite after client removed persistent group info") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + peer + " not found") dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10) if ev is None: raise Exception("Timeout on invitation") if " persistent=" in ev: raise Exception("Unexpected invitation event") pin = dev[1].wps_read_pin() dev[0].p2p_go_authorize_client(pin) c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True, freq=i_res['freq']) if not c_res['persistent']: raise Exception("Joining client did not recognize persistent group") if r_res['psk'] == c_res['psk']: raise Exception("Same PSK assigned on both times") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) terminate_group(dev[0], dev[1])
def test_nfc_p2p_ip_addr_assignment2(dev): """NFC connection handover and IP address assignment for two clients""" set_ip_addr_info(dev[1]) dev[0].global_request("SET p2p_go_intent 3") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res0['role'] != 'client' or res1['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res0) logger.info("Client 1 IP address: " + res0['ip_addr']) logger.info("Connect a P2P client") pin = dev[2].wps_read_pin() dev[1].p2p_go_authorize_client(pin) res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) check_ip_addr(res) logger.info("Client 2 IP address: " + res['ip_addr']) if res['ip_addr'] == res0['ip_addr']: raise Exception("Same IP address assigned to both clients")
def invite_from_go(go, cli, terminate=True, extra=None): logger.info("Re-invoke persistent group from GO") invite(go, cli, extra=extra) [go_res, cli_res] = check_result(go, cli) hwsim_utils.test_connectivity_p2p(go, cli) if terminate: terminate_group(go, cli) return [go_res, cli_res]
def invite_from_cli(go, cli, terminate=True): logger.info("Re-invoke persistent group from client") invite(cli, go) [go_res, cli_res] = check_result(go, cli) hwsim_utils.test_connectivity_p2p(go, cli) if terminate: terminate_group(go, cli) return [go_res, cli_res]
def invite_from_go(go, cli, terminate=True): logger.info("Re-invoke persistent group from GO") invite(go, cli) [go_res, cli_res] = check_result(go, cli) hwsim_utils.test_connectivity_p2p(go, cli) if terminate: terminate_group(go, cli) return [go_res, cli_res]
def test_autogo_2cli(dev): """P2P autonomous GO and two clients joining group""" autogo(dev[0]) connect_cli(dev[0], dev[1]) connect_cli(dev[0], dev[2]) hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) dev[2].remove_group() dev[1].remove_group() dev[0].remove_group()
def connect_cli(go, client, social=False, freq=None): logger.info("Try to connect the client to the GO") pin = client.wps_read_pin() go.p2p_go_authorize_client(pin) res = client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60, social=social, freq=freq) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(go, client) return res
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_autogo_2cli(dev): """P2P autonomous GO and two clients joining group""" autogo(dev[0]) connect_cli(dev[0], dev[1]) connect_cli(dev[0], dev[2]) hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr()) dev[1].wait_go_ending_session() dev[0].remove_group() dev[2].wait_go_ending_session()
def test_discovery_group_client(dev): """P2P device discovery for a client in a group""" logger.info("Start autonomous GO " + dev[0].ifname) res = dev[0].p2p_start_go(freq="2422") logger.debug("res: " + str(res)) logger.info("Connect a client to the GO") pin = dev[1].wps_read_pin() dev[0].p2p_go_authorize_client(pin) dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, freq=int(res['freq']), timeout=60) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Try to discover a P2P client in a group") if not dev[2].discover_peer( dev[1].p2p_dev_addr(), social=False, timeout=10): stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer( dev[1].p2p_dev_addr(), social=False, timeout=10): stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer( dev[1].p2p_dev_addr(), social=False, timeout=10): raise Exception("Could not discover group client") # This is not really perfect, but something to get a bit more testing # coverage.. For proper discoverability mechanism validation, the P2P # client would need to go to sleep to avoid acknowledging the GO Negotiation # Request frame. Offchannel Listen mode operation on the P2P Client with # mac80211_hwsim is apparently not enough to avoid the acknowledgement on # the operating channel, so need to disconnect from the group which removes # the GO-to-P2P Client part of the discoverability exchange in practice. pin = dev[2].wps_read_pin() # make group client non-responsive on operating channel dev[1].dump_monitor() dev[1].group_request("DISCONNECT") ev = dev[1].wait_group_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) if ev is None: raise Exception("Timeout on waiting disconnection") dev[2].request("P2P_CONNECT {} {} display".format(dev[1].p2p_dev_addr(), pin)) ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=2) if ev: raise Exception("Unexpected frame RX on P2P client") # make group client available on operating channe dev[1].group_request("REASSOCIATE") ev = dev[1].wait_global_event( ["CTRL-EVENT-CONNECTED", "P2P-GO-NEG-REQUEST"], timeout=10) if ev is None: raise Exception("Timeout on reconnection to group") if "P2P-GO-NEG-REQUEST" not in ev: ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10) if ev is None: raise Exception("Timeout on waiting for GO Negotiation Request")
def test_nfc_p2p_ip_addr_assignment(dev): """NFC connection handover and legacy station IP address assignment""" set_ip_addr_info(dev[1]) dev[0].global_request("SET p2p_go_intent 3") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res0['role'] != 'client' or res1['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res0) logger.info("Connect legacy P2P client that does not use new IP address assignment") res = dev[2].global_request("P2P_SET disable_ip_addr_req 1") if "FAIL" in res: raise Exception("Failed to disable IP address assignment request") pin = dev[2].wps_read_pin() dev[1].p2p_go_authorize_client(pin) res = dev[2].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60) logger.info("Client connected") res = dev[2].global_request("P2P_SET disable_ip_addr_req 0") hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) if 'ip_addr' in res: raise Exception("Unexpected IP address assignment")
def test_nfc_p2p_go_neg_ip_pool_oom(dev): """NFC connection handover to form a new P2P group and IP pool OOM""" set_ip_addr_info(dev[0]) ip = dev[0].request("GET ip_addr_go") if ip != "192.168.42.1": raise Exception("Unexpected ip_addr_go returned: " + ip) dev[0].global_request("SET p2p_go_intent 10") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() with alloc_fail(dev[0], 1, "bitfield_alloc;wpa_init"): res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(resp)" ) res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(init)" ) ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) if 'ip_addr' in res1: raise Exception("Unexpectedly received IP address from GO")
def test_p2p_go_invite_auth(dev): """P2P GO inviting a client to join (authorized invitation)""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() logger.info("Generate BSS table entry for old group") # this adds more coverage to testing by forcing the GO to be found with an # older entry in the BSS table and with that entry having a different # operating channel. dev[0].p2p_start_go(freq=2432) dev[1].scan() dev[0].remove_group() dev[0].dump_monitor() dev[1].dump_monitor() logger.info("Discover peer") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + addr1 + " not found") dev[0].p2p_listen() if not dev[1].discover_peer(addr0, social=True): raise Exception("Peer " + addr0 + " not found") dev[1].p2p_listen() logger.info("Authorize invitation") pin = dev[1].wps_read_pin() dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth") logger.info("Start GO on non-social channel") res = dev[0].p2p_start_go(freq=2427) logger.debug("res: " + str(res)) logger.info("Invite peer to join the group") dev[0].p2p_go_authorize_client(pin) dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event( ["P2P-INVITATION-RECEIVED", "P2P-GROUP-STARTED"], timeout=20) 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 invitaton") dev[1].group_form_result(ev) dev[0].dump_monitor() logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Terminate group") dev[0].remove_group() dev[1].wait_go_ending_session()
def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None, provdisc=False, r_listen=False): if r_listen: r_dev.p2p_listen() else: r_dev.p2p_find(social=True) i_dev.p2p_find(social=True) logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() res = Queue() t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) if ev is None: t.join() raise Exception("GO Negotiation timed out") r_dev.dump_monitor() # Allow some time for the GO Neg Resp to go out before initializing new # GO Negotiation. time.sleep(0.2) logger.debug("Re-initiate GO Negotiation from r_dev") try: r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", go_intent=r_intent, timeout=20, freq=r_freq) except Exception as e: logger.info("go_neg_pbc - r_dev.p2p_go_neg_init() exception: " + str(e)) t.join() raise logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join() i_res = res.get() if i_res is None: raise Exception("go_neg_init_pbc thread failed") logger.debug("i_res: " + str(i_res)) logger.info("Group formed") hwsim_utils.test_connectivity_p2p(r_dev, i_dev) i_dev.dump_monitor() return [i_res, r_res]
def test_autogo_2cli(dev): """P2P autonomous GO and two clients joining group""" autogo(dev[0], freq=2412) connect_cli(dev[0], dev[1], social=True, freq=2412) connect_cli(dev[0], dev[2], social=True, freq=2412) hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr()) dev[1].wait_go_ending_session() dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr()) dev[2].wait_go_ending_session() if "FAIL" not in dev[0].global_request("P2P_REMOVE_CLIENT foo"): raise Exception("Invalid P2P_REMOVE_CLIENT command accepted") dev[0].remove_group()
def test_nfc_p2p_go_neg(dev): """NFC connection handover to form a new P2P group (initiator becomes GO)""" set_ip_addr_info(dev[0]) ip = dev[0].request("GET ip_addr_go") if ip != "192.168.42.1": raise Exception("Unexpected ip_addr_go returned: " + ip) dev[0].global_request("SET p2p_go_intent 10") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception( "Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED" ], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res1['role'] != 'client' or res0['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res1)
def test_discovery_group_client(dev): """P2P device discovery for a client in a group""" logger.info("Start autonomous GO " + dev[0].ifname) res = dev[0].p2p_start_go(freq="2422") logger.debug("res: " + str(res)) logger.info("Connect a client to the GO") pin = dev[1].wps_read_pin() dev[0].p2p_go_authorize_client(pin) dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, freq=int(res['freq']), timeout=60) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Try to discover a P2P client in a group") if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): raise Exception("Could not discover group client") # This is not really perfect, but something to get a bit more testing # coverage.. For proper discoverability mechanism validation, the P2P # client would need to go to sleep to avoid acknowledging the GO Negotiation # Request frame. Offchannel Listen mode operation on the P2P Client with # mac80211_hwsim is apparently not enough to avoid the acknowledgement on # the operating channel, so need to disconnect from the group which removes # the GO-to-P2P Client part of the discoverability exchange in practice. pin = dev[2].wps_read_pin() # make group client non-responsive on operating channel dev[1].dump_monitor() dev[1].group_request("DISCONNECT") ev = dev[1].wait_group_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) if ev is None: raise Exception("Timeout on waiting disconnection") dev[2].request("P2P_CONNECT {} {} display".format(dev[1].p2p_dev_addr(), pin)) ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=2) if ev: raise Exception("Unexpected frame RX on P2P client") # make group client available on operating channe dev[1].group_request("REASSOCIATE") ev = dev[1].wait_global_event(["CTRL-EVENT-CONNECTED", "P2P-GO-NEG-REQUEST"], timeout=10) if ev is None: raise Exception("Timeout on reconnection to group") if "P2P-GO-NEG-REQUEST" not in ev: ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10) if ev is None: raise Exception("Timeout on waiting for GO Negotiation Request")
def test_discovery_group_client(dev): """P2P device discovery for a client in a group""" logger.info("Start autonomous GO " + dev[0].ifname) res = dev[0].p2p_start_go(freq="2422") logger.debug("res: " + str(res)) logger.info("Connect a client to the GO") pin = dev[1].wps_read_pin() dev[0].p2p_go_authorize_client(pin) dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Try to discover a P2P client in a group") if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False): raise Exception("Could not discover group client")
def test_p2p_go_invite_auth(dev): """P2P GO inviting a client to join (authorized invitation)""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() logger.info("Generate BSS table entry for old group") # this adds more coverage to testing by forcing the GO to be found with an # older entry in the BSS table and with that entry having a different # operating channel. dev[0].p2p_start_go(freq=2432) dev[1].scan() dev[0].remove_group() dev[0].dump_monitor() dev[1].dump_monitor() logger.info("Discover peer") dev[1].p2p_listen() if not dev[0].discover_peer(addr1, social=True): raise Exception("Peer " + addr1 + " not found") dev[0].p2p_listen() if not dev[1].discover_peer(addr0, social=True): raise Exception("Peer " + addr0 + " not found") dev[1].p2p_listen() logger.info("Authorize invitation") pin = dev[1].wps_read_pin() dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth") logger.info("Start GO on non-social channel") res = dev[0].p2p_start_go(freq=2427) logger.debug("res: " + str(res)) logger.info("Invite peer to join the group") dev[0].p2p_go_authorize_client(pin) dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1) ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED", "P2P-GROUP-STARTED"], timeout=20) 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 invitaton") dev[1].group_form_result(ev) dev[0].dump_monitor() logger.info("Client connected") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Terminate group") dev[0].remove_group() dev[1].wait_go_ending_session()
def go_neg_pin_authorized_persistent(i_dev, r_dev, i_intent=None, r_intent=None, i_method="enter", r_method="display"): r_dev.p2p_listen() i_dev.p2p_listen() pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, persistent=True) i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, persistent=True) r_res = r_dev.p2p_go_neg_auth_result() logger.debug("i_res: " + str(i_res)) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() i_dev.dump_monitor() logger.info("Group formed") hwsim_utils.test_connectivity_p2p(r_dev, i_dev) return [i_res, r_res]
def test_nfc_p2p_static_handover_tagdev_client_group_iface(dev): """NFC static handover to form a new P2P group (NFC Tag device becomes P2P Client with group iface)""" set_ip_addr_info(dev[0]) logger.info("Perform NFC connection handover") res = dev[1].global_request("SET p2p_listen_reg_class 81") res2 = dev[1].global_request("SET p2p_listen_channel 6") if "FAIL" in res or "FAIL" in res2: raise Exception("Could not set Listen channel") pw = dev[1].global_request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") dev[1].global_request("SET p2p_no_group_iface 0") res = dev[1].global_request("P2P_SET nfc_tag 1").rstrip() if "FAIL" in res: raise Exception("Failed to enable NFC Tag for P2P static handover") sel = dev[1].global_request( "NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") res = dev[1].global_request("P2P_LISTEN") if "FAIL" in res: raise Exception("Failed to start Listen mode") dev[1].dump_monitor() dev[0].dump_monitor() dev[0].global_request("SET p2p_go_intent 10") 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 = dev[0].wait_global_event(grpform_events, timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event(grpform_events, timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res1['role'] != 'client' or res0['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res1)
def test_nfc_p2p_go_legacy_config_token(dev): """NFC config token from P2P GO to legacy WPS STA""" logger.info("Start autonomous GOs") dev[0].p2p_start_go() logger.info("Connect legacy WPS STA with configuration token") conf = dev[0].group_request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip() if "FAIL" in conf: raise Exception("Failed to generate configuration token") dev[1].dump_monitor() res = dev[1].request("WPS_NFC_TAG_READ " + conf) if "FAIL" in res: raise Exception("Failed to provide NFC tag contents to wpa_supplicant") dev[1].wait_connected(timeout=15, error="Joining the group timed out") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) dev[1].request("DISCONNECT") dev[0].remove_group()
def test_nfc_p2p_static_handover_tagdev_client_group_iface(dev): """NFC static handover to form a new P2P group (NFC Tag device becomes P2P Client with group iface)""" set_ip_addr_info(dev[0]) logger.info("Perform NFC connection handover") res = dev[1].global_request("SET p2p_listen_reg_class 81") res2 = dev[1].global_request("SET p2p_listen_channel 6") if "FAIL" in res or "FAIL" in res2: raise Exception("Could not set Listen channel") pw = dev[1].global_request("WPS_NFC_TOKEN NDEF").rstrip() if "FAIL" in pw: raise Exception("Failed to generate password token") dev[1].global_request("SET p2p_no_group_iface 0") res = dev[1].global_request("P2P_SET nfc_tag 1").rstrip() if "FAIL" in res: raise Exception("Failed to enable NFC Tag for P2P static handover") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR-TAG").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") res = dev[1].global_request("P2P_LISTEN") if "FAIL" in res: raise Exception("Failed to start Listen mode") dev[1].dump_monitor() dev[0].dump_monitor() dev[0].global_request("SET p2p_go_intent 10") 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 = dev[0].wait_global_event(grpform_events, timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event(grpform_events, timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res1['role'] != 'client' or res0['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res1)
def test_wifi_display_persistent_group(dev): """P2P persistent group formation and re-invocation with Wi-Fi Display enabled""" try: enable_wifi_display(dev[0]) enable_wifi_display(dev[1]) enable_wifi_display(dev[2]) form(dev[0], dev[1]) peer = dev[1].get_peer(dev[0].p2p_dev_addr()) listen_freq = peer['listen_freq'] invite_from_cli(dev[0], dev[1]) invite_from_go(dev[0], dev[1]) dev[0].dump_monitor() dev[1].dump_monitor() networks = dev[0].list_networks(p2p=True) if len(networks) != 1: raise Exception("Unexpected number of networks") if "[P2P-PERSISTENT]" not in networks[0]['flags']: raise Exception("Not the persistent group data") if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq): raise Exception("Could not start GO") ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=2) if ev is None: raise Exception("GO start up timed out") dev[0].group_form_result(ev) connect_cli(dev[0], dev[2], social=True, freq=listen_freq) dev[0].dump_monitor() dev[1].dump_monitor() invite(dev[1], dev[0]) ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30) if ev is None: raise Exception("Timeout on group re-invocation (on client)") dev[1].group_form_result(ev) ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected P2P-GROUP-START on GO") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) finally: dev[0].request("SET wifi_display 0") dev[1].request("SET wifi_display 0") dev[2].request("SET wifi_display 0")
def test_nfc_p2p_go_neg_ip_pool_oom(dev): """NFC connection handover to form a new P2P group and IP pool OOM""" set_ip_addr_info(dev[0]) ip = dev[0].request("GET ip_addr_go") if ip != "192.168.42.1": raise Exception("Unexpected ip_addr_go returned: " + ip) dev[0].global_request("SET p2p_go_intent 10") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() with alloc_fail(dev[0], 1, "bitfield_alloc;wpa_init"): res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) if 'ip_addr' in res1: raise Exception("Unexpectedly received IP address from GO")
def test_autogo_chan_switch(dev): """P2P autonomous GO switching channels""" autogo(dev[0], freq=2417) connect_cli(dev[0], dev[1]) res = dev[0].request("CHAN_SWITCH 5 2422") if "FAIL" in res: # for now, skip test since mac80211_hwsim support is not yet widely # deployed return 'skip' ev = dev[0].wait_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") dev[0].dump_monitor() dev[1].dump_monitor() time.sleep(0.1) hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
def test_autogo_chan_switch(dev): """P2P autonomous GO switching channels""" autogo(dev[0], freq=2417) connect_cli(dev[0], dev[1]) res = dev[0].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 = dev[0].wait_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") dev[0].dump_monitor() dev[1].dump_monitor() time.sleep(0.1) hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
def test_nfc_p2p_go_neg(dev): """NFC connection handover to form a new P2P group (initiator becomes GO)""" set_ip_addr_info(dev[0]) ip = dev[0].request("GET ip_addr_go") if ip != "192.168.42.1": raise Exception("Unexpected ip_addr_go returned: " + ip) dev[0].global_request("SET p2p_go_intent 10") logger.info("Perform NFC connection handover") req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip() if "FAIL" in req: raise Exception("Failed to generate NFC connection handover request") sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip() if "FAIL" in sel: raise Exception("Failed to generate NFC connection handover select") dev[0].dump_monitor() dev[1].dump_monitor() res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)") res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel) if "FAIL" in res: raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)") ev = dev[0].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=15) if ev is None: raise Exception("Group formation timed out") res0 = dev[0].group_form_result(ev) ev = dev[1].wait_global_event(["P2P-GROUP-STARTED", "P2P-GO-NEG-FAILURE", "P2P-GROUP-FORMATION-FAILURE", "WPS-PIN-NEEDED"], timeout=1) if ev is None: raise Exception("Group formation timed out") res1 = dev[1].group_form_result(ev) logger.info("Group formed") if res1['role'] != 'client' or res0['role'] != 'GO': raise Exception("Unexpected roles negotiated") hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) check_ip_addr(res1)
def test_grpform_per_sta_psk(dev): """P2P group formation with per-STA PSKs""" dev[0].request("P2P_SET per_sta_psk 1") [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) check_grpform_results(i_res, r_res) pin = dev[2].wps_read_pin() dev[0].p2p_go_authorize_client(pin) c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) check_grpform_results(i_res, c_res) if r_res['psk'] == c_res['psk']: raise Exception("Same PSK assigned for both clients") hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) dev[0].remove_group() dev[1].wait_go_ending_session() dev[2].wait_go_ending_session()
def test_concurrent_p2pcli(dev, apdev): """Concurrent P2P client join""" logger.info("Connect to an infrastructure AP") hapd = hostapd.add_ap(apdev[0]["ifname"], {"ssid": "test-open"}) dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") hwsim_utils.test_connectivity(dev[0], hapd) logger.info("Join a P2P group while associated to an AP") dev[0].request("SET p2p_no_group_iface 0") dev[1].p2p_start_go(freq=2412) pin = dev[0].wps_read_pin() dev[1].p2p_go_authorize_client(pin) dev[0].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60, social=True) hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) dev[1].remove_group() dev[0].wait_go_ending_session() logger.info("Confirm AP connection after P2P group removal") hwsim_utils.test_connectivity(dev[0], hapd)
def run_autogo_chan_switch(dev): autogo(dev[0], freq=2417) connect_cli(dev[0], dev[1], freq=2417) res = dev[0].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 = dev[0].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") dev[0].dump_monitor() dev[1].dump_monitor() time.sleep(0.1) hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) dev[0].remove_group() dev[1].wait_go_ending_session()
def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display'): r_dev.p2p_listen() i_dev.p2p_listen() pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent) i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=15, go_intent=i_intent, expect_failure=expect_failure) r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure) logger.debug("i_res: " + str(i_res)) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() i_dev.dump_monitor() if i_go_neg_status: if i_res['result'] != 'go-neg-failed': raise Exception("Expected GO Negotiation failure not reported") if i_res['status'] != i_go_neg_status: raise Exception("Expected GO Negotiation status not seen") if expect_failure: return logger.info("Group formed") hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
def test_grpform_random_addr(dev): """P2P group formation with random interface addresses""" dev[0].global_request("SET p2p_no_group_iface 0") dev[1].global_request("SET p2p_no_group_iface 0") try: if "OK" not in dev[0].global_request("SET p2p_interface_random_mac_addr 1"): raise Exception("Failed to set p2p_interface_random_mac_addr") if "OK" not in dev[1].global_request("SET p2p_interface_random_mac_addr 1"): raise Exception("Failed to set p2p_interface_random_mac_addr") [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) if "p2p-wlan" not in i_res['ifname']: raise Exception("Unexpected group interface name") check_grpform_results(i_res, r_res) hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) remove_group(dev[0], dev[1]) if i_res['ifname'] in utils.get_ifnames(): raise Exception("Group interface netdev was not removed") finally: dev[0].global_request("SET p2p_interface_random_mac_addr 0") dev[1].global_request("SET p2p_interface_random_mac_addr 0")