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()
17 from utils import HwsimSkip
18 from wpasupplicant import WpaSupplicant
20 def check_grpform_results(i_res, r_res):
21 if i_res['result'] != 'success' or r_res['result'] != 'success':
22 raise Exception("Failed group formation")
23 if i_res['ssid'] != r_res['ssid']:
24 raise Exception("SSID mismatch")
25 if i_res['freq'] != r_res['freq']:
26 raise Exception("freq mismatch")
27 if 'go_neg_freq' in r_res and i_res['go_neg_freq'] != r_res['go_neg_freq']:
28 raise Exception("go_neg_freq mismatch")
29 if i_res['freq'] != i_res['go_neg_freq']:
30 raise Exception("freq/go_neg_freq mismatch")
31 if i_res['role'] != i_res['go_neg_role']:
32 raise Exception("role/go_neg_role mismatch")
33 if 'go_neg_role' in r_res and r_res['role'] != r_res['go_neg_role']:
34 raise Exception("role/go_neg_role mismatch")
35 if i_res['go_dev_addr'] != r_res['go_dev_addr']:
36 raise Exception("GO Device Address mismatch")
38 def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
39 logger.debug("Initiate GO Negotiation from i_dev")
41 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent)
42 logger.debug("i_res: " + str(i_res))
45 logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e))
48 def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
51 pin = r_dev.wps_read_pin()
52 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
55 t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
57 logger.debug("Wait for GO Negotiation Request on r_dev")
58 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
60 raise Exception("GO Negotiation timed out")
62 logger.debug("Re-initiate GO Negotiation from r_dev")
63 r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
64 logger.debug("r_res: " + str(r_res))
69 raise Exception("go_neg_init thread failed")
70 logger.debug("i_res: " + str(i_res))
71 logger.info("Group formed")
72 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
76 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):
78 pin = r_dev.wps_read_pin()
79 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
80 r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq)
82 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)
83 r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
84 logger.debug("i_res: " + str(i_res))
85 logger.debug("r_res: " + str(r_res))
89 if i_res['result'] != 'go-neg-failed':
90 raise Exception("Expected GO Negotiation failure not reported")
91 if i_res['status'] != i_go_neg_status:
92 raise Exception("Expected GO Negotiation status not seen")
95 logger.info("Group formed")
97 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
100 def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc):
101 logger.debug("Initiate GO Negotiation from i_dev")
103 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc",
104 timeout=20, go_intent=i_intent, freq=freq,
106 logger.debug("i_res: " + str(i_res))
109 logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e))
112 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):
116 r_dev.p2p_find(social=True)
117 i_dev.p2p_find(social=True)
118 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
121 t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc))
123 logger.debug("Wait for GO Negotiation Request on r_dev")
124 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
126 raise Exception("GO Negotiation timed out")
128 # Allow some time for the GO Neg Resp to go out before initializing new
131 logger.debug("Re-initiate GO Negotiation from r_dev")
132 r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc",
133 go_intent=r_intent, timeout=20, freq=r_freq)
134 logger.debug("r_res: " + str(r_res))
139 raise Exception("go_neg_init_pbc thread failed")
140 logger.debug("i_res: " + str(i_res))
141 logger.info("Group formed")
142 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
144 return [i_res, r_res]
146 def go_neg_pbc_authorized(i_dev, r_dev, i_intent=None, r_intent=None,
147 expect_failure=False, i_freq=None, r_freq=None):
149 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
150 r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), None, "pbc",
151 go_intent=r_intent, freq=r_freq)
153 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc", timeout=20,
155 expect_failure=expect_failure, freq=i_freq)
156 r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
157 logger.debug("i_res: " + str(i_res))
158 logger.debug("r_res: " + str(r_res))
163 logger.info("Group formed")
164 return [i_res, r_res]
166 def remove_group(dev1, dev2):
173 def test_grpform(dev):
174 """P2P group formation using PIN and authorized connection (init -> GO)"""
176 dev[0].global_request("SET p2p_group_idle 2")
177 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
178 r_dev=dev[1], r_intent=0)
179 check_grpform_results(i_res, r_res)
180 dev[1].remove_group()
181 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
183 raise Exception("GO did not remove group on idle timeout")
184 if "GO reason=IDLE" not in ev:
185 raise Exception("Unexpected group removal event: " + ev)
187 dev[0].global_request("SET p2p_group_idle 0")
189 def test_grpform_a(dev):
190 """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
191 dev[0].global_request("SET p2p_no_group_iface 0")
192 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
193 r_dev=dev[1], r_intent=0)
194 if "p2p-wlan" not in i_res['ifname']:
195 raise Exception("Unexpected group interface name")
196 check_grpform_results(i_res, r_res)
197 remove_group(dev[0], dev[1])
198 if i_res['ifname'] in utils.get_ifnames():
199 raise Exception("Group interface netdev was not removed")
201 def test_grpform_b(dev):
202 """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
203 dev[1].global_request("SET p2p_no_group_iface 0")
204 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
205 r_dev=dev[1], r_intent=0)
206 if "p2p-wlan" not in r_res['ifname']:
207 raise Exception("Unexpected group interface name")
208 check_grpform_results(i_res, r_res)
209 remove_group(dev[0], dev[1])
210 if r_res['ifname'] in utils.get_ifnames():
211 raise Exception("Group interface netdev was not removed")
213 def test_grpform_c(dev):
214 """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
215 dev[0].global_request("SET p2p_no_group_iface 0")
216 dev[1].global_request("SET p2p_no_group_iface 0")
217 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
218 r_dev=dev[1], r_intent=0)
219 if "p2p-wlan" not in i_res['ifname']:
220 raise Exception("Unexpected group interface name")
221 if "p2p-wlan" not in r_res['ifname']:
222 raise Exception("Unexpected group interface name")
223 check_grpform_results(i_res, r_res)
224 remove_group(dev[0], dev[1])
225 if i_res['ifname'] in utils.get_ifnames():
226 raise Exception("Group interface netdev was not removed")
227 if r_res['ifname'] in utils.get_ifnames():
228 raise Exception("Group interface netdev was not removed")
230 def test_grpform2(dev):
231 """P2P group formation using PIN and authorized connection (resp -> GO)"""
232 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
233 remove_group(dev[0], dev[1])
235 def test_grpform2_c(dev):
236 """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
237 dev[0].global_request("SET p2p_no_group_iface 0")
238 dev[1].global_request("SET p2p_no_group_iface 0")
239 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
240 remove_group(dev[0], dev[1])
241 if i_res['ifname'] in utils.get_ifnames():
242 raise Exception("Group interface netdev was not removed")
243 if r_res['ifname'] in utils.get_ifnames():
244 raise Exception("Group interface netdev was not removed")
246 def test_grpform3(dev):
247 """P2P group formation using PIN and re-init GO Negotiation"""
248 go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
249 remove_group(dev[0], dev[1])
251 def test_grpform3_c(dev):
252 """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
253 dev[0].global_request("SET p2p_no_group_iface 0")
254 dev[1].global_request("SET p2p_no_group_iface 0")
255 [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
256 remove_group(dev[0], dev[1])
257 if i_res['ifname'] in utils.get_ifnames():
258 raise Exception("Group interface netdev was not removed")
259 if r_res['ifname'] in utils.get_ifnames():
260 raise Exception("Group interface netdev was not removed")
262 def test_grpform_pbc(dev):
263 """P2P group formation using PBC and re-init GO Negotiation"""
264 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
265 check_grpform_results(i_res, r_res)
266 if i_res['role'] != 'GO' or r_res['role'] != 'client':
267 raise Exception("Unexpected device roles")
268 remove_group(dev[0], dev[1])
270 def test_grpform_pd(dev):
271 """P2P group formation with PD-before-GO-Neg workaround"""
272 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
273 check_grpform_results(i_res, r_res)
274 remove_group(dev[0], dev[1])
276 def test_grpform_ext_listen(dev):
277 """P2P group formation with extended listen timing enabled"""
278 addr0 = dev[0].p2p_dev_addr()
280 if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
281 raise Exception("Invalid P2P_EXT_LISTEN accepted")
282 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 300 1000"):
283 raise Exception("Failed to set extended listen timing")
284 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
285 raise Exception("Failed to set extended listen timing")
286 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1],
287 r_listen=True, i_freq="2417", r_freq="2417",
288 i_intent=1, r_intent=15)
289 check_grpform_results(i_res, r_res)
290 peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
291 if peer1['ext_listen_interval'] != "40000":
292 raise Exception("Extended listen interval not discovered correctly")
293 if peer1['ext_listen_period'] != "200":
294 raise Exception("Extended listen period not discovered correctly")
295 peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
296 if peer0['ext_listen_interval'] != "1000":
297 raise Exception("Extended listen interval not discovered correctly")
298 if peer0['ext_listen_period'] != "300":
299 raise Exception("Extended listen period not discovered correctly")
300 if not dev[2].discover_peer(addr0):
301 raise Exception("Could not discover peer during ext listen")
302 remove_group(dev[0], dev[1])
304 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
305 raise Exception("Failed to clear extended listen timing")
306 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
307 raise Exception("Failed to clear extended listen timing")
309 def test_both_go_intent_15(dev):
310 """P2P GO Negotiation with both devices using GO intent 15"""
311 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)
313 def test_both_go_neg_display(dev):
314 """P2P GO Negotiation with both devices trying to display PIN"""
315 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')
317 def test_both_go_neg_enter(dev):
318 """P2P GO Negotiation with both devices trying to enter PIN"""
319 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')
321 def test_go_neg_pbc_vs_pin(dev):
322 """P2P GO Negotiation with one device using PBC and the other PIN"""
323 addr0 = dev[0].p2p_dev_addr()
324 addr1 = dev[1].p2p_dev_addr()
326 if not dev[0].discover_peer(addr1):
327 raise Exception("Could not discover peer")
329 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
330 raise Exception("Failed to authorize GO Neg")
331 if not dev[1].discover_peer(addr0):
332 raise Exception("Could not discover peer")
333 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
334 raise Exception("Failed to initiate GO Neg")
335 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
337 raise Exception("GO Negotiation failure timed out")
338 if "status=10" not in ev:
339 raise Exception("Unexpected failure reason: " + ev)
341 def test_go_neg_pin_vs_pbc(dev):
342 """P2P GO Negotiation with one device using PIN and the other PBC"""
343 addr0 = dev[0].p2p_dev_addr()
344 addr1 = dev[1].p2p_dev_addr()
346 if not dev[0].discover_peer(addr1):
347 raise Exception("Could not discover peer")
349 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
350 raise Exception("Failed to authorize GO Neg")
351 if not dev[1].discover_peer(addr0):
352 raise Exception("Could not discover peer")
353 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
354 raise Exception("Failed to initiate GO Neg")
355 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
357 raise Exception("GO Negotiation failure timed out")
358 if "status=10" not in ev:
359 raise Exception("Unexpected failure reason: " + ev)
361 def test_grpform_per_sta_psk(dev):
362 """P2P group formation with per-STA PSKs"""
363 dev[0].global_request("P2P_SET per_sta_psk 1")
364 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
365 check_grpform_results(i_res, r_res)
367 pin = dev[2].wps_read_pin()
368 dev[0].p2p_go_authorize_client(pin)
369 c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
370 check_grpform_results(i_res, c_res)
372 if r_res['psk'] == c_res['psk']:
373 raise Exception("Same PSK assigned for both clients")
375 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
377 dev[0].remove_group()
378 dev[1].wait_go_ending_session()
379 dev[2].wait_go_ending_session()
381 def test_grpform_per_sta_psk_wps(dev):
382 """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
383 dev[0].global_request("P2P_SET per_sta_psk 1")
384 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
385 check_grpform_results(i_res, r_res)
387 dev[0].p2p_go_authorize_client_pbc()
388 dev[2].request("WPS_PBC")
389 dev[2].wait_connected(timeout=30)
391 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
393 dev[0].remove_group()
394 dev[2].request("DISCONNECT")
395 dev[1].wait_go_ending_session()
397 def test_grpform_force_chan_go(dev):
398 """P2P group formation forced channel selection by GO"""
399 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
401 r_dev=dev[1], r_intent=0,
403 check_grpform_results(i_res, r_res)
404 if i_res['freq'] != "2432":
405 raise Exception("Unexpected channel - did not follow GO's forced channel")
406 remove_group(dev[0], dev[1])
408 def test_grpform_force_chan_cli(dev):
409 """P2P group formation forced channel selection by client"""
410 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
412 r_dev=dev[1], r_intent=15,
414 check_grpform_results(i_res, r_res)
415 if i_res['freq'] != "2417":
416 raise Exception("Unexpected channel - did not follow GO's forced channel")
417 remove_group(dev[0], dev[1])
419 def test_grpform_force_chan_conflict(dev):
420 """P2P group formation fails due to forced channel mismatch"""
421 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
422 r_dev=dev[1], r_intent=15, r_freq=2427,
423 expect_failure=True, i_go_neg_status=7)
425 def test_grpform_pref_chan_go(dev):
426 """P2P group formation preferred channel selection by GO"""
427 dev[0].request("SET p2p_pref_chan 81:7")
428 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
429 r_dev=dev[1], r_intent=0,
431 check_grpform_results(i_res, r_res)
432 if i_res['freq'] != "2442":
433 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
434 remove_group(dev[0], dev[1])
436 def test_grpform_pref_chan_go_overridden(dev):
437 """P2P group formation preferred channel selection by GO overridden by client"""
438 dev[1].request("SET p2p_pref_chan 81:7")
439 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
441 r_dev=dev[1], r_intent=15,
443 check_grpform_results(i_res, r_res)
444 if i_res['freq'] != "2422":
445 raise Exception("Unexpected channel - did not follow client's forced channel")
446 remove_group(dev[0], dev[1])
448 def test_grpform_no_go_freq_forcing_chan(dev):
449 """P2P group formation with no-GO freq forcing channel"""
450 dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
451 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
452 r_dev=dev[1], r_intent=15,
454 check_grpform_results(i_res, r_res)
455 if int(i_res['freq']) > 4000:
456 raise Exception("Unexpected channel - did not follow no-GO freq")
457 remove_group(dev[0], dev[1])
459 def test_grpform_no_go_freq_conflict(dev):
460 """P2P group formation fails due to no-GO range forced by client"""
461 dev[1].request("SET p2p_no_go_freq 2000-3000")
462 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
463 r_dev=dev[1], r_intent=15,
464 expect_failure=True, i_go_neg_status=7)
466 def test_grpform_no_5ghz_world_roaming(dev):
467 """P2P group formation with world roaming regulatory"""
468 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
469 r_dev=dev[1], r_intent=15,
471 check_grpform_results(i_res, r_res)
472 if int(i_res['freq']) > 4000:
473 raise Exception("Unexpected channel - did not follow world roaming rules")
474 remove_group(dev[0], dev[1])
476 def test_grpform_no_5ghz_add_cli(dev):
477 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
478 dev[0].request("SET p2p_add_cli_chan 1")
479 dev[1].request("SET p2p_add_cli_chan 1")
480 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
481 r_dev=dev[1], r_intent=14,
483 check_grpform_results(i_res, r_res)
484 if int(i_res['freq']) > 4000:
485 raise Exception("Unexpected channel - did not follow world roaming rules")
486 remove_group(dev[0], dev[1])
488 def test_grpform_no_5ghz_add_cli2(dev):
489 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
490 dev[0].request("SET p2p_add_cli_chan 1")
491 dev[1].request("SET p2p_add_cli_chan 1")
492 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
493 r_dev=dev[1], r_intent=0,
495 check_grpform_results(i_res, r_res)
496 if int(i_res['freq']) > 4000:
497 raise Exception("Unexpected channel - did not follow world roaming rules")
498 remove_group(dev[0], dev[1])
500 def test_grpform_no_5ghz_add_cli3(dev):
501 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
502 dev[0].request("SET p2p_add_cli_chan 1")
503 dev[1].request("SET p2p_add_cli_chan 1")
504 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
505 r_dev=dev[1], r_intent=15,
507 check_grpform_results(i_res, r_res)
508 if int(i_res['freq']) > 4000:
509 raise Exception("Unexpected channel - did not follow world roaming rules")
510 remove_group(dev[0], dev[1])
512 def test_grpform_no_5ghz_add_cli4(dev):
513 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
514 dev[0].request("SET p2p_add_cli_chan 1")
515 dev[1].request("SET p2p_add_cli_chan 1")
516 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
517 r_dev=dev[1], r_intent=0,
519 check_grpform_results(i_res, r_res)
520 if int(i_res['freq']) > 4000:
521 raise Exception("Unexpected channel - did not follow world roaming rules")
522 remove_group(dev[0], dev[1])
524 def test_grpform_incorrect_pin(dev):
525 """P2P GO Negotiation with incorrect PIN"""
527 addr1 = dev[1].p2p_dev_addr()
528 if not dev[0].discover_peer(addr1):
529 raise Exception("Peer not found")
530 res = dev[1].global_request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
532 raise Exception("P2P_CONNECT failed to generate PIN")
533 logger.info("PIN from P2P_CONNECT: " + res)
534 dev[0].global_request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
535 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
537 raise Exception("GO Negotiation did not complete successfully(0)")
538 ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
540 raise Exception("GO Negotiation did not complete successfully(1)")
541 ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=15)
543 raise Exception("WPS failure not reported(1)")
544 if "msg=8 config_error=18" not in ev:
545 raise Exception("Unexpected WPS failure(1): " + ev)
546 ev = dev[0].wait_global_event(["WPS-FAIL"], timeout=15)
548 raise Exception("WPS failure not reported")
549 if "msg=8 config_error=18" not in ev:
550 raise Exception("Unexpected WPS failure: " + ev)
551 ev = dev[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
553 raise Exception("Group formation failure timed out")
554 ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
556 raise Exception("Group formation failure timed out")
558 def test_grpform_reject(dev):
559 """User rejecting group formation attempt by a P2P peer"""
560 addr0 = dev[0].p2p_dev_addr()
562 dev[1].p2p_go_neg_init(addr0, None, "pbc")
563 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
565 raise Exception("GO Negotiation timed out")
566 if "OK" in dev[0].global_request("P2P_REJECT foo"):
567 raise Exception("Invalid P2P_REJECT accepted")
568 if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
569 raise Exception("P2P_REJECT failed")
570 dev[1].request("P2P_STOP_FIND")
571 dev[1].p2p_go_neg_init(addr0, None, "pbc")
572 ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
574 raise Exception("Rejection not reported")
575 if "status=11" not in ev:
576 raise Exception("Unexpected status code in rejection")
578 def test_grpform_pd_no_probe_resp(dev):
579 """GO Negotiation after PD, but no Probe Response"""
580 addr0 = dev[0].p2p_dev_addr()
581 addr1 = dev[1].p2p_dev_addr()
583 if not dev[1].discover_peer(addr0):
584 raise Exception("Peer not found")
585 dev[1].p2p_stop_find()
586 dev[0].p2p_stop_find()
587 peer = dev[0].get_peer(addr1)
588 if peer['listen_freq'] == '0':
589 raise Exception("Peer listen frequency not learned from Probe Request")
591 dev[0].request("P2P_FLUSH")
593 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
594 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
596 raise Exception("PD Request timed out")
597 ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
599 raise Exception("PD Response timed out")
600 peer = dev[0].get_peer(addr1)
601 if peer['listen_freq'] != '0':
602 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
604 pin = dev[0].wps_read_pin()
605 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
606 raise Exception("P2P_CONNECT on initiator failed")
607 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
609 raise Exception("GO Negotiation start timed out")
610 peer = dev[0].get_peer(addr1)
611 if peer['listen_freq'] == '0':
612 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
613 if "FAIL" in dev[0].global_request("P2P_CONNECT " + addr1 + " " + pin + " display"):
614 raise Exception("P2P_CONNECT on responder failed")
615 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
617 raise Exception("Group formation timed out")
618 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
620 raise Exception("Group formation timed out")
622 def test_go_neg_two_peers(dev):
623 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
624 addr0 = dev[0].p2p_dev_addr()
625 addr1 = dev[1].p2p_dev_addr()
626 addr2 = dev[2].p2p_dev_addr()
629 if not dev[0].discover_peer(addr1):
630 raise Exception("Could not discover peer")
631 if not dev[0].discover_peer(addr2):
632 raise Exception("Could not discover peer")
633 if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
634 raise Exception("Failed to authorize GO Neg")
636 if not dev[2].discover_peer(addr0):
637 raise Exception("Could not discover peer")
638 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
639 raise Exception("Failed to initiate GO Neg")
640 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
642 raise Exception("timeout on GO Neg RX event")
643 dev[2].request("P2P_CONNECT " + addr0 + " pbc")
644 ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
646 raise Exception("Rejection not reported")
647 if "status=5" not in ev:
648 raise Exception("Unexpected status code in rejection: " + ev)
650 def clear_pbc_overlap(dev, ifname):
651 hapd_global = hostapd.HostapdGlobal()
652 hapd_global.remove(ifname)
653 dev[0].request("P2P_CANCEL")
654 dev[1].request("P2P_CANCEL")
655 dev[0].p2p_stop_find()
656 dev[1].p2p_stop_find()
657 dev[0].dump_monitor()
658 dev[1].dump_monitor()
660 dev[0].flush_scan_cache()
661 dev[1].flush_scan_cache()
664 def test_grpform_pbc_overlap(dev, apdev):
665 """P2P group formation during PBC overlap"""
666 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
667 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
668 hapd.request("WPS_PBC")
671 # Since P2P Client scan case is now optimzied to use a specific SSID, the
672 # WPS AP will not reply to that and the scan after GO Negotiation can quite
673 # likely miss the AP due to dwell time being short enoguh to miss the Beacon
674 # frame. This has made the test case somewhat pointless, but keep it here
675 # for now with an additional scan to confirm that PBC detection works if
676 # there is a BSS entry for a overlapping AP.
677 for i in range(0, 5):
678 dev[0].scan(freq="2412")
679 if dev[0].get_bss(apdev[0]['bssid']) is not None:
682 addr0 = dev[0].p2p_dev_addr()
683 addr1 = dev[1].p2p_dev_addr()
685 if not dev[1].discover_peer(addr0):
686 raise Exception("Could not discover peer")
688 if not dev[0].discover_peer(addr1):
689 raise Exception("Could not discover peer")
691 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
692 raise Exception("Failed to authorize GO Neg")
693 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
694 raise Exception("Failed to initiate GO Neg")
695 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
697 raise Exception("PBC overlap not reported")
699 clear_pbc_overlap(dev, apdev[0]['ifname'])
701 def test_grpform_pbc_overlap_group_iface(dev, apdev):
702 """P2P group formation during PBC overlap using group interfaces"""
703 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
704 # update use this information.
705 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
706 "beacon_int": "15", 'manage_p2p': '1' }
707 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
708 hapd.request("WPS_PBC")
710 dev[0].request("SET p2p_no_group_iface 0")
711 dev[1].request("SET p2p_no_group_iface 0")
713 addr0 = dev[0].p2p_dev_addr()
714 addr1 = dev[1].p2p_dev_addr()
716 if not dev[1].discover_peer(addr0):
717 raise Exception("Could not discover peer")
719 if not dev[0].discover_peer(addr1):
720 raise Exception("Could not discover peer")
721 dev[0].p2p_stop_find()
722 dev[0].scan(freq="2412")
724 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
725 raise Exception("Failed to authorize GO Neg")
726 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
727 raise Exception("Failed to initiate GO Neg")
728 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
729 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
730 if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
731 # Do not report this as failure since the P2P group formation case
732 # using a separate group interface has limited chances of "seeing" the
733 # overlapping AP due to a per-SSID scan and no prior scan operations on
734 # the group interface.
735 logger.info("PBC overlap not reported")
737 clear_pbc_overlap(dev, apdev[0]['ifname'])
739 def test_grpform_goneg_fail_with_group_iface(dev):
740 """P2P group formation fails while using group interface"""
741 dev[0].request("SET p2p_no_group_iface 0")
743 peer = dev[1].p2p_dev_addr()
744 if not dev[0].discover_peer(peer):
745 raise Exception("Peer " + peer + " not found")
746 if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
747 raise Exception("P2P_REJECT failed")
748 if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
749 raise Exception("P2P_CONNECT failed")
750 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
752 raise Exception("GO Negotiation failure timed out")
754 def test_grpform_cred_ready_timeout(dev, apdev, params):
755 """P2P GO Negotiation wait for credentials to become ready [long]"""
756 if not params['long']:
757 raise HwsimSkip("Skip test case with long duration due to --long not specified")
760 addr1 = dev[1].p2p_dev_addr()
761 if not dev[0].discover_peer(addr1):
762 raise Exception("Peer " + addr1 + " not found")
763 if not dev[2].discover_peer(addr1):
764 raise Exception("Peer " + addr1 + " not found(2)")
766 start = os.times()[4]
768 cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
769 if "OK" not in dev[0].global_request(cmd):
770 raise Exception("Failed to initiate GO Neg")
772 if "OK" not in dev[2].global_request(cmd):
773 raise Exception("Failed to initiate GO Neg(2)")
775 # First, check with p2p_find
776 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
778 raise Exception("Too early GO Negotiation timeout reported(2)")
779 dev[2].dump_monitor()
780 logger.info("Starting p2p_find to change state")
782 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
784 raise Exception("GO Negotiation failure timed out(2)")
785 dev[2].dump_monitor()
787 logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
788 if end - start < 120:
789 raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
791 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
792 wpas.interface_add("wlan5")
795 ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
797 raise Exception("Did not discover new device after GO Negotiation failure")
798 if wpas.p2p_dev_addr() not in ev:
799 raise Exception("Unexpected device found: " + ev)
800 dev[2].p2p_stop_find()
803 # Finally, verify without p2p_find
804 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
806 raise Exception("GO Negotiation failure timed out")
808 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
809 if end - start < 120:
810 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
812 def test_grpform_no_wsc_done(dev):
813 """P2P group formation with WSC-Done not sent"""
814 addr0 = dev[0].p2p_dev_addr()
815 addr1 = dev[1].p2p_dev_addr()
817 for i in range(0, 2):
818 dev[0].request("SET ext_eapol_frame_io 1")
819 dev[1].request("SET ext_eapol_frame_io 1")
821 dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
823 dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
824 go_intent=15, wait_group=False)
828 ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
830 raise Exception("Timeout on EAPOL-TX from GO")
832 mode = dev[0].get_status_field("mode")
833 res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
835 raise Exception("EAPOL_RX failed")
836 ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
838 raise Exception("Timeout on EAPOL-TX from P2P Client")
839 msg = ev.split(' ')[2]
840 if msg[46:56] == "102200010f":
841 logger.info("Drop WSC_Done")
842 dev[0].request("SET ext_eapol_frame_io 0")
843 dev[1].request("SET ext_eapol_frame_io 0")
844 # Fake EAP-Failure to complete session on the client
846 dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
848 res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
850 raise Exception("EAPOL_RX failed")
852 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
854 raise Exception("Group formation timed out on GO")
855 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
857 raise Exception("Group formation timed out on P2P Client")
858 dev[0].remove_group()
859 dev[1].wait_go_ending_session()
861 if mode != "P2P GO - group formation":
862 raise Exception("Unexpected mode on GO during group formation: " + mode)
864 def test_grpform_wait_peer(dev):
865 """P2P group formation wait for peer to become ready"""
866 addr0 = dev[0].p2p_dev_addr()
867 addr1 = dev[1].p2p_dev_addr()
869 if not dev[0].discover_peer(addr1):
870 raise Exception("Peer " + addr1 + " not found")
871 dev[0].request("SET extra_roc_dur 500")
872 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
873 raise Exception("Failed to initiate GO Neg")
875 dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
877 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
879 raise Exception("Group formation timed out")
880 dev[0].group_form_result(ev)
882 dev[0].request("SET extra_roc_dur 0")
883 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
885 raise Exception("Group formation timed out")
886 dev[0].remove_group()
888 def test_invalid_p2p_connect_command(dev):
889 """P2P_CONNECT error cases"""
890 id = dev[0].add_network()
893 "00:11:22:33:44:55 pbc persistent=123",
894 "00:11:22:33:44:55 pbc persistent=%d" % id,
895 "00:11:22:33:44:55 pbc go_intent=-1",
896 "00:11:22:33:44:55 pbc go_intent=16",
897 "00:11:22:33:44:55 pin",
898 "00:11:22:33:44:55 pbc freq=0" ]:
899 if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
900 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
902 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
903 raise Exception("Invalid PIN was not rejected")
905 if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
906 raise Exception("Unsupported channel not reported")
908 def test_p2p_unauthorize(dev):
909 """P2P_UNAUTHORIZE to unauthorize a peer"""
910 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
911 raise Exception("Invalid P2P_UNAUTHORIZE accepted")
912 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
913 raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
915 addr0 = dev[0].p2p_dev_addr()
916 addr1 = dev[1].p2p_dev_addr()
918 pin = dev[0].wps_read_pin()
919 dev[0].p2p_go_neg_auth(addr1, pin, "display")
921 if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
922 raise Exception("P2P_UNAUTHORIZE failed")
923 dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
924 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
926 raise Exception("No GO Negotiation Request RX reported")
928 def test_grpform_pbc_multiple(dev):
929 """P2P group formation using PBC multiple times in a row"""
931 dev[1].request("SET passive_scan 1")
933 [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
934 r_dev=dev[1], r_intent=0)
935 remove_group(dev[0], dev[1])
937 dev[1].request("SET passive_scan 0")
938 dev[1].flush_scan_cache()
940 def test_grpform_not_ready(dev):
941 """Not ready for GO Negotiation (listen)"""
942 addr0 = dev[0].p2p_dev_addr()
943 addr2 = dev[2].p2p_dev_addr()
945 if not dev[1].discover_peer(addr0):
946 raise Exception("Could not discover peer")
947 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
948 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
950 raise Exception("No P2P-GO-NEG-REQUEST event")
951 dev[0].dump_monitor()
953 if not dev[2].discover_peer(addr0):
954 raise Exception("Could not discover peer(2)")
956 dev[i].p2p_stop_find()
958 def test_grpform_not_ready2(dev):
959 """Not ready for GO Negotiation (search)"""
960 addr0 = dev[0].p2p_dev_addr()
961 addr2 = dev[2].p2p_dev_addr()
962 dev[0].p2p_find(social=True)
963 if not dev[1].discover_peer(addr0):
964 raise Exception("Could not discover peer")
965 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
966 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
968 raise Exception("No P2P-GO-NEG-REQUEST event")
969 dev[0].dump_monitor()
972 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
974 raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
976 raise Exception("Unexpected peer discovered: " + ev)
978 dev[i].p2p_stop_find()