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.
7 from remotehost import remote_compatible
10 logger = logging.getLogger()
14 from utils import HwsimSkip
16 def connect(dev, apdev, **kwargs):
17 params = { "ssid": "ap-csa",
20 ap = hostapd.add_ap(apdev[0], params)
21 dev.connect("ap-csa", key_mgmt="NONE", scan_freq="2412")
24 def switch_channel(ap, count, freq):
25 ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
26 ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
28 raise Exception("CSA finished event timed out")
29 if "freq=" + str(freq) not in ev:
30 raise Exception("Unexpected channel in CSA finished event")
32 def wait_channel_switch(dev, freq):
33 ev = dev.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=5)
35 raise Exception("Channel switch not reported")
36 if "freq=%d" % freq not in ev:
37 raise Exception("Unexpected frequency: " + ev)
39 # This function checks whether the provided dev, which may be either
40 # WpaSupplicant or Hostapd supports CSA.
41 def csa_supported(dev):
42 res = dev.get_driver_status()
43 if (int(res['capa.flags'], 0) & 0x80000000) == 0:
44 raise HwsimSkip("CSA not supported")
47 def test_ap_csa_1_switch(dev, apdev):
48 """AP Channel Switch, one switch"""
50 ap = connect(dev[0], apdev)
52 hwsim_utils.test_connectivity(dev[0], ap)
53 switch_channel(ap, 10, 2462)
54 wait_channel_switch(dev[0], 2462)
55 hwsim_utils.test_connectivity(dev[0], ap)
58 def test_ap_csa_2_switches(dev, apdev):
59 """AP Channel Switch, two switches"""
61 ap = connect(dev[0], apdev)
63 hwsim_utils.test_connectivity(dev[0], ap)
64 switch_channel(ap, 10, 2462)
65 wait_channel_switch(dev[0], 2462)
66 hwsim_utils.test_connectivity(dev[0], ap)
67 switch_channel(ap, 10, 2412)
68 wait_channel_switch(dev[0], 2412)
69 hwsim_utils.test_connectivity(dev[0], ap)
72 def test_ap_csa_1_switch_count_0(dev, apdev):
73 """AP Channel Switch, one switch with count 0"""
75 ap = connect(dev[0], apdev)
77 hwsim_utils.test_connectivity(dev[0], ap)
78 switch_channel(ap, 0, 2462)
79 # this does not result in CSA currently, so do not bother checking
83 def test_ap_csa_2_switches_count_0(dev, apdev):
84 """AP Channel Switch, two switches with count 0"""
86 ap = connect(dev[0], apdev)
88 hwsim_utils.test_connectivity(dev[0], ap)
89 switch_channel(ap, 0, 2462)
90 # this does not result in CSA currently, so do not bother checking
92 switch_channel(ap, 0, 2412)
93 # this does not result in CSA currently, so do not bother checking
97 def test_ap_csa_1_switch_count_1(dev, apdev):
98 """AP Channel Switch, one switch with count 1"""
100 ap = connect(dev[0], apdev)
102 hwsim_utils.test_connectivity(dev[0], ap)
103 switch_channel(ap, 1, 2462)
104 # this does not result in CSA currently, so do not bother checking
108 def test_ap_csa_2_switches_count_1(dev, apdev):
109 """AP Channel Switch, two switches with count 1"""
110 csa_supported(dev[0])
111 ap = connect(dev[0], apdev)
113 hwsim_utils.test_connectivity(dev[0], ap)
114 switch_channel(ap, 1, 2462)
115 # this does not result in CSA currently, so do not bother checking
117 switch_channel(ap, 1, 2412)
118 # this does not result in CSA currently, so do not bother checking
122 def test_ap_csa_1_switch_count_2(dev, apdev):
123 """AP Channel Switch, one switch with count 2"""
124 csa_supported(dev[0])
125 ap = connect(dev[0], apdev)
127 hwsim_utils.test_connectivity(dev[0], ap)
128 switch_channel(ap, 2, 2462)
129 wait_channel_switch(dev[0], 2462)
130 hwsim_utils.test_connectivity(dev[0], ap)
133 def test_ap_csa_ecsa_only(dev, apdev):
134 """AP Channel Switch, one switch with only ECSA IE"""
135 csa_supported(dev[0])
136 ap = connect(dev[0], apdev, ecsa_ie_only="1")
138 hwsim_utils.test_connectivity(dev[0], ap)
139 switch_channel(ap, 10, 2462)
140 wait_channel_switch(dev[0], 2462)
141 hwsim_utils.test_connectivity(dev[0], ap)
144 def test_ap_csa_invalid(dev, apdev):
145 """AP Channel Switch - invalid channel"""
146 csa_supported(dev[0])
147 ap = connect(dev[0], apdev)
149 vals = [ 2461, 4900, 4901, 5181, 5746, 5699, 5895, 5899 ]
151 if "FAIL" not in ap.request("CHAN_SWITCH 1 %d" % val):
152 raise Exception("Invalid channel accepted: %d" % val)