]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_dfs.py
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 logger
= logging
.getLogger()
16 def wait_dfs_event(hapd
, event
, timeout
):
17 dfs_events
= [ "DFS-RADAR-DETECTED", "DFS-NEW-CHANNEL",
18 "DFS-CAC-START", "DFS-CAC-COMPLETED",
19 "DFS-NOP-FINISHED", "AP-ENABLED" ]
20 ev
= hapd
.wait_event(dfs_events
, timeout
=timeout
)
22 raise Exception("DFS event timed out")
24 raise Exception("Unexpected DFS event")
27 def start_dfs_ap(ap
, allow_failure
=False):
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
)
35 raise Exception("Could not ping hostapd")
37 hapd
.set("ssid", "dfs")
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")
45 ev
= wait_dfs_event(hapd
, "DFS-CAC-START", 5)
46 if "DFS-CAC-START" not in ev
:
47 raise Exception("Unexpected DFS event")
49 state
= hapd
.get_status_field("state")
52 logger
.info("Interface state not DFS: " + state
)
54 raise Exception("Unexpected interface state: " + state
)
58 def test_dfs(dev
, apdev
):
59 """DFS CAC functionality on clear channel"""
61 hapd
= start_dfs_ap(apdev
[0], allow_failure
=True)
63 if not os
.path
.exists("dfs"):
65 raise Exception("Failed to start DFS AP")
67 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
68 if "success=1" not in ev
:
69 raise Exception("CAC failed")
70 if "freq=5260" not in ev
:
71 raise Exception("Unexpected DFS freq result")
73 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
75 raise Exception("AP setup timed out")
77 state
= hapd
.get_status_field("state")
78 if state
!= "ENABLED":
79 raise Exception("Unexpected interface state")
81 freq
= hapd
.get_status_field("freq")
83 raise Exception("Unexpected frequency")
85 dev
[0].connect("dfs", key_mgmt
="NONE")
86 hwsim_utils
.test_connectivity(dev
[0].ifname
, apdev
[0]['ifname'])
88 hapd
.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
89 ev
= hapd
.wait_event(["DFS-RADAR-DETECTED"], timeout
=10)
91 raise Exception("DFS-RADAR-DETECTED event not reported")
92 if "freq=5260" not in ev
:
93 raise Exception("Incorrect frequency in radar detected event: " + ev
);
94 ev
= hapd
.wait_event(["DFS-NEW-CHANNEL"], timeout
=70)
96 raise Exception("DFS-NEW-CHANNEL event not reported")
98 raise Exception("Channel did not change after radar was detected");
100 ev
= hapd
.wait_event(["AP-CSA-FINISHED"], timeout
=70)
102 raise Exception("AP-CSA-FINISHED event not reported")
103 if "freq=5260" in ev
:
104 raise Exception("Channel did not change after radar was detected(2)");
106 hwsim_utils
.test_connectivity(dev
[0].ifname
, apdev
[0]['ifname'])
108 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
110 def test_dfs_radar(dev
, apdev
):
111 """DFS CAC functionality with radar detected"""
112 if not os
.path
.exists("dfs"):
116 hapd
= start_dfs_ap(apdev
[0])
118 hapd
.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
119 ev
= wait_dfs_event(hapd
, "DFS-RADAR-DETECTED", 70)
120 if "freq=5260" not in ev
:
121 raise Exception("Unexpected DFS radar detection freq")
123 state
= hapd
.get_status_field("state")
125 raise Exception("Unexpected interface state")
127 ev
= wait_dfs_event(hapd
, "DFS-NEW-CHANNEL", 5)
128 if "freq=5260" in ev
:
129 raise Exception("Unexpected DFS new freq")
131 ev
= wait_dfs_event(hapd
, "DFS-CAC-START", 5)
132 if "DFS-CAC-START" not in ev
:
133 raise Exception("Unexpected DFS event")
135 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
136 if "success=1" not in ev
:
137 raise Exception("CAC failed")
138 if "freq=5260" in ev
:
139 raise Exception("Unexpected DFS freq result - radar channel")
141 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
143 raise Exception("AP setup timed out")
145 state
= hapd
.get_status_field("state")
146 if state
!= "ENABLED":
147 raise Exception("Unexpected interface state")
149 freq
= hapd
.get_status_field("freq")
151 raise Exception("Unexpected frequency")
153 dev
[0].connect("dfs", key_mgmt
="NONE")
155 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
157 def test_dfs_radar_on_non_dfs_channel(dev
, apdev
):
158 """DFS radar detection test code on non-DFS channel"""
159 params
= { "ssid": "radar" }
160 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
162 hapd
.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
163 hapd
.request("RADAR DETECTED freq=2412 ht_enabled=1 chan_width=1")