]>
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")
29 logger
.info("Reset regulatory setup")
30 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
32 subprocess
.call(['sudo', 'iw', 'reg', 'set', 'FI'])
33 logger
.info("Starting AP " + ifname
+ " on DFS channel")
34 hapd_global
= hostapd
.HostapdGlobal()
35 hapd_global
.remove(ifname
)
36 hapd_global
.add(ifname
)
37 hapd
= hostapd
.Hostapd(ifname
)
39 raise Exception("Could not ping hostapd")
41 hapd
.set("ssid", "dfs")
42 hapd
.set("country_code", "FI")
43 hapd
.set("ieee80211d", "1")
44 hapd
.set("ieee80211h", "1")
45 hapd
.set("hw_mode", "a")
46 hapd
.set("channel", "52")
49 ev
= wait_dfs_event(hapd
, "DFS-CAC-START", 5)
50 if "DFS-CAC-START" not in ev
:
51 raise Exception("Unexpected DFS event")
53 state
= hapd
.get_status_field("state")
55 raise Exception("Unexpected interface state")
59 def test_dfs(dev
, apdev
):
60 """DFS CAC functionality on clear channel"""
61 if not os
.path
.exists("dfs"):
63 hapd
= start_dfs_ap(apdev
[0])
65 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
66 if "success=1" not in ev
:
67 raise Exception("CAC failed")
68 if "freq=5260" not in ev
:
69 raise Exception("Unexpected DFS freq result")
71 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
73 raise Exception("AP setup timed out")
75 state
= hapd
.get_status_field("state")
76 if state
!= "ENABLED":
77 raise Exception("Unexpected interface state")
79 freq
= hapd
.get_status_field("freq")
81 raise Exception("Unexpected frequency")
83 #TODO: need to fix hwsim for DFS?!
84 #dev[0].connect("dfs", key_mgmt="NONE")
86 def test_dfs_radar(dev
, apdev
):
87 """DFS CAC functionality with radar detected"""
88 if not os
.path
.exists("dfs"):
90 hapd
= start_dfs_ap(apdev
[0])
92 hapd
.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
93 ev
= wait_dfs_event(hapd
, "DFS-RADAR-DETECTED", 70)
94 if "freq=5260" not in ev
:
95 raise Exception("Unexpected DFS radar detection freq")
97 state
= hapd
.get_status_field("state")
99 raise Exception("Unexpected interface state")
101 ev
= wait_dfs_event(hapd
, "DFS-NEW-CHANNEL", 5)
102 if "freq=5260" in ev
:
103 raise Exception("Unexpected DFS new freq")
105 ev
= wait_dfs_event(hapd
, "DFS-CAC-START", 5)
106 if "DFS-CAC-START" not in ev
:
107 raise Exception("Unexpected DFS event")
109 ev
= wait_dfs_event(hapd
, "DFS-CAC-COMPLETED", 70)
110 if "success=1" not in ev
:
111 raise Exception("CAC failed")
112 if "freq=5260" in ev
:
113 raise Exception("Unexpected DFS freq result - radar channel")
115 ev
= hapd
.wait_event(["AP-ENABLED"], timeout
=5)
117 raise Exception("AP setup timed out")
119 state
= hapd
.get_status_field("state")
120 if state
!= "ENABLED":
121 raise Exception("Unexpected interface state")
123 freq
= hapd
.get_status_field("freq")
125 raise Exception("Unexpected frequency")
127 #TODO: need to fix hwsim for DFS?!
128 #dev[0].connect("dfs", key_mgmt="NONE")