Handle NULL return from os_zalloc() in sta_track_add()
[mech_eap.git] / tests / hwsim / test_p2p_wifi_display.py
index c5dcb0b..94c7da9 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 time
@@ -12,8 +13,7 @@ import Queue
 
 import hwsim_utils
 import utils
-from test_p2p_autogo import connect_cli
-from test_p2p_persistent import form, invite_from_cli, invite_from_go
+from p2p_utils import *
 
 def test_wifi_display(dev):
     """Wi-Fi Display extensions to P2P"""
@@ -44,6 +44,10 @@ def test_wifi_display(dev):
     audio = "000f" + "010203040506070809101112131415"
     dev[0].request("WFD_SUBELEM_SET 2 " + audio)
 
+    elems = dev[0].request("WFD_SUBELEM_GET all")
+    if wfd_devinfo not in elems:
+        raise Exception("Could not fetch back configured subelements")
+
     wfd_devinfo2 = "00001c440028"
     dev[1].request("SET wifi_display 1")
     dev[1].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo2)
@@ -51,7 +55,7 @@ def test_wifi_display(dev):
         raise Exception("Could not fetch back configured subelement")
 
     dev[0].p2p_listen()
-    if "FAIL" in dev[1].request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
+    if "FAIL" in dev[1].global_request("P2P_SERV_DISC_REQ " + dev[0].p2p_dev_addr() + " wifi-display [source][pri-sink] 2,3,4,5"):
         raise Exception("Setting SD request failed")
     dev[1].p2p_find(social=True)
     ev = dev[0].wait_global_event(["P2P-SERV-DISC-REQ"], timeout=10)
@@ -97,7 +101,8 @@ def test_wifi_display(dev):
 
     pin = dev[0].wps_read_pin()
     dev[0].p2p_go_neg_auth(dev[1].p2p_dev_addr(), pin, 'display')
-    res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter', timeout=20, go_intent=15)
+    res1 = dev[1].p2p_go_neg_init(dev[0].p2p_dev_addr(), pin, 'enter',
+                                  timeout=20, go_intent=15, freq=2437)
     res2 = dev[0].p2p_go_neg_auth_result()
 
     bss = dev[0].get_bss("p2p_dev_addr=" + dev[1].p2p_dev_addr())
@@ -116,11 +121,11 @@ def test_wifi_display(dev):
     dev[2].request("SET wifi_display 1")
     dev[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo3)
     dev[2].p2p_find(social=True)
-    ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
+    ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
     if ev is None:
         raise Exception("Device discovery timed out")
     if dev[1].p2p_dev_addr() not in ev:
-        ev = dev[2].wait_event(["P2P-DEVICE-FOUND"], timeout=5)
+        ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
         if ev is None:
             raise Exception("Device discovery timed out")
         if dev[1].p2p_dev_addr() not in ev:
@@ -167,6 +172,33 @@ def test_wifi_display(dev):
     if dev[0].request("WFD_SUBELEM_GET 1") != "0006020304050608":
         raise Exception("Unexpected WFD_SUBELEM_GET 1 value (per-interface)")
 
+    elems = dev[0].request("WFD_SUBELEM_GET all")
+    if "OK" not in dev[0].request("WFD_SUBELEM_SET all " + elems):
+        raise Exception("WFD_SUBELEM_SET all failed")
+    if dev[0].request("WFD_SUBELEM_GET all") != elems:
+        raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
+    test = "00000600411c440028"
+    if "OK" not in dev[0].request("WFD_SUBELEM_SET all " + test):
+        raise Exception("WFD_SUBELEM_SET all failed")
+    if dev[0].request("WFD_SUBELEM_GET all") != test:
+        raise Exception("Mismatch in WFS_SUBELEM_SET/GET all")
+
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_SET all qwerty"):
+        raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_SET all 11"):
+        raise Exception("Invalid WFD_SUBELEM_SET all succeeded")
+    dev[0].request("WFD_SUBELEM_SET all 112233445566")
+    dev[0].request("WFD_SUBELEM_SET all ff0000fe0000fd00")
+
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_SET 300 112233"):
+        raise Exception("Invalid WFD_SUBELEM_SET 300 succeeded")
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_SET -1 112233"):
+        raise Exception("Invalid WFD_SUBELEM_SET -1 succeeded")
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_GET 300"):
+        raise Exception("Invalid WFD_SUBELEM_GET 300 succeeded")
+    if "FAIL" not in dev[0].request("WFD_SUBELEM_GET -1"):
+        raise Exception("Invalid WFD_SUBELEM_GET -1 succeeded")
+
     dev[0].request("SET wifi_display 0")
     dev[1].request("SET wifi_display 0")
     dev[2].request("SET wifi_display 0")
@@ -200,7 +232,7 @@ def test_wifi_display_go_invite(dev):
         dev[0].p2p_start_go(freq=2412)
 
         # Add test client to the group
-        connect_cli(dev[0], dev[2])
+        connect_cli(dev[0], dev[2], social=True, freq=2412)
 
         logger.info("Invite peer to join the group")
         dev[0].p2p_go_authorize_client(pin)
@@ -236,21 +268,38 @@ def test_wifi_display_persistent_group(dev):
 
         dev[0].dump_monitor()
         dev[1].dump_monitor()
-        networks = dev[0].list_networks()
+        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 state GO")
-        connect_cli(dev[0], dev[2])
-        invite_from_cli(dev[0], dev[1])
+            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")
 
+@remote_compatible
 def test_wifi_display_invalid_subelem(dev):
     """Wi-Fi Display and invalid subelement parsing"""
     addr1 = dev[1].p2p_dev_addr()
@@ -271,3 +320,41 @@ def test_wifi_display_invalid_subelem(dev):
     finally:
         dev[0].request("SET wifi_display 0")
         dev[1].request("SET wifi_display 0")
+
+def test_wifi_display_parsing(dev):
+    """Wi-Fi Display extensions to P2P and special parsing cases"""
+    try:
+        _test_wifi_display_parsing(dev)
+    finally:
+        dev[1].request("VENDOR_ELEM_REMOVE 11 *")
+        dev[0].request("SET wifi_display 0")
+
+def _test_wifi_display_parsing(dev):
+    wfd_devinfo = "00411c440028"
+    dev[0].request("SET wifi_display 1")
+    dev[0].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
+    dev[0].p2p_start_go(freq=2412)
+
+    # P2P Client with invalid WFD IE
+    if "OK" not in dev[1].request("VENDOR_ELEM_ADD 11 dd10506f9a0a000000010000060000ffffff"):
+        raise Exception("VENDOR_ELEM_ADD failed")
+
+    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,
+                             social=True, freq=2412)
+    bssid = dev[0].get_group_status_field('bssid')
+    dev[2].scan_for_bss(bssid, freq=2412, force_scan=True)
+    bss = dev[2].get_bss(bssid)
+    if bss['wfd_subelems'] != "000006" + wfd_devinfo:
+        raise Exception("Unexpected WFD elements in scan results: " + bss['wfd_subelems'])
+
+    # P2P Client without WFD IE
+    pin = dev[2].wps_read_pin()
+    dev[0].p2p_go_authorize_client(pin)
+    dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
+                             social=True, freq=2412)
+    dev[2].remove_group()
+
+    dev[0].remove_group()
+    dev[1].wait_go_ending_session()