]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_vht.py
tests: Channel switch with VHT80
[thirdparty/hostap.git] / 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 test_dfs import wait_dfs_event
16 from test_ap_csa import csa_supported
17
18 def vht_supported():
19 cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
20 reg = cmd.stdout.read()
21 if "@ 80)" in reg or "@ 160)" in reg:
22 return True
23 return False
24
25 def test_ap_vht80(dev, apdev):
26 """VHT with 80 MHz channel width"""
27 try:
28 params = { "ssid": "vht",
29 "country_code": "FI",
30 "hw_mode": "a",
31 "channel": "36",
32 "ht_capab": "[HT40+]",
33 "ieee80211n": "1",
34 "ieee80211ac": "1",
35 "vht_oper_chwidth": "1",
36 "vht_oper_centr_freq_seg0_idx": "42" }
37 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
38
39 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
40 hwsim_utils.test_connectivity(dev[0], hapd)
41 except Exception, e:
42 if isinstance(e, Exception) and str(e) == "AP startup failed":
43 if not vht_supported():
44 logger.info("80 MHz channel not supported in regulatory information")
45 return "skip"
46 raise
47 finally:
48 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
49
50 def test_ap_vht80_params(dev, apdev):
51 """VHT with 80 MHz channel width and number of optional features enabled"""
52 try:
53 params = { "ssid": "vht",
54 "country_code": "FI",
55 "hw_mode": "a",
56 "channel": "36",
57 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
58 "ieee80211n": "1",
59 "ieee80211ac": "1",
60 "vht_oper_chwidth": "1",
61 "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
62 "vht_oper_centr_freq_seg0_idx": "42",
63 "require_vht": "1" }
64 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
65
66 dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
67 disable_vht="1", wait_connect=False)
68 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
69 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
70 if ev is None:
71 raise Exception("Association rejection timed out")
72 if "status_code=104" not in ev:
73 raise Exception("Unexpected rejection status code")
74 dev[1].request("DISCONNECT")
75 hwsim_utils.test_connectivity(dev[0], hapd)
76 except Exception, e:
77 if isinstance(e, Exception) and str(e) == "AP startup failed":
78 if not vht_supported():
79 logger.info("80 MHz channel not supported in regulatory information")
80 return "skip"
81 raise
82 finally:
83 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
84
85 def test_ap_vht_20(devs, apdevs):
86 dev = devs[0]
87 ap = apdevs[0]
88 try:
89 params = { "ssid": "test-vht20",
90 "country_code": "DE",
91 "hw_mode": "a",
92 "channel": "36",
93 "ieee80211n": "1",
94 "ieee80211ac": "1",
95 "ht_capab": "",
96 "vht_capab": "",
97 "vht_oper_chwidth": "0",
98 "vht_oper_centr_freq_seg0_idx": "0",
99 "supported_rates": "60 120 240 360 480 540",
100 "require_vht": "1",
101 }
102 hapd = hostapd.add_ap(ap['ifname'], params)
103 dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
104 hwsim_utils.test_connectivity(dev, hapd)
105 finally:
106 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
107
108 def test_ap_vht_capab_not_supported(dev, apdev):
109 """VHT configuration with driver not supporting all vht_capab entries"""
110 try:
111 params = { "ssid": "vht",
112 "country_code": "FI",
113 "hw_mode": "a",
114 "channel": "36",
115 "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
116 "ieee80211n": "1",
117 "ieee80211ac": "1",
118 "vht_oper_chwidth": "1",
119 "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]",
120 "vht_oper_centr_freq_seg0_idx": "42",
121 "require_vht": "1" }
122 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
123 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
124 if ev is None:
125 raise Exception("Startup failure not reported")
126 for i in range(1, 7):
127 if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
128 raise Exception("Unexpected SET failure")
129 finally:
130 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
131
132 def test_ap_vht160(dev, apdev):
133 """VHT with 160 MHz channel width"""
134 try:
135 params = { "ssid": "vht",
136 "country_code": "FI",
137 "hw_mode": "a",
138 "channel": "36",
139 "ht_capab": "[HT40+]",
140 "ieee80211n": "1",
141 "ieee80211ac": "1",
142 "vht_oper_chwidth": "2",
143 "vht_oper_centr_freq_seg0_idx": "50",
144 'ieee80211d': '1',
145 'ieee80211h': '1' }
146 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
147
148 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
149 if "DFS-CAC-START" not in ev:
150 raise Exception("Unexpected DFS event")
151
152 state = hapd.get_status_field("state")
153 if state != "DFS":
154 if state == "DISABLED" and not os.path.exists("dfs"):
155 # Not all systems have recent enough CRDA version and
156 # wireless-regdb changes to support 160 MHz and DFS. For now,
157 # do not report failures for this test case.
158 return "skip"
159 raise Exception("Unexpected interface state: " + state)
160
161 params = { "ssid": "vht2",
162 "country_code": "FI",
163 "hw_mode": "a",
164 "channel": "100",
165 "ht_capab": "[HT40+]",
166 "ieee80211n": "1",
167 "ieee80211ac": "1",
168 "vht_oper_chwidth": "2",
169 "vht_oper_centr_freq_seg0_idx": "114",
170 'ieee80211d': '1',
171 'ieee80211h': '1' }
172 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
173
174 ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
175 if "DFS-CAC-START" not in ev:
176 raise Exception("Unexpected DFS event(2)")
177
178 state = hapd2.get_status_field("state")
179 if state != "DFS":
180 raise Exception("Unexpected interface state(2): " + state)
181
182 logger.info("Waiting for CAC to complete")
183
184 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
185 if "success=1" not in ev:
186 raise Exception("CAC failed")
187 if "freq=5180" not in ev:
188 raise Exception("Unexpected DFS freq result")
189
190 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
191 if not ev:
192 raise Exception("AP setup timed out")
193
194 state = hapd.get_status_field("state")
195 if state != "ENABLED":
196 raise Exception("Unexpected interface state")
197
198 ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
199 if "success=1" not in ev:
200 raise Exception("CAC failed(2)")
201 if "freq=5500" not in ev:
202 raise Exception("Unexpected DFS freq result(2)")
203
204 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
205 if not ev:
206 raise Exception("AP setup timed out(2)")
207
208 state = hapd2.get_status_field("state")
209 if state != "ENABLED":
210 raise Exception("Unexpected interface state(2)")
211
212 freq = hapd2.get_status_field("freq")
213 if freq != "5500":
214 raise Exception("Unexpected frequency(2)")
215
216 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
217 hwsim_utils.test_connectivity(dev[0], hapd)
218 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
219 hwsim_utils.test_connectivity(dev[1], hapd2)
220 except Exception, e:
221 if isinstance(e, Exception) and str(e) == "AP startup failed":
222 if not vht_supported():
223 logger.info("80/160 MHz channel not supported in regulatory information")
224 return "skip"
225 raise
226 finally:
227 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
228
229 def test_ap_vht80plus80(dev, apdev):
230 """VHT with 80+80 MHz channel width"""
231 try:
232 params = { "ssid": "vht",
233 "country_code": "US",
234 "hw_mode": "a",
235 "channel": "52",
236 "ht_capab": "[HT40+]",
237 "ieee80211n": "1",
238 "ieee80211ac": "1",
239 "vht_oper_chwidth": "3",
240 "vht_oper_centr_freq_seg0_idx": "58",
241 "vht_oper_centr_freq_seg1_idx": "155",
242 'ieee80211d': '1',
243 'ieee80211h': '1' }
244 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
245 # This will actually fail since DFS on 80+80 is not yet supported
246 ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
247 # ignore result to avoid breaking the test once 80+80 DFS gets enabled
248
249 params = { "ssid": "vht2",
250 "country_code": "US",
251 "hw_mode": "a",
252 "channel": "36",
253 "ht_capab": "[HT40+]",
254 "ieee80211n": "1",
255 "ieee80211ac": "1",
256 "vht_oper_chwidth": "3",
257 "vht_oper_centr_freq_seg0_idx": "42",
258 "vht_oper_centr_freq_seg1_idx": "155" }
259 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
260
261 ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
262 if not ev:
263 raise Exception("AP setup timed out(2)")
264
265 state = hapd2.get_status_field("state")
266 if state != "ENABLED":
267 raise Exception("Unexpected interface state(2)")
268
269 dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
270 hwsim_utils.test_connectivity(dev[1], hapd2)
271 except Exception, e:
272 if isinstance(e, Exception) and str(e) == "AP startup failed":
273 if not vht_supported():
274 logger.info("80/160 MHz channel not supported in regulatory information")
275 return "skip"
276 raise
277 finally:
278 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
279
280 def test_ap_vht80_csa(dev, apdev):
281 """VHT with 80 MHz channel width and CSA"""
282 if not csa_supported(dev[0]):
283 return "skip"
284 try:
285 params = { "ssid": "vht",
286 "country_code": "US",
287 "hw_mode": "a",
288 "channel": "149",
289 "ht_capab": "[HT40+]",
290 "ieee80211n": "1",
291 "ieee80211ac": "1",
292 "vht_oper_chwidth": "1",
293 "vht_oper_centr_freq_seg0_idx": "155" }
294 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
295
296 dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
297 hwsim_utils.test_connectivity(dev[0], hapd)
298
299 hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
300 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
301 if ev is None:
302 raise Exception("CSA finished event timed out")
303 if "freq=5180" not in ev:
304 raise Exception("Unexpected channel in CSA finished event")
305 time.sleep(0.5)
306 hwsim_utils.test_connectivity(dev[0], hapd)
307
308 hapd.request("CHAN_SWITCH 5 5745")
309 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
310 if ev is None:
311 raise Exception("CSA finished event timed out")
312 if "freq=5745" not in ev:
313 raise Exception("Unexpected channel in CSA finished event")
314 time.sleep(0.5)
315 hwsim_utils.test_connectivity(dev[0], hapd)
316
317 # This CSA to same channel will fail in kernel, so use this only for
318 # extra code coverage.
319 hapd.request("CHAN_SWITCH 5 5745")
320 hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
321 except Exception, e:
322 if isinstance(e, Exception) and str(e) == "AP startup failed":
323 if not vht_supported():
324 logger.info("80 MHz channel not supported in regulatory information")
325 return "skip"
326 raise
327 finally:
328 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])