1 # Test cases for VHT operations with hostapd
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
3 # Copyright (c) 2013, Intel Corporation
5 # This software may be distributed under the terms of the BSD license.
6 # See README for more details.
9 logger = logging.getLogger()
11 import subprocess, time
15 from utils import HwsimSkip
16 from test_dfs import wait_dfs_event
17 from test_ap_csa import csa_supported
20 cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
21 reg = cmd.stdout.read()
22 if "@ 80)" in reg or "@ 160)" in reg:
26 def test_ap_vht80(dev, apdev):
27 """VHT with 80 MHz channel width"""
30 params = { "ssid": "vht",
34 "ht_capab": "[HT40+]",
37 "vht_oper_chwidth": "1",
38 "vht_oper_centr_freq_seg0_idx": "42" }
39 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
40 bssid = apdev[0]['bssid']
42 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
43 hwsim_utils.test_connectivity(dev[0], hapd)
44 est = dev[0].get_bss(bssid)['est_throughput']
46 raise Exception("Unexpected BSS est_throughput: " + est)
48 if isinstance(e, Exception) and str(e) == "AP startup failed":
49 if not vht_supported():
50 raise HwsimSkip("80 MHz channel not supported in regulatory information")
53 dev[0].request("DISCONNECT")
55 hapd.request("DISABLE")
56 subprocess.call(['iw', 'reg', 'set', '00'])
57 dev[0].flush_scan_cache()
59 def test_ap_vht80_params(dev, apdev):
60 """VHT with 80 MHz channel width and number of optional features enabled"""
63 params = { "ssid": "vht",
67 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
70 "vht_oper_chwidth": "1",
71 "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
72 "vht_oper_centr_freq_seg0_idx": "42",
74 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
76 dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
77 disable_vht="1", wait_connect=False)
78 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
79 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
81 raise Exception("Association rejection timed out")
82 if "status_code=104" not in ev:
83 raise Exception("Unexpected rejection status code")
84 dev[1].request("DISCONNECT")
85 hwsim_utils.test_connectivity(dev[0], hapd)
87 if isinstance(e, Exception) and str(e) == "AP startup failed":
88 if not vht_supported():
89 raise HwsimSkip("80 MHz channel not supported in regulatory information")
92 dev[0].request("DISCONNECT")
93 dev[1].request("DISCONNECT")
95 hapd.request("DISABLE")
96 subprocess.call(['iw', 'reg', 'set', '00'])
97 dev[0].flush_scan_cache()
98 dev[1].flush_scan_cache()
100 def test_ap_vht_20(devs, apdevs):
101 """VHT and 20 MHz channel"""
106 params = { "ssid": "test-vht20",
107 "country_code": "DE",
114 "vht_oper_chwidth": "0",
115 "vht_oper_centr_freq_seg0_idx": "0",
116 "supported_rates": "60 120 240 360 480 540",
119 hapd = hostapd.add_ap(ap['ifname'], params)
120 dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
121 hwsim_utils.test_connectivity(dev, hapd)
123 dev.request("DISCONNECT")
125 hapd.request("DISABLE")
126 subprocess.call(['iw', 'reg', 'set', '00'])
127 dev.flush_scan_cache()
129 def test_ap_vht_40(devs, apdevs):
130 """VHT and 40 MHz channel"""
135 params = { "ssid": "test-vht40",
136 "country_code": "DE",
141 "ht_capab": "[HT40+]",
143 "vht_oper_chwidth": "0",
144 "vht_oper_centr_freq_seg0_idx": "0",
146 hapd = hostapd.add_ap(ap['ifname'], params)
147 dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
148 hwsim_utils.test_connectivity(dev, hapd)
150 dev.request("DISCONNECT")
152 hapd.request("DISABLE")
153 subprocess.call(['iw', 'reg', 'set', '00'])
154 dev.flush_scan_cache()
156 def test_ap_vht_capab_not_supported(dev, apdev):
157 """VHT configuration with driver not supporting all vht_capab entries"""
159 params = { "ssid": "vht",
160 "country_code": "FI",
163 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
166 "vht_oper_chwidth": "1",
167 "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][SOUNDING-DIMENSION-2][MU-BEAMFORMER][MU-BEAMFORMEE][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]",
168 "vht_oper_centr_freq_seg0_idx": "42",
170 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
171 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
173 raise Exception("Startup failure not reported")
174 for i in range(1, 7):
175 if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
176 raise Exception("Unexpected SET failure")
178 subprocess.call(['iw', 'reg', 'set', '00'])
180 def test_ap_vht160(dev, apdev):
181 """VHT with 160 MHz channel width"""
185 params = { "ssid": "vht",
186 "country_code": "FI",
189 "ht_capab": "[HT40+]",
192 "vht_oper_chwidth": "2",
193 "vht_oper_centr_freq_seg0_idx": "50",
196 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
198 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
199 if "DFS-CAC-START" not in ev:
200 raise Exception("Unexpected DFS event")
202 state = hapd.get_status_field("state")
204 if state == "DISABLED" and not os.path.exists("dfs"):
205 # Not all systems have recent enough CRDA version and
206 # wireless-regdb changes to support 160 MHz and DFS. For now,
207 # do not report failures for this test case.
208 raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
209 raise Exception("Unexpected interface state: " + state)
211 params = { "ssid": "vht2",
212 "country_code": "FI",
215 "ht_capab": "[HT40+]",
218 "vht_oper_chwidth": "2",
219 "vht_oper_centr_freq_seg0_idx": "114",
222 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
224 ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
225 if "DFS-CAC-START" not in ev:
226 raise Exception("Unexpected DFS event(2)")
228 state = hapd2.get_status_field("state")
230 raise Exception("Unexpected interface state(2): " + state)
232 logger.info("Waiting for CAC to complete")
234 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
235 if "success=1" not in ev:
236 raise Exception("CAC failed")
237 if "freq=5180" not in ev:
238 raise Exception("Unexpected DFS freq result")
240 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
242 raise Exception("AP setup timed out")
244 state = hapd.get_status_field("state")
245 if state != "ENABLED":
246 raise Exception("Unexpected interface state")
248 ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
249 if "success=1" not in ev:
250 raise Exception("CAC failed(2)")
251 if "freq=5500" not in ev:
252 raise Exception("Unexpected DFS freq result(2)")
254 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
256 raise Exception("AP setup timed out(2)")
258 state = hapd2.get_status_field("state")
259 if state != "ENABLED":
260 raise Exception("Unexpected interface state(2)")
262 freq = hapd2.get_status_field("freq")
264 raise Exception("Unexpected frequency(2)")
266 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
267 hwsim_utils.test_connectivity(dev[0], hapd)
268 sig = dev[0].request("SIGNAL_POLL").splitlines()
269 if "FREQUENCY=5180" not in sig:
270 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
271 if "WIDTH=160 MHz" not in sig:
272 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
273 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
274 hwsim_utils.test_connectivity(dev[1], hapd2)
275 sig = dev[1].request("SIGNAL_POLL").splitlines()
276 if "FREQUENCY=5500" not in sig:
277 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
278 if "WIDTH=160 MHz" not in sig:
279 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
281 if isinstance(e, Exception) and str(e) == "AP startup failed":
282 if not vht_supported():
283 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
286 dev[0].request("DISCONNECT")
287 dev[1].request("DISCONNECT")
289 hapd.request("DISABLE")
291 hapd2.request("DISABLE")
292 subprocess.call(['iw', 'reg', 'set', '00'])
293 dev[0].flush_scan_cache()
294 dev[1].flush_scan_cache()
296 def test_ap_vht80plus80(dev, apdev):
297 """VHT with 80+80 MHz channel width"""
301 params = { "ssid": "vht",
302 "country_code": "US",
305 "ht_capab": "[HT40+]",
308 "vht_oper_chwidth": "3",
309 "vht_oper_centr_freq_seg0_idx": "58",
310 "vht_oper_centr_freq_seg1_idx": "155",
313 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
314 # This will actually fail since DFS on 80+80 is not yet supported
315 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
316 # ignore result to avoid breaking the test once 80+80 DFS gets enabled
318 params = { "ssid": "vht2",
319 "country_code": "US",
322 "ht_capab": "[HT40+]",
325 "vht_oper_chwidth": "3",
326 "vht_oper_centr_freq_seg0_idx": "42",
327 "vht_oper_centr_freq_seg1_idx": "155" }
328 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
330 ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
332 raise Exception("AP setup timed out(2)")
333 if "AP-DISABLED" in ev:
334 # Assume this failed due to missing regulatory update for now
335 raise HwsimSkip("80+80 MHz channel not supported in regulatory information")
337 state = hapd2.get_status_field("state")
338 if state != "ENABLED":
339 raise Exception("Unexpected interface state(2)")
341 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
342 hwsim_utils.test_connectivity(dev[1], hapd2)
343 sig = dev[1].request("SIGNAL_POLL").splitlines()
344 if "FREQUENCY=5180" not in sig:
345 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
346 if "WIDTH=80+80 MHz" not in sig:
347 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
348 if "CENTER_FRQ1=5210" not in sig:
349 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
350 if "CENTER_FRQ2=5775" not in sig:
351 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
353 if isinstance(e, Exception) and str(e) == "AP startup failed":
354 if not vht_supported():
355 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
358 dev[0].request("DISCONNECT")
359 dev[1].request("DISCONNECT")
361 hapd.request("DISABLE")
363 hapd2.request("DISABLE")
364 subprocess.call(['iw', 'reg', 'set', '00'])
365 dev[0].flush_scan_cache()
366 dev[1].flush_scan_cache()
368 def test_ap_vht80_csa(dev, apdev):
369 """VHT with 80 MHz channel width and CSA"""
370 csa_supported(dev[0])
373 params = { "ssid": "vht",
374 "country_code": "US",
377 "ht_capab": "[HT40+]",
380 "vht_oper_chwidth": "1",
381 "vht_oper_centr_freq_seg0_idx": "155" }
382 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
384 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
385 hwsim_utils.test_connectivity(dev[0], hapd)
387 hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
388 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
390 raise Exception("CSA finished event timed out")
391 if "freq=5180" not in ev:
392 raise Exception("Unexpected channel in CSA finished event")
394 hwsim_utils.test_connectivity(dev[0], hapd)
396 hapd.request("CHAN_SWITCH 5 5745")
397 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
399 raise Exception("CSA finished event timed out")
400 if "freq=5745" not in ev:
401 raise Exception("Unexpected channel in CSA finished event")
403 hwsim_utils.test_connectivity(dev[0], hapd)
405 # This CSA to same channel will fail in kernel, so use this only for
406 # extra code coverage.
407 hapd.request("CHAN_SWITCH 5 5745")
408 hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
410 if isinstance(e, Exception) and str(e) == "AP startup failed":
411 if not vht_supported():
412 raise HwsimSkip("80 MHz channel not supported in regulatory information")
415 dev[0].request("DISCONNECT")
417 hapd.request("DISABLE")
418 subprocess.call(['iw', 'reg', 'set', '00'])
419 dev[0].flush_scan_cache()
421 def test_ap_vht_on_24ghz(dev, apdev):
422 """Subset of VHT features on 2.4 GHz"""
424 params = { "ssid": "test-vht-2g",
429 "vht_capab": "[MAX-MPDU-11454]",
430 "vht_oper_chwidth": "0",
431 "vht_oper_centr_freq_seg0_idx": "1"
433 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
435 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
436 raise Exception("Failed to add vendor element")
437 dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
438 hwsim_utils.test_connectivity(dev[0], hapd)
439 sta = hapd.get_sta(dev[0].own_addr())
440 if '[VENDOR_VHT]' not in sta['flags']:
441 raise Exception("No VENDOR_VHT STA flag")
443 dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
444 sta = hapd.get_sta(dev[1].own_addr())
445 if '[VENDOR_VHT]' in sta['flags']:
446 raise Exception("Unexpected VENDOR_VHT STA flag")
448 dev[0].request("VENDOR_ELEM_REMOVE 13 *")
450 def test_prefer_vht40(dev, apdev):
451 """Preference on VHT40 over HT40"""
455 params = { "ssid": "test",
456 "country_code": "FI",
460 "ht_capab": "[HT40+]" }
461 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
462 bssid = apdev[0]['bssid']
464 params = { "ssid": "test",
465 "country_code": "FI",
470 "ht_capab": "[HT40+]",
472 "vht_oper_chwidth": "0",
473 "vht_oper_centr_freq_seg0_idx": "0",
475 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
476 bssid2 = apdev[1]['bssid']
478 dev[0].scan_for_bss(bssid, freq=5180)
479 dev[0].scan_for_bss(bssid2, freq=5180)
480 dev[0].connect("test", scan_freq="5180", key_mgmt="NONE")
481 if dev[0].get_status_field('bssid') != bssid2:
482 raise Exception("Unexpected BSS selected")
484 est = dev[0].get_bss(bssid)['est_throughput']
486 raise Exception("Unexpected BSS0 est_throughput: " + est)
488 est = dev[0].get_bss(bssid2)['est_throughput']
490 raise Exception("Unexpected BSS1 est_throughput: " + est)
492 dev[0].request("DISCONNECT")
494 hapd2.request("DISABLE")
495 subprocess.call(['iw', 'reg', 'set', '00'])
496 dev[0].flush_scan_cache()