tests: Long P2P_LISTEN and offchannel TX
[mech_eap.git] / tests / hwsim / test_p2p_discovery.py
index 22ce173..166180e 100644 (file)
@@ -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,7 +122,8 @@ 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")
@@ -178,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)
@@ -210,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")
@@ -318,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")
@@ -327,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():
@@ -346,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()
@@ -487,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()
@@ -531,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])
@@ -556,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
@@ -576,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()