]>
Commit | Line | Data |
---|---|---|
a311c61d | 1 | # P2P group formation test cases |
0c35b91c | 2 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
a311c61d JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import logging | |
c9aa4308 | 8 | logger = logging.getLogger() |
c4fff52c JM |
9 | import time |
10 | import threading | |
11 | import Queue | |
3051c986 | 12 | import os |
a311c61d | 13 | |
095ded5d | 14 | import hostapd |
a311c61d | 15 | import hwsim_utils |
19ae1d07 | 16 | import utils |
a311c61d | 17 | |
1a4d80b8 JM |
18 | def check_grpform_results(i_res, r_res): |
19 | if i_res['result'] != 'success' or r_res['result'] != 'success': | |
20 | raise Exception("Failed group formation") | |
21 | if i_res['ssid'] != r_res['ssid']: | |
22 | raise Exception("SSID mismatch") | |
23 | if i_res['freq'] != r_res['freq']: | |
46f2cfce JM |
24 | raise Exception("freq mismatch") |
25 | if 'go_neg_freq' in r_res and i_res['go_neg_freq'] != r_res['go_neg_freq']: | |
26 | raise Exception("go_neg_freq mismatch") | |
27 | if i_res['freq'] != i_res['go_neg_freq']: | |
28 | raise Exception("freq/go_neg_freq mismatch") | |
29 | if i_res['role'] != i_res['go_neg_role']: | |
30 | raise Exception("role/go_neg_role mismatch") | |
31 | if 'go_neg_role' in r_res and r_res['role'] != r_res['go_neg_role']: | |
32 | raise Exception("role/go_neg_role mismatch") | |
1a4d80b8 JM |
33 | if i_res['go_dev_addr'] != r_res['go_dev_addr']: |
34 | raise Exception("GO Device Address mismatch") | |
35 | ||
c4fff52c JM |
36 | def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res): |
37 | logger.debug("Initiate GO Negotiation from i_dev") | |
0c35b91c JM |
38 | try: |
39 | i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent) | |
40 | logger.debug("i_res: " + str(i_res)) | |
41 | except Exception, e: | |
42 | i_res = None | |
43 | logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e)) | |
c4fff52c JM |
44 | res.put(i_res) |
45 | ||
46 | def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'): | |
47 | r_dev.p2p_listen() | |
48 | i_dev.p2p_listen() | |
49 | pin = r_dev.wps_read_pin() | |
50 | logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) | |
51 | r_dev.dump_monitor() | |
52 | res = Queue.Queue() | |
53 | t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res)) | |
54 | t.start() | |
55 | logger.debug("Wait for GO Negotiation Request on r_dev") | |
0fa28afe | 56 | ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) |
c4fff52c JM |
57 | if ev is None: |
58 | raise Exception("GO Negotiation timed out") | |
59 | r_dev.dump_monitor() | |
60 | logger.debug("Re-initiate GO Negotiation from r_dev") | |
b1ce1ec0 | 61 | r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20) |
c4fff52c JM |
62 | logger.debug("r_res: " + str(r_res)) |
63 | r_dev.dump_monitor() | |
64 | t.join() | |
65 | i_res = res.get() | |
0c35b91c JM |
66 | if i_res is None: |
67 | raise Exception("go_neg_init thread failed") | |
c4fff52c JM |
68 | logger.debug("i_res: " + str(i_res)) |
69 | logger.info("Group formed") | |
70 | hwsim_utils.test_connectivity_p2p(r_dev, i_dev) | |
71 | i_dev.dump_monitor() | |
19ae1d07 | 72 | return [i_res, r_res] |
c4fff52c | 73 | |
46f2cfce | 74 | def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display', test_data=True, i_freq=None, r_freq=None): |
a311c61d JM |
75 | i_dev.p2p_listen() |
76 | pin = r_dev.wps_read_pin() | |
77 | logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) | |
46f2cfce | 78 | r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq) |
e59aa782 | 79 | r_dev.p2p_listen() |
46f2cfce | 80 | i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, expect_failure=expect_failure, freq=i_freq) |
809079d3 | 81 | r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure) |
c68f9a61 JM |
82 | logger.debug("i_res: " + str(i_res)) |
83 | logger.debug("r_res: " + str(r_res)) | |
a311c61d JM |
84 | r_dev.dump_monitor() |
85 | i_dev.dump_monitor() | |
f7b1a750 JM |
86 | if i_go_neg_status: |
87 | if i_res['result'] != 'go-neg-failed': | |
88 | raise Exception("Expected GO Negotiation failure not reported") | |
89 | if i_res['status'] != i_go_neg_status: | |
90 | raise Exception("Expected GO Negotiation status not seen") | |
809079d3 JM |
91 | if expect_failure: |
92 | return | |
a311c61d | 93 | logger.info("Group formed") |
46f2cfce JM |
94 | if test_data: |
95 | hwsim_utils.test_connectivity_p2p(r_dev, i_dev) | |
b162675f | 96 | return [i_res, r_res] |
a311c61d | 97 | |
08e4bd87 | 98 | def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc): |
1a4d80b8 | 99 | logger.debug("Initiate GO Negotiation from i_dev") |
0c35b91c JM |
100 | try: |
101 | i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", | |
08e4bd87 JM |
102 | timeout=20, go_intent=i_intent, freq=freq, |
103 | provdisc=provdisc) | |
0c35b91c JM |
104 | logger.debug("i_res: " + str(i_res)) |
105 | except Exception, e: | |
106 | i_res = None | |
107 | logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e)) | |
1a4d80b8 JM |
108 | res.put(i_res) |
109 | ||
08e4bd87 JM |
110 | def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None, provdisc=False, r_listen=False): |
111 | if r_listen: | |
112 | r_dev.p2p_listen() | |
113 | else: | |
114 | r_dev.p2p_find(social=True) | |
4441b9d5 | 115 | i_dev.p2p_find(social=True) |
1a4d80b8 JM |
116 | logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) |
117 | r_dev.dump_monitor() | |
118 | res = Queue.Queue() | |
08e4bd87 | 119 | t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc)) |
1a4d80b8 JM |
120 | t.start() |
121 | logger.debug("Wait for GO Negotiation Request on r_dev") | |
0fa28afe | 122 | ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) |
1a4d80b8 JM |
123 | if ev is None: |
124 | raise Exception("GO Negotiation timed out") | |
125 | r_dev.dump_monitor() | |
fbb79f94 JM |
126 | # Allow some time for the GO Neg Resp to go out before initializing new |
127 | # GO Negotiation. | |
128 | time.sleep(0.2) | |
1a4d80b8 | 129 | logger.debug("Re-initiate GO Negotiation from r_dev") |
41af1305 JM |
130 | r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", |
131 | go_intent=r_intent, timeout=20, freq=r_freq) | |
1a4d80b8 JM |
132 | logger.debug("r_res: " + str(r_res)) |
133 | r_dev.dump_monitor() | |
134 | t.join() | |
135 | i_res = res.get() | |
0c35b91c JM |
136 | if i_res is None: |
137 | raise Exception("go_neg_init_pbc thread failed") | |
1a4d80b8 JM |
138 | logger.debug("i_res: " + str(i_res)) |
139 | logger.info("Group formed") | |
140 | hwsim_utils.test_connectivity_p2p(r_dev, i_dev) | |
141 | i_dev.dump_monitor() | |
142 | return [i_res, r_res] | |
143 | ||
46f2cfce JM |
144 | def remove_group(dev1, dev2): |
145 | dev1.remove_group() | |
a311c61d | 146 | try: |
46f2cfce | 147 | dev2.remove_group() |
a311c61d JM |
148 | except: |
149 | pass | |
150 | ||
46f2cfce JM |
151 | def test_grpform(dev): |
152 | """P2P group formation using PIN and authorized connection (init -> GO)""" | |
28cd9009 JM |
153 | try: |
154 | dev[0].request("SET p2p_group_idle 2") | |
155 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
156 | r_dev=dev[1], r_intent=0) | |
157 | check_grpform_results(i_res, r_res) | |
158 | dev[1].remove_group() | |
159 | ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10) | |
160 | if ev is None: | |
161 | raise Exception("GO did not remove group on idle timeout") | |
162 | if "GO reason=IDLE" not in ev: | |
163 | raise Exception("Unexpected group removal event: " + ev) | |
164 | finally: | |
165 | dev[0].request("SET p2p_group_idle 0") | |
46f2cfce | 166 | |
19ae1d07 JM |
167 | def test_grpform_a(dev): |
168 | """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)""" | |
169 | dev[0].request("SET p2p_no_group_iface 0") | |
170 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
171 | r_dev=dev[1], r_intent=0) | |
172 | if "p2p-wlan" not in i_res['ifname']: | |
173 | raise Exception("Unexpected group interface name") | |
174 | check_grpform_results(i_res, r_res) | |
175 | remove_group(dev[0], dev[1]) | |
176 | if i_res['ifname'] in utils.get_ifnames(): | |
177 | raise Exception("Group interface netdev was not removed") | |
178 | ||
179 | def test_grpform_b(dev): | |
180 | """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)""" | |
181 | dev[1].request("SET p2p_no_group_iface 0") | |
182 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
183 | r_dev=dev[1], r_intent=0) | |
184 | if "p2p-wlan" not in r_res['ifname']: | |
185 | raise Exception("Unexpected group interface name") | |
186 | check_grpform_results(i_res, r_res) | |
187 | remove_group(dev[0], dev[1]) | |
188 | if r_res['ifname'] in utils.get_ifnames(): | |
189 | raise Exception("Group interface netdev was not removed") | |
190 | ||
191 | def test_grpform_c(dev): | |
192 | """P2P group formation using PIN and authorized connection (init -> GO) (group iface)""" | |
193 | dev[0].request("SET p2p_no_group_iface 0") | |
194 | dev[1].request("SET p2p_no_group_iface 0") | |
195 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
196 | r_dev=dev[1], r_intent=0) | |
197 | if "p2p-wlan" not in i_res['ifname']: | |
198 | raise Exception("Unexpected group interface name") | |
199 | if "p2p-wlan" not in r_res['ifname']: | |
200 | raise Exception("Unexpected group interface name") | |
201 | check_grpform_results(i_res, r_res) | |
202 | remove_group(dev[0], dev[1]) | |
203 | if i_res['ifname'] in utils.get_ifnames(): | |
204 | raise Exception("Group interface netdev was not removed") | |
205 | if r_res['ifname'] in utils.get_ifnames(): | |
206 | raise Exception("Group interface netdev was not removed") | |
207 | ||
a311c61d | 208 | def test_grpform2(dev): |
47c34473 | 209 | """P2P group formation using PIN and authorized connection (resp -> GO)""" |
a311c61d | 210 | go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15) |
46f2cfce | 211 | remove_group(dev[0], dev[1]) |
a311c61d | 212 | |
19ae1d07 JM |
213 | def test_grpform2_c(dev): |
214 | """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)""" | |
215 | dev[0].request("SET p2p_no_group_iface 0") | |
216 | dev[1].request("SET p2p_no_group_iface 0") | |
217 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15) | |
218 | remove_group(dev[0], dev[1]) | |
219 | if i_res['ifname'] in utils.get_ifnames(): | |
220 | raise Exception("Group interface netdev was not removed") | |
221 | if r_res['ifname'] in utils.get_ifnames(): | |
222 | raise Exception("Group interface netdev was not removed") | |
223 | ||
c4fff52c | 224 | def test_grpform3(dev): |
47c34473 | 225 | """P2P group formation using PIN and re-init GO Negotiation""" |
c4fff52c | 226 | go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) |
46f2cfce | 227 | remove_group(dev[0], dev[1]) |
c4fff52c | 228 | |
19ae1d07 JM |
229 | def test_grpform3_c(dev): |
230 | """P2P group formation using PIN and re-init GO Negotiation (group iface)""" | |
231 | dev[0].request("SET p2p_no_group_iface 0") | |
232 | dev[1].request("SET p2p_no_group_iface 0") | |
233 | [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) | |
234 | remove_group(dev[0], dev[1]) | |
235 | if i_res['ifname'] in utils.get_ifnames(): | |
236 | raise Exception("Group interface netdev was not removed") | |
237 | if r_res['ifname'] in utils.get_ifnames(): | |
238 | raise Exception("Group interface netdev was not removed") | |
239 | ||
1a4d80b8 | 240 | def test_grpform_pbc(dev): |
47c34473 | 241 | """P2P group formation using PBC and re-init GO Negotiation""" |
1a4d80b8 JM |
242 | [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) |
243 | check_grpform_results(i_res, r_res) | |
244 | if i_res['role'] != 'GO' or r_res['role'] != 'client': | |
245 | raise Exception("Unexpected device roles") | |
46f2cfce | 246 | remove_group(dev[0], dev[1]) |
1a4d80b8 | 247 | |
08e4bd87 JM |
248 | def test_grpform_pd(dev): |
249 | """P2P group formation with PD-before-GO-Neg workaround""" | |
250 | [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True) | |
251 | check_grpform_results(i_res, r_res) | |
252 | remove_group(dev[0], dev[1]) | |
253 | ||
7e6ca8a5 JM |
254 | def test_grpform_ext_listen(dev): |
255 | """P2P group formation with extended listen timing enabled""" | |
256 | try: | |
73875325 JM |
257 | if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"): |
258 | raise Exception("Invalid P2P_EXT_LISTEN accepted") | |
7e6ca8a5 JM |
259 | if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 100 50000"): |
260 | raise Exception("Failed to set extended listen timing") | |
261 | if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"): | |
262 | raise Exception("Failed to set extended listen timing") | |
263 | [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True) | |
264 | check_grpform_results(i_res, r_res) | |
265 | peer1 = dev[0].get_peer(dev[1].p2p_dev_addr()) | |
266 | if peer1['ext_listen_interval'] != "40000": | |
267 | raise Exception("Extended listen interval not discovered correctly") | |
268 | if peer1['ext_listen_period'] != "200": | |
269 | raise Exception("Extended listen period not discovered correctly") | |
270 | peer0 = dev[1].get_peer(dev[0].p2p_dev_addr()) | |
271 | if peer0['ext_listen_interval'] != "50000": | |
272 | raise Exception("Extended listen interval not discovered correctly") | |
273 | if peer0['ext_listen_period'] != "100": | |
274 | raise Exception("Extended listen period not discovered correctly") | |
275 | remove_group(dev[0], dev[1]) | |
276 | finally: | |
277 | if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"): | |
278 | raise Exception("Failed to clear extended listen timing") | |
279 | if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"): | |
280 | raise Exception("Failed to clear extended listen timing") | |
281 | ||
809079d3 | 282 | def test_both_go_intent_15(dev): |
47c34473 | 283 | """P2P GO Negotiation with both devices using GO intent 15""" |
f7b1a750 | 284 | go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True, i_go_neg_status=9) |
809079d3 | 285 | |
caf518a7 | 286 | def test_both_go_neg_display(dev): |
47c34473 | 287 | """P2P GO Negotiation with both devices trying to display PIN""" |
caf518a7 JM |
288 | go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='display', r_method='display') |
289 | ||
290 | def test_both_go_neg_enter(dev): | |
47c34473 | 291 | """P2P GO Negotiation with both devices trying to enter PIN""" |
caf518a7 | 292 | 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') |
b162675f | 293 | |
0e674824 JM |
294 | def test_go_neg_pbc_vs_pin(dev): |
295 | """P2P GO Negotiation with one device using PBC and the other PIN""" | |
296 | addr0 = dev[0].p2p_dev_addr() | |
297 | addr1 = dev[1].p2p_dev_addr() | |
298 | dev[1].p2p_listen() | |
299 | if not dev[0].discover_peer(addr1): | |
300 | raise Exception("Could not discover peer") | |
301 | dev[0].p2p_listen() | |
302 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"): | |
303 | raise Exception("Failed to authorize GO Neg") | |
304 | if not dev[1].discover_peer(addr0): | |
305 | raise Exception("Could not discover peer") | |
306 | if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"): | |
307 | raise Exception("Failed to initiate GO Neg") | |
308 | ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10) | |
309 | if ev is None: | |
310 | raise Exception("GO Negotiation failure timed out") | |
311 | if "status=10" not in ev: | |
312 | raise Exception("Unexpected failure reason: " + ev) | |
313 | ||
314 | def test_go_neg_pin_vs_pbc(dev): | |
315 | """P2P GO Negotiation with one device using PIN and the other PBC""" | |
316 | addr0 = dev[0].p2p_dev_addr() | |
317 | addr1 = dev[1].p2p_dev_addr() | |
318 | dev[1].p2p_listen() | |
319 | if not dev[0].discover_peer(addr1): | |
320 | raise Exception("Could not discover peer") | |
321 | dev[0].p2p_listen() | |
322 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"): | |
323 | raise Exception("Failed to authorize GO Neg") | |
324 | if not dev[1].discover_peer(addr0): | |
325 | raise Exception("Could not discover peer") | |
326 | if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"): | |
327 | raise Exception("Failed to initiate GO Neg") | |
328 | ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10) | |
329 | if ev is None: | |
330 | raise Exception("GO Negotiation failure timed out") | |
331 | if "status=10" not in ev: | |
332 | raise Exception("Unexpected failure reason: " + ev) | |
333 | ||
b162675f JM |
334 | def test_grpform_per_sta_psk(dev): |
335 | """P2P group formation with per-STA PSKs""" | |
336 | dev[0].request("P2P_SET per_sta_psk 1") | |
337 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) | |
338 | check_grpform_results(i_res, r_res) | |
339 | ||
340 | pin = dev[2].wps_read_pin() | |
341 | dev[0].p2p_go_authorize_client(pin) | |
342 | c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) | |
343 | check_grpform_results(i_res, c_res) | |
344 | ||
345 | if r_res['psk'] == c_res['psk']: | |
346 | raise Exception("Same PSK assigned for both clients") | |
347 | ||
348 | hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) | |
349 | ||
350 | dev[0].remove_group() | |
2c914e24 JM |
351 | dev[1].wait_go_ending_session() |
352 | dev[2].wait_go_ending_session() | |
b162675f JM |
353 | |
354 | def test_grpform_per_sta_psk_wps(dev): | |
355 | """P2P group formation with per-STA PSKs with non-P2P WPS STA""" | |
356 | dev[0].request("P2P_SET per_sta_psk 1") | |
357 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0) | |
358 | check_grpform_results(i_res, r_res) | |
359 | ||
360 | dev[0].p2p_go_authorize_client_pbc() | |
361 | dev[2].request("WPS_PBC") | |
5f35a5e2 | 362 | dev[2].wait_connected(timeout=30) |
b162675f JM |
363 | |
364 | hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2]) | |
365 | ||
366 | dev[0].remove_group() | |
367 | dev[2].request("DISCONNECT") | |
2c914e24 | 368 | dev[1].wait_go_ending_session() |
46f2cfce JM |
369 | |
370 | def test_grpform_force_chan_go(dev): | |
371 | """P2P group formation forced channel selection by GO""" | |
372 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
373 | i_freq=2432, | |
374 | r_dev=dev[1], r_intent=0, | |
375 | test_data=False) | |
376 | check_grpform_results(i_res, r_res) | |
377 | if i_res['freq'] != "2432": | |
378 | raise Exception("Unexpected channel - did not follow GO's forced channel") | |
379 | remove_group(dev[0], dev[1]) | |
380 | ||
381 | def test_grpform_force_chan_cli(dev): | |
382 | """P2P group formation forced channel selection by client""" | |
383 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
384 | i_freq=2417, | |
385 | r_dev=dev[1], r_intent=15, | |
386 | test_data=False) | |
387 | check_grpform_results(i_res, r_res) | |
388 | if i_res['freq'] != "2417": | |
389 | raise Exception("Unexpected channel - did not follow GO's forced channel") | |
390 | remove_group(dev[0], dev[1]) | |
391 | ||
392 | def test_grpform_force_chan_conflict(dev): | |
393 | """P2P group formation fails due to forced channel mismatch""" | |
394 | go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422, | |
395 | r_dev=dev[1], r_intent=15, r_freq=2427, | |
396 | expect_failure=True, i_go_neg_status=7) | |
397 | ||
398 | def test_grpform_pref_chan_go(dev): | |
399 | """P2P group formation preferred channel selection by GO""" | |
400 | dev[0].request("SET p2p_pref_chan 81:7") | |
401 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
402 | r_dev=dev[1], r_intent=0, | |
403 | test_data=False) | |
404 | check_grpform_results(i_res, r_res) | |
405 | if i_res['freq'] != "2442": | |
406 | raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan") | |
407 | remove_group(dev[0], dev[1]) | |
408 | ||
409 | def test_grpform_pref_chan_go_overridden(dev): | |
410 | """P2P group formation preferred channel selection by GO overridden by client""" | |
411 | dev[1].request("SET p2p_pref_chan 81:7") | |
412 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
413 | i_freq=2422, | |
414 | r_dev=dev[1], r_intent=15, | |
415 | test_data=False) | |
416 | check_grpform_results(i_res, r_res) | |
417 | if i_res['freq'] != "2422": | |
418 | raise Exception("Unexpected channel - did not follow client's forced channel") | |
419 | remove_group(dev[0], dev[1]) | |
420 | ||
421 | def test_grpform_no_go_freq_forcing_chan(dev): | |
422 | """P2P group formation with no-GO freq forcing channel""" | |
423 | dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000") | |
424 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
425 | r_dev=dev[1], r_intent=15, | |
426 | test_data=False) | |
427 | check_grpform_results(i_res, r_res) | |
428 | if int(i_res['freq']) > 4000: | |
429 | raise Exception("Unexpected channel - did not follow no-GO freq") | |
430 | remove_group(dev[0], dev[1]) | |
431 | ||
432 | def test_grpform_no_go_freq_conflict(dev): | |
433 | """P2P group formation fails due to no-GO range forced by client""" | |
434 | dev[1].request("SET p2p_no_go_freq 2000-3000") | |
435 | go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422, | |
436 | r_dev=dev[1], r_intent=15, | |
437 | expect_failure=True, i_go_neg_status=7) | |
799716a8 JM |
438 | |
439 | def test_grpform_no_5ghz_world_roaming(dev): | |
440 | """P2P group formation with world roaming regulatory""" | |
441 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
442 | r_dev=dev[1], r_intent=15, | |
443 | test_data=False) | |
444 | check_grpform_results(i_res, r_res) | |
445 | if int(i_res['freq']) > 4000: | |
446 | raise Exception("Unexpected channel - did not follow world roaming rules") | |
447 | remove_group(dev[0], dev[1]) | |
448 | ||
449 | def test_grpform_no_5ghz_add_cli(dev): | |
450 | """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1""" | |
451 | dev[0].request("SET p2p_add_cli_chan 1") | |
452 | dev[1].request("SET p2p_add_cli_chan 1") | |
453 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
454 | r_dev=dev[1], r_intent=14, | |
455 | test_data=False) | |
456 | check_grpform_results(i_res, r_res) | |
457 | if int(i_res['freq']) > 4000: | |
458 | raise Exception("Unexpected channel - did not follow world roaming rules") | |
459 | remove_group(dev[0], dev[1]) | |
460 | ||
461 | def test_grpform_no_5ghz_add_cli2(dev): | |
462 | """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)""" | |
463 | dev[0].request("SET p2p_add_cli_chan 1") | |
464 | dev[1].request("SET p2p_add_cli_chan 1") | |
465 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14, | |
466 | r_dev=dev[1], r_intent=0, | |
467 | test_data=False) | |
468 | check_grpform_results(i_res, r_res) | |
469 | if int(i_res['freq']) > 4000: | |
470 | raise Exception("Unexpected channel - did not follow world roaming rules") | |
471 | remove_group(dev[0], dev[1]) | |
472 | ||
473 | def test_grpform_no_5ghz_add_cli3(dev): | |
474 | """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)""" | |
475 | dev[0].request("SET p2p_add_cli_chan 1") | |
476 | dev[1].request("SET p2p_add_cli_chan 1") | |
477 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, | |
478 | r_dev=dev[1], r_intent=15, | |
479 | test_data=False) | |
480 | check_grpform_results(i_res, r_res) | |
481 | if int(i_res['freq']) > 4000: | |
482 | raise Exception("Unexpected channel - did not follow world roaming rules") | |
483 | remove_group(dev[0], dev[1]) | |
484 | ||
485 | def test_grpform_no_5ghz_add_cli4(dev): | |
486 | """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)""" | |
487 | dev[0].request("SET p2p_add_cli_chan 1") | |
488 | dev[1].request("SET p2p_add_cli_chan 1") | |
489 | [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, | |
490 | r_dev=dev[1], r_intent=0, | |
491 | test_data=False) | |
492 | check_grpform_results(i_res, r_res) | |
493 | if int(i_res['freq']) > 4000: | |
494 | raise Exception("Unexpected channel - did not follow world roaming rules") | |
495 | remove_group(dev[0], dev[1]) | |
2db832b1 JM |
496 | |
497 | def test_grpform_incorrect_pin(dev): | |
498 | """P2P GO Negotiation with incorrect PIN""" | |
499 | dev[1].p2p_listen() | |
2db832b1 JM |
500 | addr1 = dev[1].p2p_dev_addr() |
501 | if not dev[0].discover_peer(addr1): | |
502 | raise Exception("Peer not found") | |
450e584f JM |
503 | res = dev[1].request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0") |
504 | if "FAIL" in res: | |
505 | raise Exception("P2P_CONNECT failed to generate PIN") | |
506 | logger.info("PIN from P2P_CONNECT: " + res) | |
2db832b1 | 507 | dev[0].request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15") |
450e584f JM |
508 | ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15) |
509 | if ev is None: | |
510 | raise Exception("GO Negotiation did not complete successfully(0)") | |
511 | ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15) | |
512 | if ev is None: | |
513 | raise Exception("GO Negotiation did not complete successfully(1)") | |
514 | ev = dev[1].wait_event(["WPS-FAIL"], timeout=15) | |
515 | if ev is None: | |
516 | raise Exception("WPS failure not reported(1)") | |
517 | if "msg=8 config_error=18" not in ev: | |
518 | raise Exception("Unexpected WPS failure(1): " + ev) | |
519 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
520 | if ev is None: | |
521 | raise Exception("WPS failure not reported") | |
522 | if "msg=8 config_error=18" not in ev: | |
523 | raise Exception("Unexpected WPS failure: " + ev) | |
2db832b1 JM |
524 | ev = dev[1].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10) |
525 | if ev is None: | |
526 | raise Exception("Group formation failure timed out") | |
527 | ev = dev[0].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5) | |
528 | if ev is None: | |
529 | raise Exception("Group formation failure timed out") | |
a06b1070 JM |
530 | |
531 | def test_grpform_reject(dev): | |
532 | """User rejecting group formation attempt by a P2P peer""" | |
533 | addr0 = dev[0].p2p_dev_addr() | |
534 | dev[0].p2p_listen() | |
535 | dev[1].p2p_go_neg_init(addr0, None, "pbc") | |
536 | ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) | |
537 | if ev is None: | |
538 | raise Exception("GO Negotiation timed out") | |
edd1dfb2 JM |
539 | if "OK" in dev[0].global_request("P2P_REJECT foo"): |
540 | raise Exception("Invalid P2P_REJECT accepted") | |
a06b1070 JM |
541 | if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]): |
542 | raise Exception("P2P_REJECT failed") | |
543 | dev[1].request("P2P_STOP_FIND") | |
544 | dev[1].p2p_go_neg_init(addr0, None, "pbc") | |
545 | ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10) | |
546 | if ev is None: | |
547 | raise Exception("Rejection not reported") | |
548 | if "status=11" not in ev: | |
549 | raise Exception("Unexpected status code in rejection") | |
99fa65bc JM |
550 | |
551 | def test_grpform_pd_no_probe_resp(dev): | |
552 | """GO Negotiation after PD, but no Probe Response""" | |
553 | addr0 = dev[0].p2p_dev_addr() | |
554 | addr1 = dev[1].p2p_dev_addr() | |
555 | dev[0].p2p_listen() | |
556 | if not dev[1].discover_peer(addr0): | |
557 | raise Exception("Peer not found") | |
558 | dev[1].p2p_stop_find() | |
559 | dev[0].p2p_stop_find() | |
560 | peer = dev[0].get_peer(addr1) | |
561 | if peer['listen_freq'] == '0': | |
562 | raise Exception("Peer listen frequency not learned from Probe Request") | |
563 | time.sleep(0.3) | |
564 | dev[0].request("P2P_FLUSH") | |
565 | dev[0].p2p_listen() | |
566 | dev[1].global_request("P2P_PROV_DISC " + addr0 + " display") | |
567 | ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5) | |
568 | if ev is None: | |
569 | raise Exception("PD Request timed out") | |
570 | ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5) | |
571 | if ev is None: | |
572 | raise Exception("PD Response timed out") | |
573 | peer = dev[0].get_peer(addr1) | |
574 | if peer['listen_freq'] != '0': | |
575 | raise Exception("Peer listen frequency learned unexpectedly from PD Request") | |
576 | ||
577 | pin = dev[0].wps_read_pin() | |
578 | if "FAIL" in dev[1].request("P2P_CONNECT " + addr0 + " " + pin + " enter"): | |
579 | raise Exception("P2P_CONNECT on initiator failed") | |
580 | ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5) | |
581 | if ev is None: | |
582 | raise Exception("GO Negotiation start timed out") | |
583 | peer = dev[0].get_peer(addr1) | |
584 | if peer['listen_freq'] == '0': | |
585 | raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req") | |
586 | if "FAIL" in dev[0].request("P2P_CONNECT " + addr1 + " " + pin + " display"): | |
587 | raise Exception("P2P_CONNECT on responder failed") | |
588 | ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
589 | if ev is None: | |
590 | raise Exception("Group formation timed out") | |
591 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
592 | if ev is None: | |
593 | raise Exception("Group formation timed out") | |
b89c43d3 JM |
594 | |
595 | def test_go_neg_two_peers(dev): | |
596 | """P2P GO Negotiation rejected due to already started negotiation with another peer""" | |
597 | addr0 = dev[0].p2p_dev_addr() | |
598 | addr1 = dev[1].p2p_dev_addr() | |
599 | addr2 = dev[2].p2p_dev_addr() | |
600 | dev[1].p2p_listen() | |
601 | dev[2].p2p_listen() | |
602 | if not dev[0].discover_peer(addr1): | |
603 | raise Exception("Could not discover peer") | |
604 | if not dev[0].discover_peer(addr2): | |
605 | raise Exception("Could not discover peer") | |
606 | if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"): | |
607 | raise Exception("Failed to authorize GO Neg") | |
608 | dev[0].p2p_listen() | |
609 | if not dev[2].discover_peer(addr0): | |
610 | raise Exception("Could not discover peer") | |
611 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"): | |
612 | raise Exception("Failed to initiate GO Neg") | |
613 | ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5) | |
614 | if ev is None: | |
615 | raise Exception("timeout on GO Neg RX event") | |
616 | dev[2].request("P2P_CONNECT " + addr0 + " pbc") | |
617 | ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10) | |
618 | if ev is None: | |
619 | raise Exception("Rejection not reported") | |
620 | if "status=5" not in ev: | |
621 | raise Exception("Unexpected status code in rejection: " + ev) | |
095ded5d | 622 | |
b2036fed JM |
623 | def clear_pbc_overlap(dev, ifname): |
624 | hapd_global = hostapd.HostapdGlobal() | |
625 | hapd_global.remove(ifname) | |
243dcc4a JM |
626 | dev[0].request("P2P_CANCEL") |
627 | dev[1].request("P2P_CANCEL") | |
b2036fed JM |
628 | dev[0].p2p_stop_find() |
629 | dev[1].p2p_stop_find() | |
630 | dev[0].dump_monitor() | |
631 | dev[1].dump_monitor() | |
632 | time.sleep(0.1) | |
243dcc4a JM |
633 | dev[0].flush_scan_cache() |
634 | dev[1].flush_scan_cache() | |
635 | time.sleep(0.1) | |
b2036fed | 636 | |
095ded5d JM |
637 | def test_grpform_pbc_overlap(dev, apdev): |
638 | """P2P group formation during PBC overlap""" | |
639 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" } | |
640 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
641 | hapd.request("WPS_PBC") | |
642 | time.sleep(0.1) | |
643 | ||
16dffef1 JM |
644 | # Since P2P Client scan case is now optimzied to use a specific SSID, the |
645 | # WPS AP will not reply to that and the scan after GO Negotiation can quite | |
646 | # likely miss the AP due to dwell time being short enoguh to miss the Beacon | |
647 | # frame. This has made the test case somewhat pointless, but keep it here | |
648 | # for now with an additional scan to confirm that PBC detection works if | |
649 | # there is a BSS entry for a overlapping AP. | |
650 | for i in range(0, 5): | |
651 | dev[0].scan(freq="2412") | |
652 | if dev[0].get_bss(apdev[0]['bssid']) is not None: | |
653 | break | |
654 | ||
095ded5d JM |
655 | addr0 = dev[0].p2p_dev_addr() |
656 | addr1 = dev[1].p2p_dev_addr() | |
657 | dev[0].p2p_listen() | |
658 | if not dev[1].discover_peer(addr0): | |
659 | raise Exception("Could not discover peer") | |
660 | dev[1].p2p_listen() | |
661 | if not dev[0].discover_peer(addr1): | |
662 | raise Exception("Could not discover peer") | |
663 | dev[0].p2p_listen() | |
664 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"): | |
665 | raise Exception("Failed to authorize GO Neg") | |
666 | if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"): | |
667 | raise Exception("Failed to initiate GO Neg") | |
668 | ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15) | |
669 | if ev is None: | |
670 | raise Exception("PBC overlap not reported") | |
671 | ||
b2036fed JM |
672 | clear_pbc_overlap(dev, apdev[0]['ifname']) |
673 | ||
095ded5d JM |
674 | def test_grpform_pbc_overlap_group_iface(dev, apdev): |
675 | """P2P group formation during PBC overlap using group interfaces""" | |
676 | # Note: Need to include P2P IE from the AP to get the P2P interface BSS | |
677 | # update use this information. | |
678 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "1", | |
d7d78434 | 679 | "beacon_int": "15", 'manage_p2p': '1' } |
095ded5d JM |
680 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
681 | hapd.request("WPS_PBC") | |
682 | ||
683 | dev[0].request("SET p2p_no_group_iface 0") | |
684 | dev[1].request("SET p2p_no_group_iface 0") | |
685 | ||
686 | addr0 = dev[0].p2p_dev_addr() | |
687 | addr1 = dev[1].p2p_dev_addr() | |
688 | dev[0].p2p_listen() | |
689 | if not dev[1].discover_peer(addr0): | |
690 | raise Exception("Could not discover peer") | |
691 | dev[1].p2p_listen() | |
692 | if not dev[0].discover_peer(addr1): | |
693 | raise Exception("Could not discover peer") | |
694 | dev[0].p2p_stop_find() | |
695 | dev[0].scan(freq="2412") | |
696 | dev[0].p2p_listen() | |
697 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"): | |
698 | raise Exception("Failed to authorize GO Neg") | |
699 | if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"): | |
700 | raise Exception("Failed to initiate GO Neg") | |
701 | ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED", | |
702 | "P2P-GROUP-FORMATION-SUCCESS"], timeout=15) | |
703 | if ev is None or "WPS-OVERLAP-DETECTED" not in ev: | |
d7d78434 JM |
704 | # Do not report this as failure since the P2P group formation case |
705 | # using a separate group interface has limited chances of "seeing" the | |
706 | # overlapping AP due to a per-SSID scan and no prior scan operations on | |
707 | # the group interface. | |
708 | logger.info("PBC overlap not reported") | |
b2036fed JM |
709 | |
710 | clear_pbc_overlap(dev, apdev[0]['ifname']) | |
80abf062 JM |
711 | |
712 | def test_grpform_goneg_fail_with_group_iface(dev): | |
713 | """P2P group formation fails while using group interface""" | |
714 | dev[0].request("SET p2p_no_group_iface 0") | |
715 | dev[1].p2p_listen() | |
716 | peer = dev[1].p2p_dev_addr() | |
717 | if not dev[0].discover_peer(peer): | |
718 | raise Exception("Peer " + peer + " not found") | |
719 | if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()): | |
720 | raise Exception("P2P_REJECT failed") | |
721 | if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"): | |
722 | raise Exception("P2P_CONNECT failed") | |
723 | ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10) | |
724 | if ev is None: | |
725 | raise Exception("GO Negotiation failure timed out") | |
3051c986 JM |
726 | |
727 | def test_grpform_cred_ready_timeout(dev, apdev, params): | |
728 | """P2P GO Negotiation wait for credentials to become ready [long]""" | |
729 | if not params['long']: | |
730 | logger.info("Skip test case with long duration due to --long not specified") | |
731 | return "skip" | |
732 | ||
733 | dev[1].p2p_listen() | |
734 | addr1 = dev[1].p2p_dev_addr() | |
735 | if not dev[0].discover_peer(addr1): | |
736 | raise Exception("Peer " + addr1 + " not found") | |
737 | start = os.times()[4] | |
738 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display"): | |
739 | raise Exception("Failed to initiate GO Neg") | |
740 | ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=200) | |
741 | if ev is None: | |
742 | raise Exception("GO Negotiation failure timed out") | |
743 | end = os.times()[4] | |
744 | logger.info("GO Negotiation wait time: {} seconds".format(end - start)) | |
0ee41e86 JM |
745 | if end - start < 120: |
746 | raise Exception("Too short GO Negotiation wait time: {}".format(end - start)) | |
747 | ||
748 | def test_grpform_cred_ready_timeout2(dev, apdev, params): | |
749 | """P2P GO Negotiation wait for credentials to become ready (2) [long]""" | |
750 | if not params['long']: | |
751 | logger.info("Skip test case with long duration due to --long not specified") | |
752 | return "skip" | |
753 | ||
754 | dev[1].p2p_listen() | |
755 | addr1 = dev[1].p2p_dev_addr() | |
756 | if not dev[0].discover_peer(addr1): | |
757 | raise Exception("Peer " + addr1 + " not found") | |
758 | start = os.times()[4] | |
759 | if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display"): | |
760 | raise Exception("Failed to initiate GO Neg") | |
761 | ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30) | |
762 | if ev is not None: | |
763 | raise Exception("Too early GO Negotiation timeout reported") | |
3e473674 | 764 | dev[0].dump_monitor() |
0ee41e86 JM |
765 | logger.info("Starting p2p_find to change state") |
766 | dev[0].p2p_find() | |
767 | ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100) | |
768 | if ev is None: | |
769 | raise Exception("GO Negotiation failure timed out") | |
3e473674 | 770 | dev[0].dump_monitor() |
0ee41e86 JM |
771 | end = os.times()[4] |
772 | logger.info("GO Negotiation wait time: {} seconds".format(end - start)) | |
3051c986 JM |
773 | if end - start < 120: |
774 | raise Exception("Too short GO Negotiation wait time: {}".format(end - start)) | |
b43ac5d5 | 775 | |
3e473674 JM |
776 | dev[2].p2p_listen() |
777 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10) | |
778 | if ev is None: | |
779 | raise Exception("Did not discovery new device after GO Negotiation failure") | |
780 | if dev[2].p2p_dev_addr() not in ev: | |
781 | raise Exception("Unexpected device found: " + ev) | |
782 | ||
b43ac5d5 JM |
783 | def test_grpform_no_wsc_done(dev): |
784 | """P2P group formation with WSC-Done not sent""" | |
785 | addr0 = dev[0].p2p_dev_addr() | |
786 | addr1 = dev[1].p2p_dev_addr() | |
787 | ||
788 | for i in range(0, 2): | |
789 | dev[0].request("SET ext_eapol_frame_io 1") | |
790 | dev[1].request("SET ext_eapol_frame_io 1") | |
791 | dev[0].p2p_listen() | |
792 | dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0) | |
793 | dev[1].p2p_listen() | |
794 | dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20, | |
795 | go_intent=15, wait_group=False) | |
796 | ||
061c55a2 | 797 | mode = None |
b43ac5d5 JM |
798 | while True: |
799 | ev = dev[0].wait_event(["EAPOL-TX"], timeout=15) | |
800 | if ev is None: | |
801 | raise Exception("Timeout on EAPOL-TX from GO") | |
061c55a2 JM |
802 | if not mode: |
803 | mode = dev[0].get_status_field("mode") | |
b43ac5d5 JM |
804 | res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2]) |
805 | if "OK" not in res: | |
806 | raise Exception("EAPOL_RX failed") | |
807 | ev = dev[1].wait_event(["EAPOL-TX"], timeout=15) | |
808 | if ev is None: | |
809 | raise Exception("Timeout on EAPOL-TX from P2P Client") | |
810 | msg = ev.split(' ')[2] | |
811 | if msg[46:56] == "102200010f": | |
812 | logger.info("Drop WSC_Done") | |
813 | dev[0].request("SET ext_eapol_frame_io 0") | |
814 | dev[1].request("SET ext_eapol_frame_io 0") | |
815 | # Fake EAP-Failure to complete session on the client | |
816 | id = msg[10:12] | |
817 | dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004") | |
818 | break | |
819 | res = dev[0].request("EAPOL_RX " + addr1 + " " + msg) | |
820 | if "OK" not in res: | |
821 | raise Exception("EAPOL_RX failed") | |
822 | ||
823 | ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
824 | if ev is None: | |
825 | raise Exception("Group formation timed out on GO") | |
826 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
827 | if ev is None: | |
828 | raise Exception("Group formation timed out on P2P Client") | |
829 | dev[0].remove_group() | |
42a4ba28 | 830 | |
061c55a2 JM |
831 | if mode != "P2P GO - group formation": |
832 | raise Exception("Unexpected mode on GO during group formation: " + mode) | |
833 | ||
42a4ba28 JM |
834 | def test_grpform_wait_peer(dev): |
835 | """P2P group formation wait for peer to become ready""" | |
836 | addr0 = dev[0].p2p_dev_addr() | |
837 | addr1 = dev[1].p2p_dev_addr() | |
838 | dev[1].p2p_listen() | |
839 | if not dev[0].discover_peer(addr1): | |
840 | raise Exception("Peer " + addr1 + " not found") | |
841 | dev[0].request("SET extra_roc_dur 500") | |
842 | if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"): | |
843 | raise Exception("Failed to initiate GO Neg") | |
844 | time.sleep(3) | |
845 | dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0") | |
846 | ||
847 | ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
848 | if ev is None: | |
849 | raise Exception("Group formation timed out") | |
850 | dev[0].request("SET extra_roc_dur 0") | |
851 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
852 | if ev is None: | |
853 | raise Exception("Group formation timed out") | |
854 | dev[0].remove_group() | |
450e584f JM |
855 | |
856 | def test_invalid_p2p_connect_command(dev): | |
857 | """P2P_CONNECT error cases""" | |
858 | id = dev[0].add_network() | |
859 | for cmd in [ "foo", | |
860 | "00:11:22:33:44:55", | |
861 | "00:11:22:33:44:55 pbc persistent=123", | |
862 | "00:11:22:33:44:55 pbc persistent=%d" % id, | |
863 | "00:11:22:33:44:55 pbc go_intent=-1", | |
864 | "00:11:22:33:44:55 pbc go_intent=16", | |
865 | "00:11:22:33:44:55 pin", | |
866 | "00:11:22:33:44:55 pbc freq=0" ]: | |
867 | if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd): | |
868 | raise Exception("Invalid P2P_CONNECT command accepted: " + cmd) | |
869 | ||
870 | if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"): | |
871 | raise Exception("Invalid PIN was not rejected") | |
872 | ||
873 | if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"): | |
874 | raise Exception("Unsupported channel not reported") | |
1eaeb7fb JM |
875 | |
876 | def test_p2p_unauthorize(dev): | |
877 | """P2P_UNAUTHORIZE to unauthorize a peer""" | |
878 | if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"): | |
879 | raise Exception("Invalid P2P_UNAUTHORIZE accepted") | |
880 | if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"): | |
881 | raise Exception("P2P_UNAUTHORIZE for unknown peer accepted") | |
882 | ||
883 | addr0 = dev[0].p2p_dev_addr() | |
884 | addr1 = dev[1].p2p_dev_addr() | |
885 | dev[1].p2p_listen() | |
886 | pin = dev[0].wps_read_pin() | |
887 | dev[0].p2p_go_neg_auth(addr1, pin, "display") | |
888 | dev[0].p2p_listen() | |
889 | if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1): | |
890 | raise Exception("P2P_UNAUTHORIZE failed") | |
891 | dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0) | |
892 | ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10) | |
893 | if ev is None: | |
894 | raise Exception("No GO Negotiation Request RX reported") |