]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_grpform.py
tests: Mark 525 tests as remote compatible
[thirdparty/hostap.git] / tests / hwsim / test_p2p_grpform.py
1 # P2P group formation test cases
2 # Copyright (c) 2013-2014, 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
7 from remotehost import remote_compatible
8 import binascii
9 import logging
10 logger = logging.getLogger()
11 import struct
12 import time
13 import os
14
15 import hostapd
16 import hwsim_utils
17 import utils
18 from utils import HwsimSkip
19 from wpasupplicant import WpaSupplicant
20 from p2p_utils import *
21 from test_p2p_messages import parse_p2p_public_action, p2p_hdr, p2p_attr_capability, p2p_attr_go_intent, p2p_attr_config_timeout, p2p_attr_listen_channel, p2p_attr_intended_interface_addr, p2p_attr_channel_list, p2p_attr_device_info, p2p_attr_operating_channel, ie_p2p, ie_wsc, mgmt_tx, P2P_GO_NEG_REQ
22
23 @remote_compatible
24 def test_grpform(dev):
25 """P2P group formation using PIN and authorized connection (init -> GO)"""
26 try:
27 dev[0].global_request("SET p2p_group_idle 2")
28 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
29 r_dev=dev[1], r_intent=0)
30 check_grpform_results(i_res, r_res)
31 dev[1].remove_group()
32 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
33 if ev is None:
34 raise Exception("GO did not remove group on idle timeout")
35 if "GO reason=IDLE" not in ev:
36 raise Exception("Unexpected group removal event: " + ev)
37 finally:
38 dev[0].global_request("SET p2p_group_idle 0")
39
40 def test_grpform_a(dev):
41 """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
42 dev[0].global_request("SET p2p_no_group_iface 0")
43 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
44 r_dev=dev[1], r_intent=0)
45 if "p2p-wlan" not in i_res['ifname']:
46 raise Exception("Unexpected group interface name")
47 check_grpform_results(i_res, r_res)
48 remove_group(dev[0], dev[1])
49 if i_res['ifname'] in utils.get_ifnames():
50 raise Exception("Group interface netdev was not removed")
51
52 def test_grpform_b(dev):
53 """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
54 dev[1].global_request("SET p2p_no_group_iface 0")
55 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
56 r_dev=dev[1], r_intent=0)
57 if "p2p-wlan" not in r_res['ifname']:
58 raise Exception("Unexpected group interface name")
59 check_grpform_results(i_res, r_res)
60 addr = dev[0].group_request("P2P_GROUP_MEMBER " + dev[1].p2p_dev_addr())
61 if "FAIL" in addr:
62 raise Exception("P2P_GROUP_MEMBER failed")
63 if addr != dev[1].p2p_interface_addr():
64 raise Exception("Unexpected P2P_GROUP_MEMBER result: " + addr)
65 if "FAIL" not in dev[0].group_request("P2P_GROUP_MEMBER a"):
66 raise Exception("Invalid P2P_GROUP_MEMBER command accepted")
67 if "FAIL" not in dev[0].group_request("P2P_GROUP_MEMBER 00:11:22:33:44:55"):
68 raise Exception("P2P_GROUP_MEMBER for non-member accepted")
69 remove_group(dev[0], dev[1])
70 if r_res['ifname'] in utils.get_ifnames():
71 raise Exception("Group interface netdev was not removed")
72
73 def test_grpform_c(dev):
74 """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
75 dev[0].global_request("SET p2p_no_group_iface 0")
76 dev[1].global_request("SET p2p_no_group_iface 0")
77 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
78 r_dev=dev[1], r_intent=0)
79 if "p2p-wlan" not in i_res['ifname']:
80 raise Exception("Unexpected group interface name")
81 if "p2p-wlan" not in r_res['ifname']:
82 raise Exception("Unexpected group interface name")
83 check_grpform_results(i_res, r_res)
84 remove_group(dev[0], dev[1])
85 if i_res['ifname'] in utils.get_ifnames():
86 raise Exception("Group interface netdev was not removed")
87 if r_res['ifname'] in utils.get_ifnames():
88 raise Exception("Group interface netdev was not removed")
89
90 @remote_compatible
91 def test_grpform2(dev):
92 """P2P group formation using PIN and authorized connection (resp -> GO)"""
93 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
94 remove_group(dev[0], dev[1])
95
96 def test_grpform2_c(dev):
97 """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
98 dev[0].global_request("SET p2p_no_group_iface 0")
99 dev[1].global_request("SET p2p_no_group_iface 0")
100 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
101 remove_group(dev[0], dev[1])
102 if i_res['ifname'] in utils.get_ifnames():
103 raise Exception("Group interface netdev was not removed")
104 if r_res['ifname'] in utils.get_ifnames():
105 raise Exception("Group interface netdev was not removed")
106
107 @remote_compatible
108 def test_grpform3(dev):
109 """P2P group formation using PIN and re-init GO Negotiation"""
110 go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
111 remove_group(dev[0], dev[1])
112
113 def test_grpform3_c(dev):
114 """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
115 dev[0].global_request("SET p2p_no_group_iface 0")
116 dev[1].global_request("SET p2p_no_group_iface 0")
117 [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
118 remove_group(dev[0], dev[1])
119 if i_res['ifname'] in utils.get_ifnames():
120 raise Exception("Group interface netdev was not removed")
121 if r_res['ifname'] in utils.get_ifnames():
122 raise Exception("Group interface netdev was not removed")
123
124 @remote_compatible
125 def test_grpform4(dev):
126 """P2P group formation response during p2p_find"""
127 addr1 = dev[1].p2p_dev_addr()
128 dev[1].p2p_listen()
129 dev[0].discover_peer(addr1)
130 dev[1].p2p_find(social=True)
131 time.sleep(0.4)
132 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display")
133 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
134 if ev is None:
135 raise Exception("GO Negotiation RX timed out")
136 time.sleep(0.5)
137 dev[1].p2p_stop_find()
138 dev[0].p2p_stop_find()
139
140 @remote_compatible
141 def test_grpform_pbc(dev):
142 """P2P group formation using PBC and re-init GO Negotiation"""
143 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
144 check_grpform_results(i_res, r_res)
145 if i_res['role'] != 'GO' or r_res['role'] != 'client':
146 raise Exception("Unexpected device roles")
147 remove_group(dev[0], dev[1])
148
149 @remote_compatible
150 def test_grpform_pd(dev):
151 """P2P group formation with PD-before-GO-Neg workaround"""
152 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
153 check_grpform_results(i_res, r_res)
154 remove_group(dev[0], dev[1])
155
156 def test_grpform_ext_listen(dev):
157 """P2P group formation with extended listen timing enabled"""
158 addr0 = dev[0].p2p_dev_addr()
159 try:
160 if "FAIL" not in dev[0].global_request("P2P_EXT_LISTEN 100"):
161 raise Exception("Invalid P2P_EXT_LISTEN accepted")
162 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 300 1000"):
163 raise Exception("Failed to set extended listen timing")
164 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
165 raise Exception("Failed to set extended listen timing")
166 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1],
167 r_listen=True, i_freq="2417", r_freq="2417",
168 i_intent=1, r_intent=15)
169 check_grpform_results(i_res, r_res)
170 peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
171 if peer1['ext_listen_interval'] != "40000":
172 raise Exception("Extended listen interval not discovered correctly")
173 if peer1['ext_listen_period'] != "200":
174 raise Exception("Extended listen period not discovered correctly")
175 peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
176 if peer0['ext_listen_interval'] != "1000":
177 raise Exception("Extended listen interval not discovered correctly")
178 if peer0['ext_listen_period'] != "300":
179 raise Exception("Extended listen period not discovered correctly")
180 if not dev[2].discover_peer(addr0):
181 raise Exception("Could not discover peer during ext listen")
182 remove_group(dev[0], dev[1])
183 finally:
184 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
185 raise Exception("Failed to clear extended listen timing")
186 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
187 raise Exception("Failed to clear extended listen timing")
188
189 def test_grpform_ext_listen_oper(dev):
190 """P2P extended listen timing operations"""
191 try:
192 _test_grpform_ext_listen_oper(dev)
193 finally:
194 dev[0].global_request("P2P_EXT_LISTEN")
195
196 def _test_grpform_ext_listen_oper(dev):
197 addr0 = dev[0].p2p_dev_addr()
198 dev[0].global_request("SET p2p_no_group_iface 0")
199 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
200 wpas.interface_add("wlan5")
201 addr1 = wpas.p2p_dev_addr()
202 wpas.request("P2P_SET listen_channel 1")
203 wpas.global_request("SET p2p_no_group_iface 0")
204 wpas.request("P2P_LISTEN")
205 if not dev[0].discover_peer(addr1):
206 raise Exception("Could not discover peer")
207 dev[0].request("P2P_LISTEN")
208 if not wpas.discover_peer(addr0):
209 raise Exception("Could not discover peer (2)")
210
211 dev[0].global_request("P2P_EXT_LISTEN 300 500")
212 dev[0].global_request("P2P_CONNECT " + addr1 + " 12345670 display auth go_intent=0 freq=2417")
213 wpas.global_request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=15 freq=2417")
214 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
215 if ev is None:
216 raise Exception("GO Negotiation failed")
217 ifaces = wpas.request("INTERFACES").splitlines()
218 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
219 wpas.group_ifname = iface
220 if "OK" not in wpas.group_request("STOP_AP"):
221 raise Exception("STOP_AP failed")
222 wpas.group_request("SET ext_mgmt_frame_handling 1")
223 dev[1].p2p_find(social=True)
224 time.sleep(1)
225 if dev[1].peer_known(addr0):
226 raise Exception("Unexpected peer discovery")
227 ifaces = dev[0].request("INTERFACES").splitlines()
228 iface = ifaces[0] if "p2p-wlan" in ifaces[0] else ifaces[1]
229 if "OK" not in dev[0].global_request("P2P_GROUP_REMOVE " + iface):
230 raise Exception("Failed to request group removal")
231 wpas.remove_group()
232
233 count = 0
234 timeout = 15
235 found = False
236 while count < timeout * 4:
237 time.sleep(0.25)
238 count = count + 1
239 if dev[1].peer_known(addr0):
240 found = True
241 break
242 dev[1].p2p_stop_find()
243 if not found:
244 raise Exception("Could not discover peer that was supposed to use extended listen")
245
246 @remote_compatible
247 def test_both_go_intent_15(dev):
248 """P2P GO Negotiation with both devices using GO intent 15"""
249 go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True, i_go_neg_status=9)
250
251 @remote_compatible
252 def test_both_go_neg_display(dev):
253 """P2P GO Negotiation with both devices trying to display PIN"""
254 go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='display', r_method='display')
255
256 @remote_compatible
257 def test_both_go_neg_enter(dev):
258 """P2P GO Negotiation with both devices trying to enter PIN"""
259 go_neg_pin_authorized(i_dev=dev[0], r_dev=dev[1], expect_failure=True, i_go_neg_status=10, i_method='enter', r_method='enter')
260
261 @remote_compatible
262 def test_go_neg_pbc_vs_pin(dev):
263 """P2P GO Negotiation with one device using PBC and the other PIN"""
264 addr0 = dev[0].p2p_dev_addr()
265 addr1 = dev[1].p2p_dev_addr()
266 dev[1].p2p_listen()
267 if not dev[0].discover_peer(addr1):
268 raise Exception("Could not discover peer")
269 dev[0].p2p_listen()
270 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
271 raise Exception("Failed to authorize GO Neg")
272 if not dev[1].discover_peer(addr0):
273 raise Exception("Could not discover peer")
274 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
275 raise Exception("Failed to initiate GO Neg")
276 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
277 if ev is None:
278 raise Exception("GO Negotiation failure timed out")
279 if "status=10" not in ev:
280 raise Exception("Unexpected failure reason: " + ev)
281
282 @remote_compatible
283 def test_go_neg_pin_vs_pbc(dev):
284 """P2P GO Negotiation with one device using PIN and the other PBC"""
285 addr0 = dev[0].p2p_dev_addr()
286 addr1 = dev[1].p2p_dev_addr()
287 dev[1].p2p_listen()
288 if not dev[0].discover_peer(addr1):
289 raise Exception("Could not discover peer")
290 dev[0].p2p_listen()
291 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
292 raise Exception("Failed to authorize GO Neg")
293 if not dev[1].discover_peer(addr0):
294 raise Exception("Could not discover peer")
295 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
296 raise Exception("Failed to initiate GO Neg")
297 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
298 if ev is None:
299 raise Exception("GO Negotiation failure timed out")
300 if "status=10" not in ev:
301 raise Exception("Unexpected failure reason: " + ev)
302
303 def test_grpform_per_sta_psk(dev):
304 """P2P group formation with per-STA PSKs"""
305 dev[0].global_request("P2P_SET per_sta_psk 1")
306 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
307 check_grpform_results(i_res, r_res)
308
309 pin = dev[2].wps_read_pin()
310 dev[0].p2p_go_authorize_client(pin)
311 c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
312 check_grpform_results(i_res, c_res)
313
314 if r_res['psk'] == c_res['psk']:
315 raise Exception("Same PSK assigned for both clients")
316
317 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
318
319 dev[0].remove_group()
320 dev[1].wait_go_ending_session()
321 dev[2].wait_go_ending_session()
322
323 def test_grpform_per_sta_psk_wps(dev):
324 """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
325 dev[0].global_request("P2P_SET per_sta_psk 1")
326 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
327 check_grpform_results(i_res, r_res)
328
329 dev[0].p2p_go_authorize_client_pbc()
330 dev[2].request("WPS_PBC")
331 dev[2].wait_connected(timeout=30)
332
333 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
334
335 dev[0].remove_group()
336 dev[2].request("DISCONNECT")
337 dev[1].wait_go_ending_session()
338
339 @remote_compatible
340 def test_grpform_force_chan_go(dev):
341 """P2P group formation forced channel selection by GO"""
342 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
343 i_freq=2432,
344 r_dev=dev[1], r_intent=0,
345 test_data=False)
346 check_grpform_results(i_res, r_res)
347 if i_res['freq'] != "2432":
348 raise Exception("Unexpected channel - did not follow GO's forced channel")
349 remove_group(dev[0], dev[1])
350
351 @remote_compatible
352 def test_grpform_force_chan_cli(dev):
353 """P2P group formation forced channel selection by client"""
354 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
355 i_freq=2417,
356 r_dev=dev[1], r_intent=15,
357 test_data=False)
358 check_grpform_results(i_res, r_res)
359 if i_res['freq'] != "2417":
360 raise Exception("Unexpected channel - did not follow GO's forced channel")
361 remove_group(dev[0], dev[1])
362
363 @remote_compatible
364 def test_grpform_force_chan_conflict(dev):
365 """P2P group formation fails due to forced channel mismatch"""
366 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
367 r_dev=dev[1], r_intent=15, r_freq=2427,
368 expect_failure=True, i_go_neg_status=7)
369
370 @remote_compatible
371 def test_grpform_pref_chan_go(dev):
372 """P2P group formation preferred channel selection by GO"""
373 try:
374 dev[0].request("SET p2p_pref_chan 81:7")
375 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
376 r_dev=dev[1], r_intent=0,
377 test_data=False)
378 check_grpform_results(i_res, r_res)
379 if i_res['freq'] != "2442":
380 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
381 remove_group(dev[0], dev[1])
382 finally:
383 dev[0].request("SET p2p_pref_chan ")
384
385 @remote_compatible
386 def test_grpform_pref_chan_go_overridden(dev):
387 """P2P group formation preferred channel selection by GO overridden by client"""
388 try:
389 dev[1].request("SET p2p_pref_chan 81:7")
390 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
391 i_freq=2422,
392 r_dev=dev[1], r_intent=15,
393 test_data=False)
394 check_grpform_results(i_res, r_res)
395 if i_res['freq'] != "2422":
396 raise Exception("Unexpected channel - did not follow client's forced channel")
397 remove_group(dev[0], dev[1])
398 finally:
399 dev[1].request("SET p2p_pref_chan ")
400
401 @remote_compatible
402 def test_grpform_no_go_freq_forcing_chan(dev):
403 """P2P group formation with no-GO freq forcing channel"""
404 try:
405 dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
406 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
407 r_dev=dev[1], r_intent=15,
408 test_data=False)
409 check_grpform_results(i_res, r_res)
410 if int(i_res['freq']) > 4000:
411 raise Exception("Unexpected channel - did not follow no-GO freq")
412 remove_group(dev[0], dev[1])
413 finally:
414 dev[1].request("SET p2p_no_go_freq ")
415
416 @remote_compatible
417 def test_grpform_no_go_freq_conflict(dev):
418 """P2P group formation fails due to no-GO range forced by client"""
419 try:
420 dev[1].request("SET p2p_no_go_freq 2000-3000")
421 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
422 r_dev=dev[1], r_intent=15,
423 expect_failure=True, i_go_neg_status=7)
424 finally:
425 dev[1].request("SET p2p_no_go_freq ")
426
427 @remote_compatible
428 def test_grpform_no_5ghz_world_roaming(dev):
429 """P2P group formation with world roaming regulatory"""
430 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
431 r_dev=dev[1], r_intent=15,
432 test_data=False)
433 check_grpform_results(i_res, r_res)
434 if int(i_res['freq']) > 4000:
435 raise Exception("Unexpected channel - did not follow world roaming rules")
436 remove_group(dev[0], dev[1])
437
438 @remote_compatible
439 def test_grpform_no_5ghz_add_cli(dev):
440 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
441 try:
442 dev[0].request("SET p2p_add_cli_chan 1")
443 dev[1].request("SET p2p_add_cli_chan 1")
444 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
445 r_dev=dev[1], r_intent=14,
446 test_data=False)
447 check_grpform_results(i_res, r_res)
448 if int(i_res['freq']) > 4000:
449 raise Exception("Unexpected channel - did not follow world roaming rules")
450 remove_group(dev[0], dev[1])
451 finally:
452 dev[0].request("SET p2p_add_cli_chan 0")
453 dev[1].request("SET p2p_add_cli_chan 0")
454
455 @remote_compatible
456 def test_grpform_no_5ghz_add_cli2(dev):
457 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
458 try:
459 dev[0].request("SET p2p_add_cli_chan 1")
460 dev[1].request("SET p2p_add_cli_chan 1")
461 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14,
462 r_dev=dev[1], r_intent=0,
463 test_data=False)
464 check_grpform_results(i_res, r_res)
465 if int(i_res['freq']) > 4000:
466 raise Exception("Unexpected channel - did not follow world roaming rules")
467 remove_group(dev[0], dev[1])
468 finally:
469 dev[0].request("SET p2p_add_cli_chan 0")
470 dev[1].request("SET p2p_add_cli_chan 0")
471
472 @remote_compatible
473 def test_grpform_no_5ghz_add_cli3(dev):
474 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
475 try:
476 dev[0].request("SET p2p_add_cli_chan 1")
477 dev[1].request("SET p2p_add_cli_chan 1")
478 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
479 r_dev=dev[1], r_intent=15,
480 test_data=False)
481 check_grpform_results(i_res, r_res)
482 if int(i_res['freq']) > 4000:
483 raise Exception("Unexpected channel - did not follow world roaming rules")
484 remove_group(dev[0], dev[1])
485 finally:
486 dev[0].request("SET p2p_add_cli_chan 0")
487 dev[1].request("SET p2p_add_cli_chan 0")
488
489 @remote_compatible
490 def test_grpform_no_5ghz_add_cli4(dev):
491 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
492 try:
493 dev[0].request("SET p2p_add_cli_chan 1")
494 dev[1].request("SET p2p_add_cli_chan 1")
495 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
496 r_dev=dev[1], r_intent=0,
497 test_data=False)
498 check_grpform_results(i_res, r_res)
499 if int(i_res['freq']) > 4000:
500 raise Exception("Unexpected channel - did not follow world roaming rules")
501 remove_group(dev[0], dev[1])
502 finally:
503 dev[0].request("SET p2p_add_cli_chan 0")
504 dev[1].request("SET p2p_add_cli_chan 0")
505
506 @remote_compatible
507 def test_grpform_incorrect_pin(dev):
508 """P2P GO Negotiation with incorrect PIN"""
509 dev[1].p2p_listen()
510 addr1 = dev[1].p2p_dev_addr()
511 if not dev[0].discover_peer(addr1):
512 raise Exception("Peer not found")
513 res = dev[1].global_request("P2P_CONNECT " + dev[0].p2p_dev_addr() + " pin auth go_intent=0")
514 if "FAIL" in res:
515 raise Exception("P2P_CONNECT failed to generate PIN")
516 logger.info("PIN from P2P_CONNECT: " + res)
517 dev[0].global_request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
518 ev = dev[0].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
519 if ev is None:
520 raise Exception("GO Negotiation did not complete successfully(0)")
521 ev = dev[1].wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=15)
522 if ev is None:
523 raise Exception("GO Negotiation did not complete successfully(1)")
524 ev = dev[1].wait_global_event(["WPS-FAIL"], timeout=15)
525 if ev is None:
526 raise Exception("WPS failure not reported(1)")
527 if "msg=8 config_error=18" not in ev:
528 raise Exception("Unexpected WPS failure(1): " + ev)
529 ev = dev[0].wait_global_event(["WPS-FAIL"], timeout=15)
530 if ev is None:
531 raise Exception("WPS failure not reported")
532 if "msg=8 config_error=18" not in ev:
533 raise Exception("Unexpected WPS failure: " + ev)
534 ev = dev[1].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
535 if ev is None:
536 raise Exception("Group formation failure timed out")
537 ev = dev[0].wait_global_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
538 if ev is None:
539 raise Exception("Group formation failure timed out")
540
541 @remote_compatible
542 def test_grpform_reject(dev):
543 """User rejecting group formation attempt by a P2P peer"""
544 addr0 = dev[0].p2p_dev_addr()
545 dev[0].p2p_listen()
546 dev[1].p2p_go_neg_init(addr0, None, "pbc")
547 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
548 if ev is None:
549 raise Exception("GO Negotiation timed out")
550 if "OK" in dev[0].global_request("P2P_REJECT foo"):
551 raise Exception("Invalid P2P_REJECT accepted")
552 if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
553 raise Exception("P2P_REJECT failed")
554 dev[1].request("P2P_STOP_FIND")
555 dev[1].p2p_go_neg_init(addr0, None, "pbc")
556 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
557 if ev is None:
558 raise Exception("Rejection not reported")
559 if "status=11" not in ev:
560 raise Exception("Unexpected status code in rejection")
561
562 @remote_compatible
563 def test_grpform_pd_no_probe_resp(dev):
564 """GO Negotiation after PD, but no Probe Response"""
565 addr0 = dev[0].p2p_dev_addr()
566 addr1 = dev[1].p2p_dev_addr()
567 dev[0].p2p_listen()
568 if not dev[1].discover_peer(addr0):
569 raise Exception("Peer not found")
570 dev[1].p2p_stop_find()
571 dev[0].p2p_stop_find()
572 peer = dev[0].get_peer(addr1)
573 if peer['listen_freq'] == '0':
574 raise Exception("Peer listen frequency not learned from Probe Request")
575 time.sleep(0.3)
576 dev[0].request("P2P_FLUSH")
577 dev[0].p2p_listen()
578 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
579 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
580 if ev is None:
581 raise Exception("PD Request timed out")
582 ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
583 if ev is None:
584 raise Exception("PD Response timed out")
585 peer = dev[0].get_peer(addr1)
586 if peer['listen_freq'] != '0':
587 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
588
589 pin = dev[0].wps_read_pin()
590 if "FAIL" in dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
591 raise Exception("P2P_CONNECT on initiator failed")
592 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
593 if ev is None:
594 raise Exception("GO Negotiation start timed out")
595 peer = dev[0].get_peer(addr1)
596 if peer['listen_freq'] == '0':
597 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
598 if "FAIL" in dev[0].global_request("P2P_CONNECT " + addr1 + " " + pin + " display"):
599 raise Exception("P2P_CONNECT on responder failed")
600 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
601 if ev is None:
602 raise Exception("Group formation timed out")
603 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
604 if ev is None:
605 raise Exception("Group formation timed out")
606
607 def test_go_neg_two_peers(dev):
608 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
609 addr0 = dev[0].p2p_dev_addr()
610 addr1 = dev[1].p2p_dev_addr()
611 addr2 = dev[2].p2p_dev_addr()
612 dev[1].p2p_listen()
613 dev[2].p2p_listen()
614 if not dev[0].discover_peer(addr1):
615 raise Exception("Could not discover peer")
616 if not dev[0].discover_peer(addr2):
617 raise Exception("Could not discover peer")
618 if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
619 raise Exception("Failed to authorize GO Neg")
620 dev[0].p2p_listen()
621 if not dev[2].discover_peer(addr0):
622 raise Exception("Could not discover peer")
623 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
624 raise Exception("Failed to initiate GO Neg")
625 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
626 if ev is None:
627 raise Exception("timeout on GO Neg RX event")
628 dev[2].request("P2P_CONNECT " + addr0 + " pbc")
629 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
630 if ev is None:
631 raise Exception("Rejection not reported")
632 if "status=5" not in ev:
633 raise Exception("Unexpected status code in rejection: " + ev)
634
635 def clear_pbc_overlap(dev, ap):
636 hostapd.remove_bss(ap)
637 dev[0].request("P2P_CANCEL")
638 dev[1].request("P2P_CANCEL")
639 dev[0].p2p_stop_find()
640 dev[1].p2p_stop_find()
641 dev[0].dump_monitor()
642 dev[1].dump_monitor()
643 time.sleep(0.1)
644 dev[0].flush_scan_cache()
645 dev[1].flush_scan_cache()
646 time.sleep(0.1)
647
648 @remote_compatible
649 def test_grpform_pbc_overlap(dev, apdev):
650 """P2P group formation during PBC overlap"""
651 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
652 hapd = hostapd.add_ap(apdev[0], params)
653 hapd.request("WPS_PBC")
654 time.sleep(0.1)
655
656 # Since P2P Client scan case is now optimzied to use a specific SSID, the
657 # WPS AP will not reply to that and the scan after GO Negotiation can quite
658 # likely miss the AP due to dwell time being short enoguh to miss the Beacon
659 # frame. This has made the test case somewhat pointless, but keep it here
660 # for now with an additional scan to confirm that PBC detection works if
661 # there is a BSS entry for a overlapping AP.
662 for i in range(0, 5):
663 dev[0].scan(freq="2412")
664 if dev[0].get_bss(apdev[0]['bssid']) is not None:
665 break
666
667 addr0 = dev[0].p2p_dev_addr()
668 addr1 = dev[1].p2p_dev_addr()
669 dev[0].p2p_listen()
670 if not dev[1].discover_peer(addr0):
671 raise Exception("Could not discover peer")
672 dev[1].p2p_listen()
673 if not dev[0].discover_peer(addr1):
674 raise Exception("Could not discover peer")
675 dev[0].p2p_listen()
676 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
677 raise Exception("Failed to authorize GO Neg")
678 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
679 raise Exception("Failed to initiate GO Neg")
680 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
681 if ev is None:
682 raise Exception("PBC overlap not reported")
683
684 clear_pbc_overlap(dev, apdev[0])
685
686 @remote_compatible
687 def test_grpform_pbc_overlap_group_iface(dev, apdev):
688 """P2P group formation during PBC overlap using group interfaces"""
689 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
690 # update use this information.
691 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
692 "beacon_int": "15", 'manage_p2p': '1' }
693 hapd = hostapd.add_ap(apdev[0], params)
694 hapd.request("WPS_PBC")
695
696 dev[0].request("SET p2p_no_group_iface 0")
697 dev[1].request("SET p2p_no_group_iface 0")
698
699 addr0 = dev[0].p2p_dev_addr()
700 addr1 = dev[1].p2p_dev_addr()
701 dev[0].p2p_listen()
702 if not dev[1].discover_peer(addr0):
703 raise Exception("Could not discover peer")
704 dev[1].p2p_listen()
705 if not dev[0].discover_peer(addr1):
706 raise Exception("Could not discover peer")
707 dev[0].p2p_stop_find()
708 dev[0].scan(freq="2412")
709 dev[0].p2p_listen()
710 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
711 raise Exception("Failed to authorize GO Neg")
712 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
713 raise Exception("Failed to initiate GO Neg")
714 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
715 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
716 if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
717 # Do not report this as failure since the P2P group formation case
718 # using a separate group interface has limited chances of "seeing" the
719 # overlapping AP due to a per-SSID scan and no prior scan operations on
720 # the group interface.
721 logger.info("PBC overlap not reported")
722
723 clear_pbc_overlap(dev, apdev[0])
724
725 @remote_compatible
726 def test_grpform_goneg_fail_with_group_iface(dev):
727 """P2P group formation fails while using group interface"""
728 dev[0].request("SET p2p_no_group_iface 0")
729 dev[1].p2p_listen()
730 peer = dev[1].p2p_dev_addr()
731 if not dev[0].discover_peer(peer):
732 raise Exception("Peer " + peer + " not found")
733 if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
734 raise Exception("P2P_REJECT failed")
735 if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
736 raise Exception("P2P_CONNECT failed")
737 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
738 if ev is None:
739 raise Exception("GO Negotiation failure timed out")
740
741 def test_grpform_cred_ready_timeout(dev, apdev, params):
742 """P2P GO Negotiation wait for credentials to become ready [long]"""
743 if not params['long']:
744 raise HwsimSkip("Skip test case with long duration due to --long not specified")
745
746 dev[1].p2p_listen()
747 addr1 = dev[1].p2p_dev_addr()
748 if not dev[0].discover_peer(addr1):
749 raise Exception("Peer " + addr1 + " not found")
750 if not dev[2].discover_peer(addr1):
751 raise Exception("Peer " + addr1 + " not found(2)")
752
753 start = os.times()[4]
754
755 cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
756 if "OK" not in dev[0].global_request(cmd):
757 raise Exception("Failed to initiate GO Neg")
758
759 if "OK" not in dev[2].global_request(cmd):
760 raise Exception("Failed to initiate GO Neg(2)")
761
762 # First, check with p2p_find
763 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
764 if ev is not None:
765 raise Exception("Too early GO Negotiation timeout reported(2)")
766 dev[2].dump_monitor()
767 logger.info("Starting p2p_find to change state")
768 dev[2].p2p_find()
769 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=100)
770 if ev is None:
771 raise Exception("GO Negotiation failure timed out(2)")
772 dev[2].dump_monitor()
773 end = os.times()[4]
774 logger.info("GO Negotiation wait time: {} seconds(2)".format(end - start))
775 if end - start < 120:
776 raise Exception("Too short GO Negotiation wait time(2): {}".format(end - start))
777
778 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
779 wpas.interface_add("wlan5")
780
781 wpas.p2p_listen()
782 ev = dev[2].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
783 if ev is None:
784 raise Exception("Did not discover new device after GO Negotiation failure")
785 if wpas.p2p_dev_addr() not in ev:
786 raise Exception("Unexpected device found: " + ev)
787 dev[2].p2p_stop_find()
788 wpas.p2p_stop_find()
789
790 # Finally, verify without p2p_find
791 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
792 if ev is None:
793 raise Exception("GO Negotiation failure timed out")
794 end = os.times()[4]
795 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
796 if end - start < 120:
797 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
798
799 def test_grpform_no_wsc_done(dev):
800 """P2P group formation with WSC-Done not sent"""
801 addr0 = dev[0].p2p_dev_addr()
802 addr1 = dev[1].p2p_dev_addr()
803
804 for i in range(0, 2):
805 dev[0].request("SET ext_eapol_frame_io 1")
806 dev[1].request("SET ext_eapol_frame_io 1")
807 dev[0].p2p_listen()
808 dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
809 dev[1].p2p_listen()
810 dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
811 go_intent=15, wait_group=False)
812
813 mode = None
814 while True:
815 ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
816 if ev is None:
817 raise Exception("Timeout on EAPOL-TX from GO")
818 if not mode:
819 mode = dev[0].get_status_field("mode")
820 res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
821 if "OK" not in res:
822 raise Exception("EAPOL_RX failed")
823 ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
824 if ev is None:
825 raise Exception("Timeout on EAPOL-TX from P2P Client")
826 msg = ev.split(' ')[2]
827 if msg[46:56] == "102200010f":
828 logger.info("Drop WSC_Done")
829 dev[0].request("SET ext_eapol_frame_io 0")
830 dev[1].request("SET ext_eapol_frame_io 0")
831 # Fake EAP-Failure to complete session on the client
832 id = msg[10:12]
833 dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
834 break
835 res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
836 if "OK" not in res:
837 raise Exception("EAPOL_RX failed")
838
839 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
840 if ev is None:
841 raise Exception("Group formation timed out on GO")
842 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
843 if ev is None:
844 raise Exception("Group formation timed out on P2P Client")
845 dev[0].remove_group()
846 dev[1].wait_go_ending_session()
847
848 if mode != "P2P GO - group formation":
849 raise Exception("Unexpected mode on GO during group formation: " + mode)
850
851 @remote_compatible
852 def test_grpform_wait_peer(dev):
853 """P2P group formation wait for peer to become ready"""
854 addr0 = dev[0].p2p_dev_addr()
855 addr1 = dev[1].p2p_dev_addr()
856 dev[1].p2p_listen()
857 if not dev[0].discover_peer(addr1):
858 raise Exception("Peer " + addr1 + " not found")
859 dev[0].request("SET extra_roc_dur 500")
860 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
861 raise Exception("Failed to initiate GO Neg")
862 time.sleep(3)
863 dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
864
865 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
866 if ev is None:
867 raise Exception("Group formation timed out")
868 dev[0].group_form_result(ev)
869
870 dev[0].request("SET extra_roc_dur 0")
871 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
872 if ev is None:
873 raise Exception("Group formation timed out")
874 dev[0].remove_group()
875
876 @remote_compatible
877 def test_invalid_p2p_connect_command(dev):
878 """P2P_CONNECT error cases"""
879 id = dev[0].add_network()
880 for cmd in [ "foo",
881 "00:11:22:33:44:55",
882 "00:11:22:33:44:55 pbc persistent=123",
883 "00:11:22:33:44:55 pbc persistent=%d" % id,
884 "00:11:22:33:44:55 pbc go_intent=-1",
885 "00:11:22:33:44:55 pbc go_intent=16",
886 "00:11:22:33:44:55 pin",
887 "00:11:22:33:44:55 pbc freq=0" ]:
888 if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
889 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
890
891 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
892 raise Exception("Invalid PIN was not rejected")
893 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 12345678a"):
894 raise Exception("Invalid PIN was not rejected")
895
896 if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
897 raise Exception("Unsupported channel not reported")
898
899 @remote_compatible
900 def test_p2p_unauthorize(dev):
901 """P2P_UNAUTHORIZE to unauthorize a peer"""
902 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
903 raise Exception("Invalid P2P_UNAUTHORIZE accepted")
904 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
905 raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
906
907 addr0 = dev[0].p2p_dev_addr()
908 addr1 = dev[1].p2p_dev_addr()
909 dev[1].p2p_listen()
910 pin = dev[0].wps_read_pin()
911 dev[0].p2p_go_neg_auth(addr1, pin, "display")
912 dev[0].p2p_listen()
913 if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
914 raise Exception("P2P_UNAUTHORIZE failed")
915 dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
916 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
917 if ev is None:
918 raise Exception("No GO Negotiation Request RX reported")
919
920 @remote_compatible
921 def test_grpform_pbc_multiple(dev):
922 """P2P group formation using PBC multiple times in a row"""
923 try:
924 dev[1].request("SET passive_scan 1")
925 for i in range(5):
926 [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
927 r_dev=dev[1], r_intent=0)
928 remove_group(dev[0], dev[1])
929 finally:
930 dev[1].request("SET passive_scan 0")
931 dev[1].flush_scan_cache()
932
933 def test_grpform_not_ready(dev):
934 """Not ready for GO Negotiation (listen)"""
935 addr0 = dev[0].p2p_dev_addr()
936 addr2 = dev[2].p2p_dev_addr()
937 dev[0].p2p_listen()
938 if not dev[1].discover_peer(addr0):
939 raise Exception("Could not discover peer")
940 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
941 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
942 if ev is None:
943 raise Exception("No P2P-GO-NEG-REQUEST event")
944 dev[0].dump_monitor()
945 time.sleep(5)
946 if not dev[2].discover_peer(addr0):
947 raise Exception("Could not discover peer(2)")
948 for i in range(3):
949 dev[i].p2p_stop_find()
950
951 def test_grpform_not_ready2(dev):
952 """Not ready for GO Negotiation (search)"""
953 addr0 = dev[0].p2p_dev_addr()
954 addr2 = dev[2].p2p_dev_addr()
955 dev[0].p2p_find(social=True)
956 if not dev[1].discover_peer(addr0):
957 raise Exception("Could not discover peer")
958 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
959 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
960 if ev is None:
961 raise Exception("No P2P-GO-NEG-REQUEST event")
962 dev[0].dump_monitor()
963 time.sleep(1)
964 dev[2].p2p_listen()
965 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
966 if ev is None:
967 raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
968 if addr2 not in ev:
969 raise Exception("Unexpected peer discovered: " + ev)
970 for i in range(3):
971 dev[i].p2p_stop_find()
972
973 @remote_compatible
974 def test_grpform_and_scan(dev):
975 """GO Negotiation and scan operations"""
976 addr0 = dev[0].p2p_dev_addr()
977 addr1 = dev[1].p2p_dev_addr()
978 dev[1].p2p_listen()
979 if not dev[0].discover_peer(addr1):
980 raise Exception("Could not discover peer")
981 dev[0].p2p_stop_find()
982 dev[1].p2p_stop_find()
983
984 if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
985 raise Exception("Could not start scan")
986 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
987 if ev is None:
988 raise Exception("Scan did not start")
989 time.sleep(0.1)
990 # Request PD while the previously started scan is still in progress
991 if "OK" not in dev[0].request("P2P_PROV_DISC %s pbc" % addr1):
992 raise Exception("Could not request PD")
993 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
994 if ev is None:
995 raise Exception("Scan did not complete")
996 time.sleep(0.3)
997
998 dev[1].p2p_listen()
999 ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP"], timeout=5)
1000 if ev is None:
1001 raise Exception("PD Response not received")
1002
1003 if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
1004 raise Exception("Could not start scan")
1005 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
1006 if ev is None:
1007 raise Exception("Scan did not start")
1008 time.sleep(0.1)
1009 # Request GO Neg while the previously started scan is still in progress
1010 if "OK" not in dev[0].request("P2P_CONNECT %s pbc" % addr1):
1011 raise Exception("Could not request GO Negotiation")
1012 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1013 if ev is None:
1014 raise Exception("Scan did not complete")
1015
1016 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1017 if ev is None:
1018 raise Exception("GO Neg Req RX not reported")
1019
1020 dev[1].p2p_stop_find()
1021
1022 if "OK" not in dev[1].request("SCAN TYPE=ONLY freq=2412-2472"):
1023 raise Exception("Could not start scan")
1024 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
1025 if ev is None:
1026 raise Exception("Scan did not start")
1027 time.sleep(0.1)
1028 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
1029 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1030 if ev is None:
1031 raise Exception("Scan did not complete")
1032
1033 ev0 = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1034 if ev0 is None:
1035 raise Exception("Group formation timed out on dev0")
1036 dev[0].group_form_result(ev0)
1037
1038 ev1 = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1039 if ev1 is None:
1040 raise Exception("Group formation timed out on dev1")
1041 dev[1].group_form_result(ev1)
1042
1043 dev[0].dump_monitor()
1044 dev[1].dump_monitor()
1045
1046 remove_group(dev[0], dev[1])
1047
1048 dev[0].dump_monitor()
1049 dev[1].dump_monitor()
1050
1051 def test_grpform_go_neg_dup_on_restart(dev):
1052 """Duplicated GO Negotiation Request after GO Neg restart"""
1053 if dev[0].p2p_dev_addr() > dev[1].p2p_dev_addr():
1054 higher = dev[0]
1055 lower = dev[1]
1056 else:
1057 higher = dev[1]
1058 lower = dev[0]
1059 addr_low = lower.p2p_dev_addr()
1060 addr_high = higher.p2p_dev_addr()
1061 higher.p2p_listen()
1062 if not lower.discover_peer(addr_high):
1063 raise Exception("Could not discover peer")
1064 lower.p2p_stop_find()
1065
1066 if "OK" not in lower.request("P2P_CONNECT %s pbc" % addr_high):
1067 raise Exception("Could not request GO Negotiation")
1068 ev = higher.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1069 if ev is None:
1070 raise Exception("GO Neg Req RX not reported")
1071
1072 # Wait for GO Negotiation Response (Status=1) to go through
1073 time.sleep(0.2)
1074
1075 if "FAIL" in lower.request("SET ext_mgmt_frame_handling 1"):
1076 raise Exception("Failed to enable external management frame handling")
1077
1078 higher.p2p_stop_find()
1079 higher.global_request("P2P_CONNECT " + addr_low + " pbc")
1080
1081 # Wait for the GO Negotiation Request frame of the restarted GO Negotiation
1082 rx_msg = lower.mgmt_rx()
1083 if rx_msg is None:
1084 raise Exception("MGMT-RX timeout")
1085 p2p = parse_p2p_public_action(rx_msg['payload'])
1086 if p2p is None:
1087 raise Exception("Not a P2P Public Action frame")
1088 if p2p['subtype'] != 0:
1089 raise Exception("Unexpected P2P Public Action subtype %d" % p2p['subtype'])
1090
1091 # Send duplicate GO Negotiation Request from the prior instance of GO
1092 # Negotiation
1093 lower.p2p_stop_find()
1094 peer = higher.get_peer(addr_low)
1095
1096 msg = p2p_hdr(addr_high, addr_low, type=P2P_GO_NEG_REQ, dialog_token=123)
1097 attrs = p2p_attr_capability(dev_capab=0x25, group_capab=0x08)
1098 attrs += p2p_attr_go_intent(go_intent=7, tie_breaker=1)
1099 attrs += p2p_attr_config_timeout()
1100 attrs += p2p_attr_listen_channel(chan=(int(peer['listen_freq']) - 2407) / 5)
1101 attrs += p2p_attr_intended_interface_addr(lower.p2p_dev_addr())
1102 attrs += p2p_attr_channel_list()
1103 attrs += p2p_attr_device_info(addr_low, config_methods=0x80, name="Device A")
1104 attrs += p2p_attr_operating_channel()
1105 wsc_attrs = struct.pack(">HHH", 0x1012, 2, 4)
1106 msg['payload'] += ie_p2p(attrs) + ie_wsc(wsc_attrs)
1107 mgmt_tx(lower, "MGMT_TX {} {} freq={} wait_time=200 no_cck=1 action={}".format(addr_high, addr_high, peer['listen_freq'], binascii.hexlify(msg['payload'])))
1108
1109 # Wait for the GO Negotiation Response frame which would have been sent in
1110 # this case previously, but not anymore after the check for
1111 # dev->go_neg_req_sent and dev->flags & P2P_DEV_PEER_WAITING_RESPONSE.
1112 rx_msg = lower.mgmt_rx(timeout=0.2)
1113 if rx_msg is not None:
1114 raise Exception("Unexpected management frame")
1115
1116 if "FAIL" in lower.request("SET ext_mgmt_frame_handling 0"):
1117 raise Exception("Failed to disable external management frame handling")
1118 lower.p2p_listen()
1119
1120 ev = lower.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
1121 if ev is None:
1122 raise Exception("GO Negotiation did not succeed on dev0")
1123
1124 ev = higher.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
1125 if ev is None:
1126 raise Exception("GO Negotiation did not succeed on dev1")
1127
1128 ev0 = lower.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1129 if ev0 is None:
1130 raise Exception("Group formation timed out on dev0")
1131 lower.group_form_result(ev0)
1132
1133 ev1 = higher.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1134 if ev1 is None:
1135 raise Exception("Group formation timed out on dev1")
1136 higher.group_form_result(ev1)
1137
1138 lower.dump_monitor()
1139 higher.dump_monitor()
1140
1141 remove_group(lower, higher)
1142
1143 lower.dump_monitor()
1144 higher.dump_monitor()
1145
1146 @remote_compatible
1147 def test_grpform_go_neg_stopped(dev):
1148 """GO Negotiation stopped after TX start"""
1149 addr0 = dev[0].p2p_dev_addr()
1150 dev[0].p2p_listen()
1151 if not dev[1].discover_peer(addr0):
1152 raise Exception("Could not discover peer")
1153 dev[0].p2p_stop_find()
1154 if "OK" not in dev[1].request("P2P_CONNECT %s pbc" % addr0):
1155 raise Exception("Could not request GO Negotiation")
1156 dev[1].p2p_stop_find()
1157 dev[1].p2p_listen()
1158 dev[0].p2p_find(social=True)
1159 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1.2)
1160 dev[0].p2p_stop_find()
1161 dev[1].p2p_stop_find()
1162 if ev is None:
1163 raise Exception("Did not find peer quickly enough after stopped P2P_CONNECT")