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 vht80_test(apdev, dev, channel, ht_capab):
62 params = { "ssid": "vht",
65 "channel": str(channel),
69 "vht_oper_chwidth": "1",
70 "vht_oper_centr_freq_seg0_idx": "42" }
71 hapd = hostapd.add_ap(apdev['ifname'], params)
72 bssid = apdev['bssid']
74 dev.connect("vht", key_mgmt="NONE", scan_freq=str(5000 + 5 * channel))
75 hwsim_utils.test_connectivity(dev, hapd)
77 if isinstance(e, Exception) and str(e) == "AP startup failed":
78 if not vht_supported():
79 raise HwsimSkip("80 MHz channel not supported in regulatory information")
82 dev.request("DISCONNECT")
84 hapd.request("DISABLE")
85 subprocess.call(['iw', 'reg', 'set', '00'])
86 dev.flush_scan_cache()
88 def test_ap_vht80b(dev, apdev):
89 """VHT with 80 MHz channel width (HT40- channel 40)"""
90 vht80_test(apdev[0], dev[0], 40, "[HT40-]")
92 def test_ap_vht80c(dev, apdev):
93 """VHT with 80 MHz channel width (HT40+ channel 44)"""
94 vht80_test(apdev[0], dev[0], 44, "[HT40+]")
96 def test_ap_vht80d(dev, apdev):
97 """VHT with 80 MHz channel width (HT40- channel 48)"""
98 vht80_test(apdev[0], dev[0], 48, "[HT40-]")
100 def test_ap_vht80_params(dev, apdev):
101 """VHT with 80 MHz channel width and number of optional features enabled"""
104 params = { "ssid": "vht",
105 "country_code": "FI",
108 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
111 "vht_oper_chwidth": "1",
112 "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
113 "vht_oper_centr_freq_seg0_idx": "42",
115 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
117 dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
118 disable_vht="1", wait_connect=False)
119 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
120 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
122 raise Exception("Association rejection timed out")
123 if "status_code=104" not in ev:
124 raise Exception("Unexpected rejection status code")
125 dev[1].request("DISCONNECT")
126 hwsim_utils.test_connectivity(dev[0], hapd)
128 if isinstance(e, Exception) and str(e) == "AP startup failed":
129 if not vht_supported():
130 raise HwsimSkip("80 MHz channel not supported in regulatory information")
133 dev[0].request("DISCONNECT")
134 dev[1].request("DISCONNECT")
136 hapd.request("DISABLE")
137 subprocess.call(['iw', 'reg', 'set', '00'])
138 dev[0].flush_scan_cache()
139 dev[1].flush_scan_cache()
141 def test_ap_vht_20(devs, apdevs):
142 """VHT and 20 MHz channel"""
147 params = { "ssid": "test-vht20",
148 "country_code": "DE",
155 "vht_oper_chwidth": "0",
156 "vht_oper_centr_freq_seg0_idx": "0",
157 "supported_rates": "60 120 240 360 480 540",
160 hapd = hostapd.add_ap(ap['ifname'], params)
161 dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
162 hwsim_utils.test_connectivity(dev, hapd)
164 dev.request("DISCONNECT")
166 hapd.request("DISABLE")
167 subprocess.call(['iw', 'reg', 'set', '00'])
168 dev.flush_scan_cache()
170 def test_ap_vht_40(devs, apdevs):
171 """VHT and 40 MHz channel"""
176 params = { "ssid": "test-vht40",
177 "country_code": "DE",
182 "ht_capab": "[HT40+]",
184 "vht_oper_chwidth": "0",
185 "vht_oper_centr_freq_seg0_idx": "0",
187 hapd = hostapd.add_ap(ap['ifname'], params)
188 dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
189 hwsim_utils.test_connectivity(dev, hapd)
191 dev.request("DISCONNECT")
193 hapd.request("DISABLE")
194 subprocess.call(['iw', 'reg', 'set', '00'])
195 dev.flush_scan_cache()
197 def test_ap_vht_capab_not_supported(dev, apdev):
198 """VHT configuration with driver not supporting all vht_capab entries"""
200 params = { "ssid": "vht",
201 "country_code": "FI",
204 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
207 "vht_oper_chwidth": "1",
208 "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]",
209 "vht_oper_centr_freq_seg0_idx": "42",
211 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
212 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
214 raise Exception("Startup failure not reported")
215 for i in range(1, 7):
216 if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
217 raise Exception("Unexpected SET failure")
219 subprocess.call(['iw', 'reg', 'set', '00'])
221 def test_ap_vht160(dev, apdev):
222 """VHT with 160 MHz channel width"""
226 params = { "ssid": "vht",
227 "country_code": "FI",
230 "ht_capab": "[HT40+]",
233 "vht_oper_chwidth": "2",
234 "vht_oper_centr_freq_seg0_idx": "50",
237 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
239 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
240 if "DFS-CAC-START" not in ev:
241 raise Exception("Unexpected DFS event")
243 state = hapd.get_status_field("state")
245 if state == "DISABLED" and not os.path.exists("dfs"):
246 # Not all systems have recent enough CRDA version and
247 # wireless-regdb changes to support 160 MHz and DFS. For now,
248 # do not report failures for this test case.
249 raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
250 raise Exception("Unexpected interface state: " + state)
252 params = { "ssid": "vht2",
253 "country_code": "FI",
256 "ht_capab": "[HT40-]",
259 "vht_oper_chwidth": "2",
260 "vht_oper_centr_freq_seg0_idx": "114",
263 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
265 ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
266 if "DFS-CAC-START" not in ev:
267 raise Exception("Unexpected DFS event(2)")
269 state = hapd2.get_status_field("state")
271 raise Exception("Unexpected interface state(2): " + state)
273 logger.info("Waiting for CAC to complete")
275 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
276 if "success=1" not in ev:
277 raise Exception("CAC failed")
278 if "freq=5180" not in ev:
279 raise Exception("Unexpected DFS freq result")
281 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
283 raise Exception("AP setup timed out")
285 state = hapd.get_status_field("state")
286 if state != "ENABLED":
287 raise Exception("Unexpected interface state")
289 ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
290 if "success=1" not in ev:
291 raise Exception("CAC failed(2)")
292 if "freq=5520" not in ev:
293 raise Exception("Unexpected DFS freq result(2)")
295 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
297 raise Exception("AP setup timed out(2)")
299 state = hapd2.get_status_field("state")
300 if state != "ENABLED":
301 raise Exception("Unexpected interface state(2)")
303 freq = hapd2.get_status_field("freq")
305 raise Exception("Unexpected frequency(2)")
307 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
308 hwsim_utils.test_connectivity(dev[0], hapd)
309 sig = dev[0].request("SIGNAL_POLL").splitlines()
310 if "FREQUENCY=5180" not in sig:
311 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
312 if "WIDTH=160 MHz" not in sig:
313 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
314 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5520")
315 hwsim_utils.test_connectivity(dev[1], hapd2)
316 sig = dev[1].request("SIGNAL_POLL").splitlines()
317 if "FREQUENCY=5520" not in sig:
318 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
319 if "WIDTH=160 MHz" not in sig:
320 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
322 if isinstance(e, Exception) and str(e) == "AP startup failed":
323 if not vht_supported():
324 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
327 dev[0].request("DISCONNECT")
328 dev[1].request("DISCONNECT")
330 hapd.request("DISABLE")
332 hapd2.request("DISABLE")
333 subprocess.call(['iw', 'reg', 'set', '00'])
334 dev[0].flush_scan_cache()
335 dev[1].flush_scan_cache()
337 def test_ap_vht80plus80(dev, apdev):
338 """VHT with 80+80 MHz channel width"""
342 params = { "ssid": "vht",
343 "country_code": "US",
346 "ht_capab": "[HT40+]",
349 "vht_oper_chwidth": "3",
350 "vht_oper_centr_freq_seg0_idx": "58",
351 "vht_oper_centr_freq_seg1_idx": "155",
354 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
355 # This will actually fail since DFS on 80+80 is not yet supported
356 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
357 # ignore result to avoid breaking the test once 80+80 DFS gets enabled
359 params = { "ssid": "vht2",
360 "country_code": "US",
363 "ht_capab": "[HT40+]",
366 "vht_oper_chwidth": "3",
367 "vht_oper_centr_freq_seg0_idx": "42",
368 "vht_oper_centr_freq_seg1_idx": "155" }
369 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
371 ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
373 raise Exception("AP setup timed out(2)")
374 if "AP-DISABLED" in ev:
375 # Assume this failed due to missing regulatory update for now
376 raise HwsimSkip("80+80 MHz channel not supported in regulatory information")
378 state = hapd2.get_status_field("state")
379 if state != "ENABLED":
380 raise Exception("Unexpected interface state(2)")
382 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
383 hwsim_utils.test_connectivity(dev[1], hapd2)
384 sig = dev[1].request("SIGNAL_POLL").splitlines()
385 if "FREQUENCY=5180" not in sig:
386 raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
387 if "WIDTH=80+80 MHz" not in sig:
388 raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
389 if "CENTER_FRQ1=5210" not in sig:
390 raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
391 if "CENTER_FRQ2=5775" not in sig:
392 raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
394 if isinstance(e, Exception) and str(e) == "AP startup failed":
395 if not vht_supported():
396 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
399 dev[0].request("DISCONNECT")
400 dev[1].request("DISCONNECT")
402 hapd.request("DISABLE")
404 hapd2.request("DISABLE")
405 subprocess.call(['iw', 'reg', 'set', '00'])
406 dev[0].flush_scan_cache()
407 dev[1].flush_scan_cache()
409 def test_ap_vht80_csa(dev, apdev):
410 """VHT with 80 MHz channel width and CSA"""
411 csa_supported(dev[0])
414 params = { "ssid": "vht",
415 "country_code": "US",
418 "ht_capab": "[HT40+]",
421 "vht_oper_chwidth": "1",
422 "vht_oper_centr_freq_seg0_idx": "155" }
423 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
425 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
426 hwsim_utils.test_connectivity(dev[0], hapd)
428 hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
429 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
431 raise Exception("CSA finished event timed out")
432 if "freq=5180" not in ev:
433 raise Exception("Unexpected channel in CSA finished event")
435 hwsim_utils.test_connectivity(dev[0], hapd)
437 hapd.request("CHAN_SWITCH 5 5745")
438 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
440 raise Exception("CSA finished event timed out")
441 if "freq=5745" not in ev:
442 raise Exception("Unexpected channel in CSA finished event")
444 hwsim_utils.test_connectivity(dev[0], hapd)
446 # This CSA to same channel will fail in kernel, so use this only for
447 # extra code coverage.
448 hapd.request("CHAN_SWITCH 5 5745")
449 hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
451 if isinstance(e, Exception) and str(e) == "AP startup failed":
452 if not vht_supported():
453 raise HwsimSkip("80 MHz channel not supported in regulatory information")
456 dev[0].request("DISCONNECT")
458 hapd.request("DISABLE")
459 subprocess.call(['iw', 'reg', 'set', '00'])
460 dev[0].flush_scan_cache()
462 def test_ap_vht_on_24ghz(dev, apdev):
463 """Subset of VHT features on 2.4 GHz"""
465 params = { "ssid": "test-vht-2g",
470 "vht_capab": "[MAX-MPDU-11454]",
471 "vht_oper_chwidth": "0",
472 "vht_oper_centr_freq_seg0_idx": "1"
474 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
476 if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
477 raise Exception("Failed to add vendor element")
478 dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
479 hwsim_utils.test_connectivity(dev[0], hapd)
480 sta = hapd.get_sta(dev[0].own_addr())
481 if '[VENDOR_VHT]' not in sta['flags']:
482 raise Exception("No VENDOR_VHT STA flag")
484 dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
485 sta = hapd.get_sta(dev[1].own_addr())
486 if '[VENDOR_VHT]' in sta['flags']:
487 raise Exception("Unexpected VENDOR_VHT STA flag")
489 dev[0].request("VENDOR_ELEM_REMOVE 13 *")
491 def test_prefer_vht40(dev, apdev):
492 """Preference on VHT40 over HT40"""
496 params = { "ssid": "test",
497 "country_code": "FI",
501 "ht_capab": "[HT40+]" }
502 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
503 bssid = apdev[0]['bssid']
505 params = { "ssid": "test",
506 "country_code": "FI",
511 "ht_capab": "[HT40+]",
513 "vht_oper_chwidth": "0",
514 "vht_oper_centr_freq_seg0_idx": "0",
516 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
517 bssid2 = apdev[1]['bssid']
519 dev[0].scan_for_bss(bssid, freq=5180)
520 dev[0].scan_for_bss(bssid2, freq=5180)
521 dev[0].connect("test", scan_freq="5180", key_mgmt="NONE")
522 if dev[0].get_status_field('bssid') != bssid2:
523 raise Exception("Unexpected BSS selected")
525 est = dev[0].get_bss(bssid)['est_throughput']
527 raise Exception("Unexpected BSS0 est_throughput: " + est)
529 est = dev[0].get_bss(bssid2)['est_throughput']
531 raise Exception("Unexpected BSS1 est_throughput: " + est)
533 dev[0].request("DISCONNECT")
535 hapd2.request("DISABLE")
536 subprocess.call(['iw', 'reg', 'set', '00'])
537 dev[0].flush_scan_cache()