Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / 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 utils import HwsimSkip
16 from test_dfs import wait_dfs_event
17 from test_ap_csa import csa_supported
18
19 def vht_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:
23         return True
24     return False
25
26 def test_ap_vht80(dev, apdev):
27     """VHT with 80 MHz channel width"""
28     try:
29         hapd = None
30         params = { "ssid": "vht",
31                    "country_code": "FI",
32                    "hw_mode": "a",
33                    "channel": "36",
34                    "ht_capab": "[HT40+]",
35                    "ieee80211n": "1",
36                    "ieee80211ac": "1",
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']
41
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']
45         if est != "390001":
46             raise Exception("Unexpected BSS est_throughput: " + est)
47     except Exception, e:
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")
51         raise
52     finally:
53         dev[0].request("DISCONNECT")
54         if hapd:
55             hapd.request("DISABLE")
56         subprocess.call(['iw', 'reg', 'set', '00'])
57         dev[0].flush_scan_cache()
58
59 def vht80_test(apdev, dev, channel, ht_capab):
60     try:
61         hapd = None
62         params = { "ssid": "vht",
63                    "country_code": "FI",
64                    "hw_mode": "a",
65                    "channel": str(channel),
66                    "ht_capab": ht_capab,
67                    "ieee80211n": "1",
68                    "ieee80211ac": "1",
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']
73
74         dev.connect("vht", key_mgmt="NONE", scan_freq=str(5000 + 5 * channel))
75         hwsim_utils.test_connectivity(dev, hapd)
76     except Exception, e:
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")
80         raise
81     finally:
82         dev.request("DISCONNECT")
83         if hapd:
84             hapd.request("DISABLE")
85         subprocess.call(['iw', 'reg', 'set', '00'])
86         dev.flush_scan_cache()
87
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-]")
91
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+]")
95
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-]")
99
100 def test_ap_vht80_params(dev, apdev):
101     """VHT with 80 MHz channel width and number of optional features enabled"""
102     try:
103         hapd = None
104         params = { "ssid": "vht",
105                    "country_code": "FI",
106                    "hw_mode": "a",
107                    "channel": "36",
108                    "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
109                    "ieee80211n": "1",
110                    "ieee80211ac": "1",
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",
114                    "require_vht": "1" }
115         hapd = hostapd.add_ap(apdev[0]['ifname'], params)
116
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"])
121         if ev is None:
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)
127     except Exception, e:
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")
131         raise
132     finally:
133         dev[0].request("DISCONNECT")
134         dev[1].request("DISCONNECT")
135         if hapd:
136             hapd.request("DISABLE")
137         subprocess.call(['iw', 'reg', 'set', '00'])
138         dev[0].flush_scan_cache()
139         dev[1].flush_scan_cache()
140
141 def test_ap_vht_20(devs, apdevs):
142     """VHT and 20 MHz channel"""
143     dev = devs[0]
144     ap = apdevs[0]
145     try:
146         hapd = None
147         params = { "ssid": "test-vht20",
148                    "country_code": "DE",
149                    "hw_mode": "a",
150                    "channel": "36",
151                    "ieee80211n": "1",
152                    "ieee80211ac": "1",
153                    "ht_capab": "",
154                    "vht_capab": "",
155                    "vht_oper_chwidth": "0",
156                    "vht_oper_centr_freq_seg0_idx": "0",
157                    "supported_rates": "60 120 240 360 480 540",
158                    "require_vht": "1",
159                  }
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)
163     finally:
164         dev.request("DISCONNECT")
165         if hapd:
166             hapd.request("DISABLE")
167         subprocess.call(['iw', 'reg', 'set', '00'])
168         dev.flush_scan_cache()
169
170 def test_ap_vht_40(devs, apdevs):
171     """VHT and 40 MHz channel"""
172     dev = devs[0]
173     ap = apdevs[0]
174     try:
175         hapd = None
176         params = { "ssid": "test-vht40",
177                    "country_code": "DE",
178                    "hw_mode": "a",
179                    "channel": "36",
180                    "ieee80211n": "1",
181                    "ieee80211ac": "1",
182                    "ht_capab": "[HT40+]",
183                    "vht_capab": "",
184                    "vht_oper_chwidth": "0",
185                    "vht_oper_centr_freq_seg0_idx": "0",
186                  }
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)
190     finally:
191         dev.request("DISCONNECT")
192         if hapd:
193             hapd.request("DISABLE")
194         subprocess.call(['iw', 'reg', 'set', '00'])
195         dev.flush_scan_cache()
196
197 def test_ap_vht_capab_not_supported(dev, apdev):
198     """VHT configuration with driver not supporting all vht_capab entries"""
199     try:
200         params = { "ssid": "vht",
201                    "country_code": "FI",
202                    "hw_mode": "a",
203                    "channel": "36",
204                    "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
205                    "ieee80211n": "1",
206                    "ieee80211ac": "1",
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",
210                    "require_vht": "1" }
211         hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
212         ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
213         if ev is None:
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")
218     finally:
219         subprocess.call(['iw', 'reg', 'set', '00'])
220
221 def test_ap_vht160(dev, apdev):
222     """VHT with 160 MHz channel width"""
223     try:
224         hapd = None
225         hapd2 = None
226         params = { "ssid": "vht",
227                    "country_code": "FI",
228                    "hw_mode": "a",
229                    "channel": "36",
230                    "ht_capab": "[HT40+]",
231                    "ieee80211n": "1",
232                    "ieee80211ac": "1",
233                    "vht_oper_chwidth": "2",
234                    "vht_oper_centr_freq_seg0_idx": "50",
235                    'ieee80211d': '1',
236                    'ieee80211h': '1' }
237         hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
238
239         ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
240         if "DFS-CAC-START" not in ev:
241             raise Exception("Unexpected DFS event")
242
243         state = hapd.get_status_field("state")
244         if state != "DFS":
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)
251
252         params = { "ssid": "vht2",
253                    "country_code": "FI",
254                    "hw_mode": "a",
255                    "channel": "104",
256                    "ht_capab": "[HT40-]",
257                    "ieee80211n": "1",
258                    "ieee80211ac": "1",
259                    "vht_oper_chwidth": "2",
260                    "vht_oper_centr_freq_seg0_idx": "114",
261                    'ieee80211d': '1',
262                    'ieee80211h': '1' }
263         hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
264
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)")
268
269         state = hapd2.get_status_field("state")
270         if state != "DFS":
271             raise Exception("Unexpected interface state(2): " + state)
272
273         logger.info("Waiting for CAC to complete")
274
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")
280
281         ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
282         if not ev:
283             raise Exception("AP setup timed out")
284
285         state = hapd.get_status_field("state")
286         if state != "ENABLED":
287             raise Exception("Unexpected interface state")
288
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)")
294
295         ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
296         if not ev:
297             raise Exception("AP setup timed out(2)")
298
299         state = hapd2.get_status_field("state")
300         if state != "ENABLED":
301             raise Exception("Unexpected interface state(2)")
302
303         freq = hapd2.get_status_field("freq")
304         if freq != "5520":
305             raise Exception("Unexpected frequency(2)")
306
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))
321     except Exception, e:
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")
325         raise
326     finally:
327         dev[0].request("DISCONNECT")
328         dev[1].request("DISCONNECT")
329         if hapd:
330             hapd.request("DISABLE")
331         if hapd2:
332             hapd2.request("DISABLE")
333         subprocess.call(['iw', 'reg', 'set', '00'])
334         dev[0].flush_scan_cache()
335         dev[1].flush_scan_cache()
336
337 def test_ap_vht80plus80(dev, apdev):
338     """VHT with 80+80 MHz channel width"""
339     try:
340         hapd = None
341         hapd2 = None
342         params = { "ssid": "vht",
343                    "country_code": "US",
344                    "hw_mode": "a",
345                    "channel": "52",
346                    "ht_capab": "[HT40+]",
347                    "ieee80211n": "1",
348                    "ieee80211ac": "1",
349                    "vht_oper_chwidth": "3",
350                    "vht_oper_centr_freq_seg0_idx": "58",
351                    "vht_oper_centr_freq_seg1_idx": "155",
352                    'ieee80211d': '1',
353                    'ieee80211h': '1' }
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
358
359         params = { "ssid": "vht2",
360                    "country_code": "US",
361                    "hw_mode": "a",
362                    "channel": "36",
363                    "ht_capab": "[HT40+]",
364                    "ieee80211n": "1",
365                    "ieee80211ac": "1",
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)
370
371         ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
372         if not ev:
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")
377
378         state = hapd2.get_status_field("state")
379         if state != "ENABLED":
380             raise Exception("Unexpected interface state(2)")
381
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))
393     except Exception, e:
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")
397         raise
398     finally:
399         dev[0].request("DISCONNECT")
400         dev[1].request("DISCONNECT")
401         if hapd:
402             hapd.request("DISABLE")
403         if hapd2:
404             hapd2.request("DISABLE")
405         subprocess.call(['iw', 'reg', 'set', '00'])
406         dev[0].flush_scan_cache()
407         dev[1].flush_scan_cache()
408
409 def test_ap_vht80_csa(dev, apdev):
410     """VHT with 80 MHz channel width and CSA"""
411     csa_supported(dev[0])
412     try:
413         hapd = None
414         params = { "ssid": "vht",
415                    "country_code": "US",
416                    "hw_mode": "a",
417                    "channel": "149",
418                    "ht_capab": "[HT40+]",
419                    "ieee80211n": "1",
420                    "ieee80211ac": "1",
421                    "vht_oper_chwidth": "1",
422                    "vht_oper_centr_freq_seg0_idx": "155" }
423         hapd = hostapd.add_ap(apdev[0]['ifname'], params)
424
425         dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
426         hwsim_utils.test_connectivity(dev[0], hapd)
427
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)
430         if ev is None:
431             raise Exception("CSA finished event timed out")
432         if "freq=5180" not in ev:
433             raise Exception("Unexpected channel in CSA finished event")
434         time.sleep(0.5)
435         hwsim_utils.test_connectivity(dev[0], hapd)
436
437         hapd.request("CHAN_SWITCH 5 5745")
438         ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
439         if ev is None:
440             raise Exception("CSA finished event timed out")
441         if "freq=5745" not in ev:
442             raise Exception("Unexpected channel in CSA finished event")
443         time.sleep(0.5)
444         hwsim_utils.test_connectivity(dev[0], hapd)
445
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)
450     except Exception, e:
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")
454         raise
455     finally:
456         dev[0].request("DISCONNECT")
457         if hapd:
458             hapd.request("DISABLE")
459         subprocess.call(['iw', 'reg', 'set', '00'])
460         dev[0].flush_scan_cache()
461
462 def test_ap_vht_on_24ghz(dev, apdev):
463     """Subset of VHT features on 2.4 GHz"""
464     hapd = None
465     params = { "ssid": "test-vht-2g",
466                "hw_mode": "g",
467                "channel": "1",
468                "ieee80211n": "1",
469                "vendor_vht": "1",
470                "vht_capab": "[MAX-MPDU-11454]",
471                "vht_oper_chwidth": "0",
472                "vht_oper_centr_freq_seg0_idx": "1"
473     }
474     hapd = hostapd.add_ap(apdev[0]['ifname'], params)
475     try:
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")
483
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")
488     finally:
489         dev[0].request("VENDOR_ELEM_REMOVE 13 *")
490
491 def test_prefer_vht40(dev, apdev):
492     """Preference on VHT40 over HT40"""
493     try:
494         hapd2 = None
495
496         params = { "ssid": "test",
497                    "country_code": "FI",
498                    "hw_mode": "a",
499                    "channel": "36",
500                    "ieee80211n": "1",
501                    "ht_capab": "[HT40+]" }
502         hapd = hostapd.add_ap(apdev[0]['ifname'], params)
503         bssid = apdev[0]['bssid']
504
505         params = { "ssid": "test",
506                    "country_code": "FI",
507                    "hw_mode": "a",
508                    "channel": "36",
509                    "ieee80211n": "1",
510                    "ieee80211ac": "1",
511                    "ht_capab": "[HT40+]",
512                    "vht_capab": "",
513                    "vht_oper_chwidth": "0",
514                    "vht_oper_centr_freq_seg0_idx": "0",
515                  }
516         hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
517         bssid2 = apdev[1]['bssid']
518
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")
524
525         est = dev[0].get_bss(bssid)['est_throughput']
526         if est != "135000":
527             raise Exception("Unexpected BSS0 est_throughput: " + est)
528
529         est = dev[0].get_bss(bssid2)['est_throughput']
530         if est != "135001":
531             raise Exception("Unexpected BSS1 est_throughput: " + est)
532     finally:
533         dev[0].request("DISCONNECT")
534         if hapd2:
535             hapd2.request("DISABLE")
536         subprocess.call(['iw', 'reg', 'set', '00'])
537         dev[0].flush_scan_cache()