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 not dev[1].discover_peer(addr, social=True):
536 raise Exception("Peer not found")
537 dev[1].p2p_stop_find()
538 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
539 raise Exception("P2P_CONNECT failed")
541 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
543 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
544 peer = ev.split(' ')[1]
545 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
547 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
549 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
550 if "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev:
551 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
553 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
554 if "reason=peer-not-running-GO" not in ev:
555 raise Exception("Unexpected reason: " + ev)
557 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
559 raise Exception("Joining the group timed out")
560 dev[1].group_form_result(ev)
562 dev[0].remove_group()
563 dev[1].wait_go_ending_session()
564 dev[1].flush_scan_cache()
566 def test_autogo_join_auto_go_neg_after_seeing_go(dev):
567 """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
568 autogo(dev[0], freq=2412)
569 addr = dev[0].p2p_dev_addr()
570 bssid = dev[0].p2p_interface_addr()
571 dev[1].scan_for_bss(bssid, freq=2412)
572 dev[0].remove_group()
575 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
576 raise Exception("P2P_CONNECT failed")
578 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
581 raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
583 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
585 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
586 peer = ev.split(' ')[1]
587 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
589 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
591 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
592 if "reason=no-ACK-to-PD-Req" not in ev and "reason=PD-failed" not in ev:
593 raise Exception("Unexpected reason: " + ev)
595 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
597 raise Exception("Joining the group timed out")
598 dev[1].group_form_result(ev)
600 dev[0].remove_group()
601 dev[1].wait_go_ending_session()
602 dev[1].flush_scan_cache()
604 def test_go_search_non_social(dev):
605 """P2P_FIND with freq parameter to scan a single channel"""
606 addr0 = dev[0].p2p_dev_addr()
607 autogo(dev[0], freq=2422)
608 dev[1].p2p_find(freq=2422)
609 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5)
611 raise Exception("Did not find GO quickly enough")
613 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
615 raise Exception("Did not find peer")
616 dev[2].p2p_stop_find()
617 dev[1].p2p_stop_find()
618 dev[0].remove_group()
620 def test_autogo_many(dev):
621 """P2P autonomous GO with large number of GO instances"""
622 dev[0].request("SET p2p_no_group_iface 0")
624 if "OK" not in dev[0].global_request("P2P_GROUP_ADD freq=2412"):
625 logger.info("Was able to add %d groups" % i)
627 raise Exception("P2P_GROUP_ADD failed")
628 stop_ev = dev[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout=1)
629 if stop_ev is not None:
630 raise Exception("Unexpected P2P-GROUP-REMOVE event")
632 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
634 raise Exception("GO start up timed out")
635 dev[0].group_form_result(ev)
637 for i in dev[0].global_request("INTERFACES").splitlines():
638 dev[0].request("P2P_GROUP_REMOVE " + i)
639 dev[0].dump_monitor()
640 dev[0].request("P2P_GROUP_REMOVE *")
642 def test_autogo_many_clients(dev):
643 """P2P autonomous GO and many clients (P2P IE fragmentation)"""
645 _test_autogo_many_clients(dev)
647 dev[0].global_request("SET device_name Device A")
648 dev[1].global_request("SET device_name Device B")
649 dev[2].global_request("SET device_name Device C")
651 def _test_autogo_many_clients(dev):
652 # These long device names will push the P2P IE contents beyond the limit
653 # that requires fragmentation.
654 name0 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
655 name1 = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
656 name2 = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
657 name3 = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
658 dev[0].global_request("SET device_name " + name0)
659 dev[1].global_request("SET device_name " + name1)
660 dev[2].global_request("SET device_name " + name2)
662 addr0 = dev[0].p2p_dev_addr()
663 res = autogo(dev[0], freq=2412)
664 bssid = dev[0].p2p_interface_addr()
666 connect_cli(dev[0], dev[1], social=True, freq=2412)
667 dev[0].dump_monitor()
668 connect_cli(dev[0], dev[2], social=True, freq=2412)
669 dev[0].dump_monitor()
671 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
672 wpas.interface_add("wlan5")
673 wpas.global_request("SET device_name " + name3)
674 wpas.global_request("SET sec_device_type 1-11111111-1")
675 wpas.global_request("SET sec_device_type 2-22222222-2")
676 wpas.global_request("SET sec_device_type 3-33333333-3")
677 wpas.global_request("SET sec_device_type 4-44444444-4")
678 wpas.global_request("SET sec_device_type 5-55555555-5")
679 connect_cli(dev[0], wpas, social=True, freq=2412)
680 dev[0].dump_monitor()
682 dev[1].dump_monitor()
683 dev[1].p2p_find(freq=2412)
684 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
686 raise Exception("Could not find peer (1)")
687 ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
689 raise Exception("Could not find peer (2)")
690 ev3 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
692 raise Exception("Could not find peer (3)")
693 dev[1].p2p_stop_find()
695 for i in [ name0, name2, name3 ]:
696 if i not in ev1 and i not in ev2 and i not in ev3:
697 raise Exception('name "%s" not found' % i)
702 raise Exception("MGMT-RX timeout")
703 p2p = parse_p2p_public_action(msg['payload'])
705 raise Exception("Not a P2P Public Action frame " + str(dialog_token))
706 if p2p['subtype'] != P2P_PROV_DISC_REQ:
707 raise Exception("Unexpected subtype %d" % p2p['subtype'])
708 p2p['freq'] = msg['freq']
711 def test_autogo_scan(dev):
712 """P2P autonomous GO and no P2P IE in Probe Response scan results"""
713 addr0 = dev[0].p2p_dev_addr()
714 addr1 = dev[1].p2p_dev_addr()
715 dev[0].p2p_start_go(freq=2412, persistent=True)
716 bssid = dev[0].p2p_interface_addr()
718 dev[1].discover_peer(addr0)
719 dev[1].p2p_stop_find()
720 ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2)
722 dev[1].flush_scan_cache()
724 pin = dev[1].wps_read_pin()
725 dev[0].group_request("WPS_PIN any " + pin)
728 dev[1].request("SET p2p_disabled 1")
729 dev[1].request("SCAN freq=2412")
730 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
732 raise Exception("Active scan did not complete")
734 dev[1].request("SET p2p_disabled 0")
737 dev[1].request("SCAN freq=2412 passive=1")
738 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
740 raise Exception("Scan did not complete")
742 # Disable management frame processing for a moment to skip Probe Response
744 dev[0].group_request("SET ext_mgmt_frame_handling 1")
746 dev[1].global_request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join")
748 # Skip the first Probe Request frame
749 ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
751 raise Exception("No Probe Request frame seen")
752 if not ev.split(' ')[4].startswith("40"):
753 raise Exception("Not a Probe Request frame")
755 # If a P2P Device is not used, the PD Request will be received on the group
756 # interface (which is actually wlan0, since a separate interface is not
757 # used), which was set to external management frame handling, so need to
758 # reply to it manually.
759 res = dev[0].get_driver_status()
760 if not (int(res['capa.flags'], 0) & 0x20000000):
761 # Reply to PD Request while still filtering Probe Request frames
762 msg = rx_pd_req(dev[0])
763 mgmt_tx(dev[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1, addr0, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg['dialog_token']))
765 # Skip Probe Request frames until something else is received
767 ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10)
769 raise Exception("No frame seen")
770 if not ev.split(' ')[4].startswith("40"):
773 # Allow wpa_supplicant to process authentication and association
774 dev[0].group_request("SET ext_mgmt_frame_handling 0")
776 # Joining the group should succeed and indicate persistent group based on
777 # Beacon frame P2P IE.
778 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
780 raise Exception("Failed to join group")
781 if "[PERSISTENT]" not in ev:
782 raise Exception("Did not recognize group as persistent")
783 dev[0].remove_group()
784 dev[1].wait_go_ending_session()
786 def test_autogo_join_before_found(dev):
787 """P2P client joining a group before having found GO Device Address"""
788 dev[0].request("SET p2p_no_group_iface 0")
789 res = autogo(dev[0], freq=2412)
790 if "p2p-wlan" not in res['ifname']:
791 raise Exception("Unexpected group interface name on GO")
792 status = dev[0].get_group_status()
793 bssid = status['bssid']
795 pin = dev[1].wps_read_pin()
796 dev[0].p2p_go_authorize_client(pin)
797 cmd = "P2P_CONNECT " + bssid + " " + pin + " join freq=2412"
798 if "OK" not in dev[1].global_request(cmd):
799 raise Exception("P2P_CONNECT join failed")
800 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
802 raise Exception("Joining the group timed out")
803 dev[0].remove_group()
804 dev[1].wait_go_ending_session()