2014-01-01 14:32:12 +01:00
|
|
|
# AP CSA tests
|
|
|
|
# Copyright (c) 2013, Luciano Coelho <luciano.coelho@intel.com>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
from remotehost import remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
import time
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
2015-01-07 13:19:30 +01:00
|
|
|
from utils import HwsimSkip
|
2014-01-01 14:32:12 +01:00
|
|
|
|
2019-05-04 23:40:57 +02:00
|
|
|
def connect(dev, apdev, scan_freq="2412", **kwargs):
|
2019-03-15 11:10:37 +01:00
|
|
|
params = {"ssid": "ap-csa",
|
|
|
|
"channel": "1"}
|
2015-09-08 11:46:32 +02:00
|
|
|
params.update(kwargs)
|
2016-03-30 10:55:56 +02:00
|
|
|
ap = hostapd.add_ap(apdev[0], params)
|
2019-05-04 23:40:57 +02:00
|
|
|
dev.connect("ap-csa", key_mgmt="NONE", scan_freq=scan_freq)
|
2014-01-01 14:32:12 +01:00
|
|
|
return ap
|
|
|
|
|
|
|
|
def switch_channel(ap, count, freq):
|
|
|
|
ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
|
2019-04-22 20:03:07 +02:00
|
|
|
|
|
|
|
ev = ap.wait_event(["CTRL-EVENT-STARTED-CHANNEL-SWITCH"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Channel switch start event not seen")
|
|
|
|
if "freq=" + str(freq) not in ev:
|
|
|
|
raise Exception("Unexpected channel in CS started event")
|
|
|
|
|
|
|
|
ev = ap.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Channel switch completed event not seen")
|
|
|
|
if "freq=" + str(freq) not in ev:
|
|
|
|
raise Exception("Unexpected channel in CS completed event")
|
|
|
|
|
2014-01-01 14:32:12 +01:00
|
|
|
ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("CSA finished event timed out")
|
|
|
|
if "freq=" + str(freq) not in ev:
|
|
|
|
raise Exception("Unexpected channel in CSA finished event")
|
2016-06-27 19:24:52 +02:00
|
|
|
|
|
|
|
def wait_channel_switch(dev, freq):
|
2019-04-22 20:03:07 +02:00
|
|
|
ev = dev.wait_event(["CTRL-EVENT-STARTED-CHANNEL-SWITCH"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Channel switch start not reported")
|
|
|
|
if "freq=%d" % freq not in ev:
|
|
|
|
raise Exception("Unexpected frequency in channel switch started: " + ev)
|
|
|
|
|
2016-06-27 19:24:52 +02:00
|
|
|
ev = dev.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Channel switch not reported")
|
|
|
|
if "freq=%d" % freq not in ev:
|
|
|
|
raise Exception("Unexpected frequency: " + ev)
|
2014-01-01 14:32:12 +01:00
|
|
|
|
|
|
|
# This function checks whether the provided dev, which may be either
|
|
|
|
# WpaSupplicant or Hostapd supports CSA.
|
|
|
|
def csa_supported(dev):
|
|
|
|
res = dev.get_driver_status()
|
2015-01-07 13:19:30 +01:00
|
|
|
if (int(res['capa.flags'], 0) & 0x80000000) == 0:
|
|
|
|
raise HwsimSkip("CSA not supported")
|
2014-01-01 14:32:12 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_1_switch(dev, apdev):
|
|
|
|
"""AP Channel Switch, one switch"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2019-04-14 11:41:26 +02:00
|
|
|
freq = int(dev[0].get_driver_status_field("freq"))
|
|
|
|
if freq != 0:
|
|
|
|
raise Exception("Unexpected driver freq=%d in beginning" % freq)
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
2019-04-14 11:41:26 +02:00
|
|
|
freq = int(dev[0].get_driver_status_field("freq"))
|
|
|
|
if freq != 2412:
|
|
|
|
raise Exception("Unexpected driver freq=%d after association" % freq)
|
2014-01-01 14:32:12 +01:00
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 10, 2462)
|
2016-06-27 19:24:52 +02:00
|
|
|
wait_channel_switch(dev[0], 2462)
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2019-04-14 11:41:26 +02:00
|
|
|
freq = int(dev[0].get_driver_status_field("freq"))
|
|
|
|
if freq != 2462:
|
|
|
|
raise Exception("Unexpected driver freq=%d after channel switch" % freq)
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
freq = int(dev[0].get_driver_status_field("freq"))
|
|
|
|
if freq != 0:
|
|
|
|
raise Exception("Unexpected driver freq=%d after disconnection" % freq)
|
2014-01-01 14:32:12 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_2_switches(dev, apdev):
|
|
|
|
"""AP Channel Switch, two switches"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 10, 2462)
|
2016-06-27 19:24:52 +02:00
|
|
|
wait_channel_switch(dev[0], 2462)
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 10, 2412)
|
2016-06-27 19:24:52 +02:00
|
|
|
wait_channel_switch(dev[0], 2412)
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_1_switch_count_0(dev, apdev):
|
|
|
|
"""AP Channel Switch, one switch with count 0"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 0, 2462)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_2_switches_count_0(dev, apdev):
|
|
|
|
"""AP Channel Switch, two switches with count 0"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 0, 2462)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
switch_channel(ap, 0, 2412)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_1_switch_count_1(dev, apdev):
|
|
|
|
"""AP Channel Switch, one switch with count 1"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 1, 2462)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_2_switches_count_1(dev, apdev):
|
|
|
|
"""AP Channel Switch, two switches with count 1"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 1, 2462)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
switch_channel(ap, 1, 2412)
|
|
|
|
# this does not result in CSA currently, so do not bother checking
|
|
|
|
# connectivity
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-01-01 14:32:12 +01:00
|
|
|
def test_ap_csa_1_switch_count_2(dev, apdev):
|
|
|
|
"""AP Channel Switch, one switch with count 2"""
|
2015-01-07 13:19:30 +01:00
|
|
|
csa_supported(dev[0])
|
2014-01-01 14:32:12 +01:00
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2014-01-01 14:32:12 +01:00
|
|
|
switch_channel(ap, 2, 2462)
|
2016-06-27 19:24:52 +02:00
|
|
|
wait_channel_switch(dev[0], 2462)
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2015-09-08 11:46:32 +02:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2015-09-08 11:46:32 +02:00
|
|
|
def test_ap_csa_ecsa_only(dev, apdev):
|
|
|
|
"""AP Channel Switch, one switch with only ECSA IE"""
|
|
|
|
csa_supported(dev[0])
|
|
|
|
ap = connect(dev[0], apdev, ecsa_ie_only="1")
|
|
|
|
|
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
|
|
|
switch_channel(ap, 10, 2462)
|
2016-06-27 19:24:52 +02:00
|
|
|
wait_channel_switch(dev[0], 2462)
|
2015-09-08 11:46:32 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], ap)
|
2016-03-26 18:41:24 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2016-03-26 18:41:24 +01:00
|
|
|
def test_ap_csa_invalid(dev, apdev):
|
|
|
|
"""AP Channel Switch - invalid channel"""
|
|
|
|
csa_supported(dev[0])
|
|
|
|
ap = connect(dev[0], apdev)
|
|
|
|
|
2019-03-15 11:10:37 +01:00
|
|
|
vals = [2461, 4900, 4901, 5181, 5746, 5699, 5895, 5899]
|
2016-03-26 18:41:24 +01:00
|
|
|
for val in vals:
|
|
|
|
if "FAIL" not in ap.request("CHAN_SWITCH 1 %d" % val):
|
|
|
|
raise Exception("Invalid channel accepted: %d" % val)
|
2018-10-19 19:55:18 +02:00
|
|
|
|
|
|
|
def test_ap_csa_disable(dev, apdev):
|
|
|
|
"""AP Channel Switch and DISABLE command before completion"""
|
|
|
|
csa_supported(dev[0])
|
2019-05-04 23:40:57 +02:00
|
|
|
ap = connect(dev[0], apdev, scan_freq="2412 2462")
|
2018-10-19 19:55:18 +02:00
|
|
|
if "OK" not in ap.request("CHAN_SWITCH 10 2462"):
|
|
|
|
raise Exception("CHAN_SWITCH failed")
|
|
|
|
ap.disable()
|
|
|
|
ap.enable()
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
dev[0].wait_connected()
|