X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=tests%2Fhwsim%2Ftest_p2p_discovery.py;h=166180e71f52dcc0e8c8fca33ae4d6ada6dc7171;hb=a39a54517af99232682b5af5ef0f556ebe963742;hp=c102fcc1c50eadefe460e01fadbe330f9ac3de65;hpb=700c5d0b1645330bfac0c27e729c2699366fa953;p=mech_eap.git diff --git a/tests/hwsim/test_p2p_discovery.py b/tests/hwsim/test_p2p_discovery.py index c102fcc..166180e 100644 --- a/tests/hwsim/test_p2p_discovery.py +++ b/tests/hwsim/test_p2p_discovery.py @@ -4,6 +4,7 @@ # This software may be distributed under the terms of the BSD license. # See README for more details. +from remotehost import remote_compatible import logging logger = logging.getLogger() import os @@ -15,6 +16,7 @@ from p2p_utils import * from test_gas import start_ap from test_cfg80211 import nl80211_remain_on_channel +@remote_compatible def test_discovery(dev): """P2P device discovery and provision discovery""" addr0 = dev[0].p2p_dev_addr() @@ -97,6 +99,7 @@ def test_discovery(dev): if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 00:11:22:33:44:55 foo"): raise Exception("Invalid P2P_PROV_DISC accepted") +@remote_compatible def test_discovery_pd_retries(dev): """P2P device discovery and provision discovery retries""" addr0 = dev[0].p2p_dev_addr() @@ -119,12 +122,15 @@ def test_discovery_group_client(dev): 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) + 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") @@ -159,6 +165,15 @@ def test_discovery_group_client(dev): if ev is None: raise Exception("Timeout on waiting for GO Negotiation Request") +def stop_p2p_find_and_wait(dev): + dev.request("P2P_STOP_FIND") + for i in range(10): + res = dev.get_driver_status_field("scan_state") + if "SCAN_STARTED" not in res and "SCAN_REQUESTED" not in res: + break + logger.debug("Waiting for final P2P_FIND scan to complete") + time.sleep(0.02) + def test_discovery_ctrl_char_in_devname(dev): """P2P device discovery and control character in Device Name""" try: @@ -167,7 +182,7 @@ def test_discovery_ctrl_char_in_devname(dev): dev[1].global_request("SET device_name Device B") def _test_discovery_ctrl_char_in_devname(dev): - dev[1].global_request("SET device_name Device\nB") + dev[1].global_request("SET device_name Device\tB") addr0 = dev[0].p2p_dev_addr() addr1 = dev[1].p2p_dev_addr() res = dev[0].p2p_start_go(freq=2422) @@ -177,7 +192,9 @@ def _test_discovery_ctrl_char_in_devname(dev): dev[1].scan_for_bss(bssid, freq=2422) dev[1].p2p_connect_group(addr0, pin, timeout=60, freq=2422) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): raise Exception("Could not discover group client") @@ -197,6 +214,7 @@ def _test_discovery_ctrl_char_in_devname(dev): if devname != "Device_B": raise Exception("Unexpected device_name from peer: " + devname) +@remote_compatible def test_discovery_dev_type(dev): """P2P device discovery with Device Type filter""" dev[1].request("SET sec_device_type 1-0050F204-2") @@ -305,8 +323,7 @@ def test_discovery_social_plus_one(dev): if dev[1].peer_known(go): raise Exception("GO found in social-only scan") -def test_discovery_and_interface_disabled(dev): - """P2P device discovery with interface getting didabled""" +def _test_discovery_and_interface_disabled(dev, delay=1): try: if "OK" not in dev[0].p2p_find(): raise Exception("Failed to start P2P find") @@ -314,7 +331,7 @@ def test_discovery_and_interface_disabled(dev): if ev is None: raise Exception("Scan did not start") dev[0].request("DRIVER_EVENT INTERFACE_DISABLED") - time.sleep(1) + time.sleep(delay) # verify that P2P_FIND is rejected if "FAIL" not in dev[0].p2p_find(): @@ -333,6 +350,11 @@ def test_discovery_and_interface_disabled(dev): finally: dev[0].request("DRIVER_EVENT INTERFACE_ENABLED") +def test_discovery_and_interface_disabled(dev): + """P2P device discovery with interface getting disabled""" + _test_discovery_and_interface_disabled(dev, delay=1) + _test_discovery_and_interface_disabled(dev, delay=5) + def test_discovery_auto(dev): """P2P device discovery and provision discovery with auto GO/dev selection""" dev[0].flush_scan_cache() @@ -474,6 +496,7 @@ def test_p2p_listen_and_offchannel_tx(dev): dev[2].p2p_stop_find() dev[0].p2p_stop_find() +@remote_compatible def test_p2p_listen_and_scan(dev): """P2P_LISTEN and scan""" dev[0].p2p_listen() @@ -518,6 +541,7 @@ def test_p2p_config_methods(dev): wpas.p2p_stop_find() +@remote_compatible def test_discovery_after_gas(dev, apdev): """P2P device discovery after GAS/ANQP exchange""" hapd = start_ap(apdev[0]) @@ -543,6 +567,7 @@ def test_discovery_after_gas(dev, apdev): if end - start > 1.3: raise Exception("Device discovery took unexpectedly long time") +@remote_compatible def test_discovery_listen_find(dev): """P2P_LISTEN immediately followed by P2P_FIND""" # Request an external remain-on-channel operation to delay start of the ROC @@ -563,3 +588,36 @@ def test_discovery_listen_find(dev): raise Exception("Device discovery timed out") if ev is None: raise Exception("Did not find peer quickly enough after stopped P2P_LISTEN") + +def test_discovery_long_listen(dev): + """Long P2P_LISTEN and offchannel TX""" + addr0 = dev[0].p2p_dev_addr() + dev[0].p2p_listen() + + wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') + wpas.interface_add("wlan5") + addr = wpas.p2p_dev_addr() + if not wpas.discover_peer(addr0): + raise Exception("Device discovery timed out") + peer = wpas.get_peer(addr0) + chan = '1' if peer['listen_freq'] == '2462' else '11' + + wpas.request("P2P_SET listen_channel " + chan) + wpas.request("P2P_LISTEN 10") + if not dev[0].discover_peer(addr): + raise Exception("Device discovery timed out (2)") + + time.sleep(0.1) + wpas.global_request("P2P_PROV_DISC " + addr0 + " display") + ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) + if ev is None: + raise Exception("Provision discovery timed out") + dev[0].p2p_stop_find() + + # Verify that the long listen period is still continuing after off-channel + # TX of Provision Discovery frames. + if not dev[1].discover_peer(addr): + raise Exception("Device discovery timed out (3)") + + dev[1].p2p_stop_find() + wpas.p2p_stop_find()