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)
41 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
42 hwsim_utils.test_connectivity(dev[0], hapd)
44 if isinstance(e, Exception) and str(e) == "AP startup failed":
45 if not vht_supported():
46 raise HwsimSkip("80 MHz channel not supported in regulatory information")
49 dev[0].request("DISCONNECT")
51 hapd.request("DISABLE")
52 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
53 dev[0].flush_scan_cache()
55 def test_ap_vht80_params(dev, apdev):
56 """VHT with 80 MHz channel width and number of optional features enabled"""
59 params = { "ssid": "vht",
63 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
66 "vht_oper_chwidth": "1",
67 "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
68 "vht_oper_centr_freq_seg0_idx": "42",
70 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
72 dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
73 disable_vht="1", wait_connect=False)
74 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
75 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
77 raise Exception("Association rejection timed out")
78 if "status_code=104" not in ev:
79 raise Exception("Unexpected rejection status code")
80 dev[1].request("DISCONNECT")
81 hwsim_utils.test_connectivity(dev[0], hapd)
83 if isinstance(e, Exception) and str(e) == "AP startup failed":
84 if not vht_supported():
85 raise HwsimSwkip("80 MHz channel not supported in regulatory information")
88 dev[0].request("DISCONNECT")
89 dev[1].request("DISCONNECT")
91 hapd.request("DISABLE")
92 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
93 dev[0].flush_scan_cache()
94 dev[1].flush_scan_cache()
96 def test_ap_vht_20(devs, apdevs):
97 """VHT and 20 MHz channel"""
102 params = { "ssid": "test-vht20",
103 "country_code": "DE",
110 "vht_oper_chwidth": "0",
111 "vht_oper_centr_freq_seg0_idx": "0",
112 "supported_rates": "60 120 240 360 480 540",
115 hapd = hostapd.add_ap(ap['ifname'], params)
116 dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
117 hwsim_utils.test_connectivity(dev, hapd)
119 dev.request("DISCONNECT")
121 hapd.request("DISABLE")
122 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
123 dev.flush_scan_cache()
125 def test_ap_vht_40(devs, apdevs):
126 """VHT and 40 MHz channel"""
131 params = { "ssid": "test-vht40",
132 "country_code": "DE",
137 "ht_capab": "[HT40+]",
139 "vht_oper_chwidth": "0",
140 "vht_oper_centr_freq_seg0_idx": "0",
142 hapd = hostapd.add_ap(ap['ifname'], params)
143 dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
144 hwsim_utils.test_connectivity(dev, hapd)
146 dev.request("DISCONNECT")
148 hapd.request("DISABLE")
149 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
150 dev.flush_scan_cache()
152 def test_ap_vht_capab_not_supported(dev, apdev):
153 """VHT configuration with driver not supporting all vht_capab entries"""
155 params = { "ssid": "vht",
156 "country_code": "FI",
159 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
162 "vht_oper_chwidth": "1",
163 "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]",
164 "vht_oper_centr_freq_seg0_idx": "42",
166 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
167 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
169 raise Exception("Startup failure not reported")
170 for i in range(1, 7):
171 if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
172 raise Exception("Unexpected SET failure")
174 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
176 def test_ap_vht160(dev, apdev):
177 """VHT with 160 MHz channel width"""
181 params = { "ssid": "vht",
182 "country_code": "FI",
185 "ht_capab": "[HT40+]",
188 "vht_oper_chwidth": "2",
189 "vht_oper_centr_freq_seg0_idx": "50",
192 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
194 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
195 if "DFS-CAC-START" not in ev:
196 raise Exception("Unexpected DFS event")
198 state = hapd.get_status_field("state")
200 if state == "DISABLED" and not os.path.exists("dfs"):
201 # Not all systems have recent enough CRDA version and
202 # wireless-regdb changes to support 160 MHz and DFS. For now,
203 # do not report failures for this test case.
204 raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
205 raise Exception("Unexpected interface state: " + state)
207 params = { "ssid": "vht2",
208 "country_code": "FI",
211 "ht_capab": "[HT40+]",
214 "vht_oper_chwidth": "2",
215 "vht_oper_centr_freq_seg0_idx": "114",
218 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
220 ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
221 if "DFS-CAC-START" not in ev:
222 raise Exception("Unexpected DFS event(2)")
224 state = hapd2.get_status_field("state")
226 raise Exception("Unexpected interface state(2): " + state)
228 logger.info("Waiting for CAC to complete")
230 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
231 if "success=1" not in ev:
232 raise Exception("CAC failed")
233 if "freq=5180" not in ev:
234 raise Exception("Unexpected DFS freq result")
236 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
238 raise Exception("AP setup timed out")
240 state = hapd.get_status_field("state")
241 if state != "ENABLED":
242 raise Exception("Unexpected interface state")
244 ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
245 if "success=1" not in ev:
246 raise Exception("CAC failed(2)")
247 if "freq=5500" not in ev:
248 raise Exception("Unexpected DFS freq result(2)")
250 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
252 raise Exception("AP setup timed out(2)")
254 state = hapd2.get_status_field("state")
255 if state != "ENABLED":
256 raise Exception("Unexpected interface state(2)")
258 freq = hapd2.get_status_field("freq")
260 raise Exception("Unexpected frequency(2)")
262 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
263 hwsim_utils.test_connectivity(dev[0], hapd)
264 sig = dev[0].request("SIGNAL_POLL").splitlines()
265 if "FREQUENCY=5180" not in sig:
266 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
267 if "WIDTH=160 MHz" not in sig:
268 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
269 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
270 hwsim_utils.test_connectivity(dev[1], hapd2)
271 sig = dev[1].request("SIGNAL_POLL").splitlines()
272 if "FREQUENCY=5500" not in sig:
273 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
274 if "WIDTH=160 MHz" not in sig:
275 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
277 if isinstance(e, Exception) and str(e) == "AP startup failed":
278 if not vht_supported():
279 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
282 dev[0].request("DISCONNECT")
283 dev[1].request("DISCONNECT")
285 hapd.request("DISABLE")
287 hapd2.request("DISABLE")
288 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
289 dev[0].flush_scan_cache()
290 dev[1].flush_scan_cache()
292 def test_ap_vht80plus80(dev, apdev):
293 """VHT with 80+80 MHz channel width"""
297 params = { "ssid": "vht",
298 "country_code": "US",
301 "ht_capab": "[HT40+]",
304 "vht_oper_chwidth": "3",
305 "vht_oper_centr_freq_seg0_idx": "58",
306 "vht_oper_centr_freq_seg1_idx": "155",
309 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
310 # This will actually fail since DFS on 80+80 is not yet supported
311 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
312 # ignore result to avoid breaking the test once 80+80 DFS gets enabled
314 params = { "ssid": "vht2",
315 "country_code": "US",
318 "ht_capab": "[HT40+]",
321 "vht_oper_chwidth": "3",
322 "vht_oper_centr_freq_seg0_idx": "42",
323 "vht_oper_centr_freq_seg1_idx": "155" }
324 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
326 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
328 raise Exception("AP setup timed out(2)")
330 state = hapd2.get_status_field("state")
331 if state != "ENABLED":
332 raise Exception("Unexpected interface state(2)")
334 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
335 hwsim_utils.test_connectivity(dev[1], hapd2)
336 sig = dev[1].request("SIGNAL_POLL").splitlines()
337 if "FREQUENCY=5180" not in sig:
338 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
339 if "WIDTH=80+80 MHz" not in sig:
340 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
341 if "CENTER_FRQ1=5210" not in sig:
342 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
343 if "CENTER_FRQ2=5775" not in sig:
344 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
346 if isinstance(e, Exception) and str(e) == "AP startup failed":
347 if not vht_supported():
348 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
351 dev[0].request("DISCONNECT")
352 dev[1].request("DISCONNECT")
354 hapd.request("DISABLE")
356 hapd2.request("DISABLE")
357 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
358 dev[0].flush_scan_cache()
359 dev[1].flush_scan_cache()
361 def test_ap_vht80_csa(dev, apdev):
362 """VHT with 80 MHz channel width and CSA"""
363 csa_supported(dev[0])
366 params = { "ssid": "vht",
367 "country_code": "US",
370 "ht_capab": "[HT40+]",
373 "vht_oper_chwidth": "1",
374 "vht_oper_centr_freq_seg0_idx": "155" }
375 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
377 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
378 hwsim_utils.test_connectivity(dev[0], hapd)
380 hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
381 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
383 raise Exception("CSA finished event timed out")
384 if "freq=5180" not in ev:
385 raise Exception("Unexpected channel in CSA finished event")
387 hwsim_utils.test_connectivity(dev[0], hapd)
389 hapd.request("CHAN_SWITCH 5 5745")
390 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
392 raise Exception("CSA finished event timed out")
393 if "freq=5745" not in ev:
394 raise Exception("Unexpected channel in CSA finished event")
396 hwsim_utils.test_connectivity(dev[0], hapd)
398 # This CSA to same channel will fail in kernel, so use this only for
399 # extra code coverage.
400 hapd.request("CHAN_SWITCH 5 5745")
401 hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
403 if isinstance(e, Exception) and str(e) == "AP startup failed":
404 if not vht_supported():
405 raise HwsimSkip("80 MHz channel not supported in regulatory information")
408 dev[0].request("DISCONNECT")
410 hapd.request("DISABLE")
411 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
412 dev[0].flush_scan_cache()
414 def test_ap_vht_on_24ghz(dev, apdev):
415 """Subset of VHT features on 2.4 GHz"""
417 params = { "ssid": "test-vht-2g",
422 "vht_capab": "[MAX-MPDU-11454]",
423 "vht_oper_chwidth": "0",
424 "vht_oper_centr_freq_seg0_idx": "1"
426 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
428 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
429 raise Exception("Failed to add vendor element")
430 dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
431 hwsim_utils.test_connectivity(dev[0], hapd)
432 sta = hapd.get_sta(dev[0].own_addr())
433 if '[VENDOR_VHT]' not in sta['flags']:
434 raise Exception("No VENDOR_VHT STA flag")
436 dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
437 sta = hapd.get_sta(dev[1].own_addr())
438 if '[VENDOR_VHT]' in sta['flags']:
439 raise Exception("Unexpected VENDOR_VHT STA flag")
441 dev[0].request("VENDOR_ELEM_REMOVE 13 *")