]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Add test cases for per-STA PSK in P2P group
authorJouni Malinen <j@w1.fi>
Sun, 1 Sep 2013 08:56:55 +0000 (11:56 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 1 Sep 2013 18:35:10 +0000 (21:35 +0300)
Signed-hostap: Jouni Malinen <j@w1.fi>

tests/hwsim/hwsim_utils.py
tests/hwsim/test_p2p_grpform.py
tests/hwsim/wpasupplicant.py

index cd4a1b7704d9db01e62e0129807280aee7db6ceb..365fbb25722000894f894344ac9af596d64ed4b8 100644 (file)
@@ -33,6 +33,11 @@ def test_connectivity_p2p(dev1, dev2):
     ifname2 = dev2.group_ifname if dev2.group_ifname else dev2.ifname
     test_connectivity(ifname1, ifname2)
 
+def test_connectivity_p2p_sta(dev1, dev2):
+    ifname1 = dev1.group_ifname if dev1.group_ifname else dev1.ifname
+    ifname2 = dev2.ifname
+    test_connectivity(ifname1, ifname2)
+
 def test_connectivity_sta(dev1, dev2):
     ifname1 = dev1.ifname
     ifname2 = dev2.ifname
index 61ceed9bf6e98978597af8770e98e1b3eba235fc..3780eb0f67873560ae2da6a07030ae4691cac25b 100644 (file)
@@ -76,6 +76,7 @@ def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_fai
         return
     logger.info("Group formed")
     hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
+    return [i_res, r_res]
 
 def go_neg_init_pbc(i_dev, r_dev, i_intent, res):
     logger.debug("Initiate GO Negotiation from i_dev")
@@ -158,3 +159,53 @@ def test_both_go_neg_display(dev):
 def test_both_go_neg_enter(dev):
     """P2P GO Negotiation with both devices trying to enter PIN"""
     go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='enter', r_method='enter')
+
+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()
+    ev = dev[1].wait_event(["P2P-GROUP-REMOVED"], timeout=2)
+    if ev is None:
+        raise Exception("Group removal event timed out")
+    if "reason=GO_ENDING_SESSION" not in ev:
+        raise Exception("Unexpected group removal reason")
+    ev = dev[2].wait_event(["P2P-GROUP-REMOVED"], timeout=2)
+    if ev is None:
+        raise Exception("Group removal event timed out")
+    if "reason=GO_ENDING_SESSION" not in ev:
+        raise Exception("Unexpected group removal reason")
+
+def test_grpform_per_sta_psk_wps(dev):
+    """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
+    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)
+
+    dev[0].p2p_go_authorize_client_pbc()
+    dev[2].request("WPS_PBC")
+    ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
+    if ev is None:
+        raise Exception("Association with the GO timed out")
+
+    hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
+
+    dev[0].remove_group()
+    dev[2].request("DISCONNECT")
+    ev = dev[1].wait_event(["P2P-GROUP-REMOVED"], timeout=2)
+    if ev is None:
+        raise Exception("Group removal event timed out")
+    if "reason=GO_ENDING_SESSION" not in ev:
+        raise Exception("Unexpected group removal reason")
index 3e8036e393f375fd05104e6c14ad818f79fa9640..282c6ea74ae51ec08a319e62e388f88eea01b98c 100644 (file)
@@ -53,6 +53,7 @@ class WpaSupplicant:
     def reset(self):
         self.request("FLUSH")
         self.request("SET ignore_old_scan_res 0")
+        self.request("P2P_SET per_sta_psk 0")
         self.group_ifname = None
         self.dump_monitor()
 
@@ -336,6 +337,12 @@ class WpaSupplicant:
             raise Exception("Failed to authorize client connection on GO")
         return None
 
+    def p2p_go_authorize_client_pbc(self):
+        cmd = "WPS_PBC"
+        if "FAIL" in self.group_request(cmd):
+            raise Exception("Failed to authorize client connection on GO")
+        return None
+
     def p2p_connect_group(self, go_addr, pin, timeout=0):
         self.dump_monitor()
         if not self.discover_peer(go_addr, social=False):