From b162675fd925a00246b4dedacffa373f8e5c180d Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 1 Sep 2013 11:56:55 +0300 Subject: [PATCH] tests: Add test cases for per-STA PSK in P2P group Signed-hostap: Jouni Malinen --- tests/hwsim/hwsim_utils.py | 5 ++++ tests/hwsim/test_p2p_grpform.py | 51 +++++++++++++++++++++++++++++++++ tests/hwsim/wpasupplicant.py | 7 +++++ 3 files changed, 63 insertions(+) diff --git a/tests/hwsim/hwsim_utils.py b/tests/hwsim/hwsim_utils.py index cd4a1b770..365fbb257 100644 --- a/tests/hwsim/hwsim_utils.py +++ b/tests/hwsim/hwsim_utils.py @@ -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 diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index 61ceed9bf..3780eb0f6 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -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") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 3e8036e39..282c6ea74 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -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):