]>
Commit | Line | Data |
---|---|---|
b47750be | 1 | # Test cases for automatic channel selection with hostapd |
ce5d69ac | 2 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
b47750be JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import logging | |
8 | logger = logging.getLogger() | |
b0159308 | 9 | import subprocess |
ce5d69ac | 10 | import time |
b47750be JM |
11 | |
12 | import hostapd | |
13 | ||
19ec6070 JM |
14 | def force_prev_ap_on_24g(ap): |
15 | # For now, make sure the last operating channel was on 2.4 GHz band to get | |
16 | # sufficient survey data from mac80211_hwsim. | |
17 | hostapd.add_ap(ap['ifname'], { "ssid": "open" }) | |
18 | time.sleep(0.1) | |
19 | hapd_global = hostapd.HostapdGlobal() | |
20 | hapd_global.remove(ap['ifname']) | |
21 | ||
22 | def force_prev_ap_on_5g(ap): | |
23 | # For now, make sure the last operating channel was on 5 GHz band to get | |
24 | # sufficient survey data from mac80211_hwsim. | |
25 | hostapd.add_ap(ap['ifname'], { "ssid": "open", "hw_mode": "a", | |
26 | "channel": "36", "country_code": "US" }) | |
27 | time.sleep(0.1) | |
28 | hapd_global = hostapd.HostapdGlobal() | |
29 | hapd_global.remove(ap['ifname']) | |
30 | ||
b47750be JM |
31 | def wait_acs(hapd): |
32 | ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED", | |
b0159308 | 33 | "AP-ENABLED", "AP-DISABLED"], timeout=5) |
b47750be JM |
34 | if not ev: |
35 | raise Exception("ACS start timed out") | |
36 | if "ACS-STARTED" not in ev: | |
b0159308 | 37 | raise Exception("Unexpected ACS event: " + ev) |
b47750be JM |
38 | |
39 | state = hapd.get_status_field("state") | |
40 | if state != "ACS": | |
41 | raise Exception("Unexpected interface state") | |
42 | ||
b0159308 JM |
43 | ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED", |
44 | "AP-DISABLED"], timeout=20) | |
b47750be JM |
45 | if not ev: |
46 | raise Exception("ACS timed out") | |
47 | if "ACS-COMPLETED" not in ev: | |
b0159308 | 48 | raise Exception("Unexpected ACS event: " + ev) |
b47750be | 49 | |
b0159308 | 50 | ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5) |
b47750be JM |
51 | if not ev: |
52 | raise Exception("AP setup timed out") | |
b0159308 JM |
53 | if "AP-ENABLED" not in ev: |
54 | raise Exception("Unexpected ACS event: " + ev) | |
b47750be JM |
55 | |
56 | state = hapd.get_status_field("state") | |
57 | if state != "ENABLED": | |
58 | raise Exception("Unexpected interface state") | |
59 | ||
60 | def test_ap_acs(dev, apdev): | |
61 | """Automatic channel selection""" | |
19ec6070 | 62 | force_prev_ap_on_24g(apdev[0]) |
b47750be JM |
63 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
64 | params['channel'] = '0' | |
629dbdd3 | 65 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) |
b47750be JM |
66 | wait_acs(hapd) |
67 | ||
68 | freq = hapd.get_status_field("freq") | |
69 | if int(freq) < 2400: | |
70 | raise Exception("Unexpected frequency") | |
71 | ||
72 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) | |
73 | ||
74 | def test_ap_multi_bss_acs(dev, apdev): | |
75 | """hostapd start with a multi-BSS configuration file using ACS""" | |
76 | ifname = apdev[0]['ifname'] | |
19ec6070 | 77 | force_prev_ap_on_24g(apdev[0]) |
ce5d69ac JM |
78 | |
79 | # start the actual test | |
b47750be JM |
80 | hostapd.add_iface(ifname, 'multi-bss-acs.conf') |
81 | hapd = hostapd.Hostapd(ifname) | |
82 | hapd.enable() | |
83 | wait_acs(hapd) | |
84 | ||
85 | freq = hapd.get_status_field("freq") | |
86 | if int(freq) < 2400: | |
87 | raise Exception("Unexpected frequency") | |
88 | ||
89 | dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq) | |
90 | dev[1].connect("bss-2", psk="12345678", scan_freq=freq) | |
91 | dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq) | |
b0159308 JM |
92 | |
93 | def test_ap_acs_40mhz(dev, apdev): | |
94 | """Automatic channel selection for 40 MHz channel""" | |
19ec6070 | 95 | force_prev_ap_on_24g(apdev[0]) |
b0159308 JM |
96 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
97 | params['channel'] = '0' | |
98 | params['ht_capab'] = '[HT40+]' | |
99 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) | |
100 | wait_acs(hapd) | |
101 | ||
102 | freq = hapd.get_status_field("freq") | |
103 | if int(freq) < 2400: | |
104 | raise Exception("Unexpected frequency") | |
105 | sec = hapd.get_status_field("secondary_channel") | |
106 | if int(sec) == 0: | |
107 | raise Exception("Secondary channel not set") | |
108 | ||
109 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) | |
110 | ||
111 | def test_ap_acs_5ghz(dev, apdev): | |
112 | """Automatic channel selection on 5 GHz""" | |
113 | try: | |
9d7fdac5 | 114 | hapd = None |
19ec6070 | 115 | force_prev_ap_on_5g(apdev[0]) |
b0159308 JM |
116 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
117 | params['hw_mode'] = 'a' | |
118 | params['channel'] = '0' | |
119 | params['country_code'] = 'US' | |
120 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) | |
19ec6070 JM |
121 | wait_acs(hapd) |
122 | freq = hapd.get_status_field("freq") | |
123 | if int(freq) < 5000: | |
124 | raise Exception("Unexpected frequency") | |
125 | ||
126 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) | |
b0159308 JM |
127 | |
128 | finally: | |
9d7fdac5 JM |
129 | dev[0].request("DISCONNECT") |
130 | if hapd: | |
131 | hapd.request("DISABLE") | |
c4668009 | 132 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 133 | dev[0].flush_scan_cache() |
b0159308 JM |
134 | |
135 | def test_ap_acs_5ghz_40mhz(dev, apdev): | |
136 | """Automatic channel selection on 5 GHz for 40 MHz channel""" | |
137 | try: | |
9d7fdac5 | 138 | hapd = None |
19ec6070 | 139 | force_prev_ap_on_5g(apdev[0]) |
b0159308 JM |
140 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
141 | params['hw_mode'] = 'a' | |
142 | params['channel'] = '0' | |
143 | params['ht_capab'] = '[HT40+]' | |
144 | params['country_code'] = 'US' | |
145 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) | |
19ec6070 JM |
146 | wait_acs(hapd) |
147 | freq = hapd.get_status_field("freq") | |
148 | if int(freq) < 5000: | |
149 | raise Exception("Unexpected frequency") | |
150 | ||
151 | sec = hapd.get_status_field("secondary_channel") | |
152 | if int(sec) == 0: | |
153 | raise Exception("Secondary channel not set") | |
154 | ||
155 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) | |
b0159308 JM |
156 | |
157 | finally: | |
9d7fdac5 JM |
158 | dev[0].request("DISCONNECT") |
159 | if hapd: | |
160 | hapd.request("DISABLE") | |
c4668009 | 161 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 162 | dev[0].flush_scan_cache() |
b0159308 JM |
163 | |
164 | def test_ap_acs_vht(dev, apdev): | |
165 | """Automatic channel selection for VHT""" | |
166 | try: | |
9d7fdac5 | 167 | hapd = None |
19ec6070 | 168 | force_prev_ap_on_5g(apdev[0]) |
b0159308 JM |
169 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
170 | params['hw_mode'] = 'a' | |
171 | params['channel'] = '0' | |
172 | params['ht_capab'] = '[HT40+]' | |
173 | params['country_code'] = 'US' | |
174 | params['ieee80211ac'] = '1' | |
175 | params['vht_oper_chwidth'] = '1' | |
176 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) | |
19ec6070 JM |
177 | wait_acs(hapd) |
178 | freq = hapd.get_status_field("freq") | |
179 | if int(freq) < 5000: | |
180 | raise Exception("Unexpected frequency") | |
181 | ||
182 | sec = hapd.get_status_field("secondary_channel") | |
183 | if int(sec) == 0: | |
184 | raise Exception("Secondary channel not set") | |
185 | ||
186 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) | |
b0159308 JM |
187 | |
188 | finally: | |
9d7fdac5 JM |
189 | dev[0].request("DISCONNECT") |
190 | if hapd: | |
191 | hapd.request("DISABLE") | |
c4668009 | 192 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 193 | dev[0].flush_scan_cache() |
65013c93 JM |
194 | |
195 | def test_ap_acs_bias(dev, apdev): | |
196 | """Automatic channel selection with bias values""" | |
19ec6070 | 197 | force_prev_ap_on_24g(apdev[0]) |
65013c93 JM |
198 | params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678") |
199 | params['channel'] = '0' | |
200 | params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8' | |
201 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False) | |
202 | wait_acs(hapd) | |
203 | ||
204 | freq = hapd.get_status_field("freq") | |
205 | if int(freq) < 2400: | |
206 | raise Exception("Unexpected frequency") | |
207 | ||
208 | dev[0].connect("test-acs", psk="12345678", scan_freq=freq) |