]>
Commit | Line | Data |
---|---|---|
4ea8d3b5 | 1 | # P2P autonomous GO test cases |
eb9c1554 | 2 | # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi> |
4ea8d3b5 JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
9fd6804d | 7 | from remotehost import remote_compatible |
7cb08cdb | 8 | import time |
07a2e61b | 9 | import subprocess |
4ea8d3b5 | 10 | import logging |
c9aa4308 | 11 | logger = logging.getLogger() |
4ea8d3b5 | 12 | |
ae750570 | 13 | import hostapd |
4ea8d3b5 | 14 | import hwsim_utils |
19ae1d07 | 15 | import utils |
81e787b7 | 16 | from utils import HwsimSkip |
c7860beb | 17 | from wlantest import Wlantest |
0afb797e | 18 | from wpasupplicant import WpaSupplicant |
9cb34130 JM |
19 | from p2p_utils import * |
20 | from test_p2p_messages import mgmt_tx, parse_p2p_public_action | |
4ea8d3b5 JM |
21 | |
22 | def test_autogo(dev): | |
47c34473 | 23 | """P2P autonomous GO and client joining group""" |
ca9b78ad JM |
24 | addr0 = dev[0].p2p_dev_addr() |
25 | addr2 = dev[2].p2p_dev_addr() | |
19ae1d07 JM |
26 | res = autogo(dev[0]) |
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") | |
36f28187 IP |
32 | bss = dev[1].get_bss("p2p_dev_addr=" + addr0, res['ifname']) |
33 | if not bss or bss['bssid'] != dev[0].p2p_interface_addr(): | |
3a64d523 JM |
34 | raise Exception("Unexpected BSSID in the BSS entry for the GO") |
35 | id = bss['id'] | |
36f28187 IP |
36 | bss = dev[1].get_bss("ID-" + id, res['ifname']) |
37 | if not bss or bss['id'] != id: | |
3a64d523 | 38 | raise Exception("Could not find BSS entry based on id") |
36f28187 | 39 | res = dev[1].group_request("BSS RANGE=" + id + "- MASK=0x1") |
3a64d523 JM |
40 | if "id=" + id not in res: |
41 | raise Exception("Could not find BSS entry based on id range") | |
984c5b96 | 42 | |
d463c556 JM |
43 | res = dev[1].request("SCAN_RESULTS") |
44 | if "[P2P]" not in res: | |
45 | raise Exception("P2P flag missing from scan results: " + res) | |
46 | ||
984c5b96 | 47 | # Presence request to increase testing coverage |
bf1b5973 JM |
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") | |
984c5b96 JM |
52 | if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"): |
53 | raise Exception("Could not send presence request") | |
d4f2ba74 | 54 | ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"], 10) |
bf1b5973 JM |
55 | if ev is None: |
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") | |
c0b57b24 | 59 | ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"]) |
bf1b5973 JM |
60 | if ev is None: |
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") | |
c0b57b24 | 64 | ev = dev[1].wait_group_event(["P2P-PRESENCE-RESPONSE"]) |
984c5b96 JM |
65 | if ev is None: |
66 | raise Exception("Timeout while waiting for Presence Response") | |
67 | ||
ca9b78ad JM |
68 | if not dev[2].discover_peer(addr0): |
69 | raise Exception("Could not discover GO") | |
70 | dev[0].dump_monitor() | |
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) | |
73 | if ev is None: | |
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) | |
80 | if ev is None: | |
81 | raise Exception("P2P-PROV-DISC-ENTER-PIN not reported") | |
82 | ||
19ae1d07 JM |
83 | dev[0].remove_group() |
84 | dev[1].wait_go_ending_session() | |
85 | ||
86 | def test_autogo2(dev): | |
87 | """P2P autonomous GO with a separate group interface and client joining group""" | |
9c01d6a9 | 88 | dev[0].global_request("SET p2p_no_group_iface 0") |
ee3f9f38 | 89 | res = autogo(dev[0], freq=2437) |
19ae1d07 JM |
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") | |
ee3f9f38 | 94 | connect_cli(dev[0], dev[1], social=True, freq=2437) |
4ea8d3b5 | 95 | dev[0].remove_group() |
2c914e24 | 96 | dev[1].wait_go_ending_session() |
19ae1d07 JM |
97 | if res['ifname'] in utils.get_ifnames(): |
98 | raise Exception("Group interface netdev was not removed") | |
99 | ||
100 | def test_autogo3(dev): | |
101 | """P2P autonomous GO and client with a separate group interface joining group""" | |
9c01d6a9 | 102 | dev[1].global_request("SET p2p_no_group_iface 0") |
ee3f9f38 JM |
103 | autogo(dev[0], freq=2462) |
104 | res = connect_cli(dev[0], dev[1], social=True, freq=2462) | |
19ae1d07 JM |
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() | |
111 | dev[1].ping() | |
112 | if res['ifname'] in utils.get_ifnames(): | |
113 | raise Exception("Group interface netdev was not removed") | |
114 | ||
115 | def test_autogo4(dev): | |
116 | """P2P autonomous GO and client joining group (both with a separate group interface)""" | |
9c01d6a9 IP |
117 | dev[0].global_request("SET p2p_no_group_iface 0") |
118 | dev[1].global_request("SET p2p_no_group_iface 0") | |
ee3f9f38 JM |
119 | res1 = autogo(dev[0], freq=2412) |
120 | res2 = connect_cli(dev[0], dev[1], social=True, freq=2412) | |
19ae1d07 JM |
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() | |
132 | dev[1].ping() | |
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") | |
4ea8d3b5 | 138 | |
0afb797e JM |
139 | def test_autogo_m2d(dev): |
140 | """P2P autonomous GO and clients not authorized""" | |
ee3f9f38 | 141 | autogo(dev[0], freq=2412) |
0afb797e JM |
142 | go_addr = dev[0].p2p_dev_addr() |
143 | ||
8031003f | 144 | dev[1].global_request("SET p2p_no_group_iface 0") |
0afb797e JM |
145 | if not dev[1].discover_peer(go_addr, social=True): |
146 | raise Exception("GO " + go_addr + " not found") | |
147 | dev[1].dump_monitor() | |
148 | ||
149 | if not dev[2].discover_peer(go_addr, social=True): | |
150 | raise Exception("GO " + go_addr + " not found") | |
151 | dev[2].dump_monitor() | |
152 | ||
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") | |
158 | ||
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") | |
163 | ||
cfbdb995 | 164 | ev = dev[1].wait_global_event(["WPS-M2D"], timeout=16) |
0afb797e JM |
165 | if ev is None: |
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) | |
171 | if ev is None: | |
172 | raise Exception("No M2D event on group interface") | |
173 | ||
174 | ev = dev[2].wait_global_event(["WPS-M2D"], timeout=10) | |
175 | if ev is None: | |
176 | raise Exception("No global M2D event (2)") | |
177 | ev = dev[2].wait_event(["WPS-M2D"], timeout=10) | |
178 | if ev is None: | |
179 | raise Exception("No M2D event on group interface (2)") | |
180 | ||
9fd6804d | 181 | @remote_compatible |
0afb797e JM |
182 | def test_autogo_fail(dev): |
183 | """P2P autonomous GO and incorrect PIN""" | |
ee3f9f38 | 184 | autogo(dev[0], freq=2412) |
0afb797e JM |
185 | go_addr = dev[0].p2p_dev_addr() |
186 | dev[0].p2p_go_authorize_client("00000000") | |
187 | ||
9c01d6a9 | 188 | dev[1].global_request("SET p2p_no_group_iface 0") |
0afb797e JM |
189 | if not dev[1].discover_peer(go_addr, social=True): |
190 | raise Exception("GO " + go_addr + " not found") | |
191 | dev[1].dump_monitor() | |
192 | ||
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") | |
198 | ||
199 | ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=10) | |
200 | if ev is None: | |
201 | raise Exception("No global WPS-FAIL event") | |
202 | ||
78ebbf09 | 203 | def test_autogo_2cli(dev): |
47c34473 | 204 | """P2P autonomous GO and two clients joining group""" |
ee3f9f38 JM |
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) | |
78ebbf09 | 208 | hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) |
672f3a72 | 209 | dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr()) |
2c914e24 | 210 | dev[1].wait_go_ending_session() |
c93b6706 | 211 | dev[0].global_request("P2P_REMOVE_CLIENT iface=" + dev[2].p2p_interface_addr()) |
2c914e24 | 212 | dev[2].wait_go_ending_session() |
c93b6706 JM |
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() | |
78ebbf09 | 216 | |
ab18b03b JM |
217 | def test_autogo_pbc(dev): |
218 | """P2P autonomous GO and PBC""" | |
c0b57b24 | 219 | dev[1].global_request("SET p2p_no_group_iface 0") |
ee3f9f38 | 220 | autogo(dev[0], freq=2412) |
ab18b03b JM |
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, | |
226 | social=True) | |
5590d2ec | 227 | ev = dev[2].wait_global_event(["WPS-M2D"], timeout=15) |
ab18b03b JM |
228 | if ev is None: |
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, | |
233 | social=True) | |
234 | ||
ae750570 JM |
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() | |
241 | time.sleep(0.1) | |
242 | ||
243 | dev[0].scan_for_bss(bssid, freq=2412) | |
244 | dev[1].scan_for_bss(bssid, freq=2412) | |
245 | ||
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, | |
251 | social=True) | |
252 | hapd.disable() | |
253 | remove_group(dev[0], dev[1]) | |
254 | dev[0].flush_scan_cache() | |
255 | dev[1].flush_scan_cache() | |
256 | ||
7cb08cdb | 257 | def test_autogo_tdls(dev): |
47c34473 | 258 | """P2P autonomous GO and two clients using TDLS""" |
07a2e61b JM |
259 | go = dev[0] |
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") | |
ee3f9f38 | 266 | res = go.p2p_start_go(persistent=id, freq="2462") |
07a2e61b | 267 | logger.debug("res: " + str(res)) |
8efc83d4 JA |
268 | Wlantest.setup(go, True) |
269 | wt = Wlantest() | |
c7860beb JM |
270 | wt.flush() |
271 | wt.add_passphrase("12345678") | |
ee3f9f38 JM |
272 | connect_cli(go, dev[1], social=True, freq=2462) |
273 | connect_cli(go, dev[2], social=True, freq=2462) | |
7cb08cdb | 274 | hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) |
07a2e61b JM |
275 | bssid = dev[0].p2p_interface_addr() |
276 | addr1 = dev[1].p2p_interface_addr() | |
7cb08cdb JM |
277 | addr2 = dev[2].p2p_interface_addr() |
278 | dev[1].tdls_setup(addr2) | |
279 | time.sleep(1) | |
280 | hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) | |
bc6e3288 | 281 | conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2) |
07a2e61b JM |
282 | if conf == 0: |
283 | raise Exception("No TDLS Setup Confirm (success) seen") | |
bc6e3288 | 284 | dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2) |
07a2e61b JM |
285 | if dl == 0: |
286 | raise Exception("No valid frames through direct link") | |
bc6e3288 | 287 | wt.tdls_clear(bssid, addr1, addr2) |
7cb08cdb JM |
288 | dev[1].tdls_teardown(addr2) |
289 | time.sleep(1) | |
bc6e3288 | 290 | teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2) |
d014a150 | 291 | if teardown == 0: |
07a2e61b | 292 | raise Exception("No TDLS Setup Teardown seen") |
bc6e3288 | 293 | wt.tdls_clear(bssid, addr1, addr2) |
7cb08cdb | 294 | hwsim_utils.test_connectivity_p2p(dev[1], dev[2]) |
bc6e3288 | 295 | ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2) |
07a2e61b JM |
296 | if ap_path == 0: |
297 | raise Exception("No valid frames via AP path") | |
bc6e3288 | 298 | direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2) |
07a2e61b JM |
299 | if direct_link > 0: |
300 | raise Exception("Unexpected frames through direct link") | |
c7860beb | 301 | idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1, |
bc6e3288 | 302 | addr2) |
07a2e61b JM |
303 | if idirect_link > 0: |
304 | raise Exception("Unexpected frames through direct link (invalid)") | |
7cb08cdb JM |
305 | dev[2].remove_group() |
306 | dev[1].remove_group() | |
307 | dev[0].remove_group() | |
7ebf841f JM |
308 | |
309 | def test_autogo_legacy(dev): | |
310 | """P2P autonomous GO and legacy clients""" | |
ee3f9f38 | 311 | res = autogo(dev[0], freq=2462) |
f44c45ac JM |
312 | if dev[0].get_group_status_field("passphrase", extra="WPS") != res['passphrase']: |
313 | raise Exception("passphrase mismatch") | |
acd62025 | 314 | if dev[0].group_request("P2P_GET_PASSPHRASE") != res['passphrase']: |
934d5b04 | 315 | raise Exception("passphrase mismatch(2)") |
7ebf841f JM |
316 | |
317 | logger.info("Connect P2P client") | |
ee3f9f38 | 318 | connect_cli(dev[0], dev[1], social=True, freq=2462) |
7ebf841f | 319 | |
dd15d448 JM |
320 | if "FAIL" not in dev[1].request("P2P_GET_PASSPHRASE"): |
321 | raise Exception("P2P_GET_PASSPHRASE succeeded on P2P Client") | |
322 | ||
7ebf841f JM |
323 | logger.info("Connect legacy WPS client") |
324 | pin = dev[2].wps_read_pin() | |
325 | dev[0].p2p_go_authorize_client(pin) | |
7ebf841f JM |
326 | dev[2].request("P2P_SET disabled 1") |
327 | dev[2].dump_monitor() | |
328 | dev[2].request("WPS_PIN any " + pin) | |
5f35a5e2 | 329 | dev[2].wait_connected(timeout=30) |
7ebf841f JM |
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") | |
335 | ||
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") | |
344 | ||
345 | dev[0].remove_group() | |
346 | dev[1].wait_go_ending_session() | |
393e9019 JM |
347 | |
348 | def test_autogo_chan_switch(dev): | |
349 | """P2P autonomous GO switching channels""" | |
5e8f2319 JM |
350 | run_autogo_chan_switch(dev) |
351 | ||
352 | def run_autogo_chan_switch(dev): | |
393e9019 | 353 | autogo(dev[0], freq=2417) |
5e8f2319 | 354 | connect_cli(dev[0], dev[1], freq=2417) |
4041d2af | 355 | res = dev[0].group_request("CHAN_SWITCH 5 2422") |
393e9019 JM |
356 | if "FAIL" in res: |
357 | # for now, skip test since mac80211_hwsim support is not yet widely | |
358 | # deployed | |
81e787b7 | 359 | raise HwsimSkip("Assume mac80211_hwsim did not support channel switching") |
4041d2af | 360 | ev = dev[0].wait_group_event(["AP-CSA-FINISHED"], timeout=10) |
393e9019 JM |
361 | if ev is None: |
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() | |
367 | time.sleep(0.1) | |
368 | hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) | |
8c7559ee | 369 | |
5e8f2319 JM |
370 | dev[0].remove_group() |
371 | dev[1].wait_go_ending_session() | |
372 | ||
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) | |
377 | ||
9fd6804d | 378 | @remote_compatible |
8c7559ee JM |
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") | |
ee3f9f38 JM |
383 | autogo(dev[0], freq=2412) |
384 | connect_cli(dev[0], dev[1], social=True, freq=2412) | |
8c7559ee JM |
385 | dev[0].remove_group() |
386 | dev[1].wait_go_ending_session() | |
75ee44f2 JM |
387 | |
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") | |
392 | res = autogo(wpas) | |
393 | wpas.dump_monitor() | |
394 | wpas.interface_remove("wlan5") | |
395 | wpas.interface_add("wlan5") | |
396 | res = autogo(wpas) | |
397 | wpas.dump_monitor() | |
c4668009 | 398 | subprocess.call(['ifconfig', res['ifname'], 'down']) |
75ee44f2 JM |
399 | ev = wpas.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10) |
400 | if ev is None: | |
401 | raise Exception("Group removal not reported") | |
402 | if res['ifname'] not in ev: | |
403 | raise Exception("Unexpected group removal event: " + ev) | |
42216792 | 404 | |
9fd6804d | 405 | @remote_compatible |
42216792 JM |
406 | def test_autogo_start_during_scan(dev): |
407 | """P2P autonomous GO started during ongoing manual scan""" | |
408 | try: | |
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") | |
ee3f9f38 JM |
412 | autogo(dev[0], freq=2462) |
413 | connect_cli(dev[0], dev[1], social=True, freq=2462) | |
42216792 JM |
414 | dev[0].remove_group() |
415 | dev[1].wait_go_ending_session() | |
416 | finally: | |
417 | dev[0].request("AUTOSCAN ") | |
31424fa7 JM |
418 | |
419 | def test_autogo_passphrase_len(dev): | |
420 | """P2P autonomous GO and longer passphrase""" | |
421 | try: | |
422 | if "OK" not in dev[0].request("SET p2p_passphrase_len 13"): | |
423 | raise Exception("Failed to set passphrase length") | |
ee3f9f38 | 424 | res = autogo(dev[0], freq=2412) |
31424fa7 JM |
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") | |
429 | ||
430 | logger.info("Connect P2P client") | |
ee3f9f38 | 431 | connect_cli(dev[0], dev[1], social=True, freq=2412) |
31424fa7 JM |
432 | |
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) | |
5f35a5e2 | 439 | dev[2].wait_connected(timeout=30) |
31424fa7 JM |
440 | status = dev[2].get_status() |
441 | if status['wpa_state'] != 'COMPLETED': | |
442 | raise Exception("Not fully connected") | |
443 | dev[2].request("DISCONNECT") | |
444 | ||
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") | |
453 | ||
454 | dev[0].remove_group() | |
455 | dev[1].wait_go_ending_session() | |
456 | finally: | |
457 | dev[0].request("SET p2p_passphrase_len 8") | |
d885a0ba | 458 | |
9fd6804d | 459 | @remote_compatible |
d885a0ba JM |
460 | def test_autogo_bridge(dev): |
461 | """P2P autonomous GO in a bridge""" | |
462 | try: | |
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") | |
466 | autogo(dev[0]) | |
bbcbbd37 | 467 | ifname = dev[0].get_group_ifname() |
bb04a9a9 JA |
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']) | |
d885a0ba | 472 | time.sleep(0.1) |
bb04a9a9 | 473 | dev[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname]) |
d885a0ba | 474 | time.sleep(0.1) |
bb04a9a9 | 475 | dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down']) |
d885a0ba | 476 | time.sleep(0.1) |
bb04a9a9 | 477 | dev[0].cmd_execute(['brctl', 'delbr', 'p2p-br0']) |
d885a0ba JM |
478 | ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1) |
479 | if ev is not None: | |
480 | raise Exception("P2P group removed unexpectedly") | |
bbcbbd37 | 481 | if dev[0].get_group_status_field('wpa_state') != "COMPLETED": |
d885a0ba JM |
482 | raise Exception("Unexpected wpa_state") |
483 | dev[0].remove_group() | |
484 | finally: | |
377babb2 | 485 | dev[0].request("AUTOSCAN ") |
bb04a9a9 JA |
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'], | |
491 | shell=True) | |
777bbe7a | 492 | |
9fd6804d | 493 | @remote_compatible |
777bbe7a JM |
494 | def test_presence_req_on_group_interface(dev): |
495 | """P2P_PRESENCE_REQ on group interface""" | |
9c01d6a9 | 496 | dev[1].global_request("SET p2p_no_group_iface 0") |
777bbe7a JM |
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"]) | |
502 | if ev is None: | |
503 | raise Exception("Timeout while waiting for Presence Response") | |
504 | dev[0].remove_group() | |
505 | dev[1].wait_go_ending_session() | |
d2b84e43 JM |
506 | |
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() | |
4b9d79b6 | 516 | wpas.dump_monitor() |
d2b84e43 JM |
517 | |
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 | |
524 | # exchange. | |
525 | if "OK" not in wpas.group_request("STOP_AP"): | |
526 | raise Exception("STOP_AP failed") | |
4b9d79b6 | 527 | wpas.dump_monitor() |
d2b84e43 JM |
528 | wpas.group_request("SET ext_mgmt_frame_handling 1") |
529 | wpas.p2p_listen() | |
4b9d79b6 | 530 | wpas.dump_monitor() |
d2b84e43 JM |
531 | time.sleep(0.02) |
532 | dev[1].global_request("P2P_CONNECT " + addr + " pbc auto") | |
533 | ||
c0b57b24 | 534 | ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], 15) |
4b9d79b6 | 535 | wpas.dump_monitor() |
d2b84e43 JM |
536 | if ev is None: |
537 | raise Exception("Could not trigger old-scan-only case") | |
538 | return | |
539 | ||
c0b57b24 | 540 | ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], 15) |
d2b84e43 JM |
541 | wpas.remove_group() |
542 | if ev is None: | |
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) | |
4b9d79b6 | 546 | wpas.dump_monitor() |
9177b0a8 JM |
547 | |
548 | def test_autogo_join_auto(dev): | |
549 | """P2P_CONNECT-auto joining a group""" | |
550 | autogo(dev[0]) | |
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") | |
554 | ||
555 | ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15) | |
556 | if ev is None: | |
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") | |
561 | ||
562 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
563 | if ev is None: | |
564 | raise Exception("Joining the group timed out") | |
565 | dev[1].group_form_result(ev) | |
566 | ||
567 | dev[0].remove_group() | |
568 | dev[1].wait_go_ending_session() | |
569 | dev[1].flush_scan_cache() | |
570 | ||
9fd6804d | 571 | @remote_compatible |
9177b0a8 JM |
572 | def test_autogo_join_auto_go_neg(dev): |
573 | """P2P_CONNECT-auto fallback to GO Neg""" | |
380f3a8b | 574 | dev[1].flush_scan_cache() |
9177b0a8 JM |
575 | dev[0].p2p_listen() |
576 | addr = dev[0].p2p_dev_addr() | |
be4a0d0d JM |
577 | if not dev[1].discover_peer(addr, social=True): |
578 | raise Exception("Peer not found") | |
579 | dev[1].p2p_stop_find() | |
9177b0a8 JM |
580 | if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"): |
581 | raise Exception("P2P_CONNECT failed") | |
582 | ||
583 | ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) | |
584 | if ev is None: | |
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) | |
588 | ||
589 | ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1) | |
590 | if ev is None: | |
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) | |
594 | if ev is None: | |
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) | |
598 | ||
599 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
600 | if ev is None: | |
601 | raise Exception("Joining the group timed out") | |
602 | dev[1].group_form_result(ev) | |
603 | ||
604 | dev[0].remove_group() | |
605 | dev[1].wait_go_ending_session() | |
606 | dev[1].flush_scan_cache() | |
607 | ||
9fd6804d | 608 | @remote_compatible |
9177b0a8 JM |
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() | |
616 | dev[0].p2p_listen() | |
617 | ||
618 | if "OK" not in dev[1].global_request("P2P_CONNECT " + addr + " pbc auto"): | |
619 | raise Exception("P2P_CONNECT failed") | |
620 | ||
621 | ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG-ENABLED"], | |
622 | timeout=15) | |
623 | if ev is None: | |
624 | raise Exception("No P2P-FALLBACK-TO-GO-NEG-ENABLED event seen") | |
625 | ||
626 | ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) | |
627 | if ev is None: | |
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) | |
631 | ||
632 | ev = dev[1].wait_global_event(["P2P-FALLBACK-TO-GO-NEG"], timeout=1) | |
633 | if ev is None: | |
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) | |
637 | ||
638 | ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15) | |
639 | if ev is None: | |
640 | raise Exception("Joining the group timed out") | |
641 | dev[1].group_form_result(ev) | |
642 | ||
643 | dev[0].remove_group() | |
644 | dev[1].wait_go_ending_session() | |
645 | dev[1].flush_scan_cache() | |
6d0b4474 JM |
646 | |
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) | |
c0b57b24 | 652 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=3.5) |
6d0b4474 | 653 | if ev is None: |
62e0e57a JM |
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) | |
657 | if ev is None: | |
658 | raise Exception("Did not find GO quickly enough") | |
6d0b4474 | 659 | dev[2].p2p_listen() |
c0b57b24 | 660 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) |
6d0b4474 JM |
661 | if ev is None: |
662 | raise Exception("Did not find peer") | |
663 | dev[2].p2p_stop_find() | |
664 | dev[1].p2p_stop_find() | |
665 | dev[0].remove_group() | |
bfc048b4 | 666 | |
8a5b0bbd JM |
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 | |
672 | time.sleep(1) | |
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) | |
676 | if ev is None: | |
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 | |
680 | dev[2].p2p_listen() | |
681 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) | |
682 | if ev is None: | |
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() | |
688 | ||
689 | # Verify that social channel as the specific channel works | |
690 | dev[1].p2p_find(freq=2412) | |
691 | time.sleep(0.5) | |
692 | dev[2].p2p_listen() | |
693 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) | |
694 | if ev is None: | |
695 | raise Exception("Did not find peer (2)") | |
696 | ||
bfc048b4 JM |
697 | def test_autogo_many(dev): |
698 | """P2P autonomous GO with large number of GO instances""" | |
9c01d6a9 | 699 | dev[0].global_request("SET p2p_no_group_iface 0") |
bfc048b4 JM |
700 | for i in range(100): |
701 | if "OK" not in dev[0].global_request("P2P_GROUP_ADD freq=2412"): | |
702 | logger.info("Was able to add %d groups" % i) | |
703 | if i < 5: | |
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") | |
708 | break | |
709 | ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5) | |
710 | if ev is None: | |
711 | raise Exception("GO start up timed out") | |
712 | dev[0].group_form_result(ev) | |
713 | ||
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 *") | |
eb9c1554 JM |
718 | |
719 | def test_autogo_many_clients(dev): | |
720 | """P2P autonomous GO and many clients (P2P IE fragmentation)""" | |
721 | try: | |
722 | _test_autogo_many_clients(dev) | |
723 | finally: | |
c0b57b24 IP |
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") | |
eb9c1554 JM |
727 | |
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" | |
c0b57b24 IP |
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) | |
eb9c1554 JM |
738 | |
739 | addr0 = dev[0].p2p_dev_addr() | |
740 | res = autogo(dev[0], freq=2412) | |
741 | bssid = dev[0].p2p_interface_addr() | |
742 | ||
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() | |
747 | ||
748 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
749 | wpas.interface_add("wlan5") | |
c0b57b24 IP |
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") | |
eb9c1554 JM |
756 | connect_cli(dev[0], wpas, social=True, freq=2412) |
757 | dev[0].dump_monitor() | |
758 | ||
759 | dev[1].dump_monitor() | |
760 | dev[1].p2p_find(freq=2412) | |
761 | ev1 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10) | |
762 | if ev1 is None: | |
763 | raise Exception("Could not find peer (1)") | |
764 | ev2 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10) | |
765 | if ev2 is None: | |
766 | raise Exception("Could not find peer (2)") | |
767 | ev3 = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10) | |
768 | if ev3 is None: | |
769 | raise Exception("Could not find peer (3)") | |
770 | dev[1].p2p_stop_find() | |
771 | ||
fab49f61 | 772 | for i in [name0, name2, name3]: |
eb9c1554 JM |
773 | if i not in ev1 and i not in ev2 and i not in ev3: |
774 | raise Exception('name "%s" not found' % i) | |
9464e099 JM |
775 | |
776 | def rx_pd_req(dev): | |
777 | msg = dev.mgmt_rx() | |
778 | if msg is None: | |
779 | raise Exception("MGMT-RX timeout") | |
780 | p2p = parse_p2p_public_action(msg['payload']) | |
781 | if p2p is None: | |
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'] | |
786 | return p2p | |
787 | ||
9fd6804d | 788 | @remote_compatible |
9464e099 JM |
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() | |
795 | ||
796 | dev[1].discover_peer(addr0) | |
797 | dev[1].p2p_stop_find() | |
798 | ev = dev[1].wait_global_event(["P2P-FIND-STOPPED"], timeout=2) | |
799 | time.sleep(0.1) | |
800 | dev[1].flush_scan_cache() | |
801 | ||
802 | pin = dev[1].wps_read_pin() | |
803 | dev[0].group_request("WPS_PIN any " + pin) | |
804 | ||
805 | try: | |
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"]) | |
809 | if ev is None: | |
810 | raise Exception("Active scan did not complete") | |
811 | finally: | |
812 | dev[1].request("SET p2p_disabled 0") | |
813 | ||
814 | for i in range(2): | |
815 | dev[1].request("SCAN freq=2412 passive=1") | |
816 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
817 | if ev is None: | |
818 | raise Exception("Scan did not complete") | |
819 | ||
820 | # Disable management frame processing for a moment to skip Probe Response | |
821 | # frame with P2P IE. | |
822 | dev[0].group_request("SET ext_mgmt_frame_handling 1") | |
823 | ||
a7efe6c3 | 824 | dev[1].global_request("P2P_CONNECT " + bssid + " " + pin + " freq=2412 join") |
9464e099 JM |
825 | |
826 | # Skip the first Probe Request frame | |
827 | ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) | |
828 | if ev is None: | |
829 | raise Exception("No Probe Request frame seen") | |
830 | if not ev.split(' ')[4].startswith("40"): | |
831 | raise Exception("Not a Probe Request frame") | |
832 | ||
a7efe6c3 AS |
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'])) | |
9464e099 JM |
842 | |
843 | # Skip Probe Request frames until something else is received | |
844 | for i in range(10): | |
845 | ev = dev[0].wait_group_event(["MGMT-RX"], timeout=10) | |
846 | if ev is None: | |
847 | raise Exception("No frame seen") | |
848 | if not ev.split(' ')[4].startswith("40"): | |
849 | break | |
850 | ||
851 | # Allow wpa_supplicant to process authentication and association | |
852 | dev[0].group_request("SET ext_mgmt_frame_handling 0") | |
853 | ||
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) | |
857 | if ev is None: | |
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() | |
05032725 | 863 | |
9fd6804d | 864 | @remote_compatible |
05032725 JM |
865 | def test_autogo_join_before_found(dev): |
866 | """P2P client joining a group before having found GO Device Address""" | |
9c01d6a9 | 867 | dev[0].global_request("SET p2p_no_group_iface 0") |
05032725 JM |
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'] | |
873 | ||
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) | |
880 | if ev is None: | |
881 | raise Exception("Joining the group timed out") | |
882 | dev[0].remove_group() | |
883 | dev[1].wait_go_ending_session() | |
6baab31c JM |
884 | |
885 | def test_autogo_noa(dev): | |
886 | """P2P autonomous GO and NoA""" | |
887 | res = autogo(dev[0]) | |
888 | dev[0].group_request("P2P_SET noa 1,5,20") | |
889 | dev[0].group_request("P2P_SET noa 255,10,50") | |
890 | ||
891 | # Connect and disconnect legacy STA to check NoA special cases | |
892 | try: | |
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() | |
900 | finally: | |
901 | dev[1].request("SET p2p_disabled 0") | |
902 | ||
903 | dev[0].group_request("P2P_SET noa 0,0,0") | |
e0e1fde8 JM |
904 | |
905 | def test_autogo_interworking(dev): | |
906 | """P2P autonomous GO and Interworking""" | |
907 | try: | |
908 | run_autogo_interworking(dev) | |
909 | finally: | |
910 | dev[0].set("go_interworking", "0") | |
911 | ||
912 | def run_autogo_interworking(dev): | |
1d914d01 AO |
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") | |
e0e1fde8 JM |
918 | res = autogo(dev[0]) |
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") |