]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_acs.py
3cade3ca4ef82b57739f63e69ed2d83981d5dc62
1 # Test cases for automatic channel selection with hostapd
2 # Copyright (c) 2013-2018, 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
, alloc_fail
, fail_test
, HwsimSkip
, clear_regdom
13 from test_ap_ht
import clear_scan_cache
14 from test_dfs
import wait_dfs_event
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
, {"ssid": "open"})
21 hostapd
.remove_bss(ap
)
23 def force_prev_ap_on_5g(ap
):
24 # For now, make sure the last operating channel was on 5 GHz band to get
25 # sufficient survey data from mac80211_hwsim.
26 hostapd
.add_ap(ap
, {"ssid": "open", "hw_mode": "a",
27 "channel": "36", "country_code": "US"})
29 hostapd
.remove_bss(ap
)
31 def wait_acs(hapd
, return_after_acs
=False):
32 ev
= hapd
.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
33 "AP-ENABLED", "AP-DISABLED"], timeout
=5)
35 raise Exception("ACS start timed out")
36 if "ACS-STARTED" not in ev
:
37 raise Exception("Unexpected ACS event: " + ev
)
39 state
= hapd
.get_status_field("state")
41 raise Exception("Unexpected interface state")
43 ev
= hapd
.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
44 "AP-DISABLED"], timeout
=20)
46 raise Exception("ACS timed out")
47 if "ACS-COMPLETED" not in ev
:
48 raise Exception("Unexpected ACS event: " + ev
)
53 ev
= hapd
.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout
=5)
55 raise Exception("AP setup timed out")
56 if "AP-ENABLED" not in ev
:
57 raise Exception("Unexpected ACS event: " + ev
)
59 state
= hapd
.get_status_field("state")
60 if state
!= "ENABLED":
61 raise Exception("Unexpected interface state")
63 def test_ap_acs(dev
, apdev
):
64 """Automatic channel selection"""
65 force_prev_ap_on_24g(apdev
[0])
66 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
67 params
['channel'] = '0'
68 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
71 freq
= hapd
.get_status_field("freq")
73 raise Exception("Unexpected frequency")
75 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
77 def test_ap_acs_chanlist(dev
, apdev
):
78 """Automatic channel selection with chanlist set"""
79 force_prev_ap_on_24g(apdev
[0])
80 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
81 params
['channel'] = '0'
82 params
['chanlist'] = '1 6 11'
83 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
86 freq
= hapd
.get_status_field("freq")
88 raise Exception("Unexpected frequency")
90 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
92 def test_ap_acs_freqlist(dev
, apdev
):
93 """Automatic channel selection with freqlist set"""
94 force_prev_ap_on_24g(apdev
[0])
95 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
96 params
['channel'] = '0'
97 params
['freqlist'] = '2412 2437 2462'
98 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
101 freq
= int(hapd
.get_status_field("freq"))
102 if freq
not in [2412, 2437, 2462]:
103 raise Exception("Unexpected frequency: " + freq
)
105 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=str(freq
))
107 def test_ap_acs_invalid_chanlist(dev
, apdev
):
108 """Automatic channel selection with invalid chanlist"""
109 force_prev_ap_on_24g(apdev
[0])
110 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
111 params
['channel'] = '0'
112 params
['chanlist'] = '15-18'
113 hapd
= hostapd
.add_ap(apdev
[0], params
, no_enable
=True)
114 res
= hapd
.request("ENABLE")
116 raise Exception("ENABLE command succeeded unexpectedly")
118 def test_ap_multi_bss_acs(dev
, apdev
):
119 """hostapd start with a multi-BSS configuration file using ACS"""
120 skip_with_fips(dev
[0])
121 force_prev_ap_on_24g(apdev
[0])
123 # start the actual test
124 hapd
= hostapd
.add_iface(apdev
[0], 'multi-bss-acs.conf')
128 freq
= hapd
.get_status_field("freq")
130 raise Exception("Unexpected frequency")
132 dev
[0].connect("bss-1", key_mgmt
="NONE", scan_freq
=freq
)
133 dev
[1].connect("bss-2", psk
="12345678", scan_freq
=freq
)
134 dev
[2].connect("bss-3", psk
="qwertyuiop", scan_freq
=freq
)
136 def test_ap_acs_40mhz(dev
, apdev
):
137 """Automatic channel selection for 40 MHz channel"""
138 clear_scan_cache(apdev
[0])
139 force_prev_ap_on_24g(apdev
[0])
140 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
141 params
['channel'] = '0'
142 params
['ht_capab'] = '[HT40+]'
143 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
146 freq
= hapd
.get_status_field("freq")
148 raise Exception("Unexpected frequency")
149 sec
= hapd
.get_status_field("secondary_channel")
151 raise Exception("Secondary channel not set")
153 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
155 def test_ap_acs_40mhz_minus(dev
, apdev
):
156 """Automatic channel selection for HT40- channel"""
157 clear_scan_cache(apdev
[0])
158 force_prev_ap_on_24g(apdev
[0])
159 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
160 params
['channel'] = '0'
161 params
['ht_capab'] = '[HT40-]'
162 params
['acs_num_scans'] = '1'
163 params
['chanlist'] = '1 11'
164 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
165 ev
= hapd
.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout
=10)
167 raise Exception("ACS start timed out")
168 # HT40- is not currently supported in hostapd ACS, so do not try to connect
169 # or verify that this operation succeeded.
171 def test_ap_acs_5ghz(dev
, apdev
):
172 """Automatic channel selection on 5 GHz"""
175 force_prev_ap_on_5g(apdev
[0])
176 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
177 params
['hw_mode'] = 'a'
178 params
['channel'] = '0'
179 params
['country_code'] = 'US'
180 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
182 freq
= hapd
.get_status_field("freq")
184 raise Exception("Unexpected frequency")
186 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
187 dev
[0].wait_regdom(country_ie
=True)
189 clear_regdom(hapd
, dev
)
191 def test_ap_acs_5ghz_40mhz(dev
, apdev
):
192 """Automatic channel selection on 5 GHz for 40 MHz channel"""
195 force_prev_ap_on_5g(apdev
[0])
196 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
197 params
['hw_mode'] = 'a'
198 params
['channel'] = '0'
199 params
['ht_capab'] = '[HT40+]'
200 params
['country_code'] = 'US'
201 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
203 freq
= hapd
.get_status_field("freq")
205 raise Exception("Unexpected frequency")
207 sec
= hapd
.get_status_field("secondary_channel")
209 raise Exception("Secondary channel not set")
211 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
212 dev
[0].wait_regdom(country_ie
=True)
214 clear_regdom(hapd
, dev
)
216 def test_ap_acs_vht(dev
, apdev
):
217 """Automatic channel selection for VHT"""
220 force_prev_ap_on_5g(apdev
[0])
221 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
222 params
['hw_mode'] = 'a'
223 params
['channel'] = '0'
224 params
['ht_capab'] = '[HT40+]'
225 params
['country_code'] = 'US'
226 params
['ieee80211ac'] = '1'
227 params
['vht_oper_chwidth'] = '1'
228 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
230 freq
= hapd
.get_status_field("freq")
232 raise Exception("Unexpected frequency")
234 sec
= hapd
.get_status_field("secondary_channel")
236 raise Exception("Secondary channel not set")
238 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
239 dev
[0].wait_regdom(country_ie
=True)
241 clear_regdom(hapd
, dev
)
243 def test_ap_acs_vht40(dev
, apdev
):
244 """Automatic channel selection for VHT40"""
247 force_prev_ap_on_5g(apdev
[0])
248 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
249 params
['hw_mode'] = 'a'
250 params
['channel'] = '0'
251 params
['ht_capab'] = '[HT40+]'
252 params
['country_code'] = 'US'
253 params
['ieee80211ac'] = '1'
254 params
['vht_oper_chwidth'] = '0'
255 params
['acs_num_scans'] = '1'
256 params
['chanlist'] = '36 149'
257 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
259 freq
= hapd
.get_status_field("freq")
261 raise Exception("Unexpected frequency")
263 sec
= hapd
.get_status_field("secondary_channel")
265 raise Exception("Secondary channel not set")
267 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
268 dev
[0].wait_regdom(country_ie
=True)
270 clear_regdom(hapd
, dev
)
272 def test_ap_acs_vht160(dev
, apdev
):
273 """Automatic channel selection for VHT160"""
276 force_prev_ap_on_5g(apdev
[0])
277 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
278 params
['hw_mode'] = 'a'
279 params
['channel'] = '0'
280 params
['ht_capab'] = '[HT40+]'
281 params
['country_code'] = 'ZA'
282 params
['ieee80211ac'] = '1'
283 params
['vht_oper_chwidth'] = '2'
284 params
['ieee80211d'] = '1'
285 params
['ieee80211h'] = '1'
286 params
['chanlist'] = '100'
287 params
['acs_num_scans'] = '1'
288 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
289 ev
= hapd
.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout
=10)
291 raise Exception("ACS start timed out")
292 # VHT160 is not currently supported in hostapd ACS, so do not try to
293 # enforce successful AP start.
294 if "AP-ENABLED" in ev
:
295 freq
= hapd
.get_status_field("freq")
297 raise Exception("Unexpected frequency")
298 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
299 dev
[0].wait_regdom(country_ie
=True)
301 clear_regdom(hapd
, dev
)
303 def test_ap_acs_vht160_scan_disable(dev
, apdev
):
304 """Automatic channel selection for VHT160 and DISABLE during scan"""
305 force_prev_ap_on_5g(apdev
[0])
306 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
307 params
['hw_mode'] = 'a'
308 params
['channel'] = '0'
309 params
['ht_capab'] = '[HT40+]'
310 params
['country_code'] = 'ZA'
311 params
['ieee80211ac'] = '1'
312 params
['vht_oper_chwidth'] = '2'
313 params
["vht_oper_centr_freq_seg0_idx"] = "114"
314 params
['ieee80211d'] = '1'
315 params
['ieee80211h'] = '1'
316 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
318 clear_regdom(hapd
, dev
)
320 def test_ap_acs_bias(dev
, apdev
):
321 """Automatic channel selection with bias values"""
322 force_prev_ap_on_24g(apdev
[0])
323 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
324 params
['channel'] = '0'
325 params
['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
326 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
329 freq
= hapd
.get_status_field("freq")
331 raise Exception("Unexpected frequency")
333 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
335 def test_ap_acs_survey(dev
, apdev
):
336 """Automatic channel selection using acs_survey parameter"""
337 force_prev_ap_on_24g(apdev
[0])
338 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
339 params
['channel'] = 'acs_survey'
340 params
['acs_num_scans'] = '1'
341 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
344 freq
= hapd
.get_status_field("freq")
346 raise Exception("Unexpected frequency")
348 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=freq
)
350 def test_ap_acs_errors(dev
, apdev
):
351 """Automatic channel selection failures"""
352 clear_scan_cache(apdev
[0])
353 force_prev_ap_on_24g(apdev
[0])
354 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
355 params
['channel'] = '0'
356 params
['acs_num_scans'] = '2'
357 params
['chanlist'] = '1'
358 hapd
= hostapd
.add_ap(apdev
[0], params
, no_enable
=True)
360 with
alloc_fail(hapd
, 1, "acs_request_scan"):
361 if "FAIL" not in hapd
.request("ENABLE"):
362 raise Exception("Unexpected success for ENABLE")
365 with
fail_test(hapd
, 1, "acs_request_scan"):
366 if "FAIL" not in hapd
.request("ENABLE"):
367 raise Exception("Unexpected success for ENABLE")
370 with
fail_test(hapd
, 1, "acs_scan_complete"):
372 ev
= hapd
.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout
=10)
374 raise Exception("ACS start timed out")
377 with
fail_test(hapd
, 1, "acs_request_scan;acs_scan_complete"):
379 ev
= hapd
.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout
=10)
381 raise Exception("ACS start timed out")
383 def test_ap_acs_dfs(dev
, apdev
, params
):
384 """Automatic channel selection, HT scan, and DFS [long]"""
385 if not params
['long']:
386 raise HwsimSkip("Skip test case with long duration due to --long not specified")
389 force_prev_ap_on_5g(apdev
[0])
390 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
391 params
['hw_mode'] = 'a'
392 params
['channel'] = '0'
393 params
['ht_capab'] = '[HT40+]'
394 params
['country_code'] = 'US'
395 params
['ieee80211d'] = '1'
396 params
['ieee80211h'] = '1'
397 params
['acs_num_scans'] = '1'
398 params
['chanlist'] = '52 56 60 64'
399 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
400 wait_acs(hapd
, return_after_acs
=True)
402 wait_dfs_event(hapd
, "DFS-CAC-START", 5)
403 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
404 if "success=1" not in ev
:
405 raise Exception("CAC failed")
407 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
409 raise Exception("AP setup timed out")
411 state
= hapd
.get_status_field("state")
412 if state
!= "ENABLED":
413 raise Exception("Unexpected interface state")
415 freq
= int(hapd
.get_status_field("freq"))
416 if freq
not in [5260, 5280, 5300, 5320]:
417 raise Exception("Unexpected frequency: %d" % freq
)
419 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=str(freq
))
420 dev
[0].wait_regdom(country_ie
=True)
423 hapd
.request("DISABLE")
424 dev
[0].disconnect_and_stop_scan()
425 hostapd
.cmd_execute(apdev
[0], ['iw', 'reg', 'set', '00'])
426 dev
[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=0.5)
427 dev
[0].flush_scan_cache()
429 def test_ap_acs_exclude_dfs(dev
, apdev
, params
):
430 """Automatic channel selection, exclude DFS"""
433 force_prev_ap_on_5g(apdev
[0])
434 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
435 params
['hw_mode'] = 'a'
436 params
['channel'] = '0'
437 params
['ht_capab'] = '[HT40+]'
438 params
['country_code'] = 'US'
439 params
['ieee80211d'] = '1'
440 params
['ieee80211h'] = '1'
441 params
['acs_num_scans'] = '1'
442 params
['acs_exclude_dfs'] = '1'
443 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
446 state
= hapd
.get_status_field("state")
447 if state
!= "ENABLED":
448 raise Exception("Unexpected interface state")
450 freq
= int(hapd
.get_status_field("freq"))
451 if freq
in [5260, 5280, 5300, 5320,
452 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680]:
453 raise Exception("Unexpected frequency: %d" % freq
)
455 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=str(freq
))
456 dev
[0].wait_regdom(country_ie
=True)
459 hapd
.request("DISABLE")
460 dev
[0].disconnect_and_stop_scan()
461 hostapd
.cmd_execute(apdev
[0], ['iw', 'reg', 'set', '00'])
462 dev
[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=0.5)
463 dev
[0].flush_scan_cache()
465 def test_ap_acs_vht160_dfs(dev
, apdev
, params
):
466 """Automatic channel selection 160 MHz, HT scan, and DFS [long]"""
467 if not params
['long']:
468 raise HwsimSkip("Skip test case with long duration due to --long not specified")
471 force_prev_ap_on_5g(apdev
[0])
472 params
= hostapd
.wpa2_params(ssid
="test-acs", passphrase
="12345678")
473 params
['hw_mode'] = 'a'
474 params
['channel'] = '0'
475 params
['ht_capab'] = '[HT40+]'
476 params
['country_code'] = 'US'
477 params
['ieee80211ac'] = '1'
478 params
['vht_oper_chwidth'] = '2'
479 params
['ieee80211d'] = '1'
480 params
['ieee80211h'] = '1'
481 params
['acs_num_scans'] = '1'
482 hapd
= hostapd
.add_ap(apdev
[0], params
, wait_enabled
=False)
483 wait_acs(hapd
, return_after_acs
=True)
485 wait_dfs_event(hapd
, "DFS-CAC-START", 5)
486 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
487 if "success=1" not in ev
:
488 raise Exception("CAC failed")
490 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
492 raise Exception("AP setup timed out")
494 state
= hapd
.get_status_field("state")
495 if state
!= "ENABLED":
496 raise Exception("Unexpected interface state")
498 freq
= int(hapd
.get_status_field("freq"))
499 if freq
not in [5180, 5500]:
500 raise Exception("Unexpected frequency: %d" % freq
)
502 dev
[0].connect("test-acs", psk
="12345678", scan_freq
=str(freq
))
503 dev
[0].wait_regdom(country_ie
=True)
506 hapd
.request("DISABLE")
507 dev
[0].disconnect_and_stop_scan()
508 hostapd
.cmd_execute(apdev
[0], ['iw', 'reg', 'set', '00'])
509 dev
[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout
=0.5)
510 dev
[0].flush_scan_cache()