]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_persistent.py
tests: P2P persistent group re-invocation with peer having dropped info
[thirdparty/hostap.git] / tests / hwsim / test_p2p_persistent.py
1 # P2P persistent group test cases
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import logging
8 logger = logging.getLogger()
9 import re
10 import time
11
12 import hwsim_utils
13 from p2p_utils import *
14
15 def test_persistent_group(dev):
16 """P2P persistent group formation and re-invocation"""
17 form(dev[0], dev[1])
18 invite_from_cli(dev[0], dev[1])
19 invite_from_go(dev[0], dev[1])
20
21 logger.info("Remove group on the client and try to invite from GO")
22 id = None
23 for n in dev[0].list_networks(p2p=True):
24 if "[P2P-PERSISTENT]" in n['flags']:
25 id = n['id']
26 break
27 if id is None:
28 raise Exception("Could not find persistent group entry")
29 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
30 if dev[1].p2p_dev_addr() not in clients:
31 raise Exception("Peer missing from client list")
32 if "FAIL" not in dev[1].request("SELECT_NETWORK " + str(id)):
33 raise Exception("SELECT_NETWORK succeeded unexpectedly")
34 if "FAIL" not in dev[1].request("SELECT_NETWORK 1234567"):
35 raise Exception("SELECT_NETWORK succeeded unexpectedly(2)")
36 if "FAIL" not in dev[1].request("ENABLE_NETWORK " + str(id)):
37 raise Exception("ENABLE_NETWORK succeeded unexpectedly")
38 if "FAIL" not in dev[1].request("ENABLE_NETWORK 1234567"):
39 raise Exception("ENABLE_NETWORK succeeded unexpectedly(2)")
40 if "FAIL" not in dev[1].request("DISABLE_NETWORK " + str(id)):
41 raise Exception("DISABLE_NETWORK succeeded unexpectedly")
42 if "FAIL" not in dev[1].request("DISABLE_NETWORK 1234567"):
43 raise Exception("DISABLE_NETWORK succeeded unexpectedly(2)")
44 if "FAIL" not in dev[1].request("REMOVE_NETWORK 1234567"):
45 raise Exception("REMOVE_NETWORK succeeded unexpectedly")
46 dev[1].global_request("REMOVE_NETWORK all")
47 if len(dev[1].list_networks(p2p=True)) > 0:
48 raise Exception("Unexpected network block remaining")
49 invite(dev[0], dev[1])
50 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
51 if ev is None:
52 raise Exception("No invitation result seen")
53 if "status=8" not in ev:
54 raise Exception("Unexpected invitation result: " + ev)
55 clients = dev[0].request("GET_NETWORK " + id + " p2p_client_list").rstrip()
56 if dev[1].p2p_dev_addr() in clients:
57 raise Exception("Peer was still in client list")
58
59 def test_persistent_group2(dev):
60 """P2P persistent group formation with reverse roles"""
61 form(dev[0], dev[1], reverse_init=True)
62 invite_from_cli(dev[0], dev[1])
63 invite_from_go(dev[0], dev[1])
64
65 def test_persistent_group3(dev):
66 """P2P persistent group formation and re-invocation with empty BSS table"""
67 form(dev[0], dev[1])
68 dev[1].request("BSS_FLUSH 0")
69 invite_from_cli(dev[0], dev[1])
70 dev[1].request("BSS_FLUSH 0")
71 invite_from_go(dev[0], dev[1])
72
73 def test_persistent_group_per_sta_psk(dev):
74 """P2P persistent group formation and re-invocation using per-client PSK"""
75 addr0 = dev[0].p2p_dev_addr()
76 addr1 = dev[1].p2p_dev_addr()
77 addr2 = dev[2].p2p_dev_addr()
78 dev[0].global_request("P2P_SET per_sta_psk 1")
79 logger.info("Form a persistent group")
80 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
81 r_dev=dev[1], r_intent=0)
82 if not i_res['persistent'] or not r_res['persistent']:
83 raise Exception("Formed group was not persistent")
84
85 logger.info("Join another client to the group")
86 pin = dev[2].wps_read_pin()
87 dev[0].p2p_go_authorize_client(pin)
88 social = int(i_res['freq']) in [ 2412, 2437, 2462 ]
89 c_res = dev[2].p2p_connect_group(addr0, pin, timeout=60, social=social,
90 freq=i_res['freq'])
91 if not c_res['persistent']:
92 raise Exception("Joining client did not recognize persistent group")
93 if r_res['psk'] == c_res['psk']:
94 raise Exception("Same PSK assigned for both clients")
95 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
96
97 logger.info("Remove persistent group and re-start it manually")
98 dev[0].remove_group()
99 dev[1].wait_go_ending_session()
100 dev[2].wait_go_ending_session()
101 dev[0].dump_monitor()
102 dev[1].dump_monitor()
103 dev[2].dump_monitor()
104
105 for i in range(0, 3):
106 networks = dev[i].list_networks(p2p=True)
107 if len(networks) != 1:
108 raise Exception("Unexpected number of networks")
109 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
110 raise Exception("Not the persistent group data")
111 if i > 0:
112 # speed up testing by avoiding use of the old BSS entry since the
113 # GO may have changed channels
114 dev[i].request("BSS_FLUSH 0")
115 dev[i].scan(freq="2412", only_new=True)
116 if "OK" not in dev[i].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=2412"):
117 raise Exception("Could not re-start persistent group")
118 ev = dev[i].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
119 if ev is None:
120 raise Exception("Timeout on group restart")
121 dev[i].group_form_result(ev)
122
123 logger.info("Leave persistent group and rejoin it")
124 dev[2].remove_group()
125 ev = dev[2].wait_global_event(["P2P-GROUP-REMOVED"], timeout=3)
126 if ev is None:
127 raise Exception("Group removal event timed out")
128 if not dev[2].discover_peer(addr0, social=True):
129 raise Exception("Peer " + peer + " not found")
130 dev[2].dump_monitor()
131 peer = dev[2].get_peer(addr0)
132 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
133 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
134 if ev is None:
135 raise Exception("Timeout on group restart (on client)")
136 cli_res = dev[2].group_form_result(ev)
137 if not cli_res['persistent']:
138 raise Exception("Persistent group not restarted as persistent (cli)")
139 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
140
141 logger.info("Remove one of the clients from the group without removing persistent group information for the client")
142 dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
143 dev[2].wait_go_ending_session()
144
145 logger.info("Try to reconnect after having been removed from group (but persistent group info still present)")
146 if not dev[2].discover_peer(addr0, social=True):
147 raise Exception("Peer " + peer + " not found")
148 dev[2].dump_monitor()
149 peer = dev[2].get_peer(addr0)
150 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
151 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
152 if ev is None:
153 raise Exception("Timeout on group restart (on client)")
154 if "P2P-GROUP-STARTED" not in ev:
155 raise Exception("Connection failed")
156
157 logger.info("Remove one of the clients from the group")
158 dev[0].global_request("P2P_REMOVE_CLIENT " + addr2)
159 dev[2].wait_go_ending_session()
160
161 logger.info("Try to reconnect after having been removed from group")
162 if not dev[2].discover_peer(addr0, social=True):
163 raise Exception("Peer " + peer + " not found")
164 dev[2].dump_monitor()
165 peer = dev[2].get_peer(addr0)
166 dev[2].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'] + " freq=2412")
167 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
168 if ev is None:
169 raise Exception("Timeout on group restart (on client)")
170 if "P2P-GROUP-STARTED" in ev:
171 raise Exception("Client managed to connect after being removed")
172
173 logger.info("Remove the remaining client from the group")
174 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
175 dev[1].wait_go_ending_session()
176
177 logger.info("Terminate persistent group")
178 dev[0].remove_group()
179 dev[0].dump_monitor()
180
181 logger.info("Try to re-invoke persistent group from client")
182 dev[0].global_request("SET persistent_reconnect 1")
183 dev[0].p2p_listen()
184 if not dev[1].discover_peer(addr0, social=True):
185 raise Exception("Peer " + peer + " not found")
186 dev[1].dump_monitor()
187 peer = dev[1].get_peer(addr0)
188 dev[1].global_request("P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0)
189 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
190 dev[0].group_form_result(ev)
191 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED","WPA: 4-Way Handshake failed"], timeout=30)
192 if ev is None:
193 raise Exception("Timeout on group restart (on client)")
194 if "P2P-GROUP-STARTED" in ev:
195 raise Exception("Client managed to re-invoke after being removed")
196 dev[0].dump_monitor()
197
198 logger.info("Terminate persistent group")
199 dev[0].remove_group()
200 dev[0].dump_monitor()
201
202 def test_persistent_group_invite_removed_client(dev):
203 """P2P persistent group client removal and re-invitation"""
204 addr0 = dev[0].p2p_dev_addr()
205 addr1 = dev[1].p2p_dev_addr()
206 dev[0].request("P2P_SET per_sta_psk 1")
207 logger.info("Form a persistent group")
208 [i_res, r_res] = go_neg_pin_authorized_persistent(i_dev=dev[0], i_intent=15,
209 r_dev=dev[1], r_intent=0)
210 if not i_res['persistent'] or not r_res['persistent']:
211 raise Exception("Formed group was not persistent")
212
213 logger.info("Remove client from the group")
214 dev[0].global_request("P2P_REMOVE_CLIENT " + addr1)
215 dev[1].wait_go_ending_session()
216
217 logger.info("Re-invite the removed client to join the group")
218 dev[1].p2p_listen()
219 if not dev[0].discover_peer(addr1, social=True):
220 raise Exception("Peer " + peer + " not found")
221 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
222 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
223 if ev is None:
224 raise Exception("Timeout on invitation")
225 if "sa=" + addr0 + " persistent=" not in ev:
226 raise Exception("Unexpected invitation event")
227 [event,addr,persistent] = ev.split(' ', 2)
228 dev[1].global_request("P2P_GROUP_ADD " + persistent)
229 ev = dev[1].wait_global_event(["P2P-PERSISTENT-PSK-FAIL"], timeout=30)
230 if ev is None:
231 raise Exception("Did not receive PSK failure report")
232 [tmp,id] = ev.split('=', 1)
233 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
234 if ev is None:
235 raise Exception("Group removal event timed out")
236 if "reason=PSK_FAILURE" not in ev:
237 raise Exception("Unexpected group removal reason")
238 dev[1].global_request("REMOVE_NETWORK " + id)
239
240 logger.info("Re-invite after client removed persistent group info")
241 dev[1].p2p_listen()
242 if not dev[0].discover_peer(addr1, social=True):
243 raise Exception("Peer " + peer + " not found")
244 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
245 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
246 if ev is None:
247 raise Exception("Timeout on invitation")
248 if " persistent=" in ev:
249 raise Exception("Unexpected invitation event")
250 pin = dev[1].wps_read_pin()
251 dev[0].p2p_go_authorize_client(pin)
252 c_res = dev[1].p2p_connect_group(addr0, pin, timeout=60, social=True,
253 freq=i_res['freq'])
254 if not c_res['persistent']:
255 raise Exception("Joining client did not recognize persistent group")
256 if r_res['psk'] == c_res['psk']:
257 raise Exception("Same PSK assigned on both times")
258 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
259
260 terminate_group(dev[0], dev[1])
261
262 def test_persistent_group_channel(dev):
263 """P2P persistent group re-invocation with channel selection"""
264 form(dev[0], dev[1], test_data=False)
265
266 logger.info("Re-invoke persistent group from client with forced channel")
267 invite(dev[1], dev[0], "freq=2427")
268 [go_res, cli_res] = check_result(dev[0], dev[1])
269 if go_res['freq'] != "2427":
270 raise Exception("Persistent group client forced channel not followed")
271 terminate_group(dev[0], dev[1])
272
273 logger.info("Re-invoke persistent group from GO with forced channel")
274 invite(dev[0], dev[1], "freq=2432")
275 [go_res, cli_res] = check_result(dev[0], dev[1])
276 if go_res['freq'] != "2432":
277 raise Exception("Persistent group GO channel preference not followed")
278 terminate_group(dev[0], dev[1])
279
280 logger.info("Re-invoke persistent group from client with channel preference")
281 invite(dev[1], dev[0], "pref=2417")
282 [go_res, cli_res] = check_result(dev[0], dev[1])
283 if go_res['freq'] != "2417":
284 raise Exception("Persistent group client channel preference not followed")
285 terminate_group(dev[0], dev[1])
286
287 def test_persistent_group_and_role_change(dev):
288 """P2P persistent group, auto GO in another role, and re-invocation"""
289 form(dev[0], dev[1])
290
291 logger.info("Start and stop autonomous GO on previous P2P client device")
292 dev[1].p2p_start_go()
293 dev[1].remove_group()
294 dev[1].dump_monitor()
295
296 logger.info("Re-invoke the persistent group")
297 invite_from_go(dev[0], dev[1])
298
299 def test_persistent_go_client_list(dev):
300 """P2P GO and list of clients in persistent group"""
301 addr0 = dev[0].p2p_dev_addr()
302 addr1 = dev[1].p2p_dev_addr()
303 addr2 = dev[2].p2p_dev_addr()
304
305 res = dev[0].p2p_start_go(persistent=True)
306 id = None
307 for n in dev[0].list_networks(p2p=True):
308 if "[P2P-PERSISTENT]" in n['flags']:
309 id = n['id']
310 break
311 if id is None:
312 raise Exception("Could not find persistent group entry")
313
314 connect_cli(dev[0], dev[1], social=True, freq=res['freq'])
315 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
316 if clients != addr1:
317 raise Exception("Unexpected p2p_client_list entry(2): " + clients)
318 connect_cli(dev[0], dev[2], social=True, freq=res['freq'])
319 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
320 if clients != addr2 + " " + addr1:
321 raise Exception("Unexpected p2p_client_list entry(3): " + clients)
322
323 peer = dev[1].get_peer(res['go_dev_addr'])
324 dev[1].remove_group()
325 dev[1].global_request("P2P_GROUP_ADD persistent=" + peer['persistent'])
326 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=30)
327 if ev is None:
328 raise Exception("Timeout on group restart (on client)")
329 dev[1].group_form_result(ev)
330 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
331 if clients != addr1 + " " + addr2:
332 raise Exception("Unexpected p2p_client_list entry(4): " + clients)
333
334 dev[2].remove_group()
335 dev[1].remove_group()
336 dev[0].remove_group()
337
338 clients = dev[0].global_request("GET_NETWORK " + id + " p2p_client_list").rstrip()
339 if clients != addr1 + " " + addr2:
340 raise Exception("Unexpected p2p_client_list entry(5): " + clients)
341
342 dev[1].p2p_listen()
343 dev[2].p2p_listen()
344 dev[0].request("P2P_FLUSH")
345 dev[0].discover_peer(addr1, social=True)
346 peer = dev[0].get_peer(addr1)
347 if 'persistent' not in peer or peer['persistent'] != id:
348 raise Exception("Persistent group client not recognized(1)")
349
350 dev[0].discover_peer(addr2, social=True)
351 peer = dev[0].get_peer(addr2)
352 if 'persistent' not in peer or peer['persistent'] != id:
353 raise Exception("Persistent group client not recognized(2)")
354
355 def test_persistent_group_in_grpform(dev):
356 """P2P persistent group parameters re-used in group formation"""
357 addr0 = dev[0].p2p_dev_addr()
358 addr1 = dev[1].p2p_dev_addr()
359 form(dev[0], dev[1])
360 dev[1].p2p_listen()
361 if not dev[0].discover_peer(addr1, social=True):
362 raise Exception("Could not discover peer")
363 peer = dev[0].get_peer(addr1)
364 if "persistent" not in peer:
365 raise Exception("Could not map peer to a persistent group")
366
367 pin = dev[1].wps_read_pin()
368 dev[1].p2p_go_neg_auth(addr0, pin, "display", go_intent=0)
369 i_res = dev[0].p2p_go_neg_init(addr1, pin, "enter", timeout=20,
370 go_intent=15,
371 persistent_id=peer['persistent'])
372 r_res = dev[1].p2p_go_neg_auth_result()
373 logger.debug("i_res: " + str(i_res))
374 logger.debug("r_res: " + str(r_res))
375
376 def test_persistent_group_without_persistent_reconnect(dev):
377 """P2P persistent group re-invocation without persistent reconnect"""
378 form(dev[0], dev[1])
379 dev[0].dump_monitor()
380 dev[1].dump_monitor()
381
382 logger.info("Re-invoke persistent group from client")
383 invite(dev[1], dev[0], persistent_reconnect=False)
384
385 ev = dev[0].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
386 if ev is None:
387 raise Exception("No invitation request reported");
388 if "persistent=" not in ev:
389 raise Exception("Invalid invitation type reported: " + ev)
390
391 ev2 = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
392 if ev2 is None:
393 raise Exception("No invitation response reported");
394 if "status=1" not in ev2:
395 raise Exception("Unexpected status: " + ev2)
396 dev[1].p2p_listen()
397
398 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*) freq=([0-9]*)'
399 s = re.split(exp, ev)
400 if len(s) < 5:
401 raise Exception("Could not parse invitation event")
402 sa = s[2]
403 id = s[3]
404 freq = s[4]
405 logger.info("Invalid P2P_INVITE test coverage")
406 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=0"):
407 raise Exception("Invalid P2P_INVITE accepted")
408 if "FAIL" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " pref=0"):
409 raise Exception("Invalid P2P_INVITE accepted")
410 logger.info("Re-initiate invitation based on upper layer acceptance")
411 if "OK" not in dev[0].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
412 raise Exception("Invitation command failed")
413 [go_res, cli_res] = check_result(dev[0], dev[1])
414 if go_res['freq'] != freq:
415 raise Exception("Unexpected channel on GO: {} MHz, expected {} MHz".format(go_res['freq'], freq))
416 if cli_res['freq'] != freq:
417 raise Exception("Unexpected channel on CLI: {} MHz, expected {} MHz".format(cli_res['freq'], freq))
418 terminate_group(dev[0], dev[1])
419 dev[0].dump_monitor()
420 dev[1].dump_monitor()
421
422 logger.info("Re-invoke persistent group from GO")
423 invite(dev[0], dev[1], persistent_reconnect=False)
424
425 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
426 if ev is None:
427 raise Exception("No invitation request reported");
428 if "persistent=" not in ev:
429 raise Exception("Invalid invitation type reported: " + ev)
430
431 ev2 = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
432 if ev2 is None:
433 raise Exception("No invitation response reported");
434 if "status=1" not in ev2:
435 raise Exception("Unexpected status: " + ev2)
436 dev[0].p2p_listen()
437
438 exp = r'<.>(P2P-INVITATION-RECEIVED) sa=([0-9a-f:]*) persistent=([0-9]*)'
439 s = re.split(exp, ev)
440 if len(s) < 4:
441 raise Exception("Could not parse invitation event")
442 sa = s[2]
443 id = s[3]
444 logger.info("Re-initiate invitation based on upper layer acceptance")
445 if "OK" not in dev[1].global_request("P2P_INVITE persistent=" + id + " peer=" + sa + " freq=" + freq):
446 raise Exception("Invitation command failed")
447 [go_res, cli_res] = check_result(dev[0], dev[1])
448 terminate_group(dev[0], dev[1])
449
450 def test_persistent_group_already_running(dev):
451 """P2P persistent group formation and invitation while GO already running"""
452 form(dev[0], dev[1])
453 peer = dev[1].get_peer(dev[0].p2p_dev_addr())
454 listen_freq = peer['listen_freq']
455 dev[0].dump_monitor()
456 dev[1].dump_monitor()
457 networks = dev[0].list_networks(p2p=True)
458 if len(networks) != 1:
459 raise Exception("Unexpected number of networks")
460 if "[P2P-PERSISTENT]" not in networks[0]['flags']:
461 raise Exception("Not the persistent group data")
462 if "OK" not in dev[0].global_request("P2P_GROUP_ADD persistent=" + networks[0]['id'] + " freq=" + listen_freq):
463 raise Exception("Could not state GO")
464 invite_from_cli(dev[0], dev[1])
465
466 def test_persistent_group_add_cli_chan(dev):
467 """P2P persistent group formation and re-invocation with p2p_add_cli_chan=1"""
468 try:
469 dev[0].request("SET p2p_add_cli_chan 1")
470 dev[1].request("SET p2p_add_cli_chan 1")
471 form(dev[0], dev[1])
472 dev[1].request("BSS_FLUSH 0")
473 dev[1].scan(freq="2412", only_new=True)
474 dev[1].scan(freq="2437", only_new=True)
475 dev[1].scan(freq="2462", only_new=True)
476 dev[1].request("BSS_FLUSH 0")
477 invite_from_cli(dev[0], dev[1])
478 invite_from_go(dev[0], dev[1])
479 finally:
480 dev[0].request("SET p2p_add_cli_chan 0")
481 dev[1].request("SET p2p_add_cli_chan 0")
482
483 def test_persistent_invalid_group_add(dev):
484 """Invalid P2P_GROUP_ADD command"""
485 id = dev[0].add_network()
486 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=12345"):
487 raise Exception("Invalid P2P_GROUP_ADD accepted")
488 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD persistent=%d" % id):
489 raise Exception("Invalid P2P_GROUP_ADD accepted")
490 if "FAIL" not in dev[0].global_request("P2P_GROUP_ADD foo"):
491 raise Exception("Invalid P2P_GROUP_ADD accepted")
492
493 def test_persistent_group_missed_inv_resp(dev):
494 """P2P persistent group re-invocation with invitation response getting lost"""
495 form(dev[0], dev[1])
496 addr = dev[1].p2p_dev_addr()
497 dev[1].global_request("SET persistent_reconnect 1")
498 dev[1].p2p_listen()
499 if not dev[0].discover_peer(addr, social=True):
500 raise Exception("Peer " + addr + " not found")
501 dev[0].dump_monitor()
502 peer = dev[0].get_peer(addr)
503 # Drop the first Invitation Response frame
504 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 1"):
505 raise Exception("Failed to enable external management frame handling")
506 cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr
507 dev[0].global_request(cmd)
508 rx_msg = dev[0].mgmt_rx()
509 if rx_msg is None:
510 raise Exception("MGMT-RX timeout (no Invitation Response)")
511 time.sleep(2)
512 # Allow following Invitation Response frame to go through
513 if "FAIL" in dev[0].request("SET ext_mgmt_frame_handling 0"):
514 raise Exception("Failed to disable external management frame handling")
515 time.sleep(1)
516 # Force the P2P Client side to be on its Listen channel for retry
517 dev[1].p2p_listen()
518 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
519 if ev is None:
520 raise Exception("Invitation result timed out")
521 # Allow P2P Client side to continue connection-to-GO attempts
522 dev[1].p2p_stop_find()
523
524 # Verify that group re-invocation goes through
525 ev = dev[1].wait_global_event([ "P2P-GROUP-STARTED",
526 "P2P-GROUP-FORMATION-FAILURE" ],
527 timeout=20)
528 if ev is None:
529 raise Exception("Group start event timed out")
530 if "P2P-GROUP-STARTED" not in ev:
531 raise Exception("Group re-invocation failed")
532 dev[0].group_form_result(ev)
533
534 ev = dev[0].wait_global_event([ "P2P-GROUP-STARTED" ], timeout=5)
535 if ev is None:
536 raise Exception("Group start event timed out on GO")
537 dev[0].group_form_result(ev)
538
539 terminate_group(dev[0], dev[1])
540
541 def test_persistent_group_profile_add(dev):
542 """Create a P2P persistent group with ADD_NETWORK"""
543 passphrase="passphrase here"
544 id = dev[0].add_network()
545 dev[0].set_network_quoted(id, "ssid", "DIRECT-ab")
546 dev[0].set_network_quoted(id, "psk", passphrase)
547 dev[0].set_network(id, "mode", "3")
548 dev[0].set_network(id, "disabled", "2")
549 dev[0].p2p_start_go(persistent=id, freq=2412)
550
551 pin = dev[1].wps_read_pin()
552 dev[0].p2p_go_authorize_client(pin)
553 res = dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60,
554 social=True, freq=2412)
555 if res['result'] != 'success':
556 raise Exception("Joining the group did not succeed")
557
558 dev[0].remove_group()
559 dev[1].wait_go_ending_session()
560
561 def test_persistent_group_cancel_on_cli(dev):
562 """P2P persistent group formation, re-invocation, and cancel"""
563 dev[0].global_request("SET p2p_no_group_iface 0")
564 dev[1].global_request("SET p2p_no_group_iface 0")
565 form(dev[0], dev[1])
566
567 invite_from_go(dev[0], dev[1], terminate=False)
568 if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
569 raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
570 if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
571 raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
572 terminate_group(dev[0], dev[1])
573
574 invite_from_cli(dev[0], dev[1], terminate=False)
575 if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
576 raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
577 if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
578 raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
579 terminate_group(dev[0], dev[1])
580
581 def test_persistent_group_cancel_on_cli2(dev):
582 """P2P persistent group formation, re-invocation, and cancel (2)"""
583 form(dev[0], dev[1])
584 invite_from_go(dev[0], dev[1], terminate=False)
585 if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
586 raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
587 if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
588 raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
589 terminate_group(dev[0], dev[1])
590
591 invite_from_cli(dev[0], dev[1], terminate=False)
592 if "FAIL" not in dev[1].global_request("P2P_CANCEL"):
593 raise Exception("P2P_CANCEL succeeded unexpectedly on CLI")
594 if "FAIL" not in dev[0].global_request("P2P_CANCEL"):
595 raise Exception("P2P_CANCEL succeeded unexpectedly on GO")
596 terminate_group(dev[0], dev[1])
597
598 def test_persistent_group_peer_dropped(dev):
599 """P2P persistent group formation and re-invocation with peer having dropped group"""
600 form(dev[0], dev[1], reverse_init=True)
601 invite_from_cli(dev[0], dev[1])
602
603 logger.info("Remove group on the GO and try to invite from the client")
604 dev[0].request("REMOVE_NETWORK all")
605 invite(dev[1], dev[0])
606 ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
607 if ev is None:
608 raise Exception("No invitation result seen")
609 if "status=8" not in ev:
610 raise Exception("Unexpected invitation result: " + ev)
611 networks = dev[1].list_networks(p2p=True)
612 if len(networks) > 0:
613 raise Exception("Unexpected network block on client")
614
615 logger.info("Verify that a new group can be formed")
616 form(dev[0], dev[1], reverse_init=True)
617
618 def test_persistent_group_peer_dropped2(dev):
619 """P2P persistent group formation and re-invocation with peer having dropped group (2)"""
620 form(dev[0], dev[1])
621 invite_from_go(dev[0], dev[1])
622
623 logger.info("Remove group on the client and try to invite from the GO")
624 dev[1].request("REMOVE_NETWORK all")
625 invite(dev[0], dev[1])
626 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
627 if ev is None:
628 raise Exception("No invitation result seen")
629 if "status=8" not in ev:
630 raise Exception("Unexpected invitation result: " + ev)
631 networks = dev[1].list_networks(p2p=True)
632 if len(networks) > 0:
633 raise Exception("Unexpected network block on client")
634
635 logger.info("Verify that a new group can be formed")
636 form(dev[0], dev[1])