]>
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 | ||
9fd6804d | 7 | from remotehost import remote_compatible |
8454e1fd JM |
8 | import os |
9 | import subprocess | |
10 | import time | |
11 | import logging | |
12 | logger = logging.getLogger() | |
13 | ||
14 | import hwsim_utils | |
15 | import hostapd | |
81e787b7 | 16 | from utils import HwsimSkip |
8454e1fd JM |
17 | |
18 | def wait_dfs_event(hapd, event, timeout): | |
19 | dfs_events = [ "DFS-RADAR-DETECTED", "DFS-NEW-CHANNEL", | |
20 | "DFS-CAC-START", "DFS-CAC-COMPLETED", | |
bd5a7691 | 21 | "DFS-NOP-FINISHED", "AP-ENABLED", "AP-CSA-FINISHED" ] |
8454e1fd JM |
22 | ev = hapd.wait_event(dfs_events, timeout=timeout) |
23 | if not ev: | |
24 | raise Exception("DFS event timed out") | |
bc86d8c1 | 25 | if event and event not in ev: |
9a3eba46 | 26 | raise Exception("Unexpected DFS event: " + ev + " (expected: %s)" % event) |
8454e1fd JM |
27 | return ev |
28 | ||
d92da8a2 | 29 | def start_dfs_ap(ap, allow_failure=False, ssid="dfs", ht=True, ht40=False, |
803d0190 | 30 | ht40minus=False, vht80=False, vht20=False, chanlist=None, |
9cd52ac3 | 31 | channel=None, country="FI"): |
8454e1fd | 32 | ifname = ap['ifname'] |
8454e1fd | 33 | logger.info("Starting AP " + ifname + " on DFS channel") |
b29c46be | 34 | hapd = hostapd.add_ap(ap, {}, no_enable=True) |
bd5a7691 | 35 | hapd.set("ssid", ssid) |
9cd52ac3 | 36 | hapd.set("country_code", country) |
8454e1fd JM |
37 | hapd.set("ieee80211d", "1") |
38 | hapd.set("ieee80211h", "1") | |
39 | hapd.set("hw_mode", "a") | |
40 | hapd.set("channel", "52") | |
d92da8a2 JM |
41 | if not ht: |
42 | hapd.set("ieee80211n", "0") | |
bd5a7691 JM |
43 | if ht40: |
44 | hapd.set("ht_capab", "[HT40+]") | |
d92da8a2 JM |
45 | elif ht40minus: |
46 | hapd.set("ht_capab", "[HT40-]") | |
47 | hapd.set("channel", "56") | |
2a6cce38 JM |
48 | if vht80: |
49 | hapd.set("ieee80211ac", "1") | |
50 | hapd.set("vht_oper_chwidth", "1") | |
51 | hapd.set("vht_oper_centr_freq_seg0_idx", "58") | |
52 | if vht20: | |
53 | hapd.set("ieee80211ac", "1") | |
54 | hapd.set("vht_oper_chwidth", "0") | |
55 | hapd.set("vht_oper_centr_freq_seg0_idx", "0") | |
56 | if chanlist: | |
57 | hapd.set("chanlist", chanlist) | |
803d0190 JM |
58 | if channel: |
59 | hapd.set("channel", str(channel)) | |
8454e1fd JM |
60 | hapd.enable() |
61 | ||
62 | ev = wait_dfs_event(hapd, "DFS-CAC-START", 5) | |
63 | if "DFS-CAC-START" not in ev: | |
9a3eba46 | 64 | raise Exception("Unexpected DFS event: " + ev) |
8454e1fd JM |
65 | |
66 | state = hapd.get_status_field("state") | |
67 | if state != "DFS": | |
4f62bfef JM |
68 | if allow_failure: |
69 | logger.info("Interface state not DFS: " + state) | |
81e787b7 JM |
70 | if not os.path.exists("dfs"): |
71 | raise HwsimSkip("Assume DFS testing not supported") | |
72 | raise Exception("Failed to start DFS AP") | |
4f62bfef | 73 | raise Exception("Unexpected interface state: " + state) |
8454e1fd JM |
74 | |
75 | return hapd | |
76 | ||
bd5a7691 JM |
77 | def dfs_simulate_radar(hapd): |
78 | logger.info("Trigger a simulated radar event") | |
79 | phyname = hapd.get_driver_status_field("phyname") | |
80 | radar_file = '/sys/kernel/debug/ieee80211/' + phyname + '/hwsim/dfs_simulate_radar' | |
81 | with open(radar_file, 'w') as f: | |
82 | f.write('1') | |
83 | ||
8454e1fd JM |
84 | def test_dfs(dev, apdev): |
85 | """DFS CAC functionality on clear channel""" | |
4f62bfef | 86 | try: |
e246d7d5 | 87 | hapd = None |
9cd52ac3 | 88 | hapd = start_dfs_ap(apdev[0], allow_failure=True, country="US") |
4f62bfef JM |
89 | |
90 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
91 | if "success=1" not in ev: | |
92 | raise Exception("CAC failed") | |
93 | if "freq=5260" not in ev: | |
94 | raise Exception("Unexpected DFS freq result") | |
95 | ||
96 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
97 | if not ev: | |
98 | raise Exception("AP setup timed out") | |
99 | ||
100 | state = hapd.get_status_field("state") | |
101 | if state != "ENABLED": | |
102 | raise Exception("Unexpected interface state") | |
103 | ||
104 | freq = hapd.get_status_field("freq") | |
105 | if freq != "5260": | |
106 | raise Exception("Unexpected frequency") | |
107 | ||
c634d320 | 108 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 109 | dev[0].wait_regdom(country_ie=True) |
a8375c94 | 110 | hwsim_utils.test_connectivity(dev[0], hapd) |
831cb7af JM |
111 | |
112 | hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1") | |
113 | ev = hapd.wait_event(["DFS-RADAR-DETECTED"], timeout=10) | |
114 | if ev is None: | |
115 | raise Exception("DFS-RADAR-DETECTED event not reported") | |
116 | if "freq=5260" not in ev: | |
bc6e3288 | 117 | raise Exception("Incorrect frequency in radar detected event: " + ev) |
831cb7af JM |
118 | ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=70) |
119 | if ev is None: | |
120 | raise Exception("DFS-NEW-CHANNEL event not reported") | |
121 | if "freq=5260" in ev: | |
bc6e3288 | 122 | raise Exception("Channel did not change after radar was detected") |
831cb7af JM |
123 | |
124 | ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=70) | |
125 | if ev is None: | |
126 | raise Exception("AP-CSA-FINISHED event not reported") | |
127 | if "freq=5260" in ev: | |
bc6e3288 | 128 | raise Exception("Channel did not change after radar was detected(2)") |
831cb7af | 129 | time.sleep(1) |
a8375c94 | 130 | hwsim_utils.test_connectivity(dev[0], hapd) |
9cd52ac3 | 131 | finally: |
9cd52ac3 JM |
132 | if hapd: |
133 | hapd.request("DISABLE") | |
b586054f JM |
134 | dev[0].request("DISCONNECT") |
135 | dev[0].request("ABORT_SCAN") | |
136 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
9cd52ac3 | 137 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 138 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
9cd52ac3 JM |
139 | dev[0].flush_scan_cache() |
140 | ||
141 | def test_dfs_etsi(dev, apdev, params): | |
142 | """DFS and uniform spreading requirement for ETSI [long]""" | |
143 | if not params['long']: | |
144 | raise HwsimSkip("Skip test case with long duration due to --long not specified") | |
145 | try: | |
146 | hapd = None | |
147 | hapd = start_dfs_ap(apdev[0], allow_failure=True) | |
148 | ||
149 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
150 | if "success=1" not in ev: | |
151 | raise Exception("CAC failed") | |
152 | if "freq=5260" not in ev: | |
153 | raise Exception("Unexpected DFS freq result") | |
154 | ||
155 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
156 | if not ev: | |
157 | raise Exception("AP setup timed out") | |
158 | ||
159 | state = hapd.get_status_field("state") | |
160 | if state != "ENABLED": | |
161 | raise Exception("Unexpected interface state") | |
162 | ||
163 | freq = hapd.get_status_field("freq") | |
164 | if freq != "5260": | |
165 | raise Exception("Unexpected frequency") | |
166 | ||
167 | dev[0].connect("dfs", key_mgmt="NONE") | |
b586054f | 168 | dev[0].wait_regdom(country_ie=True) |
9cd52ac3 JM |
169 | hwsim_utils.test_connectivity(dev[0], hapd) |
170 | ||
171 | hapd.request("RADAR DETECTED freq=%s ht_enabled=1 chan_width=1" % freq) | |
172 | ev = hapd.wait_event(["DFS-RADAR-DETECTED"], timeout=5) | |
173 | if ev is None: | |
174 | raise Exception("DFS-RADAR-DETECTED event not reported") | |
175 | if "freq=%s" % freq not in ev: | |
176 | raise Exception("Incorrect frequency in radar detected event: " + ev) | |
177 | ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=5) | |
178 | if ev is None: | |
179 | raise Exception("DFS-NEW-CHANNEL event not reported") | |
180 | if "freq=%s" % freq in ev: | |
181 | raise Exception("Channel did not change after radar was detected") | |
182 | ||
183 | ev = hapd.wait_event(["AP-CSA-FINISHED", "DFS-CAC-START"], timeout=10) | |
184 | if ev is None: | |
185 | raise Exception("AP-CSA-FINISHED or DFS-CAC-START event not reported") | |
186 | if "DFS-CAC-START" in ev: | |
187 | # The selected new channel requires CAC | |
188 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
189 | if "success=1" not in ev: | |
190 | raise Exception("CAC failed") | |
191 | ||
192 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
193 | if not ev: | |
194 | raise Exception("AP setup timed out") | |
195 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=30) | |
196 | if not ev: | |
197 | raise Exception("STA did not reconnect on new DFS channel") | |
198 | else: | |
199 | # The new channel did not require CAC - try again | |
200 | if "freq=%s" % freq in ev: | |
201 | raise Exception("Channel did not change after radar was detected(2)") | |
202 | time.sleep(1) | |
203 | hwsim_utils.test_connectivity(dev[0], hapd) | |
4f62bfef | 204 | finally: |
9d7fdac5 JM |
205 | if hapd: |
206 | hapd.request("DISABLE") | |
b586054f JM |
207 | dev[0].request("DISCONNECT") |
208 | dev[0].request("ABORT_SCAN") | |
209 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
c4668009 | 210 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 211 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
9d7fdac5 | 212 | dev[0].flush_scan_cache() |
8454e1fd | 213 | |
32452fd2 JM |
214 | def test_dfs_radar1(dev, apdev): |
215 | """DFS CAC functionality with radar detected during initial CAC""" | |
4f62bfef | 216 | try: |
e246d7d5 | 217 | hapd = None |
8c6f6ac1 | 218 | hapd = start_dfs_ap(apdev[0], allow_failure=True) |
bc86d8c1 | 219 | time.sleep(1) |
8454e1fd | 220 | |
bd5a7691 JM |
221 | dfs_simulate_radar(hapd) |
222 | ||
bc86d8c1 JM |
223 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) |
224 | if ev is None: | |
225 | raise Exception("Timeout on DFS aborted event") | |
226 | if "success=0 freq=5260" not in ev: | |
227 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
228 | ||
229 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
4f62bfef JM |
230 | if "freq=5260" not in ev: |
231 | raise Exception("Unexpected DFS radar detection freq") | |
8454e1fd | 232 | |
4f62bfef JM |
233 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) |
234 | if "freq=5260" in ev: | |
235 | raise Exception("Unexpected DFS new freq") | |
8454e1fd | 236 | |
bc86d8c1 JM |
237 | ev = wait_dfs_event(hapd, None, 5) |
238 | if "AP-ENABLED" in ev: | |
239 | logger.info("Started AP on non-DFS channel") | |
240 | else: | |
241 | logger.info("Trying to start AP on another DFS channel") | |
242 | if "DFS-CAC-START" not in ev: | |
9a3eba46 | 243 | raise Exception("Unexpected DFS event: " + ev) |
bc86d8c1 JM |
244 | if "freq=5260" in ev: |
245 | raise Exception("Unexpected DFS CAC freq") | |
246 | ||
247 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
248 | if "success=1" not in ev: | |
249 | raise Exception("CAC failed") | |
250 | if "freq=5260" in ev: | |
251 | raise Exception("Unexpected DFS freq result - radar channel") | |
252 | ||
253 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
254 | if not ev: | |
255 | raise Exception("AP setup timed out") | |
256 | ||
257 | state = hapd.get_status_field("state") | |
258 | if state != "ENABLED": | |
259 | raise Exception("Unexpected interface state") | |
260 | ||
261 | freq = hapd.get_status_field("freq") | |
262 | if freq == "5260": | |
263 | raise Exception("Unexpected frequency: " + freq) | |
8454e1fd | 264 | |
c634d320 | 265 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 266 | dev[0].wait_regdom(country_ie=True) |
32452fd2 | 267 | finally: |
32452fd2 JM |
268 | if hapd: |
269 | hapd.request("DISABLE") | |
b586054f JM |
270 | dev[0].request("DISCONNECT") |
271 | dev[0].request("ABORT_SCAN") | |
272 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
32452fd2 | 273 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 274 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
32452fd2 | 275 | dev[0].flush_scan_cache() |
bd5a7691 | 276 | |
32452fd2 JM |
277 | def test_dfs_radar2(dev, apdev): |
278 | """DFS CAC functionality with radar detected after initial CAC""" | |
279 | try: | |
280 | hapd = None | |
281 | hapd = start_dfs_ap(apdev[0], ssid="dfs2", ht40=True) | |
282 | ||
283 | ev = hapd.wait_event(["AP-ENABLED"], timeout=70) | |
bd5a7691 JM |
284 | if not ev: |
285 | raise Exception("AP2 setup timed out") | |
286 | ||
32452fd2 | 287 | dfs_simulate_radar(hapd) |
bd5a7691 | 288 | |
32452fd2 | 289 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) |
bd5a7691 JM |
290 | if "freq=5260 ht_enabled=1 chan_offset=1 chan_width=2" not in ev: |
291 | raise Exception("Unexpected DFS radar detection freq from AP2") | |
292 | ||
32452fd2 | 293 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) |
bd5a7691 JM |
294 | if "freq=5260" in ev: |
295 | raise Exception("Unexpected DFS new freq for AP2") | |
296 | ||
32452fd2 | 297 | wait_dfs_event(hapd, None, 5) |
4f62bfef | 298 | finally: |
9d7fdac5 JM |
299 | if hapd: |
300 | hapd.request("DISABLE") | |
c4668009 | 301 | subprocess.call(['iw', 'reg', 'set', '00']) |
ba3146e1 | 302 | time.sleep(0.1) |
8454e1fd | 303 | |
9fd6804d | 304 | @remote_compatible |
4f62bfef JM |
305 | def test_dfs_radar_on_non_dfs_channel(dev, apdev): |
306 | """DFS radar detection test code on non-DFS channel""" | |
307 | params = { "ssid": "radar" } | |
8b8a1864 | 308 | hapd = hostapd.add_ap(apdev[0], params) |
4f62bfef JM |
309 | |
310 | hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1") | |
311 | hapd.request("RADAR DETECTED freq=2412 ht_enabled=1 chan_width=1") | |
2a6cce38 JM |
312 | |
313 | def test_dfs_radar_chanlist(dev, apdev): | |
314 | """DFS chanlist when radar is detected""" | |
315 | try: | |
e246d7d5 | 316 | hapd = None |
8c6f6ac1 | 317 | hapd = start_dfs_ap(apdev[0], chanlist="40 44", allow_failure=True) |
2a6cce38 JM |
318 | time.sleep(1) |
319 | ||
320 | dfs_simulate_radar(hapd) | |
321 | ||
322 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
323 | if ev is None: | |
324 | raise Exception("Timeout on DFS aborted event") | |
325 | if "success=0 freq=5260" not in ev: | |
326 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
327 | ||
328 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
329 | if "freq=5260" not in ev: | |
330 | raise Exception("Unexpected DFS radar detection freq") | |
331 | ||
332 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
333 | if "freq=5200 chan=40" not in ev and "freq=5220 chan=44" not in ev: | |
334 | raise Exception("Unexpected DFS new freq: " + ev) | |
335 | ||
336 | ev = wait_dfs_event(hapd, None, 5) | |
337 | if "AP-ENABLED" not in ev: | |
9a3eba46 | 338 | raise Exception("Unexpected DFS event: " + ev) |
2a6cce38 | 339 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 340 | dev[0].wait_regdom(country_ie=True) |
2a6cce38 | 341 | finally: |
9d7fdac5 JM |
342 | if hapd: |
343 | hapd.request("DISABLE") | |
b586054f JM |
344 | dev[0].request("DISCONNECT") |
345 | dev[0].request("ABORT_SCAN") | |
346 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
c4668009 | 347 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 348 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
9d7fdac5 | 349 | dev[0].flush_scan_cache() |
2a6cce38 JM |
350 | |
351 | def test_dfs_radar_chanlist_vht80(dev, apdev): | |
352 | """DFS chanlist when radar is detected and VHT80 configured""" | |
353 | try: | |
e246d7d5 | 354 | hapd = None |
8c6f6ac1 JM |
355 | hapd = start_dfs_ap(apdev[0], chanlist="36", ht40=True, vht80=True, |
356 | allow_failure=True) | |
2a6cce38 JM |
357 | time.sleep(1) |
358 | ||
359 | dfs_simulate_radar(hapd) | |
360 | ||
361 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
362 | if ev is None: | |
363 | raise Exception("Timeout on DFS aborted event") | |
364 | if "success=0 freq=5260" not in ev: | |
365 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
366 | ||
367 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
368 | if "freq=5260" not in ev: | |
369 | raise Exception("Unexpected DFS radar detection freq") | |
370 | ||
371 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
372 | if "freq=5180 chan=36 sec_chan=1" not in ev: | |
373 | raise Exception("Unexpected DFS new freq: " + ev) | |
374 | ||
375 | ev = wait_dfs_event(hapd, None, 5) | |
376 | if "AP-ENABLED" not in ev: | |
9a3eba46 | 377 | raise Exception("Unexpected DFS event: " + ev) |
2a6cce38 | 378 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 379 | dev[0].wait_regdom(country_ie=True) |
2a6cce38 JM |
380 | |
381 | if hapd.get_status_field('vht_oper_centr_freq_seg0_idx') != "42": | |
382 | raise Exception("Unexpected seg0 idx") | |
383 | finally: | |
9d7fdac5 JM |
384 | if hapd: |
385 | hapd.request("DISABLE") | |
b586054f JM |
386 | dev[0].request("DISCONNECT") |
387 | dev[0].request("ABORT_SCAN") | |
388 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
c4668009 | 389 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 390 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
9d7fdac5 | 391 | dev[0].flush_scan_cache() |
2a6cce38 JM |
392 | |
393 | def test_dfs_radar_chanlist_vht20(dev, apdev): | |
394 | """DFS chanlist when radar is detected and VHT40 configured""" | |
395 | try: | |
e246d7d5 | 396 | hapd = None |
8c6f6ac1 JM |
397 | hapd = start_dfs_ap(apdev[0], chanlist="36", vht20=True, |
398 | allow_failure=True) | |
2a6cce38 JM |
399 | time.sleep(1) |
400 | ||
401 | dfs_simulate_radar(hapd) | |
402 | ||
403 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
404 | if ev is None: | |
405 | raise Exception("Timeout on DFS aborted event") | |
406 | if "success=0 freq=5260" not in ev: | |
407 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
408 | ||
409 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
410 | if "freq=5260" not in ev: | |
411 | raise Exception("Unexpected DFS radar detection freq") | |
412 | ||
413 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
414 | if "freq=5180 chan=36 sec_chan=0" not in ev: | |
415 | raise Exception("Unexpected DFS new freq: " + ev) | |
416 | ||
417 | ev = wait_dfs_event(hapd, None, 5) | |
418 | if "AP-ENABLED" not in ev: | |
9a3eba46 | 419 | raise Exception("Unexpected DFS event: " + ev) |
2a6cce38 | 420 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 421 | dev[0].wait_regdom(country_ie=True) |
2a6cce38 | 422 | finally: |
9d7fdac5 JM |
423 | if hapd: |
424 | hapd.request("DISABLE") | |
b586054f JM |
425 | dev[0].request("DISCONNECT") |
426 | dev[0].request("ABORT_SCAN") | |
427 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
c4668009 | 428 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 429 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
9d7fdac5 | 430 | dev[0].flush_scan_cache() |
d92da8a2 JM |
431 | |
432 | def test_dfs_radar_no_ht(dev, apdev): | |
433 | """DFS chanlist when radar is detected and no HT configured""" | |
434 | try: | |
e246d7d5 | 435 | hapd = None |
8c6f6ac1 JM |
436 | hapd = start_dfs_ap(apdev[0], chanlist="36", ht=False, |
437 | allow_failure=True) | |
d92da8a2 JM |
438 | time.sleep(1) |
439 | ||
440 | dfs_simulate_radar(hapd) | |
441 | ||
442 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
443 | if ev is None: | |
444 | raise Exception("Timeout on DFS aborted event") | |
445 | if "success=0 freq=5260" not in ev: | |
446 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
447 | ||
448 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
449 | if "freq=5260 ht_enabled=0" not in ev: | |
450 | raise Exception("Unexpected DFS radar detection freq: " + ev) | |
451 | ||
452 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
453 | if "freq=5180 chan=36 sec_chan=0" not in ev: | |
454 | raise Exception("Unexpected DFS new freq: " + ev) | |
455 | ||
456 | ev = wait_dfs_event(hapd, None, 5) | |
457 | if "AP-ENABLED" not in ev: | |
9a3eba46 | 458 | raise Exception("Unexpected DFS event: " + ev) |
d92da8a2 | 459 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f | 460 | dev[0].wait_regdom(country_ie=True) |
d92da8a2 | 461 | finally: |
d92da8a2 JM |
462 | if hapd: |
463 | hapd.request("DISABLE") | |
b586054f JM |
464 | dev[0].request("DISCONNECT") |
465 | dev[0].request("ABORT_SCAN") | |
466 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
d92da8a2 | 467 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 468 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
d92da8a2 JM |
469 | dev[0].flush_scan_cache() |
470 | ||
471 | def test_dfs_radar_ht40minus(dev, apdev): | |
472 | """DFS chanlist when radar is detected and HT40- configured""" | |
473 | try: | |
e246d7d5 | 474 | hapd = None |
8c6f6ac1 JM |
475 | hapd = start_dfs_ap(apdev[0], chanlist="36", ht40minus=True, |
476 | allow_failure=True) | |
d92da8a2 JM |
477 | time.sleep(1) |
478 | ||
479 | dfs_simulate_radar(hapd) | |
480 | ||
481 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5) | |
482 | if ev is None: | |
483 | raise Exception("Timeout on DFS aborted event") | |
484 | if "success=0 freq=5280 ht_enabled=1 chan_offset=-1" not in ev: | |
485 | raise Exception("Unexpected DFS aborted event contents: " + ev) | |
486 | ||
487 | ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5) | |
488 | if "freq=5280 ht_enabled=1 chan_offset=-1" not in ev: | |
489 | raise Exception("Unexpected DFS radar detection freq: " + ev) | |
490 | ||
491 | ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5) | |
492 | if "freq=5180 chan=36 sec_chan=1" not in ev: | |
493 | raise Exception("Unexpected DFS new freq: " + ev) | |
494 | ||
495 | ev = wait_dfs_event(hapd, None, 5) | |
496 | if "AP-ENABLED" not in ev: | |
9a3eba46 | 497 | raise Exception("Unexpected DFS event: " + ev) |
d92da8a2 | 498 | dev[0].connect("dfs", key_mgmt="NONE") |
b586054f JM |
499 | dev[0].wait_regdom(country_ie=True) |
500 | dev[0].request("STA_AUTOCONNECT 0") | |
d92da8a2 | 501 | finally: |
d92da8a2 JM |
502 | if hapd: |
503 | hapd.request("DISABLE") | |
b586054f JM |
504 | dev[0].request("DISCONNECT") |
505 | dev[0].request("ABORT_SCAN") | |
506 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
d92da8a2 | 507 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 508 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
d92da8a2 | 509 | dev[0].flush_scan_cache() |
b586054f | 510 | dev[0].request("STA_AUTOCONNECT 1") |
803d0190 JM |
511 | |
512 | def test_dfs_ht40_minus(dev, apdev, params): | |
513 | """DFS CAC functionality on channel 104 HT40- [long]""" | |
514 | if not params['long']: | |
515 | raise HwsimSkip("Skip test case with long duration due to --long not specified") | |
516 | try: | |
517 | hapd = None | |
518 | hapd = start_dfs_ap(apdev[0], allow_failure=True, ht40minus=True, | |
519 | channel=104) | |
520 | ||
521 | ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) | |
522 | if "success=1" not in ev: | |
523 | raise Exception("CAC failed") | |
524 | if "freq=5520" not in ev: | |
525 | raise Exception("Unexpected DFS freq result") | |
526 | ||
527 | ev = hapd.wait_event(["AP-ENABLED"], timeout=5) | |
528 | if not ev: | |
529 | raise Exception("AP setup timed out") | |
530 | ||
531 | state = hapd.get_status_field("state") | |
532 | if state != "ENABLED": | |
533 | raise Exception("Unexpected interface state") | |
534 | ||
535 | freq = hapd.get_status_field("freq") | |
536 | if freq != "5520": | |
537 | raise Exception("Unexpected frequency") | |
538 | ||
539 | dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5520") | |
b586054f | 540 | dev[0].wait_regdom(country_ie=True) |
803d0190 JM |
541 | hwsim_utils.test_connectivity(dev[0], hapd) |
542 | finally: | |
803d0190 JM |
543 | if hapd: |
544 | hapd.request("DISABLE") | |
b586054f JM |
545 | dev[0].request("DISCONNECT") |
546 | dev[0].request("ABORT_SCAN") | |
547 | dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
803d0190 | 548 | subprocess.call(['iw', 'reg', 'set', '00']) |
b586054f | 549 | dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5) |
803d0190 | 550 | dev[0].flush_scan_cache() |