1 # P2P concurrency test cases
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
13 from test_p2p_grpform import go_neg_pin_authorized
14 from test_p2p_grpform import go_neg_pbc
15 from test_p2p_grpform import check_grpform_results
16 from test_p2p_grpform import remove_group
17 from test_p2p_persistent import form
18 from test_p2p_persistent import invite_from_cli
19 from test_p2p_persistent import invite_from_go
20 from test_p2p_persistent import invite
22 def test_concurrent_autogo(dev, apdev):
23 """Concurrent P2P autonomous GO"""
24 logger.info("Connect to an infrastructure AP")
25 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
26 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
27 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
29 logger.info("Start a P2P group while associated to an AP")
30 dev[0].request("SET p2p_no_group_iface 0")
32 pin = dev[1].wps_read_pin()
33 dev[0].p2p_go_authorize_client(pin)
34 dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
36 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
38 dev[1].wait_go_ending_session()
40 logger.info("Confirm AP connection after P2P group removal")
41 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
43 def test_concurrent_p2pcli(dev, apdev):
44 """Concurrent P2P client join"""
45 logger.info("Connect to an infrastructure AP")
46 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
47 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
48 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
50 logger.info("Join a P2P group while associated to an AP")
51 dev[0].request("SET p2p_no_group_iface 0")
52 dev[1].p2p_start_go(freq=2412)
53 pin = dev[0].wps_read_pin()
54 dev[1].p2p_go_authorize_client(pin)
55 dev[0].p2p_connect_group(dev[1].p2p_dev_addr(), pin, timeout=60,
57 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
59 dev[0].wait_go_ending_session()
61 logger.info("Confirm AP connection after P2P group removal")
62 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
64 def test_concurrent_grpform_go(dev, apdev):
65 """Concurrent P2P group formation to become GO"""
66 logger.info("Connect to an infrastructure AP")
67 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
68 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
69 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
71 logger.info("Form a P2P group while associated to an AP")
72 dev[0].request("SET p2p_no_group_iface 0")
74 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
75 r_dev=dev[1], r_intent=0)
76 check_grpform_results(i_res, r_res)
77 remove_group(dev[0], dev[1])
79 logger.info("Confirm AP connection after P2P group removal")
80 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
82 def test_concurrent_grpform_cli(dev, apdev):
83 """Concurrent P2P group formation to become P2P Client"""
84 logger.info("Connect to an infrastructure AP")
85 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
86 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
87 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
89 logger.info("Form a P2P group while associated to an AP")
90 dev[0].request("SET p2p_no_group_iface 0")
92 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
93 r_dev=dev[1], r_intent=15)
94 check_grpform_results(i_res, r_res)
95 remove_group(dev[0], dev[1])
97 logger.info("Confirm AP connection after P2P group removal")
98 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
100 def test_concurrent_grpform_while_connecting(dev, apdev):
101 """Concurrent P2P group formation while connecting to an AP"""
102 logger.info("Start connection to an infrastructure AP")
103 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
104 dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
106 logger.info("Form a P2P group while connecting to an AP")
107 dev[0].request("SET p2p_no_group_iface 0")
109 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_freq=2412,
110 r_dev=dev[1], r_freq=2412)
111 check_grpform_results(i_res, r_res)
112 remove_group(dev[0], dev[1])
114 logger.info("Confirm AP connection after P2P group removal")
115 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
117 def test_concurrent_grpform_while_connecting2(dev, apdev):
118 """Concurrent P2P group formation while connecting to an AP (2)"""
119 logger.info("Start connection to an infrastructure AP")
120 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
121 dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
123 logger.info("Form a P2P group while connecting to an AP")
124 dev[0].request("SET p2p_no_group_iface 0")
126 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, i_freq=2412,
127 r_dev=dev[1], r_intent=0, r_freq=2412)
128 check_grpform_results(i_res, r_res)
129 remove_group(dev[0], dev[1])
131 logger.info("Confirm AP connection after P2P group removal")
132 dev[0].wait_completed()
133 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
135 def test_concurrent_grpform_while_connecting3(dev, apdev):
136 """Concurrent P2P group formation while connecting to an AP (3)"""
137 logger.info("Start connection to an infrastructure AP")
138 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
139 dev[0].connect("test-open", key_mgmt="NONE", wait_connect=False)
141 logger.info("Form a P2P group while connecting to an AP")
142 dev[0].request("SET p2p_no_group_iface 0")
144 [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=15, i_freq=2412,
145 r_dev=dev[0], r_intent=0, r_freq=2412)
146 check_grpform_results(i_res, r_res)
147 remove_group(dev[0], dev[1])
149 logger.info("Confirm AP connection after P2P group removal")
150 dev[0].wait_completed()
151 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
153 def test_concurrent_persistent_group(dev, apdev):
154 """Concurrent P2P persistent group"""
155 logger.info("Connect to an infrastructure AP")
156 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open", "channel": "2" })
157 dev[0].request("SET p2p_no_group_iface 0")
158 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
160 logger.info("Run persistent group test while associated to an AP")
162 [go_res, cli_res] = invite_from_cli(dev[0], dev[1])
163 if go_res['freq'] != '2417':
164 raise Exception("Unexpected channel selected: " + go_res['freq'])
165 [go_res, cli_res] = invite_from_go(dev[0], dev[1])
166 if go_res['freq'] != '2417':
167 raise Exception("Unexpected channel selected: " + go_res['freq'])
169 def test_concurrent_invitation_channel_mismatch(dev, apdev):
170 """P2P persistent group invitation and channel mismatch"""
172 dev[0].dump_monitor()
173 dev[1].dump_monitor()
175 logger.info("Connect to an infrastructure AP")
176 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open", "channel": "2" })
177 dev[0].request("SET p2p_no_group_iface 0")
178 dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2417")
179 invite(dev[1], dev[0], extra="freq=2412")
180 ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
182 raise Exception("P2P invitation result not received")
183 if "status=7" not in ev:
184 raise Exception("Unexpected P2P invitation result: " + ev)