1 # Test cases for automatic channel selection with hostapd
2 # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
12 from utils import skip_with_fips
13 from test_ap_ht import clear_scan_cache
15 def force_prev_ap_on_24g(ap):
16 # For now, make sure the last operating channel was on 2.4 GHz band to get
17 # sufficient survey data from mac80211_hwsim.
18 hostapd.add_ap(ap, { "ssid": "open" })
20 hostapd.remove_bss(ap)
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, { "ssid": "open", "hw_mode": "a",
26 "channel": "36", "country_code": "US" })
28 hostapd.remove_bss(ap)
31 ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
32 "AP-ENABLED", "AP-DISABLED"], timeout=5)
34 raise Exception("ACS start timed out")
35 if "ACS-STARTED" not in ev:
36 raise Exception("Unexpected ACS event: " + ev)
38 state = hapd.get_status_field("state")
40 raise Exception("Unexpected interface state")
42 ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
43 "AP-DISABLED"], timeout=20)
45 raise Exception("ACS timed out")
46 if "ACS-COMPLETED" not in ev:
47 raise Exception("Unexpected ACS event: " + ev)
49 ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
51 raise Exception("AP setup timed out")
52 if "AP-ENABLED" not in ev:
53 raise Exception("Unexpected ACS event: " + ev)
55 state = hapd.get_status_field("state")
56 if state != "ENABLED":
57 raise Exception("Unexpected interface state")
59 def test_ap_acs(dev, apdev):
60 """Automatic channel selection"""
61 force_prev_ap_on_24g(apdev[0])
62 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
63 params['channel'] = '0'
64 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
67 freq = hapd.get_status_field("freq")
69 raise Exception("Unexpected frequency")
71 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
73 def test_ap_acs_chanlist(dev, apdev):
74 """Automatic channel selection with chanlist set"""
75 force_prev_ap_on_24g(apdev[0])
76 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
77 params['channel'] = '0'
78 params['chanlist'] = '1 6 11'
79 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
82 freq = hapd.get_status_field("freq")
84 raise Exception("Unexpected frequency")
86 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
88 def test_ap_multi_bss_acs(dev, apdev):
89 """hostapd start with a multi-BSS configuration file using ACS"""
90 skip_with_fips(dev[0])
91 force_prev_ap_on_24g(apdev[0])
93 # start the actual test
94 hapd = hostapd.add_iface(apdev[0], 'multi-bss-acs.conf')
98 freq = hapd.get_status_field("freq")
100 raise Exception("Unexpected frequency")
102 dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
103 dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
104 dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
106 def test_ap_acs_40mhz(dev, apdev):
107 """Automatic channel selection for 40 MHz channel"""
108 clear_scan_cache(apdev[0])
109 force_prev_ap_on_24g(apdev[0])
110 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
111 params['channel'] = '0'
112 params['ht_capab'] = '[HT40+]'
113 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
116 freq = hapd.get_status_field("freq")
118 raise Exception("Unexpected frequency")
119 sec = hapd.get_status_field("secondary_channel")
121 raise Exception("Secondary channel not set")
123 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
125 def test_ap_acs_5ghz(dev, apdev):
126 """Automatic channel selection on 5 GHz"""
129 force_prev_ap_on_5g(apdev[0])
130 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
131 params['hw_mode'] = 'a'
132 params['channel'] = '0'
133 params['country_code'] = 'US'
134 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
136 freq = hapd.get_status_field("freq")
138 raise Exception("Unexpected frequency")
140 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
143 dev[0].request("DISCONNECT")
145 hapd.request("DISABLE")
146 hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
147 dev[0].flush_scan_cache()
149 def test_ap_acs_5ghz_40mhz(dev, apdev):
150 """Automatic channel selection on 5 GHz for 40 MHz channel"""
153 force_prev_ap_on_5g(apdev[0])
154 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
155 params['hw_mode'] = 'a'
156 params['channel'] = '0'
157 params['ht_capab'] = '[HT40+]'
158 params['country_code'] = 'US'
159 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
161 freq = hapd.get_status_field("freq")
163 raise Exception("Unexpected frequency")
165 sec = hapd.get_status_field("secondary_channel")
167 raise Exception("Secondary channel not set")
169 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
172 dev[0].request("DISCONNECT")
174 hapd.request("DISABLE")
175 hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
176 dev[0].flush_scan_cache()
178 def test_ap_acs_vht(dev, apdev):
179 """Automatic channel selection for VHT"""
182 force_prev_ap_on_5g(apdev[0])
183 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
184 params['hw_mode'] = 'a'
185 params['channel'] = '0'
186 params['ht_capab'] = '[HT40+]'
187 params['country_code'] = 'US'
188 params['ieee80211ac'] = '1'
189 params['vht_oper_chwidth'] = '1'
190 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
192 freq = hapd.get_status_field("freq")
194 raise Exception("Unexpected frequency")
196 sec = hapd.get_status_field("secondary_channel")
198 raise Exception("Secondary channel not set")
200 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
203 dev[0].request("DISCONNECT")
205 hapd.request("DISABLE")
206 hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
207 dev[0].flush_scan_cache()
209 def test_ap_acs_bias(dev, apdev):
210 """Automatic channel selection with bias values"""
211 force_prev_ap_on_24g(apdev[0])
212 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
213 params['channel'] = '0'
214 params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
215 hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
218 freq = hapd.get_status_field("freq")
220 raise Exception("Unexpected frequency")
222 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)