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].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 c_res = dev[2].p2p_connect_group(addr0, pin, timeout=60, social=True,
189 if not c_res['persistent']:
190 raise Exception("Joining client did not recognize persistent group")
191 if r_res['psk'] == c_res['psk']:
192 raise Exception("Same PSK assigned for both clients")
193 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
195 logger.info("Remove persistent group and re-start it manually")
196 dev[0].remove_group()
197 dev[1].wait_go_ending_session()
198 dev[2].wait_go_ending_session()
199 dev[0].dump_monitor()
200 dev[1].dump_monitor()
201 dev[2].dump_monitor()
203 for i in range(0, 3):
204 networks = dev[i].list_networks(p2p=True)
205 if len(networks) != 1:
206 raise Exception("Unexpected number of networks")
207 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
208 raise Exception("Not the persistent group data")
210 # speed up testing by avoiding use of the old BSS entry since the
211 # GO may have changed channels
212 dev[i].request("BSS_FLUSH 0")
213 dev[i].scan(freq="2412", only_new=True)
214 if "OK" not in dev[i].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=2412"):
215 raise Exception("Could not re-start persistent group")
216 ev = dev[i].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
218 raise Exception("Timeout on group restart")
219 dev[i].group_form_result(ev)
221 logger.info("Leave persistent group and rejoin it")
222 dev[2].remove_group()
223 ev = dev[2].wait_global_event(["P2P-GROUP-REMOVED"], timeout=3)
225 raise Exception("Group removal event timed out")
226 if not dev[2].discover_peer(addr0, social=True):
227 raise Exception("Peer " + peer + " not found")
228 dev[2].dump_monitor()
229 peer = dev[2].get_peer(addr0)
230 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
231 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
233 raise Exception("Timeout on group restart (on client)")
234 cli_res = dev[2].group_form_result(ev)
235 if not cli_res['persistent']:
236 raise Exception("Persistent group not restarted as persistent (cli)")
237 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
239 logger.info("Remove one of the clients from the group without removing persistent group information for the client")
240 dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
241 dev[2].wait_go_ending_session()
243 logger.info("Try to reconnect after having been removed from group (but persistent group info still present)")
244 if not dev[2].discover_peer(addr0, social=True):
245 raise Exception("Peer " + peer + " not found")
246 dev[2].dump_monitor()
247 peer = dev[2].get_peer(addr0)
248 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
249 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
251 raise Exception("Timeout on group restart (on client)")
252 if "P2P-GROUP-STARTED" not in ev:
253 raise Exception("Connection failed")
255 logger.info("Remove one of the clients from the group")
256 dev[0].global_request("P2P_REMOVE_CLIENT " + addr2)
257 dev[2].wait_go_ending_session()
259 logger.info("Try to reconnect after having been removed from group")
260 if not dev[2].discover_peer(addr0, social=True):
261 raise Exception("Peer " + peer + " not found")
262 dev[2].dump_monitor()
263 peer = dev[2].get_peer(addr0)
264 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
265 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
267 raise Exception("Timeout on group restart (on client)")
268 if "P2P-GROUP-STARTED" in ev:
269 raise Exception("Client managed to connect after being removed")
271 logger.info("Remove the remaining client from the group")
272 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
273 dev[1].wait_go_ending_session()
275 logger.info("Terminate persistent group")
276 dev[0].remove_group()
277 dev[0].dump_monitor()
279 logger.info("Try to re-invoke persistent group from client")
280 dev[0].global_request("SET persistent_reconnect 1")
282 if not dev[1].discover_peer(addr0, social=True):
283 raise Exception("Peer " + peer + " not found")
284 dev[1].dump_monitor()
285 peer = dev[1].get_peer(addr0)
286 dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
287 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
288 dev[0].group_form_result(ev)
289 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
291 raise Exception("Timeout on group restart (on client)")
292 if "P2P-GROUP-STARTED" in ev:
293 raise Exception("Client managed to re-invoke after being removed")
294 dev[0].dump_monitor()
296 logger.info("Terminate persistent group")
297 dev[0].remove_group()
298 dev[0].dump_monitor()
300 def test_persistent_group_invite_removed_client(dev):
301 """P2P persistent group client removal and re-invitation"""
302 addr0 = dev[0].p2p_dev_addr()
303 addr1 = dev[1].p2p_dev_addr()
304 dev[0].request("P2P_SET per_sta_psk 1")
305 logger.info("Form a persistent group")
306 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
307 r_dev=dev[1], r_intent=0)
308 if not i_res['persistent'] or not r_res['persistent']:
309 raise Exception("Formed group was not persistent")
311 logger.info("Remove client from the group")
312 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
313 dev[1].wait_go_ending_session()
315 logger.info("Re-invite the removed client to join the group")
317 if not dev[0].discover_peer(addr1, social=True):
318 raise Exception("Peer " + peer + " not found")
319 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
320 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
322 raise Exception("Timeout on invitation")
323 if "sa=" + addr0 + " persistent=" not in ev:
324 raise Exception("Unexpected invitation event")
325 [event,addr,persistent] = ev.split(' ', 2)
326 dev[1].global_request("P2P_GROUP_ADD " + persistent)
327 ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30)
329 raise Exception("Did not receive PSK failure report")
330 [tmp,id] = ev.split('=', 1)
331 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
333 raise Exception("Group removal event timed out")
334 if "reason=PSK_FAILURE" not in ev:
335 raise Exception("Unexpected group removal reason")
336 dev[1].global_request("REMOVE_NETWORK " + id)
338 logger.info("Re-invite after client removed persistent group info")
340 if not dev[0].discover_peer(addr1, social=True):
341 raise Exception("Peer " + peer + " not found")
342 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
343 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
345 raise Exception("Timeout on invitation")
346 if " persistent=" in ev:
347 raise Exception("Unexpected invitation event")
348 pin = dev[1].wps_read_pin()
349 dev[0].p2p_go_authorize_client(pin)
350 c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True,
352 if not c_res['persistent']:
353 raise Exception("Joining client did not recognize persistent group")
354 if r_res['psk'] == c_res['psk']:
355 raise Exception("Same PSK assigned on both times")
356 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
358 terminate_group(dev[0], dev[1])
360 def test_persistent_group_channel(dev):
361 """P2P persistent group re-invocation with channel selection"""
362 form(dev[0], dev[1], test_data=False)
364 logger.info("Re-invoke persistent group from client with forced channel")
365 invite(dev[1], dev[0], "freq=2427")
366 [go_res, cli_res] = check_result(dev[0], dev[1])
367 if go_res['freq'] != "2427":
368 raise Exception("Persistent group client forced channel not followed")
369 terminate_group(dev[0], dev[1])
371 logger.info("Re-invoke persistent group from GO with forced channel")
372 invite(dev[0], dev[1], "freq=2432")
373 [go_res, cli_res] = check_result(dev[0], dev[1])
374 if go_res['freq'] != "2432":
375 raise Exception("Persistent group GO channel preference not followed")
376 terminate_group(dev[0], dev[1])
378 logger.info("Re-invoke persistent group from client with channel preference")
379 invite(dev[1], dev[0], "pref=2417")
380 [go_res, cli_res] = check_result(dev[0], dev[1])
381 if go_res['freq'] != "2417":
382 raise Exception("Persistent group client channel preference not followed")
383 terminate_group(dev[0], dev[1])
385 def test_persistent_group_and_role_change(dev):
386 """P2P persistent group, auto GO in another role, and re-invocation"""
389 logger.info("Start and stop autonomous GO on previous P2P client device")
390 dev[1].p2p_start_go()
391 dev[1].remove_group()
392 dev[1].dump_monitor()
394 logger.info("Re-invoke the persistent group")
395 invite_from_go(dev[0], dev[1])
397 def test_persistent_go_client_list(dev):
398 """P2P GO and list of clients in persistent group"""
399 addr0 = dev[0].p2p_dev_addr()
400 addr1 = dev[1].p2p_dev_addr()
401 addr2 = dev[2].p2p_dev_addr()
403 res = dev[0].p2p_start_go(persistent=True)
405 for n in dev[0].list_networks(p2p=True):
406 if "[P2P-PERSISTENT]" in n['flags']:
410 raise Exception("Could not find persistent group entry")
412 connect_cli(dev[0], dev[1], social=True, freq=res['freq'])
413 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
415 raise Exception("Unexpected p2p_client_list entry(2): " + clients)
416 connect_cli(dev[0], dev[2], social=True, freq=res['freq'])
417 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
418 if clients != addr2 + " " + addr1:
419 raise Exception("Unexpected p2p_client_list entry(3): " + clients)
421 peer = dev[1].get_peer(res['go_dev_addr'])
422 dev[1].remove_group()
423 dev[1].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'])
424 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
426 raise Exception("Timeout on group restart (on client)")
427 dev[1].group_form_result(ev)
428 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
429 if clients != addr1 + " " + addr2:
430 raise Exception("Unexpected p2p_client_list entry(4): " + clients)
432 dev[2].remove_group()
433 dev[1].remove_group()
434 dev[0].remove_group()
436 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
437 if clients != addr1 + " " + addr2:
438 raise Exception("Unexpected p2p_client_list entry(5): " + clients)
442 dev[0].request("P2P_FLUSH")
443 dev[0].discover_peer(addr1, social=True)
444 peer = dev[0].get_peer(addr1)
445 if 'persistent' not in peer or peer['persistent'] != id:
446 raise Exception("Persistent group client not recognized(1)")
448 dev[0].discover_peer(addr2, social=True)
449 peer = dev[0].get_peer(addr2)
450 if 'persistent' not in peer or peer['persistent'] != id:
451 raise Exception("Persistent group client not recognized(2)")
453 def test_persistent_group_in_grpform(dev):
454 """P2P persistent group parameters re-used in group formation"""
455 addr0 = dev[0].p2p_dev_addr()
456 addr1 = dev[1].p2p_dev_addr()
459 if not dev[0].discover_peer(addr1, social=True):
460 raise Exception("Could not discover peer")
461 peer = dev[0].get_peer(addr1)
462 if "persistent" not in peer:
463 raise Exception("Could not map peer to a persistent group")
465 pin = dev[1].wps_read_pin()
466 dev[1].p2p_go_neg_auth(addr0, pin, "display", go_intent=0)
467 i_res = dev[0].p2p_go_neg_init(addr1, pin, "enter", timeout=20,
469 persistent_id=peer['persistent'])
470 r_res = dev[1].p2p_go_neg_auth_result()
471 logger.debug("i_res: " + str(i_res))
472 logger.debug("r_res: " + str(r_res))
474 def test_persistent_group_without_persistent_reconnect(dev):
475 """P2P persistent group re-invocation without persistent reconnect"""
477 dev[0].dump_monitor()
478 dev[1].dump_monitor()
480 logger.info("Re-invoke persistent group from client")
481 invite(dev[1], dev[0], persistent_reconnect=False)
483 ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
485 raise Exception("No invitation request reported");
486 if "persistent=" not in ev:
487 raise Exception("Invalid invitation type reported: " + ev)
489 ev2 = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
491 raise Exception("No invitation response reported");
492 if "status=1" not in ev2:
493 raise Exception("Unexpected status: " + ev2)
496 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*) freq=([0-9]*)'
497 s = re.split(exp, ev)
499 raise Exception("Could not parse invitation event")
503 logger.info("Invalid P2P_INVITE test coverage")
504 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=0"):
505 raise Exception("Invalid P2P_INVITE accepted")
506 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " pref=0"):
507 raise Exception("Invalid P2P_INVITE accepted")
508 logger.info("Re-initiate invitation based on upper layer acceptance")
509 if "OK" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
510 raise Exception("Invitation command failed")
511 [go_res, cli_res] = check_result(dev[0], dev[1])
512 if go_res['freq'] != freq:
513 raise Exception("Unexpected channel on GO: {} MHz, expected {} MHz".format(go_res['freq'], freq))
514 if cli_res['freq'] != freq:
515 raise Exception("Unexpected channel on CLI: {} MHz, expected {} MHz".format(cli_res['freq'], freq))
516 terminate_group(dev[0], dev[1])
517 dev[0].dump_monitor()
518 dev[1].dump_monitor()
520 logger.info("Re-invoke persistent group from GO")
521 invite(dev[0], dev[1], persistent_reconnect=False)
523 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
525 raise Exception("No invitation request reported");
526 if "persistent=" not in ev:
527 raise Exception("Invalid invitation type reported: " + ev)
529 ev2 = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
531 raise Exception("No invitation response reported");
532 if "status=1" not in ev2:
533 raise Exception("Unexpected status: " + ev2)
536 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*)'
537 s = re.split(exp, ev)
539 raise Exception("Could not parse invitation event")
542 logger.info("Re-initiate invitation based on upper layer acceptance")
543 if "OK" not in dev[1].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
544 raise Exception("Invitation command failed")
545 [go_res, cli_res] = check_result(dev[0], dev[1])
546 terminate_group(dev[0], dev[1])
548 def test_persistent_group_already_running(dev):
549 """P2P persistent group formation and invitation while GO already running"""
551 peer = dev[1].get_peer(dev[0].p2p_dev_addr())
552 listen_freq = peer['listen_freq']
553 dev[0].dump_monitor()
554 dev[1].dump_monitor()
555 networks = dev[0].list_networks(p2p=True)
556 if len(networks) != 1:
557 raise Exception("Unexpected number of networks")
558 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
559 raise Exception("Not the persistent group data")
560 if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
561 raise Exception("Could not state GO")
562 invite_from_cli(dev[0], dev[1])
564 def test_persistent_group_add_cli_chan(dev):
565 """P2P persistent group formation and re-invocation with p2p_add_cli_chan=1"""
566 dev[0].request("SET p2p_add_cli_chan 1")
567 dev[1].request("SET p2p_add_cli_chan 1")
569 dev[1].request("BSS_FLUSH 0")
570 dev[1].scan(freq="2412", only_new=True)
571 dev[1].scan(freq="2437", only_new=True)
572 dev[1].scan(freq="2462", only_new=True)
573 dev[1].request("BSS_FLUSH 0")
574 invite_from_cli(dev[0], dev[1])
575 invite_from_go(dev[0], dev[1])
577 def test_persistent_invalid_group_add(dev):
578 """Invalid P2P_GROUP_ADD command"""
579 id = dev[0].add_network()
580 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=12345"):
581 raise Exception("Invalid P2P_GROUP_ADD accepted")
582 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=%d" % id):
583 raise Exception("Invalid P2P_GROUP_ADD accepted")
584 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD foo"):
585 raise Exception("Invalid P2P_GROUP_ADD accepted")
587 def test_persistent_group_missed_inv_resp(dev):
588 """P2P persistent group re-invocation with invitation response getting lost"""
590 addr = dev[1].p2p_dev_addr()
591 dev[1].global_request("SET persistent_reconnect 1")
593 if not dev[0].discover_peer(addr, social=True):
594 raise Exception("Peer " + addr + " not found")
595 dev[0].dump_monitor()
596 peer = dev[0].get_peer(addr)
597 # Drop the first Invitation Response frame
598 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
599 raise Exception("Failed to enable external management frame handling")
600 cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr
601 dev[0].global_request(cmd)
602 rx_msg = dev[0].mgmt_rx()
604 raise Exception("MGMT-RX timeout (no Invitation Response)")
606 # Allow following Invitation Response frame to go through
607 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
608 raise Exception("Failed to disable external management frame handling")
610 # Force the P2P Client side to be on its Listen channel for retry
612 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
614 raise Exception("Invitation result timed out")
615 # Allow P2P Client side to continue connection-to-GO attempts
616 dev[1].p2p_stop_find()
618 # Verify that group re-invocation goes through
619 ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED",
620 "P2P-GROUP-FORMATION-FAILURE" ],
623 raise Exception("Group start event timed out")
624 if "P2P-GROUP-STARTED" not in ev:
625 raise Exception("Group re-invocation failed")
626 dev[0].group_form_result(ev)
628 ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED" ], timeout=5)
630 raise Exception("Group start event timed out on GO")
631 dev[0].group_form_result(ev)
633 terminate_group(dev[0], dev[1])
635 def test_persistent_group_profile_add(dev):
636 """Create a P2P persistent group with ADD_NETWORK"""
637 passphrase="passphrase here"
638 id = dev[0].add_network()
639 dev[0].set_network_quoted(id, "ssid", "DIRECT-ab")
640 dev[0].set_network_quoted(id, "psk", passphrase)
641 dev[0].set_network(id, "mode", "3")
642 dev[0].set_network(id, "disabled", "2")
643 dev[0].p2p_start_go(persistent=id, freq=2412)
645 pin = dev[1].wps_read_pin()
646 dev[0].p2p_go_authorize_client(pin)
647 res = dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
648 social=True, freq=2412)
649 if res['result'] != 'success':
650 raise Exception("Joining the group did not succeed")
652 dev[0].remove_group()
653 dev[1].wait_go_ending_session()