1 # P2P group formation test cases
2 # Copyright (c) 2013-2014, 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()
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']:
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")
33 if i_res['go_dev_addr'] != r_res['go_dev_addr']:
34 raise Exception("GO Device Address mismatch")
36 def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
37 logger.debug("Initiate GO Negotiation from i_dev")
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))
43 logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e))
46 def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
49 pin = r_dev.wps_read_pin()
50 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
53 t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
55 logger.debug("Wait for GO Negotiation Request on r_dev")
56 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
58 raise Exception("GO Negotiation timed out")
60 logger.debug("Re-initiate GO Negotiation from r_dev")
61 r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
62 logger.debug("r_res: " + str(r_res))
67 raise Exception("go_neg_init thread failed")
68 logger.debug("i_res: " + str(i_res))
69 logger.info("Group formed")
70 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
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):
76 pin = r_dev.wps_read_pin()
77 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
78 r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq)
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)
81 r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
82 logger.debug("i_res: " + str(i_res))
83 logger.debug("r_res: " + str(r_res))
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")
93 logger.info("Group formed")
95 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
98 def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc):
99 logger.debug("Initiate GO Negotiation from i_dev")
101 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc",
102 timeout=20, go_intent=i_intent, freq=freq,
104 logger.debug("i_res: " + str(i_res))
107 logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e))
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):
114 r_dev.p2p_find(social=True)
115 i_dev.p2p_find(social=True)
116 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
119 t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc))
121 logger.debug("Wait for GO Negotiation Request on r_dev")
122 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
124 raise Exception("GO Negotiation timed out")
126 # Allow some time for the GO Neg Resp to go out before initializing new
129 logger.debug("Re-initiate GO Negotiation from r_dev")
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)
132 logger.debug("r_res: " + str(r_res))
137 raise Exception("go_neg_init_pbc thread failed")
138 logger.debug("i_res: " + str(i_res))
139 logger.info("Group formed")
140 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
142 return [i_res, r_res]
144 def remove_group(dev1, dev2):
151 def test_grpform(dev):
152 """P2P group formation using PIN and authorized connection (init -> GO)"""
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)
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)
165 dev[0].request("SET p2p_group_idle 0")
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")
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")
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")
208 def test_grpform2(dev):
209 """P2P group formation using PIN and authorized connection (resp -> GO)"""
210 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
211 remove_group(dev[0], dev[1])
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")
224 def test_grpform3(dev):
225 """P2P group formation using PIN and re-init GO Negotiation"""
226 go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
227 remove_group(dev[0], dev[1])
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")
240 def test_grpform_pbc(dev):
241 """P2P group formation using PBC and re-init GO Negotiation"""
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")
246 remove_group(dev[0], dev[1])
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])
254 def test_grpform_ext_listen(dev):
255 """P2P group formation with extended listen timing enabled"""
257 if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
258 raise Exception("Invalid P2P_EXT_LISTEN accepted")
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])
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")
282 def test_both_go_intent_15(dev):
283 """P2P GO Negotiation with both devices using GO intent 15"""
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)
286 def test_both_go_neg_display(dev):
287 """P2P GO Negotiation with both devices trying to display PIN"""
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')
290 def test_both_go_neg_enter(dev):
291 """P2P GO Negotiation with both devices trying to enter PIN"""
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')
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()
299 if not dev[0].discover_peer(addr1):
300 raise Exception("Could not discover peer")
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)
310 raise Exception("GO Negotiation failure timed out")
311 if "status=10" not in ev:
312 raise Exception("Unexpected failure reason: " + ev)
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()
319 if not dev[0].discover_peer(addr1):
320 raise Exception("Could not discover peer")
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)
330 raise Exception("GO Negotiation failure timed out")
331 if "status=10" not in ev:
332 raise Exception("Unexpected failure reason: " + ev)
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)
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)
345 if r_res['psk'] == c_res['psk']:
346 raise Exception("Same PSK assigned for both clients")
348 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
350 dev[0].remove_group()
351 dev[1].wait_go_ending_session()
352 dev[2].wait_go_ending_session()
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)
360 dev[0].p2p_go_authorize_client_pbc()
361 dev[2].request("WPS_PBC")
362 ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
364 raise Exception("Association with the GO timed out")
366 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
368 dev[0].remove_group()
369 dev[2].request("DISCONNECT")
370 dev[1].wait_go_ending_session()
372 def test_grpform_force_chan_go(dev):
373 """P2P group formation forced channel selection by GO"""
374 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
376 r_dev=dev[1], r_intent=0,
378 check_grpform_results(i_res, r_res)
379 if i_res['freq'] != "2432":
380 raise Exception("Unexpected channel - did not follow GO's forced channel")
381 remove_group(dev[0], dev[1])
383 def test_grpform_force_chan_cli(dev):
384 """P2P group formation forced channel selection by client"""
385 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
387 r_dev=dev[1], r_intent=15,
389 check_grpform_results(i_res, r_res)
390 if i_res['freq'] != "2417":
391 raise Exception("Unexpected channel - did not follow GO's forced channel")
392 remove_group(dev[0], dev[1])
394 def test_grpform_force_chan_conflict(dev):
395 """P2P group formation fails due to forced channel mismatch"""
396 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
397 r_dev=dev[1], r_intent=15, r_freq=2427,
398 expect_failure=True, i_go_neg_status=7)
400 def test_grpform_pref_chan_go(dev):
401 """P2P group formation preferred channel selection by GO"""
402 dev[0].request("SET p2p_pref_chan 81:7")
403 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
404 r_dev=dev[1], r_intent=0,
406 check_grpform_results(i_res, r_res)
407 if i_res['freq'] != "2442":
408 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
409 remove_group(dev[0], dev[1])
411 def test_grpform_pref_chan_go_overridden(dev):
412 """P2P group formation preferred channel selection by GO overridden by client"""
413 dev[1].request("SET p2p_pref_chan 81:7")
414 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
416 r_dev=dev[1], r_intent=15,
418 check_grpform_results(i_res, r_res)
419 if i_res['freq'] != "2422":
420 raise Exception("Unexpected channel - did not follow client's forced channel")
421 remove_group(dev[0], dev[1])
423 def test_grpform_no_go_freq_forcing_chan(dev):
424 """P2P group formation with no-GO freq forcing channel"""
425 dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
426 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
427 r_dev=dev[1], r_intent=15,
429 check_grpform_results(i_res, r_res)
430 if int(i_res['freq']) > 4000:
431 raise Exception("Unexpected channel - did not follow no-GO freq")
432 remove_group(dev[0], dev[1])
434 def test_grpform_no_go_freq_conflict(dev):
435 """P2P group formation fails due to no-GO range forced by client"""
436 dev[1].request("SET p2p_no_go_freq 2000-3000")
437 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
438 r_dev=dev[1], r_intent=15,
439 expect_failure=True, i_go_neg_status=7)
441 def test_grpform_no_5ghz_world_roaming(dev):
442 """P2P group formation with world roaming regulatory"""
443 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
444 r_dev=dev[1], r_intent=15,
446 check_grpform_results(i_res, r_res)
447 if int(i_res['freq']) > 4000:
448 raise Exception("Unexpected channel - did not follow world roaming rules")
449 remove_group(dev[0], dev[1])
451 def test_grpform_no_5ghz_add_cli(dev):
452 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
453 dev[0].request("SET p2p_add_cli_chan 1")
454 dev[1].request("SET p2p_add_cli_chan 1")
455 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
456 r_dev=dev[1], r_intent=14,
458 check_grpform_results(i_res, r_res)
459 if int(i_res['freq']) > 4000:
460 raise Exception("Unexpected channel - did not follow world roaming rules")
461 remove_group(dev[0], dev[1])
463 def test_grpform_no_5ghz_add_cli2(dev):
464 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
465 dev[0].request("SET p2p_add_cli_chan 1")
466 dev[1].request("SET p2p_add_cli_chan 1")
467 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
468 r_dev=dev[1], r_intent=0,
470 check_grpform_results(i_res, r_res)
471 if int(i_res['freq']) > 4000:
472 raise Exception("Unexpected channel - did not follow world roaming rules")
473 remove_group(dev[0], dev[1])
475 def test_grpform_no_5ghz_add_cli3(dev):
476 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
477 dev[0].request("SET p2p_add_cli_chan 1")
478 dev[1].request("SET p2p_add_cli_chan 1")
479 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
480 r_dev=dev[1], r_intent=15,
482 check_grpform_results(i_res, r_res)
483 if int(i_res['freq']) > 4000:
484 raise Exception("Unexpected channel - did not follow world roaming rules")
485 remove_group(dev[0], dev[1])
487 def test_grpform_no_5ghz_add_cli4(dev):
488 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
489 dev[0].request("SET p2p_add_cli_chan 1")
490 dev[1].request("SET p2p_add_cli_chan 1")
491 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
492 r_dev=dev[1], r_intent=0,
494 check_grpform_results(i_res, r_res)
495 if int(i_res['freq']) > 4000:
496 raise Exception("Unexpected channel - did not follow world roaming rules")
497 remove_group(dev[0], dev[1])
499 def test_grpform_incorrect_pin(dev):
500 """P2P GO Negotiation with incorrect PIN"""
502 addr1 = dev[1].p2p_dev_addr()
503 if not dev[0].discover_peer(addr1):
504 raise Exception("Peer not found")
505 res = dev[1].request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
507 raise Exception("P2P_CONNECT failed to generate PIN")
508 logger.info("PIN from P2P_CONNECT: " + res)
509 dev[0].request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
510 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
512 raise Exception("GO Negotiation did not complete successfully(0)")
513 ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
515 raise Exception("GO Negotiation did not complete successfully(1)")
516 ev = dev[1].wait_event(["WPS-FAIL"], timeout=15)
518 raise Exception("WPS failure not reported(1)")
519 if "msg=8 config_error=18" not in ev:
520 raise Exception("Unexpected WPS failure(1): " + ev)
521 ev = dev[0].wait_event(["WPS-FAIL"], timeout=15)
523 raise Exception("WPS failure not reported")
524 if "msg=8 config_error=18" not in ev:
525 raise Exception("Unexpected WPS failure: " + ev)
526 ev = dev[1].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
528 raise Exception("Group formation failure timed out")
529 ev = dev[0].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
531 raise Exception("Group formation failure timed out")
533 def test_grpform_reject(dev):
534 """User rejecting group formation attempt by a P2P peer"""
535 addr0 = dev[0].p2p_dev_addr()
537 dev[1].p2p_go_neg_init(addr0, None, "pbc")
538 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
540 raise Exception("GO Negotiation timed out")
541 if "OK" in dev[0].global_request("P2P_REJECT foo"):
542 raise Exception("Invalid P2P_REJECT accepted")
543 if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
544 raise Exception("P2P_REJECT failed")
545 dev[1].request("P2P_STOP_FIND")
546 dev[1].p2p_go_neg_init(addr0, None, "pbc")
547 ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
549 raise Exception("Rejection not reported")
550 if "status=11" not in ev:
551 raise Exception("Unexpected status code in rejection")
553 def test_grpform_pd_no_probe_resp(dev):
554 """GO Negotiation after PD, but no Probe Response"""
555 addr0 = dev[0].p2p_dev_addr()
556 addr1 = dev[1].p2p_dev_addr()
558 if not dev[1].discover_peer(addr0):
559 raise Exception("Peer not found")
560 dev[1].p2p_stop_find()
561 dev[0].p2p_stop_find()
562 peer = dev[0].get_peer(addr1)
563 if peer['listen_freq'] == '0':
564 raise Exception("Peer listen frequency not learned from Probe Request")
566 dev[0].request("P2P_FLUSH")
568 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
569 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
571 raise Exception("PD Request timed out")
572 ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
574 raise Exception("PD Response timed out")
575 peer = dev[0].get_peer(addr1)
576 if peer['listen_freq'] != '0':
577 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
579 pin = dev[0].wps_read_pin()
580 if "FAIL" in dev[1].request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
581 raise Exception("P2P_CONNECT on initiator failed")
582 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
584 raise Exception("GO Negotiation start timed out")
585 peer = dev[0].get_peer(addr1)
586 if peer['listen_freq'] == '0':
587 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
588 if "FAIL" in dev[0].request("P2P_CONNECT " + addr1 + " " + pin + " display"):
589 raise Exception("P2P_CONNECT on responder failed")
590 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
592 raise Exception("Group formation timed out")
593 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
595 raise Exception("Group formation timed out")
597 def test_go_neg_two_peers(dev):
598 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
599 addr0 = dev[0].p2p_dev_addr()
600 addr1 = dev[1].p2p_dev_addr()
601 addr2 = dev[2].p2p_dev_addr()
604 if not dev[0].discover_peer(addr1):
605 raise Exception("Could not discover peer")
606 if not dev[0].discover_peer(addr2):
607 raise Exception("Could not discover peer")
608 if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
609 raise Exception("Failed to authorize GO Neg")
611 if not dev[2].discover_peer(addr0):
612 raise Exception("Could not discover peer")
613 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
614 raise Exception("Failed to initiate GO Neg")
615 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
617 raise Exception("timeout on GO Neg RX event")
618 dev[2].request("P2P_CONNECT " + addr0 + " pbc")
619 ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
621 raise Exception("Rejection not reported")
622 if "status=5" not in ev:
623 raise Exception("Unexpected status code in rejection: " + ev)
625 def clear_pbc_overlap(dev, ifname):
626 hapd_global = hostapd.HostapdGlobal()
627 hapd_global.remove(ifname)
628 dev[0].request("P2P_CANCEL")
629 dev[1].request("P2P_CANCEL")
630 dev[0].p2p_stop_find()
631 dev[1].p2p_stop_find()
632 dev[0].dump_monitor()
633 dev[1].dump_monitor()
635 dev[0].flush_scan_cache()
636 dev[1].flush_scan_cache()
639 def test_grpform_pbc_overlap(dev, apdev):
640 """P2P group formation during PBC overlap"""
641 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
642 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
643 hapd.request("WPS_PBC")
646 # Since P2P Client scan case is now optimzied to use a specific SSID, the
647 # WPS AP will not reply to that and the scan after GO Negotiation can quite
648 # likely miss the AP due to dwell time being short enoguh to miss the Beacon
649 # frame. This has made the test case somewhat pointless, but keep it here
650 # for now with an additional scan to confirm that PBC detection works if
651 # there is a BSS entry for a overlapping AP.
652 for i in range(0, 5):
653 dev[0].scan(freq="2412")
654 if dev[0].get_bss(apdev[0]['bssid']) is not None:
657 addr0 = dev[0].p2p_dev_addr()
658 addr1 = dev[1].p2p_dev_addr()
660 if not dev[1].discover_peer(addr0):
661 raise Exception("Could not discover peer")
663 if not dev[0].discover_peer(addr1):
664 raise Exception("Could not discover peer")
666 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
667 raise Exception("Failed to authorize GO Neg")
668 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
669 raise Exception("Failed to initiate GO Neg")
670 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
672 raise Exception("PBC overlap not reported")
674 clear_pbc_overlap(dev, apdev[0]['ifname'])
676 def test_grpform_pbc_overlap_group_iface(dev, apdev):
677 """P2P group formation during PBC overlap using group interfaces"""
678 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
679 # update use this information.
680 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
681 "beacon_int": "15", 'manage_p2p': '1' }
682 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
683 hapd.request("WPS_PBC")
685 dev[0].request("SET p2p_no_group_iface 0")
686 dev[1].request("SET p2p_no_group_iface 0")
688 addr0 = dev[0].p2p_dev_addr()
689 addr1 = dev[1].p2p_dev_addr()
691 if not dev[1].discover_peer(addr0):
692 raise Exception("Could not discover peer")
694 if not dev[0].discover_peer(addr1):
695 raise Exception("Could not discover peer")
696 dev[0].p2p_stop_find()
697 dev[0].scan(freq="2412")
699 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
700 raise Exception("Failed to authorize GO Neg")
701 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
702 raise Exception("Failed to initiate GO Neg")
703 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
704 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
705 if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
706 # Do not report this as failure since the P2P group formation case
707 # using a separate group interface has limited chances of "seeing" the
708 # overlapping AP due to a per-SSID scan and no prior scan operations on
709 # the group interface.
710 logger.info("PBC overlap not reported")
712 clear_pbc_overlap(dev, apdev[0]['ifname'])
714 def test_grpform_goneg_fail_with_group_iface(dev):
715 """P2P group formation fails while using group interface"""
716 dev[0].request("SET p2p_no_group_iface 0")
718 peer = dev[1].p2p_dev_addr()
719 if not dev[0].discover_peer(peer):
720 raise Exception("Peer " + peer + " not found")
721 if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
722 raise Exception("P2P_REJECT failed")
723 if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
724 raise Exception("P2P_CONNECT failed")
725 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
727 raise Exception("GO Negotiation failure timed out")
729 def test_grpform_cred_ready_timeout(dev, apdev, params):
730 """P2P GO Negotiation wait for credentials to become ready [long]"""
731 if not params['long']:
732 logger.info("Skip test case with long duration due to --long not specified")
736 addr1 = dev[1].p2p_dev_addr()
737 if not dev[0].discover_peer(addr1):
738 raise Exception("Peer " + addr1 + " not found")
739 start = os.times()[4]
740 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display"):
741 raise Exception("Failed to initiate GO Neg")
742 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=200)
744 raise Exception("GO Negotiation failure timed out")
746 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
747 if end - start < 120:
748 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
750 def test_grpform_cred_ready_timeout2(dev, apdev, params):
751 """P2P GO Negotiation wait for credentials to become ready (2) [long]"""
752 if not params['long']:
753 logger.info("Skip test case with long duration due to --long not specified")
757 addr1 = dev[1].p2p_dev_addr()
758 if not dev[0].discover_peer(addr1):
759 raise Exception("Peer " + addr1 + " not found")
760 start = os.times()[4]
761 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display"):
762 raise Exception("Failed to initiate GO Neg")
763 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
765 raise Exception("Too early GO Negotiation timeout reported")
766 dev[0].dump_monitor()
767 logger.info("Starting p2p_find to change state")
769 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
771 raise Exception("GO Negotiation failure timed out")
772 dev[0].dump_monitor()
774 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
775 if end - start < 120:
776 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
779 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
781 raise Exception("Did not discovery new device after GO Negotiation failure")
782 if dev[2].p2p_dev_addr() not in ev:
783 raise Exception("Unexpected device found: " + ev)
785 def test_grpform_no_wsc_done(dev):
786 """P2P group formation with WSC-Done not sent"""
787 addr0 = dev[0].p2p_dev_addr()
788 addr1 = dev[1].p2p_dev_addr()
790 for i in range(0, 2):
791 dev[0].request("SET ext_eapol_frame_io 1")
792 dev[1].request("SET ext_eapol_frame_io 1")
794 dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
796 dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
797 go_intent=15, wait_group=False)
801 ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
803 raise Exception("Timeout on EAPOL-TX from GO")
805 mode = dev[0].get_status_field("mode")
806 res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
808 raise Exception("EAPOL_RX failed")
809 ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
811 raise Exception("Timeout on EAPOL-TX from P2P Client")
812 msg = ev.split(' ')[2]
813 if msg[46:56] == "102200010f":
814 logger.info("Drop WSC_Done")
815 dev[0].request("SET ext_eapol_frame_io 0")
816 dev[1].request("SET ext_eapol_frame_io 0")
817 # Fake EAP-Failure to complete session on the client
819 dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
821 res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
823 raise Exception("EAPOL_RX failed")
825 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
827 raise Exception("Group formation timed out on GO")
828 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
830 raise Exception("Group formation timed out on P2P Client")
831 dev[0].remove_group()
833 if mode != "P2P GO - group formation":
834 raise Exception("Unexpected mode on GO during group formation: " + mode)
836 def test_grpform_wait_peer(dev):
837 """P2P group formation wait for peer to become ready"""
838 addr0 = dev[0].p2p_dev_addr()
839 addr1 = dev[1].p2p_dev_addr()
841 if not dev[0].discover_peer(addr1):
842 raise Exception("Peer " + addr1 + " not found")
843 dev[0].request("SET extra_roc_dur 500")
844 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
845 raise Exception("Failed to initiate GO Neg")
847 dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
849 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
851 raise Exception("Group formation timed out")
852 dev[0].request("SET extra_roc_dur 0")
853 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
855 raise Exception("Group formation timed out")
856 dev[0].remove_group()
858 def test_invalid_p2p_connect_command(dev):
859 """P2P_CONNECT error cases"""
860 id = dev[0].add_network()
863 "00:11:22:33:44:55 pbc persistent=123",
864 "00:11:22:33:44:55 pbc persistent=%d" % id,
865 "00:11:22:33:44:55 pbc go_intent=-1",
866 "00:11:22:33:44:55 pbc go_intent=16",
867 "00:11:22:33:44:55 pin",
868 "00:11:22:33:44:55 pbc freq=0" ]:
869 if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
870 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
872 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
873 raise Exception("Invalid PIN was not rejected")
875 if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
876 raise Exception("Unsupported channel not reported")