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