]>
Commit | Line | Data |
---|---|---|
5743006d JM |
1 | # P2P device discovery test cases |
2 | # Copyright (c) 2013, Jouni Malinen <j@w1.fi> | |
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 |
5743006d | 8 | import logging |
c9aa4308 | 9 | logger = logging.getLogger() |
3bba9c71 | 10 | import os |
33714def | 11 | import time |
5743006d | 12 | |
5924d4c1 | 13 | import hwsim_utils |
b1d5134e | 14 | from wpasupplicant import WpaSupplicant |
7f2fea59 | 15 | from p2p_utils import * |
3bba9c71 | 16 | from test_gas import start_ap |
700c5d0b | 17 | from test_cfg80211 import nl80211_remain_on_channel |
5924d4c1 | 18 | |
9fd6804d | 19 | @remote_compatible |
5743006d | 20 | def test_discovery(dev): |
47c34473 | 21 | """P2P device discovery and provision discovery""" |
5743006d JM |
22 | addr0 = dev[0].p2p_dev_addr() |
23 | addr1 = dev[1].p2p_dev_addr() | |
24 | logger.info("Start device discovery") | |
7457c635 | 25 | dev[0].p2p_find(social=True, delay=1) |
fde43cdd | 26 | if not dev[1].discover_peer(addr0): |
5743006d | 27 | raise Exception("Device discovery timed out") |
fde43cdd | 28 | if not dev[0].discover_peer(addr1): |
5743006d | 29 | raise Exception("Device discovery timed out") |
5743006d JM |
30 | |
31 | logger.info("Test provision discovery for display") | |
0fa28afe JM |
32 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " display") |
33 | ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) | |
5743006d | 34 | if ev1 is None: |
b12b7c7a | 35 | raise Exception("Provision discovery timed out (display/dev1)") |
5743006d JM |
36 | if addr0 not in ev1: |
37 | raise Exception("Dev0 not in provision discovery event") | |
0fa28afe JM |
38 | ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN", |
39 | "P2P-PROV-DISC-FAILURE"], timeout=15) | |
5743006d | 40 | if ev0 is None: |
b12b7c7a JM |
41 | raise Exception("Provision discovery timed out (display/dev0)") |
42 | if "P2P-PROV-DISC-FAILURE" in ev0: | |
43 | raise Exception("Provision discovery failed (display/dev0)") | |
5743006d JM |
44 | if addr1 not in ev0: |
45 | raise Exception("Dev1 not in provision discovery event") | |
46 | ||
47 | logger.info("Test provision discovery for keypad") | |
0fa28afe JM |
48 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " keypad") |
49 | ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=15) | |
5743006d | 50 | if ev1 is None: |
b12b7c7a | 51 | raise Exception("Provision discovery timed out (keypad/dev1)") |
5743006d JM |
52 | if addr0 not in ev1: |
53 | raise Exception("Dev0 not in provision discovery event") | |
0fa28afe JM |
54 | ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN", |
55 | "P2P-PROV-DISC-FAILURE"], | |
56 | timeout=15) | |
5743006d | 57 | if ev0 is None: |
b12b7c7a JM |
58 | raise Exception("Provision discovery timed out (keypad/dev0)") |
59 | if "P2P-PROV-DISC-FAILURE" in ev0: | |
60 | raise Exception("Provision discovery failed (keypad/dev0)") | |
5743006d JM |
61 | if addr1 not in ev0: |
62 | raise Exception("Dev1 not in provision discovery event") | |
63 | ||
64 | logger.info("Test provision discovery for push button") | |
0fa28afe JM |
65 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " pbc") |
66 | ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15) | |
5743006d | 67 | if ev1 is None: |
b12b7c7a | 68 | raise Exception("Provision discovery timed out (pbc/dev1)") |
5743006d JM |
69 | if addr0 not in ev1: |
70 | raise Exception("Dev0 not in provision discovery event") | |
0fa28afe JM |
71 | ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP", |
72 | "P2P-PROV-DISC-FAILURE"], | |
73 | timeout=15) | |
5743006d | 74 | if ev0 is None: |
b12b7c7a JM |
75 | raise Exception("Provision discovery timed out (pbc/dev0)") |
76 | if "P2P-PROV-DISC-FAILURE" in ev0: | |
77 | raise Exception("Provision discovery failed (pbc/dev0)") | |
5743006d JM |
78 | if addr1 not in ev0: |
79 | raise Exception("Dev1 not in provision discovery event") | |
80 | ||
81 | dev[0].p2p_stop_find | |
82 | dev[1].p2p_stop_find | |
5924d4c1 | 83 | |
7457c635 JM |
84 | if "FAIL" not in dev[0].p2p_find(dev_id="foo"): |
85 | raise Exception("P2P_FIND with invalid dev_id accepted") | |
86 | if "FAIL" not in dev[0].p2p_find(dev_type="foo"): | |
87 | raise Exception("P2P_FIND with invalid dev_type accepted") | |
24b7f282 JM |
88 | if "FAIL" not in dev[0].p2p_find(dev_type="1-foo-2"): |
89 | raise Exception("P2P_FIND with invalid dev_type accepted") | |
90 | if "FAIL" not in dev[0].p2p_find(dev_type="1-11223344"): | |
91 | raise Exception("P2P_FIND with invalid dev_type accepted") | |
7457c635 | 92 | |
ca9b78ad JM |
93 | if "FAIL" not in dev[0].global_request("P2P_PROV_DISC foo pbc"): |
94 | raise Exception("Invalid P2P_PROV_DISC accepted") | |
95 | if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 00:11:22:33:44:55"): | |
96 | raise Exception("Invalid P2P_PROV_DISC accepted") | |
97 | if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 00:11:22:33:44:55 pbc join"): | |
98 | raise Exception("Invalid P2P_PROV_DISC accepted") | |
2acd2985 JM |
99 | if "FAIL" not in dev[0].global_request("P2P_PROV_DISC 00:11:22:33:44:55 foo"): |
100 | raise Exception("Invalid P2P_PROV_DISC accepted") | |
ca9b78ad | 101 | |
9fd6804d | 102 | @remote_compatible |
26e0c68f JM |
103 | def test_discovery_pd_retries(dev): |
104 | """P2P device discovery and provision discovery retries""" | |
105 | addr0 = dev[0].p2p_dev_addr() | |
106 | addr1 = dev[1].p2p_dev_addr() | |
107 | dev[1].p2p_listen() | |
108 | if not dev[0].discover_peer(addr1): | |
109 | raise Exception("Device discovery timed out") | |
110 | dev[1].p2p_stop_find() | |
111 | dev[0].p2p_stop_find() | |
112 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " display") | |
4ef05faf | 113 | ev = dev[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout=60) |
26e0c68f JM |
114 | if ev is None: |
115 | raise Exception("No PD failure reported") | |
116 | ||
5924d4c1 JM |
117 | def test_discovery_group_client(dev): |
118 | """P2P device discovery for a client in a group""" | |
119 | logger.info("Start autonomous GO " + dev[0].ifname) | |
120 | res = dev[0].p2p_start_go(freq="2422") | |
121 | logger.debug("res: " + str(res)) | |
122 | logger.info("Connect a client to the GO") | |
123 | pin = dev[1].wps_read_pin() | |
124 | dev[0].p2p_go_authorize_client(pin) | |
8251be17 JM |
125 | dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, freq=int(res['freq']), |
126 | timeout=60) | |
5924d4c1 JM |
127 | logger.info("Client connected") |
128 | hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) | |
129 | logger.info("Try to discover a P2P client in a group") | |
54c20c9b | 130 | if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): |
de8a45b6 | 131 | stop_p2p_find_and_wait(dev[2]) |
54c20c9b | 132 | if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): |
de8a45b6 | 133 | stop_p2p_find_and_wait(dev[2]) |
54c20c9b JM |
134 | if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): |
135 | raise Exception("Could not discover group client") | |
9a170ed2 JM |
136 | |
137 | # This is not really perfect, but something to get a bit more testing | |
138 | # coverage.. For proper discoverability mechanism validation, the P2P | |
139 | # client would need to go to sleep to avoid acknowledging the GO Negotiation | |
140 | # Request frame. Offchannel Listen mode operation on the P2P Client with | |
141 | # mac80211_hwsim is apparently not enough to avoid the acknowledgement on | |
142 | # the operating channel, so need to disconnect from the group which removes | |
143 | # the GO-to-P2P Client part of the discoverability exchange in practice. | |
144 | ||
145 | pin = dev[2].wps_read_pin() | |
146 | # make group client non-responsive on operating channel | |
147 | dev[1].dump_monitor() | |
148 | dev[1].group_request("DISCONNECT") | |
4ef05faf IP |
149 | ev = dev[1].wait_group_event(["CTRL-EVENT-DISCONNECTED"], timeout=10) |
150 | if ev is None: | |
151 | raise Exception("Timeout on waiting disconnection") | |
9a170ed2 JM |
152 | dev[2].request("P2P_CONNECT {} {} display".format(dev[1].p2p_dev_addr(), |
153 | pin)) | |
4ef05faf | 154 | ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=2) |
9a170ed2 JM |
155 | if ev: |
156 | raise Exception("Unexpected frame RX on P2P client") | |
157 | # make group client available on operating channe | |
4ef05faf IP |
158 | dev[1].group_request("REASSOCIATE") |
159 | ev = dev[1].wait_global_event(["CTRL-EVENT-CONNECTED", | |
160 | "P2P-GO-NEG-REQUEST"], timeout=10) | |
9a170ed2 JM |
161 | if ev is None: |
162 | raise Exception("Timeout on reconnection to group") | |
163 | if "P2P-GO-NEG-REQUEST" not in ev: | |
4ef05faf | 164 | ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10) |
9a170ed2 JM |
165 | if ev is None: |
166 | raise Exception("Timeout on waiting for GO Negotiation Request") | |
c70ebce0 | 167 | |
de8a45b6 JM |
168 | def stop_p2p_find_and_wait(dev): |
169 | dev.request("P2P_STOP_FIND") | |
170 | for i in range(10): | |
171 | res = dev.get_driver_status_field("scan_state") | |
172 | if "SCAN_STARTED" not in res and "SCAN_REQUESTED" not in res: | |
173 | break | |
174 | logger.debug("Waiting for final P2P_FIND scan to complete") | |
175 | time.sleep(0.02) | |
176 | ||
7f2fea59 JM |
177 | def test_discovery_ctrl_char_in_devname(dev): |
178 | """P2P device discovery and control character in Device Name""" | |
179 | try: | |
180 | _test_discovery_ctrl_char_in_devname(dev) | |
181 | finally: | |
182 | dev[1].global_request("SET device_name Device B") | |
183 | ||
184 | def _test_discovery_ctrl_char_in_devname(dev): | |
596a3fef | 185 | dev[1].global_request("SET device_name Device\tB") |
7f2fea59 JM |
186 | addr0 = dev[0].p2p_dev_addr() |
187 | addr1 = dev[1].p2p_dev_addr() | |
188 | res = dev[0].p2p_start_go(freq=2422) | |
189 | bssid = dev[0].p2p_interface_addr() | |
190 | pin = dev[1].wps_read_pin() | |
191 | dev[0].p2p_go_authorize_client(pin) | |
192 | dev[1].scan_for_bss(bssid, freq=2422) | |
193 | dev[1].p2p_connect_group(addr0, pin, timeout=60, freq=2422) | |
194 | if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): | |
de8a45b6 | 195 | stop_p2p_find_and_wait(dev[2]) |
7f2fea59 | 196 | if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): |
de8a45b6 | 197 | stop_p2p_find_and_wait(dev[2]) |
7f2fea59 JM |
198 | if not dev[2].discover_peer(addr1, social=False, freq=2422, |
199 | timeout=5): | |
200 | raise Exception("Could not discover group client") | |
201 | devname = dev[2].get_peer(addr1)['device_name'] | |
202 | dev[2].p2p_stop_find() | |
203 | if devname != "Device_B": | |
204 | raise Exception("Unexpected device_name from group client: " + devname) | |
205 | ||
206 | terminate_group(dev[0], dev[1]) | |
207 | dev[2].request("P2P_FLUSH") | |
208 | ||
209 | dev[1].p2p_listen() | |
210 | if not dev[2].discover_peer(addr1, social=True, timeout=10): | |
211 | raise Exception("Could not discover peer") | |
212 | devname = dev[2].get_peer(addr1)['device_name'] | |
213 | dev[2].p2p_stop_find() | |
214 | if devname != "Device_B": | |
215 | raise Exception("Unexpected device_name from peer: " + devname) | |
216 | ||
9fd6804d | 217 | @remote_compatible |
c70ebce0 JM |
218 | def test_discovery_dev_type(dev): |
219 | """P2P device discovery with Device Type filter""" | |
220 | dev[1].request("SET sec_device_type 1-0050F204-2") | |
221 | dev[1].p2p_listen() | |
222 | dev[0].p2p_find(social=True, dev_type="5-0050F204-1") | |
4ef05faf | 223 | ev = dev[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout=1) |
c70ebce0 JM |
224 | if ev: |
225 | raise Exception("Unexpected P2P device found") | |
226 | dev[0].p2p_find(social=True, dev_type="1-0050F204-2") | |
4ef05faf | 227 | ev = dev[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout=2) |
c70ebce0 JM |
228 | if ev is None: |
229 | raise Exception("P2P device not found") | |
d6df0d7e JM |
230 | peer = dev[0].get_peer(dev[1].p2p_dev_addr()) |
231 | if "1-0050F204-2" not in peer['sec_dev_type']: | |
232 | raise Exception("sec_device_type not reported properly") | |
c70ebce0 JM |
233 | |
234 | def test_discovery_dev_type_go(dev): | |
235 | """P2P device discovery with Device Type filter on GO""" | |
236 | addr1 = dev[1].p2p_dev_addr() | |
237 | dev[1].request("SET sec_device_type 1-0050F204-2") | |
238 | res = dev[0].p2p_start_go(freq="2412") | |
239 | pin = dev[1].wps_read_pin() | |
240 | dev[0].p2p_go_authorize_client(pin) | |
241 | dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) | |
242 | ||
243 | dev[2].p2p_find(social=True, dev_type="5-0050F204-1") | |
4ef05faf | 244 | ev = dev[2].wait_global_event(['P2P-DEVICE-FOUND'], timeout=1) |
c70ebce0 JM |
245 | if ev: |
246 | raise Exception("Unexpected P2P device found") | |
247 | dev[2].p2p_find(social=True, dev_type="1-0050F204-2") | |
4ef05faf | 248 | ev = dev[2].wait_global_event(['P2P-DEVICE-FOUND ' + addr1], timeout=2) |
c70ebce0 JM |
249 | if ev is None: |
250 | raise Exception("P2P device not found") | |
251 | ||
252 | def test_discovery_dev_id(dev): | |
253 | """P2P device discovery with Device ID filter""" | |
b1d5134e JM |
254 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') |
255 | wpas.interface_add("wlan5") | |
256 | wpas.request("P2P_LISTEN 1") | |
257 | status = wpas.global_request("STATUS") | |
258 | if "p2p_state=LISTEN_ONLY" not in status: | |
259 | raise Exception("Unexpected status: " + status) | |
c70ebce0 JM |
260 | addr1 = dev[1].p2p_dev_addr() |
261 | dev[1].p2p_listen() | |
262 | dev[0].p2p_find(social=True, dev_id="02:03:04:05:06:07") | |
098a687f | 263 | ev = dev[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout=1) |
c70ebce0 JM |
264 | if ev: |
265 | raise Exception("Unexpected P2P device found") | |
266 | dev[0].p2p_find(social=True, dev_id=addr1) | |
098a687f | 267 | ev = dev[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout=5) |
c70ebce0 JM |
268 | if ev is None: |
269 | raise Exception("P2P device not found") | |
b1d5134e JM |
270 | if addr1 not in ev: |
271 | raise Exception("Unexpected P2P peer found") | |
272 | status = wpas.global_request("STATUS") | |
273 | for i in range(0, 2): | |
274 | if "p2p_state=IDLE" in status: | |
275 | break | |
276 | time.sleep(0.5) | |
277 | status = wpas.global_request("STATUS") | |
278 | if "p2p_state=IDLE" not in status: | |
279 | raise Exception("Unexpected status: " + status) | |
c70ebce0 JM |
280 | |
281 | def test_discovery_dev_id_go(dev): | |
282 | """P2P device discovery with Device ID filter on GO""" | |
283 | addr1 = dev[1].p2p_dev_addr() | |
284 | res = dev[0].p2p_start_go(freq="2412") | |
285 | pin = dev[1].wps_read_pin() | |
286 | dev[0].p2p_go_authorize_client(pin) | |
287 | dev[1].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60) | |
288 | ||
289 | dev[2].p2p_find(social=True, dev_id="02:03:04:05:06:07") | |
4ef05faf | 290 | ev = dev[2].wait_global_event(['P2P-DEVICE-FOUND'], timeout=1) |
c70ebce0 JM |
291 | if ev: |
292 | raise Exception("Unexpected P2P device found") | |
293 | dev[2].p2p_find(social=True, dev_id=addr1) | |
4ef05faf | 294 | ev = dev[2].wait_global_event(['P2P-DEVICE-FOUND ' + addr1], timeout=2) |
c70ebce0 JM |
295 | if ev is None: |
296 | raise Exception("P2P device not found") | |
5070b14a JM |
297 | |
298 | def test_discovery_social_plus_one(dev): | |
299 | """P2P device discovery with social-plus-one""" | |
300 | logger.info("Start autonomous GO " + dev[0].ifname) | |
5070b14a JM |
301 | dev[1].p2p_find(social=True) |
302 | dev[0].p2p_find(progressive=True) | |
d7fb9e48 JM |
303 | logger.info("Wait for initial progressive find phases") |
304 | dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"]) | |
305 | dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"]) | |
306 | go = dev[2].p2p_dev_addr() | |
307 | dev[2].p2p_start_go(freq="2422") | |
308 | logger.info("Verify whether the GO on non-social channel can be found") | |
309 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15) | |
5070b14a JM |
310 | if ev is None: |
311 | raise Exception("Peer not found") | |
d7fb9e48 JM |
312 | if go not in ev: |
313 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15) | |
314 | if ev is None: | |
315 | raise Exception("Peer not found") | |
316 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15) | |
5070b14a JM |
317 | if ev is None: |
318 | raise Exception("Peer not found") | |
319 | dev[0].p2p_stop_find() | |
320 | dev[1].p2p_stop_find() | |
321 | if not dev[0].peer_known(go): | |
322 | raise Exception("GO not found in progressive scan") | |
323 | if dev[1].peer_known(go): | |
324 | raise Exception("GO found in social-only scan") | |
33714def | 325 | |
d4b521a3 | 326 | def _test_discovery_and_interface_disabled(dev, delay=1): |
33714def JM |
327 | try: |
328 | if "OK" not in dev[0].p2p_find(): | |
329 | raise Exception("Failed to start P2P find") | |
330 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"]) | |
331 | if ev is None: | |
332 | raise Exception("Scan did not start") | |
333 | dev[0].request("DRIVER_EVENT INTERFACE_DISABLED") | |
d4b521a3 | 334 | time.sleep(delay) |
33714def JM |
335 | |
336 | # verify that P2P_FIND is rejected | |
337 | if "FAIL" not in dev[0].p2p_find(): | |
338 | raise Exception("New P2P_FIND request was accepted unexpectedly") | |
339 | ||
340 | dev[0].request("DRIVER_EVENT INTERFACE_ENABLED") | |
341 | time.sleep(3) | |
342 | dev[0].scan(freq="2412") | |
343 | if "OK" not in dev[0].p2p_find(): | |
344 | raise Exception("Failed to start P2P find") | |
345 | dev[0].dump_monitor() | |
346 | dev[1].p2p_listen() | |
347 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=15) | |
348 | if ev is None: | |
349 | raise Exception("Peer not found") | |
350 | finally: | |
351 | dev[0].request("DRIVER_EVENT INTERFACE_ENABLED") | |
7c33a656 | 352 | |
d4b521a3 IP |
353 | def test_discovery_and_interface_disabled(dev): |
354 | """P2P device discovery with interface getting disabled""" | |
355 | _test_discovery_and_interface_disabled(dev, delay=1) | |
356 | _test_discovery_and_interface_disabled(dev, delay=5) | |
357 | ||
7c33a656 JM |
358 | def test_discovery_auto(dev): |
359 | """P2P device discovery and provision discovery with auto GO/dev selection""" | |
f751368e | 360 | dev[0].flush_scan_cache() |
7c33a656 JM |
361 | addr0 = dev[0].p2p_dev_addr() |
362 | addr1 = dev[1].p2p_dev_addr() | |
363 | addr2 = dev[2].p2p_dev_addr() | |
364 | dev[2].p2p_start_go(freq="2412") | |
365 | logger.info("Start device discovery") | |
366 | dev[0].p2p_listen() | |
367 | if not dev[1].discover_peer(addr0): | |
368 | raise Exception("Device discovery timed out") | |
369 | dev[1].p2p_listen() | |
370 | if not dev[0].discover_peer(addr1): | |
371 | raise Exception("Device discovery timed out") | |
372 | if not dev[0].discover_peer(addr2): | |
373 | raise Exception("Device discovery timed out") | |
374 | ||
375 | logger.info("Test provision discovery for display (device)") | |
376 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " display auto") | |
377 | ev1 = dev[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) | |
378 | if ev1 is None: | |
379 | raise Exception("Provision discovery timed out (display/dev1)") | |
380 | if addr0 not in ev1: | |
381 | raise Exception("Dev0 not in provision discovery event") | |
382 | if " group=" in ev1: | |
383 | raise Exception("Unexpected group parameter from non-GO") | |
384 | ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN", | |
385 | "P2P-PROV-DISC-FAILURE"], timeout=15) | |
386 | if ev0 is None: | |
387 | raise Exception("Provision discovery timed out (display/dev0)") | |
388 | if "P2P-PROV-DISC-FAILURE" in ev0: | |
389 | raise Exception("Provision discovery failed (display/dev0)") | |
390 | if addr1 not in ev0: | |
391 | raise Exception("Dev1 not in provision discovery event") | |
392 | if "peer_go=0" not in ev0: | |
393 | raise Exception("peer_go incorrect in PD response from non-GO") | |
394 | ||
395 | logger.info("Test provision discovery for display (GO)") | |
396 | dev[0].global_request("P2P_PROV_DISC " + addr2 + " display auto") | |
397 | ev2 = dev[2].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) | |
398 | if ev2 is None: | |
399 | raise Exception("Provision discovery timed out (display/dev2)") | |
400 | if addr0 not in ev2: | |
401 | raise Exception("Dev0 not in provision discovery event") | |
402 | if " group=" not in ev2: | |
403 | raise Exception("Group parameter missing from GO") | |
404 | ev0 = dev[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN", | |
405 | "P2P-PROV-DISC-FAILURE"], timeout=15) | |
406 | if ev0 is None: | |
407 | raise Exception("Provision discovery timed out (display/dev0)") | |
408 | if "P2P-PROV-DISC-FAILURE" in ev0: | |
409 | raise Exception("Provision discovery failed (display/dev0)") | |
410 | if addr2 not in ev0: | |
411 | raise Exception("Dev1 not in provision discovery event") | |
412 | if "peer_go=1" not in ev0: | |
413 | raise Exception("peer_go incorrect in PD response from GO") | |
70892f69 JM |
414 | |
415 | def test_discovery_stop(dev): | |
416 | """P2P device discovery and p2p_stop_find""" | |
417 | addr0 = dev[0].p2p_dev_addr() | |
418 | addr1 = dev[1].p2p_dev_addr() | |
419 | dev[1].p2p_listen() | |
420 | dev[2].p2p_listen() | |
421 | ||
422 | dev[0].p2p_find(social=False) | |
423 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.5) | |
424 | if ev is None: | |
425 | logger.info("No CTRL-EVENT-SCAN-STARTED event") | |
426 | dev[0].p2p_stop_find() | |
427 | ev = dev[0].wait_global_event(["P2P-FIND-STOPPED"], timeout=1) | |
428 | if ev is None: | |
429 | raise Exception("P2P_STOP not reported") | |
430 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) | |
431 | if ev is not None: | |
432 | raise Exception("Peer found unexpectedly: " + ev) | |
433 | ||
434 | dev[0].p2p_find(social=False) | |
435 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.5) | |
436 | if ev is None: | |
437 | logger.info("No CTRL-EVENT-SCAN-STARTED event") | |
e9986d8b | 438 | dev[0].global_request("P2P_FLUSH") |
70892f69 JM |
439 | ev = dev[0].wait_global_event(["P2P-FIND-STOPPED"], timeout=1) |
440 | if ev is None: | |
441 | raise Exception("P2P_STOP not reported") | |
442 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) | |
443 | if ev is not None: | |
444 | raise Exception("Peer found unexpectedly: " + ev) | |
7b7b2017 JM |
445 | |
446 | def test_p2p_peer_command(dev): | |
447 | """P2P_PEER command""" | |
448 | addr0 = dev[0].p2p_dev_addr() | |
449 | addr1 = dev[1].p2p_dev_addr() | |
450 | addr2 = dev[2].p2p_dev_addr() | |
451 | dev[1].p2p_listen() | |
452 | dev[2].p2p_listen() | |
453 | if not dev[0].discover_peer(addr1): | |
454 | raise Exception("Device discovery timed out") | |
455 | if not dev[0].discover_peer(addr2): | |
456 | raise Exception("Device discovery timed out") | |
457 | dev[0].p2p_stop_find() | |
458 | dev[1].p2p_stop_find() | |
459 | dev[2].p2p_stop_find() | |
460 | ||
461 | res0 = dev[0].request("P2P_PEER FIRST") | |
462 | peer = res0.splitlines()[0] | |
463 | if peer not in [ addr1, addr2 ]: | |
464 | raise Exception("Unexpected P2P_PEER FIRST address") | |
465 | res1 = dev[0].request("P2P_PEER NEXT-" + peer) | |
466 | peer2 = res1.splitlines()[0] | |
467 | if peer2 not in [ addr1, addr2 ] or peer == peer2: | |
468 | raise Exception("Unexpected P2P_PEER NEXT address") | |
469 | ||
470 | if "FAIL" not in dev[0].request("P2P_PEER NEXT-foo"): | |
471 | raise Exception("Invalid P2P_PEER command accepted") | |
472 | if "FAIL" not in dev[0].request("P2P_PEER foo"): | |
473 | raise Exception("Invalid P2P_PEER command accepted") | |
474 | if "FAIL" not in dev[0].request("P2P_PEER 00:11:22:33:44:55"): | |
475 | raise Exception("P2P_PEER command for unknown peer accepted") | |
7c5c1ba7 JM |
476 | |
477 | def test_p2p_listen_and_offchannel_tx(dev): | |
478 | """P2P_LISTEN behavior with offchannel TX""" | |
479 | addr0 = dev[0].p2p_dev_addr() | |
480 | addr1 = dev[1].p2p_dev_addr() | |
481 | addr2 = dev[2].p2p_dev_addr() | |
482 | ||
483 | dev[1].p2p_listen() | |
484 | if not dev[0].discover_peer(addr1): | |
485 | raise Exception("Device discovery timed out") | |
486 | ||
487 | dev[0].p2p_listen() | |
488 | dev[0].global_request("P2P_PROV_DISC " + addr1 + " display") | |
e9986d8b | 489 | ev = dev[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=15) |
7c5c1ba7 JM |
490 | if ev is None: |
491 | raise Exception("No PD result reported") | |
492 | dev[1].p2p_stop_find() | |
493 | ||
494 | if not dev[2].discover_peer(addr0): | |
495 | raise Exception("Device discovery timed out after PD exchange") | |
496 | dev[2].p2p_stop_find() | |
497 | dev[0].p2p_stop_find() | |
ed930f06 | 498 | |
9fd6804d | 499 | @remote_compatible |
ed930f06 JM |
500 | def test_p2p_listen_and_scan(dev): |
501 | """P2P_LISTEN and scan""" | |
502 | dev[0].p2p_listen() | |
503 | if "OK" not in dev[0].request("SCAN freq=2412"): | |
504 | raise Exception("Failed to request a scan") | |
505 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 3) | |
506 | if ev is not None: | |
507 | raise Exception("Unexpected scan results") | |
508 | dev[0].p2p_stop_find() | |
509 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15) | |
510 | if ev is None: | |
511 | raise Exception("Scan timed out") | |
926404a6 JM |
512 | |
513 | def test_p2p_config_methods(dev): | |
514 | """P2P and WPS config method update""" | |
515 | addr0 = dev[0].p2p_dev_addr() | |
516 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
517 | wpas.interface_add("wlan5") | |
518 | addr1 = wpas.p2p_dev_addr() | |
519 | ||
520 | if "OK" not in wpas.request("SET config_methods keypad virtual_push_button"): | |
521 | raise Exception("Failed to set config_methods") | |
522 | ||
523 | wpas.p2p_listen() | |
524 | if not dev[0].discover_peer(addr1): | |
525 | raise Exception("Device discovery timed out") | |
526 | dev[0].p2p_stop_find() | |
527 | peer = dev[0].get_peer(addr1) | |
528 | if peer['config_methods'] != '0x180': | |
529 | raise Exception("Unexpected peer config methods(1): " + peer['config_methods']) | |
530 | dev[0].global_request("P2P_FLUSH") | |
531 | ||
532 | if "OK" not in wpas.request("SET config_methods virtual_display"): | |
533 | raise Exception("Failed to set config_methods") | |
534 | ||
535 | if not dev[0].discover_peer(addr1): | |
536 | raise Exception("Device discovery timed out") | |
537 | dev[0].p2p_stop_find() | |
538 | peer = dev[0].get_peer(addr1) | |
539 | if peer['config_methods'] != '0x8': | |
540 | raise Exception("Unexpected peer config methods(2): " + peer['config_methods']) | |
541 | ||
542 | wpas.p2p_stop_find() | |
3bba9c71 | 543 | |
9fd6804d | 544 | @remote_compatible |
3bba9c71 JM |
545 | def test_discovery_after_gas(dev, apdev): |
546 | """P2P device discovery after GAS/ANQP exchange""" | |
547 | hapd = start_ap(apdev[0]) | |
548 | hapd.set("gas_frag_limit", "50") | |
549 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) | |
550 | dev[0].request("FETCH_ANQP") | |
551 | ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10) | |
552 | if ev is None: | |
553 | raise Exception("No ANQP-QUERY-DONE event") | |
554 | dev[0].dump_monitor() | |
555 | ||
556 | start = os.times()[4] | |
557 | dev[0].p2p_listen() | |
558 | dev[1].p2p_find(social=True) | |
559 | ev = dev[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout=5) | |
560 | if ev is None: | |
561 | raise Exception("Peer not discovered") | |
562 | end = os.times()[4] | |
563 | dev[0].dump_monitor() | |
564 | dev[0].p2p_stop_find() | |
565 | dev[1].p2p_stop_find() | |
566 | logger.info("Device discovery after fragmented GAS took %f seconds" % (end - start)) | |
567 | if end - start > 1.3: | |
568 | raise Exception("Device discovery took unexpectedly long time") | |
700c5d0b | 569 | |
9fd6804d | 570 | @remote_compatible |
700c5d0b JM |
571 | def test_discovery_listen_find(dev): |
572 | """P2P_LISTEN immediately followed by P2P_FIND""" | |
573 | # Request an external remain-on-channel operation to delay start of the ROC | |
574 | # for the following p2p_listen() enough to get p2p_find() processed before | |
575 | # the ROC started event shows up. This is done to test a code path where the | |
576 | # p2p_find() needs to clear the wait for the pending listen operation | |
577 | # (p2p->pending_listen_freq). | |
578 | ifindex = int(dev[0].get_driver_status_field("ifindex")) | |
579 | nl80211_remain_on_channel(dev[0], ifindex, 2417, 200) | |
580 | ||
581 | addr0 = dev[0].p2p_dev_addr() | |
582 | dev[0].p2p_listen() | |
583 | dev[0].p2p_find(social=True) | |
584 | time.sleep(0.4) | |
585 | dev[1].p2p_listen() | |
586 | ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1.2) | |
587 | if not dev[1].discover_peer(addr0): | |
588 | raise Exception("Device discovery timed out") | |
589 | if ev is None: | |
590 | raise Exception("Did not find peer quickly enough after stopped P2P_LISTEN") |