]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_grpform.py
tests: P2P group idle timeout on GO
[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 logging
8 logger = logging.getLogger()
9 import time
10 import threading
11 import Queue
12
13 import hostapd
14 import hwsim_utils
15 import utils
16
17 def check_grpform_results(i_res, r_res):
18 if i_res['result'] != 'success' or r_res['result'] != 'success':
19 raise Exception("Failed group formation")
20 if i_res['ssid'] != r_res['ssid']:
21 raise Exception("SSID mismatch")
22 if i_res['freq'] != r_res['freq']:
23 raise Exception("freq mismatch")
24 if 'go_neg_freq' in r_res and i_res['go_neg_freq'] != r_res['go_neg_freq']:
25 raise Exception("go_neg_freq mismatch")
26 if i_res['freq'] != i_res['go_neg_freq']:
27 raise Exception("freq/go_neg_freq mismatch")
28 if i_res['role'] != i_res['go_neg_role']:
29 raise Exception("role/go_neg_role mismatch")
30 if 'go_neg_role' in r_res and r_res['role'] != r_res['go_neg_role']:
31 raise Exception("role/go_neg_role mismatch")
32 if i_res['go_dev_addr'] != r_res['go_dev_addr']:
33 raise Exception("GO Device Address mismatch")
34
35 def go_neg_init(i_dev, r_dev, pin, i_method, i_intent, res):
36 logger.debug("Initiate GO Negotiation from i_dev")
37 try:
38 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent)
39 logger.debug("i_res: " + str(i_res))
40 except Exception, e:
41 i_res = None
42 logger.info("go_neg_init thread caught an exception from p2p_go_neg_init: " + str(e))
43 res.put(i_res)
44
45 def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_method='display'):
46 r_dev.p2p_listen()
47 i_dev.p2p_listen()
48 pin = r_dev.wps_read_pin()
49 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
50 r_dev.dump_monitor()
51 res = Queue.Queue()
52 t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res))
53 t.start()
54 logger.debug("Wait for GO Negotiation Request on r_dev")
55 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
56 if ev is None:
57 raise Exception("GO Negotiation timed out")
58 r_dev.dump_monitor()
59 logger.debug("Re-initiate GO Negotiation from r_dev")
60 r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20)
61 logger.debug("r_res: " + str(r_res))
62 r_dev.dump_monitor()
63 t.join()
64 i_res = res.get()
65 if i_res is None:
66 raise Exception("go_neg_init thread failed")
67 logger.debug("i_res: " + str(i_res))
68 logger.info("Group formed")
69 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
70 i_dev.dump_monitor()
71 return [i_res, r_res]
72
73 def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None, i_method='enter', r_method='display', test_data=True, i_freq=None, r_freq=None):
74 i_dev.p2p_listen()
75 pin = r_dev.wps_read_pin()
76 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
77 r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, freq=r_freq)
78 r_dev.p2p_listen()
79 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, i_method, timeout=20, go_intent=i_intent, expect_failure=expect_failure, freq=i_freq)
80 r_res = r_dev.p2p_go_neg_auth_result(expect_failure=expect_failure)
81 logger.debug("i_res: " + str(i_res))
82 logger.debug("r_res: " + str(r_res))
83 r_dev.dump_monitor()
84 i_dev.dump_monitor()
85 if i_go_neg_status:
86 if i_res['result'] != 'go-neg-failed':
87 raise Exception("Expected GO Negotiation failure not reported")
88 if i_res['status'] != i_go_neg_status:
89 raise Exception("Expected GO Negotiation status not seen")
90 if expect_failure:
91 return
92 logger.info("Group formed")
93 if test_data:
94 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
95 return [i_res, r_res]
96
97 def go_neg_init_pbc(i_dev, r_dev, i_intent, res, freq, provdisc):
98 logger.debug("Initiate GO Negotiation from i_dev")
99 try:
100 i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), None, "pbc",
101 timeout=20, go_intent=i_intent, freq=freq,
102 provdisc=provdisc)
103 logger.debug("i_res: " + str(i_res))
104 except Exception, e:
105 i_res = None
106 logger.info("go_neg_init_pbc thread caught an exception from p2p_go_neg_init: " + str(e))
107 res.put(i_res)
108
109 def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=None, provdisc=False, r_listen=False):
110 if r_listen:
111 r_dev.p2p_listen()
112 else:
113 r_dev.p2p_find(social=True)
114 i_dev.p2p_find(social=True)
115 logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname)
116 r_dev.dump_monitor()
117 res = Queue.Queue()
118 t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc))
119 t.start()
120 logger.debug("Wait for GO Negotiation Request on r_dev")
121 ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
122 if ev is None:
123 raise Exception("GO Negotiation timed out")
124 r_dev.dump_monitor()
125 logger.debug("Re-initiate GO Negotiation from r_dev")
126 r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc",
127 go_intent=r_intent, timeout=20, freq=r_freq)
128 logger.debug("r_res: " + str(r_res))
129 r_dev.dump_monitor()
130 t.join()
131 i_res = res.get()
132 if i_res is None:
133 raise Exception("go_neg_init_pbc thread failed")
134 logger.debug("i_res: " + str(i_res))
135 logger.info("Group formed")
136 hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
137 i_dev.dump_monitor()
138 return [i_res, r_res]
139
140 def remove_group(dev1, dev2):
141 dev1.remove_group()
142 try:
143 dev2.remove_group()
144 except:
145 pass
146
147 def test_grpform(dev):
148 """P2P group formation using PIN and authorized connection (init -> GO)"""
149 try:
150 dev[0].request("SET p2p_group_idle 2")
151 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
152 r_dev=dev[1], r_intent=0)
153 check_grpform_results(i_res, r_res)
154 dev[1].remove_group()
155 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
156 if ev is None:
157 raise Exception("GO did not remove group on idle timeout")
158 if "GO reason=IDLE" not in ev:
159 raise Exception("Unexpected group removal event: " + ev)
160 finally:
161 dev[0].request("SET p2p_group_idle 0")
162
163 def test_grpform_a(dev):
164 """P2P group formation using PIN and authorized connection (init -> GO) (init: group iface)"""
165 dev[0].request("SET p2p_no_group_iface 0")
166 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
167 r_dev=dev[1], r_intent=0)
168 if "p2p-wlan" not in i_res['ifname']:
169 raise Exception("Unexpected group interface name")
170 check_grpform_results(i_res, r_res)
171 remove_group(dev[0], dev[1])
172 if i_res['ifname'] in utils.get_ifnames():
173 raise Exception("Group interface netdev was not removed")
174
175 def test_grpform_b(dev):
176 """P2P group formation using PIN and authorized connection (init -> GO) (resp: group iface)"""
177 dev[1].request("SET p2p_no_group_iface 0")
178 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
179 r_dev=dev[1], r_intent=0)
180 if "p2p-wlan" not in r_res['ifname']:
181 raise Exception("Unexpected group interface name")
182 check_grpform_results(i_res, r_res)
183 remove_group(dev[0], dev[1])
184 if r_res['ifname'] in utils.get_ifnames():
185 raise Exception("Group interface netdev was not removed")
186
187 def test_grpform_c(dev):
188 """P2P group formation using PIN and authorized connection (init -> GO) (group iface)"""
189 dev[0].request("SET p2p_no_group_iface 0")
190 dev[1].request("SET p2p_no_group_iface 0")
191 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
192 r_dev=dev[1], r_intent=0)
193 if "p2p-wlan" not in i_res['ifname']:
194 raise Exception("Unexpected group interface name")
195 if "p2p-wlan" not in r_res['ifname']:
196 raise Exception("Unexpected group interface name")
197 check_grpform_results(i_res, r_res)
198 remove_group(dev[0], dev[1])
199 if i_res['ifname'] in utils.get_ifnames():
200 raise Exception("Group interface netdev was not removed")
201 if r_res['ifname'] in utils.get_ifnames():
202 raise Exception("Group interface netdev was not removed")
203
204 def test_grpform2(dev):
205 """P2P group formation using PIN and authorized connection (resp -> GO)"""
206 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
207 remove_group(dev[0], dev[1])
208
209 def test_grpform2_c(dev):
210 """P2P group formation using PIN and authorized connection (resp -> GO) (group iface)"""
211 dev[0].request("SET p2p_no_group_iface 0")
212 dev[1].request("SET p2p_no_group_iface 0")
213 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
214 remove_group(dev[0], dev[1])
215 if i_res['ifname'] in utils.get_ifnames():
216 raise Exception("Group interface netdev was not removed")
217 if r_res['ifname'] in utils.get_ifnames():
218 raise Exception("Group interface netdev was not removed")
219
220 def test_grpform3(dev):
221 """P2P group formation using PIN and re-init GO Negotiation"""
222 go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
223 remove_group(dev[0], dev[1])
224
225 def test_grpform3_c(dev):
226 """P2P group formation using PIN and re-init GO Negotiation (group iface)"""
227 dev[0].request("SET p2p_no_group_iface 0")
228 dev[1].request("SET p2p_no_group_iface 0")
229 [i_res, r_res] = go_neg_pin(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
230 remove_group(dev[0], dev[1])
231 if i_res['ifname'] in utils.get_ifnames():
232 raise Exception("Group interface netdev was not removed")
233 if r_res['ifname'] in utils.get_ifnames():
234 raise Exception("Group interface netdev was not removed")
235
236 def test_grpform_pbc(dev):
237 """P2P group formation using PBC and re-init GO Negotiation"""
238 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
239 check_grpform_results(i_res, r_res)
240 if i_res['role'] != 'GO' or r_res['role'] != 'client':
241 raise Exception("Unexpected device roles")
242 remove_group(dev[0], dev[1])
243
244 def test_grpform_pd(dev):
245 """P2P group formation with PD-before-GO-Neg workaround"""
246 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
247 check_grpform_results(i_res, r_res)
248 remove_group(dev[0], dev[1])
249
250 def test_grpform_ext_listen(dev):
251 """P2P group formation with extended listen timing enabled"""
252 try:
253 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN 100 50000"):
254 raise Exception("Failed to set extended listen timing")
255 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN 200 40000"):
256 raise Exception("Failed to set extended listen timing")
257 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], provdisc=True, r_dev=dev[1], r_listen=True)
258 check_grpform_results(i_res, r_res)
259 peer1 = dev[0].get_peer(dev[1].p2p_dev_addr())
260 if peer1['ext_listen_interval'] != "40000":
261 raise Exception("Extended listen interval not discovered correctly")
262 if peer1['ext_listen_period'] != "200":
263 raise Exception("Extended listen period not discovered correctly")
264 peer0 = dev[1].get_peer(dev[0].p2p_dev_addr())
265 if peer0['ext_listen_interval'] != "50000":
266 raise Exception("Extended listen interval not discovered correctly")
267 if peer0['ext_listen_period'] != "100":
268 raise Exception("Extended listen period not discovered correctly")
269 remove_group(dev[0], dev[1])
270 finally:
271 if "OK" not in dev[0].global_request("P2P_EXT_LISTEN"):
272 raise Exception("Failed to clear extended listen timing")
273 if "OK" not in dev[1].global_request("P2P_EXT_LISTEN"):
274 raise Exception("Failed to clear extended listen timing")
275
276 def test_both_go_intent_15(dev):
277 """P2P GO Negotiation with both devices using GO intent 15"""
278 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)
279
280 def test_both_go_neg_display(dev):
281 """P2P GO Negotiation with both devices trying to display PIN"""
282 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')
283
284 def test_both_go_neg_enter(dev):
285 """P2P GO Negotiation with both devices trying to enter PIN"""
286 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')
287
288 def test_go_neg_pbc_vs_pin(dev):
289 """P2P GO Negotiation with one device using PBC and the other PIN"""
290 addr0 = dev[0].p2p_dev_addr()
291 addr1 = dev[1].p2p_dev_addr()
292 dev[1].p2p_listen()
293 if not dev[0].discover_peer(addr1):
294 raise Exception("Could not discover peer")
295 dev[0].p2p_listen()
296 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth"):
297 raise Exception("Failed to authorize GO Neg")
298 if not dev[1].discover_peer(addr0):
299 raise Exception("Could not discover peer")
300 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " 12345670 display"):
301 raise Exception("Failed to initiate GO Neg")
302 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
303 if ev is None:
304 raise Exception("GO Negotiation failure timed out")
305 if "status=10" not in ev:
306 raise Exception("Unexpected failure reason: " + ev)
307
308 def test_go_neg_pin_vs_pbc(dev):
309 """P2P GO Negotiation with one device using PIN and the other PBC"""
310 addr0 = dev[0].p2p_dev_addr()
311 addr1 = dev[1].p2p_dev_addr()
312 dev[1].p2p_listen()
313 if not dev[0].discover_peer(addr1):
314 raise Exception("Could not discover peer")
315 dev[0].p2p_listen()
316 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " 12345670 display auth"):
317 raise Exception("Failed to authorize GO Neg")
318 if not dev[1].discover_peer(addr0):
319 raise Exception("Could not discover peer")
320 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc"):
321 raise Exception("Failed to initiate GO Neg")
322 ev = dev[1].wait_global_event(["P2P-GO-NEG-FAILURE"], timeout=10)
323 if ev is None:
324 raise Exception("GO Negotiation failure timed out")
325 if "status=10" not in ev:
326 raise Exception("Unexpected failure reason: " + ev)
327
328 def test_grpform_per_sta_psk(dev):
329 """P2P group formation with per-STA PSKs"""
330 dev[0].request("P2P_SET per_sta_psk 1")
331 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
332 check_grpform_results(i_res, r_res)
333
334 pin = dev[2].wps_read_pin()
335 dev[0].p2p_go_authorize_client(pin)
336 c_res = dev[2].p2p_connect_group(dev[0].p2p_dev_addr(), pin, timeout=60)
337 check_grpform_results(i_res, c_res)
338
339 if r_res['psk'] == c_res['psk']:
340 raise Exception("Same PSK assigned for both clients")
341
342 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
343
344 dev[0].remove_group()
345 dev[1].wait_go_ending_session()
346 dev[2].wait_go_ending_session()
347
348 def test_grpform_per_sta_psk_wps(dev):
349 """P2P group formation with per-STA PSKs with non-P2P WPS STA"""
350 dev[0].request("P2P_SET per_sta_psk 1")
351 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
352 check_grpform_results(i_res, r_res)
353
354 dev[0].p2p_go_authorize_client_pbc()
355 dev[2].request("WPS_PBC")
356 ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
357 if ev is None:
358 raise Exception("Association with the GO timed out")
359
360 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
361
362 dev[0].remove_group()
363 dev[2].request("DISCONNECT")
364 dev[1].wait_go_ending_session()
365
366 def test_grpform_force_chan_go(dev):
367 """P2P group formation forced channel selection by GO"""
368 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
369 i_freq=2432,
370 r_dev=dev[1], r_intent=0,
371 test_data=False)
372 check_grpform_results(i_res, r_res)
373 if i_res['freq'] != "2432":
374 raise Exception("Unexpected channel - did not follow GO's forced channel")
375 remove_group(dev[0], dev[1])
376
377 def test_grpform_force_chan_cli(dev):
378 """P2P group formation forced channel selection by client"""
379 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
380 i_freq=2417,
381 r_dev=dev[1], r_intent=15,
382 test_data=False)
383 check_grpform_results(i_res, r_res)
384 if i_res['freq'] != "2417":
385 raise Exception("Unexpected channel - did not follow GO's forced channel")
386 remove_group(dev[0], dev[1])
387
388 def test_grpform_force_chan_conflict(dev):
389 """P2P group formation fails due to forced channel mismatch"""
390 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
391 r_dev=dev[1], r_intent=15, r_freq=2427,
392 expect_failure=True, i_go_neg_status=7)
393
394 def test_grpform_pref_chan_go(dev):
395 """P2P group formation preferred channel selection by GO"""
396 dev[0].request("SET p2p_pref_chan 81:7")
397 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
398 r_dev=dev[1], r_intent=0,
399 test_data=False)
400 check_grpform_results(i_res, r_res)
401 if i_res['freq'] != "2442":
402 raise Exception("Unexpected channel - did not follow GO's p2p_pref_chan")
403 remove_group(dev[0], dev[1])
404
405 def test_grpform_pref_chan_go_overridden(dev):
406 """P2P group formation preferred channel selection by GO overridden by client"""
407 dev[1].request("SET p2p_pref_chan 81:7")
408 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
409 i_freq=2422,
410 r_dev=dev[1], r_intent=15,
411 test_data=False)
412 check_grpform_results(i_res, r_res)
413 if i_res['freq'] != "2422":
414 raise Exception("Unexpected channel - did not follow client's forced channel")
415 remove_group(dev[0], dev[1])
416
417 def test_grpform_no_go_freq_forcing_chan(dev):
418 """P2P group formation with no-GO freq forcing channel"""
419 dev[1].request("SET p2p_no_go_freq 100-200,300,4000-6000")
420 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
421 r_dev=dev[1], r_intent=15,
422 test_data=False)
423 check_grpform_results(i_res, r_res)
424 if int(i_res['freq']) > 4000:
425 raise Exception("Unexpected channel - did not follow no-GO freq")
426 remove_group(dev[0], dev[1])
427
428 def test_grpform_no_go_freq_conflict(dev):
429 """P2P group formation fails due to no-GO range forced by client"""
430 dev[1].request("SET p2p_no_go_freq 2000-3000")
431 go_neg_pin_authorized(i_dev=dev[0], i_intent=0, i_freq=2422,
432 r_dev=dev[1], r_intent=15,
433 expect_failure=True, i_go_neg_status=7)
434
435 def test_grpform_no_5ghz_world_roaming(dev):
436 """P2P group formation with world roaming regulatory"""
437 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
438 r_dev=dev[1], r_intent=15,
439 test_data=False)
440 check_grpform_results(i_res, r_res)
441 if int(i_res['freq']) > 4000:
442 raise Exception("Unexpected channel - did not follow world roaming rules")
443 remove_group(dev[0], dev[1])
444
445 def test_grpform_no_5ghz_add_cli(dev):
446 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1"""
447 dev[0].request("SET p2p_add_cli_chan 1")
448 dev[1].request("SET p2p_add_cli_chan 1")
449 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
450 r_dev=dev[1], r_intent=14,
451 test_data=False)
452 check_grpform_results(i_res, r_res)
453 if int(i_res['freq']) > 4000:
454 raise Exception("Unexpected channel - did not follow world roaming rules")
455 remove_group(dev[0], dev[1])
456
457 def test_grpform_no_5ghz_add_cli2(dev):
458 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)"""
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
469 def test_grpform_no_5ghz_add_cli3(dev):
470 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)"""
471 dev[0].request("SET p2p_add_cli_chan 1")
472 dev[1].request("SET p2p_add_cli_chan 1")
473 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
474 r_dev=dev[1], r_intent=15,
475 test_data=False)
476 check_grpform_results(i_res, r_res)
477 if int(i_res['freq']) > 4000:
478 raise Exception("Unexpected channel - did not follow world roaming rules")
479 remove_group(dev[0], dev[1])
480
481 def test_grpform_no_5ghz_add_cli4(dev):
482 """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)"""
483 dev[0].request("SET p2p_add_cli_chan 1")
484 dev[1].request("SET p2p_add_cli_chan 1")
485 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
486 r_dev=dev[1], r_intent=0,
487 test_data=False)
488 check_grpform_results(i_res, r_res)
489 if int(i_res['freq']) > 4000:
490 raise Exception("Unexpected channel - did not follow world roaming rules")
491 remove_group(dev[0], dev[1])
492
493 def test_grpform_incorrect_pin(dev):
494 """P2P GO Negotiation with incorrect PIN"""
495 dev[1].p2p_listen()
496 pin = dev[1].wps_read_pin()
497 addr1 = dev[1].p2p_dev_addr()
498 if not dev[0].discover_peer(addr1):
499 raise Exception("Peer not found")
500 dev[1].p2p_go_neg_auth(dev[0].p2p_dev_addr(), pin, 'display', go_intent=0)
501 dev[0].request("P2P_CONNECT " + addr1 + " 00000000 enter go_intent=15")
502 ev = dev[1].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=10)
503 if ev is None:
504 raise Exception("Group formation failure timed out")
505 ev = dev[0].wait_event(["P2P-GROUP-FORMATION-FAILURE"], timeout=5)
506 if ev is None:
507 raise Exception("Group formation failure timed out")
508
509 def test_grpform_reject(dev):
510 """User rejecting group formation attempt by a P2P peer"""
511 addr0 = dev[0].p2p_dev_addr()
512 dev[0].p2p_listen()
513 dev[1].p2p_go_neg_init(addr0, None, "pbc")
514 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
515 if ev is None:
516 raise Exception("GO Negotiation timed out")
517 if "FAIL" in dev[0].global_request("P2P_REJECT " + ev.split(' ')[1]):
518 raise Exception("P2P_REJECT failed")
519 dev[1].request("P2P_STOP_FIND")
520 dev[1].p2p_go_neg_init(addr0, None, "pbc")
521 ev = dev[1].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
522 if ev is None:
523 raise Exception("Rejection not reported")
524 if "status=11" not in ev:
525 raise Exception("Unexpected status code in rejection")
526
527 def test_grpform_pd_no_probe_resp(dev):
528 """GO Negotiation after PD, but no Probe Response"""
529 addr0 = dev[0].p2p_dev_addr()
530 addr1 = dev[1].p2p_dev_addr()
531 dev[0].p2p_listen()
532 if not dev[1].discover_peer(addr0):
533 raise Exception("Peer not found")
534 dev[1].p2p_stop_find()
535 dev[0].p2p_stop_find()
536 peer = dev[0].get_peer(addr1)
537 if peer['listen_freq'] == '0':
538 raise Exception("Peer listen frequency not learned from Probe Request")
539 time.sleep(0.3)
540 dev[0].request("P2P_FLUSH")
541 dev[0].p2p_listen()
542 dev[1].global_request("P2P_PROV_DISC " + addr0 + " display")
543 ev = dev[0].wait_global_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=5)
544 if ev is None:
545 raise Exception("PD Request timed out")
546 ev = dev[1].wait_global_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=5)
547 if ev is None:
548 raise Exception("PD Response timed out")
549 peer = dev[0].get_peer(addr1)
550 if peer['listen_freq'] != '0':
551 raise Exception("Peer listen frequency learned unexpectedly from PD Request")
552
553 pin = dev[0].wps_read_pin()
554 if "FAIL" in dev[1].request("P2P_CONNECT " + addr0 + " " + pin + " enter"):
555 raise Exception("P2P_CONNECT on initiator failed")
556 ev = dev[0].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
557 if ev is None:
558 raise Exception("GO Negotiation start timed out")
559 peer = dev[0].get_peer(addr1)
560 if peer['listen_freq'] == '0':
561 raise Exception("Peer listen frequency not learned from PD followed by GO Neg Req")
562 if "FAIL" in dev[0].request("P2P_CONNECT " + addr1 + " " + pin + " display"):
563 raise Exception("P2P_CONNECT on responder failed")
564 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
565 if ev is None:
566 raise Exception("Group formation timed out")
567 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
568 if ev is None:
569 raise Exception("Group formation timed out")
570
571 def test_go_neg_two_peers(dev):
572 """P2P GO Negotiation rejected due to already started negotiation with another peer"""
573 addr0 = dev[0].p2p_dev_addr()
574 addr1 = dev[1].p2p_dev_addr()
575 addr2 = dev[2].p2p_dev_addr()
576 dev[1].p2p_listen()
577 dev[2].p2p_listen()
578 if not dev[0].discover_peer(addr1):
579 raise Exception("Could not discover peer")
580 if not dev[0].discover_peer(addr2):
581 raise Exception("Could not discover peer")
582 if "OK" not in dev[0].request("P2P_CONNECT " + addr2 + " pbc auth"):
583 raise Exception("Failed to authorize GO Neg")
584 dev[0].p2p_listen()
585 if not dev[2].discover_peer(addr0):
586 raise Exception("Could not discover peer")
587 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc"):
588 raise Exception("Failed to initiate GO Neg")
589 ev = dev[1].wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=5)
590 if ev is None:
591 raise Exception("timeout on GO Neg RX event")
592 dev[2].request("P2P_CONNECT " + addr0 + " pbc")
593 ev = dev[2].wait_global_event(["GO-NEG-FAILURE"], timeout=10)
594 if ev is None:
595 raise Exception("Rejection not reported")
596 if "status=5" not in ev:
597 raise Exception("Unexpected status code in rejection: " + ev)
598
599 def clear_pbc_overlap(dev, ifname):
600 hapd_global = hostapd.HostapdGlobal()
601 hapd_global.remove(ifname)
602 dev[0].p2p_stop_find()
603 dev[1].p2p_stop_find()
604 dev[0].dump_monitor()
605 dev[1].dump_monitor()
606 time.sleep(0.1)
607 dev[0].request("BSS_FLUSH 0")
608 dev[0].request("SCAN freq=2412 only_new=1")
609 dev[1].request("BSS_FLUSH 0")
610 dev[1].request("SCAN freq=2412 only_new=1")
611 time.sleep(1)
612
613 def test_grpform_pbc_overlap(dev, apdev):
614 """P2P group formation during PBC overlap"""
615 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" }
616 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
617 hapd.request("WPS_PBC")
618 time.sleep(0.1)
619
620 addr0 = dev[0].p2p_dev_addr()
621 addr1 = dev[1].p2p_dev_addr()
622 dev[0].p2p_listen()
623 if not dev[1].discover_peer(addr0):
624 raise Exception("Could not discover peer")
625 dev[1].p2p_listen()
626 if not dev[0].discover_peer(addr1):
627 raise Exception("Could not discover peer")
628 dev[0].p2p_listen()
629 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
630 raise Exception("Failed to authorize GO Neg")
631 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
632 raise Exception("Failed to initiate GO Neg")
633 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED"], timeout=15)
634 if ev is None:
635 raise Exception("PBC overlap not reported")
636
637 clear_pbc_overlap(dev, apdev[0]['ifname'])
638
639 def test_grpform_pbc_overlap_group_iface(dev, apdev):
640 """P2P group formation during PBC overlap using group interfaces"""
641 # Note: Need to include P2P IE from the AP to get the P2P interface BSS
642 # update use this information.
643 params = { "ssid": "wps", "eap_server": "1", "wps_state": "1",
644 "beacon_int": "15", 'manage_p2p': '1' }
645 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
646 hapd.request("WPS_PBC")
647
648 dev[0].request("SET p2p_no_group_iface 0")
649 dev[1].request("SET p2p_no_group_iface 0")
650
651 addr0 = dev[0].p2p_dev_addr()
652 addr1 = dev[1].p2p_dev_addr()
653 dev[0].p2p_listen()
654 if not dev[1].discover_peer(addr0):
655 raise Exception("Could not discover peer")
656 dev[1].p2p_listen()
657 if not dev[0].discover_peer(addr1):
658 raise Exception("Could not discover peer")
659 dev[0].p2p_stop_find()
660 dev[0].scan(freq="2412")
661 dev[0].p2p_listen()
662 if "OK" not in dev[0].request("P2P_CONNECT " + addr1 + " pbc auth go_intent=0"):
663 raise Exception("Failed to authorize GO Neg")
664 if "OK" not in dev[1].request("P2P_CONNECT " + addr0 + " pbc go_intent=15 freq=2412"):
665 raise Exception("Failed to initiate GO Neg")
666 ev = dev[0].wait_global_event(["WPS-OVERLAP-DETECTED",
667 "P2P-GROUP-FORMATION-SUCCESS"], timeout=15)
668 if ev is None or "WPS-OVERLAP-DETECTED" not in ev:
669 # Do not report this as failure since the P2P group formation case
670 # using a separate group interface has limited chances of "seeing" the
671 # overlapping AP due to a per-SSID scan and no prior scan operations on
672 # the group interface.
673 logger.info("PBC overlap not reported")
674
675 clear_pbc_overlap(dev, apdev[0]['ifname'])