1 # P2P autonomous GO test cases
2 # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
10 logger = logging.getLogger()
14 from utils import HwsimSkip
15 from wlantest import Wlantest
16 from wpasupplicant import WpaSupplicant
17 from p2p_utils import *
18 from test_p2p_messages import mgmt_tx, parse_p2p_public_action
21 """P2P autonomous GO and client joining group"""
22 addr0 = dev[0].p2p_dev_addr()
23 addr2 = dev[2].p2p_dev_addr()
25 if "p2p-wlan" in res['ifname']:
26 raise Exception("Unexpected group interface name on GO")
27 res = connect_cli(dev[0], dev[1])
28 if "p2p-wlan" in res['ifname']:
29 raise Exception("Unexpected group interface name on client")
30 bss = dev[1].get_bss("p2p_dev_addr=" + addr0, res['ifname'])
31 if not bss or bss['bssid'] != dev[0].p2p_interface_addr():
32 raise Exception("Unexpected BSSID in the BSS entry for the GO")
34 bss = dev[1].get_bss("ID-" + id, res['ifname'])
35 if not bss or bss['id'] != id:
36 raise Exception("Could not find BSS entry based on id")
37 res = dev[1].group_request("BSS RANGE=" + id + "- MASK=0x1")
38 if "id=" + id not in res:
39 raise Exception("Could not find BSS entry based on id range")
41 res = dev[1].request("SCAN_RESULTS")
42 if "[P2P]" not in res:
43 raise Exception("P2P flag missing from scan results: " + res)
45 # Presence request to increase testing coverage
46 if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000"):
47 raise Exception("Invald P2P_PRESENCE_REQ accepted")
48 if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 30001"):
49 raise Exception("Invald P2P_PRESENCE_REQ accepted")
50 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
51 raise Exception("Could not send presence request")
52 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10)
54 raise Exception("Timeout while waiting for Presence Response")
55 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 20000 102400"):
56 raise Exception("Could not send presence request")
57 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
59 raise Exception("Timeout while waiting for Presence Response")
60 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ"):
61 raise Exception("Could not send presence request")
62 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
64 raise Exception("Timeout while waiting for Presence Response")
66 if not dev[2].discover_peer(addr0):
67 raise Exception("Could not discover GO")
69 dev[2].global_request("P2P_PROV_DISC " + addr0 + " display join")
70 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10)
72 raise Exception("GO did not report P2P-PROV-DISC-SHOW-PIN")
73 if "p2p_dev_addr=" + addr2 not in ev:
74 raise Exception("Unexpected P2P Device Address in event: " + ev)
75 if "group=" + dev[0].group_ifname not in ev:
76 raise Exception("Unexpected group interface in event: " + ev)
77 ev = dev[2].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
79 raise Exception("P2P-PROV-DISC-ENTER-PIN not reported")
82 dev[1].wait_go_ending_session()
84 def test_autogo2(dev):
85 """P2P autonomous GO with a separate group interface and client joining group"""
86 dev[0].request("SET p2p_no_group_iface 0")
87 res = autogo(dev[0], freq=2437)
88 if "p2p-wlan" not in res['ifname']:
89 raise Exception("Unexpected group interface name on GO")
90 if res['ifname'] not in utils.get_ifnames():
91 raise Exception("Could not find group interface netdev")
92 connect_cli(dev[0], dev[1], social=True, freq=2437)
94 dev[1].wait_go_ending_session()
95 if res['ifname'] in utils.get_ifnames():
96 raise Exception("Group interface netdev was not removed")
98 def test_autogo3(dev):
99 """P2P autonomous GO and client with a separate group interface joining group"""
100 dev[1].request("SET p2p_no_group_iface 0")
101 autogo(dev[0], freq=2462)
102 res = connect_cli(dev[0], dev[1], social=True, freq=2462)
103 if "p2p-wlan" not in res['ifname']:
104 raise Exception("Unexpected group interface name on client")
105 if res['ifname'] not in utils.get_ifnames():
106 raise Exception("Could not find group interface netdev")
107 dev[0].remove_group()
108 dev[1].wait_go_ending_session()
110 if res['ifname'] in utils.get_ifnames():
111 raise Exception("Group interface netdev was not removed")
113 def test_autogo4(dev):
114 """P2P autonomous GO and client joining group (both with a separate group interface)"""
115 dev[0].request("SET p2p_no_group_iface 0")
116 dev[1].request("SET p2p_no_group_iface 0")
117 res1 = autogo(dev[0], freq=2412)
118 res2 = connect_cli(dev[0], dev[1], social=True, freq=2412)
119 if "p2p-wlan" not in res1['ifname']:
120 raise Exception("Unexpected group interface name on GO")
121 if "p2p-wlan" not in res2['ifname']:
122 raise Exception("Unexpected group interface name on client")
123 ifnames = utils.get_ifnames()
124 if res1['ifname'] not in ifnames:
125 raise Exception("Could not find GO group interface netdev")
126 if res2['ifname'] not in ifnames:
127 raise Exception("Could not find client group interface netdev")
128 dev[0].remove_group()
129 dev[1].wait_go_ending_session()
131 ifnames = utils.get_ifnames()
132 if res1['ifname'] in ifnames:
133 raise Exception("GO group interface netdev was not removed")
134 if res2['ifname'] in ifnames:
135 raise Exception("Client group interface netdev was not removed")
137 def test_autogo_m2d(dev):
138 """P2P autonomous GO and clients not authorized"""
139 autogo(dev[0], freq=2412)
140 go_addr = dev[0].p2p_dev_addr()
142 dev[1].request("SET p2p_no_group_iface 0")
143 if not dev[1].discover_peer(go_addr, social=True):
144 raise Exception("GO " + go_addr + " not found")
145 dev[1].dump_monitor()
147 if not dev[2].discover_peer(go_addr, social=True):
148 raise Exception("GO " + go_addr + " not found")
149 dev[2].dump_monitor()
151 logger.info("Trying to join the group when GO has not authorized the client")
152 pin = dev[1].wps_read_pin()
153 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
154 if "OK" not in dev[1].global_request(cmd):
155 raise Exception("P2P_CONNECT join failed")
157 pin = dev[2].wps_read_pin()
158 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
159 if "OK" not in dev[2].global_request(cmd):
160 raise Exception("P2P_CONNECT join failed")
162 ev = dev[1].wait_global_event(["WPS-M2D"], timeout=16)
164 raise Exception("No global M2D event")
165 ifaces = dev[1].request("INTERFACES").splitlines()
166 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
167 wpas = WpaSupplicant(ifname=iface)
168 ev = wpas.wait_event(["WPS-M2D"], timeout=10)
170 raise Exception("No M2D event on group interface")
172 ev = dev[2].wait_global_event(["WPS-M2D"], timeout=10)
174 raise Exception("No global M2D event (2)")
175 ev = dev[2].wait_event(["WPS-M2D"], timeout=10)
177 raise Exception("No M2D event on group interface (2)")
179 def test_autogo_fail(dev):
180 """P2P autonomous GO and incorrect PIN"""
181 autogo(dev[0], freq=2412)
182 go_addr = dev[0].p2p_dev_addr()
183 dev[0].p2p_go_authorize_client("00000000")
185 dev[1].request("SET p2p_no_group_iface 0")
186 if not dev[1].discover_peer(go_addr, social=True):
187 raise Exception("GO " + go_addr + " not found")
188 dev[1].dump_monitor()
190 logger.info("Trying to join the group when GO has not authorized the client")
191 pin = dev[1].wps_read_pin()
192 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
193 if "OK" not in dev[1].global_request(cmd):
194 raise Exception("P2P_CONNECT join failed")
196 ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=10)
198 raise Exception("No global WPS-FAIL event")
200 def test_autogo_2cli(dev):
201 """P2P autonomous GO and two clients joining group"""
202 autogo(dev[0], freq=2412)
203 connect_cli(dev[0], dev[1], social=True, freq=2412)
204 connect_cli(dev[0], dev[2], social=True, freq=2412)
205 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
206 dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
207 dev[1].wait_go_ending_session()
208 dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
209 dev[2].wait_go_ending_session()
210 if "FAIL" not in dev[0].global_request("P2P_REMOVE_CLIENT foo"):
211 raise Exception("Invalid P2P_REMOVE_CLIENT command accepted")
212 dev[0].remove_group()
214 def test_autogo_pbc(dev):
215 """P2P autonomous GO and PBC"""
216 dev[1].global_request("SET p2p_no_group_iface 0")
217 autogo(dev[0], freq=2412)
218 if "FAIL" not in dev[0].group_request("WPS_PBC p2p_dev_addr=00:11:22:33:44"):
219 raise Exception("Invalid WPS_PBC succeeded")
220 if "OK" not in dev[0].group_request("WPS_PBC p2p_dev_addr=" + dev[1].p2p_dev_addr()):
221 raise Exception("WPS_PBC failed")
222 dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=0,
224 ev = dev[2].wait_global_event(["WPS-M2D"], timeout=15)
226 raise Exception("WPS-M2D not reported")
227 if "config_error=12" not in ev:
228 raise Exception("Unexpected config_error: " + ev)
229 dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=15,
232 def test_autogo_tdls(dev):
233 """P2P autonomous GO and two clients using TDLS"""
236 logger.info("Start autonomous GO with fixed parameters " + go.ifname)
237 id = go.add_network()
238 go.set_network_quoted(id, "ssid", "DIRECT-tdls")
239 go.set_network_quoted(id, "psk", "12345678")
240 go.set_network(id, "mode", "3")
241 go.set_network(id, "disabled", "2")
242 res = go.p2p_start_go(persistent=id, freq="2462")
243 logger.debug("res: " + str(res))
245 wt.add_passphrase("12345678")
246 connect_cli(go, dev[1], social=True, freq=2462)
247 connect_cli(go, dev[2], social=True, freq=2462)
248 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
249 bssid = dev[0].p2p_interface_addr()
250 addr1 = dev[1].p2p_interface_addr()
251 addr2 = dev[2].p2p_interface_addr()
252 dev[1].tdls_setup(addr2)
254 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
255 conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
257 raise Exception("No TDLS Setup Confirm (success) seen")
258 dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
260 raise Exception("No valid frames through direct link")
261 wt.tdls_clear(bssid, addr1, addr2);
262 dev[1].tdls_teardown(addr2)
264 teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
266 raise Exception("No TDLS Setup Teardown seen")
267 wt.tdls_clear(bssid, addr1, addr2);
268 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
269 ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
271 raise Exception("No valid frames via AP path")
272 direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
274 raise Exception("Unexpected frames through direct link")
275 idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
278 raise Exception("Unexpected frames through direct link (invalid)")
279 dev[2].remove_group()
280 dev[1].remove_group()
281 dev[0].remove_group()
283 def test_autogo_legacy(dev):
284 """P2P autonomous GO and legacy clients"""
285 res = autogo(dev[0], freq=2462)
286 if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
287 raise Exception("passphrase mismatch")
288 if dev[0].group_request("P2P_GET_PASSPHRASE") != res['passphrase']:
289 raise Exception("passphrase mismatch(2)")
291 logger.info("Connect P2P client")
292 connect_cli(dev[0], dev[1], social=True, freq=2462)
294 if "FAIL" not in dev[1].request("P2P_GET_PASSPHRASE"):
295 raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client")
297 logger.info("Connect legacy WPS client")
298 pin = dev[2].wps_read_pin()
299 dev[0].p2p_go_authorize_client(pin)
300 dev[2].request("P2P_SET disabled 1")
301 dev[2].dump_monitor()
302 dev[2].request("WPS_PIN any " + pin)
303 dev[2].wait_connected(timeout=30)
304 status = dev[2].get_status()
305 if status['wpa_state'] != 'COMPLETED':
306 raise Exception("Not fully connected")
307 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
308 dev[2].request("DISCONNECT")
310 logger.info("Connect legacy non-WPS client")
311 dev[2].request("FLUSH")
312 dev[2].request("P2P_SET disabled 1")
313 dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
314 key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
315 scan_freq=res['freq'])
316 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
317 dev[2].request("DISCONNECT")
319 dev[0].remove_group()
320 dev[1].wait_go_ending_session()
322 def test_autogo_chan_switch(dev):
323 """P2P autonomous GO switching channels"""
324 autogo(dev[0], freq=2417)
325 connect_cli(dev[0], dev[1])
326 res = dev[0].request("CHAN_SWITCH 5 2422")
328 # for now, skip test since mac80211_hwsim support is not yet widely
330 raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
331 ev = dev[0].wait_event(["AP-CSA-FINISHED"], timeout=10)
333 raise Exception("CSA finished event timed out")
334 if "freq=2422" not in ev:
335 raise Exception("Unexpected cahnnel in CSA finished event")
336 dev[0].dump_monitor()
337 dev[1].dump_monitor()
339 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
341 def test_autogo_extra_cred(dev):
342 """P2P autonomous GO sending two WPS credentials"""
343 if "FAIL" in dev[0].request("SET wps_testing_dummy_cred 1"):
344 raise Exception("Failed to enable test mode")
345 autogo(dev[0], freq=2412)
346 connect_cli(dev[0], dev[1], social=True, freq=2412)
347 dev[0].remove_group()
348 dev[1].wait_go_ending_session()
350 def test_autogo_ifdown(dev):
351 """P2P autonomous GO and external ifdown"""
352 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
353 wpas.interface_add("wlan5")
356 wpas.interface_remove("wlan5")
357 wpas.interface_add("wlan5")
360 subprocess.call(['ifconfig', res['ifname'], 'down'])
361 ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
363 raise Exception("Group removal not reported")
364 if res['ifname'] not in ev:
365 raise Exception("Unexpected group removal event: " + ev)
367 def test_autogo_start_during_scan(dev):
368 """P2P autonomous GO started during ongoing manual scan"""
370 # use autoscan to set scan_req = MANUAL_SCAN_REQ
371 if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
372 raise Exception("Failed to set autoscan")
373 autogo(dev[0], freq=2462)
374 connect_cli(dev[0], dev[1], social=True, freq=2462)
375 dev[0].remove_group()
376 dev[1].wait_go_ending_session()
378 dev[0].request("AUTOSCAN ")
380 def test_autogo_passphrase_len(dev):
381 """P2P autonomous GO and longer passphrase"""
383 if "OK" not in dev[0].request("SET p2p_passphrase_len 13"):
384 raise Exception("Failed to set passphrase length")
385 res = autogo(dev[0], freq=2412)
386 if len(res['passphrase']) != 13:
387 raise Exception("Unexpected passphrase length")
388 if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
389 raise Exception("passphrase mismatch")
391 logger.info("Connect P2P client")
392 connect_cli(dev[0], dev[1], social=True, freq=2412)
394 logger.info("Connect legacy WPS client")
395 pin = dev[2].wps_read_pin()
396 dev[0].p2p_go_authorize_client(pin)
397 dev[2].request("P2P_SET disabled 1")
398 dev[2].dump_monitor()
399 dev[2].request("WPS_PIN any " + pin)
400 dev[2].wait_connected(timeout=30)
401 status = dev[2].get_status()
402 if status['wpa_state'] != 'COMPLETED':
403 raise Exception("Not fully connected")
404 dev[2].request("DISCONNECT")
406 logger.info("Connect legacy non-WPS client")
407 dev[2].request("FLUSH")
408 dev[2].request("P2P_SET disabled 1")
409 dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
410 key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
411 scan_freq=res['freq'])
412 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
413 dev[2].request("DISCONNECT")
415 dev[0].remove_group()
416 dev[1].wait_go_ending_session()
418 dev[0].request("SET p2p_passphrase_len 8")
420 def test_autogo_bridge(dev):
421 """P2P autonomous GO in a bridge"""
423 # use autoscan to set scan_req = MANUAL_SCAN_REQ
424 if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
425 raise Exception("Failed to set autoscan")
427 ifname = dev[0].get_group_ifname()
428 subprocess.call(['brctl', 'addbr', 'p2p-br0'])
429 subprocess.call(['brctl', 'setfd', 'p2p-br0', '0'])
430 subprocess.call(['brctl', 'addif', 'p2p-br0', ifname])
431 subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
433 subprocess.call(['brctl', 'delif', 'p2p-br0', ifname])
435 subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
437 subprocess.call(['brctl', 'delbr', 'p2p-br0'])
438 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1)
440 raise Exception("P2P group removed unexpectedly")
441 if dev[0].get_group_status_field('wpa_state') != "COMPLETED":
442 raise Exception("Unexpected wpa_state")
443 dev[0].remove_group()
445 dev[0].request("AUTOSCAN ")
446 subprocess.Popen(['brctl', 'delif', 'p2p-br0', ifname],
447 stderr=open('/dev/null', 'w'))
448 subprocess.Popen(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'],
449 stderr=open('/dev/null', 'w'))
450 subprocess.Popen(['brctl', 'delbr', 'p2p-br0'],
451 stderr=open('/dev/null', 'w'))
453 def test_presence_req_on_group_interface(dev):
454 """P2P_PRESENCE_REQ on group interface"""
455 dev[1].request("SET p2p_no_group_iface 0")
456 res = autogo(dev[0], freq=2437)
457 res = connect_cli(dev[0], dev[1], social=True, freq=2437)
458 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
459 raise Exception("Could not send presence request")
460 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
462 raise Exception("Timeout while waiting for Presence Response")
463 dev[0].remove_group()
464 dev[1].wait_go_ending_session()
466 def test_autogo_join_auto_go_not_found(dev):
467 """P2P_CONNECT-auto not finding GO"""
468 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
469 wpas.interface_add("wlan5")
470 wpas.request("P2P_SET listen_channel 1")
471 wpas.global_request("SET p2p_no_group_iface 0")
472 autogo(wpas, freq=2412)
473 addr = wpas.p2p_dev_addr()
474 bssid = wpas.p2p_interface_addr()
477 dev[1].global_request("SET p2p_no_group_iface 0")
478 dev[1].scan_for_bss(bssid, freq=2412)
479 # This makes the GO not show up in the scan iteration following the
480 # P2P_CONNECT command by stopping beaconing and handling Probe Request
481 # frames externally (but not really replying to them). P2P listen mode is
482 # needed to keep the GO listening on the operating channel for the PD
484 if "OK" not in wpas.group_request("STOP_AP"):
485 raise Exception("STOP_AP failed")
487 wpas.group_request("SET ext_mgmt_frame_handling 1")
491 dev[1].global_request("P2P_CONNECT " + addr + " pbc auto")
493 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15)
496 raise Exception("Could not trigger old-scan-only case")
499 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15)
502 raise Exception("Fallback to GO Negotiation not seen")
503 if "reason=GO-not-found" not in ev:
504 raise Exception("Unexpected reason for fallback: " + ev)
507 def test_autogo_join_auto(dev):
508 """P2P_CONNECT-auto joining a group"""
510 addr = dev[0].p2p_dev_addr()
511 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
512 raise Exception("P2P_CONNECT failed")
514 ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15)
516 raise Exception("Timeout on P2P-PROV-DISC-PBC-REQ")
517 if "group=" + dev[0].group_ifname not in ev:
518 raise Exception("Unexpected PD event contents: " + ev)
519 dev[0].group_request("WPS_PBC")
521 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
523 raise Exception("Joining the group timed out")
524 dev[1].group_form_result(ev)
526 dev[0].remove_group()
527 dev[1].wait_go_ending_session()
528 dev[1].flush_scan_cache()
530 def test_autogo_join_auto_go_neg(dev):
531 """P2P_CONNECT-auto fallback to GO Neg"""
532 dev[1].flush_scan_cache()
534 addr = dev[0].p2p_dev_addr()
535 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
536 raise Exception("P2P_CONNECT failed")
538 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
540 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
541 peer = ev.split(' ')[1]
542 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
544 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
546 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
547 if "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev:
548 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
550 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
551 if "reason=peer-not-running-GO" not in ev:
552 raise Exception("Unexpected reason: " + ev)
554 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
556 raise Exception("Joining the group timed out")
557 dev[1].group_form_result(ev)
559 dev[0].remove_group()
560 dev[1].wait_go_ending_session()
561 dev[1].flush_scan_cache()
563 def test_autogo_join_auto_go_neg_after_seeing_go(dev):
564 """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
565 autogo(dev[0], freq=2412)
566 addr = dev[0].p2p_dev_addr()
567 bssid = dev[0].p2p_interface_addr()
568 dev[1].scan_for_bss(bssid, freq=2412)
569 dev[0].remove_group()
572 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
573 raise Exception("P2P_CONNECT failed")
575 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
578 raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
580 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
582 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
583 peer = ev.split(' ')[1]
584 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
586 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
588 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
589 if "reason=no-ACK-to-PD-Req" not in ev and "reason=PD-failed" not in ev:
590 raise Exception("Unexpected reason: " + ev)
592 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
594 raise Exception("Joining the group timed out")
595 dev[1].group_form_result(ev)
597 dev[0].remove_group()
598 dev[1].wait_go_ending_session()
599 dev[1].flush_scan_cache()
601 def test_go_search_non_social(dev):
602 """P2P_FIND with freq parameter to scan a single channel"""
603 addr0 = dev[0].p2p_dev_addr()
604 autogo(dev[0], freq=2422)
605 dev[1].p2p_find(freq=2422)
606 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5)
608 raise Exception("Did not find GO quickly enough")
610 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
612 raise Exception("Did not find peer")
613 dev[2].p2p_stop_find()
614 dev[1].p2p_stop_find()
615 dev[0].remove_group()
617 def test_autogo_many(dev):
618 """P2P autonomous GO with large number of GO instances"""
619 dev[0].request("SET p2p_no_group_iface 0")
621 if "OK" not in dev[0].global_request("P2P_GROUP_ADD freq=2412"):
622 logger.info("Was able to add %d groups" % i)
624 raise Exception("P2P_GROUP_ADD failed")
625 stop_ev = dev[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout=1)
626 if stop_ev is not None:
627 raise Exception("Unexpected P2P-GROUP-REMOVE event")
629 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
631 raise Exception("GO start up timed out")
632 dev[0].group_form_result(ev)
634 for i in dev[0].global_request("INTERFACES").splitlines():
635 dev[0].request("P2P_GROUP_REMOVE " + i)
636 dev[0].dump_monitor()
637 dev[0].request("P2P_GROUP_REMOVE *")
639 def test_autogo_many_clients(dev):
640 """P2P autonomous GO and many clients (P2P IE fragmentation)"""
642 _test_autogo_many_clients(dev)
644 dev[0].global_request("SET device_name Device A")
645 dev[1].global_request("SET device_name Device B")
646 dev[2].global_request("SET device_name Device C")
648 def _test_autogo_many_clients(dev):
649 # These long device names will push the P2P IE contents beyond the limit
650 # that requires fragmentation.
651 name0 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
652 name1 = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
653 name2 = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
654 name3 = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
655 dev[0].global_request("SET device_name " + name0)
656 dev[1].global_request("SET device_name " + name1)
657 dev[2].global_request("SET device_name " + name2)
659 addr0 = dev[0].p2p_dev_addr()
660 res = autogo(dev[0], freq=2412)
661 bssid = dev[0].p2p_interface_addr()
663 connect_cli(dev[0], dev[1], social=True, freq=2412)
664 dev[0].dump_monitor()
665 connect_cli(dev[0], dev[2], social=True, freq=2412)
666 dev[0].dump_monitor()
668 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
669 wpas.interface_add("wlan5")
670 wpas.global_request("SET device_name " + name3)
671 wpas.global_request("SET sec_device_type 1-11111111-1")
672 wpas.global_request("SET sec_device_type 2-22222222-2")
673 wpas.global_request("SET sec_device_type 3-33333333-3")
674 wpas.global_request("SET sec_device_type 4-44444444-4")
675 wpas.global_request("SET sec_device_type 5-55555555-5")
676 connect_cli(dev[0], wpas, social=True, freq=2412)
677 dev[0].dump_monitor()
679 dev[1].dump_monitor()
680 dev[1].p2p_find(freq=2412)
681 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
683 raise Exception("Could not find peer (1)")
684 ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
686 raise Exception("Could not find peer (2)")
687 ev3 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
689 raise Exception("Could not find peer (3)")
690 dev[1].p2p_stop_find()
692 for i in [ name0, name2, name3 ]:
693 if i not in ev1 and i not in ev2 and i not in ev3:
694 raise Exception('name "%s" not found' % i)
699 raise Exception("MGMT-RX timeout")
700 p2p = parse_p2p_public_action(msg['payload'])
702 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
703 if p2p['subtype'] != P2P_PROV_DISC_REQ:
704 raise Exception("Unexpected subtype %d" % p2p['subtype'])
705 p2p['freq'] = msg['freq']
708 def test_autogo_scan(dev):
709 """P2P autonomous GO and no P2P IE in Probe Response scan results"""
710 addr0 = dev[0].p2p_dev_addr()
711 addr1 = dev[1].p2p_dev_addr()
712 dev[0].p2p_start_go(freq=2412, persistent=True)
713 bssid = dev[0].p2p_interface_addr()
715 dev[1].discover_peer(addr0)
716 dev[1].p2p_stop_find()
717 ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2)
719 dev[1].flush_scan_cache()
721 pin = dev[1].wps_read_pin()
722 dev[0].group_request("WPS_PIN any " + pin)
725 dev[1].request("SET p2p_disabled 1")
726 dev[1].request("SCAN freq=2412")
727 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
729 raise Exception("Active scan did not complete")
731 dev[1].request("SET p2p_disabled 0")
734 dev[1].request("SCAN freq=2412 passive=1")
735 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
737 raise Exception("Scan did not complete")
739 # Disable management frame processing for a moment to skip Probe Response
741 dev[0].group_request("SET ext_mgmt_frame_handling 1")
743 dev[1].request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join")
745 # Skip the first Probe Request frame
746 ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
748 raise Exception("No Probe Request frame seen")
749 if not ev.split(' ')[4].startswith("40"):
750 raise Exception("Not a Probe Request frame")
752 # Reply to PD Request while still filtering Probe Request frames
753 msg = rx_pd_req(dev[0])
754 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr0, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg['dialog_token']))
756 # Skip Probe Request frames until something else is received
758 ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
760 raise Exception("No frame seen")
761 if not ev.split(' ')[4].startswith("40"):
764 # Allow wpa_supplicant to process authentication and association
765 dev[0].group_request("SET ext_mgmt_frame_handling 0")
767 # Joining the group should succeed and indicate persistent group based on
768 # Beacon frame P2P IE.
769 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
771 raise Exception("Failed to join group")
772 if "[PERSISTENT]" not in ev:
773 raise Exception("Did not recognize group as persistent")
774 dev[0].remove_group()
775 dev[1].wait_go_ending_session()
777 def test_autogo_join_before_found(dev):
778 """P2P client joining a group before having found GO Device Address"""
779 dev[0].request("SET p2p_no_group_iface 0")
780 res = autogo(dev[0], freq=2412)
781 if "p2p-wlan" not in res['ifname']:
782 raise Exception("Unexpected group interface name on GO")
783 status = dev[0].get_group_status()
784 bssid = status['bssid']
786 pin = dev[1].wps_read_pin()
787 dev[0].p2p_go_authorize_client(pin)
788 cmd = "P2P_CONNECT " + bssid + " " + pin + " join freq=2412"
789 if "OK" not in dev[1].global_request(cmd):
790 raise Exception("P2P_CONNECT join failed")
791 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
793 raise Exception("Joining the group timed out")
794 dev[0].remove_group()
795 dev[1].wait_go_ending_session()