]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_autogo.py
e896323f181c11d4fb5a861c8ca5c32d725517d0
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()
15 from utils
import HwsimSkip
16 from wlantest
import Wlantest
17 from wpasupplicant
import WpaSupplicant
18 from p2p_utils
import *
19 from test_p2p_messages
import mgmt_tx
, parse_p2p_public_action
22 """P2P autonomous GO and client joining group"""
23 addr0
= dev
[0].p2p_dev_addr()
24 addr2
= dev
[2].p2p_dev_addr()
26 if "p2p-wlan" in res
['ifname']:
27 raise Exception("Unexpected group interface name on GO")
28 res
= connect_cli(dev
[0], dev
[1])
29 if "p2p-wlan" in res
['ifname']:
30 raise Exception("Unexpected group interface name on client")
31 bss
= dev
[1].get_bss("p2p_dev_addr=" + addr0
, res
['ifname'])
32 if not bss
or bss
['bssid'] != dev
[0].p2p_interface_addr():
33 raise Exception("Unexpected BSSID in the BSS entry for the GO")
35 bss
= dev
[1].get_bss("ID-" + id, res
['ifname'])
36 if not bss
or bss
['id'] != id:
37 raise Exception("Could not find BSS entry based on id")
38 res
= dev
[1].group_request("BSS RANGE=" + id + "- MASK=0x1")
39 if "id=" + id not in res
:
40 raise Exception("Could not find BSS entry based on id range")
42 res
= dev
[1].request("SCAN_RESULTS")
43 if "[P2P]" not in res
:
44 raise Exception("P2P flag missing from scan results: " + res
)
46 # Presence request to increase testing coverage
47 if "FAIL" not in dev
[1].group_request("P2P_PRESENCE_REQ 30000"):
48 raise Exception("Invald P2P_PRESENCE_REQ accepted")
49 if "FAIL" not in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400 30001"):
50 raise Exception("Invald P2P_PRESENCE_REQ accepted")
51 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
52 raise Exception("Could not send presence request")
53 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10)
55 raise Exception("Timeout while waiting for Presence Response")
56 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400 20000 102400"):
57 raise Exception("Could not send presence request")
58 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
60 raise Exception("Timeout while waiting for Presence Response")
61 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ"):
62 raise Exception("Could not send presence request")
63 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
65 raise Exception("Timeout while waiting for Presence Response")
67 if not dev
[2].discover_peer(addr0
):
68 raise Exception("Could not discover GO")
70 dev
[2].global_request("P2P_PROV_DISC " + addr0
+ " display join")
71 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=10)
73 raise Exception("GO did not report P2P-PROV-DISC-SHOW-PIN")
74 if "p2p_dev_addr=" + addr2
not in ev
:
75 raise Exception("Unexpected P2P Device Address in event: " + ev
)
76 if "group=" + dev
[0].group_ifname
not in ev
:
77 raise Exception("Unexpected group interface in event: " + ev
)
78 ev
= dev
[2].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=10)
80 raise Exception("P2P-PROV-DISC-ENTER-PIN not reported")
83 dev
[1].wait_go_ending_session()
85 def test_autogo2(dev
):
86 """P2P autonomous GO with a separate group interface and client joining group"""
87 dev
[0].global_request("SET p2p_no_group_iface 0")
88 res
= autogo(dev
[0], freq
=2437)
89 if "p2p-wlan" not in res
['ifname']:
90 raise Exception("Unexpected group interface name on GO")
91 if res
['ifname'] not in utils
.get_ifnames():
92 raise Exception("Could not find group interface netdev")
93 connect_cli(dev
[0], dev
[1], social
=True, freq
=2437)
95 dev
[1].wait_go_ending_session()
96 if res
['ifname'] in utils
.get_ifnames():
97 raise Exception("Group interface netdev was not removed")
99 def test_autogo3(dev
):
100 """P2P autonomous GO and client with a separate group interface joining group"""
101 dev
[1].global_request("SET p2p_no_group_iface 0")
102 autogo(dev
[0], freq
=2462)
103 res
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
104 if "p2p-wlan" not in res
['ifname']:
105 raise Exception("Unexpected group interface name on client")
106 if res
['ifname'] not in utils
.get_ifnames():
107 raise Exception("Could not find group interface netdev")
108 dev
[0].remove_group()
109 dev
[1].wait_go_ending_session()
111 if res
['ifname'] in utils
.get_ifnames():
112 raise Exception("Group interface netdev was not removed")
114 def test_autogo4(dev
):
115 """P2P autonomous GO and client joining group (both with a separate group interface)"""
116 dev
[0].global_request("SET p2p_no_group_iface 0")
117 dev
[1].global_request("SET p2p_no_group_iface 0")
118 res1
= autogo(dev
[0], freq
=2412)
119 res2
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
120 if "p2p-wlan" not in res1
['ifname']:
121 raise Exception("Unexpected group interface name on GO")
122 if "p2p-wlan" not in res2
['ifname']:
123 raise Exception("Unexpected group interface name on client")
124 ifnames
= utils
.get_ifnames()
125 if res1
['ifname'] not in ifnames
:
126 raise Exception("Could not find GO group interface netdev")
127 if res2
['ifname'] not in ifnames
:
128 raise Exception("Could not find client group interface netdev")
129 dev
[0].remove_group()
130 dev
[1].wait_go_ending_session()
132 ifnames
= utils
.get_ifnames()
133 if res1
['ifname'] in ifnames
:
134 raise Exception("GO group interface netdev was not removed")
135 if res2
['ifname'] in ifnames
:
136 raise Exception("Client group interface netdev was not removed")
138 def test_autogo_m2d(dev
):
139 """P2P autonomous GO and clients not authorized"""
140 autogo(dev
[0], freq
=2412)
141 go_addr
= dev
[0].p2p_dev_addr()
143 dev
[1].global_request("SET p2p_no_group_iface 0")
144 if not dev
[1].discover_peer(go_addr
, social
=True):
145 raise Exception("GO " + go_addr
+ " not found")
146 dev
[1].dump_monitor()
148 if not dev
[2].discover_peer(go_addr
, social
=True):
149 raise Exception("GO " + go_addr
+ " not found")
150 dev
[2].dump_monitor()
152 logger
.info("Trying to join the group when GO has not authorized the client")
153 pin
= dev
[1].wps_read_pin()
154 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
155 if "OK" not in dev
[1].global_request(cmd
):
156 raise Exception("P2P_CONNECT join failed")
158 pin
= dev
[2].wps_read_pin()
159 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
160 if "OK" not in dev
[2].global_request(cmd
):
161 raise Exception("P2P_CONNECT join failed")
163 ev
= dev
[1].wait_global_event(["WPS-M2D"], timeout
=16)
165 raise Exception("No global M2D event")
166 ifaces
= dev
[1].request("INTERFACES").splitlines()
167 iface
= ifaces
[0] if "p2p-wlan" in ifaces
[0] else ifaces
[1]
168 wpas
= WpaSupplicant(ifname
=iface
)
169 ev
= wpas
.wait_event(["WPS-M2D"], timeout
=10)
171 raise Exception("No M2D event on group interface")
173 ev
= dev
[2].wait_global_event(["WPS-M2D"], timeout
=10)
175 raise Exception("No global M2D event (2)")
176 ev
= dev
[2].wait_event(["WPS-M2D"], timeout
=10)
178 raise Exception("No M2D event on group interface (2)")
181 def test_autogo_fail(dev
):
182 """P2P autonomous GO and incorrect PIN"""
183 autogo(dev
[0], freq
=2412)
184 go_addr
= dev
[0].p2p_dev_addr()
185 dev
[0].p2p_go_authorize_client("00000000")
187 dev
[1].global_request("SET p2p_no_group_iface 0")
188 if not dev
[1].discover_peer(go_addr
, social
=True):
189 raise Exception("GO " + go_addr
+ " not found")
190 dev
[1].dump_monitor()
192 logger
.info("Trying to join the group when GO has not authorized the client")
193 pin
= dev
[1].wps_read_pin()
194 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
195 if "OK" not in dev
[1].global_request(cmd
):
196 raise Exception("P2P_CONNECT join failed")
198 ev
= dev
[1].wait_global_event(["WPS-FAIL"], timeout
=10)
200 raise Exception("No global WPS-FAIL event")
202 def test_autogo_2cli(dev
):
203 """P2P autonomous GO and two clients joining group"""
204 autogo(dev
[0], freq
=2412)
205 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
206 connect_cli(dev
[0], dev
[2], social
=True, freq
=2412)
207 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
208 dev
[0].global_request("P2P_REMOVE_CLIENT " + dev
[1].p2p_dev_addr())
209 dev
[1].wait_go_ending_session()
210 dev
[0].global_request("P2P_REMOVE_CLIENT iface=" + dev
[2].p2p_interface_addr())
211 dev
[2].wait_go_ending_session()
212 if "FAIL" not in dev
[0].global_request("P2P_REMOVE_CLIENT foo"):
213 raise Exception("Invalid P2P_REMOVE_CLIENT command accepted")
214 dev
[0].remove_group()
216 def test_autogo_pbc(dev
):
217 """P2P autonomous GO and PBC"""
218 dev
[1].global_request("SET p2p_no_group_iface 0")
219 autogo(dev
[0], freq
=2412)
220 if "FAIL" not in dev
[0].group_request("WPS_PBC p2p_dev_addr=00:11:22:33:44"):
221 raise Exception("Invalid WPS_PBC succeeded")
222 if "OK" not in dev
[0].group_request("WPS_PBC p2p_dev_addr=" + dev
[1].p2p_dev_addr()):
223 raise Exception("WPS_PBC failed")
224 dev
[2].p2p_connect_group(dev
[0].p2p_dev_addr(), "pbc", timeout
=0,
226 ev
= dev
[2].wait_global_event(["WPS-M2D"], timeout
=15)
228 raise Exception("WPS-M2D not reported")
229 if "config_error=12" not in ev
:
230 raise Exception("Unexpected config_error: " + ev
)
231 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), "pbc", timeout
=15,
234 def test_autogo_tdls(dev
):
235 """P2P autonomous GO and two clients using TDLS"""
237 logger
.info("Start autonomous GO with fixed parameters " + go
.ifname
)
238 id = go
.add_network()
239 go
.set_network_quoted(id, "ssid", "DIRECT-tdls")
240 go
.set_network_quoted(id, "psk", "12345678")
241 go
.set_network(id, "mode", "3")
242 go
.set_network(id, "disabled", "2")
243 res
= go
.p2p_start_go(persistent
=id, freq
="2462")
244 logger
.debug("res: " + str(res
))
245 Wlantest
.setup(go
, True)
248 wt
.add_passphrase("12345678")
249 connect_cli(go
, dev
[1], social
=True, freq
=2462)
250 connect_cli(go
, dev
[2], social
=True, freq
=2462)
251 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
252 bssid
= dev
[0].p2p_interface_addr()
253 addr1
= dev
[1].p2p_interface_addr()
254 addr2
= dev
[2].p2p_interface_addr()
255 dev
[1].tdls_setup(addr2
)
257 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
258 conf
= wt
.get_tdls_counter("setup_conf_ok", bssid
, addr1
, addr2
)
260 raise Exception("No TDLS Setup Confirm (success) seen")
261 dl
= wt
.get_tdls_counter("valid_direct_link", bssid
, addr1
, addr2
)
263 raise Exception("No valid frames through direct link")
264 wt
.tdls_clear(bssid
, addr1
, addr2
)
265 dev
[1].tdls_teardown(addr2
)
267 teardown
= wt
.get_tdls_counter("teardown", bssid
, addr1
, addr2
)
269 raise Exception("No TDLS Setup Teardown seen")
270 wt
.tdls_clear(bssid
, addr1
, addr2
)
271 hwsim_utils
.test_connectivity_p2p(dev
[1], dev
[2])
272 ap_path
= wt
.get_tdls_counter("valid_ap_path", bssid
, addr1
, addr2
)
274 raise Exception("No valid frames via AP path")
275 direct_link
= wt
.get_tdls_counter("valid_direct_link", bssid
, addr1
, addr2
)
277 raise Exception("Unexpected frames through direct link")
278 idirect_link
= wt
.get_tdls_counter("invalid_direct_link", bssid
, addr1
,
281 raise Exception("Unexpected frames through direct link (invalid)")
282 dev
[2].remove_group()
283 dev
[1].remove_group()
284 dev
[0].remove_group()
286 def test_autogo_legacy(dev
):
287 """P2P autonomous GO and legacy clients"""
288 res
= autogo(dev
[0], freq
=2462)
289 if dev
[0].get_group_status_field("passphrase", extra
="WPS") != res
['passphrase']:
290 raise Exception("passphrase mismatch")
291 if dev
[0].group_request("P2P_GET_PASSPHRASE") != res
['passphrase']:
292 raise Exception("passphrase mismatch(2)")
294 logger
.info("Connect P2P client")
295 connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
297 if "FAIL" not in dev
[1].request("P2P_GET_PASSPHRASE"):
298 raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client")
300 logger
.info("Connect legacy WPS client")
301 pin
= dev
[2].wps_read_pin()
302 dev
[0].p2p_go_authorize_client(pin
)
303 dev
[2].request("P2P_SET disabled 1")
304 dev
[2].dump_monitor()
305 dev
[2].request("WPS_PIN any " + pin
)
306 dev
[2].wait_connected(timeout
=30)
307 status
= dev
[2].get_status()
308 if status
['wpa_state'] != 'COMPLETED':
309 raise Exception("Not fully connected")
310 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
311 dev
[2].request("DISCONNECT")
313 logger
.info("Connect legacy non-WPS client")
314 dev
[2].request("FLUSH")
315 dev
[2].request("P2P_SET disabled 1")
316 dev
[2].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
317 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
318 scan_freq
=res
['freq'])
319 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
320 dev
[2].request("DISCONNECT")
322 dev
[0].remove_group()
323 dev
[1].wait_go_ending_session()
325 def test_autogo_chan_switch(dev
):
326 """P2P autonomous GO switching channels"""
327 run_autogo_chan_switch(dev
)
329 def run_autogo_chan_switch(dev
):
330 autogo(dev
[0], freq
=2417)
331 connect_cli(dev
[0], dev
[1], freq
=2417)
332 res
= dev
[0].group_request("CHAN_SWITCH 5 2422")
334 # for now, skip test since mac80211_hwsim support is not yet widely
336 raise HwsimSkip("Assume mac80211_hwsim did not support channel switching")
337 ev
= dev
[0].wait_group_event(["AP-CSA-FINISHED"], timeout
=10)
339 raise Exception("CSA finished event timed out")
340 if "freq=2422" not in ev
:
341 raise Exception("Unexpected cahnnel in CSA finished event")
342 dev
[0].dump_monitor()
343 dev
[1].dump_monitor()
345 hwsim_utils
.test_connectivity_p2p(dev
[0], dev
[1])
347 dev
[0].remove_group()
348 dev
[1].wait_go_ending_session()
350 def test_autogo_chan_switch_group_iface(dev
):
351 """P2P autonomous GO switching channels (separate group interface)"""
352 dev
[0].global_request("SET p2p_no_group_iface 0")
353 run_autogo_chan_switch(dev
)
356 def test_autogo_extra_cred(dev
):
357 """P2P autonomous GO sending two WPS credentials"""
358 if "FAIL" in dev
[0].request("SET wps_testing_dummy_cred 1"):
359 raise Exception("Failed to enable test mode")
360 autogo(dev
[0], freq
=2412)
361 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
362 dev
[0].remove_group()
363 dev
[1].wait_go_ending_session()
365 def test_autogo_ifdown(dev
):
366 """P2P autonomous GO and external ifdown"""
367 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
368 wpas
.interface_add("wlan5")
371 wpas
.interface_remove("wlan5")
372 wpas
.interface_add("wlan5")
375 subprocess
.call(['ifconfig', res
['ifname'], 'down'])
376 ev
= wpas
.wait_global_event(["P2P-GROUP-REMOVED"], timeout
=10)
378 raise Exception("Group removal not reported")
379 if res
['ifname'] not in ev
:
380 raise Exception("Unexpected group removal event: " + ev
)
383 def test_autogo_start_during_scan(dev
):
384 """P2P autonomous GO started during ongoing manual scan"""
386 # use autoscan to set scan_req = MANUAL_SCAN_REQ
387 if "OK" not in dev
[0].request("AUTOSCAN periodic:1"):
388 raise Exception("Failed to set autoscan")
389 autogo(dev
[0], freq
=2462)
390 connect_cli(dev
[0], dev
[1], social
=True, freq
=2462)
391 dev
[0].remove_group()
392 dev
[1].wait_go_ending_session()
394 dev
[0].request("AUTOSCAN ")
396 def test_autogo_passphrase_len(dev
):
397 """P2P autonomous GO and longer passphrase"""
399 if "OK" not in dev
[0].request("SET p2p_passphrase_len 13"):
400 raise Exception("Failed to set passphrase length")
401 res
= autogo(dev
[0], freq
=2412)
402 if len(res
['passphrase']) != 13:
403 raise Exception("Unexpected passphrase length")
404 if dev
[0].get_group_status_field("passphrase", extra
="WPS") != res
['passphrase']:
405 raise Exception("passphrase mismatch")
407 logger
.info("Connect P2P client")
408 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
410 logger
.info("Connect legacy WPS client")
411 pin
= dev
[2].wps_read_pin()
412 dev
[0].p2p_go_authorize_client(pin
)
413 dev
[2].request("P2P_SET disabled 1")
414 dev
[2].dump_monitor()
415 dev
[2].request("WPS_PIN any " + pin
)
416 dev
[2].wait_connected(timeout
=30)
417 status
= dev
[2].get_status()
418 if status
['wpa_state'] != 'COMPLETED':
419 raise Exception("Not fully connected")
420 dev
[2].request("DISCONNECT")
422 logger
.info("Connect legacy non-WPS client")
423 dev
[2].request("FLUSH")
424 dev
[2].request("P2P_SET disabled 1")
425 dev
[2].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
426 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
427 scan_freq
=res
['freq'])
428 hwsim_utils
.test_connectivity_p2p_sta(dev
[1], dev
[2])
429 dev
[2].request("DISCONNECT")
431 dev
[0].remove_group()
432 dev
[1].wait_go_ending_session()
434 dev
[0].request("SET p2p_passphrase_len 8")
437 def test_autogo_bridge(dev
):
438 """P2P autonomous GO in a bridge"""
440 # use autoscan to set scan_req = MANUAL_SCAN_REQ
441 if "OK" not in dev
[0].request("AUTOSCAN periodic:1"):
442 raise Exception("Failed to set autoscan")
444 ifname
= dev
[0].get_group_ifname()
445 dev
[0].cmd_execute(['brctl', 'addbr', 'p2p-br0'])
446 dev
[0].cmd_execute(['brctl', 'setfd', 'p2p-br0', '0'])
447 dev
[0].cmd_execute(['brctl', 'addif', 'p2p-br0', ifname
])
448 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
450 dev
[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname
])
452 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
454 dev
[0].cmd_execute(['brctl', 'delbr', 'p2p-br0'])
455 ev
= dev
[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout
=1)
457 raise Exception("P2P group removed unexpectedly")
458 if dev
[0].get_group_status_field('wpa_state') != "COMPLETED":
459 raise Exception("Unexpected wpa_state")
460 dev
[0].remove_group()
462 dev
[0].request("AUTOSCAN ")
463 dev
[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname
,
464 '2>', '/dev/null'], shell
=True)
465 dev
[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down',
466 '2>', '/dev/null'], shell
=True)
467 dev
[0].cmd_execute(['brctl', 'delbr', 'p2p-br0', '2>', '/dev/null'],
471 def test_presence_req_on_group_interface(dev
):
472 """P2P_PRESENCE_REQ on group interface"""
473 dev
[1].global_request("SET p2p_no_group_iface 0")
474 res
= autogo(dev
[0], freq
=2437)
475 res
= connect_cli(dev
[0], dev
[1], social
=True, freq
=2437)
476 if "FAIL" in dev
[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
477 raise Exception("Could not send presence request")
478 ev
= dev
[1].wait_group_event(["P2P-PRESENCE-RESPONSE"])
480 raise Exception("Timeout while waiting for Presence Response")
481 dev
[0].remove_group()
482 dev
[1].wait_go_ending_session()
484 def test_autogo_join_auto_go_not_found(dev
):
485 """P2P_CONNECT-auto not finding GO"""
486 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
487 wpas
.interface_add("wlan5")
488 wpas
.request("P2P_SET listen_channel 1")
489 wpas
.global_request("SET p2p_no_group_iface 0")
490 autogo(wpas
, freq
=2412)
491 addr
= wpas
.p2p_dev_addr()
492 bssid
= wpas
.p2p_interface_addr()
495 dev
[1].global_request("SET p2p_no_group_iface 0")
496 dev
[1].scan_for_bss(bssid
, freq
=2412)
497 # This makes the GO not show up in the scan iteration following the
498 # P2P_CONNECT command by stopping beaconing and handling Probe Request
499 # frames externally (but not really replying to them). P2P listen mode is
500 # needed to keep the GO listening on the operating channel for the PD
502 if "OK" not in wpas
.group_request("STOP_AP"):
503 raise Exception("STOP_AP failed")
505 wpas
.group_request("SET ext_mgmt_frame_handling 1")
509 dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto")
511 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15)
514 raise Exception("Could not trigger old-scan-only case")
517 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15)
520 raise Exception("Fallback to GO Negotiation not seen")
521 if "reason=GO-not-found" not in ev
:
522 raise Exception("Unexpected reason for fallback: " + ev
)
525 def test_autogo_join_auto(dev
):
526 """P2P_CONNECT-auto joining a group"""
528 addr
= dev
[0].p2p_dev_addr()
529 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
530 raise Exception("P2P_CONNECT failed")
532 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout
=15)
534 raise Exception("Timeout on P2P-PROV-DISC-PBC-REQ")
535 if "group=" + dev
[0].group_ifname
not in ev
:
536 raise Exception("Unexpected PD event contents: " + ev
)
537 dev
[0].group_request("WPS_PBC")
539 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
541 raise Exception("Joining the group timed out")
542 dev
[1].group_form_result(ev
)
544 dev
[0].remove_group()
545 dev
[1].wait_go_ending_session()
546 dev
[1].flush_scan_cache()
549 def test_autogo_join_auto_go_neg(dev
):
550 """P2P_CONNECT-auto fallback to GO Neg"""
551 dev
[1].flush_scan_cache()
553 addr
= dev
[0].p2p_dev_addr()
554 if not dev
[1].discover_peer(addr
, social
=True):
555 raise Exception("Peer not found")
556 dev
[1].p2p_stop_find()
557 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
558 raise Exception("P2P_CONNECT failed")
560 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=15)
562 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
563 peer
= ev
.split(' ')[1]
564 dev
[0].p2p_go_neg_init(peer
, None, "pbc", timeout
=15, go_intent
=15)
566 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout
=1)
568 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
569 if "P2P-FALLBACK-TO-GO-NEG-ENABLED" in ev
:
570 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout
=1)
572 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
573 if "reason=peer-not-running-GO" not in ev
:
574 raise Exception("Unexpected reason: " + ev
)
576 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
578 raise Exception("Joining the group timed out")
579 dev
[1].group_form_result(ev
)
581 dev
[0].remove_group()
582 dev
[1].wait_go_ending_session()
583 dev
[1].flush_scan_cache()
586 def test_autogo_join_auto_go_neg_after_seeing_go(dev
):
587 """P2P_CONNECT-auto fallback to GO Neg after seeing GO"""
588 autogo(dev
[0], freq
=2412)
589 addr
= dev
[0].p2p_dev_addr()
590 bssid
= dev
[0].p2p_interface_addr()
591 dev
[1].scan_for_bss(bssid
, freq
=2412)
592 dev
[0].remove_group()
595 if "OK" not in dev
[1].global_request("P2P_CONNECT " + addr
+ " pbc auto"):
596 raise Exception("P2P_CONNECT failed")
598 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"],
601 raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen")
603 ev
= dev
[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=15)
605 raise Exception("Timeout on P2P-GO-NEG-REQUEST")
606 peer
= ev
.split(' ')[1]
607 dev
[0].p2p_go_neg_init(peer
, None, "pbc", timeout
=15, go_intent
=15)
609 ev
= dev
[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout
=1)
611 raise Exception("No P2P-FALLBACK-TO-GO-NEG event seen")
612 if "reason=no-ACK-to-PD-Req" not in ev
and "reason=PD-failed" not in ev
:
613 raise Exception("Unexpected reason: " + ev
)
615 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
617 raise Exception("Joining the group timed out")
618 dev
[1].group_form_result(ev
)
620 dev
[0].remove_group()
621 dev
[1].wait_go_ending_session()
622 dev
[1].flush_scan_cache()
624 def test_go_search_non_social(dev
):
625 """P2P_FIND with freq parameter to scan a single channel"""
626 addr0
= dev
[0].p2p_dev_addr()
627 autogo(dev
[0], freq
=2422)
628 dev
[1].p2p_find(freq
=2422)
629 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=3.5)
631 dev
[1].p2p_stop_find()
632 dev
[1].p2p_find(freq
=2422)
633 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=3.5)
635 raise Exception("Did not find GO quickly enough")
637 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
639 raise Exception("Did not find peer")
640 dev
[2].p2p_stop_find()
641 dev
[1].p2p_stop_find()
642 dev
[0].remove_group()
644 def test_go_search_non_social2(dev
):
645 """P2P_FIND with freq parameter to scan a single channel (2)"""
646 addr0
= dev
[0].p2p_dev_addr()
647 dev
[1].p2p_find(freq
=2422)
648 # Wait for the first p2p_find scan round to complete before starting GO
650 autogo(dev
[0], freq
=2422)
651 # Verify that p2p_find is still scanning the specified frequency
652 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
654 dev
[1].p2p_stop_find()
655 raise Exception("Did not find GO quickly enough")
656 # Verify that p2p_find is scanning the social channels
658 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
660 raise Exception("Did not find peer")
661 dev
[2].p2p_stop_find()
662 dev
[1].p2p_stop_find()
663 dev
[0].remove_group()
664 dev
[1].dump_monitor()
666 # Verify that social channel as the specific channel works
667 dev
[1].p2p_find(freq
=2412)
670 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
672 raise Exception("Did not find peer (2)")
674 def test_autogo_many(dev
):
675 """P2P autonomous GO with large number of GO instances"""
676 dev
[0].global_request("SET p2p_no_group_iface 0")
678 if "OK" not in dev
[0].global_request("P2P_GROUP_ADD freq=2412"):
679 logger
.info("Was able to add %d groups" % i
)
681 raise Exception("P2P_GROUP_ADD failed")
682 stop_ev
= dev
[0].wait_global_event(["P2P-GROUP-REMOVE"], timeout
=1)
683 if stop_ev
is not None:
684 raise Exception("Unexpected P2P-GROUP-REMOVE event")
686 ev
= dev
[0].wait_global_event(["P2P-GROUP-STARTED"], timeout
=5)
688 raise Exception("GO start up timed out")
689 dev
[0].group_form_result(ev
)
691 for i
in dev
[0].global_request("INTERFACES").splitlines():
692 dev
[0].request("P2P_GROUP_REMOVE " + i
)
693 dev
[0].dump_monitor()
694 dev
[0].request("P2P_GROUP_REMOVE *")
696 def test_autogo_many_clients(dev
):
697 """P2P autonomous GO and many clients (P2P IE fragmentation)"""
699 _test_autogo_many_clients(dev
)
701 dev
[0].global_request("SET device_name Device A")
702 dev
[1].global_request("SET device_name Device B")
703 dev
[2].global_request("SET device_name Device C")
705 def _test_autogo_many_clients(dev
):
706 # These long device names will push the P2P IE contents beyond the limit
707 # that requires fragmentation.
708 name0
= "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
709 name1
= "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
710 name2
= "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
711 name3
= "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
712 dev
[0].global_request("SET device_name " + name0
)
713 dev
[1].global_request("SET device_name " + name1
)
714 dev
[2].global_request("SET device_name " + name2
)
716 addr0
= dev
[0].p2p_dev_addr()
717 res
= autogo(dev
[0], freq
=2412)
718 bssid
= dev
[0].p2p_interface_addr()
720 connect_cli(dev
[0], dev
[1], social
=True, freq
=2412)
721 dev
[0].dump_monitor()
722 connect_cli(dev
[0], dev
[2], social
=True, freq
=2412)
723 dev
[0].dump_monitor()
725 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
726 wpas
.interface_add("wlan5")
727 wpas
.global_request("SET device_name " + name3
)
728 wpas
.global_request("SET sec_device_type 1-11111111-1")
729 wpas
.global_request("SET sec_device_type 2-22222222-2")
730 wpas
.global_request("SET sec_device_type 3-33333333-3")
731 wpas
.global_request("SET sec_device_type 4-44444444-4")
732 wpas
.global_request("SET sec_device_type 5-55555555-5")
733 connect_cli(dev
[0], wpas
, social
=True, freq
=2412)
734 dev
[0].dump_monitor()
736 dev
[1].dump_monitor()
737 dev
[1].p2p_find(freq
=2412)
738 ev1
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
740 raise Exception("Could not find peer (1)")
741 ev2
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
743 raise Exception("Could not find peer (2)")
744 ev3
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=10)
746 raise Exception("Could not find peer (3)")
747 dev
[1].p2p_stop_find()
749 for i
in [name0
, name2
, name3
]:
750 if i
not in ev1
and i
not in ev2
and i
not in ev3
:
751 raise Exception('name "%s" not found' % i
)
756 raise Exception("MGMT-RX timeout")
757 p2p
= parse_p2p_public_action(msg
['payload'])
759 raise Exception("Not a P2P Public Action frame " + str(dialog_token
))
760 if p2p
['subtype'] != P2P_PROV_DISC_REQ
:
761 raise Exception("Unexpected subtype %d" % p2p
['subtype'])
762 p2p
['freq'] = msg
['freq']
766 def test_autogo_scan(dev
):
767 """P2P autonomous GO and no P2P IE in Probe Response scan results"""
768 addr0
= dev
[0].p2p_dev_addr()
769 addr1
= dev
[1].p2p_dev_addr()
770 dev
[0].p2p_start_go(freq
=2412, persistent
=True)
771 bssid
= dev
[0].p2p_interface_addr()
773 dev
[1].discover_peer(addr0
)
774 dev
[1].p2p_stop_find()
775 ev
= dev
[1].wait_global_event(["P2P-FIND-STOPPED"], timeout
=2)
777 dev
[1].flush_scan_cache()
779 pin
= dev
[1].wps_read_pin()
780 dev
[0].group_request("WPS_PIN any " + pin
)
783 dev
[1].request("SET p2p_disabled 1")
784 dev
[1].request("SCAN freq=2412")
785 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
787 raise Exception("Active scan did not complete")
789 dev
[1].request("SET p2p_disabled 0")
792 dev
[1].request("SCAN freq=2412 passive=1")
793 ev
= dev
[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
795 raise Exception("Scan did not complete")
797 # Disable management frame processing for a moment to skip Probe Response
799 dev
[0].group_request("SET ext_mgmt_frame_handling 1")
801 dev
[1].global_request("P2P_CONNECT " + bssid
+ " " + pin
+ " freq=2412 join")
803 # Skip the first Probe Request frame
804 ev
= dev
[0].wait_group_event(["MGMT-RX"], timeout
=10)
806 raise Exception("No Probe Request frame seen")
807 if not ev
.split(' ')[4].startswith("40"):
808 raise Exception("Not a Probe Request frame")
810 # If a P2P Device is not used, the PD Request will be received on the group
811 # interface (which is actually wlan0, since a separate interface is not
812 # used), which was set to external management frame handling, so need to
813 # reply to it manually.
814 res
= dev
[0].get_driver_status()
815 if not (int(res
['capa.flags'], 0) & 0x20000000):
816 # Reply to PD Request while still filtering Probe Request frames
817 msg
= rx_pd_req(dev
[0])
818 mgmt_tx(dev
[0], "MGMT_TX {} {} freq={} wait_time=10 no_cck=1 action={}".format(addr1
, addr0
, 2412, "0409506f9a0908%02xdd0a0050f204100800020008" % msg
['dialog_token']))
820 # Skip Probe Request frames until something else is received
822 ev
= dev
[0].wait_group_event(["MGMT-RX"], timeout
=10)
824 raise Exception("No frame seen")
825 if not ev
.split(' ')[4].startswith("40"):
828 # Allow wpa_supplicant to process authentication and association
829 dev
[0].group_request("SET ext_mgmt_frame_handling 0")
831 # Joining the group should succeed and indicate persistent group based on
832 # Beacon frame P2P IE.
833 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=10)
835 raise Exception("Failed to join group")
836 if "[PERSISTENT]" not in ev
:
837 raise Exception("Did not recognize group as persistent")
838 dev
[0].remove_group()
839 dev
[1].wait_go_ending_session()
842 def test_autogo_join_before_found(dev
):
843 """P2P client joining a group before having found GO Device Address"""
844 dev
[0].global_request("SET p2p_no_group_iface 0")
845 res
= autogo(dev
[0], freq
=2412)
846 if "p2p-wlan" not in res
['ifname']:
847 raise Exception("Unexpected group interface name on GO")
848 status
= dev
[0].get_group_status()
849 bssid
= status
['bssid']
851 pin
= dev
[1].wps_read_pin()
852 dev
[0].p2p_go_authorize_client(pin
)
853 cmd
= "P2P_CONNECT " + bssid
+ " " + pin
+ " join freq=2412"
854 if "OK" not in dev
[1].global_request(cmd
):
855 raise Exception("P2P_CONNECT join failed")
856 ev
= dev
[1].wait_global_event(["P2P-GROUP-STARTED"], timeout
=15)
858 raise Exception("Joining the group timed out")
859 dev
[0].remove_group()
860 dev
[1].wait_go_ending_session()
862 def test_autogo_noa(dev
):
863 """P2P autonomous GO and NoA"""
865 dev
[0].group_request("P2P_SET noa 1,5,20")
866 dev
[0].group_request("P2P_SET noa 255,10,50")
868 # Connect and disconnect legacy STA to check NoA special cases
870 dev
[1].request("SET p2p_disabled 1")
871 dev
[1].connect(ssid
=res
['ssid'], psk
=res
['passphrase'], proto
='RSN',
872 key_mgmt
='WPA-PSK', pairwise
='CCMP', group
='CCMP',
873 scan_freq
=res
['freq'])
874 dev
[0].group_request("P2P_SET noa 255,15,55")
875 dev
[1].request("DISCONNECT")
876 dev
[1].wait_disconnected()
878 dev
[1].request("SET p2p_disabled 0")
880 dev
[0].group_request("P2P_SET noa 0,0,0")
882 def test_autogo_interworking(dev
):
883 """P2P autonomous GO and Interworking"""
885 run_autogo_interworking(dev
)
887 dev
[0].set("go_interworking", "0")
889 def run_autogo_interworking(dev
):
890 dev
[0].global_request("SET go_interworking 1")
891 dev
[0].global_request("SET go_access_network_type 1")
892 dev
[0].global_request("SET go_internet 1")
893 dev
[0].global_request("SET go_venue_group 2")
894 dev
[0].global_request("SET go_venue_type 3")
896 bssid
= dev
[0].p2p_interface_addr()
897 dev
[1].scan_for_bss(bssid
, freq
=res
['freq'])
898 bss
= dev
[1].get_bss(bssid
)
899 dev
[0].remove_group()
900 if '6b03110203' not in bss
['ie']:
901 raise Exception("Interworking element not seen")