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