]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_p2p_channel.py
tests: Fix ap_ft_reassoc_replay for case where wlantest has the PSK
[thirdparty/hostap.git] / tests / hwsim / test_p2p_channel.py
1 # P2P channel selection test cases
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 from remotehost import remote_compatible
8 import logging
9 logger = logging.getLogger()
10 import os
11 import subprocess
12 import time
13
14 import hostapd
15 import hwsim_utils
16 from tshark import run_tshark
17 from wpasupplicant import WpaSupplicant
18 from hwsim import HWSimRadio
19 from p2p_utils import *
20 from utils import clear_regdom_dev
21
22 def set_country(country, dev=None):
23 subprocess.call(['iw', 'reg', 'set', country])
24 time.sleep(0.1)
25 if dev:
26 for i in range(10):
27 ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
28 if ev is None:
29 raise Exception("No regdom change event seen")
30 if "type=COUNTRY alpha2=" + country in ev:
31 return
32 raise Exception("No matching regdom event seen for set_country(%s)" % country)
33
34 def test_p2p_channel_5ghz(dev):
35 """P2P group formation with 5 GHz preference"""
36 try:
37 set_country("US", dev[0])
38 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
39 r_dev=dev[1], r_intent=0,
40 test_data=False)
41 check_grpform_results(i_res, r_res)
42 freq = int(i_res['freq'])
43 if freq < 5000:
44 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
45 remove_group(dev[0], dev[1])
46 finally:
47 set_country("00")
48 dev[1].flush_scan_cache()
49
50 def test_p2p_channel_5ghz_no_vht(dev):
51 """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
52 try:
53 set_country("US", dev[0])
54 dev[0].global_request("P2P_SET disallow_freq 5180-5240")
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 test_data=False)
58 check_grpform_results(i_res, r_res)
59 freq = int(i_res['freq'])
60 if freq < 5000:
61 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
62 remove_group(dev[0], dev[1])
63 finally:
64 set_country("00")
65 dev[0].global_request("P2P_SET disallow_freq ")
66 dev[1].flush_scan_cache()
67
68 def test_p2p_channel_random_social(dev):
69 """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
70 try:
71 set_country("US", dev[0])
72 dev[0].global_request("SET p2p_oper_channel 11")
73 dev[0].global_request("P2P_SET disallow_freq 5000-6000,2462")
74 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
75 r_dev=dev[1], r_intent=0,
76 test_data=False)
77 check_grpform_results(i_res, r_res)
78 freq = int(i_res['freq'])
79 if freq not in [2412, 2437, 2462]:
80 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
81 remove_group(dev[0], dev[1])
82 finally:
83 set_country("00")
84 dev[0].global_request("P2P_SET disallow_freq ")
85 dev[1].flush_scan_cache()
86
87 def test_p2p_channel_random(dev):
88 """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
89 try:
90 set_country("US", dev[0])
91 dev[0].global_request("SET p2p_oper_channel 11")
92 dev[0].global_request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
93 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
94 r_dev=dev[1], r_intent=0,
95 test_data=False)
96 check_grpform_results(i_res, r_res)
97 freq = int(i_res['freq'])
98 if freq > 2500 or freq in [2412, 2437, 2462]:
99 raise Exception("Unexpected channel %d MHz" % freq)
100 remove_group(dev[0], dev[1])
101 finally:
102 set_country("00")
103 dev[0].global_request("P2P_SET disallow_freq ")
104 dev[1].flush_scan_cache()
105
106 def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
107 """P2P group formation using random social channel with oper class change needed"""
108 try:
109 set_country("US", dev[0])
110 logger.info("Start group on 5 GHz")
111 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
112 r_dev=dev[1], r_intent=0,
113 test_data=False)
114 check_grpform_results(i_res, r_res)
115 freq = int(i_res['freq'])
116 if freq < 5000:
117 raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
118 remove_group(dev[0], dev[1])
119
120 logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
121 dev[0].global_request("SET p2p_oper_reg_class 115")
122 dev[0].global_request("SET p2p_oper_channel 36")
123 dev[0].global_request("P2P_SET disallow_freq 5000-6000")
124 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
125 r_dev=dev[1], r_intent=0,
126 test_data=False)
127 check_grpform_results(i_res, r_res)
128 freq = int(i_res['freq'])
129 if freq not in [2412, 2437, 2462]:
130 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
131 remove_group(dev[0], dev[1])
132
133 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
134 "wifi_p2p.public_action.subtype == 0")
135 if out is not None:
136 last = None
137 for l in out.splitlines():
138 if "Operating Channel:" not in l:
139 continue
140 last = l
141 if last is None:
142 raise Exception("Could not find GO Negotiation Request")
143 if "Operating Class 81" not in last:
144 raise Exception("Unexpected operating class: " + last.strip())
145 finally:
146 set_country("00")
147 dev[0].global_request("P2P_SET disallow_freq ")
148 dev[0].global_request("SET p2p_oper_reg_class 0")
149 dev[0].global_request("SET p2p_oper_channel 0")
150 dev[1].flush_scan_cache()
151
152 def test_p2p_channel_avoid(dev):
153 """P2P and avoid frequencies driver event"""
154 try:
155 set_country("US", dev[0])
156 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5000-6000,2412,2437,2462"):
157 raise Exception("Could not simulate driver event")
158 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
159 if ev is None:
160 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
161 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
162 r_dev=dev[1], r_intent=0,
163 test_data=False)
164 check_grpform_results(i_res, r_res)
165 freq = int(i_res['freq'])
166 if freq > 2500 or freq in [2412, 2437, 2462]:
167 raise Exception("Unexpected channel %d MHz" % freq)
168
169 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES"):
170 raise Exception("Could not simulate driver event(2)")
171 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
172 if ev is None:
173 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
174 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
175 "AP-CSA-FINISHED"], timeout=1)
176 if ev is not None:
177 raise Exception("Unexpected + " + ev + " event")
178
179 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
180 raise Exception("Could not simulate driver event(3)")
181 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
182 if ev is None:
183 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
184 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
185 "AP-CSA-FINISHED"],
186 timeout=10)
187 if ev is None:
188 raise Exception("No P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED event")
189 finally:
190 set_country("00")
191 dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
192 dev[1].flush_scan_cache()
193
194 def test_p2p_channel_avoid2(dev):
195 """P2P and avoid frequencies driver event on 5 GHz"""
196 try:
197 set_country("US", dev[0])
198 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
199 r_dev=dev[1], r_intent=0,
200 test_data=False,
201 i_max_oper_chwidth=80,
202 i_ht40=True, i_vht=True)
203 check_grpform_results(i_res, r_res)
204 freq = int(i_res['freq'])
205 if freq < 5000:
206 raise Exception("Unexpected channel %d MHz" % freq)
207
208 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
209 raise Exception("Could not simulate driver event(2)")
210 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
211 if ev is None:
212 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
213 ev = dev[0].wait_group_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=10)
214 if ev is None:
215 raise Exception("No channel switch event seen")
216 if "ch_width=80 MHz" not in ev:
217 raise Exception("Could not move to a VHT80 channel")
218 ev = dev[0].wait_group_event(["AP-CSA-FINISHED"], timeout=1)
219 if ev is None:
220 raise Exception("No AP-CSA-FINISHED event seen")
221 finally:
222 set_country("00")
223 dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
224 dev[1].flush_scan_cache()
225
226 def test_p2p_channel_avoid3(dev):
227 """P2P and avoid frequencies driver event on 5 GHz"""
228 try:
229 set_country("CN", dev[0])
230 form(dev[0], dev[1])
231 set_country("CN", dev[0])
232 [i_res, r_res] = invite_from_go(dev[0], dev[1], terminate=False,
233 extra="ht40 vht")
234 freq = int(i_res['freq'])
235 if freq < 5000:
236 raise Exception("Unexpected channel %d MHz" % freq)
237
238 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5180-5320,5500-5640"):
239 raise Exception("Could not simulate driver event(2)")
240 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
241 if ev is None:
242 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
243 ev = dev[0].wait_group_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=10)
244 if ev is None:
245 raise Exception("No channel switch event seen")
246 if "ch_width=80 MHz" not in ev:
247 raise Exception("Could not move to a VHT80 channel")
248 ev = dev[0].wait_group_event(["AP-CSA-FINISHED"], timeout=1)
249 if ev is None:
250 raise Exception("No AP-CSA-FINISHED event seen")
251 finally:
252 set_country("00")
253 dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
254 dev[1].flush_scan_cache()
255
256 @remote_compatible
257 def test_autogo_following_bss(dev, apdev):
258 """P2P autonomous GO operate on the same channel as station interface"""
259 if dev[0].get_mcc() > 1:
260 logger.info("test mode: MCC")
261
262 dev[0].global_request("SET p2p_no_group_iface 0")
263
264 channels = {3: "2422", 5: "2432", 9: "2452"}
265 for key in channels:
266 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test',
267 "channel": str(key)})
268 dev[0].connect("ap-test", key_mgmt="NONE",
269 scan_freq=str(channels[key]))
270 res_go = autogo(dev[0])
271 if res_go['freq'] != channels[key]:
272 raise Exception("Group operation channel is not the same as on connected station interface")
273 hwsim_utils.test_connectivity(dev[0], hapd)
274 dev[0].remove_group(res_go['ifname'])
275
276 @remote_compatible
277 def test_go_neg_with_bss_connected(dev, apdev):
278 """P2P channel selection: GO negotiation when station interface is connected"""
279
280 dev[0].flush_scan_cache()
281 dev[1].flush_scan_cache()
282 dev[0].global_request("SET p2p_no_group_iface 0")
283
284 hapd = hostapd.add_ap(apdev[0],
285 {"ssid": 'bss-2.4ghz', "channel": '5'})
286 dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2432")
287 #dev[0] as GO
288 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
289 r_intent=1)
290 check_grpform_results(i_res, r_res)
291 if i_res['role'] != "GO":
292 raise Exception("GO not selected according to go_intent")
293 if i_res['freq'] != "2432":
294 raise Exception("Group formed on a different frequency than BSS")
295 hwsim_utils.test_connectivity(dev[0], hapd)
296 dev[0].remove_group(i_res['ifname'])
297 dev[1].wait_go_ending_session()
298
299 if dev[0].get_mcc() > 1:
300 logger.info("Skip as-client case due to MCC being enabled")
301 return
302
303 #dev[0] as client
304 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
305 r_intent=10)
306 check_grpform_results(i_res2, r_res2)
307 if i_res2['role'] != "client":
308 raise Exception("GO not selected according to go_intent")
309 if i_res2['freq'] != "2432":
310 raise Exception("Group formed on a different frequency than BSS")
311 hwsim_utils.test_connectivity(dev[0], hapd)
312 dev[1].remove_group(r_res2['ifname'])
313 dev[0].wait_go_ending_session()
314 dev[0].request("DISCONNECT")
315 hapd.disable()
316 dev[0].flush_scan_cache()
317 dev[1].flush_scan_cache()
318
319 def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
320 """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
321
322 with HWSimRadio(n_channels=2) as (radio, iface):
323 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
324 wpas.interface_add(iface)
325
326 wpas.global_request("SET p2p_no_group_iface 0")
327
328 if wpas.get_mcc() < 2:
329 raise Exception("New radio does not support MCC")
330
331 try:
332 hapd = hostapd.add_ap(apdev[0], {"ssid": 'bss-2.4ghz',
333 "channel": '1'})
334 wpas.global_request("P2P_SET disallow_freq 2412")
335 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
336 res = autogo(wpas)
337 if res['freq'] == "2412":
338 raise Exception("GO set on a disallowed channel")
339 hwsim_utils.test_connectivity(wpas, hapd)
340 finally:
341 wpas.global_request("P2P_SET disallow_freq ")
342
343 def test_go_neg_with_bss_on_disallowed_chan(dev, apdev):
344 """P2P channel selection: GO negotiation with station interface on a disallowed channel"""
345
346 with HWSimRadio(n_channels=2) as (radio, iface):
347 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
348 wpas.interface_add(iface)
349
350 wpas.global_request("SET p2p_no_group_iface 0")
351
352 if wpas.get_mcc() < 2:
353 raise Exception("New radio does not support MCC")
354
355 try:
356 hapd = hostapd.add_ap(apdev[0],
357 {"ssid": 'bss-2.4ghz', "channel": '1'})
358 # make sure PBC overlap from old test cases is not maintained
359 dev[1].flush_scan_cache()
360 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
361 wpas.global_request("P2P_SET disallow_freq 2412")
362
363 #wpas as GO
364 [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
365 r_intent=1)
366 check_grpform_results(i_res, r_res)
367 if i_res['role'] != "GO":
368 raise Exception("GO not selected according to go_intent")
369 if i_res['freq'] == "2412":
370 raise Exception("Group formed on a disallowed channel")
371 hwsim_utils.test_connectivity(wpas, hapd)
372 wpas.remove_group(i_res['ifname'])
373 dev[1].wait_go_ending_session()
374 dev[1].flush_scan_cache()
375
376 wpas.dump_monitor()
377 dev[1].dump_monitor()
378
379 #wpas as client
380 [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
381 r_intent=10)
382 check_grpform_results(i_res2, r_res2)
383 if i_res2['role'] != "client":
384 raise Exception("GO not selected according to go_intent")
385 if i_res2['freq'] == "2412":
386 raise Exception("Group formed on a disallowed channel")
387 hwsim_utils.test_connectivity(wpas, hapd)
388 dev[1].remove_group(r_res2['ifname'])
389 wpas.wait_go_ending_session()
390 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
391 if ev is None:
392 raise Exception("Group removal not indicated")
393 wpas.request("DISCONNECT")
394 hapd.disable()
395 finally:
396 wpas.global_request("P2P_SET disallow_freq ")
397
398 def test_autogo_force_diff_channel(dev, apdev):
399 """P2P autonomous GO and station interface operate on different channels"""
400 with HWSimRadio(n_channels=2) as (radio, iface):
401 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
402 wpas.interface_add(iface)
403
404 if wpas.get_mcc() < 2:
405 raise Exception("New radio does not support MCC")
406
407 wpas.global_request("SET p2p_no_group_iface 0")
408
409 hapd = hostapd.add_ap(apdev[0],
410 {"ssid": 'ap-test', "channel": '1'})
411 wpas.connect("ap-test", key_mgmt="NONE", scan_freq="2412")
412 wpas.dump_monitor()
413 channels = {2: 2417, 5: 2432, 9: 2452}
414 for key in channels:
415 res_go = autogo(wpas, channels[key])
416 wpas.dump_monitor()
417 hwsim_utils.test_connectivity(wpas, hapd)
418 if int(res_go['freq']) == 2412:
419 raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
420 wpas.remove_group(res_go['ifname'])
421 wpas.dump_monitor()
422
423 def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
424 """P2P channel selection: GO negotiation with forced freq different than station interface"""
425 with HWSimRadio(n_channels=2) as (radio, iface):
426 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
427 wpas.interface_add(iface)
428
429 if wpas.get_mcc() < 2:
430 raise Exception("New radio does not support MCC")
431
432 # Clear possible PBC session overlap from previous test case
433 dev[1].flush_scan_cache()
434
435 wpas.global_request("SET p2p_no_group_iface 0")
436
437 hapd = hostapd.add_ap(apdev[0],
438 {"country_code": 'US',
439 "ssid": 'bss-5ghz', "hw_mode": 'a',
440 "channel": '40'})
441 wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
442
443 # GO and peer force the same freq, different than BSS freq,
444 # wpas to become GO
445 [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
446 r_dev=wpas, r_intent=14, r_freq=5180)
447 check_grpform_results(i_res, r_res)
448 if i_res['freq'] != "5180":
449 raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
450 if r_res['role'] != "GO":
451 raise Exception("GO not selected according to go_intent")
452 hwsim_utils.test_connectivity(wpas, hapd)
453 wpas.remove_group(r_res['ifname'])
454 dev[1].wait_go_ending_session()
455 dev[1].flush_scan_cache()
456
457 # GO and peer force the same freq, different than BSS freq, wpas to
458 # become client
459 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
460 r_dev=wpas, r_intent=1, r_freq=2422)
461 check_grpform_results(i_res2, r_res2)
462 if i_res2['freq'] != "2422":
463 raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
464 if r_res2['role'] != "client":
465 raise Exception("GO not selected according to go_intent")
466 hwsim_utils.test_connectivity(wpas, hapd)
467
468 hapd.request("DISABLE")
469 wpas.request("DISCONNECT")
470 wpas.request("ABORT_SCAN")
471 wpas.wait_disconnected()
472 subprocess.call(['iw', 'reg', 'set', '00'])
473 wpas.flush_scan_cache()
474
475 @remote_compatible
476 def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
477 """P2P channel selection: Station on different channel than GO configured pref channel"""
478
479 dev[0].global_request("SET p2p_no_group_iface 0")
480
481 try:
482 hapd = hostapd.add_ap(apdev[0], {"ssid": 'bss-2.4ghz',
483 "channel": '1'})
484 dev[0].global_request("SET p2p_pref_chan 81:2")
485 dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
486 res = autogo(dev[0])
487 if res['freq'] != "2412":
488 raise Exception("GO channel did not follow BSS")
489 hwsim_utils.test_connectivity(dev[0], hapd)
490 finally:
491 dev[0].global_request("SET p2p_pref_chan ")
492
493 def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
494 """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
495 with HWSimRadio(n_channels=2) as (radio, iface):
496 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
497 wpas.interface_add(iface)
498
499 if wpas.get_mcc() < 2:
500 raise Exception("New radio does not support MCC")
501
502 wpas.global_request("SET p2p_no_group_iface 0")
503
504 try:
505 hapd = hostapd.add_ap(apdev[0], {"ssid": 'bss-2.4ghz',
506 "channel": '1'})
507 wpas.global_request("P2P_SET disallow_freq 2412")
508 wpas.global_request("SET p2p_pref_chan 81:2")
509 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
510 res2 = autogo(wpas)
511 if res2['freq'] != "2417":
512 raise Exception("GO channel did not follow pref_chan configuration")
513 hwsim_utils.test_connectivity(wpas, hapd)
514 finally:
515 wpas.global_request("P2P_SET disallow_freq ")
516 wpas.global_request("SET p2p_pref_chan ")
517
518 @remote_compatible
519 def test_no_go_freq(dev, apdev):
520 """P2P channel selection: no GO freq"""
521 try:
522 dev[0].global_request("SET p2p_no_go_freq 2412")
523 # dev[0] as client, channel 1 is ok
524 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
525 r_dev=dev[1], r_intent=14, r_freq=2412)
526 check_grpform_results(i_res, r_res)
527 if i_res['freq'] != "2412":
528 raise Exception("P2P group not formed on forced freq")
529
530 dev[1].remove_group(r_res['ifname'])
531 dev[0].wait_go_ending_session()
532 dev[0].flush_scan_cache()
533
534 fail = False
535 # dev[0] as GO, channel 1 is not allowed
536 try:
537 dev[0].global_request("SET p2p_no_go_freq 2412")
538 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
539 r_dev=dev[1], r_intent=1, r_freq=2412)
540 check_grpform_results(i_res2, r_res2)
541 fail = True
542 except:
543 pass
544 if fail:
545 raise Exception("GO set on a disallowed freq")
546 finally:
547 dev[0].global_request("SET p2p_no_go_freq ")
548
549 @remote_compatible
550 def test_go_neg_peers_force_diff_freq(dev, apdev):
551 """P2P channel selection when peers for different frequency"""
552 try:
553 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
554 r_dev=dev[1], r_intent=0, r_freq=5200)
555 except Exception as e:
556 return
557 raise Exception("Unexpected group formation success")
558
559 @remote_compatible
560 def test_autogo_random_channel(dev, apdev):
561 """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
562 freqs = []
563 go_freqs = ["2412", "2437", "2462"]
564 for i in range(0, 20):
565 result = autogo(dev[0])
566 if result['freq'] not in go_freqs:
567 raise Exception("Unexpected frequency selected: " + result['freq'])
568 if result['freq'] not in freqs:
569 freqs.append(result['freq'])
570 if len(freqs) == 3:
571 break
572 dev[0].remove_group(result['ifname'])
573 if i == 20:
574 raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
575
576 @remote_compatible
577 def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
578 """P2P channel selection: GO preferred channels are disallowed"""
579 try:
580 dev[0].global_request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
581 dev[0].global_request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
582 for i in range(0, 5):
583 res = autogo(dev[0])
584 if res['freq'] in ["2412", "2422", "2437", "2452", "2462"]:
585 raise Exception("GO channel is disallowed")
586 dev[0].remove_group(res['ifname'])
587 finally:
588 dev[0].global_request("P2P_SET disallow_freq ")
589 dev[0].global_request("SET p2p_pref_chan ")
590
591 def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
592 """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
593 try:
594 set_country("US", dev[0])
595 dev[0].global_request("SET p2p_pref_chan 124:149")
596 res = autogo(dev[0], persistent=True)
597 if res['freq'] != "5745":
598 raise Exception("Unexpected channel selected: " + res['freq'])
599 dev[0].remove_group(res['ifname'])
600
601 netw = dev[0].list_networks(p2p=True)
602 if len(netw) != 1:
603 raise Exception("Unexpected number of network blocks: " + str(netw))
604 id = netw[0]['id']
605
606 set_country("SE", dev[0])
607 res = autogo(dev[0], persistent=id)
608 if res['freq'] == "5745":
609 raise Exception("Unexpected channel selected(2): " + res['freq'])
610 dev[0].remove_group(res['ifname'])
611 finally:
612 dev[0].global_request("SET p2p_pref_chan ")
613 clear_regdom_dev(dev)
614
615 def run_autogo(dev, param):
616 if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
617 raise Exception("P2P_GROUP_ADD failed: " + param)
618 ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
619 if ev is None:
620 raise Exception("GO start up timed out")
621 res = dev.group_form_result(ev)
622 dev.remove_group()
623 return res
624
625 def _test_autogo_ht_vht(dev):
626 res = run_autogo(dev[0], "ht40")
627
628 res = run_autogo(dev[0], "vht")
629
630 res = run_autogo(dev[0], "freq=2")
631 freq = int(res['freq'])
632 if freq < 2412 or freq > 2462:
633 raise Exception("Unexpected freq=2 channel: " + str(freq))
634
635 res = run_autogo(dev[0], "freq=5")
636 freq = int(res['freq'])
637 if freq < 5000 or freq >= 6000:
638 raise Exception("Unexpected freq=5 channel: " + str(freq))
639
640 res = run_autogo(dev[0], "freq=5 ht40 vht")
641 logger.info(str(res))
642 freq = int(res['freq'])
643 if freq < 5000 or freq >= 6000:
644 raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
645
646 def test_autogo_ht_vht(dev):
647 """P2P autonomous GO with HT/VHT parameters"""
648 try:
649 set_country("US", dev[0])
650 _test_autogo_ht_vht(dev)
651 finally:
652 clear_regdom_dev(dev)
653
654 def test_p2p_listen_chan_optimize(dev, apdev):
655 """P2P listen channel optimization"""
656 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
657 wpas.interface_add("wlan5")
658 addr5 = wpas.p2p_dev_addr()
659 try:
660 if "OK" not in wpas.global_request("SET p2p_optimize_listen_chan 1"):
661 raise Exception("Failed to set p2p_optimize_listen_chan")
662 wpas.p2p_listen()
663 if not dev[0].discover_peer(addr5):
664 raise Exception("Could not discover peer")
665 peer = dev[0].get_peer(addr5)
666 lfreq = peer['listen_freq']
667 wpas.p2p_stop_find()
668 dev[0].p2p_stop_find()
669
670 channel = "1" if lfreq != '2412' else "6"
671 freq = "2412" if lfreq != '2412' else "2437"
672 params = {"ssid": "test-open", "channel": channel}
673 hapd = hostapd.add_ap(apdev[0], params)
674
675 id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
676 wpas.p2p_listen()
677
678 if "OK" not in dev[0].global_request("P2P_FLUSH"):
679 raise Exception("P2P_FLUSH failed")
680 if not dev[0].discover_peer(addr5):
681 raise Exception("Could not discover peer")
682 peer = dev[0].get_peer(addr5)
683 lfreq2 = peer['listen_freq']
684 if lfreq == lfreq2:
685 raise Exception("Listen channel did not change")
686 if lfreq2 != freq:
687 raise Exception("Listen channel not on AP's operating channel")
688 wpas.p2p_stop_find()
689 dev[0].p2p_stop_find()
690
691 wpas.request("DISCONNECT")
692 wpas.wait_disconnected()
693
694 # for larger coverage, cover case of current channel matching
695 wpas.select_network(id)
696 wpas.wait_connected()
697 wpas.request("DISCONNECT")
698 wpas.wait_disconnected()
699
700 lchannel = "1" if channel != "1" else "6"
701 lfreq3 = "2412" if channel != "1" else "2437"
702 if "OK" not in wpas.global_request("P2P_SET listen_channel " + lchannel):
703 raise Exception("Failed to set listen channel")
704
705 wpas.select_network(id)
706 wpas.wait_connected()
707 wpas.p2p_listen()
708
709 if "OK" not in dev[0].global_request("P2P_FLUSH"):
710 raise Exception("P2P_FLUSH failed")
711 if not dev[0].discover_peer(addr5):
712 raise Exception("Could not discover peer")
713 peer = dev[0].get_peer(addr5)
714 lfreq4 = peer['listen_freq']
715 if lfreq4 != lfreq3:
716 raise Exception("Unexpected Listen channel after configuration")
717 wpas.p2p_stop_find()
718 dev[0].p2p_stop_find()
719 finally:
720 wpas.global_request("SET p2p_optimize_listen_chan 0")
721
722 def test_p2p_channel_5ghz_only(dev):
723 """P2P GO start with only 5 GHz band allowed"""
724 try:
725 set_country("US", dev[0])
726 dev[0].global_request("P2P_SET disallow_freq 2400-2500")
727 res = autogo(dev[0])
728 freq = int(res['freq'])
729 if freq < 5000:
730 raise Exception("Unexpected channel %d MHz" % freq)
731 dev[0].remove_group()
732 finally:
733 dev[0].global_request("P2P_SET disallow_freq ")
734 clear_regdom_dev(dev)
735
736 def test_p2p_channel_5ghz_165_169_us(dev):
737 """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
738 try:
739 set_country("US", dev[0])
740 res = dev[0].p2p_start_go(freq=5825)
741 if res['freq'] != "5825":
742 raise Exception("Unexpected frequency: " + res['freq'])
743 dev[0].remove_group()
744
745 res = dev[0].global_request("P2P_GROUP_ADD freq=5845")
746 if "FAIL" not in res:
747 raise Exception("GO on channel 169 allowed unexpectedly")
748 finally:
749 clear_regdom_dev(dev)
750
751 def wait_go_down_up(dev):
752 ev = dev.wait_group_event(["AP-DISABLED"], timeout=5)
753 if ev is None:
754 raise Exception("AP-DISABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
755 ev = dev.wait_group_event(["AP-ENABLED"], timeout=5)
756 if ev is None:
757 raise Exception("AP-ENABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
758
759 def test_p2p_go_move_reg_change(dev, apdev):
760 """P2P GO move due to regulatory change"""
761 try:
762 set_country("US")
763 dev[0].global_request("P2P_SET disallow_freq 2400-5000,5700-6000")
764 res = autogo(dev[0])
765 freq1 = int(res['freq'])
766 if freq1 < 5000:
767 raise Exception("Unexpected channel %d MHz" % freq1)
768 dev[0].dump_monitor()
769
770 dev[0].global_request("P2P_SET disallow_freq ")
771
772 # GO move is not allowed while waiting for initial client connection
773 connect_cli(dev[0], dev[1], freq=freq1)
774 dev[1].remove_group()
775 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
776 if ev is None:
777 raise Exception("P2P-GROUP-REMOVED not reported on client")
778 dev[1].dump_monitor()
779 dev[0].dump_monitor()
780
781 freq = dev[0].get_group_status_field('freq')
782 if int(freq) < 5000:
783 raise Exception("Unexpected freq after initial client: " + freq)
784 dev[0].dump_monitor()
785
786 dev[0].request("NOTE Setting country=BD")
787 set_country("BD")
788 dev[0].request("NOTE Waiting for GO channel change")
789 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
790 "AP-CSA-FINISHED"],
791 timeout=10)
792 if ev is None:
793 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
794 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
795 wait_go_down_up(dev[0])
796
797 freq2 = dev[0].get_group_status_field('freq')
798 if freq1 == freq2:
799 raise Exception("Unexpected freq after group reform=" + freq2)
800
801 dev[0].remove_group()
802 finally:
803 dev[0].global_request("P2P_SET disallow_freq ")
804 set_country("00")
805
806 def test_p2p_go_move_active(dev, apdev):
807 """P2P GO stays in freq although SCM is possible"""
808 with HWSimRadio(n_channels=2) as (radio, iface):
809 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
810 wpas.interface_add(iface)
811
812 if wpas.get_mcc() < 2:
813 raise Exception("New radio does not support MCC")
814
815 ndev = [wpas, dev[1]]
816 _test_p2p_go_move_active(ndev, apdev)
817
818 def _test_p2p_go_move_active(dev, apdev):
819 dev[0].global_request("SET p2p_no_group_iface 0")
820 try:
821 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
822 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test',
823 "channel": '11'})
824 dev[0].connect("ap-test", key_mgmt="NONE",
825 scan_freq="2462")
826
827 res = autogo(dev[0])
828 freq = int(res['freq'])
829 if freq > 2430:
830 raise Exception("Unexpected channel %d MHz" % freq)
831
832 # GO move is not allowed while waiting for initial client connection
833 connect_cli(dev[0], dev[1], freq=freq)
834 dev[1].remove_group()
835
836 freq = dev[0].get_group_status_field('freq')
837 if int(freq) > 2430:
838 raise Exception("Unexpected freq after initial client: " + freq)
839
840 dev[0].dump_monitor()
841 dev[0].global_request("P2P_SET disallow_freq ")
842
843 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
844 "AP-CSA-FINISHED"],
845 timeout=10)
846 if ev is not None:
847 raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
848
849 dev[0].remove_group()
850 finally:
851 dev[0].global_request("P2P_SET disallow_freq ")
852
853 def test_p2p_go_move_scm(dev, apdev):
854 """P2P GO move due to SCM operation preference"""
855 with HWSimRadio(n_channels=2) as (radio, iface):
856 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
857 wpas.interface_add(iface)
858
859 if wpas.get_mcc() < 2:
860 raise Exception("New radio does not support MCC")
861
862 ndev = [wpas, dev[1]]
863 _test_p2p_go_move_scm(ndev, apdev)
864
865 def _test_p2p_go_move_scm(dev, apdev):
866 dev[0].global_request("SET p2p_no_group_iface 0")
867 try:
868 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
869 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test',
870 "channel": '11'})
871 dev[0].connect("ap-test", key_mgmt="NONE",
872 scan_freq="2462")
873
874 dev[0].global_request("SET p2p_go_freq_change_policy 0")
875 res = autogo(dev[0])
876 freq = int(res['freq'])
877 if freq > 2430:
878 raise Exception("Unexpected channel %d MHz" % freq)
879
880 # GO move is not allowed while waiting for initial client connection
881 connect_cli(dev[0], dev[1], freq=freq)
882 dev[1].remove_group()
883
884 freq = dev[0].get_group_status_field('freq')
885 if int(freq) > 2430:
886 raise Exception("Unexpected freq after initial client: " + freq)
887
888 dev[0].dump_monitor()
889 dev[0].global_request("P2P_SET disallow_freq ")
890
891 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
892 "AP-CSA-FINISHED"], timeout=3)
893 if ev is None:
894 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
895 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
896 wait_go_down_up(dev[0])
897
898 freq = dev[0].get_group_status_field('freq')
899 if freq != '2462':
900 raise Exception("Unexpected freq after group reform=" + freq)
901
902 dev[0].remove_group()
903 finally:
904 dev[0].global_request("P2P_SET disallow_freq ")
905 dev[0].global_request("SET p2p_go_freq_change_policy 2")
906
907 def test_p2p_go_move_scm_peer_supports(dev, apdev):
908 """P2P GO move due to SCM operation preference (peer supports)"""
909 with HWSimRadio(n_channels=2) as (radio, iface):
910 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
911 wpas.interface_add(iface)
912
913 if wpas.get_mcc() < 2:
914 raise Exception("New radio does not support MCC")
915
916 ndev = [wpas, dev[1]]
917 _test_p2p_go_move_scm_peer_supports(ndev, apdev)
918
919 def _test_p2p_go_move_scm_peer_supports(dev, apdev):
920 try:
921 dev[0].global_request("SET p2p_go_freq_change_policy 1")
922 set_country("US", dev[0])
923
924 dev[0].global_request("SET p2p_no_group_iface 0")
925 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
926 r_dev=dev[1], r_intent=0,
927 test_data=False)
928 check_grpform_results(i_res, r_res)
929 freq = int(i_res['freq'])
930 if freq < 5000:
931 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
932
933 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test',
934 "channel": '11'})
935 logger.info('Connecting client to to an AP on channel 11')
936 dev[0].connect("ap-test", key_mgmt="NONE",
937 scan_freq="2462")
938
939 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
940 "AP-CSA-FINISHED"], timeout=3)
941 if ev is None:
942 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
943 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
944 wait_go_down_up(dev[0])
945
946 freq = dev[0].get_group_status_field('freq')
947 if freq != '2462':
948 raise Exception("Unexpected freq after group reform=" + freq)
949
950 dev[0].remove_group()
951 finally:
952 dev[0].global_request("SET p2p_go_freq_change_policy 2")
953 set_country("00")
954
955 def test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
956 """No P2P GO move due to SCM operation (peer does not supports)"""
957 with HWSimRadio(n_channels=2) as (radio, iface):
958 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
959 wpas.interface_add(iface)
960
961 if wpas.get_mcc() < 2:
962 raise Exception("New radio does not support MCC")
963
964 ndev = [wpas, dev[1]]
965 _test_p2p_go_move_scm_peer_does_not_support(ndev, apdev)
966
967 def _test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
968 try:
969 dev[0].global_request("SET p2p_go_freq_change_policy 1")
970 set_country("US", dev[0])
971
972 dev[0].global_request("SET p2p_no_group_iface 0")
973 if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
974 raise Exception("Could not simulate driver event")
975 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
976 r_dev=dev[1], r_intent=0,
977 test_data=False)
978 check_grpform_results(i_res, r_res)
979 freq = int(i_res['freq'])
980 if freq < 5000:
981 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
982
983 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test',
984 "channel": '11'})
985 logger.info('Connecting client to to an AP on channel 11')
986 dev[0].connect("ap-test", key_mgmt="NONE",
987 scan_freq="2462")
988
989 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
990 "AP-CSA-FINISHED"],
991 timeout=10)
992 if ev is not None:
993 raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
994
995 dev[0].remove_group()
996 finally:
997 dev[0].global_request("SET p2p_go_freq_change_policy 2")
998 dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES")
999 clear_regdom_dev(dev, 2)
1000
1001 def test_p2p_go_move_scm_multi(dev, apdev):
1002 """P2P GO move due to SCM operation preference multiple times"""
1003 with HWSimRadio(n_channels=2) as (radio, iface):
1004 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1005 wpas.interface_add(iface)
1006
1007 if wpas.get_mcc() < 2:
1008 raise Exception("New radio does not support MCC")
1009
1010 ndev = [wpas, dev[1]]
1011 _test_p2p_go_move_scm_multi(ndev, apdev)
1012
1013 def _test_p2p_go_move_scm_multi(dev, apdev):
1014 dev[0].request("SET p2p_no_group_iface 0")
1015 try:
1016 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
1017 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test-1',
1018 "channel": '11'})
1019 dev[0].connect("ap-test-1", key_mgmt="NONE",
1020 scan_freq="2462")
1021
1022 dev[0].global_request("SET p2p_go_freq_change_policy 0")
1023 res = autogo(dev[0])
1024 freq = int(res['freq'])
1025 if freq > 2430:
1026 raise Exception("Unexpected channel %d MHz" % freq)
1027
1028 # GO move is not allowed while waiting for initial client connection
1029 connect_cli(dev[0], dev[1], freq=freq)
1030 dev[1].remove_group()
1031
1032 freq = dev[0].get_group_status_field('freq')
1033 if int(freq) > 2430:
1034 raise Exception("Unexpected freq after initial client: " + freq)
1035
1036 dev[0].dump_monitor()
1037 dev[0].global_request("P2P_SET disallow_freq ")
1038
1039 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
1040 "AP-CSA-FINISHED"], timeout=3)
1041 if ev is None:
1042 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
1043 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
1044 wait_go_down_up(dev[0])
1045
1046 freq = dev[0].get_group_status_field('freq')
1047 if freq != '2462':
1048 raise Exception("Unexpected freq after group reform=" + freq)
1049
1050 hapd = hostapd.add_ap(apdev[0], {"ssid": 'ap-test-2',
1051 "channel": '6'})
1052 dev[0].connect("ap-test-2", key_mgmt="NONE",
1053 scan_freq="2437")
1054
1055 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
1056 "AP-CSA-FINISHED"], timeout=5)
1057 if ev is None:
1058 raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
1059 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
1060 wait_go_down_up(dev[0])
1061
1062 freq = dev[0].get_group_status_field('freq')
1063 if freq != '2437':
1064 raise Exception("(2) Unexpected freq after group reform=" + freq)
1065
1066 dev[0].remove_group()
1067 finally:
1068 dev[0].global_request("P2P_SET disallow_freq ")
1069 dev[0].global_request("SET p2p_go_freq_change_policy 2")
1070
1071 def test_p2p_delay_go_csa(dev, apdev, params):
1072 """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
1073 with HWSimRadio(n_channels=2) as (radio, iface):
1074 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1075 wpas.interface_add(iface)
1076
1077 wpas.global_request("SET p2p_no_group_iface 0")
1078
1079 if wpas.get_mcc() < 2:
1080 raise Exception("New radio does not support MCC")
1081
1082 addr0 = wpas.p2p_dev_addr()
1083 addr1 = dev[1].p2p_dev_addr()
1084
1085 try:
1086 dev[1].p2p_listen()
1087 if not wpas.discover_peer(addr1, social=True):
1088 raise Exception("Peer " + addr1 + " not found")
1089 wpas.p2p_stop_find()
1090
1091 hapd = hostapd.add_ap(apdev[0], {"ssid": 'bss-2.4ghz',
1092 "channel": '1'})
1093
1094 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
1095
1096 wpas.global_request("SET p2p_go_freq_change_policy 0")
1097 wpas.dump_monitor()
1098
1099 logger.info("Start GO on channel 6")
1100 res = autogo(wpas, freq=2437)
1101 if res['freq'] != "2437":
1102 raise Exception("GO set on a freq=%s instead of 2437" % res['freq'])
1103
1104 # Start find on dev[1] to run scans with dev[2] in parallel
1105 dev[1].p2p_find(social=True)
1106
1107 # Use another client device to stop the initial client connection
1108 # timeout on the GO
1109 if not dev[2].discover_peer(addr0, social=True):
1110 raise Exception("Peer2 did not find the GO")
1111 dev[2].p2p_stop_find()
1112 pin = dev[2].wps_read_pin()
1113 wpas.p2p_go_authorize_client(pin)
1114 dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
1115 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1116 if ev is None:
1117 raise Exception("Peer2 did not get connected")
1118
1119 if not dev[1].discover_peer(addr0, social=True):
1120 raise Exception("Peer did not find the GO")
1121
1122 pin = dev[1].wps_read_pin()
1123 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
1124 dev[1].p2p_listen()
1125
1126 # Force P2P GO channel switch on successful invitation signaling
1127 wpas.group_request("SET p2p_go_csa_on_inv 1")
1128
1129 logger.info("Starting invitation")
1130 wpas.p2p_go_authorize_client(pin)
1131 wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
1132 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
1133 "P2P-GROUP-STARTED"], timeout=10)
1134
1135 if ev is None:
1136 raise Exception("Timeout on invitation on peer")
1137 if "P2P-INVITATION-RECEIVED" in ev:
1138 raise Exception("Unexpected request to accept pre-authorized invitation")
1139
1140 # A P2P GO move is not expected at this stage, as during the
1141 # invitation signaling, the P2P GO includes only its current
1142 # operating channel in the channel list, and as the invitation
1143 # response can only include channels that were also in the
1144 # invitation request channel list, the group common channels
1145 # includes only the current P2P GO operating channel.
1146 ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
1147 "AP-CSA-FINISHED"], timeout=1)
1148 if ev is not None:
1149 raise Exception("Unexpected + " + ev + " event")
1150
1151 finally:
1152 wpas.global_request("SET p2p_go_freq_change_policy 2")
1153
1154 def test_p2p_channel_vht80(dev):
1155 """P2P group formation with VHT 80 MHz"""
1156 try:
1157 set_country("FI", dev[0])
1158 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1159 i_freq=5180,
1160 i_max_oper_chwidth=80,
1161 i_ht40=True, i_vht=True,
1162 r_dev=dev[1], r_intent=0,
1163 test_data=False)
1164 check_grpform_results(i_res, r_res)
1165 freq = int(i_res['freq'])
1166 if freq < 5000:
1167 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
1168 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1169 if "FREQUENCY=5180" not in sig:
1170 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1171 if "WIDTH=80 MHz" not in sig:
1172 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1173 remove_group(dev[0], dev[1])
1174 finally:
1175 set_country("00")
1176 dev[1].flush_scan_cache()
1177
1178 def test_p2p_channel_vht80p80(dev):
1179 """P2P group formation and VHT 80+80 MHz channel"""
1180 try:
1181 set_country("US", dev[0])
1182 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1183 i_freq=5180,
1184 i_freq2=5775,
1185 i_max_oper_chwidth=160,
1186 i_ht40=True, i_vht=True,
1187 r_dev=dev[1], r_intent=0,
1188 test_data=False)
1189 check_grpform_results(i_res, r_res)
1190 freq = int(i_res['freq'])
1191 if freq < 5000:
1192 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
1193 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1194 if "FREQUENCY=5180" not in sig:
1195 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1196 if "WIDTH=80+80 MHz" not in sig:
1197 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1198 if "CENTER_FRQ1=5210" not in sig:
1199 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1200 if "CENTER_FRQ2=5775" not in sig:
1201 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1202 remove_group(dev[0], dev[1])
1203 finally:
1204 set_country("00")
1205 dev[1].flush_scan_cache()
1206
1207 def test_p2p_channel_vht80p80_autogo(dev):
1208 """P2P autonomous GO and VHT 80+80 MHz channel"""
1209 addr0 = dev[0].p2p_dev_addr()
1210
1211 try:
1212 set_country("US", dev[0])
1213 if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 freq2=5775"):
1214 raise Exception("Could not start GO")
1215 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
1216 if ev is None:
1217 raise Exception("GO start up timed out")
1218 dev[0].group_form_result(ev)
1219
1220 pin = dev[1].wps_read_pin()
1221 dev[0].p2p_go_authorize_client(pin)
1222
1223 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1224 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1225 if ev is None:
1226 raise Exception("Peer did not get connected")
1227
1228 dev[1].group_form_result(ev)
1229 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1230 if "FREQUENCY=5180" not in sig:
1231 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1232 if "WIDTH=80+80 MHz" not in sig:
1233 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1234 if "CENTER_FRQ1=5210" not in sig:
1235 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1236 if "CENTER_FRQ2=5775" not in sig:
1237 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1238 remove_group(dev[0], dev[1])
1239 finally:
1240 set_country("00")
1241 dev[1].flush_scan_cache()
1242
1243 def test_p2p_channel_vht80_autogo(dev):
1244 """P2P autonomous GO and VHT 80 MHz channel"""
1245 addr0 = dev[0].p2p_dev_addr()
1246
1247 try:
1248 set_country("US", dev[0])
1249 if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 max_oper_chwidth=80"):
1250 raise Exception("Could not start GO")
1251 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
1252 if ev is None:
1253 raise Exception("GO start up timed out")
1254 dev[0].group_form_result(ev)
1255
1256 pin = dev[1].wps_read_pin()
1257 dev[0].p2p_go_authorize_client(pin)
1258
1259 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1260 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1261 if ev is None:
1262 raise Exception("Peer did not get connected")
1263
1264 dev[1].group_form_result(ev)
1265 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1266 if "FREQUENCY=5180" not in sig:
1267 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1268 if "WIDTH=80 MHz" not in sig:
1269 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1270 remove_group(dev[0], dev[1])
1271 finally:
1272 set_country("00")
1273 dev[1].flush_scan_cache()
1274
1275 def test_p2p_channel_vht80p80_persistent(dev):
1276 """P2P persistent group re-invocation and VHT 80+80 MHz channel"""
1277 addr0 = dev[0].p2p_dev_addr()
1278 form(dev[0], dev[1])
1279
1280 try:
1281 set_country("US", dev[0])
1282 invite(dev[0], dev[1], extra="vht freq=5745 freq2=5210")
1283 [go_res, cli_res] = check_result(dev[0], dev[1])
1284
1285 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1286 if "FREQUENCY=5745" not in sig:
1287 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1288 if "WIDTH=80+80 MHz" not in sig:
1289 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1290 if "CENTER_FRQ1=5775" not in sig:
1291 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1292 if "CENTER_FRQ2=5210" not in sig:
1293 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1294 remove_group(dev[0], dev[1])
1295 finally:
1296 set_country("00")
1297 dev[1].flush_scan_cache()
1298
1299 def test_p2p_channel_drv_pref_go_neg(dev):
1300 """P2P GO Negotiation with GO device channel preference"""
1301 dev[0].global_request("SET get_pref_freq_list_override 3:2417 4:2422")
1302 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1303 r_dev=dev[1], r_intent=0,
1304 test_data=False)
1305 check_grpform_results(i_res, r_res)
1306 freq = int(i_res['freq'])
1307 if freq != 2417:
1308 raise Exception("Unexpected channel selected: %d" % freq)
1309 remove_group(dev[0], dev[1])
1310
1311 def test_p2p_channel_drv_pref_go_neg2(dev):
1312 """P2P GO Negotiation with P2P client device channel preference"""
1313 dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422")
1314 dev[1].global_request("SET get_pref_freq_list_override 4:2422")
1315 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1316 r_dev=dev[1], r_intent=0,
1317 test_data=False)
1318 check_grpform_results(i_res, r_res)
1319 freq = int(i_res['freq'])
1320 if freq != 2422:
1321 raise Exception("Unexpected channel selected: %d" % freq)
1322 remove_group(dev[0], dev[1])
1323
1324 def test_p2p_channel_drv_pref_go_neg3(dev):
1325 """P2P GO Negotiation with GO device channel preference"""
1326 dev[1].global_request("SET get_pref_freq_list_override 3:2417,2427 4:2422")
1327 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0,
1328 r_dev=dev[1], r_intent=15,
1329 test_data=False)
1330 check_grpform_results(i_res, r_res)
1331 freq = int(i_res['freq'])
1332 if freq != 2417:
1333 raise Exception("Unexpected channel selected: %d" % freq)
1334 remove_group(dev[0], dev[1])
1335
1336 def test_p2p_channel_drv_pref_go_neg4(dev):
1337 """P2P GO Negotiation with P2P client device channel preference"""
1338 dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422,5180")
1339 dev[1].global_request("P2P_SET override_pref_op_chan 115:36")
1340 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1341 r_dev=dev[1], r_intent=0,
1342 test_data=False)
1343 check_grpform_results(i_res, r_res)
1344 freq = int(i_res['freq'])
1345 if freq != 2417:
1346 raise Exception("Unexpected channel selected: %d" % freq)
1347 remove_group(dev[0], dev[1])
1348
1349 def test_p2p_channel_drv_pref_go_neg5(dev):
1350 """P2P GO Negotiation with P2P client device channel preference"""
1351 dev[0].global_request("SET get_pref_freq_list_override 3:2417")
1352 dev[1].global_request("SET get_pref_freq_list_override 4:2422")
1353 dev[1].global_request("P2P_SET override_pref_op_chan 115:36")
1354 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1355 r_dev=dev[1], r_intent=0,
1356 test_data=False)
1357 check_grpform_results(i_res, r_res)
1358 freq = int(i_res['freq'])
1359 if freq != 2417:
1360 raise Exception("Unexpected channel selected: %d" % freq)
1361 remove_group(dev[0], dev[1])
1362
1363 def test_p2p_channel_drv_pref_autogo(dev):
1364 """P2P autonomous GO with driver channel preference"""
1365 dev[0].global_request("SET get_pref_freq_list_override 3:2417,2422,5180")
1366 res_go = autogo(dev[0])
1367 if res_go['freq'] != "2417":
1368 raise Exception("Unexpected operating frequency: " + res_go['freq'])