tests: Pass full apdev to add_ap() function (1)
[mech_eap.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 import logging
8 logger = logging.getLogger()
9 import os
10 import subprocess
11 import time
12
13 import hostapd
14 import hwsim_utils
15 from tshark import run_tshark
16 from wpasupplicant import WpaSupplicant
17 from hwsim import HWSimRadio
18 from p2p_utils import *
19
20 def set_country(country, dev=None):
21     subprocess.call(['iw', 'reg', 'set', country])
22     time.sleep(0.1)
23     if dev:
24         for i in range(10):
25             ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=15)
26             if ev is None:
27                 raise Exception("No regdom change event seen")
28             if "type=COUNTRY alpha2=" + country in ev:
29                 return
30         raise Exception("No matching regdom event seen for set_country(%s)" % country)
31
32 def test_p2p_channel_5ghz(dev):
33     """P2P group formation with 5 GHz preference"""
34     try:
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,
38                                                test_data=False)
39         check_grpform_results(i_res, r_res)
40         freq = int(i_res['freq'])
41         if freq < 5000:
42             raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
43         remove_group(dev[0], dev[1])
44     finally:
45         set_country("00")
46         dev[1].flush_scan_cache()
47
48 def test_p2p_channel_5ghz_no_vht(dev):
49     """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
50     try:
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,
55                                                test_data=False)
56         check_grpform_results(i_res, r_res)
57         freq = int(i_res['freq'])
58         if freq < 5000:
59             raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
60         remove_group(dev[0], dev[1])
61     finally:
62         set_country("00")
63         dev[0].request("P2P_SET disallow_freq ")
64         dev[1].flush_scan_cache()
65
66 def test_p2p_channel_random_social(dev):
67     """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
68     try:
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,
74                                                test_data=False)
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])
80     finally:
81         set_country("00")
82         dev[0].request("P2P_SET disallow_freq ")
83         dev[1].flush_scan_cache()
84
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"""
87     try:
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,
93                                                test_data=False)
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])
99     finally:
100         set_country("00")
101         dev[0].request("P2P_SET disallow_freq ")
102         dev[1].flush_scan_cache()
103
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"""
106     try:
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,
111                                                test_data=False)
112         check_grpform_results(i_res, r_res)
113         freq = int(i_res['freq'])
114         if freq < 5000:
115             raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
116         remove_group(dev[0], dev[1])
117
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,
124                                                test_data=False)
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])
130
131         out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
132                          "wifi_p2p.public_action.subtype == 0")
133         if out is not None:
134             last = None
135             for l in out.splitlines():
136                 if "Operating Channel:" not in l:
137                     continue
138                 last = l
139             if last is None:
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())
143     finally:
144         set_country("00")
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()
149
150 def test_p2p_channel_avoid(dev):
151     """P2P and avoid frequencies driver event"""
152     try:
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)
157         if ev is None:
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,
161                                                test_data=False)
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)
166
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)
170         if ev is None:
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)
174         if ev is not None:
175             raise Exception("Unexpected + " + ev + " event")
176
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)
180         if ev is None:
181             raise Exception("No CTRL-EVENT-AVOID-FREQ event")
182         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
183                                       "AP-CSA-FINISHED"],
184                                      timeout=10)
185         if ev is None:
186             raise Exception("No P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED event")
187     finally:
188         set_country("00")
189         dev[0].request("DRIVER_EVENT AVOID_FREQUENCIES")
190         dev[1].flush_scan_cache()
191
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")
196
197     dev[0].request("SET p2p_no_group_iface 0")
198
199     channels = { 3 : "2422", 5 : "2432", 9 : "2452" }
200     for key in channels:
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'])
210
211 def test_go_neg_with_bss_connected(dev, apdev):
212     """P2P channel selection: GO negotiation when station interface is connected"""
213
214     dev[0].flush_scan_cache()
215     dev[1].flush_scan_cache()
216     dev[0].request("SET p2p_no_group_iface 0")
217
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")
221     #dev[0] as GO
222     [i_res, r_res] = go_neg_pbc(i_dev=dev[0], i_intent=10, r_dev=dev[1],
223                                 r_intent=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()
232
233     if dev[0].get_mcc() > 1:
234         logger.info("Skip as-client case due to MCC being enabled")
235         return;
236
237     #dev[0] as client
238     [i_res2, r_res2] = go_neg_pbc(i_dev=dev[0], i_intent=1, r_dev=dev[1],
239                                   r_intent=10)
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")
249     hapd.disable()
250     dev[0].flush_scan_cache()
251     dev[1].flush_scan_cache()
252
253 def test_autogo_with_bss_on_disallowed_chan(dev, apdev):
254     """P2P channel selection: Autonomous GO with BSS on a disallowed channel"""
255
256     with HWSimRadio(n_channels=2) as (radio, iface):
257         wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
258         wpas.interface_add(iface)
259
260         wpas.request("SET p2p_no_group_iface 0")
261
262         if wpas.get_mcc() < 2:
263            raise Exception("New radio does not support MCC")
264
265         try:
266             hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
267                                               "channel": '1' })
268             wpas.request("P2P_SET disallow_freq 2412")
269             wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
270             res = autogo(wpas)
271             if res['freq'] == "2412":
272                raise Exception("GO set on a disallowed channel")
273             hwsim_utils.test_connectivity(wpas, hapd)
274         finally:
275             wpas.request("P2P_SET disallow_freq ")
276
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"""
279
280     with HWSimRadio(n_channels=2) as (radio, iface):
281         wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
282         wpas.interface_add(iface)
283
284         wpas.request("SET p2p_no_group_iface 0")
285
286         if wpas.get_mcc() < 2:
287            raise Exception("New radio does not support MCC")
288
289         try:
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")
296
297             #wpas as GO
298             [i_res, r_res] = go_neg_pbc(i_dev=wpas, i_intent=10, r_dev=dev[1],
299                                         r_intent=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()
309
310             wpas.dump_monitor()
311             dev[1].dump_monitor()
312
313             #wpas as client
314             [i_res2, r_res2] = go_neg_pbc(i_dev=wpas, i_intent=1, r_dev=dev[1],
315                                           r_intent=10)
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)
325             if ev is None:
326                 raise Exception("Group removal not indicated")
327             wpas.request("DISCONNECT")
328             hapd.disable()
329         finally:
330             wpas.request("P2P_SET disallow_freq ")
331
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)
337
338         if wpas.get_mcc() < 2:
339            raise Exception("New radio does not support MCC")
340
341         wpas.request("SET p2p_no_group_iface 0")
342
343         hapd = hostapd.add_ap(apdev[0],
344                               {"ssid" : 'ap-test', "channel" : '1'})
345         wpas.connect("ap-test", key_mgmt = "NONE", scan_freq = "2412")
346         wpas.dump_monitor()
347         channels = { 2 : 2417, 5 : 2432, 9 : 2452 }
348         for key in channels:
349             res_go = autogo(wpas, channels[key])
350             wpas.dump_monitor()
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'])
355             wpas.dump_monitor()
356
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)
362
363         if wpas.get_mcc() < 2:
364            raise Exception("New radio does not support MCC")
365
366         # Clear possible PBC session overlap from previous test case
367         dev[1].flush_scan_cache()
368
369         wpas.request("SET p2p_no_group_iface 0")
370
371         hapd = hostapd.add_ap(apdev[0],
372                               { "country_code": 'US',
373                                 "ssid": 'bss-5ghz', "hw_mode": 'a',
374                                 "channel": '40' })
375         wpas.connect("bss-5ghz", key_mgmt="NONE", scan_freq="5200")
376
377         # GO and peer force the same freq, different than BSS freq,
378         # wpas to become GO
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()
390
391         # GO and peer force the same freq, different than BSS freq, wpas to
392         # become client
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)
401
402         wpas.request("DISCONNECT")
403         hapd.request("DISABLE")
404         subprocess.call(['iw', 'reg', 'set', '00'])
405         wpas.flush_scan_cache()
406
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"""
409
410     dev[0].request("SET p2p_no_group_iface 0")
411
412     try:
413         hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
414                                           "channel": '1' })
415         dev[0].request("SET p2p_pref_chan 81:2")
416         dev[0].connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
417         res = autogo(dev[0])
418         if res['freq'] != "2412":
419            raise Exception("GO channel did not follow BSS")
420         hwsim_utils.test_connectivity(dev[0], hapd)
421     finally:
422         dev[0].request("SET p2p_pref_chan ")
423
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)
429
430         if wpas.get_mcc() < 2:
431            raise Exception("New radio does not support MCC")
432
433         wpas.request("SET p2p_no_group_iface 0")
434
435         try:
436             hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
437                                               "channel": '1' })
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")
441             res2 = autogo(wpas)
442             if res2['freq'] != "2417":
443                raise Exception("GO channel did not follow pref_chan configuration")
444             hwsim_utils.test_connectivity(wpas, hapd)
445         finally:
446             wpas.request("P2P_SET disallow_freq ")
447             wpas.request("SET p2p_pref_chan ")
448
449 def test_no_go_freq(dev, apdev):
450     """P2P channel selection: no GO freq"""
451     try:
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")
459
460        dev[1].remove_group(r_res['ifname'])
461        dev[0].wait_go_ending_session()
462        dev[0].flush_scan_cache()
463
464        fail = False
465        # dev[0] as GO, channel 1 is not allowed
466        try:
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)
471           fail = True
472        except:
473            pass
474        if fail:
475            raise Exception("GO set on a disallowed freq")
476     finally:
477        dev[0].request("SET p2p_no_go_freq ")
478
479 def test_go_neg_peers_force_diff_freq(dev, apdev):
480     """P2P channel selection when peers for different frequency"""
481     try:
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)
484     except Exception, e:
485         return
486     raise Exception("Unexpected group formation success")
487
488 def test_autogo_random_channel(dev, apdev):
489     """P2P channel selection: GO instantiated on random channel 1, 6, 11"""
490     freqs = []
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'])
498         if len(freqs) == 3:
499             break
500         dev[0].remove_group(result['ifname'])
501     if i == 20:
502        raise Exception("GO created 20 times and not all social channels were selected. freqs not selected: " + str(list(set(go_freqs) - set(freqs))))
503
504 def test_p2p_autogo_pref_chan_disallowed(dev, apdev):
505     """P2P channel selection: GO preferred channels are disallowed"""
506     try:
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):
510            res = autogo(dev[0])
511            if res['freq'] in [ "2412", "2422", "2437", "2452", "2462" ]:
512                raise Exception("GO channel is disallowed")
513            dev[0].remove_group(res['ifname'])
514     finally:
515        dev[0].request("P2P_SET disallow_freq ")
516        dev[0].request("SET p2p_pref_chan ")
517
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"""
520     try:
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'])
527
528         netw = dev[0].list_networks(p2p=True)
529         if len(netw) != 1:
530             raise Exception("Unexpected number of network blocks: " + str(netw))
531         id = netw[0]['id']
532
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'])
538     finally:
539         dev[0].request("SET p2p_pref_chan ")
540         set_country("00")
541
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)
546     if ev is None:
547         raise Exception("GO start up timed out")
548     res = dev.group_form_result(ev)
549     dev.remove_group()
550     return res
551
552 def _test_autogo_ht_vht(dev):
553     res = run_autogo(dev[0], "ht40")
554
555     res = run_autogo(dev[0], "vht")
556
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))
561
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))
566
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))
572
573 def test_autogo_ht_vht(dev):
574     """P2P autonomous GO with HT/VHT parameters"""
575     try:
576         set_country("US", dev[0])
577         _test_autogo_ht_vht(dev)
578     finally:
579         set_country("00")
580
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()
586     try:
587         if "OK" not in wpas.request("SET p2p_optimize_listen_chan 1"):
588             raise Exception("Failed to set p2p_optimize_listen_chan")
589         wpas.p2p_listen()
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']
594         wpas.p2p_stop_find()
595         dev[0].p2p_stop_find()
596
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)
601
602         id = wpas.connect("test-open", key_mgmt="NONE", scan_freq=freq)
603         wpas.p2p_listen()
604
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']
611         if lfreq == lfreq2:
612             raise Exception("Listen channel did not change")
613         if lfreq2 != freq:
614             raise Exception("Listen channel not on AP's operating channel")
615         wpas.p2p_stop_find()
616         dev[0].p2p_stop_find()
617
618         wpas.request("DISCONNECT")
619         wpas.wait_disconnected()
620
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()
626
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")
631
632         wpas.select_network(id)
633         wpas.wait_connected()
634         wpas.p2p_listen()
635
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']
642         if lfreq4 != lfreq3:
643             raise Exception("Unexpected Listen channel after configuration")
644         wpas.p2p_stop_find()
645         dev[0].p2p_stop_find()
646     finally:
647         wpas.request("SET p2p_optimize_listen_chan 0")
648
649 def test_p2p_channel_5ghz_only(dev):
650     """P2P GO start with only 5 GHz band allowed"""
651     try:
652         set_country("US", dev[0])
653         dev[0].request("P2P_SET disallow_freq 2400-2500")
654         res = autogo(dev[0])
655         freq = int(res['freq'])
656         if freq < 5000:
657             raise Exception("Unexpected channel %d MHz" % freq)
658         dev[0].remove_group()
659     finally:
660         set_country("00")
661         dev[0].request("P2P_SET disallow_freq ")
662
663 def test_p2p_channel_5ghz_165_169_us(dev):
664     """P2P GO and 5 GHz channels 165 (allowed) and 169 (disallowed) in US"""
665     try:
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()
671
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")
675     finally:
676         set_country("00")
677
678 def wait_go_down_up(dev):
679     ev = dev.wait_group_event(["AP-DISABLED"], timeout=5)
680     if ev is None:
681         raise Exception("AP-DISABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
682     ev = dev.wait_group_event(["AP-ENABLED"], timeout=5)
683     if ev is None:
684         raise Exception("AP-ENABLED not seen after P2P-REMOVE-AND-REFORM-GROUP")
685
686 def test_p2p_go_move_reg_change(dev, apdev):
687     """P2P GO move due to regulatory change"""
688     try:
689         set_country("US")
690         dev[0].global_request("P2P_SET disallow_freq 2400-5000")
691         res = autogo(dev[0])
692         freq1 = int(res['freq'])
693         if freq1 < 5000:
694             raise Exception("Unexpected channel %d MHz" % freq1)
695
696         dev[0].global_request("P2P_SET disallow_freq ")
697
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()
701
702         freq = dev[0].get_group_status_field('freq')
703         if int(freq) < 5000:
704             raise Exception("Unexpected freq after initial client: " + freq)
705         dev[0].dump_monitor()
706
707         set_country("00")
708         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
709                                       "AP-CSA-FINISHED"],
710                                      timeout=10)
711         if ev is None:
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])
715
716         freq2 = dev[0].get_group_status_field('freq')
717         if freq1 == freq2:
718             raise Exception("Unexpected freq after group reform=" + freq2)
719
720         dev[0].remove_group()
721     finally:
722         dev[0].global_request("P2P_SET disallow_freq ")
723         set_country("00")
724
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)
730
731         if wpas.get_mcc() < 2:
732             raise Exception("New radio does not support MCC")
733
734         ndev = [ wpas, dev[1] ]
735         _test_p2p_go_move_active(ndev, apdev)
736
737 def _test_p2p_go_move_active(dev, apdev):
738     dev[0].request("SET p2p_no_group_iface 0")
739     try:
740         dev[0].global_request("P2P_SET disallow_freq 2430-6000")
741         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
742                                           "channel" : '11' })
743         dev[0].connect("ap-test", key_mgmt="NONE",
744                        scan_freq="2462")
745
746         res = autogo(dev[0])
747         freq = int(res['freq'])
748         if freq > 2430:
749             raise Exception("Unexpected channel %d MHz" % freq)
750
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()
754
755         freq = dev[0].get_group_status_field('freq')
756         if int(freq) > 2430:
757             raise Exception("Unexpected freq after initial client: " + freq)
758
759         dev[0].dump_monitor()
760         dev[0].global_request("P2P_SET disallow_freq ")
761
762         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
763                                       "AP-CSA-FINISHED"],
764                                      timeout=10)
765         if ev is not None:
766             raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
767
768         dev[0].remove_group()
769     finally:
770         dev[0].global_request("P2P_SET disallow_freq ")
771
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)
777
778         if wpas.get_mcc() < 2:
779             raise Exception("New radio does not support MCC")
780
781         ndev = [ wpas, dev[1] ]
782         _test_p2p_go_move_scm(ndev, apdev)
783
784 def _test_p2p_go_move_scm(dev, apdev):
785     dev[0].request("SET p2p_no_group_iface 0")
786     try:
787         dev[0].global_request("P2P_SET disallow_freq 2430-6000")
788         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
789                                           "channel" : '11' })
790         dev[0].connect("ap-test", key_mgmt="NONE",
791                        scan_freq="2462")
792
793         dev[0].global_request("SET p2p_go_freq_change_policy 0")
794         res = autogo(dev[0])
795         freq = int(res['freq'])
796         if freq > 2430:
797             raise Exception("Unexpected channel %d MHz" % freq)
798
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()
802
803         freq = dev[0].get_group_status_field('freq')
804         if int(freq) > 2430:
805             raise Exception("Unexpected freq after initial client: " + freq)
806
807         dev[0].dump_monitor()
808         dev[0].global_request("P2P_SET disallow_freq ")
809
810         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
811                                       "AP-CSA-FINISHED"], timeout=3)
812         if ev is None:
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])
816
817         freq = dev[0].get_group_status_field('freq')
818         if freq != '2462':
819             raise Exception("Unexpected freq after group reform=" + freq)
820
821         dev[0].remove_group()
822     finally:
823         dev[0].global_request("P2P_SET disallow_freq ")
824         dev[0].global_request("SET p2p_go_freq_change_policy 2")
825
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)
831
832         if wpas.get_mcc() < 2:
833             raise Exception("New radio does not support MCC")
834
835         ndev = [ wpas, dev[1] ]
836         _test_p2p_go_move_scm_peer_supports(ndev, apdev)
837
838 def _test_p2p_go_move_scm_peer_supports(dev, apdev):
839     try:
840         dev[0].global_request("SET p2p_go_freq_change_policy 1")
841         set_country("US", dev[0])
842
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,
846                                                test_data=False)
847         check_grpform_results(i_res, r_res)
848         freq = int(i_res['freq'])
849         if freq < 5000:
850             raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
851
852         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
853                                           "channel" : '11' })
854         logger.info('Connecting client to to an AP on channel 11');
855         dev[0].connect("ap-test", key_mgmt="NONE",
856                        scan_freq="2462")
857
858         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
859                                       "AP-CSA-FINISHED"], timeout=3)
860         if ev is None:
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])
864
865         freq = dev[0].get_group_status_field('freq')
866         if freq != '2462':
867             raise Exception("Unexpected freq after group reform=" + freq)
868
869         dev[0].remove_group()
870     finally:
871         dev[0].global_request("SET p2p_go_freq_change_policy 2")
872         set_country("00")
873
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)
879
880         if wpas.get_mcc() < 2:
881             raise Exception("New radio does not support MCC")
882
883         ndev = [ wpas, dev[1] ]
884         _test_p2p_go_move_scm_peer_does_not_support(ndev, apdev)
885
886 def _test_p2p_go_move_scm_peer_does_not_support(dev, apdev):
887     try:
888         dev[0].global_request("SET p2p_go_freq_change_policy 1")
889         set_country("US", dev[0])
890
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,
896                                                test_data=False)
897         check_grpform_results(i_res, r_res)
898         freq = int(i_res['freq'])
899         if freq < 5000:
900             raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
901
902         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test',
903                                           "channel" : '11' })
904         logger.info('Connecting client to to an AP on channel 11');
905         dev[0].connect("ap-test", key_mgmt="NONE",
906                        scan_freq="2462")
907
908         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
909                                       "AP-CSA-FINISHED"],
910                                      timeout=10)
911         if ev is not None:
912             raise Exception("Unexpected P2P-REMOVE-AND-REFORM-GROUP or AP-CSA-FINISHED seen")
913
914         dev[0].remove_group()
915     finally:
916         dev[0].global_request("SET p2p_go_freq_change_policy 2")
917         dev[1].request("DRIVER_EVENT AVOID_FREQUENCIES")
918         set_country("00")
919
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)
925
926         if wpas.get_mcc() < 2:
927             raise Exception("New radio does not support MCC")
928
929         ndev = [ wpas, dev[1] ]
930         _test_p2p_go_move_scm_multi(ndev, apdev)
931
932 def _test_p2p_go_move_scm_multi(dev, apdev):
933     dev[0].request("SET p2p_no_group_iface 0")
934     try:
935         dev[0].global_request("P2P_SET disallow_freq 2430-6000")
936         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-1',
937                                           "channel" : '11' })
938         dev[0].connect("ap-test-1", key_mgmt="NONE",
939                        scan_freq="2462")
940
941         dev[0].global_request("SET p2p_go_freq_change_policy 0")
942         res = autogo(dev[0])
943         freq = int(res['freq'])
944         if freq > 2430:
945             raise Exception("Unexpected channel %d MHz" % freq)
946
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()
950
951         freq = dev[0].get_group_status_field('freq')
952         if int(freq) > 2430:
953             raise Exception("Unexpected freq after initial client: " + freq)
954
955         dev[0].dump_monitor()
956         dev[0].global_request("P2P_SET disallow_freq ")
957
958         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
959                                       "AP-CSA-FINISHED"], timeout=3)
960         if ev is None:
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])
964
965         freq = dev[0].get_group_status_field('freq')
966         if freq != '2462':
967             raise Exception("Unexpected freq after group reform=" + freq)
968
969         hapd = hostapd.add_ap(apdev[0], { "ssid" : 'ap-test-2',
970                                           "channel" : '6' })
971         dev[0].connect("ap-test-2", key_mgmt="NONE",
972                        scan_freq="2437")
973
974         ev = dev[0].wait_group_event(["P2P-REMOVE-AND-REFORM-GROUP",
975                                       "AP-CSA-FINISHED"], timeout=5)
976         if ev is None:
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])
980
981         freq = dev[0].get_group_status_field('freq')
982         if freq != '2437':
983             raise Exception("(2) Unexpected freq after group reform=" + freq)
984
985         dev[0].remove_group()
986     finally:
987         dev[0].global_request("P2P_SET disallow_freq ")
988         dev[0].global_request("SET p2p_go_freq_change_policy 2")
989
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)
995
996         wpas.global_request("SET p2p_no_group_iface 0")
997
998         if wpas.get_mcc() < 2:
999            raise Exception("New radio does not support MCC")
1000
1001         addr0 = wpas.p2p_dev_addr()
1002         addr1 = dev[1].p2p_dev_addr()
1003
1004         try:
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()
1009
1010             hapd = hostapd.add_ap(apdev[0], { "ssid": 'bss-2.4ghz',
1011                                               "channel": '1' })
1012
1013             wpas.connect("bss-2.4ghz", key_mgmt="NONE", scan_freq="2412")
1014
1015             wpas.global_request("SET p2p_go_freq_change_policy 0")
1016             wpas.dump_monitor()
1017
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'])
1022
1023             # Start find on dev[1] to run scans with dev[2] in parallel
1024             dev[1].p2p_find(social=True)
1025
1026             # Use another client device to stop the initial client connection
1027             # timeout on the GO
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)
1035             if ev is None:
1036                 raise Exception("Peer2 did not get connected")
1037
1038             if not dev[1].discover_peer(addr0, social=True):
1039                 raise Exception("Peer did not find the GO")
1040
1041             pin = dev[1].wps_read_pin()
1042             dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
1043             dev[1].p2p_listen();
1044
1045             # Force P2P GO channel switch on successful invitation signaling
1046             wpas.group_request("SET p2p_go_csa_on_inv 1")
1047
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)
1053
1054             if ev is None:
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")
1058
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)
1067             if ev is not None:
1068                 raise Exception("Unexpected + " + ev + " event")
1069
1070         finally:
1071             wpas.global_request("SET p2p_go_freq_change_policy 2")
1072
1073 def test_p2p_channel_vht80p80(dev):
1074     """P2P group formation and VHT 80+80 MHz channel"""
1075     try:
1076         set_country("US", dev[0])
1077         [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
1078                                                i_freq=5180,
1079                                                i_freq2=5775,
1080                                                i_max_oper_chwidth=160,
1081                                                i_ht40=True, i_vht=True,
1082                                                r_dev=dev[1], r_intent=0,
1083                                                test_data=False)
1084         check_grpform_results(i_res, r_res)
1085         freq = int(i_res['freq'])
1086         if freq < 5000:
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])
1098     finally:
1099         set_country("00")
1100         dev[1].flush_scan_cache()
1101
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()
1105
1106     try:
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)
1111         if ev is None:
1112             raise Exception("GO start up timed out")
1113         dev[0].group_form_result(ev)
1114
1115         pin = dev[1].wps_read_pin()
1116         dev[0].p2p_go_authorize_client(pin)
1117
1118         dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1119         ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1120         if ev is None:
1121             raise Exception("Peer did not get connected")
1122
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])
1133     finally:
1134         set_country("00")
1135         dev[1].flush_scan_cache()
1136
1137 def test_p2p_channel_vht80_autogo(dev):
1138     """P2P autonomous GO and VHT 80 MHz channel"""
1139     addr0 = dev[0].p2p_dev_addr()
1140
1141     try:
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)
1146         if ev is None:
1147             raise Exception("GO start up timed out")
1148         dev[0].group_form_result(ev)
1149
1150         pin = dev[1].wps_read_pin()
1151         dev[0].p2p_go_authorize_client(pin)
1152
1153         dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join freq=5180")
1154         ev = dev[1].wait_global_event(["P2P-GROUP-STARTED"], timeout=10)
1155         if ev is None:
1156             raise Exception("Peer did not get connected")
1157
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])
1164     finally:
1165         set_country("00")
1166         dev[1].flush_scan_cache()
1167
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])
1172
1173     try:
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])
1177
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])
1188     finally:
1189         set_country("00")
1190         dev[1].flush_scan_cache()