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_grpform4(dev):
263 """P2P group formation response during p2p_find"""
264 addr1 = dev[1].p2p_dev_addr()
266 dev[0].discover_peer(addr1)
267 dev[1].p2p_find(social=True)
269 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display")
270 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
272 raise Exception("GO Negotiation RX timed out")
274 dev[1].p2p_stop_find()
275 dev[0].p2p_stop_find()
277 def test_grpform_pbc(dev):
278 """P2P group formation using PBC and re-init GO Negotiation"""
279 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
280 check_grpform_results(i_res, r_res)
281 if i_res['role'] != 'GO' or r_res['role'] != 'client':
282 raise Exception("Unexpected device roles")
283 remove_group(dev[0], dev[1])
285 def test_grpform_pd(dev):
286 """P2P group formation with PD-before-GO-Neg workaround"""
287 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
288 check_grpform_results(i_res, r_res)
289 remove_group(dev[0], dev[1])
291 def test_grpform_ext_listen(dev):
292 """P2P group formation with extended listen timing enabled"""
293 addr0 = dev[0].p2p_dev_addr()
295 if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
296 raise Exception("Invalid P2P_EXT_LISTEN accepted")
297 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 300 1000"):
298 raise Exception("Failed to set extended listen timing")
299 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
300 raise Exception("Failed to set extended listen timing")
301 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1],
302 r_listen=True, i_freq="2417", r_freq="2417",
303 i_intent=1, r_intent=15)
304 check_grpform_results(i_res, r_res)
305 peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
306 if peer1['ext_listen_interval'] != "40000":
307 raise Exception("Extended listen interval not discovered correctly")
308 if peer1['ext_listen_period'] != "200":
309 raise Exception("Extended listen period not discovered correctly")
310 peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
311 if peer0['ext_listen_interval'] != "1000":
312 raise Exception("Extended listen interval not discovered correctly")
313 if peer0['ext_listen_period'] != "300":
314 raise Exception("Extended listen period not discovered correctly")
315 if not dev[2].discover_peer(addr0):
316 raise Exception("Could not discover peer during ext listen")
317 remove_group(dev[0], dev[1])
319 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
320 raise Exception("Failed to clear extended listen timing")
321 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
322 raise Exception("Failed to clear extended listen timing")
324 def test_grpform_ext_listen_oper(dev):
325 """P2P extended listen timing operations"""
327 _test_grpform_ext_listen_oper(dev)
329 dev[0].global_request("P2P_EXT_LISTEN")
331 def _test_grpform_ext_listen_oper(dev):
332 addr0 = dev[0].p2p_dev_addr()
333 dev[0].global_request("SET p2p_no_group_iface 0")
334 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
335 wpas.interface_add("wlan5")
336 addr1 = wpas.p2p_dev_addr()
337 wpas.request("P2P_SET listen_channel 1")
338 wpas.global_request("SET p2p_no_group_iface 0")
339 wpas.request("P2P_LISTEN")
340 if not dev[0].discover_peer(addr1):
341 raise Exception("Could not discover peer")
342 dev[0].request("P2P_LISTEN")
343 if not wpas.discover_peer(addr0):
344 raise Exception("Could not discover peer (2)")
346 dev[0].global_request("P2P_EXT_LISTEN 300 500")
347 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display auth go_intent=0 freq=2417")
348 wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=15 freq=2417")
349 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
351 raise Exception("GO Negotiation failed")
352 ifaces = wpas.request("INTERFACES").splitlines()
353 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
354 wpas.group_ifname = iface
355 if "OK" not in wpas.group_request("STOP_AP"):
356 raise Exception("STOP_AP failed")
357 wpas.group_request("SET ext_mgmt_frame_handling 1")
358 dev[1].p2p_find(social=True)
360 if dev[1].peer_known(addr0):
361 raise Exception("Unexpected peer discovery")
362 ifaces = dev[0].request("INTERFACES").splitlines()
363 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
364 if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE " + iface):
365 raise Exception("Failed to request group removal")
371 while count < timeout * 4:
374 if dev[1].peer_known(addr0):
377 dev[1].p2p_stop_find()
379 raise Exception("Could not discover peer that was supposed to use extended listen")
381 def test_both_go_intent_15(dev):
382 """P2P GO Negotiation with both devices using GO intent 15"""
383 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)
385 def test_both_go_neg_display(dev):
386 """P2P GO Negotiation with both devices trying to display PIN"""
387 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')
389 def test_both_go_neg_enter(dev):
390 """P2P GO Negotiation with both devices trying to enter PIN"""
391 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')
393 def test_go_neg_pbc_vs_pin(dev):
394 """P2P GO Negotiation with one device using PBC and the other PIN"""
395 addr0 = dev[0].p2p_dev_addr()
396 addr1 = dev[1].p2p_dev_addr()
398 if not dev[0].discover_peer(addr1):
399 raise Exception("Could not discover peer")
401 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
402 raise Exception("Failed to authorize GO Neg")
403 if not dev[1].discover_peer(addr0):
404 raise Exception("Could not discover peer")
405 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
406 raise Exception("Failed to initiate GO Neg")
407 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
409 raise Exception("GO Negotiation failure timed out")
410 if "status=10" not in ev:
411 raise Exception("Unexpected failure reason: " + ev)
413 def test_go_neg_pin_vs_pbc(dev):
414 """P2P GO Negotiation with one device using PIN and the other PBC"""
415 addr0 = dev[0].p2p_dev_addr()
416 addr1 = dev[1].p2p_dev_addr()
418 if not dev[0].discover_peer(addr1):
419 raise Exception("Could not discover peer")
421 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
422 raise Exception("Failed to authorize GO Neg")
423 if not dev[1].discover_peer(addr0):
424 raise Exception("Could not discover peer")
425 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
426 raise Exception("Failed to initiate GO Neg")
427 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
429 raise Exception("GO Negotiation failure timed out")
430 if "status=10" not in ev:
431 raise Exception("Unexpected failure reason: " + ev)
433 def test_grpform_per_sta_psk(dev):
434 """P2P group formation with per-STA PSKs"""
435 dev[0].global_request("P2P_SET per_sta_psk 1")
436 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
437 check_grpform_results(i_res, r_res)
439 pin = dev[2].wps_read_pin()
440 dev[0].p2p_go_authorize_client(pin)
441 c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
442 check_grpform_results(i_res, c_res)
444 if r_res['psk'] == c_res['psk']:
445 raise Exception("Same PSK assigned for both clients")
447 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
449 dev[0].remove_group()
450 dev[1].wait_go_ending_session()
451 dev[2].wait_go_ending_session()
453 def test_grpform_per_sta_psk_wps(dev):
454 """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
455 dev[0].global_request("P2P_SET per_sta_psk 1")
456 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
457 check_grpform_results(i_res, r_res)
459 dev[0].p2p_go_authorize_client_pbc()
460 dev[2].request("WPS_PBC")
461 dev[2].wait_connected(timeout=30)
463 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
465 dev[0].remove_group()
466 dev[2].request("DISCONNECT")
467 dev[1].wait_go_ending_session()
469 def test_grpform_force_chan_go(dev):
470 """P2P group formation forced channel selection by GO"""
471 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
473 r_dev=dev[1], r_intent=0,
475 check_grpform_results(i_res, r_res)
476 if i_res['freq'] != "2432":
477 raise Exception("Unexpected channel - did not follow GO's forced channel")
478 remove_group(dev[0], dev[1])
480 def test_grpform_force_chan_cli(dev):
481 """P2P group formation forced channel selection by client"""
482 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
484 r_dev=dev[1], r_intent=15,
486 check_grpform_results(i_res, r_res)
487 if i_res['freq'] != "2417":
488 raise Exception("Unexpected channel - did not follow GO's forced channel")
489 remove_group(dev[0], dev[1])
491 def test_grpform_force_chan_conflict(dev):
492 """P2P group formation fails due to forced channel mismatch"""
493 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
494 r_dev=dev[1], r_intent=15, r_freq=2427,
495 expect_failure=True, i_go_neg_status=7)
497 def test_grpform_pref_chan_go(dev):
498 """P2P group formation preferred channel selection by GO"""
499 dev[0].request("SET p2p_pref_chan 81:7")
500 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
501 r_dev=dev[1], r_intent=0,
503 check_grpform_results(i_res, r_res)
504 if i_res['freq'] != "2442":
505 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
506 remove_group(dev[0], dev[1])
508 def test_grpform_pref_chan_go_overridden(dev):
509 """P2P group formation preferred channel selection by GO overridden by client"""
510 dev[1].request("SET p2p_pref_chan 81:7")
511 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
513 r_dev=dev[1], r_intent=15,
515 check_grpform_results(i_res, r_res)
516 if i_res['freq'] != "2422":
517 raise Exception("Unexpected channel - did not follow client's forced channel")
518 remove_group(dev[0], dev[1])
520 def test_grpform_no_go_freq_forcing_chan(dev):
521 """P2P group formation with no-GO freq forcing channel"""
522 dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
523 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
524 r_dev=dev[1], r_intent=15,
526 check_grpform_results(i_res, r_res)
527 if int(i_res['freq']) > 4000:
528 raise Exception("Unexpected channel - did not follow no-GO freq")
529 remove_group(dev[0], dev[1])
531 def test_grpform_no_go_freq_conflict(dev):
532 """P2P group formation fails due to no-GO range forced by client"""
533 dev[1].request("SET p2p_no_go_freq 2000-3000")
534 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
535 r_dev=dev[1], r_intent=15,
536 expect_failure=True, i_go_neg_status=7)
538 def test_grpform_no_5ghz_world_roaming(dev):
539 """P2P group formation with world roaming regulatory"""
540 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
541 r_dev=dev[1], r_intent=15,
543 check_grpform_results(i_res, r_res)
544 if int(i_res['freq']) > 4000:
545 raise Exception("Unexpected channel - did not follow world roaming rules")
546 remove_group(dev[0], dev[1])
548 def test_grpform_no_5ghz_add_cli(dev):
549 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
550 dev[0].request("SET p2p_add_cli_chan 1")
551 dev[1].request("SET p2p_add_cli_chan 1")
552 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
553 r_dev=dev[1], r_intent=14,
555 check_grpform_results(i_res, r_res)
556 if int(i_res['freq']) > 4000:
557 raise Exception("Unexpected channel - did not follow world roaming rules")
558 remove_group(dev[0], dev[1])
560 def test_grpform_no_5ghz_add_cli2(dev):
561 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
562 dev[0].request("SET p2p_add_cli_chan 1")
563 dev[1].request("SET p2p_add_cli_chan 1")
564 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
565 r_dev=dev[1], r_intent=0,
567 check_grpform_results(i_res, r_res)
568 if int(i_res['freq']) > 4000:
569 raise Exception("Unexpected channel - did not follow world roaming rules")
570 remove_group(dev[0], dev[1])
572 def test_grpform_no_5ghz_add_cli3(dev):
573 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
574 dev[0].request("SET p2p_add_cli_chan 1")
575 dev[1].request("SET p2p_add_cli_chan 1")
576 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
577 r_dev=dev[1], r_intent=15,
579 check_grpform_results(i_res, r_res)
580 if int(i_res['freq']) > 4000:
581 raise Exception("Unexpected channel - did not follow world roaming rules")
582 remove_group(dev[0], dev[1])
584 def test_grpform_no_5ghz_add_cli4(dev):
585 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
586 dev[0].request("SET p2p_add_cli_chan 1")
587 dev[1].request("SET p2p_add_cli_chan 1")
588 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
589 r_dev=dev[1], r_intent=0,
591 check_grpform_results(i_res, r_res)
592 if int(i_res['freq']) > 4000:
593 raise Exception("Unexpected channel - did not follow world roaming rules")
594 remove_group(dev[0], dev[1])
596 def test_grpform_incorrect_pin(dev):
597 """P2P GO Negotiation with incorrect PIN"""
599 addr1 = dev[1].p2p_dev_addr()
600 if not dev[0].discover_peer(addr1):
601 raise Exception("Peer not found")
602 res = dev[1].global_request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
604 raise Exception("P2P_CONNECT failed to generate PIN")
605 logger.info("PIN from P2P_CONNECT: " + res)
606 dev[0].global_request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
607 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
609 raise Exception("GO Negotiation did not complete successfully(0)")
610 ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
612 raise Exception("GO Negotiation did not complete successfully(1)")
613 ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=15)
615 raise Exception("WPS failure not reported(1)")
616 if "msg=8 config_error=18" not in ev:
617 raise Exception("Unexpected WPS failure(1): " + ev)
618 ev = dev[0].wait_global_event(["WPS-FAIL"], timeout=15)
620 raise Exception("WPS failure not reported")
621 if "msg=8 config_error=18" not in ev:
622 raise Exception("Unexpected WPS failure: " + ev)
623 ev = dev[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
625 raise Exception("Group formation failure timed out")
626 ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
628 raise Exception("Group formation failure timed out")
630 def test_grpform_reject(dev):
631 """User rejecting group formation attempt by a P2P peer"""
632 addr0 = dev[0].p2p_dev_addr()
634 dev[1].p2p_go_neg_init(addr0, None, "pbc")
635 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
637 raise Exception("GO Negotiation timed out")
638 if "OK" in dev[0].global_request("P2P_REJECT foo"):
639 raise Exception("Invalid P2P_REJECT accepted")
640 if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
641 raise Exception("P2P_REJECT failed")
642 dev[1].request("P2P_STOP_FIND")
643 dev[1].p2p_go_neg_init(addr0, None, "pbc")
644 ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
646 raise Exception("Rejection not reported")
647 if "status=11" not in ev:
648 raise Exception("Unexpected status code in rejection")
650 def test_grpform_pd_no_probe_resp(dev):
651 """GO Negotiation after PD, but no Probe Response"""
652 addr0 = dev[0].p2p_dev_addr()
653 addr1 = dev[1].p2p_dev_addr()
655 if not dev[1].discover_peer(addr0):
656 raise Exception("Peer not found")
657 dev[1].p2p_stop_find()
658 dev[0].p2p_stop_find()
659 peer = dev[0].get_peer(addr1)
660 if peer['listen_freq'] == '0':
661 raise Exception("Peer listen frequency not learned from Probe Request")
663 dev[0].request("P2P_FLUSH")
665 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
666 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
668 raise Exception("PD Request timed out")
669 ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
671 raise Exception("PD Response timed out")
672 peer = dev[0].get_peer(addr1)
673 if peer['listen_freq'] != '0':
674 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
676 pin = dev[0].wps_read_pin()
677 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
678 raise Exception("P2P_CONNECT on initiator failed")
679 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
681 raise Exception("GO Negotiation start timed out")
682 peer = dev[0].get_peer(addr1)
683 if peer['listen_freq'] == '0':
684 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
685 if "FAIL" in dev[0].global_request("P2P_CONNECT " + addr1 + " " + pin + " display"):
686 raise Exception("P2P_CONNECT on responder failed")
687 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
689 raise Exception("Group formation timed out")
690 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
692 raise Exception("Group formation timed out")
694 def test_go_neg_two_peers(dev):
695 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
696 addr0 = dev[0].p2p_dev_addr()
697 addr1 = dev[1].p2p_dev_addr()
698 addr2 = dev[2].p2p_dev_addr()
701 if not dev[0].discover_peer(addr1):
702 raise Exception("Could not discover peer")
703 if not dev[0].discover_peer(addr2):
704 raise Exception("Could not discover peer")
705 if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
706 raise Exception("Failed to authorize GO Neg")
708 if not dev[2].discover_peer(addr0):
709 raise Exception("Could not discover peer")
710 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
711 raise Exception("Failed to initiate GO Neg")
712 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
714 raise Exception("timeout on GO Neg RX event")
715 dev[2].request("P2P_CONNECT " + addr0 + " pbc")
716 ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
718 raise Exception("Rejection not reported")
719 if "status=5" not in ev:
720 raise Exception("Unexpected status code in rejection: " + ev)
722 def clear_pbc_overlap(dev, ifname):
723 hapd_global = hostapd.HostapdGlobal()
724 hapd_global.remove(ifname)
725 dev[0].request("P2P_CANCEL")
726 dev[1].request("P2P_CANCEL")
727 dev[0].p2p_stop_find()
728 dev[1].p2p_stop_find()
729 dev[0].dump_monitor()
730 dev[1].dump_monitor()
732 dev[0].flush_scan_cache()
733 dev[1].flush_scan_cache()
736 def test_grpform_pbc_overlap(dev, apdev):
737 """P2P group formation during PBC overlap"""
738 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
739 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
740 hapd.request("WPS_PBC")
743 # Since P2P Client scan case is now optimzied to use a specific SSID, the
744 # WPS AP will not reply to that and the scan after GO Negotiation can quite
745 # likely miss the AP due to dwell time being short enoguh to miss the Beacon
746 # frame. This has made the test case somewhat pointless, but keep it here
747 # for now with an additional scan to confirm that PBC detection works if
748 # there is a BSS entry for a overlapping AP.
749 for i in range(0, 5):
750 dev[0].scan(freq="2412")
751 if dev[0].get_bss(apdev[0]['bssid']) is not None:
754 addr0 = dev[0].p2p_dev_addr()
755 addr1 = dev[1].p2p_dev_addr()
757 if not dev[1].discover_peer(addr0):
758 raise Exception("Could not discover peer")
760 if not dev[0].discover_peer(addr1):
761 raise Exception("Could not discover peer")
763 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
764 raise Exception("Failed to authorize GO Neg")
765 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
766 raise Exception("Failed to initiate GO Neg")
767 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
769 raise Exception("PBC overlap not reported")
771 clear_pbc_overlap(dev, apdev[0]['ifname'])
773 def test_grpform_pbc_overlap_group_iface(dev, apdev):
774 """P2P group formation during PBC overlap using group interfaces"""
775 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
776 # update use this information.
777 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
778 "beacon_int": "15", 'manage_p2p': '1' }
779 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
780 hapd.request("WPS_PBC")
782 dev[0].request("SET p2p_no_group_iface 0")
783 dev[1].request("SET p2p_no_group_iface 0")
785 addr0 = dev[0].p2p_dev_addr()
786 addr1 = dev[1].p2p_dev_addr()
788 if not dev[1].discover_peer(addr0):
789 raise Exception("Could not discover peer")
791 if not dev[0].discover_peer(addr1):
792 raise Exception("Could not discover peer")
793 dev[0].p2p_stop_find()
794 dev[0].scan(freq="2412")
796 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
797 raise Exception("Failed to authorize GO Neg")
798 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
799 raise Exception("Failed to initiate GO Neg")
800 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
801 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
802 if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
803 # Do not report this as failure since the P2P group formation case
804 # using a separate group interface has limited chances of "seeing" the
805 # overlapping AP due to a per-SSID scan and no prior scan operations on
806 # the group interface.
807 logger.info("PBC overlap not reported")
809 clear_pbc_overlap(dev, apdev[0]['ifname'])
811 def test_grpform_goneg_fail_with_group_iface(dev):
812 """P2P group formation fails while using group interface"""
813 dev[0].request("SET p2p_no_group_iface 0")
815 peer = dev[1].p2p_dev_addr()
816 if not dev[0].discover_peer(peer):
817 raise Exception("Peer " + peer + " not found")
818 if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
819 raise Exception("P2P_REJECT failed")
820 if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
821 raise Exception("P2P_CONNECT failed")
822 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
824 raise Exception("GO Negotiation failure timed out")
826 def test_grpform_cred_ready_timeout(dev, apdev, params):
827 """P2P GO Negotiation wait for credentials to become ready [long]"""
828 if not params['long']:
829 raise HwsimSkip("Skip test case with long duration due to --long not specified")
832 addr1 = dev[1].p2p_dev_addr()
833 if not dev[0].discover_peer(addr1):
834 raise Exception("Peer " + addr1 + " not found")
835 if not dev[2].discover_peer(addr1):
836 raise Exception("Peer " + addr1 + " not found(2)")
838 start = os.times()[4]
840 cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
841 if "OK" not in dev[0].global_request(cmd):
842 raise Exception("Failed to initiate GO Neg")
844 if "OK" not in dev[2].global_request(cmd):
845 raise Exception("Failed to initiate GO Neg(2)")
847 # First, check with p2p_find
848 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
850 raise Exception("Too early GO Negotiation timeout reported(2)")
851 dev[2].dump_monitor()
852 logger.info("Starting p2p_find to change state")
854 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
856 raise Exception("GO Negotiation failure timed out(2)")
857 dev[2].dump_monitor()
859 logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
860 if end - start < 120:
861 raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
863 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
864 wpas.interface_add("wlan5")
867 ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
869 raise Exception("Did not discover new device after GO Negotiation failure")
870 if wpas.p2p_dev_addr() not in ev:
871 raise Exception("Unexpected device found: " + ev)
872 dev[2].p2p_stop_find()
875 # Finally, verify without p2p_find
876 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
878 raise Exception("GO Negotiation failure timed out")
880 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
881 if end - start < 120:
882 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
884 def test_grpform_no_wsc_done(dev):
885 """P2P group formation with WSC-Done not sent"""
886 addr0 = dev[0].p2p_dev_addr()
887 addr1 = dev[1].p2p_dev_addr()
889 for i in range(0, 2):
890 dev[0].request("SET ext_eapol_frame_io 1")
891 dev[1].request("SET ext_eapol_frame_io 1")
893 dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
895 dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
896 go_intent=15, wait_group=False)
900 ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
902 raise Exception("Timeout on EAPOL-TX from GO")
904 mode = dev[0].get_status_field("mode")
905 res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
907 raise Exception("EAPOL_RX failed")
908 ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
910 raise Exception("Timeout on EAPOL-TX from P2P Client")
911 msg = ev.split(' ')[2]
912 if msg[46:56] == "102200010f":
913 logger.info("Drop WSC_Done")
914 dev[0].request("SET ext_eapol_frame_io 0")
915 dev[1].request("SET ext_eapol_frame_io 0")
916 # Fake EAP-Failure to complete session on the client
918 dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
920 res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
922 raise Exception("EAPOL_RX failed")
924 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
926 raise Exception("Group formation timed out on GO")
927 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
929 raise Exception("Group formation timed out on P2P Client")
930 dev[0].remove_group()
931 dev[1].wait_go_ending_session()
933 if mode != "P2P GO - group formation":
934 raise Exception("Unexpected mode on GO during group formation: " + mode)
936 def test_grpform_wait_peer(dev):
937 """P2P group formation wait for peer to become ready"""
938 addr0 = dev[0].p2p_dev_addr()
939 addr1 = dev[1].p2p_dev_addr()
941 if not dev[0].discover_peer(addr1):
942 raise Exception("Peer " + addr1 + " not found")
943 dev[0].request("SET extra_roc_dur 500")
944 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
945 raise Exception("Failed to initiate GO Neg")
947 dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
949 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
951 raise Exception("Group formation timed out")
952 dev[0].group_form_result(ev)
954 dev[0].request("SET extra_roc_dur 0")
955 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
957 raise Exception("Group formation timed out")
958 dev[0].remove_group()
960 def test_invalid_p2p_connect_command(dev):
961 """P2P_CONNECT error cases"""
962 id = dev[0].add_network()
965 "00:11:22:33:44:55 pbc persistent=123",
966 "00:11:22:33:44:55 pbc persistent=%d" % id,
967 "00:11:22:33:44:55 pbc go_intent=-1",
968 "00:11:22:33:44:55 pbc go_intent=16",
969 "00:11:22:33:44:55 pin",
970 "00:11:22:33:44:55 pbc freq=0" ]:
971 if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
972 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
974 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
975 raise Exception("Invalid PIN was not rejected")
976 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 12345678a"):
977 raise Exception("Invalid PIN was not rejected")
979 if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
980 raise Exception("Unsupported channel not reported")
982 def test_p2p_unauthorize(dev):
983 """P2P_UNAUTHORIZE to unauthorize a peer"""
984 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
985 raise Exception("Invalid P2P_UNAUTHORIZE accepted")
986 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
987 raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
989 addr0 = dev[0].p2p_dev_addr()
990 addr1 = dev[1].p2p_dev_addr()
992 pin = dev[0].wps_read_pin()
993 dev[0].p2p_go_neg_auth(addr1, pin, "display")
995 if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
996 raise Exception("P2P_UNAUTHORIZE failed")
997 dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
998 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1000 raise Exception("No GO Negotiation Request RX reported")
1002 def test_grpform_pbc_multiple(dev):
1003 """P2P group formation using PBC multiple times in a row"""
1005 dev[1].request("SET passive_scan 1")
1007 [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
1008 r_dev=dev[1], r_intent=0)
1009 remove_group(dev[0], dev[1])
1011 dev[1].request("SET passive_scan 0")
1012 dev[1].flush_scan_cache()
1014 def test_grpform_not_ready(dev):
1015 """Not ready for GO Negotiation (listen)"""
1016 addr0 = dev[0].p2p_dev_addr()
1017 addr2 = dev[2].p2p_dev_addr()
1019 if not dev[1].discover_peer(addr0):
1020 raise Exception("Could not discover peer")
1021 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
1022 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
1024 raise Exception("No P2P-GO-NEG-REQUEST event")
1025 dev[0].dump_monitor()
1027 if not dev[2].discover_peer(addr0):
1028 raise Exception("Could not discover peer(2)")
1030 dev[i].p2p_stop_find()
1032 def test_grpform_not_ready2(dev):
1033 """Not ready for GO Negotiation (search)"""
1034 addr0 = dev[0].p2p_dev_addr()
1035 addr2 = dev[2].p2p_dev_addr()
1036 dev[0].p2p_find(social=True)
1037 if not dev[1].discover_peer(addr0):
1038 raise Exception("Could not discover peer")
1039 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
1040 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
1042 raise Exception("No P2P-GO-NEG-REQUEST event")
1043 dev[0].dump_monitor()
1046 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
1048 raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
1050 raise Exception("Unexpected peer discovered: " + ev)
1052 dev[i].p2p_stop_find()