Updated to hostap_2_6
[mech_eap.git] / libeap / tests / hwsim / test_ap_vht.py
1 # Test cases for VHT operations with hostapd
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
3 # Copyright (c) 2013, Intel Corporation
4 #
5 # This software may be distributed under the terms of the BSD license.
6 # See README for more details.
7
8 import logging
9 logger = logging.getLogger()
10 import os
11 import subprocess, time
12
13 import hwsim_utils
14 import hostapd
15 from utils import HwsimSkip
16 from test_dfs import wait_dfs_event
17 from test_ap_csa import csa_supported
18 from test_ap_ht import clear_scan_cache
19
20 def vht_supported():
21     cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
22     reg = cmd.stdout.read()
23     if "@ 80)" in reg or "@ 160)" in reg:
24         return True
25     return False
26
27 def test_ap_vht80(dev, apdev):
28     """VHT with 80 MHz channel width"""
29     try:
30         hapd = None
31         params = { "ssid": "vht",
32                    "country_code": "FI",
33                    "hw_mode": "a",
34                    "channel": "36",
35                    "ht_capab": "[HT40+]",
36                    "ieee80211n": "1",
37                    "ieee80211ac": "1",
38                    "vht_oper_chwidth": "1",
39                    "vht_oper_centr_freq_seg0_idx": "42" }
40         hapd = hostapd.add_ap(apdev[0], params)
41         bssid = apdev[0]['bssid']
42
43         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
44         hwsim_utils.test_connectivity(dev[0], hapd)
45         sig = dev[0].request("SIGNAL_POLL").splitlines()
46         if "FREQUENCY=5180" not in sig:
47             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
48         if "WIDTH=80 MHz" not in sig:
49             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
50         est = dev[0].get_bss(bssid)['est_throughput']
51         if est != "390001":
52             raise Exception("Unexpected BSS est_throughput: " + est)
53         status = hapd.get_status()
54         logger.info("hostapd STATUS: " + str(status))
55         if status["ieee80211n"] != "1":
56             raise Exception("Unexpected STATUS ieee80211n value")
57         if status["ieee80211ac"] != "1":
58             raise Exception("Unexpected STATUS ieee80211ac value")
59         if status["secondary_channel"] != "1":
60             raise Exception("Unexpected STATUS secondary_channel value")
61         if status["vht_oper_chwidth"] != "1":
62             raise Exception("Unexpected STATUS vht_oper_chwidth value")
63         if status["vht_oper_centr_freq_seg0_idx"] != "42":
64             raise Exception("Unexpected STATUS vht_oper_centr_freq_seg0_idx value")
65     except Exception, e:
66         if isinstance(e, Exception) and str(e) == "AP startup failed":
67             if not vht_supported():
68                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
69         raise
70     finally:
71         dev[0].request("DISCONNECT")
72         if hapd:
73             hapd.request("DISABLE")
74         subprocess.call(['iw', 'reg', 'set', '00'])
75         dev[0].flush_scan_cache()
76
77 def vht80_test(apdev, dev, channel, ht_capab):
78     clear_scan_cache(apdev)
79     try:
80         hapd = None
81         params = { "ssid": "vht",
82                    "country_code": "FI",
83                    "hw_mode": "a",
84                    "channel": str(channel),
85                    "ht_capab": ht_capab,
86                    "ieee80211n": "1",
87                    "ieee80211ac": "1",
88                    "vht_oper_chwidth": "1",
89                    "vht_oper_centr_freq_seg0_idx": "42" }
90         hapd = hostapd.add_ap(apdev, params)
91         bssid = apdev['bssid']
92
93         dev.connect("vht", key_mgmt="NONE", scan_freq=str(5000 + 5 * channel))
94         hwsim_utils.test_connectivity(dev, hapd)
95     except Exception, e:
96         if isinstance(e, Exception) and str(e) == "AP startup failed":
97             if not vht_supported():
98                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
99         raise
100     finally:
101         dev.request("DISCONNECT")
102         if hapd:
103             hapd.request("DISABLE")
104         subprocess.call(['iw', 'reg', 'set', '00'])
105         dev.flush_scan_cache()
106
107 def test_ap_vht80b(dev, apdev):
108     """VHT with 80 MHz channel width (HT40- channel 40)"""
109     vht80_test(apdev[0], dev[0], 40, "[HT40-]")
110
111 def test_ap_vht80c(dev, apdev):
112     """VHT with 80 MHz channel width (HT40+ channel 44)"""
113     vht80_test(apdev[0], dev[0], 44, "[HT40+]")
114
115 def test_ap_vht80d(dev, apdev):
116     """VHT with 80 MHz channel width (HT40- channel 48)"""
117     vht80_test(apdev[0], dev[0], 48, "[HT40-]")
118
119 def test_ap_vht80_params(dev, apdev):
120     """VHT with 80 MHz channel width and number of optional features enabled"""
121     try:
122         hapd = None
123         params = { "ssid": "vht",
124                    "country_code": "FI",
125                    "hw_mode": "a",
126                    "channel": "36",
127                    "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
128                    "ieee80211n": "1",
129                    "ieee80211ac": "1",
130                    "vht_oper_chwidth": "1",
131                    "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
132                    "vht_oper_centr_freq_seg0_idx": "42",
133                    "require_vht": "1" }
134         hapd = hostapd.add_ap(apdev[0], params)
135
136         dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
137                        disable_vht="1", wait_connect=False)
138         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
139         ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
140         if ev is None:
141             raise Exception("Association rejection timed out")
142         if "status_code=104" not in ev:
143             raise Exception("Unexpected rejection status code")
144         dev[1].request("DISCONNECT")
145         hwsim_utils.test_connectivity(dev[0], hapd)
146     except Exception, e:
147         if isinstance(e, Exception) and str(e) == "AP startup failed":
148             if not vht_supported():
149                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
150         raise
151     finally:
152         dev[0].request("DISCONNECT")
153         dev[1].request("DISCONNECT")
154         if hapd:
155             hapd.request("DISABLE")
156         subprocess.call(['iw', 'reg', 'set', '00'])
157         dev[0].flush_scan_cache()
158         dev[1].flush_scan_cache()
159
160 def test_ap_vht80_invalid(dev, apdev):
161     """VHT with invalid 80 MHz channel configuration (seg1)"""
162     try:
163         hapd = None
164         params = { "ssid": "vht",
165                    "country_code": "US",
166                    "hw_mode": "a",
167                    "channel": "36",
168                    "ht_capab": "[HT40+]",
169                    "ieee80211n": "1",
170                    "ieee80211ac": "1",
171                    "vht_oper_chwidth": "1",
172                    "vht_oper_centr_freq_seg0_idx": "42",
173                    "vht_oper_centr_freq_seg1_idx": "155",
174                    'ieee80211d': '1',
175                    'ieee80211h': '1' }
176         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
177         # This fails due to unexpected seg1 configuration
178         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
179         if ev is None:
180             raise Exception("AP-DISABLED not reported")
181     except Exception, e:
182         if isinstance(e, Exception) and str(e) == "AP startup failed":
183             if not vht_supported():
184                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
185         raise
186     finally:
187         if hapd:
188             hapd.request("DISABLE")
189         subprocess.call(['iw', 'reg', 'set', '00'])
190
191 def test_ap_vht80_invalid2(dev, apdev):
192     """VHT with invalid 80 MHz channel configuration (seg0)"""
193     try:
194         hapd = None
195         params = { "ssid": "vht",
196                    "country_code": "US",
197                    "hw_mode": "a",
198                    "channel": "36",
199                    "ht_capab": "[HT40+]",
200                    "ieee80211n": "1",
201                    "ieee80211ac": "1",
202                    "vht_oper_chwidth": "1",
203                    "vht_oper_centr_freq_seg0_idx": "46",
204                    'ieee80211d': '1',
205                    'ieee80211h': '1' }
206         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
207         # This fails due to invalid seg0 configuration
208         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
209         if ev is None:
210             raise Exception("AP-DISABLED not reported")
211     except Exception, e:
212         if isinstance(e, Exception) and str(e) == "AP startup failed":
213             if not vht_supported():
214                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
215         raise
216     finally:
217         if hapd:
218             hapd.request("DISABLE")
219         subprocess.call(['iw', 'reg', 'set', '00'])
220
221 def test_ap_vht_20(devs, apdevs):
222     """VHT and 20 MHz channel"""
223     dev = devs[0]
224     ap = apdevs[0]
225     try:
226         hapd = None
227         params = { "ssid": "test-vht20",
228                    "country_code": "DE",
229                    "hw_mode": "a",
230                    "channel": "36",
231                    "ieee80211n": "1",
232                    "ieee80211ac": "1",
233                    "ht_capab": "",
234                    "vht_capab": "",
235                    "vht_oper_chwidth": "0",
236                    "vht_oper_centr_freq_seg0_idx": "0",
237                    "supported_rates": "60 120 240 360 480 540",
238                    "require_vht": "1",
239                  }
240         hapd = hostapd.add_ap(ap, params)
241         dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
242         hwsim_utils.test_connectivity(dev, hapd)
243     finally:
244         dev.request("DISCONNECT")
245         if hapd:
246             hapd.request("DISABLE")
247         subprocess.call(['iw', 'reg', 'set', '00'])
248         dev.flush_scan_cache()
249
250 def test_ap_vht_40(devs, apdevs):
251     """VHT and 40 MHz channel"""
252     dev = devs[0]
253     ap = apdevs[0]
254     try:
255         hapd = None
256         params = { "ssid": "test-vht40",
257                    "country_code": "DE",
258                    "hw_mode": "a",
259                    "channel": "36",
260                    "ieee80211n": "1",
261                    "ieee80211ac": "1",
262                    "ht_capab": "[HT40+]",
263                    "vht_capab": "",
264                    "vht_oper_chwidth": "0",
265                    "vht_oper_centr_freq_seg0_idx": "0",
266                  }
267         hapd = hostapd.add_ap(ap, params)
268         dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
269         hwsim_utils.test_connectivity(dev, hapd)
270     finally:
271         dev.request("DISCONNECT")
272         if hapd:
273             hapd.request("DISABLE")
274         subprocess.call(['iw', 'reg', 'set', '00'])
275         dev.flush_scan_cache()
276
277 def test_ap_vht_capab_not_supported(dev, apdev):
278     """VHT configuration with driver not supporting all vht_capab entries"""
279     try:
280         params = { "ssid": "vht",
281                    "country_code": "FI",
282                    "hw_mode": "a",
283                    "channel": "36",
284                    "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
285                    "ieee80211n": "1",
286                    "ieee80211ac": "1",
287                    "vht_oper_chwidth": "1",
288                    "vht_capab": "[MAX-MPDU-7991][MAX-MPDU-11454][VHT160][VHT160-80PLUS80][RXLDPC][SHORT-GI-80][SHORT-GI-160][TX-STBC-2BY1][RX-STBC-1][RX-STBC-12][RX-STBC-123][RX-STBC-1234][SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][BF-ANTENNA-3][BF-ANTENNA-4][SOUNDING-DIMENSION-2][SOUNDING-DIMENSION-3][SOUNDING-DIMENSION-4][MU-BEAMFORMER][VHT-TXOP-PS][HTC-VHT][MAX-A-MPDU-LEN-EXP0][MAX-A-MPDU-LEN-EXP7][VHT-LINK-ADAPT2][VHT-LINK-ADAPT3][RX-ANTENNA-PATTERN][TX-ANTENNA-PATTERN]",
289                    "vht_oper_centr_freq_seg0_idx": "42",
290                    "require_vht": "1" }
291         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
292         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
293         if ev is None:
294             raise Exception("Startup failure not reported")
295         for i in range(1, 7):
296             if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
297                 raise Exception("Unexpected SET failure")
298     finally:
299         subprocess.call(['iw', 'reg', 'set', '00'])
300
301 def test_ap_vht160(dev, apdev):
302     """VHT with 160 MHz channel width"""
303     try:
304         hapd = None
305         hapd2 = None
306         params = { "ssid": "vht",
307                    "country_code": "FI",
308                    "hw_mode": "a",
309                    "channel": "36",
310                    "ht_capab": "[HT40+]",
311                    "ieee80211n": "1",
312                    "ieee80211ac": "1",
313                    "vht_oper_chwidth": "2",
314                    "vht_oper_centr_freq_seg0_idx": "50",
315                    'ieee80211d': '1',
316                    'ieee80211h': '1' }
317         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
318
319         ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
320         if "DFS-CAC-START" not in ev:
321             raise Exception("Unexpected DFS event")
322
323         state = hapd.get_status_field("state")
324         if state != "DFS":
325             if state == "DISABLED" and not os.path.exists("dfs"):
326                 # Not all systems have recent enough CRDA version and
327                 # wireless-regdb changes to support 160 MHz and DFS. For now,
328                 # do not report failures for this test case.
329                 raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
330             raise Exception("Unexpected interface state: " + state)
331
332         params = { "ssid": "vht2",
333                    "country_code": "FI",
334                    "hw_mode": "a",
335                    "channel": "104",
336                    "ht_capab": "[HT40-]",
337                    "ieee80211n": "1",
338                    "ieee80211ac": "1",
339                    "vht_oper_chwidth": "2",
340                    "vht_oper_centr_freq_seg0_idx": "114",
341                    'ieee80211d': '1',
342                    'ieee80211h': '1' }
343         hapd2 = hostapd.add_ap(apdev[1], params, wait_enabled=False)
344
345         ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
346         if "DFS-CAC-START" not in ev:
347             raise Exception("Unexpected DFS event(2)")
348
349         state = hapd2.get_status_field("state")
350         if state != "DFS":
351             raise Exception("Unexpected interface state(2): " + state)
352
353         logger.info("Waiting for CAC to complete")
354
355         ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
356         if "success=1" not in ev:
357             raise Exception("CAC failed")
358         if "freq=5180" not in ev:
359             raise Exception("Unexpected DFS freq result")
360
361         ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
362         if not ev:
363             raise Exception("AP setup timed out")
364
365         state = hapd.get_status_field("state")
366         if state != "ENABLED":
367             raise Exception("Unexpected interface state")
368
369         ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
370         if "success=1" not in ev:
371             raise Exception("CAC failed(2)")
372         if "freq=5520" not in ev:
373             raise Exception("Unexpected DFS freq result(2)")
374
375         ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
376         if not ev:
377             raise Exception("AP setup timed out(2)")
378
379         state = hapd2.get_status_field("state")
380         if state != "ENABLED":
381             raise Exception("Unexpected interface state(2)")
382
383         freq = hapd2.get_status_field("freq")
384         if freq != "5520":
385             raise Exception("Unexpected frequency(2)")
386
387         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
388         hwsim_utils.test_connectivity(dev[0], hapd)
389         sig = dev[0].request("SIGNAL_POLL").splitlines()
390         if "FREQUENCY=5180" not in sig:
391             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
392         if "WIDTH=160 MHz" not in sig:
393             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
394         dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5520")
395         hwsim_utils.test_connectivity(dev[1], hapd2)
396         sig = dev[1].request("SIGNAL_POLL").splitlines()
397         if "FREQUENCY=5520" not in sig:
398             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
399         if "WIDTH=160 MHz" not in sig:
400             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
401     except Exception, e:
402         if isinstance(e, Exception) and str(e) == "AP startup failed":
403             if not vht_supported():
404                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
405         raise
406     finally:
407         dev[0].request("DISCONNECT")
408         dev[1].request("DISCONNECT")
409         if hapd:
410             hapd.request("DISABLE")
411         if hapd2:
412             hapd2.request("DISABLE")
413         subprocess.call(['iw', 'reg', 'set', '00'])
414         dev[0].flush_scan_cache()
415         dev[1].flush_scan_cache()
416
417 def test_ap_vht160_no_dfs(dev, apdev):
418     """VHT with 160 MHz channel width and no DFS"""
419     try:
420         hapd = None
421         params = { "ssid": "vht",
422                    "country_code": "ZA",
423                    "hw_mode": "a",
424                    "channel": "104",
425                    "ht_capab": "[HT40-]",
426                    "ieee80211n": "1",
427                    "ieee80211ac": "1",
428                    "vht_oper_chwidth": "2",
429                    "vht_oper_centr_freq_seg0_idx": "114",
430                    'ieee80211d': '1',
431                    'ieee80211h': '1' }
432         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
433         ev = hapd.wait_event(["AP-ENABLED"], timeout=2)
434         if not ev:
435             cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
436             reg = cmd.stdout.readlines()
437             for r in reg:
438                 if "5490" in r and "DFS" in r:
439                     raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
440             raise Exception("AP setup timed out")
441
442         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5520")
443         hwsim_utils.test_connectivity(dev[0], hapd)
444         sig = dev[0].request("SIGNAL_POLL").splitlines()
445         if "FREQUENCY=5520" not in sig:
446             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
447         if "WIDTH=160 MHz" not in sig:
448             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
449     except Exception, e:
450         if isinstance(e, Exception) and str(e) == "AP startup failed":
451             if not vht_supported():
452                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
453         raise
454     finally:
455         dev[0].request("DISCONNECT")
456         if hapd:
457             hapd.request("DISABLE")
458         subprocess.call(['iw', 'reg', 'set', '00'])
459         dev[0].flush_scan_cache()
460
461 def test_ap_vht80plus80(dev, apdev):
462     """VHT with 80+80 MHz channel width"""
463     try:
464         hapd = None
465         hapd2 = None
466         params = { "ssid": "vht",
467                    "country_code": "US",
468                    "hw_mode": "a",
469                    "channel": "52",
470                    "ht_capab": "[HT40+]",
471                    "ieee80211n": "1",
472                    "ieee80211ac": "1",
473                    "vht_oper_chwidth": "3",
474                    "vht_oper_centr_freq_seg0_idx": "58",
475                    "vht_oper_centr_freq_seg1_idx": "155",
476                    'ieee80211d': '1',
477                    'ieee80211h': '1' }
478         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
479         # This will actually fail since DFS on 80+80 is not yet supported
480         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
481         # ignore result to avoid breaking the test once 80+80 DFS gets enabled
482
483         params = { "ssid": "vht2",
484                    "country_code": "US",
485                    "hw_mode": "a",
486                    "channel": "36",
487                    "ht_capab": "[HT40+]",
488                    "ieee80211n": "1",
489                    "ieee80211ac": "1",
490                    "vht_oper_chwidth": "3",
491                    "vht_oper_centr_freq_seg0_idx": "42",
492                    "vht_oper_centr_freq_seg1_idx": "155" }
493         hapd2 = hostapd.add_ap(apdev[1], params, wait_enabled=False)
494
495         ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
496         if not ev:
497             raise Exception("AP setup timed out(2)")
498         if "AP-DISABLED" in ev:
499             # Assume this failed due to missing regulatory update for now
500             raise HwsimSkip("80+80 MHz channel not supported in regulatory information")
501
502         state = hapd2.get_status_field("state")
503         if state != "ENABLED":
504             raise Exception("Unexpected interface state(2)")
505
506         dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
507         hwsim_utils.test_connectivity(dev[1], hapd2)
508         sig = dev[1].request("SIGNAL_POLL").splitlines()
509         if "FREQUENCY=5180" not in sig:
510             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
511         if "WIDTH=80+80 MHz" not in sig:
512             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
513         if "CENTER_FRQ1=5210" not in sig:
514             raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
515         if "CENTER_FRQ2=5775" not in sig:
516             raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
517     except Exception, e:
518         if isinstance(e, Exception) and str(e) == "AP startup failed":
519             if not vht_supported():
520                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
521         raise
522     finally:
523         dev[0].request("DISCONNECT")
524         dev[1].request("DISCONNECT")
525         if hapd:
526             hapd.request("DISABLE")
527         if hapd2:
528             hapd2.request("DISABLE")
529         subprocess.call(['iw', 'reg', 'set', '00'])
530         dev[0].flush_scan_cache()
531         dev[1].flush_scan_cache()
532
533 def test_ap_vht80plus80_invalid(dev, apdev):
534     """VHT with invalid 80+80 MHz channel"""
535     try:
536         hapd = None
537         params = { "ssid": "vht",
538                    "country_code": "US",
539                    "hw_mode": "a",
540                    "channel": "36",
541                    "ht_capab": "[HT40+]",
542                    "ieee80211n": "1",
543                    "ieee80211ac": "1",
544                    "vht_oper_chwidth": "3",
545                    "vht_oper_centr_freq_seg0_idx": "42",
546                    "vht_oper_centr_freq_seg1_idx": "0",
547                    'ieee80211d': '1',
548                    'ieee80211h': '1' }
549         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
550         # This fails due to missing(invalid) seg1 configuration
551         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
552         if ev is None:
553             raise Exception("AP-DISABLED not reported")
554     except Exception, e:
555         if isinstance(e, Exception) and str(e) == "AP startup failed":
556             if not vht_supported():
557                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
558         raise
559     finally:
560         if hapd:
561             hapd.request("DISABLE")
562         subprocess.call(['iw', 'reg', 'set', '00'])
563
564 def test_ap_vht80_csa(dev, apdev):
565     """VHT with 80 MHz channel width and CSA"""
566     csa_supported(dev[0])
567     try:
568         hapd = None
569         params = { "ssid": "vht",
570                    "country_code": "US",
571                    "hw_mode": "a",
572                    "channel": "149",
573                    "ht_capab": "[HT40+]",
574                    "ieee80211n": "1",
575                    "ieee80211ac": "1",
576                    "vht_oper_chwidth": "1",
577                    "vht_oper_centr_freq_seg0_idx": "155" }
578         hapd = hostapd.add_ap(apdev[0], params)
579
580         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
581         hwsim_utils.test_connectivity(dev[0], hapd)
582
583         hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
584         ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
585         if ev is None:
586             raise Exception("CSA finished event timed out")
587         if "freq=5180" not in ev:
588             raise Exception("Unexpected channel in CSA finished event")
589         time.sleep(0.5)
590         hwsim_utils.test_connectivity(dev[0], hapd)
591
592         hapd.request("CHAN_SWITCH 5 5745")
593         ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
594         if ev is None:
595             raise Exception("CSA finished event timed out")
596         if "freq=5745" not in ev:
597             raise Exception("Unexpected channel in CSA finished event")
598         time.sleep(0.5)
599         hwsim_utils.test_connectivity(dev[0], hapd)
600
601         # This CSA to same channel will fail in kernel, so use this only for
602         # extra code coverage.
603         hapd.request("CHAN_SWITCH 5 5745")
604         hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
605     except Exception, e:
606         if isinstance(e, Exception) and str(e) == "AP startup failed":
607             if not vht_supported():
608                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
609         raise
610     finally:
611         dev[0].request("DISCONNECT")
612         if hapd:
613             hapd.request("DISABLE")
614         subprocess.call(['iw', 'reg', 'set', '00'])
615         dev[0].flush_scan_cache()
616
617 def test_ap_vht_on_24ghz(dev, apdev):
618     """Subset of VHT features on 2.4 GHz"""
619     hapd = None
620     params = { "ssid": "test-vht-2g",
621                "hw_mode": "g",
622                "channel": "1",
623                "ieee80211n": "1",
624                "vendor_vht": "1",
625                "vht_capab": "[MAX-MPDU-11454]",
626                "vht_oper_chwidth": "0",
627                "vht_oper_centr_freq_seg0_idx": "1"
628     }
629     hapd = hostapd.add_ap(apdev[0], params)
630     try:
631         if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
632             raise Exception("Failed to add vendor element")
633         dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
634         hwsim_utils.test_connectivity(dev[0], hapd)
635         sta = hapd.get_sta(dev[0].own_addr())
636         if '[VENDOR_VHT]' not in sta['flags']:
637             raise Exception("No VENDOR_VHT STA flag")
638
639         dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
640         sta = hapd.get_sta(dev[1].own_addr())
641         if '[VENDOR_VHT]' in sta['flags']:
642             raise Exception("Unexpected VENDOR_VHT STA flag")
643     finally:
644         dev[0].request("VENDOR_ELEM_REMOVE 13 *")
645
646 def test_prefer_vht40(dev, apdev):
647     """Preference on VHT40 over HT40"""
648     try:
649         hapd2 = None
650
651         params = { "ssid": "test",
652                    "country_code": "FI",
653                    "hw_mode": "a",
654                    "channel": "36",
655                    "ieee80211n": "1",
656                    "ht_capab": "[HT40+]" }
657         hapd = hostapd.add_ap(apdev[0], params)
658         bssid = apdev[0]['bssid']
659
660         params = { "ssid": "test",
661                    "country_code": "FI",
662                    "hw_mode": "a",
663                    "channel": "36",
664                    "ieee80211n": "1",
665                    "ieee80211ac": "1",
666                    "ht_capab": "[HT40+]",
667                    "vht_capab": "",
668                    "vht_oper_chwidth": "0",
669                    "vht_oper_centr_freq_seg0_idx": "0",
670                  }
671         hapd2 = hostapd.add_ap(apdev[1], params)
672         bssid2 = apdev[1]['bssid']
673
674         dev[0].scan_for_bss(bssid, freq=5180)
675         dev[0].scan_for_bss(bssid2, freq=5180)
676         dev[0].connect("test", scan_freq="5180", key_mgmt="NONE")
677         if dev[0].get_status_field('bssid') != bssid2:
678             raise Exception("Unexpected BSS selected")
679
680         est = dev[0].get_bss(bssid)['est_throughput']
681         if est != "135000":
682             raise Exception("Unexpected BSS0 est_throughput: " + est)
683
684         est = dev[0].get_bss(bssid2)['est_throughput']
685         if est != "135001":
686             raise Exception("Unexpected BSS1 est_throughput: " + est)
687     finally:
688         dev[0].request("DISCONNECT")
689         if hapd2:
690             hapd2.request("DISABLE")
691         subprocess.call(['iw', 'reg', 'set', '00'])
692         dev[0].flush_scan_cache()
693
694 def test_ap_vht80_pwr_constraint(dev, apdev):
695     """VHT with 80 MHz channel width and local power constraint"""
696     hapd = None
697     try:
698         params = { "ssid": "vht",
699                    "country_code": "FI",
700                    "hw_mode": "a",
701                    "channel": "36",
702                    "ht_capab": "[HT40+]",
703                    "ieee80211d": "1",
704                    "local_pwr_constraint": "3",
705                    "ieee80211n": "1",
706                    "ieee80211ac": "1",
707                    "vht_oper_chwidth": "1",
708                    "vht_oper_centr_freq_seg0_idx": "42" }
709         hapd = hostapd.add_ap(apdev[0], params)
710
711         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
712     except Exception, e:
713         if isinstance(e, Exception) and str(e) == "AP startup failed":
714             if not vht_supported():
715                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
716         raise
717     finally:
718         dev[0].request("DISCONNECT")
719         if hapd:
720             hapd.request("DISABLE")
721         subprocess.call(['iw', 'reg', 'set', '00'])
722         dev[0].flush_scan_cache()
723
724 def test_ap_vht_use_sta_nsts(dev, apdev):
725     """VHT with 80 MHz channel width and use_sta_nsts=1"""
726     try:
727         hapd = None
728         params = { "ssid": "vht",
729                    "country_code": "FI",
730                    "hw_mode": "a",
731                    "channel": "36",
732                    "ht_capab": "[HT40+]",
733                    "ieee80211n": "1",
734                    "ieee80211ac": "1",
735                    "vht_oper_chwidth": "1",
736                    "vht_oper_centr_freq_seg0_idx": "42",
737                    "use_sta_nsts": "1" }
738         hapd = hostapd.add_ap(apdev[0], params)
739         bssid = apdev[0]['bssid']
740
741         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
742         hwsim_utils.test_connectivity(dev[0], hapd)
743     except Exception, e:
744         if isinstance(e, Exception) and str(e) == "AP startup failed":
745             if not vht_supported():
746                 raise HwsimSkip("80 MHz channel not supported in regulatory information")
747         raise
748     finally:
749         dev[0].request("DISCONNECT")
750         if hapd:
751             hapd.request("DISABLE")
752         subprocess.call(['iw', 'reg', 'set', '00'])
753         dev[0].flush_scan_cache()