2 # Copyright (c) 2013, Luciano Coelho <luciano.coelho@intel.com>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
9 logger = logging.getLogger()
13 from utils import HwsimSkip
15 def connect(dev, apdev):
16 params = { "ssid": "ap-csa",
18 ap = hostapd.add_ap(apdev[0]['ifname'], params)
19 dev.connect("ap-csa", key_mgmt="NONE")
22 def switch_channel(ap, count, freq):
23 ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
24 ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
26 raise Exception("CSA finished event timed out")
27 if "freq=" + str(freq) not in ev:
28 raise Exception("Unexpected channel in CSA finished event")
31 # This function checks whether the provided dev, which may be either
32 # WpaSupplicant or Hostapd supports CSA.
33 def csa_supported(dev):
34 res = dev.get_driver_status()
35 if (int(res['capa.flags'], 0) & 0x80000000) == 0:
36 raise HwsimSkip("CSA not supported")
38 def test_ap_csa_1_switch(dev, apdev):
39 """AP Channel Switch, one switch"""
41 ap = connect(dev[0], apdev)
43 hwsim_utils.test_connectivity(dev[0], ap)
44 switch_channel(ap, 10, 2462)
45 hwsim_utils.test_connectivity(dev[0], ap)
47 def test_ap_csa_2_switches(dev, apdev):
48 """AP Channel Switch, two switches"""
50 ap = connect(dev[0], apdev)
52 hwsim_utils.test_connectivity(dev[0], ap)
53 switch_channel(ap, 10, 2462)
54 hwsim_utils.test_connectivity(dev[0], ap)
55 switch_channel(ap, 10, 2412)
56 hwsim_utils.test_connectivity(dev[0], ap)
58 def test_ap_csa_1_switch_count_0(dev, apdev):
59 """AP Channel Switch, one switch with count 0"""
61 ap = connect(dev[0], apdev)
63 hwsim_utils.test_connectivity(dev[0], ap)
64 switch_channel(ap, 0, 2462)
65 # this does not result in CSA currently, so do not bother checking
68 def test_ap_csa_2_switches_count_0(dev, apdev):
69 """AP Channel Switch, two switches with count 0"""
71 ap = connect(dev[0], apdev)
73 hwsim_utils.test_connectivity(dev[0], ap)
74 switch_channel(ap, 0, 2462)
75 # this does not result in CSA currently, so do not bother checking
77 switch_channel(ap, 0, 2412)
78 # this does not result in CSA currently, so do not bother checking
81 def test_ap_csa_1_switch_count_1(dev, apdev):
82 """AP Channel Switch, one switch with count 1"""
84 ap = connect(dev[0], apdev)
86 hwsim_utils.test_connectivity(dev[0], ap)
87 switch_channel(ap, 1, 2462)
88 # this does not result in CSA currently, so do not bother checking
91 def test_ap_csa_2_switches_count_1(dev, apdev):
92 """AP Channel Switch, two switches with count 1"""
94 ap = connect(dev[0], apdev)
96 hwsim_utils.test_connectivity(dev[0], ap)
97 switch_channel(ap, 1, 2462)
98 # this does not result in CSA currently, so do not bother checking
100 switch_channel(ap, 1, 2412)
101 # this does not result in CSA currently, so do not bother checking
104 def test_ap_csa_1_switch_count_2(dev, apdev):
105 """AP Channel Switch, one switch with count 2"""
106 csa_supported(dev[0])
107 ap = connect(dev[0], apdev)
109 hwsim_utils.test_connectivity(dev[0], ap)
110 switch_channel(ap, 2, 2462)
111 hwsim_utils.test_connectivity(dev[0], ap)