]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_dfs.py
tests: QoS Map ctrl_iface error cases
[thirdparty/hostap.git] / tests / hwsim / test_dfs.py
CommitLineData
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
7import os
8import subprocess
9import time
10import logging
11logger = logging.getLogger()
12
13import hwsim_utils
14import hostapd
15
16def 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)
21 if not ev:
22 raise Exception("DFS event timed out")
23 if event not in ev:
24 raise Exception("Unexpected DFS event")
25 return ev
26
27def start_dfs_ap(ap):
28 ifname = ap['ifname']
29 logger.info("Reset regulatory setup")
30 subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
31 time.sleep(1)
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)
38 if not hapd.ping():
39 raise Exception("Could not ping hostapd")
40 hapd.set_defaults()
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")
47 hapd.enable()
48
49 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
50 if "DFS-CAC-START" not in ev:
51 raise Exception("Unexpected DFS event")
52
53 state = hapd.get_status_field("state")
54 if state != "DFS":
55 raise Exception("Unexpected interface state")
56
57 return hapd
58
59def test_dfs(dev, apdev):
60 """DFS CAC functionality on clear channel"""
61 if not os.path.exists("dfs"):
62 return "skip"
63 hapd = start_dfs_ap(apdev[0])
64
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")
70
71 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
72 if not ev:
73 raise Exception("AP setup timed out")
74
75 state = hapd.get_status_field("state")
76 if state != "ENABLED":
77 raise Exception("Unexpected interface state")
78
79 freq = hapd.get_status_field("freq")
80 if freq != "5260":
81 raise Exception("Unexpected frequency")
82
83 #TODO: need to fix hwsim for DFS?!
84 #dev[0].connect("dfs", key_mgmt="NONE")
85
86def test_dfs_radar(dev, apdev):
87 """DFS CAC functionality with radar detected"""
88 if not os.path.exists("dfs"):
89 return "skip"
90 hapd = start_dfs_ap(apdev[0])
91
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")
96
97 state = hapd.get_status_field("state")
98 if state != "DFS":
99 raise Exception("Unexpected interface state")
100
101 ev = wait_dfs_event(hapd, "DFS-NEW-CHANNEL", 5)
102 if "freq=5260" in ev:
103 raise Exception("Unexpected DFS new freq")
104
105 ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
106 if "DFS-CAC-START" not in ev:
107 raise Exception("Unexpected DFS event")
108
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")
114
115 ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
116 if not ev:
117 raise Exception("AP setup timed out")
118
119 state = hapd.get_status_field("state")
120 if state != "ENABLED":
121 raise Exception("Unexpected interface state")
122
123 freq = hapd.get_status_field("freq")
124 if freq != "5260":
125 raise Exception("Unexpected frequency")
126
127 #TODO: need to fix hwsim for DFS?!
128 #dev[0].connect("dfs", key_mgmt="NONE")