]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_grpform.py
tests: WPS PBC session overlap detection with single BSSID selected
[thirdparty/hostap.git] / tests / hwsim / test_p2p_grpform.py
1 # P2P group formation test cases
2 # Copyright (c) 2013-2019, 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 remove_group(dev[0], dev[1], allow_failure=True)
642 dev[0].dump_monitor()
643 dev[1].dump_monitor()
644 time.sleep(0.1)
645 dev[0].flush_scan_cache()
646 dev[1].flush_scan_cache()
647 time.sleep(0.1)
648
649 @remote_compatible
650 def test_grpform_pbc_overlap(dev, apdev):
651 """P2P group formation during PBC overlap"""
652 params = {"ssid": "wps", "eap_server": "1", "wps_state": "1"}
653 hapd = hostapd.add_ap(apdev[0], params)
654 hapd.request("WPS_PBC")
655 time.sleep(0.1)
656
657 # Since P2P Client scan case is now optimized to use a specific SSID, the
658 # WPS AP will not reply to that and the scan after GO Negotiation can quite
659 # likely miss the AP due to dwell time being short enough to miss the Beacon
660 # frame. This has made the test case somewhat pointless, but keep it here
661 # for now with an additional scan to confirm that PBC detection works if
662 # there is a BSS entry for a overlapping AP.
663 for i in range(0, 5):
664 dev[0].scan(freq="2412")
665 if dev[0].get_bss(apdev[0]['bssid']) is not None:
666 break
667
668 addr0 = dev[0].p2p_dev_addr()
669 addr1 = dev[1].p2p_dev_addr()
670 dev[0].p2p_listen()
671 if not dev[1].discover_peer(addr0):
672 raise Exception("Could not discover peer")
673 dev[1].p2p_listen()
674 if not dev[0].discover_peer(addr1):
675 raise Exception("Could not discover peer")
676 dev[0].p2p_listen()
677 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
678 raise Exception("Failed to authorize GO Neg")
679 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
680 raise Exception("Failed to initiate GO Neg")
681 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
682 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
683 clear_pbc_overlap(dev, apdev[0])
684 if ev is None or "P2P-GROUP-FORMATION-SUCCESS" not in ev:
685 raise Exception("P2P group formation did not complete")
686
687 @remote_compatible
688 def test_grpform_pbc_overlap_group_iface(dev, apdev):
689 """P2P group formation during PBC overlap using group interfaces"""
690 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
691 # update use this information.
692 params = {"ssid": "wps", "eap_server": "1", "wps_state": "1",
693 "beacon_int": "15", 'manage_p2p': '1'}
694 hapd = hostapd.add_ap(apdev[0], params)
695 hapd.request("WPS_PBC")
696
697 dev[0].request("SET p2p_no_group_iface 0")
698 dev[1].request("SET p2p_no_group_iface 0")
699
700 addr0 = dev[0].p2p_dev_addr()
701 addr1 = dev[1].p2p_dev_addr()
702 dev[0].p2p_listen()
703 if not dev[1].discover_peer(addr0):
704 raise Exception("Could not discover peer")
705 dev[1].p2p_listen()
706 if not dev[0].discover_peer(addr1):
707 raise Exception("Could not discover peer")
708 dev[0].p2p_stop_find()
709 dev[0].scan(freq="2412")
710 dev[0].p2p_listen()
711 if "OK" not in dev[0].global_request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
712 raise Exception("Failed to authorize GO Neg")
713 if "OK" not in dev[1].global_request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
714 raise Exception("Failed to initiate GO Neg")
715 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
716 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
717 clear_pbc_overlap(dev, apdev[0])
718 if ev is None or "P2P-GROUP-FORMATION-SUCCESS" not in ev:
719 raise Exception("P2P group formation did not complete")
720
721 @remote_compatible
722 def test_grpform_goneg_fail_with_group_iface(dev):
723 """P2P group formation fails while using group interface"""
724 dev[0].request("SET p2p_no_group_iface 0")
725 dev[1].p2p_listen()
726 peer = dev[1].p2p_dev_addr()
727 if not dev[0].discover_peer(peer):
728 raise Exception("Peer " + peer + " not found")
729 if "OK" not in dev[1].request("P2P_REJECT " + dev[0].p2p_dev_addr()):
730 raise Exception("P2P_REJECT failed")
731 if "OK" not in dev[0].request("P2P_CONNECT " + peer + " pbc"):
732 raise Exception("P2P_CONNECT failed")
733 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
734 if ev is None:
735 raise Exception("GO Negotiation failure timed out")
736
737 def test_grpform_cred_ready_timeout(dev, apdev, params):
738 """P2P GO Negotiation wait for credentials to become ready [long]"""
739 if not params['long']:
740 raise HwsimSkip("Skip test case with long duration due to --long not specified")
741
742 dev[1].p2p_listen()
743 addr1 = dev[1].p2p_dev_addr()
744 if not dev[0].discover_peer(addr1):
745 raise Exception("Peer " + addr1 + " not found")
746 if not dev[2].discover_peer(addr1):
747 raise Exception("Peer " + addr1 + " not found(2)")
748
749 start = os.times()[4]
750
751 cmd = "P2P_CONNECT " + addr1 + " 12345670 display"
752 if "OK" not in dev[0].global_request(cmd):
753 raise Exception("Failed to initiate GO Neg")
754
755 if "OK" not in dev[2].global_request(cmd):
756 raise Exception("Failed to initiate GO Neg(2)")
757
758 # First, check with p2p_find
759 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=30)
760 if ev is not None:
761 raise Exception("Too early GO Negotiation timeout reported(2)")
762 dev[2].dump_monitor()
763 logger.info("Starting p2p_find to change state")
764 dev[2].p2p_find()
765 for i in range(10):
766 ev = dev[2].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
767 if ev:
768 break
769 dev[2].dump_monitor(global_mon=False)
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 dev[2].dump_monitor()
789 wpas.p2p_stop_find()
790 wpas.close_monitor()
791 del wpas
792
793 # Finally, verify without p2p_find
794 ev = dev[0].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=120)
795 if ev is None:
796 raise Exception("GO Negotiation failure timed out")
797 end = os.times()[4]
798 logger.info("GO Negotiation wait time: {} seconds".format(end - start))
799 if end - start < 120:
800 raise Exception("Too short GO Negotiation wait time: {}".format(end - start))
801
802 def test_grpform_no_wsc_done(dev):
803 """P2P group formation with WSC-Done not sent"""
804 addr0 = dev[0].p2p_dev_addr()
805 addr1 = dev[1].p2p_dev_addr()
806
807 for i in range(0, 2):
808 dev[0].request("SET ext_eapol_frame_io 1")
809 dev[1].request("SET ext_eapol_frame_io 1")
810 dev[0].p2p_listen()
811 dev[1].p2p_go_neg_auth(addr0, "12345670", "display", 0)
812 dev[1].p2p_listen()
813 dev[0].p2p_go_neg_init(addr1, "12345670", "enter", timeout=20,
814 go_intent=15, wait_group=False)
815
816 mode = None
817 while True:
818 ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
819 if ev is None:
820 raise Exception("Timeout on EAPOL-TX from GO")
821 if not mode:
822 mode = dev[0].get_status_field("mode")
823 res = dev[1].request("EAPOL_RX " + addr0 + " " + ev.split(' ')[2])
824 if "OK" not in res:
825 raise Exception("EAPOL_RX failed")
826 ev = dev[1].wait_event(["EAPOL-TX"], timeout=15)
827 if ev is None:
828 raise Exception("Timeout on EAPOL-TX from P2P Client")
829 msg = ev.split(' ')[2]
830 if msg[46:56] == "102200010f":
831 logger.info("Drop WSC_Done")
832 dev[0].request("SET ext_eapol_frame_io 0")
833 dev[1].request("SET ext_eapol_frame_io 0")
834 # Fake EAP-Failure to complete session on the client
835 id = msg[10:12]
836 dev[1].request("EAPOL_RX " + addr0 + " 0300000404" + id + "0004")
837 break
838 res = dev[0].request("EAPOL_RX " + addr1 + " " + msg)
839 if "OK" not in res:
840 raise Exception("EAPOL_RX failed")
841
842 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
843 if ev is None:
844 raise Exception("Group formation timed out on GO")
845 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
846 if ev is None:
847 raise Exception("Group formation timed out on P2P Client")
848 dev[0].remove_group()
849 dev[1].wait_go_ending_session()
850
851 if mode != "P2P GO - group formation":
852 raise Exception("Unexpected mode on GO during group formation: " + mode)
853
854 @remote_compatible
855 def test_grpform_wait_peer(dev):
856 """P2P group formation wait for peer to become ready"""
857 addr0 = dev[0].p2p_dev_addr()
858 addr1 = dev[1].p2p_dev_addr()
859 dev[1].p2p_listen()
860 if not dev[0].discover_peer(addr1):
861 raise Exception("Peer " + addr1 + " not found")
862 dev[0].request("SET extra_roc_dur 500")
863 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display go_intent=15"):
864 raise Exception("Failed to initiate GO Neg")
865 time.sleep(3)
866 dev[1].request("P2P_CONNECT " + addr0 + " 12345670 enter go_intent=0")
867
868 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
869 if ev is None:
870 raise Exception("Group formation timed out")
871 dev[0].group_form_result(ev)
872
873 dev[0].request("SET extra_roc_dur 0")
874 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
875 if ev is None:
876 raise Exception("Group formation timed out")
877 dev[0].remove_group()
878
879 @remote_compatible
880 def test_invalid_p2p_connect_command(dev):
881 """P2P_CONNECT error cases"""
882 id = dev[0].add_network()
883 for cmd in ["foo",
884 "00:11:22:33:44:55",
885 "00:11:22:33:44:55 pbc persistent=123",
886 "00:11:22:33:44:55 pbc persistent=%d" % id,
887 "00:11:22:33:44:55 pbc go_intent=-1",
888 "00:11:22:33:44:55 pbc go_intent=16",
889 "00:11:22:33:44:55 pin",
890 "00:11:22:33:44:55 pbc freq=0"]:
891 if "FAIL" not in dev[0].request("P2P_CONNECT " + cmd):
892 raise Exception("Invalid P2P_CONNECT command accepted: " + cmd)
893
894 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 1234567"):
895 raise Exception("Invalid PIN was not rejected")
896 if "FAIL-INVALID-PIN" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 12345678a"):
897 raise Exception("Invalid PIN was not rejected")
898
899 if "FAIL-CHANNEL-UNSUPPORTED" not in dev[0].request("P2P_CONNECT 00:11:22:33:44:55 pin freq=3000"):
900 raise Exception("Unsupported channel not reported")
901
902 @remote_compatible
903 def test_p2p_unauthorize(dev):
904 """P2P_UNAUTHORIZE to unauthorize a peer"""
905 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE foo"):
906 raise Exception("Invalid P2P_UNAUTHORIZE accepted")
907 if "FAIL" not in dev[0].request("P2P_UNAUTHORIZE 00:11:22:33:44:55"):
908 raise Exception("P2P_UNAUTHORIZE for unknown peer accepted")
909
910 addr0 = dev[0].p2p_dev_addr()
911 addr1 = dev[1].p2p_dev_addr()
912 dev[1].p2p_listen()
913 pin = dev[0].wps_read_pin()
914 dev[0].p2p_go_neg_auth(addr1, pin, "display")
915 dev[0].p2p_listen()
916 if "OK" not in dev[0].request("P2P_UNAUTHORIZE " + addr1):
917 raise Exception("P2P_UNAUTHORIZE failed")
918 dev[1].p2p_go_neg_init(addr0, pin, "keypad", timeout=0)
919 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
920 if ev is None:
921 raise Exception("No GO Negotiation Request RX reported")
922
923 @remote_compatible
924 def test_grpform_pbc_multiple(dev):
925 """P2P group formation using PBC multiple times in a row"""
926 try:
927 dev[1].request("SET passive_scan 1")
928 for i in range(5):
929 [i_res, r_res] = go_neg_pbc_authorized(i_dev=dev[0], i_intent=15,
930 r_dev=dev[1], r_intent=0)
931 remove_group(dev[0], dev[1])
932 finally:
933 dev[1].request("SET passive_scan 0")
934 dev[1].flush_scan_cache()
935
936 def test_grpform_not_ready(dev):
937 """Not ready for GO Negotiation (listen)"""
938 addr0 = dev[0].p2p_dev_addr()
939 addr2 = dev[2].p2p_dev_addr()
940 dev[0].p2p_listen()
941 if not dev[1].discover_peer(addr0):
942 raise Exception("Could not discover peer")
943 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
944 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
945 if ev is None:
946 raise Exception("No P2P-GO-NEG-REQUEST event")
947 dev[0].dump_monitor()
948 time.sleep(5)
949 if not dev[2].discover_peer(addr0):
950 raise Exception("Could not discover peer(2)")
951 for i in range(3):
952 dev[i].p2p_stop_find()
953
954 def test_grpform_not_ready2(dev):
955 """Not ready for GO Negotiation (search)"""
956 addr0 = dev[0].p2p_dev_addr()
957 addr2 = dev[2].p2p_dev_addr()
958 dev[0].p2p_find(social=True)
959 if not dev[1].discover_peer(addr0):
960 raise Exception("Could not discover peer")
961 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
962 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
963 if ev is None:
964 raise Exception("No P2P-GO-NEG-REQUEST event")
965 dev[0].dump_monitor()
966 time.sleep(1)
967 dev[2].p2p_listen()
968 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=10)
969 if ev is None:
970 raise Exception("Peer not discovered after GO Neg Resp(status=1) TX")
971 if addr2 not in ev:
972 raise Exception("Unexpected peer discovered: " + ev)
973 for i in range(3):
974 dev[i].p2p_stop_find()
975
976 @remote_compatible
977 def test_grpform_and_scan(dev):
978 """GO Negotiation and scan operations"""
979 addr0 = dev[0].p2p_dev_addr()
980 addr1 = dev[1].p2p_dev_addr()
981 dev[1].p2p_listen()
982 if not dev[0].discover_peer(addr1):
983 raise Exception("Could not discover peer")
984 dev[0].p2p_stop_find()
985 dev[1].p2p_stop_find()
986
987 if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
988 raise Exception("Could not start scan")
989 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
990 if ev is None:
991 raise Exception("Scan did not start")
992 time.sleep(0.1)
993 # Request PD while the previously started scan is still in progress
994 if "OK" not in dev[0].request("P2P_PROV_DISC %s pbc" % addr1):
995 raise Exception("Could not request PD")
996 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
997 if ev is None:
998 raise Exception("Scan did not complete")
999 time.sleep(0.3)
1000
1001 dev[1].p2p_listen()
1002 ev = dev[0].wait_global_event(["P2P-PROV-DISC-PBC-RESP"], timeout=5)
1003 if ev is None:
1004 raise Exception("PD Response not received")
1005
1006 if "OK" not in dev[0].request("SCAN TYPE=ONLY freq=2412-2472"):
1007 raise Exception("Could not start scan")
1008 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
1009 if ev is None:
1010 raise Exception("Scan did not start")
1011 time.sleep(0.1)
1012 # Request GO Neg while the previously started scan is still in progress
1013 if "OK" not in dev[0].request("P2P_CONNECT %s pbc" % addr1):
1014 raise Exception("Could not request GO Negotiation")
1015 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1016 if ev is None:
1017 raise Exception("Scan did not complete")
1018
1019 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1020 if ev is None:
1021 raise Exception("GO Neg Req RX not reported")
1022
1023 dev[1].p2p_stop_find()
1024
1025 if "OK" not in dev[1].request("SCAN TYPE=ONLY freq=2412-2472"):
1026 raise Exception("Could not start scan")
1027 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
1028 if ev is None:
1029 raise Exception("Scan did not start")
1030 time.sleep(0.1)
1031 dev[1].global_request("P2P_CONNECT " + addr0 + " pbc")
1032 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
1033 if ev is None:
1034 raise Exception("Scan did not complete")
1035
1036 ev0 = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1037 if ev0 is None:
1038 raise Exception("Group formation timed out on dev0")
1039 dev[0].group_form_result(ev0)
1040
1041 ev1 = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1042 if ev1 is None:
1043 raise Exception("Group formation timed out on dev1")
1044 dev[1].group_form_result(ev1)
1045
1046 dev[0].dump_monitor()
1047 dev[1].dump_monitor()
1048
1049 remove_group(dev[0], dev[1])
1050
1051 dev[0].dump_monitor()
1052 dev[1].dump_monitor()
1053
1054 def test_grpform_go_neg_dup_on_restart(dev):
1055 """Duplicated GO Negotiation Request after GO Neg restart"""
1056 if dev[0].p2p_dev_addr() > dev[1].p2p_dev_addr():
1057 higher = dev[0]
1058 lower = dev[1]
1059 else:
1060 higher = dev[1]
1061 lower = dev[0]
1062 addr_low = lower.p2p_dev_addr()
1063 addr_high = higher.p2p_dev_addr()
1064 higher.p2p_listen()
1065 if not lower.discover_peer(addr_high):
1066 raise Exception("Could not discover peer")
1067 lower.p2p_stop_find()
1068
1069 if "OK" not in lower.request("P2P_CONNECT %s pbc" % addr_high):
1070 raise Exception("Could not request GO Negotiation")
1071 ev = higher.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=10)
1072 if ev is None:
1073 raise Exception("GO Neg Req RX not reported")
1074
1075 # Wait for GO Negotiation Response (Status=1) to go through
1076 time.sleep(0.2)
1077
1078 if "FAIL" in lower.request("SET ext_mgmt_frame_handling 1"):
1079 raise Exception("Failed to enable external management frame handling")
1080
1081 higher.p2p_stop_find()
1082 higher.global_request("P2P_CONNECT " + addr_low + " pbc")
1083
1084 # Wait for the GO Negotiation Request frame of the restarted GO Negotiation
1085 rx_msg = lower.mgmt_rx()
1086 if rx_msg is None:
1087 raise Exception("MGMT-RX timeout")
1088 p2p = parse_p2p_public_action(rx_msg['payload'])
1089 if p2p is None:
1090 raise Exception("Not a P2P Public Action frame")
1091 if p2p['subtype'] != 0:
1092 raise Exception("Unexpected P2P Public Action subtype %d" % p2p['subtype'])
1093
1094 # Send duplicate GO Negotiation Request from the prior instance of GO
1095 # Negotiation
1096 lower.p2p_stop_find()
1097 peer = higher.get_peer(addr_low)
1098
1099 msg = p2p_hdr(addr_high, addr_low, type=P2P_GO_NEG_REQ, dialog_token=123)
1100 attrs = p2p_attr_capability(dev_capab=0x25, group_capab=0x08)
1101 attrs += p2p_attr_go_intent(go_intent=7, tie_breaker=1)
1102 attrs += p2p_attr_config_timeout()
1103 attrs += p2p_attr_listen_channel(chan=(int(peer['listen_freq']) - 2407) // 5)
1104 attrs += p2p_attr_intended_interface_addr(lower.p2p_dev_addr())
1105 attrs += p2p_attr_channel_list()
1106 attrs += p2p_attr_device_info(addr_low, config_methods=0x80, name="Device A")
1107 attrs += p2p_attr_operating_channel()
1108 wsc_attrs = struct.pack(">HHH", 0x1012, 2, 4)
1109 msg['payload'] += ie_p2p(attrs) + ie_wsc(wsc_attrs)
1110 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']).decode()))
1111
1112 # Wait for the GO Negotiation Response frame which would have been sent in
1113 # this case previously, but not anymore after the check for
1114 # dev->go_neg_req_sent and dev->flags & P2P_DEV_PEER_WAITING_RESPONSE.
1115 rx_msg = lower.mgmt_rx(timeout=0.2)
1116 if rx_msg is not None:
1117 raise Exception("Unexpected management frame")
1118
1119 if "FAIL" in lower.request("SET ext_mgmt_frame_handling 0"):
1120 raise Exception("Failed to disable external management frame handling")
1121 lower.p2p_listen()
1122
1123 ev = lower.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
1124 if ev is None:
1125 raise Exception("GO Negotiation did not succeed on dev0")
1126
1127 ev = higher.wait_global_event(["P2P-GO-NEG-SUCCESS"], timeout=10)
1128 if ev is None:
1129 raise Exception("GO Negotiation did not succeed on dev1")
1130
1131 ev0 = lower.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1132 if ev0 is None:
1133 raise Exception("Group formation timed out on dev0")
1134 lower.group_form_result(ev0)
1135
1136 ev1 = higher.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
1137 if ev1 is None:
1138 raise Exception("Group formation timed out on dev1")
1139 higher.group_form_result(ev1)
1140
1141 lower.dump_monitor()
1142 higher.dump_monitor()
1143
1144 remove_group(lower, higher)
1145
1146 lower.dump_monitor()
1147 higher.dump_monitor()
1148
1149 @remote_compatible
1150 def test_grpform_go_neg_stopped(dev):
1151 """GO Negotiation stopped after TX start"""
1152 addr0 = dev[0].p2p_dev_addr()
1153 dev[0].p2p_listen()
1154 if not dev[1].discover_peer(addr0):
1155 raise Exception("Could not discover peer")
1156 dev[0].p2p_stop_find()
1157 if "OK" not in dev[1].request("P2P_CONNECT %s pbc" % addr0):
1158 raise Exception("Could not request GO Negotiation")
1159 dev[1].p2p_stop_find()
1160 dev[1].p2p_listen()
1161 dev[0].p2p_find(social=True)
1162 ev = dev[0].wait_global_event(["P2P-DEVICE-FOUND"], timeout=1.2)
1163 dev[0].p2p_stop_find()
1164 dev[1].p2p_stop_find()
1165 if ev is None:
1166 raise Exception("Did not find peer quickly enough after stopped P2P_CONNECT")
1167
1168 def test_grpform_random_addr(dev):
1169 """P2P group formation with random interface addresses"""
1170 dev[0].global_request("SET p2p_no_group_iface 0")
1171 dev[1].global_request("SET p2p_no_group_iface 0")
1172 try:
1173 if "OK" not in dev[0].global_request("SET p2p_interface_random_mac_addr 1"):
1174 raise Exception("Failed to set p2p_interface_random_mac_addr")
1175 if "OK" not in dev[1].global_request("SET p2p_interface_random_mac_addr 1"):
1176 raise Exception("Failed to set p2p_interface_random_mac_addr")
1177 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1178 r_dev=dev[1], r_intent=0)
1179 if "p2p-wlan" not in i_res['ifname']:
1180 raise Exception("Unexpected group interface name")
1181 check_grpform_results(i_res, r_res)
1182 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
1183 remove_group(dev[0], dev[1])
1184 if i_res['ifname'] in utils.get_ifnames():
1185 raise Exception("Group interface netdev was not removed")
1186 finally:
1187 dev[0].global_request("SET p2p_interface_random_mac_addr 0")
1188 dev[1].global_request("SET p2p_interface_random_mac_addr 0")