1 # P2P channel selection test cases
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
15 from tshark import run_tshark
16 from wpasupplicant import WpaSupplicant
17 from hwsim import HWSimRadio
18 from p2p_utils import *
20 def set_country(country, dev=None):
21 subprocess.call(['iw', 'reg', 'set', country])
25 ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
27 raise Exception("No regdom change event seen")
28 if "type=COUNTRY alpha2=" + country in ev:
30 raise Exception("No matching regdom event seen for set_country(%s)" % country)
32 def test_p2p_channel_5ghz(dev):
33 """P2P group formation with 5 GHz preference"""
35 set_country("US", dev[0])
36 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
37 r_dev=dev[1], r_intent=0,
39 check_grpform_results(i_res, r_res)
40 freq = int(i_res['freq'])
42 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
43 remove_group(dev[0], dev[1])
46 dev[1].flush_scan_cache()
48 def test_p2p_channel_5ghz_no_vht(dev):
49 """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
51 set_country("US", dev[0])
52 dev[0].request("P2P_SET disallow_freq 5180-5240")
53 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
54 r_dev=dev[1], r_intent=0,
56 check_grpform_results(i_res, r_res)
57 freq = int(i_res['freq'])
59 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
60 remove_group(dev[0], dev[1])
63 dev[0].request("P2P_SET disallow_freq ")
64 dev[1].flush_scan_cache()
66 def test_p2p_channel_random_social(dev):
67 """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
69 set_country("US", dev[0])
70 dev[0].request("SET p2p_oper_channel 11")
71 dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
72 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
73 r_dev=dev[1], r_intent=0,
75 check_grpform_results(i_res, r_res)
76 freq = int(i_res['freq'])
77 if freq not in [ 2412, 2437, 2462 ]:
78 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
79 remove_group(dev[0], dev[1])
82 dev[0].request("P2P_SET disallow_freq ")
83 dev[1].flush_scan_cache()
85 def test_p2p_channel_random(dev):
86 """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
88 set_country("US", dev[0])
89 dev[0].request("SET p2p_oper_channel 11")
90 dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
91 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
92 r_dev=dev[1], r_intent=0,
94 check_grpform_results(i_res, r_res)
95 freq = int(i_res['freq'])
96 if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
97 raise Exception("Unexpected channel %d MHz" % freq)
98 remove_group(dev[0], dev[1])
101 dev[0].request("P2P_SET disallow_freq ")
102 dev[1].flush_scan_cache()
104 def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
105 """P2P group formation using random social channel with oper class change needed"""
107 set_country("US", dev[0])
108 logger.info("Start group on 5 GHz")
109 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
110 r_dev=dev[1], r_intent=0,
112 check_grpform_results(i_res, r_res)
113 freq = int(i_res['freq'])
115 raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
116 remove_group(dev[0], dev[1])
118 logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
119 dev[0].request("SET p2p_oper_reg_class 115")
120 dev[0].request("SET p2p_oper_channel 36")
121 dev[0].request("P2P_SET disallow_freq 5000-6000")
122 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
123 r_dev=dev[1], r_intent=0,
125 check_grpform_results(i_res, r_res)
126 freq = int(i_res['freq'])
127 if freq not in [ 2412, 2437, 2462 ]:
128 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
129 remove_group(dev[0], dev[1])
131 out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
132 "wifi_p2p.public_action.subtype == 0")
135 for l in out.splitlines():
136 if "Operating Channel:" not in l:
140 raise Exception("Could not find GO Negotiation Request")
141 if "Operating Class 81" not in last:
142 raise Exception("Unexpected operating class: " + last.strip())
145 dev[0].request("P2P_SET disallow_freq ")
146 dev[0].request("SET p2p_oper_reg_class 0")
147 dev[0].request("SET p2p_oper_channel 0")
148 dev[1].flush_scan_cache()
150 def test_p2p_channel_avoid(dev):
151 """P2P and avoid frequencies driver event"""
153 set_country("US", dev[0])
154 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES 5000-6000,2412,2437,2462"):
155 raise Exception("Could not simulate driver event")
156 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
158 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
159 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
160 r_dev=dev[1], r_intent=0,
162 check_grpform_results(i_res, r_res)
163 freq = int(i_res['freq'])
164 if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
165 raise Exception("Unexpected channel %d MHz" % freq)
167 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES"):
168 raise Exception("Could not simulate driver event(2)")
169 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
171 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
172 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
173 "AP-CSA-FINISHED"], timeout=1)
175 raise Exception("Unexpected + " + ev + " event")
177 if "OK" not in dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES " + str(freq)):
178 raise Exception("Could not simulate driver event(3)")
179 ev = dev[0].wait_event(["CTRL-EVENT-AVOID-FREQ"], timeout=10)
181 raise Exception("No CTRL-EVENT-AVOID-FREQ event")
182 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
186 raise Exception("No P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED event")
189 dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
190 dev[1].flush_scan_cache()
192 def test_autogo_following_bss(dev, apdev):
193 """P2P autonomous GO operate on the same channel as station interface"""
194 if dev[0].get_mcc() > 1:
195 logger.info("test mode: MCC")
197 dev[0].request("SET p2p_no_group_iface 0")
199 channels = { 3 : "2422", 5 : "2432", 9 : "2452" }
201 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
202 "channel" : str(key) })
203 dev[0].connect("ap-test", key_mgmt="NONE",
204 scan_freq=str(channels[key]))
205 res_go = autogo(dev[0])
206 if res_go['freq'] != channels[key]:
207 raise Exception("Group operation channel is not the same as on connected station interface")
208 hwsim_utils.test_connectivity(dev[0], hapd)
209 dev[0].remove_group(res_go['ifname'])
211 def test_go_neg_with_bss_connected(dev, apdev):
212 """P2P channel selection: GO negotiation when station interface is connected"""
214 dev[0].flush_scan_cache()
215 dev[1].flush_scan_cache()
216 dev[0].request("SET p2p_no_group_iface 0")
218 hapd = hostapd.add_ap(apdev[0],
219 { "ssid": 'bss-2.4ghz', "channel": '5' })
220 dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2432")
222 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
224 check_grpform_results(i_res, r_res)
225 if i_res['role'] != "GO":
226 raise Exception("GO not selected according to go_intent")
227 if i_res['freq'] != "2432":
228 raise Exception("Group formed on a different frequency than BSS")
229 hwsim_utils.test_connectivity(dev[0], hapd)
230 dev[0].remove_group(i_res['ifname'])
231 dev[1].wait_go_ending_session()
233 if dev[0].get_mcc() > 1:
234 logger.info("Skip as-client case due to MCC being enabled")
238 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
240 check_grpform_results(i_res2, r_res2)
241 if i_res2['role'] != "client":
242 raise Exception("GO not selected according to go_intent")
243 if i_res2['freq'] != "2432":
244 raise Exception("Group formed on a different frequency than BSS")
245 hwsim_utils.test_connectivity(dev[0], hapd)
246 dev[1].remove_group(r_res2['ifname'])
247 dev[0].wait_go_ending_session()
248 dev[0].request("DISCONNECT")
250 dev[0].flush_scan_cache()
251 dev[1].flush_scan_cache()
253 def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
254 """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
256 with HWSimRadio(n_channels=2) as (radio, iface):
257 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
258 wpas.interface_add(iface)
260 wpas.request("SET p2p_no_group_iface 0")
262 if wpas.get_mcc() < 2:
263 raise Exception("New radio does not support MCC")
266 hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
268 wpas.request("P2P_SET disallow_freq 2412")
269 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
271 if res['freq'] == "2412":
272 raise Exception("GO set on a disallowed channel")
273 hwsim_utils.test_connectivity(wpas, hapd)
275 wpas.request("P2P_SET disallow_freq ")
277 def test_go_neg_with_bss_on_disallowed_chan(dev, apdev):
278 """P2P channel selection: GO negotiation with station interface on a disallowed channel"""
280 with HWSimRadio(n_channels=2) as (radio, iface):
281 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
282 wpas.interface_add(iface)
284 wpas.request("SET p2p_no_group_iface 0")
286 if wpas.get_mcc() < 2:
287 raise Exception("New radio does not support MCC")
290 hapd = hostapd.add_ap(apdev[0],
291 { "ssid": 'bss-2.4ghz', "channel": '1' })
292 # make sure PBC overlap from old test cases is not maintained
293 dev[1].flush_scan_cache()
294 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
295 wpas.request("P2P_SET disallow_freq 2412")
298 [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
300 check_grpform_results(i_res, r_res)
301 if i_res['role'] != "GO":
302 raise Exception("GO not selected according to go_intent")
303 if i_res['freq'] == "2412":
304 raise Exception("Group formed on a disallowed channel")
305 hwsim_utils.test_connectivity(wpas, hapd)
306 wpas.remove_group(i_res['ifname'])
307 dev[1].wait_go_ending_session()
308 dev[1].flush_scan_cache()
311 dev[1].dump_monitor()
314 [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
316 check_grpform_results(i_res2, r_res2)
317 if i_res2['role'] != "client":
318 raise Exception("GO not selected according to go_intent")
319 if i_res2['freq'] == "2412":
320 raise Exception("Group formed on a disallowed channel")
321 hwsim_utils.test_connectivity(wpas, hapd)
322 dev[1].remove_group(r_res2['ifname'])
323 wpas.wait_go_ending_session()
324 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=5)
326 raise Exception("Group removal not indicated")
327 wpas.request("DISCONNECT")
330 wpas.request("P2P_SET disallow_freq ")
332 def test_autogo_force_diff_channel(dev, apdev):
333 """P2P autonomous GO and station interface operate on different channels"""
334 with HWSimRadio(n_channels=2) as (radio, iface):
335 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
336 wpas.interface_add(iface)
338 if wpas.get_mcc() < 2:
339 raise Exception("New radio does not support MCC")
341 wpas.request("SET p2p_no_group_iface 0")
343 hapd = hostapd.add_ap(apdev[0],
344 {"ssid" : 'ap-test', "channel" : '1'})
345 wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412")
347 channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
349 res_go = autogo(wpas, channels[key])
351 hwsim_utils.test_connectivity(wpas, hapd)
352 if int(res_go['freq']) == 2412:
353 raise Exception("Group operation channel is: 2412 excepted: " + res_go['freq'])
354 wpas.remove_group(res_go['ifname'])
357 def test_go_neg_forced_freq_diff_than_bss_freq(dev, apdev):
358 """P2P channel selection: GO negotiation with forced freq different than station interface"""
359 with HWSimRadio(n_channels=2) as (radio, iface):
360 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
361 wpas.interface_add(iface)
363 if wpas.get_mcc() < 2:
364 raise Exception("New radio does not support MCC")
366 # Clear possible PBC session overlap from previous test case
367 dev[1].flush_scan_cache()
369 wpas.request("SET p2p_no_group_iface 0")
371 hapd = hostapd.add_ap(apdev[0],
372 { "country_code": 'US',
373 "ssid": 'bss-5ghz', "hw_mode": 'a',
375 wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
377 # GO and peer force the same freq, different than BSS freq,
379 [i_res, r_res] = go_neg_pbc(i_dev=dev[1], i_intent=1, i_freq=5180,
380 r_dev=wpas, r_intent=14, r_freq=5180)
381 check_grpform_results(i_res, r_res)
382 if i_res['freq'] != "5180":
383 raise Exception("P2P group formed on unexpected frequency: " + i_res['freq'])
384 if r_res['role'] != "GO":
385 raise Exception("GO not selected according to go_intent")
386 hwsim_utils.test_connectivity(wpas, hapd)
387 wpas.remove_group(r_res['ifname'])
388 dev[1].wait_go_ending_session()
389 dev[1].flush_scan_cache()
391 # GO and peer force the same freq, different than BSS freq, wpas to
393 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[1], i_intent=14, i_freq=2422,
394 r_dev=wpas, r_intent=1, r_freq=2422)
395 check_grpform_results(i_res2, r_res2)
396 if i_res2['freq'] != "2422":
397 raise Exception("P2P group formed on unexpected frequency: " + i_res2['freq'])
398 if r_res2['role'] != "client":
399 raise Exception("GO not selected according to go_intent")
400 hwsim_utils.test_connectivity(wpas, hapd)
402 wpas.request("DISCONNECT")
403 hapd.request("DISABLE")
404 subprocess.call(['iw', 'reg', 'set', '00'])
405 wpas.flush_scan_cache()
407 def test_go_pref_chan_bss_on_diff_chan(dev, apdev):
408 """P2P channel selection: Station on different channel than GO configured pref channel"""
410 dev[0].request("SET p2p_no_group_iface 0")
413 hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
415 dev[0].request("SET p2p_pref_chan 81:2")
416 dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
418 if res['freq'] != "2412":
419 raise Exception("GO channel did not follow BSS")
420 hwsim_utils.test_connectivity(dev[0], hapd)
422 dev[0].request("SET p2p_pref_chan ")
424 def test_go_pref_chan_bss_on_disallowed_chan(dev, apdev):
425 """P2P channel selection: Station interface on different channel than GO configured pref channel, and station channel is disallowed"""
426 with HWSimRadio(n_channels=2) as (radio, iface):
427 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
428 wpas.interface_add(iface)
430 if wpas.get_mcc() < 2:
431 raise Exception("New radio does not support MCC")
433 wpas.request("SET p2p_no_group_iface 0")
436 hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
438 wpas.request("P2P_SET disallow_freq 2412")
439 wpas.request("SET p2p_pref_chan 81:2")
440 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
442 if res2['freq'] != "2417":
443 raise Exception("GO channel did not follow pref_chan configuration")
444 hwsim_utils.test_connectivity(wpas, hapd)
446 wpas.request("P2P_SET disallow_freq ")
447 wpas.request("SET p2p_pref_chan ")
449 def test_no_go_freq(dev, apdev):
450 """P2P channel selection: no GO freq"""
452 dev[0].request("SET p2p_no_go_freq 2412")
453 # dev[0] as client, channel 1 is ok
454 [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=1,
455 r_dev=dev[1], r_intent=14, r_freq=2412)
456 check_grpform_results(i_res, r_res)
457 if i_res['freq'] != "2412":
458 raise Exception("P2P group not formed on forced freq")
460 dev[1].remove_group(r_res['ifname'])
461 dev[0].wait_go_ending_session()
462 dev[0].flush_scan_cache()
465 # dev[0] as GO, channel 1 is not allowed
467 dev[0].request("SET p2p_no_go_freq 2412")
468 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14,
469 r_dev=dev[1], r_intent=1, r_freq=2412)
470 check_grpform_results(i_res2, r_res2)
475 raise Exception("GO set on a disallowed freq")
477 dev[0].request("SET p2p_no_go_freq ")
479 def test_go_neg_peers_force_diff_freq(dev, apdev):
480 """P2P channel selection when peers for different frequency"""
482 [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=14, i_freq=5180,
483 r_dev=dev[1], r_intent=0, r_freq=5200)
486 raise Exception("Unexpected group formation success")
488 def test_autogo_random_channel(dev, apdev):
489 """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
491 go_freqs = ["2412", "2437", "2462"]
492 for i in range(0, 20):
493 result = autogo(dev[0])
494 if result['freq'] not in go_freqs:
495 raise Exception("Unexpected frequency selected: " + result['freq'])
496 if result['freq'] not in freqs:
497 freqs.append(result['freq'])
500 dev[0].remove_group(result['ifname'])
502 raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
504 def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
505 """P2P channel selection: GO preferred channels are disallowed"""
507 dev[0].request("SET p2p_pref_chan 81:1,81:3,81:6,81:9,81:11")
508 dev[0].request("P2P_SET disallow_freq 2412,2422,2437,2452,2462")
509 for i in range(0, 5):
511 if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
512 raise Exception("GO channel is disallowed")
513 dev[0].remove_group(res['ifname'])
515 dev[0].request("P2P_SET disallow_freq ")
516 dev[0].request("SET p2p_pref_chan ")
518 def test_p2p_autogo_pref_chan_not_in_regulatory(dev, apdev):
519 """P2P channel selection: GO preferred channel not allowed in the regulatory rules"""
521 set_country("US", dev[0])
522 dev[0].request("SET p2p_pref_chan 124:149")
523 res = autogo(dev[0], persistent=True)
524 if res['freq'] != "5745":
525 raise Exception("Unexpected channel selected: " + res['freq'])
526 dev[0].remove_group(res['ifname'])
528 netw = dev[0].list_networks(p2p=True)
530 raise Exception("Unexpected number of network blocks: " + str(netw))
533 set_country("DE", dev[0])
534 res = autogo(dev[0], persistent=id)
535 if res['freq'] == "5745":
536 raise Exception("Unexpected channel selected(2): " + res['freq'])
537 dev[0].remove_group(res['ifname'])
539 dev[0].request("SET p2p_pref_chan ")
542 def run_autogo(dev, param):
543 if "OK" not in dev.global_request("P2P_GROUP_ADD " + param):
544 raise Exception("P2P_GROUP_ADD failed: " + param)
545 ev = dev.wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
547 raise Exception("GO start up timed out")
548 res = dev.group_form_result(ev)
552 def _test_autogo_ht_vht(dev):
553 res = run_autogo(dev[0], "ht40")
555 res = run_autogo(dev[0], "vht")
557 res = run_autogo(dev[0], "freq=2")
558 freq = int(res['freq'])
559 if freq < 2412 or freq > 2462:
560 raise Exception("Unexpected freq=2 channel: " + str(freq))
562 res = run_autogo(dev[0], "freq=5")
563 freq = int(res['freq'])
564 if freq < 5000 or freq >= 6000:
565 raise Exception("Unexpected freq=5 channel: " + str(freq))
567 res = run_autogo(dev[0], "freq=5 ht40 vht")
568 logger.info(str(res))
569 freq = int(res['freq'])
570 if freq < 5000 or freq >= 6000:
571 raise Exception("Unexpected freq=5 ht40 vht channel: " + str(freq))
573 def test_autogo_ht_vht(dev):
574 """P2P autonomous GO with HT/VHT parameters"""
576 set_country("US", dev[0])
577 _test_autogo_ht_vht(dev)
581 def test_p2p_listen_chan_optimize(dev, apdev):
582 """P2P listen channel optimization"""
583 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
584 wpas.interface_add("wlan5")
585 addr5 = wpas.p2p_dev_addr()
587 if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
588 raise Exception("Failed to set p2p_optimize_listen_chan")
590 if not dev[0].discover_peer(addr5):
591 raise Exception("Could not discover peer")
592 peer = dev[0].get_peer(addr5)
593 lfreq = peer['listen_freq']
595 dev[0].p2p_stop_find()
597 channel = "1" if lfreq != '2412' else "6"
598 freq = "2412" if lfreq != '2412' else "2437"
599 params = { "ssid": "test-open", "channel": channel }
600 hapd = hostapd.add_ap(apdev[0], params)
602 id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
605 if "OK" not in dev[0].request("P2P_FLUSH"):
606 raise Exception("P2P_FLUSH failed")
607 if not dev[0].discover_peer(addr5):
608 raise Exception("Could not discover peer")
609 peer = dev[0].get_peer(addr5)
610 lfreq2 = peer['listen_freq']
612 raise Exception("Listen channel did not change")
614 raise Exception("Listen channel not on AP's operating channel")
616 dev[0].p2p_stop_find()
618 wpas.request("DISCONNECT")
619 wpas.wait_disconnected()
621 # for larger coverage, cover case of current channel matching
622 wpas.select_network(id)
623 wpas.wait_connected()
624 wpas.request("DISCONNECT")
625 wpas.wait_disconnected()
627 lchannel = "1" if channel != "1" else "6"
628 lfreq3 = "2412" if channel != "1" else "2437"
629 if "OK" not in wpas.request("P2P_SET listen_channel " + lchannel):
630 raise Exception("Failed to set listen channel")
632 wpas.select_network(id)
633 wpas.wait_connected()
636 if "OK" not in dev[0].request("P2P_FLUSH"):
637 raise Exception("P2P_FLUSH failed")
638 if not dev[0].discover_peer(addr5):
639 raise Exception("Could not discover peer")
640 peer = dev[0].get_peer(addr5)
641 lfreq4 = peer['listen_freq']
643 raise Exception("Unexpected Listen channel after configuration")
645 dev[0].p2p_stop_find()
647 wpas.request("SET p2p_optimize_listen_chan 0")
649 def test_p2p_channel_5ghz_only(dev):
650 """P2P GO start with only 5 GHz band allowed"""
652 set_country("US", dev[0])
653 dev[0].request("P2P_SET disallow_freq 2400-2500")
655 freq = int(res['freq'])
657 raise Exception("Unexpected channel %d MHz" % freq)
658 dev[0].remove_group()
661 dev[0].request("P2P_SET disallow_freq ")
663 def test_p2p_channel_5ghz_165_169_us(dev):
664 """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
666 set_country("US", dev[0])
667 res = dev[0].p2p_start_go(freq=5825)
668 if res['freq'] != "5825":
669 raise Exception("Unexpected frequency: " + res['freq'])
670 dev[0].remove_group()
672 res = dev[0].global_request("P2P_GROUP_ADD freq=5845")
673 if "FAIL" not in res:
674 raise Exception("GO on channel 169 allowed unexpectedly")
678 def wait_go_down_up(dev):
679 ev = dev.wait_group_event(["AP-DISABLED"], timeout=5)
681 raise Exception("AP-DISABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
682 ev = dev.wait_group_event(["AP-ENABLED"], timeout=5)
684 raise Exception("AP-ENABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
686 def test_p2p_go_move_reg_change(dev, apdev):
687 """P2P GO move due to regulatory change"""
690 dev[0].global_request("P2P_SET disallow_freq 2400-5000")
692 freq1 = int(res['freq'])
694 raise Exception("Unexpected channel %d MHz" % freq1)
696 dev[0].global_request("P2P_SET disallow_freq ")
698 # GO move is not allowed while waiting for initial client connection
699 connect_cli(dev[0], dev[1], freq=freq1)
700 dev[1].remove_group()
702 freq = dev[0].get_group_status_field('freq')
704 raise Exception("Unexpected freq after initial client: " + freq)
705 dev[0].dump_monitor()
708 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
712 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
713 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
714 wait_go_down_up(dev[0])
716 freq2 = dev[0].get_group_status_field('freq')
718 raise Exception("Unexpected freq after group reform=" + freq2)
720 dev[0].remove_group()
722 dev[0].global_request("P2P_SET disallow_freq ")
725 def test_p2p_go_move_active(dev, apdev):
726 """P2P GO stays in freq although SCM is possible"""
727 with HWSimRadio(n_channels=2) as (radio, iface):
728 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
729 wpas.interface_add(iface)
731 if wpas.get_mcc() < 2:
732 raise Exception("New radio does not support MCC")
734 ndev = [ wpas, dev[1] ]
735 _test_p2p_go_move_active(ndev, apdev)
737 def _test_p2p_go_move_active(dev, apdev):
738 dev[0].request("SET p2p_no_group_iface 0")
740 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
741 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
743 dev[0].connect("ap-test", key_mgmt="NONE",
747 freq = int(res['freq'])
749 raise Exception("Unexpected channel %d MHz" % freq)
751 # GO move is not allowed while waiting for initial client connection
752 connect_cli(dev[0], dev[1], freq=freq)
753 dev[1].remove_group()
755 freq = dev[0].get_group_status_field('freq')
757 raise Exception("Unexpected freq after initial client: " + freq)
759 dev[0].dump_monitor()
760 dev[0].global_request("P2P_SET disallow_freq ")
762 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
766 raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
768 dev[0].remove_group()
770 dev[0].global_request("P2P_SET disallow_freq ")
772 def test_p2p_go_move_scm(dev, apdev):
773 """P2P GO move due to SCM operation preference"""
774 with HWSimRadio(n_channels=2) as (radio, iface):
775 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
776 wpas.interface_add(iface)
778 if wpas.get_mcc() < 2:
779 raise Exception("New radio does not support MCC")
781 ndev = [ wpas, dev[1] ]
782 _test_p2p_go_move_scm(ndev, apdev)
784 def _test_p2p_go_move_scm(dev, apdev):
785 dev[0].request("SET p2p_no_group_iface 0")
787 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
788 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
790 dev[0].connect("ap-test", key_mgmt="NONE",
793 dev[0].global_request("SET p2p_go_freq_change_policy 0")
795 freq = int(res['freq'])
797 raise Exception("Unexpected channel %d MHz" % freq)
799 # GO move is not allowed while waiting for initial client connection
800 connect_cli(dev[0], dev[1], freq=freq)
801 dev[1].remove_group()
803 freq = dev[0].get_group_status_field('freq')
805 raise Exception("Unexpected freq after initial client: " + freq)
807 dev[0].dump_monitor()
808 dev[0].global_request("P2P_SET disallow_freq ")
810 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
811 "AP-CSA-FINISHED"], timeout=3)
813 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
814 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
815 wait_go_down_up(dev[0])
817 freq = dev[0].get_group_status_field('freq')
819 raise Exception("Unexpected freq after group reform=" + freq)
821 dev[0].remove_group()
823 dev[0].global_request("P2P_SET disallow_freq ")
824 dev[0].global_request("SET p2p_go_freq_change_policy 2")
826 def test_p2p_go_move_scm_peer_supports(dev, apdev):
827 """P2P GO move due to SCM operation preference (peer supports)"""
828 with HWSimRadio(n_channels=2) as (radio, iface):
829 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
830 wpas.interface_add(iface)
832 if wpas.get_mcc() < 2:
833 raise Exception("New radio does not support MCC")
835 ndev = [ wpas, dev[1] ]
836 _test_p2p_go_move_scm_peer_supports(ndev, apdev)
838 def _test_p2p_go_move_scm_peer_supports(dev, apdev):
840 dev[0].global_request("SET p2p_go_freq_change_policy 1")
841 set_country("US", dev[0])
843 dev[0].request("SET p2p_no_group_iface 0")
844 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
845 r_dev=dev[1], r_intent=0,
847 check_grpform_results(i_res, r_res)
848 freq = int(i_res['freq'])
850 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
852 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
854 logger.info('Connecting client to to an AP on channel 11');
855 dev[0].connect("ap-test", key_mgmt="NONE",
858 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
859 "AP-CSA-FINISHED"], timeout=3)
861 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
862 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
863 wait_go_down_up(dev[0])
865 freq = dev[0].get_group_status_field('freq')
867 raise Exception("Unexpected freq after group reform=" + freq)
869 dev[0].remove_group()
871 dev[0].global_request("SET p2p_go_freq_change_policy 2")
874 def test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
875 """No P2P GO move due to SCM operation (peer does not supports)"""
876 with HWSimRadio(n_channels=2) as (radio, iface):
877 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
878 wpas.interface_add(iface)
880 if wpas.get_mcc() < 2:
881 raise Exception("New radio does not support MCC")
883 ndev = [ wpas, dev[1] ]
884 _test_p2p_go_move_scm_peer_does_not_support(ndev, apdev)
886 def _test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
888 dev[0].global_request("SET p2p_go_freq_change_policy 1")
889 set_country("US", dev[0])
891 dev[0].request("SET p2p_no_group_iface 0")
892 if "OK" not in dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES 2400-2500"):
893 raise Exception("Could not simulate driver event")
894 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
895 r_dev=dev[1], r_intent=0,
897 check_grpform_results(i_res, r_res)
898 freq = int(i_res['freq'])
900 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
902 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
904 logger.info('Connecting client to to an AP on channel 11');
905 dev[0].connect("ap-test", key_mgmt="NONE",
908 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
912 raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
914 dev[0].remove_group()
916 dev[0].global_request("SET p2p_go_freq_change_policy 2")
917 dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES")
920 def test_p2p_go_move_scm_multi(dev, apdev):
921 """P2P GO move due to SCM operation preference multiple times"""
922 with HWSimRadio(n_channels=2) as (radio, iface):
923 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
924 wpas.interface_add(iface)
926 if wpas.get_mcc() < 2:
927 raise Exception("New radio does not support MCC")
929 ndev = [ wpas, dev[1] ]
930 _test_p2p_go_move_scm_multi(ndev, apdev)
932 def _test_p2p_go_move_scm_multi(dev, apdev):
933 dev[0].request("SET p2p_no_group_iface 0")
935 dev[0].global_request("P2P_SET disallow_freq 2430-6000")
936 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-1',
938 dev[0].connect("ap-test-1", key_mgmt="NONE",
941 dev[0].global_request("SET p2p_go_freq_change_policy 0")
943 freq = int(res['freq'])
945 raise Exception("Unexpected channel %d MHz" % freq)
947 # GO move is not allowed while waiting for initial client connection
948 connect_cli(dev[0], dev[1], freq=freq)
949 dev[1].remove_group()
951 freq = dev[0].get_group_status_field('freq')
953 raise Exception("Unexpected freq after initial client: " + freq)
955 dev[0].dump_monitor()
956 dev[0].global_request("P2P_SET disallow_freq ")
958 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
959 "AP-CSA-FINISHED"], timeout=3)
961 raise Exception("P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
962 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
963 wait_go_down_up(dev[0])
965 freq = dev[0].get_group_status_field('freq')
967 raise Exception("Unexpected freq after group reform=" + freq)
969 hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-2',
971 dev[0].connect("ap-test-2", key_mgmt="NONE",
974 ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
975 "AP-CSA-FINISHED"], timeout=5)
977 raise Exception("(2) P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED not seen")
978 if "P2P-REMOVE-AND-REFORM-GROUP" in ev:
979 wait_go_down_up(dev[0])
981 freq = dev[0].get_group_status_field('freq')
983 raise Exception("(2) Unexpected freq after group reform=" + freq)
985 dev[0].remove_group()
987 dev[0].global_request("P2P_SET disallow_freq ")
988 dev[0].global_request("SET p2p_go_freq_change_policy 2")
990 def test_p2p_delay_go_csa(dev, apdev, params):
991 """P2P GO CSA delayed when inviting a P2P Device to an active P2P Group"""
992 with HWSimRadio(n_channels=2) as (radio, iface):
993 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
994 wpas.interface_add(iface)
996 wpas.global_request("SET p2p_no_group_iface 0")
998 if wpas.get_mcc() < 2:
999 raise Exception("New radio does not support MCC")
1001 addr0 = wpas.p2p_dev_addr()
1002 addr1 = dev[1].p2p_dev_addr()
1005 dev[1].p2p_listen();
1006 if not wpas.discover_peer(addr1, social=True):
1007 raise Exception("Peer " + addr1 + " not found")
1008 wpas.p2p_stop_find()
1010 hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
1013 wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
1015 wpas.global_request("SET p2p_go_freq_change_policy 0")
1018 logger.info("Start GO on channel 6")
1019 res = autogo(wpas, freq=2437)
1020 if res['freq'] != "2437":
1021 raise Exception("GO set on a freq=%s instead of 2437" % res['freq'])
1023 # Start find on dev[1] to run scans with dev[2] in parallel
1024 dev[1].p2p_find(social=True)
1026 # Use another client device to stop the initial client connection
1028 if not dev[2].discover_peer(addr0, social=True):
1029 raise Exception("Peer2 did not find the GO")
1030 dev[2].p2p_stop_find()
1031 pin = dev[2].wps_read_pin()
1032 wpas.p2p_go_authorize_client(pin)
1033 dev[2].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=2437")
1034 ev = dev[2].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1036 raise Exception("Peer2 did not get connected")
1038 if not dev[1].discover_peer(addr0, social=True):
1039 raise Exception("Peer did not find the GO")
1041 pin = dev[1].wps_read_pin()
1042 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
1043 dev[1].p2p_listen();
1045 # Force P2P GO channel switch on successful invitation signaling
1046 wpas.group_request("SET p2p_go_csa_on_inv 1")
1048 logger.info("Starting invitation")
1049 wpas.p2p_go_authorize_client(pin)
1050 wpas.global_request("P2P_INVITE group=" + wpas.group_ifname + " peer=" + addr1)
1051 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
1052 "P2P-GROUP-STARTED"], timeout=10)
1055 raise Exception("Timeout on invitation on peer")
1056 if "P2P-INVITATION-RECEIVED" in ev:
1057 raise Exception("Unexpected request to accept pre-authorized invitation")
1059 # A P2P GO move is not expected at this stage, as during the
1060 # invitation signaling, the P2P GO includes only its current
1061 # operating channel in the channel list, and as the invitation
1062 # response can only include channels that were also in the
1063 # invitation request channel list, the group common channels
1064 # includes only the current P2P GO operating channel.
1065 ev = wpas.wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
1066 "AP-CSA-FINISHED"], timeout=1)
1068 raise Exception("Unexpected + " + ev + " event")
1071 wpas.global_request("SET p2p_go_freq_change_policy 2")
1073 def test_p2p_channel_vht80p80(dev):
1074 """P2P group formation and VHT 80+80 MHz channel"""
1076 set_country("US", dev[0])
1077 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1080 i_max_oper_chwidth=160,
1081 i_ht40=True, i_vht=True,
1082 r_dev=dev[1], r_intent=0,
1084 check_grpform_results(i_res, r_res)
1085 freq = int(i_res['freq'])
1087 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
1088 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1089 if "FREQUENCY=5180" not in sig:
1090 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1091 if "WIDTH=80+80 MHz" not in sig:
1092 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1093 if "CENTER_FRQ1=5210" not in sig:
1094 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1095 if "CENTER_FRQ2=5775" not in sig:
1096 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1097 remove_group(dev[0], dev[1])
1100 dev[1].flush_scan_cache()
1102 def test_p2p_channel_vht80p80_autogo(dev):
1103 """P2P autonomous GO and VHT 80+80 MHz channel"""
1104 addr0 = dev[0].p2p_dev_addr()
1107 set_country("US", dev[0])
1108 if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 freq2=5775"):
1109 raise Exception("Could not start GO")
1110 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
1112 raise Exception("GO start up timed out")
1113 dev[0].group_form_result(ev)
1115 pin = dev[1].wps_read_pin()
1116 dev[0].p2p_go_authorize_client(pin)
1118 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1119 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1121 raise Exception("Peer did not get connected")
1123 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1124 if "FREQUENCY=5180" not in sig:
1125 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1126 if "WIDTH=80+80 MHz" not in sig:
1127 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1128 if "CENTER_FRQ1=5210" not in sig:
1129 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1130 if "CENTER_FRQ2=5775" not in sig:
1131 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1132 remove_group(dev[0], dev[1])
1135 dev[1].flush_scan_cache()
1137 def test_p2p_channel_vht80_autogo(dev):
1138 """P2P autonomous GO and VHT 80 MHz channel"""
1139 addr0 = dev[0].p2p_dev_addr()
1142 set_country("US", dev[0])
1143 if "OK" not in dev[0].global_request("P2P_GROUP_ADD vht freq=5180 max_oper_chwidth=80"):
1144 raise Exception("Could not start GO")
1145 ev = dev[0].wait_global_event(["P2P-GROUP-STARTED"], timeout=5)
1147 raise Exception("GO start up timed out")
1148 dev[0].group_form_result(ev)
1150 pin = dev[1].wps_read_pin()
1151 dev[0].p2p_go_authorize_client(pin)
1153 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1154 ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1156 raise Exception("Peer did not get connected")
1158 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1159 if "FREQUENCY=5180" not in sig:
1160 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1161 if "WIDTH=80 MHz" not in sig:
1162 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1163 remove_group(dev[0], dev[1])
1166 dev[1].flush_scan_cache()
1168 def test_p2p_channel_vht80p80_persistent(dev):
1169 """P2P persistent group re-invocation and VHT 80+80 MHz channel"""
1170 addr0 = dev[0].p2p_dev_addr()
1171 form(dev[0], dev[1])
1174 set_country("US", dev[0])
1175 invite(dev[0], dev[1], extra="vht freq=5745 freq2=5210")
1176 [go_res, cli_res] = check_result(dev[0], dev[1])
1178 sig = dev[1].group_request("SIGNAL_POLL").splitlines()
1179 if "FREQUENCY=5745" not in sig:
1180 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
1181 if "WIDTH=80+80 MHz" not in sig:
1182 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
1183 if "CENTER_FRQ1=5775" not in sig:
1184 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
1185 if "CENTER_FRQ2=5210" not in sig:
1186 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
1187 remove_group(dev[0], dev[1])
1190 dev[1].flush_scan_cache()