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
18 def autogo(go, freq=None, persistent=None):
19 logger.info("Start autonomous GO " + go.ifname)
20 res = go.p2p_start_go(freq=freq, persistent=persistent)
21 logger.debug("res: " + str(res))
24 def connect_cli(go, client, social=False, freq=None):
25 logger.info("Try to connect the client to the GO")
26 pin = client.wps_read_pin()
27 go.p2p_go_authorize_client(pin)
28 res = client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60,
29 social=social, freq=freq)
30 logger.info("Client connected")
31 hwsim_utils.test_connectivity_p2p(go, client)
35 """P2P autonomous GO and client joining group"""
36 addr0 = dev[0].p2p_dev_addr()
37 addr2 = dev[2].p2p_dev_addr()
39 if "p2p-wlan" in res['ifname']:
40 raise Exception("Unexpected group interface name on GO")
41 res = connect_cli(dev[0], dev[1])
42 if "p2p-wlan" in res['ifname']:
43 raise Exception("Unexpected group interface name on client")
44 bss = dev[1].get_bss("p2p_dev_addr=" + addr0, res['ifname'])
45 if not bss or bss['bssid'] != dev[0].p2p_interface_addr():
46 raise Exception("Unexpected BSSID in the BSS entry for the GO")
48 bss = dev[1].get_bss("ID-" + id, res['ifname'])
49 if not bss or bss['id'] != id:
50 raise Exception("Could not find BSS entry based on id")
51 res = dev[1].group_request("BSS RANGE=" + id + "- MASK=0x1")
52 if "id=" + id not in res:
53 raise Exception("Could not find BSS entry based on id range")
55 res = dev[1].request("SCAN_RESULTS")
56 if "[P2P]" not in res:
57 raise Exception("P2P flag missing from scan results: " + res)
59 # Presence request to increase testing coverage
60 if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000"):
61 raise Exception("Invald P2P_PRESENCE_REQ accepted")
62 if "FAIL" not in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 30001"):
63 raise Exception("Invald P2P_PRESENCE_REQ accepted")
64 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
65 raise Exception("Could not send presence request")
66 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10)
68 raise Exception("Timeout while waiting for Presence Response")
69 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400 20000 102400"):
70 raise Exception("Could not send presence request")
71 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
73 raise Exception("Timeout while waiting for Presence Response")
74 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ"):
75 raise Exception("Could not send presence request")
76 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
78 raise Exception("Timeout while waiting for Presence Response")
80 if not dev[2].discover_peer(addr0):
81 raise Exception("Could not discover GO")
83 dev[2].global_request("P2P_PROV_DISC " + addr0 + " display join")
84 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=10)
86 raise Exception("GO did not report P2P-PROV-DISC-SHOW-PIN")
87 if "p2p_dev_addr=" + addr2 not in ev:
88 raise Exception("Unexpected P2P Device Address in event: " + ev)
89 if "group=" + dev[0].group_ifname not in ev:
90 raise Exception("Unexpected group interface in event: " + ev)
91 ev = dev[2].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=10)
93 raise Exception("P2P-PROV-DISC-ENTER-PIN not reported")
96 dev[1].wait_go_ending_session()
98 def test_autogo2(dev):
99 """P2P autonomous GO with a separate group interface and client joining group"""
100 dev[0].request("SET p2p_no_group_iface 0")
101 res = autogo(dev[0], freq=2437)
102 if "p2p-wlan" not in res['ifname']:
103 raise Exception("Unexpected group interface name on GO")
104 if res['ifname'] not in utils.get_ifnames():
105 raise Exception("Could not find group interface netdev")
106 connect_cli(dev[0], dev[1], social=True, freq=2437)
107 dev[0].remove_group()
108 dev[1].wait_go_ending_session()
109 if res['ifname'] in utils.get_ifnames():
110 raise Exception("Group interface netdev was not removed")
112 def test_autogo3(dev):
113 """P2P autonomous GO and client with a separate group interface joining group"""
114 dev[1].request("SET p2p_no_group_iface 0")
115 autogo(dev[0], freq=2462)
116 res = connect_cli(dev[0], dev[1], social=True, freq=2462)
117 if "p2p-wlan" not in res['ifname']:
118 raise Exception("Unexpected group interface name on client")
119 if res['ifname'] not in utils.get_ifnames():
120 raise Exception("Could not find group interface netdev")
121 dev[0].remove_group()
122 dev[1].wait_go_ending_session()
124 if res['ifname'] in utils.get_ifnames():
125 raise Exception("Group interface netdev was not removed")
127 def test_autogo4(dev):
128 """P2P autonomous GO and client joining group (both with a separate group interface)"""
129 dev[0].request("SET p2p_no_group_iface 0")
130 dev[1].request("SET p2p_no_group_iface 0")
131 res1 = autogo(dev[0], freq=2412)
132 res2 = connect_cli(dev[0], dev[1], social=True, freq=2412)
133 if "p2p-wlan" not in res1['ifname']:
134 raise Exception("Unexpected group interface name on GO")
135 if "p2p-wlan" not in res2['ifname']:
136 raise Exception("Unexpected group interface name on client")
137 ifnames = utils.get_ifnames()
138 if res1['ifname'] not in ifnames:
139 raise Exception("Could not find GO group interface netdev")
140 if res2['ifname'] not in ifnames:
141 raise Exception("Could not find client group interface netdev")
142 dev[0].remove_group()
143 dev[1].wait_go_ending_session()
145 ifnames = utils.get_ifnames()
146 if res1['ifname'] in ifnames:
147 raise Exception("GO group interface netdev was not removed")
148 if res2['ifname'] in ifnames:
149 raise Exception("Client group interface netdev was not removed")
151 def test_autogo_m2d(dev):
152 """P2P autonomous GO and clients not authorized"""
153 autogo(dev[0], freq=2412)
154 go_addr = dev[0].p2p_dev_addr()
156 dev[1].request("SET p2p_no_group_iface 0")
157 if not dev[1].discover_peer(go_addr, social=True):
158 raise Exception("GO " + go_addr + " not found")
159 dev[1].dump_monitor()
161 if not dev[2].discover_peer(go_addr, social=True):
162 raise Exception("GO " + go_addr + " not found")
163 dev[2].dump_monitor()
165 logger.info("Trying to join the group when GO has not authorized the client")
166 pin = dev[1].wps_read_pin()
167 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
168 if "OK" not in dev[1].global_request(cmd):
169 raise Exception("P2P_CONNECT join failed")
171 pin = dev[2].wps_read_pin()
172 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
173 if "OK" not in dev[2].global_request(cmd):
174 raise Exception("P2P_CONNECT join failed")
176 ev = dev[1].wait_global_event(["WPS-M2D"], timeout=16)
178 raise Exception("No global M2D event")
179 ifaces = dev[1].request("INTERFACES").splitlines()
180 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
181 wpas = WpaSupplicant(ifname=iface)
182 ev = wpas.wait_event(["WPS-M2D"], timeout=10)
184 raise Exception("No M2D event on group interface")
186 ev = dev[2].wait_global_event(["WPS-M2D"], timeout=10)
188 raise Exception("No global M2D event (2)")
189 ev = dev[2].wait_event(["WPS-M2D"], timeout=10)
191 raise Exception("No M2D event on group interface (2)")
193 def test_autogo_fail(dev):
194 """P2P autonomous GO and incorrect PIN"""
195 autogo(dev[0], freq=2412)
196 go_addr = dev[0].p2p_dev_addr()
197 dev[0].p2p_go_authorize_client("00000000")
199 dev[1].request("SET p2p_no_group_iface 0")
200 if not dev[1].discover_peer(go_addr, social=True):
201 raise Exception("GO " + go_addr + " not found")
202 dev[1].dump_monitor()
204 logger.info("Trying to join the group when GO has not authorized the client")
205 pin = dev[1].wps_read_pin()
206 cmd = "P2P_CONNECT " + go_addr + " " + pin + " join"
207 if "OK" not in dev[1].global_request(cmd):
208 raise Exception("P2P_CONNECT join failed")
210 ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=10)
212 raise Exception("No global WPS-FAIL event")
214 def test_autogo_2cli(dev):
215 """P2P autonomous GO and two clients joining group"""
216 autogo(dev[0], freq=2412)
217 connect_cli(dev[0], dev[1], social=True, freq=2412)
218 connect_cli(dev[0], dev[2], social=True, freq=2412)
219 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
220 dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
221 dev[1].wait_go_ending_session()
222 dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr())
223 dev[2].wait_go_ending_session()
224 if "FAIL" not in dev[0].global_request("P2P_REMOVE_CLIENT foo"):
225 raise Exception("Invalid P2P_REMOVE_CLIENT command accepted")
226 dev[0].remove_group()
228 def test_autogo_pbc(dev):
229 """P2P autonomous GO and PBC"""
230 dev[1].global_request("SET p2p_no_group_iface 0")
231 autogo(dev[0], freq=2412)
232 if "FAIL" not in dev[0].group_request("WPS_PBC p2p_dev_addr=00:11:22:33:44"):
233 raise Exception("Invalid WPS_PBC succeeded")
234 if "OK" not in dev[0].group_request("WPS_PBC p2p_dev_addr=" + dev[1].p2p_dev_addr()):
235 raise Exception("WPS_PBC failed")
236 dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=0,
238 ev = dev[2].wait_global_event(["WPS-M2D"], timeout=15)
240 raise Exception("WPS-M2D not reported")
241 if "config_error=12" not in ev:
242 raise Exception("Unexpected config_error: " + ev)
243 dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), "pbc", timeout=15,
246 def test_autogo_tdls(dev):
247 """P2P autonomous GO and two clients using TDLS"""
250 logger.info("Start autonomous GO with fixed parameters " + go.ifname)
251 id = go.add_network()
252 go.set_network_quoted(id, "ssid", "DIRECT-tdls")
253 go.set_network_quoted(id, "psk", "12345678")
254 go.set_network(id, "mode", "3")
255 go.set_network(id, "disabled", "2")
256 res = go.p2p_start_go(persistent=id, freq="2462")
257 logger.debug("res: " + str(res))
259 wt.add_passphrase("12345678")
260 connect_cli(go, dev[1], social=True, freq=2462)
261 connect_cli(go, dev[2], social=True, freq=2462)
262 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
263 bssid = dev[0].p2p_interface_addr()
264 addr1 = dev[1].p2p_interface_addr()
265 addr2 = dev[2].p2p_interface_addr()
266 dev[1].tdls_setup(addr2)
268 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
269 conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
271 raise Exception("No TDLS Setup Confirm (success) seen")
272 dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
274 raise Exception("No valid frames through direct link")
275 wt.tdls_clear(bssid, addr1, addr2);
276 dev[1].tdls_teardown(addr2)
278 teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
280 raise Exception("No TDLS Setup Teardown seen")
281 wt.tdls_clear(bssid, addr1, addr2);
282 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
283 ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
285 raise Exception("No valid frames via AP path")
286 direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
288 raise Exception("Unexpected frames through direct link")
289 idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
292 raise Exception("Unexpected frames through direct link (invalid)")
293 dev[2].remove_group()
294 dev[1].remove_group()
295 dev[0].remove_group()
297 def test_autogo_legacy(dev):
298 """P2P autonomous GO and legacy clients"""
299 res = autogo(dev[0], freq=2462)
300 if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
301 raise Exception("passphrase mismatch")
302 if dev[0].group_request("P2P_GET_PASSPHRASE") != res['passphrase']:
303 raise Exception("passphrase mismatch(2)")
305 logger.info("Connect P2P client")
306 connect_cli(dev[0], dev[1], social=True, freq=2462)
308 if "FAIL" not in dev[1].request("P2P_GET_PASSPHRASE"):
309 raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client")
311 logger.info("Connect legacy WPS client")
312 pin = dev[2].wps_read_pin()
313 dev[0].p2p_go_authorize_client(pin)
314 dev[2].request("P2P_SET disabled 1")
315 dev[2].dump_monitor()
316 dev[2].request("WPS_PIN any " + pin)
317 dev[2].wait_connected(timeout=30)
318 status = dev[2].get_status()
319 if status['wpa_state'] != 'COMPLETED':
320 raise Exception("Not fully connected")
321 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
322 dev[2].request("DISCONNECT")
324 logger.info("Connect legacy non-WPS client")
325 dev[2].request("FLUSH")
326 dev[2].request("P2P_SET disabled 1")
327 dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
328 key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
329 scan_freq=res['freq'])
330 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
331 dev[2].request("DISCONNECT")
333 dev[0].remove_group()
334 dev[1].wait_go_ending_session()
336 def test_autogo_chan_switch(dev):
337 """P2P autonomous GO switching channels"""
338 autogo(dev[0], freq=2417)
339 connect_cli(dev[0], dev[1])
340 res = dev[0].request("CHAN_SWITCH 5 2422")
342 # for now, skip test since mac80211_hwsim support is not yet widely
344 raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
345 ev = dev[0].wait_event(["AP-CSA-FINISHED"], timeout=10)
347 raise Exception("CSA finished event timed out")
348 if "freq=2422" not in ev:
349 raise Exception("Unexpected cahnnel in CSA finished event")
350 dev[0].dump_monitor()
351 dev[1].dump_monitor()
353 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
355 def test_autogo_extra_cred(dev):
356 """P2P autonomous GO sending two WPS credentials"""
357 if "FAIL" in dev[0].request("SET wps_testing_dummy_cred 1"):
358 raise Exception("Failed to enable test mode")
359 autogo(dev[0], freq=2412)
360 connect_cli(dev[0], dev[1], social=True, freq=2412)
361 dev[0].remove_group()
362 dev[1].wait_go_ending_session()
364 def test_autogo_ifdown(dev):
365 """P2P autonomous GO and external ifdown"""
366 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
367 wpas.interface_add("wlan5")
370 wpas.interface_remove("wlan5")
371 wpas.interface_add("wlan5")
374 subprocess.call(['ifconfig', res['ifname'], 'down'])
375 ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
377 raise Exception("Group removal not reported")
378 if res['ifname'] not in ev:
379 raise Exception("Unexpected group removal event: " + ev)
381 def test_autogo_start_during_scan(dev):
382 """P2P autonomous GO started during ongoing manual scan"""
384 # use autoscan to set scan_req = MANUAL_SCAN_REQ
385 if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
386 raise Exception("Failed to set autoscan")
387 autogo(dev[0], freq=2462)
388 connect_cli(dev[0], dev[1], social=True, freq=2462)
389 dev[0].remove_group()
390 dev[1].wait_go_ending_session()
392 dev[0].request("AUTOSCAN ")
394 def test_autogo_passphrase_len(dev):
395 """P2P autonomous GO and longer passphrase"""
397 if "OK" not in dev[0].request("SET p2p_passphrase_len 13"):
398 raise Exception("Failed to set passphrase length")
399 res = autogo(dev[0], freq=2412)
400 if len(res['passphrase']) != 13:
401 raise Exception("Unexpected passphrase length")
402 if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']:
403 raise Exception("passphrase mismatch")
405 logger.info("Connect P2P client")
406 connect_cli(dev[0], dev[1], social=True, freq=2412)
408 logger.info("Connect legacy WPS client")
409 pin = dev[2].wps_read_pin()
410 dev[0].p2p_go_authorize_client(pin)
411 dev[2].request("P2P_SET disabled 1")
412 dev[2].dump_monitor()
413 dev[2].request("WPS_PIN any " + pin)
414 dev[2].wait_connected(timeout=30)
415 status = dev[2].get_status()
416 if status['wpa_state'] != 'COMPLETED':
417 raise Exception("Not fully connected")
418 dev[2].request("DISCONNECT")
420 logger.info("Connect legacy non-WPS client")
421 dev[2].request("FLUSH")
422 dev[2].request("P2P_SET disabled 1")
423 dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
424 key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
425 scan_freq=res['freq'])
426 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
427 dev[2].request("DISCONNECT")
429 dev[0].remove_group()
430 dev[1].wait_go_ending_session()
432 dev[0].request("SET p2p_passphrase_len 8")
434 def test_autogo_bridge(dev):
435 """P2P autonomous GO in a bridge"""
437 # use autoscan to set scan_req = MANUAL_SCAN_REQ
438 if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
439 raise Exception("Failed to set autoscan")
441 ifname = dev[0].get_group_ifname()
442 subprocess.call(['brctl', 'addbr', 'p2p-br0'])
443 subprocess.call(['brctl', 'setfd', 'p2p-br0', '0'])
444 subprocess.call(['brctl', 'addif', 'p2p-br0', ifname])
445 subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
447 subprocess.call(['brctl', 'delif', 'p2p-br0', ifname])
449 subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
451 subprocess.call(['brctl', 'delbr', 'p2p-br0'])
452 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1)
454 raise Exception("P2P group removed unexpectedly")
455 if dev[0].get_group_status_field('wpa_state') != "COMPLETED":
456 raise Exception("Unexpected wpa_state")
457 dev[0].remove_group()
459 dev[0].request("AUTOSCAN ")
460 subprocess.Popen(['brctl', 'delif', 'p2p-br0', ifname],
461 stderr=open('/dev/null', 'w'))
462 subprocess.Popen(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'],
463 stderr=open('/dev/null', 'w'))
464 subprocess.Popen(['brctl', 'delbr', 'p2p-br0'],
465 stderr=open('/dev/null', 'w'))
467 def test_presence_req_on_group_interface(dev):
468 """P2P_PRESENCE_REQ on group interface"""
469 dev[1].request("SET p2p_no_group_iface 0")
470 res = autogo(dev[0], freq=2437)
471 res = connect_cli(dev[0], dev[1], social=True, freq=2437)
472 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
473 raise Exception("Could not send presence request")
474 ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
476 raise Exception("Timeout while waiting for Presence Response")
477 dev[0].remove_group()
478 dev[1].wait_go_ending_session()
480 def test_autogo_join_auto_go_not_found(dev):
481 """P2P_CONNECT-auto not finding GO"""
482 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
483 wpas.interface_add("wlan5")
484 wpas.request("P2P_SET listen_channel 1")
485 wpas.global_request("SET p2p_no_group_iface 0")
486 autogo(wpas, freq=2412)
487 addr = wpas.p2p_dev_addr()
488 bssid = wpas.p2p_interface_addr()
490 dev[1].global_request("SET p2p_no_group_iface 0")
491 dev[1].scan_for_bss(bssid, freq=2412)
492 # This makes the GO not show up in the scan iteration following the
493 # P2P_CONNECT command by stopping beaconing and handling Probe Request
494 # frames externally (but not really replying to them). P2P listen mode is
495 # needed to keep the GO listening on the operating channel for the PD
497 if "OK" not in wpas.group_request("STOP_AP"):
498 raise Exception("STOP_AP failed")
499 wpas.group_request("SET ext_mgmt_frame_handling 1")
502 dev[1].global_request("P2P_CONNECT " + addr + " pbc auto")
504 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15)
506 raise Exception("Could not trigger old-scan-only case")
509 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15)
512 raise Exception("Fallback to GO Negotiation not seen")
513 if "reason=GO-not-found" not in ev:
514 raise Exception("Unexpected reason for fallback: " + ev)
516 def test_autogo_join_auto(dev):
517 """P2P_CONNECT-auto joining a group"""
519 addr = dev[0].p2p_dev_addr()
520 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
521 raise Exception("P2P_CONNECT failed")
523 ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15)
525 raise Exception("Timeout on P2P-PROV-DISC-PBC-REQ")
526 if "group=" + dev[0].group_ifname not in ev:
527 raise Exception("Unexpected PD event contents: " + ev)
528 dev[0].group_request("WPS_PBC")
530 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
532 raise Exception("Joining the group timed out")
533 dev[1].group_form_result(ev)
535 dev[0].remove_group()
536 dev[1].wait_go_ending_session()
537 dev[1].flush_scan_cache()
539 def test_autogo_join_auto_go_neg(dev):
540 """P2P_CONNECT-auto fallback to GO Neg"""
541 dev[1].flush_scan_cache()
543 addr = dev[0].p2p_dev_addr()
544 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
545 raise Exception("P2P_CONNECT failed")
547 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
549 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
550 peer = ev.split(' ')[1]
551 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
553 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
555 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
556 if "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev:
557 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
559 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
560 if "reason=peer-not-running-GO" not in ev:
561 raise Exception("Unexpected reason: " + ev)
563 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
565 raise Exception("Joining the group timed out")
566 dev[1].group_form_result(ev)
568 dev[0].remove_group()
569 dev[1].wait_go_ending_session()
570 dev[1].flush_scan_cache()
572 def test_autogo_join_auto_go_neg_after_seeing_go(dev):
573 """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
574 autogo(dev[0], freq=2412)
575 addr = dev[0].p2p_dev_addr()
576 bssid = dev[0].p2p_interface_addr()
577 dev[1].scan_for_bss(bssid, freq=2412)
578 dev[0].remove_group()
581 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"):
582 raise Exception("P2P_CONNECT failed")
584 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
587 raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
589 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
591 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
592 peer = ev.split(' ')[1]
593 dev[0].p2p_go_neg_init(peer, None, "pbc", timeout=15, go_intent=15)
595 ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1)
597 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
598 if "reason=no-ACK-to-PD-Req" not in ev and "reason=PD-failed" not in ev:
599 raise Exception("Unexpected reason: " + ev)
601 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
603 raise Exception("Joining the group timed out")
604 dev[1].group_form_result(ev)
606 dev[0].remove_group()
607 dev[1].wait_go_ending_session()
608 dev[1].flush_scan_cache()
610 def test_go_search_non_social(dev):
611 """P2P_FIND with freq parameter to scan a single channel"""
612 addr0 = dev[0].p2p_dev_addr()
613 autogo(dev[0], freq=2422)
614 dev[1].p2p_find(freq=2422)
615 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5)
617 raise Exception("Did not find GO quickly enough")
619 ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5)
621 raise Exception("Did not find peer")
622 dev[2].p2p_stop_find()
623 dev[1].p2p_stop_find()
624 dev[0].remove_group()
626 def test_autogo_many(dev):
627 """P2P autonomous GO with large number of GO instances"""
628 dev[0].request("SET p2p_no_group_iface 0")
630 if "OK" not in dev[0].global_request("P2P_GROUP_ADD freq=2412"):
631 logger.info("Was able to add %d groups" % i)
633 raise Exception("P2P_GROUP_ADD failed")
634 stop_ev = dev[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout=1)
635 if stop_ev is not None:
636 raise Exception("Unexpected P2P-GROUP-REMOVE event")
638 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
640 raise Exception("GO start up timed out")
641 dev[0].group_form_result(ev)
643 for i in dev[0].global_request("INTERFACES").splitlines():
644 dev[0].request("P2P_GROUP_REMOVE " + i)
645 dev[0].dump_monitor()
646 dev[0].request("P2P_GROUP_REMOVE *")
648 def test_autogo_many_clients(dev):
649 """P2P autonomous GO and many clients (P2P IE fragmentation)"""
651 _test_autogo_many_clients(dev)
653 dev[0].global_request("SET device_name Device A")
654 dev[1].global_request("SET device_name Device B")
655 dev[2].global_request("SET device_name Device C")
657 def _test_autogo_many_clients(dev):
658 # These long device names will push the P2P IE contents beyond the limit
659 # that requires fragmentation.
660 name0 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
661 name1 = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
662 name2 = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
663 name3 = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
664 dev[0].global_request("SET device_name " + name0)
665 dev[1].global_request("SET device_name " + name1)
666 dev[2].global_request("SET device_name " + name2)
668 addr0 = dev[0].p2p_dev_addr()
669 res = autogo(dev[0], freq=2412)
670 bssid = dev[0].p2p_interface_addr()
672 connect_cli(dev[0], dev[1], social=True, freq=2412)
673 dev[0].dump_monitor()
674 connect_cli(dev[0], dev[2], social=True, freq=2412)
675 dev[0].dump_monitor()
677 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
678 wpas.interface_add("wlan5")
679 wpas.global_request("SET device_name " + name3)
680 wpas.global_request("SET sec_device_type 1-11111111-1")
681 wpas.global_request("SET sec_device_type 2-22222222-2")
682 wpas.global_request("SET sec_device_type 3-33333333-3")
683 wpas.global_request("SET sec_device_type 4-44444444-4")
684 wpas.global_request("SET sec_device_type 5-55555555-5")
685 connect_cli(dev[0], wpas, social=True, freq=2412)
686 dev[0].dump_monitor()
688 dev[1].dump_monitor()
689 dev[1].p2p_find(freq=2412)
690 ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
692 raise Exception("Could not find peer (1)")
693 ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
695 raise Exception("Could not find peer (2)")
696 ev3 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
698 raise Exception("Could not find peer (3)")
699 dev[1].p2p_stop_find()
701 for i in [ name0, name2, name3 ]:
702 if i not in ev1 and i not in ev2 and i not in ev3:
703 raise Exception('name "%s" not found' % i)