2013-11-03 19:50:39 +01:00
|
|
|
# Test cases for automatic channel selection with hostapd
|
2015-08-01 21:54:07 +02:00
|
|
|
# Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
|
2013-11-03 19:50:39 +01:00
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
2014-03-29 08:24:22 +01:00
|
|
|
import subprocess
|
2014-04-13 23:38:37 +02:00
|
|
|
import time
|
2013-11-03 19:50:39 +01:00
|
|
|
|
|
|
|
import hostapd
|
2015-08-01 21:54:07 +02:00
|
|
|
from utils import skip_with_fips
|
2015-03-07 15:23:48 +01:00
|
|
|
from test_ap_ht import clear_scan_cache
|
2013-11-03 19:50:39 +01:00
|
|
|
|
2015-03-03 15:01:52 +01:00
|
|
|
def force_prev_ap_on_24g(ap):
|
|
|
|
# For now, make sure the last operating channel was on 2.4 GHz band to get
|
|
|
|
# sufficient survey data from mac80211_hwsim.
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(ap, { "ssid": "open" })
|
2015-03-03 15:01:52 +01:00
|
|
|
time.sleep(0.1)
|
|
|
|
hapd_global = hostapd.HostapdGlobal()
|
|
|
|
hapd_global.remove(ap['ifname'])
|
|
|
|
|
|
|
|
def force_prev_ap_on_5g(ap):
|
|
|
|
# For now, make sure the last operating channel was on 5 GHz band to get
|
|
|
|
# sufficient survey data from mac80211_hwsim.
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(ap, { "ssid": "open", "hw_mode": "a",
|
|
|
|
"channel": "36", "country_code": "US" })
|
2015-03-03 15:01:52 +01:00
|
|
|
time.sleep(0.1)
|
|
|
|
hapd_global = hostapd.HostapdGlobal()
|
|
|
|
hapd_global.remove(ap['ifname'])
|
|
|
|
|
2013-11-03 19:50:39 +01:00
|
|
|
def wait_acs(hapd):
|
|
|
|
ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
|
2014-03-29 08:24:22 +01:00
|
|
|
"AP-ENABLED", "AP-DISABLED"], timeout=5)
|
2013-11-03 19:50:39 +01:00
|
|
|
if not ev:
|
|
|
|
raise Exception("ACS start timed out")
|
|
|
|
if "ACS-STARTED" not in ev:
|
2014-03-29 08:24:22 +01:00
|
|
|
raise Exception("Unexpected ACS event: " + ev)
|
2013-11-03 19:50:39 +01:00
|
|
|
|
|
|
|
state = hapd.get_status_field("state")
|
|
|
|
if state != "ACS":
|
|
|
|
raise Exception("Unexpected interface state")
|
|
|
|
|
2014-03-29 08:24:22 +01:00
|
|
|
ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
|
|
|
|
"AP-DISABLED"], timeout=20)
|
2013-11-03 19:50:39 +01:00
|
|
|
if not ev:
|
|
|
|
raise Exception("ACS timed out")
|
|
|
|
if "ACS-COMPLETED" not in ev:
|
2014-03-29 08:24:22 +01:00
|
|
|
raise Exception("Unexpected ACS event: " + ev)
|
2013-11-03 19:50:39 +01:00
|
|
|
|
2014-03-29 08:24:22 +01:00
|
|
|
ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
|
2013-11-03 19:50:39 +01:00
|
|
|
if not ev:
|
|
|
|
raise Exception("AP setup timed out")
|
2014-03-29 08:24:22 +01:00
|
|
|
if "AP-ENABLED" not in ev:
|
|
|
|
raise Exception("Unexpected ACS event: " + ev)
|
2013-11-03 19:50:39 +01:00
|
|
|
|
|
|
|
state = hapd.get_status_field("state")
|
|
|
|
if state != "ENABLED":
|
|
|
|
raise Exception("Unexpected interface state")
|
|
|
|
|
|
|
|
def test_ap_acs(dev, apdev):
|
|
|
|
"""Automatic channel selection"""
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2013-11-03 19:50:39 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['channel'] = '0'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2013-11-03 19:50:39 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 2400:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
|
|
|
|
2015-05-24 09:43:44 +02:00
|
|
|
def test_ap_acs_chanlist(dev, apdev):
|
|
|
|
"""Automatic channel selection with chanlist set"""
|
|
|
|
force_prev_ap_on_24g(apdev[0])
|
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['chanlist'] = '1 6 11'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2015-05-24 09:43:44 +02:00
|
|
|
wait_acs(hapd)
|
|
|
|
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 2400:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
|
|
|
|
2013-11-03 19:50:39 +01:00
|
|
|
def test_ap_multi_bss_acs(dev, apdev):
|
|
|
|
"""hostapd start with a multi-BSS configuration file using ACS"""
|
2015-08-01 21:54:07 +02:00
|
|
|
skip_with_fips(dev[0])
|
2013-11-03 19:50:39 +01:00
|
|
|
ifname = apdev[0]['ifname']
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2014-04-13 23:38:37 +02:00
|
|
|
|
|
|
|
# start the actual test
|
2016-04-07 07:38:01 +02:00
|
|
|
hostapd.add_iface(apdev[0], 'multi-bss-acs.conf')
|
2013-11-03 19:50:39 +01:00
|
|
|
hapd = hostapd.Hostapd(ifname)
|
|
|
|
hapd.enable()
|
|
|
|
wait_acs(hapd)
|
|
|
|
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 2400:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
|
|
|
|
dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
|
|
|
|
dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
def test_ap_acs_40mhz(dev, apdev):
|
|
|
|
"""Automatic channel selection for 40 MHz channel"""
|
2015-03-07 15:23:48 +01:00
|
|
|
clear_scan_cache(apdev[0]['ifname'])
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2014-03-29 08:24:22 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['ht_capab'] = '[HT40+]'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2014-03-29 08:24:22 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 2400:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
sec = hapd.get_status_field("secondary_channel")
|
|
|
|
if int(sec) == 0:
|
|
|
|
raise Exception("Secondary channel not set")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
|
|
|
|
|
|
|
def test_ap_acs_5ghz(dev, apdev):
|
|
|
|
"""Automatic channel selection on 5 GHz"""
|
|
|
|
try:
|
2014-12-15 00:32:01 +01:00
|
|
|
hapd = None
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_5g(apdev[0])
|
2014-03-29 08:24:22 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['hw_mode'] = 'a'
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['country_code'] = 'US'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2015-03-03 15:01:52 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 5000:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
finally:
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
if hapd:
|
|
|
|
hapd.request("DISABLE")
|
2015-02-06 23:22:32 +01:00
|
|
|
subprocess.call(['iw', 'reg', 'set', '00'])
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].flush_scan_cache()
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
def test_ap_acs_5ghz_40mhz(dev, apdev):
|
|
|
|
"""Automatic channel selection on 5 GHz for 40 MHz channel"""
|
|
|
|
try:
|
2014-12-15 00:32:01 +01:00
|
|
|
hapd = None
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_5g(apdev[0])
|
2014-03-29 08:24:22 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['hw_mode'] = 'a'
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['ht_capab'] = '[HT40+]'
|
|
|
|
params['country_code'] = 'US'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2015-03-03 15:01:52 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 5000:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
sec = hapd.get_status_field("secondary_channel")
|
|
|
|
if int(sec) == 0:
|
|
|
|
raise Exception("Secondary channel not set")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
finally:
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
if hapd:
|
|
|
|
hapd.request("DISABLE")
|
2015-02-06 23:22:32 +01:00
|
|
|
subprocess.call(['iw', 'reg', 'set', '00'])
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].flush_scan_cache()
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
def test_ap_acs_vht(dev, apdev):
|
|
|
|
"""Automatic channel selection for VHT"""
|
|
|
|
try:
|
2014-12-15 00:32:01 +01:00
|
|
|
hapd = None
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_5g(apdev[0])
|
2014-03-29 08:24:22 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['hw_mode'] = 'a'
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['ht_capab'] = '[HT40+]'
|
|
|
|
params['country_code'] = 'US'
|
|
|
|
params['ieee80211ac'] = '1'
|
|
|
|
params['vht_oper_chwidth'] = '1'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2015-03-03 15:01:52 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 5000:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
sec = hapd.get_status_field("secondary_channel")
|
|
|
|
if int(sec) == 0:
|
|
|
|
raise Exception("Secondary channel not set")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|
2014-03-29 08:24:22 +01:00
|
|
|
|
|
|
|
finally:
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
if hapd:
|
|
|
|
hapd.request("DISABLE")
|
2015-02-06 23:22:32 +01:00
|
|
|
subprocess.call(['iw', 'reg', 'set', '00'])
|
2014-12-15 00:32:01 +01:00
|
|
|
dev[0].flush_scan_cache()
|
2015-02-06 17:02:33 +01:00
|
|
|
|
|
|
|
def test_ap_acs_bias(dev, apdev):
|
|
|
|
"""Automatic channel selection with bias values"""
|
2015-03-03 15:01:52 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2015-02-06 17:02:33 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
|
|
|
|
params['channel'] = '0'
|
|
|
|
params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
|
2015-02-06 17:02:33 +01:00
|
|
|
wait_acs(hapd)
|
|
|
|
|
|
|
|
freq = hapd.get_status_field("freq")
|
|
|
|
if int(freq) < 2400:
|
|
|
|
raise Exception("Unexpected frequency")
|
|
|
|
|
|
|
|
dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
|