def test_autogo_scan(dev): """P2P autonomous GO and no P2P IE in Probe Response scan results""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() dev[0].p2p_start_go(freq=2412, persistent=True) bssid = dev[0].p2p_interface_addr() dev[1].discover_peer(addr0) dev[1].p2p_stop_find() ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2) time.sleep(0.1) dev[1].flush_scan_cache() pin = dev[1].wps_read_pin() dev[0].group_request("WPS_PIN any " + pin) try: dev[1].request("SET p2p_disabled 1") dev[1].request("SCAN freq=2412") ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) if ev is None: raise Exception("Active scan did not complete") finally: dev[1].request("SET p2p_disabled 0") for i in range(2): dev[1].request("SCAN freq=2412 passive=1") ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) if ev is None: raise Exception("Scan did not complete") # Disable management frame processing for a moment to skip Probe Response # frame with P2P IE. dev[0].group_request("SET ext_mgmt_frame_handling 1") dev[1].global_request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join") # Skip the first Probe Request frame ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) if ev is None: raise Exception("No Probe Request frame seen") if not ev.split(' ')[4].startswith("40"): raise Exception("Not a Probe Request frame") # If a P2P Device is not used, the PD Request will be received on the group # interface (which is actually wlan0, since a separate interface is not # used), which was set to external management frame handling, so need to # reply to it manually. res = dev[0].get_driver_status() if not (int(res['capa.flags'], 0) & 0x20000000): # Reply to PD Request while still filtering Probe Request frames msg = rx_pd_req(dev[0]) mgmt_tx( dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format( addr1, addr0, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg['dialog_token'])) # Skip Probe Request frames until something else is received for i in range(10): ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) if ev is None: raise Exception("No frame seen") if not ev.split(' ')[4].startswith("40"): break # Allow wpa_supplicant to process authentication and association dev[0].group_request("SET ext_mgmt_frame_handling 0") # Joining the group should succeed and indicate persistent group based on # Beacon frame P2P IE. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10) if ev is None: raise Exception("Failed to join group") if "[PERSISTENT]" not in ev: raise Exception("Did not recognize group as persistent") dev[0].remove_group() dev[1].wait_go_ending_session()
def test_autogo_scan(dev): """P2P autonomous GO and no P2P IE in Probe Response scan results""" addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() dev[0].p2p_start_go(freq=2412, persistent=True) bssid = dev[0].p2p_interface_addr() dev[1].discover_peer(addr0) dev[1].p2p_stop_find() ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2) time.sleep(0.1) dev[1].flush_scan_cache() pin = dev[1].wps_read_pin() dev[0].group_request("WPS_PIN any " + pin) try: dev[1].request("SET p2p_disabled 1") dev[1].request("SCAN freq=2412") ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) if ev is None: raise Exception("Active scan did not complete") finally: dev[1].request("SET p2p_disabled 0") for i in range(2): dev[1].request("SCAN freq=2412 passive=1") ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) if ev is None: raise Exception("Scan did not complete") # Disable management frame processing for a moment to skip Probe Response # frame with P2P IE. dev[0].group_request("SET ext_mgmt_frame_handling 1") dev[1].global_request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join") # Skip the first Probe Request frame ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) if ev is None: raise Exception("No Probe Request frame seen") if not ev.split(' ')[4].startswith("40"): raise Exception("Not a Probe Request frame") # If a P2P Device is not used, the PD Request will be received on the group # interface (which is actually wlan0, since a separate interface is not # used), which was set to external management frame handling, so need to # reply to it manually. res = dev[0].get_driver_status() if not (int(res['capa.flags'], 0) & 0x20000000): # Reply to PD Request while still filtering Probe Request frames msg = rx_pd_req(dev[0]) mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr0, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg['dialog_token'])) # Skip Probe Request frames until something else is received for i in range(10): ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) if ev is None: raise Exception("No frame seen") if not ev.split(' ')[4].startswith("40"): break # Allow wpa_supplicant to process authentication and association dev[0].group_request("SET ext_mgmt_frame_handling 0") # Joining the group should succeed and indicate persistent group based on # Beacon frame P2P IE. ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10) if ev is None: raise Exception("Failed to join group") if "[PERSISTENT]" not in ev: raise Exception("Did not recognize group as persistent") dev[0].remove_group() dev[1].wait_go_ending_session()
def test_grpform_go_neg_dup_on_restart(dev): """Duplicated GO Negotiation Request after GO Neg restart""" if dev[0].p2p_dev_addr() > dev[1].p2p_dev_addr(): higher = dev[0] lower = dev[1] else: higher = dev[1] lower = dev[0] addr_low = lower.p2p_dev_addr() addr_high = higher.p2p_dev_addr() higher.p2p_listen() if not lower.discover_peer(addr_high): raise Exception("Could not discover peer") lower.p2p_stop_find() if "OK" not in lower.request("P2P_CONNECT %s pbc" % addr_high): raise Exception("Could not request GO Negotiation") ev = higher.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10) if ev is None: raise Exception("GO Neg Req RX not reported") # Wait for GO Negotiation Response (Status=1) to go through time.sleep(0.2) if "FAIL" in lower.request("SET ext_mgmt_frame_handling 1"): raise Exception("Failed to enable external management frame handling") higher.p2p_stop_find() higher.global_request("P2P_CONNECT " + addr_low + " pbc") # Wait for the GO Negotiation Request frame of the restarted GO Negotiation rx_msg = lower.mgmt_rx() if rx_msg is None: raise Exception("MGMT-RX timeout") p2p = parse_p2p_public_action(rx_msg['payload']) if p2p is None: raise Exception("Not a P2P Public Action frame") if p2p['subtype'] != 0: raise Exception("Unexpected P2P Public Action subtype %d" % p2p['subtype']) # Send duplicate GO Negotiation Request from the prior instance of GO # Negotiation lower.p2p_stop_find() peer = higher.get_peer(addr_low) msg = p2p_hdr(addr_high, addr_low, type=P2P_GO_NEG_REQ, dialog_token=123) attrs = p2p_attr_capability(dev_capab=0x25, group_capab=0x08) attrs += p2p_attr_go_intent(go_intent=7, tie_breaker=1) attrs += p2p_attr_config_timeout() attrs += p2p_attr_listen_channel(chan=(int(peer['listen_freq']) - 2407) / 5) attrs += p2p_attr_intended_interface_addr(lower.p2p_dev_addr()) attrs += p2p_attr_channel_list() attrs += p2p_attr_device_info(addr_low, config_methods=0x80, name="Device A") attrs += p2p_attr_operating_channel() wsc_attrs = struct.pack(">HHH", 0x1012, 2, 4) msg['payload'] += ie_p2p(attrs) + ie_wsc(wsc_attrs) mgmt_tx(lower, "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr_high, addr_high, peer['listen_freq'], binascii.hexlify(msg['payload']))) # Wait for the GO Negotiation Response frame which would have been sent in # this case previously, but not anymore after the check for # dev->go_neg_req_sent and dev->flags & P2P_DEV_PEER_WAITING_RESPONSE. rx_msg = lower.mgmt_rx(timeout=0.2) if rx_msg is not None: raise Exception("Unexpected management frame") if "FAIL" in lower.request("SET ext_mgmt_frame_handling 0"): raise Exception("Failed to disable external management frame handling") lower.p2p_listen() ev = lower.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10) if ev is None: raise Exception("GO Negotiation did not succeed on dev0") ev = higher.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10) if ev is None: raise Exception("GO Negotiation did not succeed on dev1") ev0 = lower.wait_global_event(["P2P-GROUP-STARTED"], timeout=15) if ev0 is None: raise Exception("Group formation timed out on dev0") lower.group_form_result(ev0) ev1 = higher.wait_global_event(["P2P-GROUP-STARTED"], timeout=15) if ev1 is None: raise Exception("Group formation timed out on dev1") higher.group_form_result(ev1) lower.dump_monitor() higher.dump_monitor() remove_group(lower, higher) lower.dump_monitor() higher.dump_monitor()