1 # P2P autonomous GO test cases
2 # Copyright (c) 2013-2014, 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_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_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=10)
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].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_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()