]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ap_csa.py
tests: Fix ap_ft_reassoc_replay for case where wlantest has the PSK
[thirdparty/hostap.git] / tests / hwsim / test_ap_csa.py
CommitLineData
5d7746b5
LC
1# AP CSA tests
2# Copyright (c) 2013, Luciano Coelho <luciano.coelho@intel.com>
3#
4# This software may be distributed under the terms of the BSD license.
5# See README for more details.
6
9fd6804d 7from remotehost import remote_compatible
5d7746b5
LC
8import time
9import logging
10logger = logging.getLogger()
11
12import hwsim_utils
13import hostapd
81e787b7 14from utils import HwsimSkip
5d7746b5 15
4abaf4df 16def connect(dev, apdev, scan_freq="2412", **kwargs):
fab49f61
JM
17 params = {"ssid": "ap-csa",
18 "channel": "1"}
f2270437 19 params.update(kwargs)
8b8a1864 20 ap = hostapd.add_ap(apdev[0], params)
4abaf4df 21 dev.connect("ap-csa", key_mgmt="NONE", scan_freq=scan_freq)
5d7746b5
LC
22 return ap
23
24def switch_channel(ap, count, freq):
25 ap.request("CHAN_SWITCH " + str(count) + " " + str(freq))
64c20a83
JM
26
27 ev = ap.wait_event(["CTRL-EVENT-STARTED-CHANNEL-SWITCH"], timeout=10)
28 if ev is None:
29 raise Exception("Channel switch start event not seen")
30 if "freq=" + str(freq) not in ev:
31 raise Exception("Unexpected channel in CS started event")
32
33 ev = ap.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=10)
34 if ev is None:
35 raise Exception("Channel switch completed event not seen")
36 if "freq=" + str(freq) not in ev:
37 raise Exception("Unexpected channel in CS completed event")
38
5d7746b5
LC
39 ev = ap.wait_event(["AP-CSA-FINISHED"], timeout=10)
40 if ev is None:
41 raise Exception("CSA finished event timed out")
42 if "freq=" + str(freq) not in ev:
43 raise Exception("Unexpected channel in CSA finished event")
f9442f29
JM
44
45def wait_channel_switch(dev, freq):
64c20a83
JM
46 ev = dev.wait_event(["CTRL-EVENT-STARTED-CHANNEL-SWITCH"], timeout=5)
47 if ev is None:
48 raise Exception("Channel switch start not reported")
49 if "freq=%d" % freq not in ev:
50 raise Exception("Unexpected frequency in channel switch started: " + ev)
51
f9442f29
JM
52 ev = dev.wait_event(["CTRL-EVENT-CHANNEL-SWITCH"], timeout=5)
53 if ev is None:
54 raise Exception("Channel switch not reported")
55 if "freq=%d" % freq not in ev:
56 raise Exception("Unexpected frequency: " + ev)
5d7746b5
LC
57
58# This function checks whether the provided dev, which may be either
59# WpaSupplicant or Hostapd supports CSA.
60def csa_supported(dev):
61 res = dev.get_driver_status()
81e787b7
JM
62 if (int(res['capa.flags'], 0) & 0x80000000) == 0:
63 raise HwsimSkip("CSA not supported")
5d7746b5 64
9fd6804d 65@remote_compatible
5d7746b5
LC
66def test_ap_csa_1_switch(dev, apdev):
67 """AP Channel Switch, one switch"""
81e787b7 68 csa_supported(dev[0])
815f58a9
JM
69 freq = int(dev[0].get_driver_status_field("freq"))
70 if freq != 0:
71 raise Exception("Unexpected driver freq=%d in beginning" % freq)
5d7746b5 72 ap = connect(dev[0], apdev)
815f58a9
JM
73 freq = int(dev[0].get_driver_status_field("freq"))
74 if freq != 2412:
75 raise Exception("Unexpected driver freq=%d after association" % freq)
5d7746b5 76
a8375c94 77 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5 78 switch_channel(ap, 10, 2462)
f9442f29 79 wait_channel_switch(dev[0], 2462)
a8375c94 80 hwsim_utils.test_connectivity(dev[0], ap)
815f58a9
JM
81 freq = int(dev[0].get_driver_status_field("freq"))
82 if freq != 2462:
83 raise Exception("Unexpected driver freq=%d after channel switch" % freq)
84 dev[0].request("DISCONNECT")
85 dev[0].wait_disconnected()
86 freq = int(dev[0].get_driver_status_field("freq"))
87 if freq != 0:
88 raise Exception("Unexpected driver freq=%d after disconnection" % freq)
5d7746b5 89
9fd6804d 90@remote_compatible
5d7746b5
LC
91def test_ap_csa_2_switches(dev, apdev):
92 """AP Channel Switch, two switches"""
81e787b7 93 csa_supported(dev[0])
5d7746b5
LC
94 ap = connect(dev[0], apdev)
95
a8375c94 96 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5 97 switch_channel(ap, 10, 2462)
f9442f29 98 wait_channel_switch(dev[0], 2462)
a8375c94 99 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5 100 switch_channel(ap, 10, 2412)
f9442f29 101 wait_channel_switch(dev[0], 2412)
a8375c94 102 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5 103
9fd6804d 104@remote_compatible
5d7746b5
LC
105def test_ap_csa_1_switch_count_0(dev, apdev):
106 """AP Channel Switch, one switch with count 0"""
81e787b7 107 csa_supported(dev[0])
5d7746b5
LC
108 ap = connect(dev[0], apdev)
109
a8375c94 110 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5
LC
111 switch_channel(ap, 0, 2462)
112 # this does not result in CSA currently, so do not bother checking
113 # connectivity
114
9fd6804d 115@remote_compatible
5d7746b5
LC
116def test_ap_csa_2_switches_count_0(dev, apdev):
117 """AP Channel Switch, two switches with count 0"""
81e787b7 118 csa_supported(dev[0])
5d7746b5
LC
119 ap = connect(dev[0], apdev)
120
a8375c94 121 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5
LC
122 switch_channel(ap, 0, 2462)
123 # this does not result in CSA currently, so do not bother checking
124 # connectivity
125 switch_channel(ap, 0, 2412)
126 # this does not result in CSA currently, so do not bother checking
127 # connectivity
128
9fd6804d 129@remote_compatible
5d7746b5
LC
130def test_ap_csa_1_switch_count_1(dev, apdev):
131 """AP Channel Switch, one switch with count 1"""
81e787b7 132 csa_supported(dev[0])
5d7746b5
LC
133 ap = connect(dev[0], apdev)
134
a8375c94 135 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5
LC
136 switch_channel(ap, 1, 2462)
137 # this does not result in CSA currently, so do not bother checking
138 # connectivity
139
9fd6804d 140@remote_compatible
5d7746b5
LC
141def test_ap_csa_2_switches_count_1(dev, apdev):
142 """AP Channel Switch, two switches with count 1"""
81e787b7 143 csa_supported(dev[0])
5d7746b5
LC
144 ap = connect(dev[0], apdev)
145
a8375c94 146 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5
LC
147 switch_channel(ap, 1, 2462)
148 # this does not result in CSA currently, so do not bother checking
149 # connectivity
150 switch_channel(ap, 1, 2412)
151 # this does not result in CSA currently, so do not bother checking
152 # connectivity
153
9fd6804d 154@remote_compatible
5d7746b5
LC
155def test_ap_csa_1_switch_count_2(dev, apdev):
156 """AP Channel Switch, one switch with count 2"""
81e787b7 157 csa_supported(dev[0])
5d7746b5
LC
158 ap = connect(dev[0], apdev)
159
a8375c94 160 hwsim_utils.test_connectivity(dev[0], ap)
5d7746b5 161 switch_channel(ap, 2, 2462)
f9442f29 162 wait_channel_switch(dev[0], 2462)
a8375c94 163 hwsim_utils.test_connectivity(dev[0], ap)
f2270437 164
9fd6804d 165@remote_compatible
f2270437
JB
166def test_ap_csa_ecsa_only(dev, apdev):
167 """AP Channel Switch, one switch with only ECSA IE"""
168 csa_supported(dev[0])
169 ap = connect(dev[0], apdev, ecsa_ie_only="1")
170
171 hwsim_utils.test_connectivity(dev[0], ap)
172 switch_channel(ap, 10, 2462)
f9442f29 173 wait_channel_switch(dev[0], 2462)
f2270437 174 hwsim_utils.test_connectivity(dev[0], ap)
dd73d9a8 175
9fd6804d 176@remote_compatible
dd73d9a8
JM
177def test_ap_csa_invalid(dev, apdev):
178 """AP Channel Switch - invalid channel"""
179 csa_supported(dev[0])
180 ap = connect(dev[0], apdev)
181
fab49f61 182 vals = [2461, 4900, 4901, 5181, 5746, 5699, 5895, 5899]
dd73d9a8
JM
183 for val in vals:
184 if "FAIL" not in ap.request("CHAN_SWITCH 1 %d" % val):
185 raise Exception("Invalid channel accepted: %d" % val)
c3da3815
JM
186
187def test_ap_csa_disable(dev, apdev):
188 """AP Channel Switch and DISABLE command before completion"""
189 csa_supported(dev[0])
4abaf4df 190 ap = connect(dev[0], apdev, scan_freq="2412 2462")
c3da3815
JM
191 if "OK" not in ap.request("CHAN_SWITCH 10 2462"):
192 raise Exception("CHAN_SWITCH failed")
193 ap.disable()
194 ap.enable()
195 dev[0].wait_disconnected()
196 dev[0].wait_connected()