]> git.ipfire.org Git - thirdparty/hostap.git/blame_incremental - tests/hwsim/test_dfs.py
tests: DFS channel switch
[thirdparty/hostap.git] / tests / hwsim / test_dfs.py
... / ...
CommitLineData
1# Test cases for DFS
2# Copyright (c) 2013-2019, 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
7from remotehost import remote_compatible
8import os
9import subprocess
10import time
11import logging
12logger = logging.getLogger()
13
14import hwsim_utils
15import hostapd
16from utils import *
17
18def wait_dfs_event(hapd, event, timeout):
19 dfs_events = ["DFS-RADAR-DETECTED", "DFS-NEW-CHANNEL",
20 "DFS-CAC-START", "DFS-CAC-COMPLETED",
21 "DFS-NOP-FINISHED", "AP-ENABLED", "AP-CSA-FINISHED"]
22 ev = hapd.wait_event(dfs_events, timeout=timeout)
23 if not ev:
24 raise Exception("DFS event timed out")
25 if event and event not in ev:
26 raise Exception("Unexpected DFS event: " + ev + " (expected: %s)" % event)
27 return ev
28
29def start_dfs_ap(ap, ssid="dfs", ht=True, ht40=False,
30 ht40minus=False, vht80=False, vht20=False, chanlist=None,
31 channel=None, country="FI", rrm_beacon_report=False,
32 chan100=False):
33 ifname = ap['ifname']
34 logger.info("Starting AP " + ifname + " on DFS channel")
35 hapd = hostapd.add_ap(ap, {}, no_enable=True)
36 hapd.set("ssid", ssid)
37 hapd.set("country_code", country)
38 hapd.set("ieee80211d", "1")
39 hapd.set("ieee80211h", "1")
40 hapd.set("hw_mode", "a")
41 if chan100:
42 hapd.set("channel", "100")
43 else:
44 hapd.set("channel", "52")
45 if not ht:
46 hapd.set("ieee80211n", "0")
47 if ht40:
48 hapd.set("ht_capab", "[HT40+]")
49 elif ht40minus:
50 hapd.set("ht_capab", "[HT40-]")
51 hapd.set("channel", "56")
52 if vht80:
53 hapd.set("ieee80211ac", "1")
54 hapd.set("vht_oper_chwidth", "1")
55 if chan100:
56 hapd.set("vht_oper_centr_freq_seg0_idx", "106")
57 else:
58 hapd.set("vht_oper_centr_freq_seg0_idx", "58")
59 if vht20:
60 hapd.set("ieee80211ac", "1")
61 hapd.set("vht_oper_chwidth", "0")
62 hapd.set("vht_oper_centr_freq_seg0_idx", "0")
63 if chanlist:
64 hapd.set("chanlist", chanlist)
65 if channel:
66 hapd.set("channel", str(channel))
67 if rrm_beacon_report:
68 hapd.set("rrm_beacon_report", "1")
69 hapd.enable()
70
71 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
72 if "DFS-CAC-START" not in ev:
73 raise Exception("Unexpected DFS event: " + ev)
74
75 state = hapd.get_status_field("state")
76 if state != "DFS":
77 raise Exception("Unexpected interface state: " + state)
78
79 return hapd
80
81def dfs_simulate_radar(hapd):
82 logger.info("Trigger a simulated radar event")
83 phyname = hapd.get_driver_status_field("phyname")
84 radar_file = '/sys/kernel/debug/ieee80211/' + phyname + '/hwsim/dfs_simulate_radar'
85 with open(radar_file, 'w') as f:
86 f.write('1')
87
88def test_dfs(dev, apdev):
89 """DFS CAC functionality on clear channel"""
90 try:
91 hapd = None
92 hapd = start_dfs_ap(apdev[0], country="US")
93
94 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
95 if "success=1" not in ev:
96 raise Exception("CAC failed")
97 if "freq=5260" not in ev:
98 raise Exception("Unexpected DFS freq result")
99
100 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
101 if not ev:
102 raise Exception("AP setup timed out")
103
104 state = hapd.get_status_field("state")
105 if state != "ENABLED":
106 raise Exception("Unexpected interface state")
107
108 freq = hapd.get_status_field("freq")
109 if freq != "5260":
110 raise Exception("Unexpected frequency")
111
112 dev[0].connect("dfs", key_mgmt="NONE")
113 dev[0].wait_regdom(country_ie=True)
114 hwsim_utils.test_connectivity(dev[0], hapd)
115
116 hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
117 ev = hapd.wait_event(["DFS-RADAR-DETECTED"], timeout=10)
118 if ev is None:
119 raise Exception("DFS-RADAR-DETECTED event not reported")
120 if "freq=5260" not in ev:
121 raise Exception("Incorrect frequency in radar detected event: " + ev)
122 ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=70)
123 if ev is None:
124 raise Exception("DFS-NEW-CHANNEL event not reported")
125 if "freq=5260" in ev:
126 raise Exception("Channel did not change after radar was detected")
127
128 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=70)
129 if ev is None:
130 raise Exception("AP-CSA-FINISHED event not reported")
131 if "freq=5260" in ev:
132 raise Exception("Channel did not change after radar was detected(2)")
133 time.sleep(1)
134 hwsim_utils.test_connectivity(dev[0], hapd)
135 finally:
136 clear_regdom(hapd, dev)
137
138def test_dfs_etsi(dev, apdev, params):
139 """DFS and uniform spreading requirement for ETSI [long]"""
140 if not params['long']:
141 raise HwsimSkip("Skip test case with long duration due to --long not specified")
142 try:
143 hapd = None
144 hapd = start_dfs_ap(apdev[0])
145
146 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
147 if "success=1" not in ev:
148 raise Exception("CAC failed")
149 if "freq=5260" not in ev:
150 raise Exception("Unexpected DFS freq result")
151
152 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
153 if not ev:
154 raise Exception("AP setup timed out")
155
156 state = hapd.get_status_field("state")
157 if state != "ENABLED":
158 raise Exception("Unexpected interface state")
159
160 freq = hapd.get_status_field("freq")
161 if freq != "5260":
162 raise Exception("Unexpected frequency")
163
164 dev[0].connect("dfs", key_mgmt="NONE")
165 dev[0].wait_regdom(country_ie=True)
166 hwsim_utils.test_connectivity(dev[0], hapd)
167
168 hapd.request("RADAR DETECTED freq=%s ht_enabled=1 chan_width=1" % freq)
169 ev = hapd.wait_event(["DFS-RADAR-DETECTED"], timeout=5)
170 if ev is None:
171 raise Exception("DFS-RADAR-DETECTED event not reported")
172 if "freq=%s" % freq not in ev:
173 raise Exception("Incorrect frequency in radar detected event: " + ev)
174 ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=5)
175 if ev is None:
176 raise Exception("DFS-NEW-CHANNEL event not reported")
177 if "freq=%s" % freq in ev:
178 raise Exception("Channel did not change after radar was detected")
179
180 ev = hapd.wait_event(["AP-CSA-FINISHED", "DFS-CAC-START"], timeout=10)
181 if ev is None:
182 raise Exception("AP-CSA-FINISHED or DFS-CAC-START event not reported")
183 if "DFS-CAC-START" in ev:
184 # The selected new channel requires CAC
185 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
186 if "success=1" not in ev:
187 raise Exception("CAC failed")
188
189 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
190 if not ev:
191 raise Exception("AP setup timed out")
192 ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=30)
193 if not ev:
194 raise Exception("STA did not reconnect on new DFS channel")
195 else:
196 # The new channel did not require CAC - try again
197 if "freq=%s" % freq in ev:
198 raise Exception("Channel did not change after radar was detected(2)")
199 time.sleep(1)
200 hwsim_utils.test_connectivity(dev[0], hapd)
201 finally:
202 clear_regdom(hapd, dev)
203
204def test_dfs_radar1(dev, apdev):
205 """DFS CAC functionality with radar detected during initial CAC"""
206 try:
207 hapd = None
208 hapd = start_dfs_ap(apdev[0])
209 time.sleep(1)
210
211 dfs_simulate_radar(hapd)
212
213 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
214 if ev is None:
215 raise Exception("Timeout on DFS aborted event")
216 if "success=0 freq=5260" not in ev:
217 raise Exception("Unexpected DFS aborted event contents: " + ev)
218
219 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
220 if "freq=5260" not in ev:
221 raise Exception("Unexpected DFS radar detection freq")
222
223 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
224 if "freq=5260" in ev:
225 raise Exception("Unexpected DFS new freq")
226
227 ev = wait_dfs_event(hapd, None, 5)
228 if "AP-ENABLED" in ev:
229 logger.info("Started AP on non-DFS channel")
230 else:
231 logger.info("Trying to start AP on another DFS channel")
232 if "DFS-CAC-START" not in ev:
233 raise Exception("Unexpected DFS event: " + ev)
234 if "freq=5260" in ev:
235 raise Exception("Unexpected DFS CAC freq")
236
237 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
238 if "success=1" not in ev:
239 raise Exception("CAC failed")
240 if "freq=5260" in ev:
241 raise Exception("Unexpected DFS freq result - radar channel")
242
243 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
244 if not ev:
245 raise Exception("AP setup timed out")
246
247 state = hapd.get_status_field("state")
248 if state != "ENABLED":
249 raise Exception("Unexpected interface state")
250
251 freq = hapd.get_status_field("freq")
252 if freq == "5260":
253 raise Exception("Unexpected frequency: " + freq)
254
255 dev[0].connect("dfs", key_mgmt="NONE")
256 dev[0].wait_regdom(country_ie=True)
257 finally:
258 clear_regdom(hapd, dev)
259
260def test_dfs_radar2(dev, apdev):
261 """DFS CAC functionality with radar detected after initial CAC"""
262 try:
263 hapd = None
264 hapd = start_dfs_ap(apdev[0], ssid="dfs2", ht40=True)
265
266 ev = hapd.wait_event(["AP-ENABLED"], timeout=70)
267 if not ev:
268 raise Exception("AP2 setup timed out")
269
270 dfs_simulate_radar(hapd)
271
272 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
273 if "freq=5260 ht_enabled=1 chan_offset=1 chan_width=2" not in ev:
274 raise Exception("Unexpected DFS radar detection freq from AP2")
275
276 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
277 if "freq=5260" in ev:
278 raise Exception("Unexpected DFS new freq for AP2")
279
280 wait_dfs_event(hapd, None, 5)
281 finally:
282 clear_regdom(hapd, dev)
283
284@remote_compatible
285def test_dfs_radar_on_non_dfs_channel(dev, apdev):
286 """DFS radar detection test code on non-DFS channel"""
287 params = {"ssid": "radar"}
288 hapd = hostapd.add_ap(apdev[0], params)
289
290 hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
291 hapd.request("RADAR DETECTED freq=2412 ht_enabled=1 chan_width=1")
292
293def test_dfs_radar_chanlist(dev, apdev):
294 """DFS chanlist when radar is detected"""
295 try:
296 hapd = None
297 hapd = start_dfs_ap(apdev[0], chanlist="40 44")
298 time.sleep(1)
299
300 dfs_simulate_radar(hapd)
301
302 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
303 if ev is None:
304 raise Exception("Timeout on DFS aborted event")
305 if "success=0 freq=5260" not in ev:
306 raise Exception("Unexpected DFS aborted event contents: " + ev)
307
308 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
309 if "freq=5260" not in ev:
310 raise Exception("Unexpected DFS radar detection freq")
311
312 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
313 if "freq=5200 chan=40" not in ev and "freq=5220 chan=44" not in ev:
314 raise Exception("Unexpected DFS new freq: " + ev)
315
316 ev = wait_dfs_event(hapd, None, 5)
317 if "AP-ENABLED" not in ev:
318 raise Exception("Unexpected DFS event: " + ev)
319 dev[0].connect("dfs", key_mgmt="NONE")
320 dev[0].wait_regdom(country_ie=True)
321 finally:
322 clear_regdom(hapd, dev)
323
324def test_dfs_radar_chanlist_vht80(dev, apdev):
325 """DFS chanlist when radar is detected and VHT80 configured"""
326 try:
327 hapd = None
328 hapd = start_dfs_ap(apdev[0], chanlist="36", ht40=True, vht80=True)
329 time.sleep(1)
330
331 dfs_simulate_radar(hapd)
332
333 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
334 if ev is None:
335 raise Exception("Timeout on DFS aborted event")
336 if "success=0 freq=5260" not in ev:
337 raise Exception("Unexpected DFS aborted event contents: " + ev)
338
339 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
340 if "freq=5260" not in ev:
341 raise Exception("Unexpected DFS radar detection freq")
342
343 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
344 if "freq=5180 chan=36 sec_chan=1" not in ev:
345 raise Exception("Unexpected DFS new freq: " + ev)
346
347 ev = wait_dfs_event(hapd, None, 5)
348 if "AP-ENABLED" not in ev:
349 raise Exception("Unexpected DFS event: " + ev)
350 dev[0].connect("dfs", key_mgmt="NONE")
351 dev[0].wait_regdom(country_ie=True)
352
353 if hapd.get_status_field('vht_oper_centr_freq_seg0_idx') != "42":
354 raise Exception("Unexpected seg0 idx")
355 finally:
356 clear_regdom(hapd, dev)
357
358def test_dfs_radar_chanlist_vht20(dev, apdev):
359 """DFS chanlist when radar is detected and VHT40 configured"""
360 try:
361 hapd = None
362 hapd = start_dfs_ap(apdev[0], chanlist="36", vht20=True)
363 time.sleep(1)
364
365 dfs_simulate_radar(hapd)
366
367 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
368 if ev is None:
369 raise Exception("Timeout on DFS aborted event")
370 if "success=0 freq=5260" not in ev:
371 raise Exception("Unexpected DFS aborted event contents: " + ev)
372
373 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
374 if "freq=5260" not in ev:
375 raise Exception("Unexpected DFS radar detection freq")
376
377 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
378 if "freq=5180 chan=36 sec_chan=0" not in ev:
379 raise Exception("Unexpected DFS new freq: " + ev)
380
381 ev = wait_dfs_event(hapd, None, 5)
382 if "AP-ENABLED" not in ev:
383 raise Exception("Unexpected DFS event: " + ev)
384 dev[0].connect("dfs", key_mgmt="NONE")
385 dev[0].wait_regdom(country_ie=True)
386 finally:
387 clear_regdom(hapd, dev)
388
389def test_dfs_radar_no_ht(dev, apdev):
390 """DFS chanlist when radar is detected and no HT configured"""
391 try:
392 hapd = None
393 hapd = start_dfs_ap(apdev[0], chanlist="36", ht=False)
394 time.sleep(1)
395
396 dfs_simulate_radar(hapd)
397
398 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
399 if ev is None:
400 raise Exception("Timeout on DFS aborted event")
401 if "success=0 freq=5260" not in ev:
402 raise Exception("Unexpected DFS aborted event contents: " + ev)
403
404 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
405 if "freq=5260 ht_enabled=0" not in ev:
406 raise Exception("Unexpected DFS radar detection freq: " + ev)
407
408 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
409 if "freq=5180 chan=36 sec_chan=0" not in ev:
410 raise Exception("Unexpected DFS new freq: " + ev)
411
412 ev = wait_dfs_event(hapd, None, 5)
413 if "AP-ENABLED" not in ev:
414 raise Exception("Unexpected DFS event: " + ev)
415 dev[0].connect("dfs", key_mgmt="NONE")
416 dev[0].wait_regdom(country_ie=True)
417 finally:
418 clear_regdom(hapd, dev)
419
420def test_dfs_radar_ht40minus(dev, apdev):
421 """DFS chanlist when radar is detected and HT40- configured"""
422 try:
423 hapd = None
424 hapd = start_dfs_ap(apdev[0], chanlist="36", ht40minus=True)
425 time.sleep(1)
426
427 dfs_simulate_radar(hapd)
428
429 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
430 if ev is None:
431 raise Exception("Timeout on DFS aborted event")
432 if "success=0 freq=5280 ht_enabled=1 chan_offset=-1" not in ev:
433 raise Exception("Unexpected DFS aborted event contents: " + ev)
434
435 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
436 if "freq=5280 ht_enabled=1 chan_offset=-1" not in ev:
437 raise Exception("Unexpected DFS radar detection freq: " + ev)
438
439 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
440 if "freq=5180 chan=36 sec_chan=1" not in ev:
441 raise Exception("Unexpected DFS new freq: " + ev)
442
443 ev = wait_dfs_event(hapd, None, 5)
444 if "AP-ENABLED" not in ev:
445 raise Exception("Unexpected DFS event: " + ev)
446 dev[0].connect("dfs", key_mgmt="NONE")
447 dev[0].wait_regdom(country_ie=True)
448 dev[0].request("STA_AUTOCONNECT 0")
449 finally:
450 clear_regdom(hapd, dev)
451 dev[0].request("STA_AUTOCONNECT 1")
452
453def test_dfs_ht40_minus(dev, apdev, params):
454 """DFS CAC functionality on channel 104 HT40- [long]"""
455 if not params['long']:
456 raise HwsimSkip("Skip test case with long duration due to --long not specified")
457 try:
458 hapd = None
459 hapd = start_dfs_ap(apdev[0], ht40minus=True, channel=104)
460
461 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
462 if "success=1" not in ev:
463 raise Exception("CAC failed")
464 if "freq=5520" not in ev:
465 raise Exception("Unexpected DFS freq result")
466
467 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
468 if not ev:
469 raise Exception("AP setup timed out")
470
471 state = hapd.get_status_field("state")
472 if state != "ENABLED":
473 raise Exception("Unexpected interface state")
474
475 freq = hapd.get_status_field("freq")
476 if freq != "5520":
477 raise Exception("Unexpected frequency")
478
479 dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5520")
480 dev[0].wait_regdom(country_ie=True)
481 hwsim_utils.test_connectivity(dev[0], hapd)
482 finally:
483 clear_regdom(hapd, dev)
484
485def test_dfs_cac_restart_on_enable(dev, apdev):
486 """DFS CAC interrupted and restarted"""
487 try:
488 hapd = None
489 hapd = start_dfs_ap(apdev[0])
490 time.sleep(0.1)
491 subprocess.check_call(['ip', 'link', 'set', 'dev', hapd.ifname, 'down'])
492 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
493 if ev is None:
494 raise Exception("Timeout on DFS aborted event")
495 if "success=0 freq=5260" not in ev:
496 raise Exception("Unexpected DFS aborted event contents: " + ev)
497 time.sleep(0.1)
498 subprocess.check_call(['ip', 'link', 'set', 'dev', hapd.ifname, 'up'])
499
500 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
501 if "DFS-CAC-START" not in ev:
502 raise Exception("Unexpected DFS event: " + ev)
503 hapd.disable()
504
505 finally:
506 clear_regdom(hapd, dev)
507
508def test_dfs_rrm(dev, apdev, params):
509 """DFS with RRM [long]"""
510 if not params['long']:
511 raise HwsimSkip("Skip test case with long duration due to --long not specified")
512 try:
513 hapd = None
514 hapd = start_dfs_ap(apdev[0], country="US", rrm_beacon_report=True)
515
516 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
517 if "success=1" not in ev or "freq=5260" not in ev:
518 raise Exception("Unexpected DFS freq result")
519 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
520 if not ev:
521 raise Exception("AP setup timed out")
522
523 dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5260")
524 dev[0].wait_regdom(country_ie=True)
525 hapd.wait_sta()
526 hwsim_utils.test_connectivity(dev[0], hapd)
527 addr = dev[0].own_addr()
528 token = hapd.request("REQ_BEACON " + addr + " " + "51000000000002ffffffffffff")
529 if "FAIL" in token:
530 raise Exception("REQ_BEACON failed")
531 ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
532 if ev is None:
533 raise Exception("Beacon report response not received")
534 finally:
535 clear_regdom(hapd, dev)
536
537def test_dfs_radar_vht80_downgrade(dev, apdev, params):
538 """DFS channel bandwidth downgrade from VHT80 to VHT40 [long]"""
539 if not params['long']:
540 raise HwsimSkip("Skip test case with long duration due to --long not specified")
541 try:
542 # Start with 80 MHz channel 100 (5500 MHz) to find a radar
543 hapd = None
544 hapd = start_dfs_ap(apdev[0], chanlist="100-140",
545 ht40=True, vht80=True, chan100=True)
546 time.sleep(1)
547 dfs_simulate_radar(hapd)
548
549 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
550 if ev is None:
551 raise Exception("Timeout on DFS aborted event")
552 if "success=0 freq=5500" not in ev:
553 raise Exception("Unexpected DFS aborted event contents: " + ev)
554
555 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
556 if "freq=5500" not in ev:
557 raise Exception("Unexpected DFS radar detection freq: " + ev)
558
559 # The only other available 80 MHz channel in the chanlist is
560 # 116 (5580 MHz), so that will be selected next.
561 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
562 if "freq=5580 chan=116 sec_chan=1" not in ev:
563 raise Exception("Unexpected DFS new freq: " + ev)
564
565 ev = wait_dfs_event(hapd, None, 5)
566 if "DFS-CAC-START" not in ev:
567 raise Exception("Unexpected DFS event: " + ev)
568 if "freq=5580" not in ev:
569 raise Exception("Unexpected DFS CAC freq: " + ev)
570
571 time.sleep(1)
572 dfs_simulate_radar(hapd)
573 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 5)
574 if ev is None:
575 raise Exception("Timeout on DFS aborted event (2)")
576 if "success=0 freq=5580" not in ev:
577 raise Exception("Unexpected DFS aborted event (2) contents: " + ev)
578
579 ev = wait_dfs_event(hapd, "DFS-RADAR-DETECTED", 5)
580 if "freq=5580" not in ev:
581 raise Exception("Unexpected DFS radar detection (2) freq: " + ev)
582
583 # No more 80 MHz channels are available, so have to downgrade to 40 MHz
584 # channels and the only remaining one is channel 132 (5660 MHz).
585 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
586 if "freq=5660 chan=132 sec_chan=1" not in ev:
587 raise Exception("Unexpected DFS new freq (2): " + ev)
588
589 ev = wait_dfs_event(hapd, None, 5)
590 if "DFS-CAC-START" not in ev:
591 raise Exception("Unexpected DFS event: " + ev)
592 if "freq=5660" not in ev:
593 raise Exception("Unexpected DFS CAC freq (2): " + ev)
594
595 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
596 if "success=1" not in ev:
597 raise Exception("CAC failed")
598 if "freq=5660" not in ev:
599 raise Exception("Unexpected DFS freq result: " + ev)
600
601 ev = wait_dfs_event(hapd, None, 5)
602 if "AP-ENABLED" not in ev:
603 raise Exception("Unexpected DFS event: " + ev)
604 dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5660")
605 dev[0].wait_regdom(country_ie=True)
606 sig = dev[0].request("SIGNAL_POLL").splitlines()
607 if "FREQUENCY=5660" not in sig or "WIDTH=40 MHz" not in sig:
608 raise Exception("Unexpected SIGNAL_POLL value: " + str(sig))
609 finally:
610 clear_regdom(hapd, dev)
611
612def test_dfs_chan_switch(dev, apdev, params):
613 """DFS channel switch [long]"""
614 if not params['long']:
615 raise HwsimSkip("Skip test case with long duration due to --long not specified")
616 try:
617 hapd = None
618 hapd = start_dfs_ap(apdev[0], country="US")
619
620 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
621 if "success=1" not in ev:
622 raise Exception("CAC failed")
623 if "freq=5260" not in ev:
624 raise Exception("Unexpected DFS freq result")
625 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
626 if not ev:
627 raise Exception("AP setup timed out")
628 freq = hapd.get_status_field("freq")
629 if freq != "5260":
630 raise Exception("Unexpected frequency")
631
632 dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5260 5280")
633 dev[0].wait_regdom(country_ie=True)
634 hwsim_utils.test_connectivity(dev[0], hapd)
635
636 if "OK" not in hapd.request("CHAN_SWITCH 5 5280 ht"):
637 raise Exception("CHAN_SWITCH failed")
638 # This results in BSS going down before restart, so the STA is expected
639 # to report disconnection.
640 dev[0].wait_disconnected()
641 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
642 if "freq=5280" not in ev:
643 raise Exception("Unexpected channel: " + ev)
644 ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
645 if "success=1" not in ev:
646 raise Exception("CAC failed")
647 if "freq=5280" not in ev:
648 raise Exception("Unexpected DFS freq result")
649 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
650 if not ev:
651 raise Exception("AP setup timed out")
652 freq = hapd.get_status_field("freq")
653 if freq != "5280":
654 raise Exception("Unexpected frequency")
655
656 dev[0].wait_connected(timeout=30)
657 hwsim_utils.test_connectivity(dev[0], hapd)
658 finally:
659 clear_regdom(hapd, dev)