]>
Commit | Line | Data |
---|---|---|
8454e1fd JM |
1 | # Test cases for DFS |
2 | # Copyright (c) 2013, Jouni Malinen <j@w1.fi> | |
3 | # | |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import os | |
8 | import subprocess | |
9 | import time | |
10 | import logging | |
11 | logger = logging.getLogger() | |
12 | ||
13 | import hwsim_utils | |
14 | import hostapd | |
15 | ||
16 | def wait_dfs_event(hapd, event, timeout): | |
17 | dfs_events = [ "DFS-RADAR-DETECTED", "DFS-NEW-CHANNEL", | |
18 | "DFS-CAC-START", "DFS-CAC-COMPLETED", | |
bd5a7691 | 19 | "DFS-NOP-FINISHED", "AP-ENABLED", "AP-CSA-FINISHED" ] |
8454e1fd JM |
20 | ev = hapd.wait_event(dfs_events, timeout=timeout) |
21 | if not ev: | |
22 | raise Exception("DFS event timed out") | |
bc86d8c1 | 23 | if event and event not in ev: |
8454e1fd JM |
24 | raise Exception("Unexpected DFS event") |
25 | return ev | |
26 | ||
2a6cce38 | 27 | def start_dfs_ap(ap, allow_failure=False, ssid="dfs", ht40=False, vht80=False, vht20=False, chanlist=None): |
8454e1fd | 28 | ifname = ap['ifname'] |
8454e1fd JM |
29 | logger.info("Starting AP " + ifname + " on DFS channel") |
30 | hapd_global = hostapd.HostapdGlobal() | |
31 | hapd_global.remove(ifname) | |
32 | hapd_global.add(ifname) | |
33 | hapd = hostapd.Hostapd(ifname) | |
34 | if not hapd.ping(): | |
35 | raise Exception("Could not ping hostapd") | |
36 | hapd.set_defaults() | |
bd5a7691 | 37 | hapd.set("ssid", ssid) |
8454e1fd JM |
38 | hapd.set("country_code", "FI") |
39 | hapd.set("ieee80211d", "1") | |
40 | hapd.set("ieee80211h", "1") | |
41 | hapd.set("hw_mode", "a") | |
42 | hapd.set("channel", "52") | |
bd5a7691 JM |
43 | if ht40: |
44 | hapd.set("ht_capab", "[HT40+]") | |
2a6cce38 JM |
45 | if vht80: |
46 | hapd.set("ieee80211ac", "1") | |
47 | hapd.set("vht_oper_chwidth", "1") | |
48 | hapd.set("vht_oper_centr_freq_seg0_idx", "58") | |
49 | if vht20: | |
50 | hapd.set("ieee80211ac", "1") | |
51 | hapd.set("vht_oper_chwidth", "0") | |
52 | hapd.set("vht_oper_centr_freq_seg0_idx", "0") | |
53 | if chanlist: | |
54 | hapd.set("chanlist", chanlist) | |
8454e1fd JM |
55 | hapd.enable() |
56 | ||
57 | ev = wait_dfs_event(hapd, "DFS-CAC-START", 5) | |
58 | if "DFS-CAC-START" not in ev: | |
59 | raise Exception("Unexpected DFS event") | |
60 | ||
61 | state = hapd.get_status_field("state") | |
62 | if state != "DFS": | |
4f62bfef JM |
63 | if allow_failure: |
64 | logger.info("Interface state not DFS: " + state) | |
65 | return None | |
66 | raise Exception("Unexpected interface state: " + state) | |
8454e1fd JM |
67 | |
68 | return hapd | |
69 | ||
bd5a7691 JM |
70 | def dfs_simulate_radar(hapd): |
71 | logger.info("Trigger a simulated radar event") | |
72 | phyname = hapd.get_driver_status_field("phyname") | |
73 | radar_file = '/sys/kernel/debug/ieee80211/' + phyname + '/hwsim/dfs_simulate_radar' | |
74 | with open(radar_file, 'w') as f: | |
75 | f.write('1') | |
76 | ||
8454e1fd JM |
77 | def test_dfs(dev, apdev): |
78 | """DFS CAC functionality on clear channel""" | |
4f62bfef JM |
79 | try: |
80 | hapd = start_dfs_ap(apdev[0], allow_failure=True) | |
81 | if hapd is None: | |
82 | if not os.path.exists("dfs"): | |
83 | return "skip" | |
84 | raise Exception("Failed to start DFS AP") | |
85 | ||
86 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
87 | if "success=1" not in ev: | |
88 | raise Exception("CAC failed") | |
89 | if "freq=5260" not in ev: | |
90 | raise Exception("Unexpected DFS freq result") | |
91 | ||
92 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
93 | if not ev: | |
94 | raise Exception("AP setup timed out") | |
95 | ||
96 | state = hapd.get_status_field("state") | |
97 | if state != "ENABLED": | |
98 | raise Exception("Unexpected interface state") | |
99 | ||
100 | freq = hapd.get_status_field("freq") | |
101 | if freq != "5260": | |
102 | raise Exception("Unexpected frequency") | |
103 | ||
c634d320 | 104 | dev[0].connect("dfs", key_mgmt="NONE") |
a8375c94 | 105 | hwsim_utils.test_connectivity(dev[0], hapd) |
831cb7af JM |
106 | |
107 | hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1") | |
108 | ev = hapd.wait_event(["DFS-RADAR-DETECTED"], timeout=10) | |
109 | if ev is None: | |
110 | raise Exception("DFS-RADAR-DETECTED event not reported") | |
111 | if "freq=5260" not in ev: | |
112 | raise Exception("Incorrect frequency in radar detected event: " + ev); | |
113 | ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=70) | |
114 | if ev is None: | |
115 | raise Exception("DFS-NEW-CHANNEL event not reported") | |
116 | if "freq=5260" in ev: | |
117 | raise Exception("Channel did not change after radar was detected"); | |
118 | ||
119 | ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=70) | |
120 | if ev is None: | |
121 | raise Exception("AP-CSA-FINISHED event not reported") | |
122 | if "freq=5260" in ev: | |
123 | raise Exception("Channel did not change after radar was detected(2)"); | |
124 | time.sleep(1) | |
a8375c94 | 125 | hwsim_utils.test_connectivity(dev[0], hapd) |
4f62bfef | 126 | finally: |
9d7fdac5 JM |
127 | dev[0].request("DISCONNECT") |
128 | if hapd: | |
129 | hapd.request("DISABLE") | |
4f62bfef | 130 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 131 | dev[0].flush_scan_cache() |
8454e1fd JM |
132 | |
133 | def test_dfs_radar(dev, apdev): | |
134 | """DFS CAC functionality with radar detected""" | |
4f62bfef | 135 | try: |
9d7fdac5 | 136 | hapd2 = None |
4f62bfef | 137 | hapd = start_dfs_ap(apdev[0]) |
bc86d8c1 JM |
138 | if hapd is None: |
139 | if not os.path.exists("dfs"): | |
140 | return "skip" | |
141 | raise Exception("Failed to start DFS AP") | |
142 | time.sleep(1) | |
8454e1fd | 143 | |
bd5a7691 JM |
144 | dfs_simulate_radar(hapd) |
145 | ||
146 | hapd2 = start_dfs_ap(apdev[1], ssid="dfs2", ht40=True) | |
bc86d8c1 JM |
147 | |
148 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
149 | if ev is None: | |
150 | raise Exception("Timeout on DFS aborted event") | |
151 | if "success=0 freq=5260" not in ev: | |
152 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
153 | ||
154 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
4f62bfef JM |
155 | if "freq=5260" not in ev: |
156 | raise Exception("Unexpected DFS radar detection freq") | |
8454e1fd | 157 | |
4f62bfef JM |
158 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) |
159 | if "freq=5260" in ev: | |
160 | raise Exception("Unexpected DFS new freq") | |
8454e1fd | 161 | |
bc86d8c1 JM |
162 | ev = wait_dfs_event(hapd, None, 5) |
163 | if "AP-ENABLED" in ev: | |
164 | logger.info("Started AP on non-DFS channel") | |
165 | else: | |
166 | logger.info("Trying to start AP on another DFS channel") | |
167 | if "DFS-CAC-START" not in ev: | |
168 | raise Exception("Unexpected DFS event") | |
169 | if "freq=5260" in ev: | |
170 | raise Exception("Unexpected DFS CAC freq") | |
171 | ||
172 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
173 | if "success=1" not in ev: | |
174 | raise Exception("CAC failed") | |
175 | if "freq=5260" in ev: | |
176 | raise Exception("Unexpected DFS freq result - radar channel") | |
177 | ||
178 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
179 | if not ev: | |
180 | raise Exception("AP setup timed out") | |
181 | ||
182 | state = hapd.get_status_field("state") | |
183 | if state != "ENABLED": | |
184 | raise Exception("Unexpected interface state") | |
185 | ||
186 | freq = hapd.get_status_field("freq") | |
187 | if freq == "5260": | |
188 | raise Exception("Unexpected frequency: " + freq) | |
8454e1fd | 189 | |
c634d320 | 190 | dev[0].connect("dfs", key_mgmt="NONE") |
bd5a7691 JM |
191 | |
192 | ev = hapd2.wait_event(["AP-ENABLED"], timeout=70) | |
193 | if not ev: | |
194 | raise Exception("AP2 setup timed out") | |
195 | ||
196 | dfs_simulate_radar(hapd2) | |
197 | ||
198 | ev = wait_dfs_event(hapd2, "DFS-RADAR-DETECTED", 5) | |
199 | if "freq=5260 ht_enabled=1 chan_offset=1 chan_width=2" not in ev: | |
200 | raise Exception("Unexpected DFS radar detection freq from AP2") | |
201 | ||
202 | ev = wait_dfs_event(hapd2, "DFS-NEW-CHANNEL", 5) | |
203 | if "freq=5260" in ev: | |
204 | raise Exception("Unexpected DFS new freq for AP2") | |
205 | ||
206 | wait_dfs_event(hapd2, None, 5) | |
4f62bfef | 207 | finally: |
9d7fdac5 JM |
208 | dev[0].request("DISCONNECT") |
209 | if hapd: | |
210 | hapd.request("DISABLE") | |
211 | if hapd2: | |
212 | hapd2.request("DISABLE") | |
4f62bfef | 213 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 214 | dev[0].flush_scan_cache() |
8454e1fd | 215 | |
4f62bfef JM |
216 | def test_dfs_radar_on_non_dfs_channel(dev, apdev): |
217 | """DFS radar detection test code on non-DFS channel""" | |
218 | params = { "ssid": "radar" } | |
219 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
220 | ||
221 | hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1") | |
222 | hapd.request("RADAR DETECTED freq=2412 ht_enabled=1 chan_width=1") | |
2a6cce38 JM |
223 | |
224 | def test_dfs_radar_chanlist(dev, apdev): | |
225 | """DFS chanlist when radar is detected""" | |
226 | try: | |
227 | hapd = start_dfs_ap(apdev[0], chanlist="40 44") | |
228 | if hapd is None: | |
229 | if not os.path.exists("dfs"): | |
230 | return "skip" | |
231 | raise Exception("Failed to start DFS AP") | |
232 | time.sleep(1) | |
233 | ||
234 | dfs_simulate_radar(hapd) | |
235 | ||
236 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
237 | if ev is None: | |
238 | raise Exception("Timeout on DFS aborted event") | |
239 | if "success=0 freq=5260" not in ev: | |
240 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
241 | ||
242 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
243 | if "freq=5260" not in ev: | |
244 | raise Exception("Unexpected DFS radar detection freq") | |
245 | ||
246 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
247 | if "freq=5200 chan=40" not in ev and "freq=5220 chan=44" not in ev: | |
248 | raise Exception("Unexpected DFS new freq: " + ev) | |
249 | ||
250 | ev = wait_dfs_event(hapd, None, 5) | |
251 | if "AP-ENABLED" not in ev: | |
252 | raise Exception("Unexpected DFS event") | |
253 | dev[0].connect("dfs", key_mgmt="NONE") | |
254 | finally: | |
9d7fdac5 JM |
255 | dev[0].request("DISCONNECT") |
256 | if hapd: | |
257 | hapd.request("DISABLE") | |
2a6cce38 | 258 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 259 | dev[0].flush_scan_cache() |
2a6cce38 JM |
260 | |
261 | def test_dfs_radar_chanlist_vht80(dev, apdev): | |
262 | """DFS chanlist when radar is detected and VHT80 configured""" | |
263 | try: | |
264 | hapd = start_dfs_ap(apdev[0], chanlist="36", ht40=True, vht80=True) | |
265 | if hapd is None: | |
266 | if not os.path.exists("dfs"): | |
267 | return "skip" | |
268 | raise Exception("Failed to start DFS AP") | |
269 | time.sleep(1) | |
270 | ||
271 | dfs_simulate_radar(hapd) | |
272 | ||
273 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
274 | if ev is None: | |
275 | raise Exception("Timeout on DFS aborted event") | |
276 | if "success=0 freq=5260" not in ev: | |
277 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
278 | ||
279 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
280 | if "freq=5260" not in ev: | |
281 | raise Exception("Unexpected DFS radar detection freq") | |
282 | ||
283 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
284 | if "freq=5180 chan=36 sec_chan=1" not in ev: | |
285 | raise Exception("Unexpected DFS new freq: " + ev) | |
286 | ||
287 | ev = wait_dfs_event(hapd, None, 5) | |
288 | if "AP-ENABLED" not in ev: | |
289 | raise Exception("Unexpected DFS event") | |
290 | dev[0].connect("dfs", key_mgmt="NONE") | |
291 | ||
292 | if hapd.get_status_field('vht_oper_centr_freq_seg0_idx') != "42": | |
293 | raise Exception("Unexpected seg0 idx") | |
294 | finally: | |
9d7fdac5 JM |
295 | dev[0].request("DISCONNECT") |
296 | if hapd: | |
297 | hapd.request("DISABLE") | |
2a6cce38 | 298 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 299 | dev[0].flush_scan_cache() |
2a6cce38 JM |
300 | |
301 | def test_dfs_radar_chanlist_vht20(dev, apdev): | |
302 | """DFS chanlist when radar is detected and VHT40 configured""" | |
303 | try: | |
304 | hapd = start_dfs_ap(apdev[0], chanlist="36", vht20=True) | |
305 | if hapd is None: | |
306 | if not os.path.exists("dfs"): | |
307 | return "skip" | |
308 | raise Exception("Failed to start DFS AP") | |
309 | time.sleep(1) | |
310 | ||
311 | dfs_simulate_radar(hapd) | |
312 | ||
313 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
314 | if ev is None: | |
315 | raise Exception("Timeout on DFS aborted event") | |
316 | if "success=0 freq=5260" not in ev: | |
317 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
318 | ||
319 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
320 | if "freq=5260" not in ev: | |
321 | raise Exception("Unexpected DFS radar detection freq") | |
322 | ||
323 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
324 | if "freq=5180 chan=36 sec_chan=0" not in ev: | |
325 | raise Exception("Unexpected DFS new freq: " + ev) | |
326 | ||
327 | ev = wait_dfs_event(hapd, None, 5) | |
328 | if "AP-ENABLED" not in ev: | |
329 | raise Exception("Unexpected DFS event") | |
330 | dev[0].connect("dfs", key_mgmt="NONE") | |
331 | finally: | |
9d7fdac5 JM |
332 | dev[0].request("DISCONNECT") |
333 | if hapd: | |
334 | hapd.request("DISABLE") | |
2a6cce38 | 335 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 336 | dev[0].flush_scan_cache() |