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()
13 from utils import skip_with_fips
14 from test_ap_ht import clear_scan_cache
16 def force_prev_ap_on_24g(ap):
17 # For now, make sure the last operating channel was on 2.4 GHz band to get
18 # sufficient survey data from mac80211_hwsim.
19 hostapd.add_ap(ap['ifname'], { "ssid": "open" })
21 hapd_global = hostapd.HostapdGlobal()
22 hapd_global.remove(ap['ifname'])
24 def force_prev_ap_on_5g(ap):
25 # For now, make sure the last operating channel was on 5 GHz band to get
26 # sufficient survey data from mac80211_hwsim.
27 hostapd.add_ap(ap['ifname'], { "ssid": "open", "hw_mode": "a",
28 "channel": "36", "country_code": "US" })
30 hapd_global = hostapd.HostapdGlobal()
31 hapd_global.remove(ap['ifname'])
34 ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
35 "AP-ENABLED", "AP-DISABLED"], timeout=5)
37 raise Exception("ACS start timed out")
38 if "ACS-STARTED" not in ev:
39 raise Exception("Unexpected ACS event: " + ev)
41 state = hapd.get_status_field("state")
43 raise Exception("Unexpected interface state")
45 ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
46 "AP-DISABLED"], timeout=20)
48 raise Exception("ACS timed out")
49 if "ACS-COMPLETED" not in ev:
50 raise Exception("Unexpected ACS event: " + ev)
52 ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
54 raise Exception("AP setup timed out")
55 if "AP-ENABLED" not in ev:
56 raise Exception("Unexpected ACS event: " + ev)
58 state = hapd.get_status_field("state")
59 if state != "ENABLED":
60 raise Exception("Unexpected interface state")
62 def test_ap_acs(dev, apdev):
63 """Automatic channel selection"""
64 force_prev_ap_on_24g(apdev[0])
65 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
66 params['channel'] = '0'
67 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
70 freq = hapd.get_status_field("freq")
72 raise Exception("Unexpected frequency")
74 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
76 def test_ap_acs_chanlist(dev, apdev):
77 """Automatic channel selection with chanlist set"""
78 force_prev_ap_on_24g(apdev[0])
79 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
80 params['channel'] = '0'
81 params['chanlist'] = '1 6 11'
82 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
85 freq = hapd.get_status_field("freq")
87 raise Exception("Unexpected frequency")
89 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
91 def test_ap_multi_bss_acs(dev, apdev):
92 """hostapd start with a multi-BSS configuration file using ACS"""
93 skip_with_fips(dev[0])
94 ifname = apdev[0]['ifname']
95 force_prev_ap_on_24g(apdev[0])
97 # start the actual test
98 hostapd.add_iface(ifname, 'multi-bss-acs.conf')
99 hapd = hostapd.Hostapd(ifname)
103 freq = hapd.get_status_field("freq")
105 raise Exception("Unexpected frequency")
107 dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
108 dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
109 dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
111 def test_ap_acs_40mhz(dev, apdev):
112 """Automatic channel selection for 40 MHz channel"""
113 clear_scan_cache(apdev[0]['ifname'])
114 force_prev_ap_on_24g(apdev[0])
115 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
116 params['channel'] = '0'
117 params['ht_capab'] = '[HT40+]'
118 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
121 freq = hapd.get_status_field("freq")
123 raise Exception("Unexpected frequency")
124 sec = hapd.get_status_field("secondary_channel")
126 raise Exception("Secondary channel not set")
128 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
130 def test_ap_acs_5ghz(dev, apdev):
131 """Automatic channel selection on 5 GHz"""
134 force_prev_ap_on_5g(apdev[0])
135 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
136 params['hw_mode'] = 'a'
137 params['channel'] = '0'
138 params['country_code'] = 'US'
139 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
141 freq = hapd.get_status_field("freq")
143 raise Exception("Unexpected frequency")
145 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
148 dev[0].request("DISCONNECT")
150 hapd.request("DISABLE")
151 subprocess.call(['iw', 'reg', 'set', '00'])
152 dev[0].flush_scan_cache()
154 def test_ap_acs_5ghz_40mhz(dev, apdev):
155 """Automatic channel selection on 5 GHz for 40 MHz channel"""
158 force_prev_ap_on_5g(apdev[0])
159 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
160 params['hw_mode'] = 'a'
161 params['channel'] = '0'
162 params['ht_capab'] = '[HT40+]'
163 params['country_code'] = 'US'
164 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
166 freq = hapd.get_status_field("freq")
168 raise Exception("Unexpected frequency")
170 sec = hapd.get_status_field("secondary_channel")
172 raise Exception("Secondary channel not set")
174 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
177 dev[0].request("DISCONNECT")
179 hapd.request("DISABLE")
180 subprocess.call(['iw', 'reg', 'set', '00'])
181 dev[0].flush_scan_cache()
183 def test_ap_acs_vht(dev, apdev):
184 """Automatic channel selection for VHT"""
187 force_prev_ap_on_5g(apdev[0])
188 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
189 params['hw_mode'] = 'a'
190 params['channel'] = '0'
191 params['ht_capab'] = '[HT40+]'
192 params['country_code'] = 'US'
193 params['ieee80211ac'] = '1'
194 params['vht_oper_chwidth'] = '1'
195 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
197 freq = hapd.get_status_field("freq")
199 raise Exception("Unexpected frequency")
201 sec = hapd.get_status_field("secondary_channel")
203 raise Exception("Secondary channel not set")
205 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
208 dev[0].request("DISCONNECT")
210 hapd.request("DISABLE")
211 subprocess.call(['iw', 'reg', 'set', '00'])
212 dev[0].flush_scan_cache()
214 def test_ap_acs_bias(dev, apdev):
215 """Automatic channel selection with bias values"""
216 force_prev_ap_on_24g(apdev[0])
217 params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
218 params['channel'] = '0'
219 params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
220 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
223 freq = hapd.get_status_field("freq")
225 raise Exception("Unexpected frequency")
227 dev[0].connect("test-acs", psk="12345678", scan_freq=freq)