]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_autogo.py
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.
7 from remotehost
import remote_compatible
11 logger
= logging
.getLogger()
16 from utils
import HwsimSkip
17 from wlantest
import Wlantest
18 from wpasupplicant
import WpaSupplicant
19 from p2p_utils
import *
20 from test_p2p_messages
import mgmt_tx
, parse_p2p_public_action
23 """P2P autonomous GO and client joining group"""
24 addr0
= dev
[0].p2p_dev_addr()
25 addr2
= dev
[2].p2p_dev_addr()
27 if "p2p-wlan" in res
['ifname']:
28 raise Exception("Unexpected group interface name on GO")
29 res
= connect_cli(dev
[0], dev
[1])
30 if "p2p-wlan" in res
['ifname']:
31 raise Exception("Unexpected group interface name on client")
32 bss
= dev
[1].get_bss("p2p_dev_addr=" + addr0
, res
['ifname'])
33 if not bss
or bss
['bssid'] != dev
[0].p2p_interface_addr():
34 raise Exception("Unexpected BSSID in the BSS entry for the GO")
36 bss
= dev
[1].get_bss("ID-" + id, res
['ifname'])
37 if not bss
or bss
['id'] != id:
38 raise Exception("Could not find BSS entry based on id")
39 res
= dev
[1].group_request("BSS RANGE=" + id + "- MASK=0x1")
40 if "id=" + id not in res
:
41 raise Exception("Could not find BSS entry based on id range")
43 res
= dev
[1].request("SCAN_RESULTS")
44 if "[P2P]" not in res
:
45 raise Exception("P2P flag missing from scan results: " + res
)
47 # Presence request to increase testing coverage
48 if "FAIL" not in dev
[1].group_request("P2P_PRESENCE_REQ 30000"):
49 raise Exception("Invald P2P_PRESENCE_REQ accepted")
50 if "FAIL" not in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400 30001"):
51 raise Exception("Invald P2P_PRESENCE_REQ accepted")
52 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
53 raise Exception("Could not send presence request")
54 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10)
56 raise Exception("Timeout while waiting for Presence Response")
57 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400 20000 102400"):
58 raise Exception("Could not send presence request")
59 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
61 raise Exception("Timeout while waiting for Presence Response")
62 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ"):
63 raise Exception("Could not send presence request")
64 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
66 raise Exception("Timeout while waiting for Presence Response")
68 if not dev
[2].discover_peer(addr0
):
69 raise Exception("Could not discover GO")
71 dev
[2].global_request("P2P_PROV_DISC " + addr0
+ " display join")
72 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=10)
74 raise Exception("GO did not report P2P-PROV-DISC-SHOW-PIN")
75 if "p2p_dev_addr=" + addr2
not in ev
:
76 raise Exception("Unexpected P2P Device Address in event: " + ev
)
77 if "group=" + dev
[0].group_ifname
not in ev
:
78 raise Exception("Unexpected group interface in event: " + ev
)
79 ev
= dev
[2].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=10)
81 raise Exception("P2P-PROV-DISC-ENTER-PIN not reported")
84 dev
[1].wait_go_ending_session()
86 def test_autogo2(dev
):
87 """P2P autonomous GO with a separate group interface and client joining group"""
88 dev
[0].global_request("SET p2p_no_group_iface 0")
89 res
= autogo(dev
[0], freq
=2437)
90 if "p2p-wlan" not in res
['ifname']:
91 raise Exception("Unexpected group interface name on GO")
92 if res
['ifname'] not in utils
.get_ifnames():
93 raise Exception("Could not find group interface netdev")
94 connect_cli(dev
[0], dev
[1], social
=True, freq
=2437)
96 dev
[1].wait_go_ending_session()
97 if res
['ifname'] in utils
.get_ifnames():
98 raise Exception("Group interface netdev was not removed")
100 def test_autogo3(dev
):
101 """P2P autonomous GO and client with a separate group interface joining group"""
102 dev
[1].global_request("SET p2p_no_group_iface 0")
103 autogo(dev
[0], freq
=2462)
104 res
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
105 if "p2p-wlan" not in res
['ifname']:
106 raise Exception("Unexpected group interface name on client")
107 if res
['ifname'] not in utils
.get_ifnames():
108 raise Exception("Could not find group interface netdev")
109 dev
[0].remove_group()
110 dev
[1].wait_go_ending_session()
112 if res
['ifname'] in utils
.get_ifnames():
113 raise Exception("Group interface netdev was not removed")
115 def test_autogo4(dev
):
116 """P2P autonomous GO and client joining group (both with a separate group interface)"""
117 dev
[0].global_request("SET p2p_no_group_iface 0")
118 dev
[1].global_request("SET p2p_no_group_iface 0")
119 res1
= autogo(dev
[0], freq
=2412)
120 res2
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
121 if "p2p-wlan" not in res1
['ifname']:
122 raise Exception("Unexpected group interface name on GO")
123 if "p2p-wlan" not in res2
['ifname']:
124 raise Exception("Unexpected group interface name on client")
125 ifnames
= utils
.get_ifnames()
126 if res1
['ifname'] not in ifnames
:
127 raise Exception("Could not find GO group interface netdev")
128 if res2
['ifname'] not in ifnames
:
129 raise Exception("Could not find client group interface netdev")
130 dev
[0].remove_group()
131 dev
[1].wait_go_ending_session()
133 ifnames
= utils
.get_ifnames()
134 if res1
['ifname'] in ifnames
:
135 raise Exception("GO group interface netdev was not removed")
136 if res2
['ifname'] in ifnames
:
137 raise Exception("Client group interface netdev was not removed")
139 def test_autogo_m2d(dev
):
140 """P2P autonomous GO and clients not authorized"""
141 autogo(dev
[0], freq
=2412)
142 go_addr
= dev
[0].p2p_dev_addr()
144 dev
[1].global_request("SET p2p_no_group_iface 0")
145 if not dev
[1].discover_peer(go_addr
, social
=True):
146 raise Exception("GO " + go_addr
+ " not found")
147 dev
[1].dump_monitor()
149 if not dev
[2].discover_peer(go_addr
, social
=True):
150 raise Exception("GO " + go_addr
+ " not found")
151 dev
[2].dump_monitor()
153 logger
.info("Trying to join the group when GO has not authorized the client")
154 pin
= dev
[1].wps_read_pin()
155 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
156 if "OK" not in dev
[1].global_request(cmd
):
157 raise Exception("P2P_CONNECT join failed")
159 pin
= dev
[2].wps_read_pin()
160 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
161 if "OK" not in dev
[2].global_request(cmd
):
162 raise Exception("P2P_CONNECT join failed")
164 ev
= dev
[1].wait_global_event(["WPS-M2D"], timeout
=16)
166 raise Exception("No global M2D event")
167 ifaces
= dev
[1].request("INTERFACES").splitlines()
168 iface
= ifaces
[0] if "p2p-wlan" in ifaces
[0] else ifaces
[1]
169 wpas
= WpaSupplicant(ifname
=iface
)
170 ev
= wpas
.wait_event(["WPS-M2D"], timeout
=10)
172 raise Exception("No M2D event on group interface")
174 ev
= dev
[2].wait_global_event(["WPS-M2D"], timeout
=10)
176 raise Exception("No global M2D event (2)")
177 ev
= dev
[2].wait_event(["WPS-M2D"], timeout
=10)
179 raise Exception("No M2D event on group interface (2)")
182 def test_autogo_fail(dev
):
183 """P2P autonomous GO and incorrect PIN"""
184 autogo(dev
[0], freq
=2412)
185 go_addr
= dev
[0].p2p_dev_addr()
186 dev
[0].p2p_go_authorize_client("00000000")
188 dev
[1].global_request("SET p2p_no_group_iface 0")
189 if not dev
[1].discover_peer(go_addr
, social
=True):
190 raise Exception("GO " + go_addr
+ " not found")
191 dev
[1].dump_monitor()
193 logger
.info("Trying to join the group when GO has not authorized the client")
194 pin
= dev
[1].wps_read_pin()
195 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
196 if "OK" not in dev
[1].global_request(cmd
):
197 raise Exception("P2P_CONNECT join failed")
199 ev
= dev
[1].wait_global_event(["WPS-FAIL"], timeout
=10)
201 raise Exception("No global WPS-FAIL event")
203 def test_autogo_2cli(dev
):
204 """P2P autonomous GO and two clients joining group"""
205 autogo(dev
[0], freq
=2412)
206 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
207 connect_cli(dev
[0], dev
[2], social
=True, freq
=2412)
208 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
209 dev
[0].global_request("P2P_REMOVE_CLIENT " + dev
[1].p2p_dev_addr())
210 dev
[1].wait_go_ending_session()
211 dev
[0].global_request("P2P_REMOVE_CLIENT iface=" + dev
[2].p2p_interface_addr())
212 dev
[2].wait_go_ending_session()
213 if "FAIL" not in dev
[0].global_request("P2P_REMOVE_CLIENT foo"):
214 raise Exception("Invalid P2P_REMOVE_CLIENT command accepted")
215 dev
[0].remove_group()
217 def test_autogo_pbc(dev
):
218 """P2P autonomous GO and PBC"""
219 dev
[1].global_request("SET p2p_no_group_iface 0")
220 autogo(dev
[0], freq
=2412)
221 if "FAIL" not in dev
[0].group_request("WPS_PBC p2p_dev_addr=00:11:22:33:44"):
222 raise Exception("Invalid WPS_PBC succeeded")
223 if "OK" not in dev
[0].group_request("WPS_PBC p2p_dev_addr=" + dev
[1].p2p_dev_addr()):
224 raise Exception("WPS_PBC failed")
225 dev
[2].p2p_connect_group(dev
[0].p2p_dev_addr(), "pbc", timeout
=0,
227 ev
= dev
[2].wait_global_event(["WPS-M2D"], timeout
=15)
229 raise Exception("WPS-M2D not reported")
230 if "config_error=12" not in ev
:
231 raise Exception("Unexpected config_error: " + ev
)
232 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), "pbc", timeout
=15,
235 def test_autogo_pbc_session_overlap(dev
, apdev
):
236 """P2P autonomous GO and PBC session overlap"""
237 params
= {"ssid": "wps", "eap_server": "1", "wps_state": "1"}
238 hapd
= hostapd
.add_ap(apdev
[0], params
)
239 hapd
.request("WPS_PBC")
240 bssid
= hapd
.own_addr()
243 dev
[0].scan_for_bss(bssid
, freq
=2412)
244 dev
[1].scan_for_bss(bssid
, freq
=2412)
246 dev
[1].global_request("SET p2p_no_group_iface 0")
247 autogo(dev
[0], freq
=2412)
248 if "OK" not in dev
[0].group_request("WPS_PBC p2p_dev_addr=" + dev
[1].p2p_dev_addr()):
249 raise Exception("WPS_PBC failed")
250 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), "pbc", timeout
=15,
253 remove_group(dev
[0], dev
[1])
254 dev
[0].flush_scan_cache()
255 dev
[1].flush_scan_cache()
257 def test_autogo_tdls(dev
):
258 """P2P autonomous GO and two clients using TDLS"""
260 logger
.info("Start autonomous GO with fixed parameters " + go
.ifname
)
261 id = go
.add_network()
262 go
.set_network_quoted(id, "ssid", "DIRECT-tdls")
263 go
.set_network_quoted(id, "psk", "12345678")
264 go
.set_network(id, "mode", "3")
265 go
.set_network(id, "disabled", "2")
266 res
= go
.p2p_start_go(persistent
=id, freq
="2462")
267 logger
.debug("res: " + str(res
))
268 Wlantest
.setup(go
, True)
271 wt
.add_passphrase("12345678")
272 connect_cli(go
, dev
[1], social
=True, freq
=2462)
273 connect_cli(go
, dev
[2], social
=True, freq
=2462)
274 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
275 bssid
= dev
[0].p2p_interface_addr()
276 addr1
= dev
[1].p2p_interface_addr()
277 addr2
= dev
[2].p2p_interface_addr()
278 dev
[1].tdls_setup(addr2
)
280 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
281 conf
= wt
.get_tdls_counter("setup_conf_ok", bssid
, addr1
, addr2
)
283 raise Exception("No TDLS Setup Confirm (success) seen")
284 dl
= wt
.get_tdls_counter("valid_direct_link", bssid
, addr1
, addr2
)
286 raise Exception("No valid frames through direct link")
287 wt
.tdls_clear(bssid
, addr1
, addr2
)
288 dev
[1].tdls_teardown(addr2
)
290 teardown
= wt
.get_tdls_counter("teardown", bssid
, addr1
, addr2
)
292 raise Exception("No TDLS Setup Teardown seen")
293 wt
.tdls_clear(bssid
, addr1
, addr2
)
294 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
295 ap_path
= wt
.get_tdls_counter("valid_ap_path", bssid
, addr1
, addr2
)
297 raise Exception("No valid frames via AP path")
298 direct_link
= wt
.get_tdls_counter("valid_direct_link", bssid
, addr1
, addr2
)
300 raise Exception("Unexpected frames through direct link")
301 idirect_link
= wt
.get_tdls_counter("invalid_direct_link", bssid
, addr1
,
304 raise Exception("Unexpected frames through direct link (invalid)")
305 dev
[2].remove_group()
306 dev
[1].remove_group()
307 dev
[0].remove_group()
309 def test_autogo_legacy(dev
):
310 """P2P autonomous GO and legacy clients"""
311 res
= autogo(dev
[0], freq
=2462)
312 if dev
[0].get_group_status_field("passphrase", extra
="WPS") != res
['passphrase']:
313 raise Exception("passphrase mismatch")
314 if dev
[0].group_request("P2P_GET_PASSPHRASE") != res
['passphrase']:
315 raise Exception("passphrase mismatch(2)")
317 logger
.info("Connect P2P client")
318 connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
320 if "FAIL" not in dev
[1].request("P2P_GET_PASSPHRASE"):
321 raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client")
323 logger
.info("Connect legacy WPS client")
324 pin
= dev
[2].wps_read_pin()
325 dev
[0].p2p_go_authorize_client(pin
)
326 dev
[2].request("P2P_SET disabled 1")
327 dev
[2].dump_monitor()
328 dev
[2].request("WPS_PIN any " + pin
)
329 dev
[2].wait_connected(timeout
=30)
330 status
= dev
[2].get_status()
331 if status
['wpa_state'] != 'COMPLETED':
332 raise Exception("Not fully connected")
333 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
334 dev
[2].request("DISCONNECT")
336 logger
.info("Connect legacy non-WPS client")
337 dev
[2].request("FLUSH")
338 dev
[2].request("P2P_SET disabled 1")
339 dev
[2].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
340 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
341 scan_freq
=res
['freq'])
342 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
343 dev
[2].request("DISCONNECT")
345 dev
[0].remove_group()
346 dev
[1].wait_go_ending_session()
348 def test_autogo_chan_switch(dev
):
349 """P2P autonomous GO switching channels"""
350 run_autogo_chan_switch(dev
)
352 def run_autogo_chan_switch(dev
):
353 autogo(dev
[0], freq
=2417)
354 connect_cli(dev
[0], dev
[1], freq
=2417)
355 res
= dev
[0].group_request("CHAN_SWITCH 5 2422")
357 # for now, skip test since mac80211_hwsim support is not yet widely
359 raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
360 ev
= dev
[0].wait_group_event(["AP-CSA-FINISHED"], timeout
=10)
362 raise Exception("CSA finished event timed out")
363 if "freq=2422" not in ev
:
364 raise Exception("Unexpected cahnnel in CSA finished event")
365 dev
[0].dump_monitor()
366 dev
[1].dump_monitor()
368 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
370 dev
[0].remove_group()
371 dev
[1].wait_go_ending_session()
373 def test_autogo_chan_switch_group_iface(dev
):
374 """P2P autonomous GO switching channels (separate group interface)"""
375 dev
[0].global_request("SET p2p_no_group_iface 0")
376 run_autogo_chan_switch(dev
)
379 def test_autogo_extra_cred(dev
):
380 """P2P autonomous GO sending two WPS credentials"""
381 if "FAIL" in dev
[0].request("SET wps_testing_dummy_cred 1"):
382 raise Exception("Failed to enable test mode")
383 autogo(dev
[0], freq
=2412)
384 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
385 dev
[0].remove_group()
386 dev
[1].wait_go_ending_session()
388 def test_autogo_ifdown(dev
):
389 """P2P autonomous GO and external ifdown"""
390 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
391 wpas
.interface_add("wlan5")
394 wpas
.interface_remove("wlan5")
395 wpas
.interface_add("wlan5")
398 subprocess
.call(['ifconfig', res
['ifname'], 'down'])
399 ev
= wpas
.wait_global_event(["P2P-GROUP-REMOVED"], timeout
=10)
401 raise Exception("Group removal not reported")
402 if res
['ifname'] not in ev
:
403 raise Exception("Unexpected group removal event: " + ev
)
406 def test_autogo_start_during_scan(dev
):
407 """P2P autonomous GO started during ongoing manual scan"""
409 # use autoscan to set scan_req = MANUAL_SCAN_REQ
410 if "OK" not in dev
[0].request("AUTOSCAN periodic:1"):
411 raise Exception("Failed to set autoscan")
412 autogo(dev
[0], freq
=2462)
413 connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
414 dev
[0].remove_group()
415 dev
[1].wait_go_ending_session()
417 dev
[0].request("AUTOSCAN ")
419 def test_autogo_passphrase_len(dev
):
420 """P2P autonomous GO and longer passphrase"""
422 if "OK" not in dev
[0].request("SET p2p_passphrase_len 13"):
423 raise Exception("Failed to set passphrase length")
424 res
= autogo(dev
[0], freq
=2412)
425 if len(res
['passphrase']) != 13:
426 raise Exception("Unexpected passphrase length")
427 if dev
[0].get_group_status_field("passphrase", extra
="WPS") != res
['passphrase']:
428 raise Exception("passphrase mismatch")
430 logger
.info("Connect P2P client")
431 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
433 logger
.info("Connect legacy WPS client")
434 pin
= dev
[2].wps_read_pin()
435 dev
[0].p2p_go_authorize_client(pin
)
436 dev
[2].request("P2P_SET disabled 1")
437 dev
[2].dump_monitor()
438 dev
[2].request("WPS_PIN any " + pin
)
439 dev
[2].wait_connected(timeout
=30)
440 status
= dev
[2].get_status()
441 if status
['wpa_state'] != 'COMPLETED':
442 raise Exception("Not fully connected")
443 dev
[2].request("DISCONNECT")
445 logger
.info("Connect legacy non-WPS client")
446 dev
[2].request("FLUSH")
447 dev
[2].request("P2P_SET disabled 1")
448 dev
[2].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
449 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
450 scan_freq
=res
['freq'])
451 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
452 dev
[2].request("DISCONNECT")
454 dev
[0].remove_group()
455 dev
[1].wait_go_ending_session()
457 dev
[0].request("SET p2p_passphrase_len 8")
460 def test_autogo_bridge(dev
):
461 """P2P autonomous GO in a bridge"""
463 # use autoscan to set scan_req = MANUAL_SCAN_REQ
464 if "OK" not in dev
[0].request("AUTOSCAN periodic:1"):
465 raise Exception("Failed to set autoscan")
467 ifname
= dev
[0].get_group_ifname()
468 dev
[0].cmd_execute(['brctl', 'addbr', 'p2p-br0'])
469 dev
[0].cmd_execute(['brctl', 'setfd', 'p2p-br0', '0'])
470 dev
[0].cmd_execute(['brctl', 'addif', 'p2p-br0', ifname
])
471 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
473 dev
[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname
])
475 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
477 dev
[0].cmd_execute(['brctl', 'delbr', 'p2p-br0'])
478 ev
= dev
[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout
=1)
480 raise Exception("P2P group removed unexpectedly")
481 if dev
[0].get_group_status_field('wpa_state') != "COMPLETED":
482 raise Exception("Unexpected wpa_state")
483 dev
[0].remove_group()
485 dev
[0].request("AUTOSCAN ")
486 dev
[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname
,
487 '2>', '/dev/null'], shell
=True)
488 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down',
489 '2>', '/dev/null'], shell
=True)
490 dev
[0].cmd_execute(['brctl', 'delbr', 'p2p-br0', '2>', '/dev/null'],
494 def test_presence_req_on_group_interface(dev
):
495 """P2P_PRESENCE_REQ on group interface"""
496 dev
[1].global_request("SET p2p_no_group_iface 0")
497 res
= autogo(dev
[0], freq
=2437)
498 res
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2437)
499 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
500 raise Exception("Could not send presence request")
501 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
503 raise Exception("Timeout while waiting for Presence Response")
504 dev
[0].remove_group()
505 dev
[1].wait_go_ending_session()
507 def test_autogo_join_auto_go_not_found(dev
):
508 """P2P_CONNECT-auto not finding GO"""
509 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
510 wpas
.interface_add("wlan5")
511 wpas
.request("P2P_SET listen_channel 1")
512 wpas
.global_request("SET p2p_no_group_iface 0")
513 autogo(wpas
, freq
=2412)
514 addr
= wpas
.p2p_dev_addr()
515 bssid
= wpas
.p2p_interface_addr()
518 dev
[1].global_request("SET p2p_no_group_iface 0")
519 dev
[1].scan_for_bss(bssid
, freq
=2412)
520 # This makes the GO not show up in the scan iteration following the
521 # P2P_CONNECT command by stopping beaconing and handling Probe Request
522 # frames externally (but not really replying to them). P2P listen mode is
523 # needed to keep the GO listening on the operating channel for the PD
525 if "OK" not in wpas
.group_request("STOP_AP"):
526 raise Exception("STOP_AP failed")
528 wpas
.group_request("SET ext_mgmt_frame_handling 1")
532 dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto")
534 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15)
537 raise Exception("Could not trigger old-scan-only case")
540 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15)
543 raise Exception("Fallback to GO Negotiation not seen")
544 if "reason=GO-not-found" not in ev
:
545 raise Exception("Unexpected reason for fallback: " + ev
)
548 def test_autogo_join_auto(dev
):
549 """P2P_CONNECT-auto joining a group"""
551 addr
= dev
[0].p2p_dev_addr()
552 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
553 raise Exception("P2P_CONNECT failed")
555 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout
=15)
557 raise Exception("Timeout on P2P-PROV-DISC-PBC-REQ")
558 if "group=" + dev
[0].group_ifname
not in ev
:
559 raise Exception("Unexpected PD event contents: " + ev
)
560 dev
[0].group_request("WPS_PBC")
562 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
564 raise Exception("Joining the group timed out")
565 dev
[1].group_form_result(ev
)
567 dev
[0].remove_group()
568 dev
[1].wait_go_ending_session()
569 dev
[1].flush_scan_cache()
572 def test_autogo_join_auto_go_neg(dev
):
573 """P2P_CONNECT-auto fallback to GO Neg"""
574 dev
[1].flush_scan_cache()
576 addr
= dev
[0].p2p_dev_addr()
577 if not dev
[1].discover_peer(addr
, social
=True):
578 raise Exception("Peer not found")
579 dev
[1].p2p_stop_find()
580 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
581 raise Exception("P2P_CONNECT failed")
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 "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev
:
593 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout
=1)
595 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
596 if "reason=peer-not-running-GO" not in ev
:
597 raise Exception("Unexpected reason: " + ev
)
599 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
601 raise Exception("Joining the group timed out")
602 dev
[1].group_form_result(ev
)
604 dev
[0].remove_group()
605 dev
[1].wait_go_ending_session()
606 dev
[1].flush_scan_cache()
609 def test_autogo_join_auto_go_neg_after_seeing_go(dev
):
610 """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
611 autogo(dev
[0], freq
=2412)
612 addr
= dev
[0].p2p_dev_addr()
613 bssid
= dev
[0].p2p_interface_addr()
614 dev
[1].scan_for_bss(bssid
, freq
=2412)
615 dev
[0].remove_group()
618 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
619 raise Exception("P2P_CONNECT failed")
621 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
624 raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
626 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=15)
628 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
629 peer
= ev
.split(' ')[1]
630 dev
[0].p2p_go_neg_init(peer
, None, "pbc", timeout
=15, go_intent
=15)
632 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout
=1)
634 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
635 if "reason=no-ACK-to-PD-Req" not in ev
and "reason=PD-failed" not in ev
:
636 raise Exception("Unexpected reason: " + ev
)
638 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
640 raise Exception("Joining the group timed out")
641 dev
[1].group_form_result(ev
)
643 dev
[0].remove_group()
644 dev
[1].wait_go_ending_session()
645 dev
[1].flush_scan_cache()
647 def test_go_search_non_social(dev
):
648 """P2P_FIND with freq parameter to scan a single channel"""
649 addr0
= dev
[0].p2p_dev_addr()
650 autogo(dev
[0], freq
=2422)
651 dev
[1].p2p_find(freq
=2422)
652 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=3.5)
654 dev
[1].p2p_stop_find()
655 dev
[1].p2p_find(freq
=2422)
656 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=3.5)
658 raise Exception("Did not find GO quickly enough")
660 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
662 raise Exception("Did not find peer")
663 dev
[2].p2p_stop_find()
664 dev
[1].p2p_stop_find()
665 dev
[0].remove_group()
667 def test_go_search_non_social2(dev
):
668 """P2P_FIND with freq parameter to scan a single channel (2)"""
669 addr0
= dev
[0].p2p_dev_addr()
670 dev
[1].p2p_find(freq
=2422)
671 # Wait for the first p2p_find scan round to complete before starting GO
673 autogo(dev
[0], freq
=2422)
674 # Verify that p2p_find is still scanning the specified frequency
675 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
677 dev
[1].p2p_stop_find()
678 raise Exception("Did not find GO quickly enough")
679 # Verify that p2p_find is scanning the social channels
681 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
683 raise Exception("Did not find peer")
684 dev
[2].p2p_stop_find()
685 dev
[1].p2p_stop_find()
686 dev
[0].remove_group()
687 dev
[1].dump_monitor()
689 # Verify that social channel as the specific channel works
690 dev
[1].p2p_find(freq
=2412)
693 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
695 raise Exception("Did not find peer (2)")
697 def test_autogo_many(dev
):
698 """P2P autonomous GO with large number of GO instances"""
699 dev
[0].global_request("SET p2p_no_group_iface 0")
701 if "OK" not in dev
[0].global_request("P2P_GROUP_ADD freq=2412"):
702 logger
.info("Was able to add %d groups" % i
)
704 raise Exception("P2P_GROUP_ADD failed")
705 stop_ev
= dev
[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout
=1)
706 if stop_ev
is not None:
707 raise Exception("Unexpected P2P-GROUP-REMOVE event")
709 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5)
711 raise Exception("GO start up timed out")
712 dev
[0].group_form_result(ev
)
714 for i
in dev
[0].global_request("INTERFACES").splitlines():
715 dev
[0].request("P2P_GROUP_REMOVE " + i
)
716 dev
[0].dump_monitor()
717 dev
[0].request("P2P_GROUP_REMOVE *")
719 def test_autogo_many_clients(dev
):
720 """P2P autonomous GO and many clients (P2P IE fragmentation)"""
722 _test_autogo_many_clients(dev
)
724 dev
[0].global_request("SET device_name Device A")
725 dev
[1].global_request("SET device_name Device B")
726 dev
[2].global_request("SET device_name Device C")
728 def _test_autogo_many_clients(dev
):
729 # These long device names will push the P2P IE contents beyond the limit
730 # that requires fragmentation.
731 name0
= "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
732 name1
= "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
733 name2
= "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
734 name3
= "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
735 dev
[0].global_request("SET device_name " + name0
)
736 dev
[1].global_request("SET device_name " + name1
)
737 dev
[2].global_request("SET device_name " + name2
)
739 addr0
= dev
[0].p2p_dev_addr()
740 res
= autogo(dev
[0], freq
=2412)
741 bssid
= dev
[0].p2p_interface_addr()
743 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
744 dev
[0].dump_monitor()
745 connect_cli(dev
[0], dev
[2], social
=True, freq
=2412)
746 dev
[0].dump_monitor()
748 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
749 wpas
.interface_add("wlan5")
750 wpas
.global_request("SET device_name " + name3
)
751 wpas
.global_request("SET sec_device_type 1-11111111-1")
752 wpas
.global_request("SET sec_device_type 2-22222222-2")
753 wpas
.global_request("SET sec_device_type 3-33333333-3")
754 wpas
.global_request("SET sec_device_type 4-44444444-4")
755 wpas
.global_request("SET sec_device_type 5-55555555-5")
756 connect_cli(dev
[0], wpas
, social
=True, freq
=2412)
757 dev
[0].dump_monitor()
759 dev
[1].dump_monitor()
760 dev
[1].p2p_find(freq
=2412)
761 ev1
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
763 raise Exception("Could not find peer (1)")
764 ev2
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
766 raise Exception("Could not find peer (2)")
767 ev3
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
769 raise Exception("Could not find peer (3)")
770 dev
[1].p2p_stop_find()
772 for i
in [name0
, name2
, name3
]:
773 if i
not in ev1
and i
not in ev2
and i
not in ev3
:
774 raise Exception('name "%s" not found' % i
)
779 raise Exception("MGMT-RX timeout")
780 p2p
= parse_p2p_public_action(msg
['payload'])
782 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
783 if p2p
['subtype'] != P2P_PROV_DISC_REQ
:
784 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
785 p2p
['freq'] = msg
['freq']
789 def test_autogo_scan(dev
):
790 """P2P autonomous GO and no P2P IE in Probe Response scan results"""
791 addr0
= dev
[0].p2p_dev_addr()
792 addr1
= dev
[1].p2p_dev_addr()
793 dev
[0].p2p_start_go(freq
=2412, persistent
=True)
794 bssid
= dev
[0].p2p_interface_addr()
796 dev
[1].discover_peer(addr0
)
797 dev
[1].p2p_stop_find()
798 ev
= dev
[1].wait_global_event(["P2P-FIND-STOPPED"], timeout
=2)
800 dev
[1].flush_scan_cache()
802 pin
= dev
[1].wps_read_pin()
803 dev
[0].group_request("WPS_PIN any " + pin
)
806 dev
[1].request("SET p2p_disabled 1")
807 dev
[1].request("SCAN freq=2412")
808 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
810 raise Exception("Active scan did not complete")
812 dev
[1].request("SET p2p_disabled 0")
815 dev
[1].request("SCAN freq=2412 passive=1")
816 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
818 raise Exception("Scan did not complete")
820 # Disable management frame processing for a moment to skip Probe Response
822 dev
[0].group_request("SET ext_mgmt_frame_handling 1")
824 dev
[1].global_request("P2P_CONNECT " + bssid
+ " " + pin
+ " freq=2412 join")
826 # Skip the first Probe Request frame
827 ev
= dev
[0].wait_group_event(["MGMT-RX"], timeout
=10)
829 raise Exception("No Probe Request frame seen")
830 if not ev
.split(' ')[4].startswith("40"):
831 raise Exception("Not a Probe Request frame")
833 # If a P2P Device is not used, the PD Request will be received on the group
834 # interface (which is actually wlan0, since a separate interface is not
835 # used), which was set to external management frame handling, so need to
836 # reply to it manually.
837 res
= dev
[0].get_driver_status()
838 if not (int(res
['capa.flags'], 0) & 0x20000000):
839 # Reply to PD Request while still filtering Probe Request frames
840 msg
= rx_pd_req(dev
[0])
841 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr0
, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg
['dialog_token']))
843 # Skip Probe Request frames until something else is received
845 ev
= dev
[0].wait_group_event(["MGMT-RX"], timeout
=10)
847 raise Exception("No frame seen")
848 if not ev
.split(' ')[4].startswith("40"):
851 # Allow wpa_supplicant to process authentication and association
852 dev
[0].group_request("SET ext_mgmt_frame_handling 0")
854 # Joining the group should succeed and indicate persistent group based on
855 # Beacon frame P2P IE.
856 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=10)
858 raise Exception("Failed to join group")
859 if "[PERSISTENT]" not in ev
:
860 raise Exception("Did not recognize group as persistent")
861 dev
[0].remove_group()
862 dev
[1].wait_go_ending_session()
865 def test_autogo_join_before_found(dev
):
866 """P2P client joining a group before having found GO Device Address"""
867 dev
[0].global_request("SET p2p_no_group_iface 0")
868 res
= autogo(dev
[0], freq
=2412)
869 if "p2p-wlan" not in res
['ifname']:
870 raise Exception("Unexpected group interface name on GO")
871 status
= dev
[0].get_group_status()
872 bssid
= status
['bssid']
874 pin
= dev
[1].wps_read_pin()
875 dev
[0].p2p_go_authorize_client(pin
)
876 cmd
= "P2P_CONNECT " + bssid
+ " " + pin
+ " join freq=2412"
877 if "OK" not in dev
[1].global_request(cmd
):
878 raise Exception("P2P_CONNECT join failed")
879 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
881 raise Exception("Joining the group timed out")
882 dev
[0].remove_group()
883 dev
[1].wait_go_ending_session()
885 def test_autogo_noa(dev
):
886 """P2P autonomous GO and NoA"""
888 dev
[0].group_request("P2P_SET noa 1,5,20")
889 dev
[0].group_request("P2P_SET noa 255,10,50")
891 # Connect and disconnect legacy STA to check NoA special cases
893 dev
[1].request("SET p2p_disabled 1")
894 dev
[1].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
895 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
896 scan_freq
=res
['freq'])
897 dev
[0].group_request("P2P_SET noa 255,15,55")
898 dev
[1].request("DISCONNECT")
899 dev
[1].wait_disconnected()
901 dev
[1].request("SET p2p_disabled 0")
903 dev
[0].group_request("P2P_SET noa 0,0,0")
905 def test_autogo_interworking(dev
):
906 """P2P autonomous GO and Interworking"""
908 run_autogo_interworking(dev
)
910 dev
[0].set("go_interworking", "0")
912 def run_autogo_interworking(dev
):
913 dev
[0].global_request("SET go_interworking 1")
914 dev
[0].global_request("SET go_access_network_type 1")
915 dev
[0].global_request("SET go_internet 1")
916 dev
[0].global_request("SET go_venue_group 2")
917 dev
[0].global_request("SET go_venue_type 3")
919 bssid
= dev
[0].p2p_interface_addr()
920 dev
[1].scan_for_bss(bssid
, freq
=res
['freq'])
921 bss
= dev
[1].get_bss(bssid
)
922 dev
[0].remove_group()
923 if '6b03110203' not in bss
['ie']:
924 raise Exception("Interworking element not seen")