1 # P2P device discovery test cases
2 # Copyright (c) 2013, 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
9 logger
= logging
.getLogger()
14 from wpasupplicant
import WpaSupplicant
15 from p2p_utils
import *
16 from test_gas
import start_ap
17 from test_cfg80211
import nl80211_remain_on_channel
20 def test_discovery(dev
):
21 """P2P device discovery and provision discovery"""
22 addr0
= dev
[0].p2p_dev_addr()
23 addr1
= dev
[1].p2p_dev_addr()
24 logger
.info("Start device discovery")
25 dev
[0].p2p_find(social
=True, delay
=1)
26 if not dev
[1].discover_peer(addr0
):
27 raise Exception("Device discovery timed out")
28 if not dev
[0].discover_peer(addr1
):
29 raise Exception("Device discovery timed out")
31 logger
.info("Test provision discovery for display")
32 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " display")
33 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout
=15)
35 raise Exception("Provision discovery timed out (display/dev1)")
37 raise Exception("Dev0 not in provision discovery event")
38 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN",
39 "P2P-PROV-DISC-FAILURE"], timeout
=15)
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)")
45 raise Exception("Dev1 not in provision discovery event")
47 logger
.info("Test provision discovery for keypad")
48 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " keypad")
49 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=15)
51 raise Exception("Provision discovery timed out (keypad/dev1)")
53 raise Exception("Dev0 not in provision discovery event")
54 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN",
55 "P2P-PROV-DISC-FAILURE"],
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)")
62 raise Exception("Dev1 not in provision discovery event")
64 logger
.info("Test provision discovery for push button")
65 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " pbc")
66 ev1
= dev
[1].wait_global_event(["P2P-PROV-DISC-PBC-REQ"], timeout
=15)
68 raise Exception("Provision discovery timed out (pbc/dev1)")
70 raise Exception("Dev0 not in provision discovery event")
71 ev0
= dev
[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP",
72 "P2P-PROV-DISC-FAILURE"],
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)")
79 raise Exception("Dev1 not in provision discovery event")
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")
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")
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")
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")
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()
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")
113 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-FAILURE"], timeout
=60)
115 raise Exception("No PD failure reported")
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
)
125 dev
[1].p2p_connect_group(dev
[0].p2p_dev_addr(), pin
, freq
=int(res
['freq']),
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")
130 if not dev
[2].discover_peer(dev
[1].p2p_dev_addr(), social
=False, timeout
=10):
131 stop_p2p_find_and_wait(dev
[2])
132 if not dev
[2].discover_peer(dev
[1].p2p_dev_addr(), social
=False, timeout
=10):
133 stop_p2p_find_and_wait(dev
[2])
134 if not dev
[2].discover_peer(dev
[1].p2p_dev_addr(), social
=False, timeout
=10):
135 raise Exception("Could not discover group client")
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.
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")
149 ev
= dev
[1].wait_group_event(["CTRL-EVENT-DISCONNECTED"], timeout
=10)
151 raise Exception("Timeout on waiting disconnection")
152 dev
[2].request("P2P_CONNECT {} {} display".format(dev
[1].p2p_dev_addr(),
154 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=2)
156 raise Exception("Unexpected frame RX on P2P client")
157 # make group client available on operating channe
158 dev
[1].group_request("REASSOCIATE")
159 ev
= dev
[1].wait_global_event(["CTRL-EVENT-CONNECTED",
160 "P2P-GO-NEG-REQUEST"], timeout
=10)
162 raise Exception("Timeout on reconnection to group")
163 if "P2P-GO-NEG-REQUEST" not in ev
:
164 ev
= dev
[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout
=10)
166 raise Exception("Timeout on waiting for GO Negotiation Request")
168 def stop_p2p_find_and_wait(dev
):
169 dev
.request("P2P_STOP_FIND")
171 res
= dev
.get_driver_status_field("scan_state")
172 if "SCAN_STARTED" not in res
and "SCAN_REQUESTED" not in res
:
174 logger
.debug("Waiting for final P2P_FIND scan to complete")
177 def test_discovery_ctrl_char_in_devname(dev
):
178 """P2P device discovery and control character in Device Name"""
180 _test_discovery_ctrl_char_in_devname(dev
)
182 dev
[1].global_request("SET device_name Device B")
184 def _test_discovery_ctrl_char_in_devname(dev
):
185 dev
[1].global_request("SET device_name Device\tB")
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):
195 stop_p2p_find_and_wait(dev
[2])
196 if not dev
[2].discover_peer(addr1
, social
=False, freq
=2422, timeout
=5):
197 stop_p2p_find_and_wait(dev
[2])
198 if not dev
[2].discover_peer(addr1
, social
=False, freq
=2422,
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
)
206 terminate_group(dev
[0], dev
[1])
207 dev
[2].request("P2P_FLUSH")
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
)
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")
222 dev
[0].p2p_find(social
=True, dev_type
="5-0050F204-1")
223 ev
= dev
[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=1)
225 raise Exception("Unexpected P2P device found")
226 dev
[0].p2p_find(social
=True, dev_type
="1-0050F204-2")
227 ev
= dev
[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=2)
229 raise Exception("P2P device not found")
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")
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)
243 dev
[2].p2p_find(social
=True, dev_type
="5-0050F204-1")
244 ev
= dev
[2].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=1)
246 raise Exception("Unexpected P2P device found")
247 dev
[2].p2p_find(social
=True, dev_type
="1-0050F204-2")
248 ev
= dev
[2].wait_global_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
250 raise Exception("P2P device not found")
252 def test_discovery_dev_id(dev
):
253 """P2P device discovery with Device ID filter"""
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
)
260 addr1
= dev
[1].p2p_dev_addr()
262 dev
[0].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
263 ev
= dev
[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=1)
265 raise Exception("Unexpected P2P device found")
266 dev
[0].p2p_find(social
=True, dev_id
=addr1
)
267 ev
= dev
[0].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=5)
269 raise Exception("P2P device not found")
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
:
277 status
= wpas
.global_request("STATUS")
278 if "p2p_state=IDLE" not in status
:
279 raise Exception("Unexpected status: " + status
)
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)
289 dev
[2].p2p_find(social
=True, dev_id
="02:03:04:05:06:07")
290 ev
= dev
[2].wait_global_event(['P2P-DEVICE-FOUND'], timeout
=1)
292 raise Exception("Unexpected P2P device found")
293 dev
[2].p2p_find(social
=True, dev_id
=addr1
)
294 ev
= dev
[2].wait_global_event(['P2P-DEVICE-FOUND ' + addr1
], timeout
=2)
296 raise Exception("P2P device not found")
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
)
301 dev
[1].p2p_find(social
=True)
302 dev
[0].p2p_find(progressive
=True)
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)
311 raise Exception("Peer not found")
313 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
315 raise Exception("Peer not found")
316 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
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")
326 def _test_discovery_and_interface_disabled(dev
, delay
=1):
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"])
332 raise Exception("Scan did not start")
333 dev
[0].request("DRIVER_EVENT INTERFACE_DISABLED")
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")
340 dev
[0].request("DRIVER_EVENT INTERFACE_ENABLED")
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()
347 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=15)
349 raise Exception("Peer not found")
351 dev
[0].request("DRIVER_EVENT INTERFACE_ENABLED")
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)
358 def test_discovery_auto(dev
):
359 """P2P device discovery and provision discovery with auto GO/dev selection"""
360 dev
[0].flush_scan_cache()
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")
367 if not dev
[1].discover_peer(addr0
):
368 raise Exception("Device discovery timed out")
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")
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)
379 raise Exception("Provision discovery timed out (display/dev1)")
381 raise Exception("Dev0 not in provision discovery event")
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)
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)")
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")
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)
399 raise Exception("Provision discovery timed out (display/dev2)")
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)
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)")
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")
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()
422 dev
[0].p2p_find(social
=False)
423 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=0.5)
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)
429 raise Exception("P2P_STOP not reported")
430 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
432 raise Exception("Peer found unexpectedly: " + ev
)
434 dev
[0].p2p_find(social
=False)
435 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=0.5)
437 logger
.info("No CTRL-EVENT-SCAN-STARTED event")
438 dev
[0].global_request("P2P_FLUSH")
439 ev
= dev
[0].wait_global_event(["P2P-FIND-STOPPED"], timeout
=1)
441 raise Exception("P2P_STOP not reported")
442 ev
= dev
[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
444 raise Exception("Peer found unexpectedly: " + ev
)
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()
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()
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")
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")
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()
484 if not dev
[0].discover_peer(addr1
):
485 raise Exception("Device discovery timed out")
488 dev
[0].global_request("P2P_PROV_DISC " + addr1
+ " display")
489 ev
= dev
[0].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout
=15)
491 raise Exception("No PD result reported")
492 dev
[1].p2p_stop_find()
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()
500 def test_p2p_listen_and_scan(dev
):
501 """P2P_LISTEN and scan"""
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)
507 raise Exception("Unexpected scan results")
508 dev
[0].p2p_stop_find()
509 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
511 raise Exception("Scan timed out")
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()
520 if "OK" not in wpas
.request("SET config_methods keypad virtual_push_button"):
521 raise Exception("Failed to set config_methods")
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")
532 if "OK" not in wpas
.request("SET config_methods virtual_display"):
533 raise Exception("Failed to set config_methods")
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'])
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)
553 raise Exception("No ANQP-QUERY-DONE event")
554 dev
[0].dump_monitor()
556 start
= os
.times()[4]
558 dev
[1].p2p_find(social
=True)
559 ev
= dev
[1].wait_global_event(["P2P-DEVICE-FOUND"], timeout
=5)
561 raise Exception("Peer not discovered")
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")
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)
581 addr0
= dev
[0].p2p_dev_addr()
583 dev
[0].p2p_find(social
=True)
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")
590 raise Exception("Did not find peer quickly enough after stopped P2P_LISTEN")