diff --git a/tests/hwsim/test_p2p_concurrency.py b/tests/hwsim/test_p2p_concurrency.py new file mode 100644 index 000000000..29aaa26e0 --- /dev/null +++ b/tests/hwsim/test_p2p_concurrency.py @@ -0,0 +1,149 @@ +#!/usr/bin/python +# +# P2P concurrency test cases +# Copyright (c) 2013, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import logging +logger = logging.getLogger() +import time + +import hwsim_utils +import hostapd +from test_p2p_grpform import go_neg_pin_authorized +from test_p2p_grpform import go_neg_pbc +from test_p2p_grpform import check_grpform_results +from test_p2p_grpform import remove_group + +def test_concurrent_autogo(dev, apdev): + """Concurrent P2P autonomous GO""" + logger.info("Connect to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + + logger.info("Start a P2P group while associated to an AP") + dev[0].request("SET p2p_no_group_iface 0") + dev[0].p2p_start_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, + social=True) + hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) + dev[0].remove_group() + dev[1].wait_go_ending_session() + + logger.info("Confirm AP connection after P2P group removal") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_p2pcli(dev, apdev): + """Concurrent P2P client join""" + logger.info("Connect to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + + logger.info("Join a P2P group while associated to an AP") + dev[0].request("SET p2p_no_group_iface 0") + dev[1].p2p_start_go(freq=2412) + pin = dev[0].wps_read_pin() + dev[1].p2p_go_authorize_client(pin) + dev[0].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60, + social=True) + hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) + dev[1].remove_group() + dev[0].wait_go_ending_session() + + logger.info("Confirm AP connection after P2P group removal") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_grpform_go(dev, apdev): + """Concurrent P2P group formation to become GO""" + logger.info("Connect to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + + logger.info("Form a P2P group while associated to an AP") + dev[0].request("SET p2p_no_group_iface 0") + + [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) + remove_group(dev[0], dev[1]) + + logger.info("Confirm AP connection after P2P group removal") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_grpform_cli(dev, apdev): + """Concurrent P2P group formation to become P2P Client""" + logger.info("Connect to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + + logger.info("Form a P2P group while associated to an AP") + dev[0].request("SET p2p_no_group_iface 0") + + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, + r_dev=dev[1], r_intent=15) + check_grpform_results(i_res, r_res) + remove_group(dev[0], dev[1]) + + logger.info("Confirm AP connection after P2P group removal") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_grpform_while_connecting(dev, apdev): + """Concurrent P2P group formation while connecting to an AP""" + logger.info("Start connection to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False) + + logger.info("Form a P2P group while connecting to an AP") + dev[0].request("SET p2p_no_group_iface 0") + + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412, + r_dev=dev[1], r_freq=2412) + check_grpform_results(i_res, r_res) + remove_group(dev[0], dev[1]) + + logger.info("Confirm AP connection after P2P group removal") + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_grpform_while_connecting2(dev, apdev): + """Concurrent P2P group formation while connecting to an AP (2)""" + logger.info("Start connection to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False) + + logger.info("Form a P2P group while connecting to an AP") + dev[0].request("SET p2p_no_group_iface 0") + + [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, i_freq=2412, + r_dev=dev[1], r_intent=0, r_freq=2412) + check_grpform_results(i_res, r_res) + remove_group(dev[0], dev[1]) + + logger.info("Confirm AP connection after P2P group removal") + dev[0].wait_completed() + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) + +def test_concurrent_grpform_while_connecting3(dev, apdev): + """Concurrent P2P group formation while connecting to an AP (3)""" + logger.info("Start connection to an infrastructure AP") + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) + dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False) + + logger.info("Form a P2P group while connecting to an AP") + dev[0].request("SET p2p_no_group_iface 0") + + [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=15, i_freq=2412, + r_dev=dev[0], r_intent=0, r_freq=2412) + check_grpform_results(i_res, r_res) + remove_group(dev[0], dev[1]) + + logger.info("Confirm AP connection after P2P group removal") + dev[0].wait_completed() + hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname']) diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index cf24578dd..868dc8d67 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -89,19 +89,20 @@ def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_fai 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): +def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq): logger.debug("Initiate GO Negotiation from i_dev") - i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", timeout=20, go_intent=i_intent) + i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", + timeout=20, go_intent=i_intent, freq=freq) logger.debug("i_res: " + str(i_res)) res.put(i_res) -def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None): +def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None): r_dev.p2p_find(social=True) i_dev.p2p_find(social=True) logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() res = Queue.Queue() - t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res)) + t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) @@ -109,7 +110,8 @@ def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None): raise Exception("GO Negotiation timed out") r_dev.dump_monitor() logger.debug("Re-initiate GO Negotiation from r_dev") - r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", go_intent=r_intent, timeout=20) + r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", + go_intent=r_intent, timeout=20, freq=r_freq) logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join() diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 18ef0e175..8c449787f 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -494,9 +494,9 @@ class WpaSupplicant: raise Exception("Failed to authorize client connection on GO") return None - def p2p_connect_group(self, go_addr, pin, timeout=0): + def p2p_connect_group(self, go_addr, pin, timeout=0, social=False): self.dump_monitor() - if not self.discover_peer(go_addr, social=False): + if not self.discover_peer(go_addr, social=social): raise Exception("GO " + go_addr + " not found") self.dump_monitor() cmd = "P2P_CONNECT " + go_addr + " " + pin + " join" @@ -622,3 +622,10 @@ class WpaSupplicant: def relog(self): self.request("RELOG") + + def wait_completed(self, timeout=10): + for i in range(0, timeout * 2): + if self.get_status_field("wpa_state") == "COMPLETED": + return + time.sleep(0.5) + raise Exception("Timeout while waiting for COMPLETED state")