1 # P2P persistent group 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()
13 from test_p2p_autogo import connect_cli
15 def go_neg_pin_authorized_persistent(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display', test_data=True):
18 pin = r_dev.wps_read_pin()
19 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
20 r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method,
21 go_intent=r_intent, persistent=True)
23 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method,
24 timeout=20, go_intent=i_intent,
26 r_res = r_dev.p2p_go_neg_auth_result()
27 logger.debug("i_res: " + str(i_res))
28 logger.debug("r_res: " + str(r_res))
31 logger.info("Group formed")
33 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
36 def terminate_group(go, cli):
37 logger.info("Terminate persistent group")
39 cli.wait_go_ending_session()
41 def invite(inv, resp, extra=None, persistent_reconnect=True):
42 addr = resp.p2p_dev_addr()
43 if persistent_reconnect:
44 resp.global_request("SET persistent_reconnect 1")
46 resp.global_request("SET persistent_reconnect 0")
48 if not inv.discover_peer(addr, social=True):
49 raise Exception("Peer " + addr + " not found")
51 peer = inv.get_peer(addr)
52 cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr
54 cmd = cmd + " " + extra;
55 inv.global_request(cmd)
57 def check_result(go, cli):
58 ev = go.wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
60 raise Exception("Timeout on group re-invocation (on GO)")
61 if "[PERSISTENT]" not in ev:
62 raise Exception("Re-invoked group not marked persistent")
63 go_res = go.group_form_result(ev)
64 if go_res['role'] != 'GO':
65 raise Exception("Persistent group GO did not become GO")
66 if not go_res['persistent']:
67 raise Exception("Persistent group not re-invoked as persistent (GO)")
68 ev = cli.wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
70 raise Exception("Timeout on group re-invocation (on client)")
71 if "[PERSISTENT]" not in ev:
72 raise Exception("Re-invoked group not marked persistent")
73 cli_res = cli.group_form_result(ev)
74 if cli_res['role'] != 'client':
75 raise Exception("Persistent group client did not become client")
76 if not cli_res['persistent']:
77 raise Exception("Persistent group not re-invoked as persistent (cli)")
78 return [go_res, cli_res]
80 def form(go, cli, test_data=True, reverse_init=False):
81 logger.info("Form a persistent group")
83 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=cli, i_intent=0,
84 r_dev=go, r_intent=15,
87 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=go, i_intent=15,
88 r_dev=cli, r_intent=0,
90 if not i_res['persistent'] or not r_res['persistent']:
91 raise Exception("Formed group was not persistent")
92 terminate_group(go, cli)
98 def invite_from_cli(go, cli):
99 logger.info("Re-invoke persistent group from client")
101 [go_res, cli_res] = check_result(go, cli)
102 hwsim_utils.test_connectivity_p2p(go, cli)
103 terminate_group(go, cli)
104 return [go_res, cli_res]
106 def invite_from_go(go, cli):
107 logger.info("Re-invoke persistent group from GO")
109 [go_res, cli_res] = check_result(go, cli)
110 hwsim_utils.test_connectivity_p2p(go, cli)
111 terminate_group(go, cli)
112 return [go_res, cli_res]
114 def test_persistent_group(dev):
115 """P2P persistent group formation and re-invocation"""
117 invite_from_cli(dev[0], dev[1])
118 invite_from_go(dev[0], dev[1])
120 logger.info("Remove group on the client and try to invite from GO")
122 for n in dev[0].list_networks(p2p=True):
123 if "[P2P-PERSISTENT]" in n['flags']:
127 raise Exception("Could not find persistent group entry")
128 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
129 if dev[1].p2p_dev_addr() not in clients:
130 raise Exception("Peer missing from client list")
131 if "FAIL" not in dev[1].request("SELECT_NETWORK " + str(id)):
132 raise Exception("SELECT_NETWORK succeeded unexpectedly")
133 if "FAIL" not in dev[1].request("SELECT_NETWORK 1234567"):
134 raise Exception("SELECT_NETWORK succeeded unexpectedly(2)")
135 if "FAIL" not in dev[1].request("ENABLE_NETWORK " + str(id)):
136 raise Exception("ENABLE_NETWORK succeeded unexpectedly")
137 if "FAIL" not in dev[1].request("ENABLE_NETWORK 1234567"):
138 raise Exception("ENABLE_NETWORK succeeded unexpectedly(2)")
139 if "FAIL" not in dev[1].request("DISABLE_NETWORK " + str(id)):
140 raise Exception("DISABLE_NETWORK succeeded unexpectedly")
141 if "FAIL" not in dev[1].request("DISABLE_NETWORK 1234567"):
142 raise Exception("DISABLE_NETWORK succeeded unexpectedly(2)")
143 if "FAIL" not in dev[1].request("REMOVE_NETWORK 1234567"):
144 raise Exception("REMOVE_NETWORK succeeded unexpectedly")
145 dev[1].global_request("REMOVE_NETWORK all")
146 if len(dev[1].list_networks(p2p=True)) > 0:
147 raise Exception("Unexpected network block remaining")
148 invite(dev[0], dev[1])
149 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
151 raise Exception("No invitation result seen")
152 if "status=8" not in ev:
153 raise Exception("Unexpected invitation result: " + ev)
154 clients = dev[0].request("GET_NETWORK " + id + " p2p_client_list").rstrip()
155 if dev[1].p2p_dev_addr() in clients:
156 raise Exception("Peer was still in client list")
158 def test_persistent_group2(dev):
159 """P2P persistent group formation with reverse roles"""
160 form(dev[0], dev[1], reverse_init=True)
161 invite_from_cli(dev[0], dev[1])
162 invite_from_go(dev[0], dev[1])
164 def test_persistent_group3(dev):
165 """P2P persistent group formation and re-invocation with empty BSS table"""
167 dev[1].request("BSS_FLUSH 0")
168 invite_from_cli(dev[0], dev[1])
169 dev[1].request("BSS_FLUSH 0")
170 invite_from_go(dev[0], dev[1])
172 def test_persistent_group_per_sta_psk(dev):
173 """P2P persistent group formation and re-invocation using per-client PSK"""
174 addr0 = dev[0].p2p_dev_addr()
175 addr1 = dev[1].p2p_dev_addr()
176 addr2 = dev[2].p2p_dev_addr()
177 dev[0].global_request("P2P_SET per_sta_psk 1")
178 logger.info("Form a persistent group")
179 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
180 r_dev=dev[1], r_intent=0)
181 if not i_res['persistent'] or not r_res['persistent']:
182 raise Exception("Formed group was not persistent")
184 logger.info("Join another client to the group")
185 pin = dev[2].wps_read_pin()
186 dev[0].p2p_go_authorize_client(pin)
187 social = int(i_res['freq']) in [ 2412, 2437, 2462 ]
188 c_res = dev[2].p2p_connect_group(addr0, pin, timeout=60, social=social,
190 if not c_res['persistent']:
191 raise Exception("Joining client did not recognize persistent group")
192 if r_res['psk'] == c_res['psk']:
193 raise Exception("Same PSK assigned for both clients")
194 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
196 logger.info("Remove persistent group and re-start it manually")
197 dev[0].remove_group()
198 dev[1].wait_go_ending_session()
199 dev[2].wait_go_ending_session()
200 dev[0].dump_monitor()
201 dev[1].dump_monitor()
202 dev[2].dump_monitor()
204 for i in range(0, 3):
205 networks = dev[i].list_networks(p2p=True)
206 if len(networks) != 1:
207 raise Exception("Unexpected number of networks")
208 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
209 raise Exception("Not the persistent group data")
211 # speed up testing by avoiding use of the old BSS entry since the
212 # GO may have changed channels
213 dev[i].request("BSS_FLUSH 0")
214 dev[i].scan(freq="2412", only_new=True)
215 if "OK" not in dev[i].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=2412"):
216 raise Exception("Could not re-start persistent group")
217 ev = dev[i].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
219 raise Exception("Timeout on group restart")
220 dev[i].group_form_result(ev)
222 logger.info("Leave persistent group and rejoin it")
223 dev[2].remove_group()
224 ev = dev[2].wait_global_event(["P2P-GROUP-REMOVED"], timeout=3)
226 raise Exception("Group removal event timed out")
227 if not dev[2].discover_peer(addr0, social=True):
228 raise Exception("Peer " + peer + " not found")
229 dev[2].dump_monitor()
230 peer = dev[2].get_peer(addr0)
231 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
232 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
234 raise Exception("Timeout on group restart (on client)")
235 cli_res = dev[2].group_form_result(ev)
236 if not cli_res['persistent']:
237 raise Exception("Persistent group not restarted as persistent (cli)")
238 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
240 logger.info("Remove one of the clients from the group without removing persistent group information for the client")
241 dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
242 dev[2].wait_go_ending_session()
244 logger.info("Try to reconnect after having been removed from group (but persistent group info still present)")
245 if not dev[2].discover_peer(addr0, social=True):
246 raise Exception("Peer " + peer + " not found")
247 dev[2].dump_monitor()
248 peer = dev[2].get_peer(addr0)
249 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
250 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
252 raise Exception("Timeout on group restart (on client)")
253 if "P2P-GROUP-STARTED" not in ev:
254 raise Exception("Connection failed")
256 logger.info("Remove one of the clients from the group")
257 dev[0].global_request("P2P_REMOVE_CLIENT " + addr2)
258 dev[2].wait_go_ending_session()
260 logger.info("Try to reconnect after having been removed from group")
261 if not dev[2].discover_peer(addr0, social=True):
262 raise Exception("Peer " + peer + " not found")
263 dev[2].dump_monitor()
264 peer = dev[2].get_peer(addr0)
265 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
266 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
268 raise Exception("Timeout on group restart (on client)")
269 if "P2P-GROUP-STARTED" in ev:
270 raise Exception("Client managed to connect after being removed")
272 logger.info("Remove the remaining client from the group")
273 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
274 dev[1].wait_go_ending_session()
276 logger.info("Terminate persistent group")
277 dev[0].remove_group()
278 dev[0].dump_monitor()
280 logger.info("Try to re-invoke persistent group from client")
281 dev[0].global_request("SET persistent_reconnect 1")
283 if not dev[1].discover_peer(addr0, social=True):
284 raise Exception("Peer " + peer + " not found")
285 dev[1].dump_monitor()
286 peer = dev[1].get_peer(addr0)
287 dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
288 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
289 dev[0].group_form_result(ev)
290 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
292 raise Exception("Timeout on group restart (on client)")
293 if "P2P-GROUP-STARTED" in ev:
294 raise Exception("Client managed to re-invoke after being removed")
295 dev[0].dump_monitor()
297 logger.info("Terminate persistent group")
298 dev[0].remove_group()
299 dev[0].dump_monitor()
301 def test_persistent_group_invite_removed_client(dev):
302 """P2P persistent group client removal and re-invitation"""
303 addr0 = dev[0].p2p_dev_addr()
304 addr1 = dev[1].p2p_dev_addr()
305 dev[0].request("P2P_SET per_sta_psk 1")
306 logger.info("Form a persistent group")
307 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
308 r_dev=dev[1], r_intent=0)
309 if not i_res['persistent'] or not r_res['persistent']:
310 raise Exception("Formed group was not persistent")
312 logger.info("Remove client from the group")
313 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
314 dev[1].wait_go_ending_session()
316 logger.info("Re-invite the removed client to join the group")
318 if not dev[0].discover_peer(addr1, social=True):
319 raise Exception("Peer " + peer + " not found")
320 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
321 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
323 raise Exception("Timeout on invitation")
324 if "sa=" + addr0 + " persistent=" not in ev:
325 raise Exception("Unexpected invitation event")
326 [event,addr,persistent] = ev.split(' ', 2)
327 dev[1].global_request("P2P_GROUP_ADD " + persistent)
328 ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30)
330 raise Exception("Did not receive PSK failure report")
331 [tmp,id] = ev.split('=', 1)
332 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
334 raise Exception("Group removal event timed out")
335 if "reason=PSK_FAILURE" not in ev:
336 raise Exception("Unexpected group removal reason")
337 dev[1].global_request("REMOVE_NETWORK " + id)
339 logger.info("Re-invite after client removed persistent group info")
341 if not dev[0].discover_peer(addr1, social=True):
342 raise Exception("Peer " + peer + " not found")
343 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
344 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
346 raise Exception("Timeout on invitation")
347 if " persistent=" in ev:
348 raise Exception("Unexpected invitation event")
349 pin = dev[1].wps_read_pin()
350 dev[0].p2p_go_authorize_client(pin)
351 c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True,
353 if not c_res['persistent']:
354 raise Exception("Joining client did not recognize persistent group")
355 if r_res['psk'] == c_res['psk']:
356 raise Exception("Same PSK assigned on both times")
357 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
359 terminate_group(dev[0], dev[1])
361 def test_persistent_group_channel(dev):
362 """P2P persistent group re-invocation with channel selection"""
363 form(dev[0], dev[1], test_data=False)
365 logger.info("Re-invoke persistent group from client with forced channel")
366 invite(dev[1], dev[0], "freq=2427")
367 [go_res, cli_res] = check_result(dev[0], dev[1])
368 if go_res['freq'] != "2427":
369 raise Exception("Persistent group client forced channel not followed")
370 terminate_group(dev[0], dev[1])
372 logger.info("Re-invoke persistent group from GO with forced channel")
373 invite(dev[0], dev[1], "freq=2432")
374 [go_res, cli_res] = check_result(dev[0], dev[1])
375 if go_res['freq'] != "2432":
376 raise Exception("Persistent group GO channel preference not followed")
377 terminate_group(dev[0], dev[1])
379 logger.info("Re-invoke persistent group from client with channel preference")
380 invite(dev[1], dev[0], "pref=2417")
381 [go_res, cli_res] = check_result(dev[0], dev[1])
382 if go_res['freq'] != "2417":
383 raise Exception("Persistent group client channel preference not followed")
384 terminate_group(dev[0], dev[1])
386 def test_persistent_group_and_role_change(dev):
387 """P2P persistent group, auto GO in another role, and re-invocation"""
390 logger.info("Start and stop autonomous GO on previous P2P client device")
391 dev[1].p2p_start_go()
392 dev[1].remove_group()
393 dev[1].dump_monitor()
395 logger.info("Re-invoke the persistent group")
396 invite_from_go(dev[0], dev[1])
398 def test_persistent_go_client_list(dev):
399 """P2P GO and list of clients in persistent group"""
400 addr0 = dev[0].p2p_dev_addr()
401 addr1 = dev[1].p2p_dev_addr()
402 addr2 = dev[2].p2p_dev_addr()
404 res = dev[0].p2p_start_go(persistent=True)
406 for n in dev[0].list_networks(p2p=True):
407 if "[P2P-PERSISTENT]" in n['flags']:
411 raise Exception("Could not find persistent group entry")
413 connect_cli(dev[0], dev[1], social=True, freq=res['freq'])
414 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
416 raise Exception("Unexpected p2p_client_list entry(2): " + clients)
417 connect_cli(dev[0], dev[2], social=True, freq=res['freq'])
418 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
419 if clients != addr2 + " " + addr1:
420 raise Exception("Unexpected p2p_client_list entry(3): " + clients)
422 peer = dev[1].get_peer(res['go_dev_addr'])
423 dev[1].remove_group()
424 dev[1].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'])
425 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
427 raise Exception("Timeout on group restart (on client)")
428 dev[1].group_form_result(ev)
429 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
430 if clients != addr1 + " " + addr2:
431 raise Exception("Unexpected p2p_client_list entry(4): " + clients)
433 dev[2].remove_group()
434 dev[1].remove_group()
435 dev[0].remove_group()
437 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
438 if clients != addr1 + " " + addr2:
439 raise Exception("Unexpected p2p_client_list entry(5): " + clients)
443 dev[0].request("P2P_FLUSH")
444 dev[0].discover_peer(addr1, social=True)
445 peer = dev[0].get_peer(addr1)
446 if 'persistent' not in peer or peer['persistent'] != id:
447 raise Exception("Persistent group client not recognized(1)")
449 dev[0].discover_peer(addr2, social=True)
450 peer = dev[0].get_peer(addr2)
451 if 'persistent' not in peer or peer['persistent'] != id:
452 raise Exception("Persistent group client not recognized(2)")
454 def test_persistent_group_in_grpform(dev):
455 """P2P persistent group parameters re-used in group formation"""
456 addr0 = dev[0].p2p_dev_addr()
457 addr1 = dev[1].p2p_dev_addr()
460 if not dev[0].discover_peer(addr1, social=True):
461 raise Exception("Could not discover peer")
462 peer = dev[0].get_peer(addr1)
463 if "persistent" not in peer:
464 raise Exception("Could not map peer to a persistent group")
466 pin = dev[1].wps_read_pin()
467 dev[1].p2p_go_neg_auth(addr0, pin, "display", go_intent=0)
468 i_res = dev[0].p2p_go_neg_init(addr1, pin, "enter", timeout=20,
470 persistent_id=peer['persistent'])
471 r_res = dev[1].p2p_go_neg_auth_result()
472 logger.debug("i_res: " + str(i_res))
473 logger.debug("r_res: " + str(r_res))
475 def test_persistent_group_without_persistent_reconnect(dev):
476 """P2P persistent group re-invocation without persistent reconnect"""
478 dev[0].dump_monitor()
479 dev[1].dump_monitor()
481 logger.info("Re-invoke persistent group from client")
482 invite(dev[1], dev[0], persistent_reconnect=False)
484 ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
486 raise Exception("No invitation request reported");
487 if "persistent=" not in ev:
488 raise Exception("Invalid invitation type reported: " + ev)
490 ev2 = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
492 raise Exception("No invitation response reported");
493 if "status=1" not in ev2:
494 raise Exception("Unexpected status: " + ev2)
497 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*) freq=([0-9]*)'
498 s = re.split(exp, ev)
500 raise Exception("Could not parse invitation event")
504 logger.info("Invalid P2P_INVITE test coverage")
505 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=0"):
506 raise Exception("Invalid P2P_INVITE accepted")
507 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " pref=0"):
508 raise Exception("Invalid P2P_INVITE accepted")
509 logger.info("Re-initiate invitation based on upper layer acceptance")
510 if "OK" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
511 raise Exception("Invitation command failed")
512 [go_res, cli_res] = check_result(dev[0], dev[1])
513 if go_res['freq'] != freq:
514 raise Exception("Unexpected channel on GO: {} MHz, expected {} MHz".format(go_res['freq'], freq))
515 if cli_res['freq'] != freq:
516 raise Exception("Unexpected channel on CLI: {} MHz, expected {} MHz".format(cli_res['freq'], freq))
517 terminate_group(dev[0], dev[1])
518 dev[0].dump_monitor()
519 dev[1].dump_monitor()
521 logger.info("Re-invoke persistent group from GO")
522 invite(dev[0], dev[1], persistent_reconnect=False)
524 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
526 raise Exception("No invitation request reported");
527 if "persistent=" not in ev:
528 raise Exception("Invalid invitation type reported: " + ev)
530 ev2 = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
532 raise Exception("No invitation response reported");
533 if "status=1" not in ev2:
534 raise Exception("Unexpected status: " + ev2)
537 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*)'
538 s = re.split(exp, ev)
540 raise Exception("Could not parse invitation event")
543 logger.info("Re-initiate invitation based on upper layer acceptance")
544 if "OK" not in dev[1].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
545 raise Exception("Invitation command failed")
546 [go_res, cli_res] = check_result(dev[0], dev[1])
547 terminate_group(dev[0], dev[1])
549 def test_persistent_group_already_running(dev):
550 """P2P persistent group formation and invitation while GO already running"""
552 peer = dev[1].get_peer(dev[0].p2p_dev_addr())
553 listen_freq = peer['listen_freq']
554 dev[0].dump_monitor()
555 dev[1].dump_monitor()
556 networks = dev[0].list_networks(p2p=True)
557 if len(networks) != 1:
558 raise Exception("Unexpected number of networks")
559 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
560 raise Exception("Not the persistent group data")
561 if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
562 raise Exception("Could not state GO")
563 invite_from_cli(dev[0], dev[1])
565 def test_persistent_group_add_cli_chan(dev):
566 """P2P persistent group formation and re-invocation with p2p_add_cli_chan=1"""
567 dev[0].request("SET p2p_add_cli_chan 1")
568 dev[1].request("SET p2p_add_cli_chan 1")
570 dev[1].request("BSS_FLUSH 0")
571 dev[1].scan(freq="2412", only_new=True)
572 dev[1].scan(freq="2437", only_new=True)
573 dev[1].scan(freq="2462", only_new=True)
574 dev[1].request("BSS_FLUSH 0")
575 invite_from_cli(dev[0], dev[1])
576 invite_from_go(dev[0], dev[1])
578 def test_persistent_invalid_group_add(dev):
579 """Invalid P2P_GROUP_ADD command"""
580 id = dev[0].add_network()
581 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=12345"):
582 raise Exception("Invalid P2P_GROUP_ADD accepted")
583 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=%d" % id):
584 raise Exception("Invalid P2P_GROUP_ADD accepted")
585 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD foo"):
586 raise Exception("Invalid P2P_GROUP_ADD accepted")
588 def test_persistent_group_missed_inv_resp(dev):
589 """P2P persistent group re-invocation with invitation response getting lost"""
591 addr = dev[1].p2p_dev_addr()
592 dev[1].global_request("SET persistent_reconnect 1")
594 if not dev[0].discover_peer(addr, social=True):
595 raise Exception("Peer " + addr + " not found")
596 dev[0].dump_monitor()
597 peer = dev[0].get_peer(addr)
598 # Drop the first Invitation Response frame
599 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
600 raise Exception("Failed to enable external management frame handling")
601 cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr
602 dev[0].global_request(cmd)
603 rx_msg = dev[0].mgmt_rx()
605 raise Exception("MGMT-RX timeout (no Invitation Response)")
607 # Allow following Invitation Response frame to go through
608 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
609 raise Exception("Failed to disable external management frame handling")
611 # Force the P2P Client side to be on its Listen channel for retry
613 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
615 raise Exception("Invitation result timed out")
616 # Allow P2P Client side to continue connection-to-GO attempts
617 dev[1].p2p_stop_find()
619 # Verify that group re-invocation goes through
620 ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED",
621 "P2P-GROUP-FORMATION-FAILURE" ],
624 raise Exception("Group start event timed out")
625 if "P2P-GROUP-STARTED" not in ev:
626 raise Exception("Group re-invocation failed")
627 dev[0].group_form_result(ev)
629 ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED" ], timeout=5)
631 raise Exception("Group start event timed out on GO")
632 dev[0].group_form_result(ev)
634 terminate_group(dev[0], dev[1])
636 def test_persistent_group_profile_add(dev):
637 """Create a P2P persistent group with ADD_NETWORK"""
638 passphrase="passphrase here"
639 id = dev[0].add_network()
640 dev[0].set_network_quoted(id, "ssid", "DIRECT-ab")
641 dev[0].set_network_quoted(id, "psk", passphrase)
642 dev[0].set_network(id, "mode", "3")
643 dev[0].set_network(id, "disabled", "2")
644 dev[0].p2p_start_go(persistent=id, freq=2412)
646 pin = dev[1].wps_read_pin()
647 dev[0].p2p_go_authorize_client(pin)
648 res = dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
649 social=True, freq=2412)
650 if res['result'] != 'success':
651 raise Exception("Joining the group did not succeed")
653 dev[0].remove_group()
654 dev[1].wait_go_ending_session()