ae97947faba1437a4b15b6c09faa0c86550e84c6
[openwrt/staging/ldir.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Tue, 16 Nov 2021 15:03:36 +0100
3 Subject: [PATCH] cfg80211: allow continuous radar monitoring on offchannel
4 chain
5
6 Allow continuous radar detection on the offchannel chain in order
7 to switch to the monitored channel whenever the underlying driver
8 reports a radar pattern on the main channel.
9
10 Tested-by: Owen Peng <owen.peng@mediatek.com>
11 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
12 Link: https://lore.kernel.org/r/d46217310a49b14ff0e9c002f0a6e0547d70fd2c.1637071350.git.lorenzo@kernel.org
13 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
14 ---
15
16 --- a/net/wireless/chan.c
17 +++ b/net/wireless/chan.c
18 @@ -712,6 +712,19 @@ static bool cfg80211_is_wiphy_oper_chan(
19 return false;
20 }
21
22 +static bool
23 +cfg80211_offchan_chain_is_active(struct cfg80211_registered_device *rdev,
24 + struct ieee80211_channel *channel)
25 +{
26 + if (!rdev->offchan_radar_wdev)
27 + return false;
28 +
29 + if (!cfg80211_chandef_valid(&rdev->offchan_radar_chandef))
30 + return false;
31 +
32 + return cfg80211_is_sub_chan(&rdev->offchan_radar_chandef, channel);
33 +}
34 +
35 bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
36 struct ieee80211_channel *chan)
37 {
38 @@ -728,6 +741,9 @@ bool cfg80211_any_wiphy_oper_chan(struct
39
40 if (cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan))
41 return true;
42 +
43 + if (cfg80211_offchan_chain_is_active(rdev, chan))
44 + return true;
45 }
46
47 return false;
48 --- a/net/wireless/mlme.c
49 +++ b/net/wireless/mlme.c
50 @@ -988,7 +988,7 @@ __cfg80211_offchan_cac_event(struct cfg8
51 if (!cfg80211_chandef_valid(chandef))
52 return;
53
54 - if (event != NL80211_RADAR_CAC_STARTED && !rdev->offchan_radar_wdev)
55 + if (!rdev->offchan_radar_wdev)
56 return;
57
58 switch (event) {
59 @@ -998,17 +998,13 @@ __cfg80211_offchan_cac_event(struct cfg8
60 queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
61 cfg80211_sched_dfs_chan_update(rdev);
62 wdev = rdev->offchan_radar_wdev;
63 - rdev->offchan_radar_wdev = NULL;
64 break;
65 case NL80211_RADAR_CAC_ABORTED:
66 if (!cancel_delayed_work(&rdev->offchan_cac_done_wk))
67 return;
68 wdev = rdev->offchan_radar_wdev;
69 - rdev->offchan_radar_wdev = NULL;
70 break;
71 case NL80211_RADAR_CAC_STARTED:
72 - WARN_ON(!wdev);
73 - rdev->offchan_radar_wdev = wdev;
74 break;
75 default:
76 return;
77 @@ -1024,7 +1020,8 @@ cfg80211_offchan_cac_event(struct cfg802
78 enum nl80211_radar_event event)
79 {
80 wiphy_lock(&rdev->wiphy);
81 - __cfg80211_offchan_cac_event(rdev, NULL, chandef, event);
82 + __cfg80211_offchan_cac_event(rdev, rdev->offchan_radar_wdev,
83 + chandef, event);
84 wiphy_unlock(&rdev->wiphy);
85 }
86
87 @@ -1071,7 +1068,13 @@ cfg80211_start_offchan_radar_detection(s
88 NL80211_EXT_FEATURE_RADAR_OFFCHAN))
89 return -EOPNOTSUPP;
90
91 - if (rdev->offchan_radar_wdev)
92 + /* Offchannel chain already locked by another wdev */
93 + if (rdev->offchan_radar_wdev && rdev->offchan_radar_wdev != wdev)
94 + return -EBUSY;
95 +
96 + /* CAC already in progress on the offchannel chain */
97 + if (rdev->offchan_radar_wdev == wdev &&
98 + delayed_work_pending(&rdev->offchan_cac_done_wk))
99 return -EBUSY;
100
101 err = rdev_set_radar_offchan(rdev, chandef);
102 @@ -1083,6 +1086,8 @@ cfg80211_start_offchan_radar_detection(s
103 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
104
105 rdev->offchan_radar_chandef = *chandef;
106 + rdev->offchan_radar_wdev = wdev; /* Get offchain ownership */
107 +
108 __cfg80211_offchan_cac_event(rdev, wdev, chandef,
109 NL80211_RADAR_CAC_STARTED);
110 queue_delayed_work(cfg80211_wq, &rdev->offchan_cac_done_wk,
111 @@ -1102,6 +1107,7 @@ void cfg80211_stop_offchan_radar_detecti
112 return;
113
114 rdev_set_radar_offchan(rdev, NULL);
115 + rdev->offchan_radar_wdev = NULL; /* Release offchain ownership */
116
117 __cfg80211_offchan_cac_event(rdev, wdev, &rdev->offchan_radar_chandef,
118 NL80211_RADAR_CAC_ABORTED);
119 --- a/net/wireless/nl80211.c
120 +++ b/net/wireless/nl80211.c
121 @@ -9260,42 +9260,60 @@ static int nl80211_start_radar_detection
122 struct cfg80211_chan_def chandef;
123 enum nl80211_dfs_regions dfs_region;
124 unsigned int cac_time_ms;
125 - int err;
126 + int err = -EINVAL;
127 +
128 + flush_delayed_work(&rdev->dfs_update_channels_wk);
129 +
130 + wiphy_lock(wiphy);
131
132 dfs_region = reg_get_dfs_region(wiphy);
133 if (dfs_region == NL80211_DFS_UNSET)
134 - return -EINVAL;
135 + goto unlock;
136
137 err = nl80211_parse_chandef(rdev, info, &chandef);
138 if (err)
139 - return err;
140 + goto unlock;
141
142 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
143 if (err < 0)
144 - return err;
145 + goto unlock;
146
147 - if (err == 0)
148 - return -EINVAL;
149 + if (err == 0) {
150 + err = -EINVAL;
151 + goto unlock;
152 + }
153
154 - if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
155 - return -EINVAL;
156 + if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) {
157 + err = -EINVAL;
158 + goto unlock;
159 + }
160
161 - if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_OFFCHAN]))
162 - return cfg80211_start_offchan_radar_detection(rdev, wdev,
163 - &chandef);
164 + if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_OFFCHAN])) {
165 + err = cfg80211_start_offchan_radar_detection(rdev, wdev,
166 + &chandef);
167 + goto unlock;
168 + }
169
170 - if (netif_carrier_ok(dev))
171 - return -EBUSY;
172 + if (netif_carrier_ok(dev)) {
173 + err = -EBUSY;
174 + goto unlock;
175 + }
176
177 - if (wdev->cac_started)
178 - return -EBUSY;
179 + if (wdev->cac_started) {
180 + err = -EBUSY;
181 + goto unlock;
182 + }
183
184 /* CAC start is offloaded to HW and can't be started manually */
185 - if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
186 - return -EOPNOTSUPP;
187 + if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) {
188 + err = -EOPNOTSUPP;
189 + goto unlock;
190 + }
191
192 - if (!rdev->ops->start_radar_detection)
193 - return -EOPNOTSUPP;
194 + if (!rdev->ops->start_radar_detection) {
195 + err = -EOPNOTSUPP;
196 + goto unlock;
197 + }
198
199 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
200 if (WARN_ON(!cac_time_ms))
201 @@ -9308,6 +9326,9 @@ static int nl80211_start_radar_detection
202 wdev->cac_start_time = jiffies;
203 wdev->cac_time_ms = cac_time_ms;
204 }
205 +unlock:
206 + wiphy_unlock(wiphy);
207 +
208 return err;
209 }
210
211 @@ -15926,7 +15947,8 @@ static const struct genl_small_ops nl802
212 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
213 .doit = nl80211_start_radar_detection,
214 .flags = GENL_UNS_ADMIN_PERM,
215 - .internal_flags = NL80211_FLAG_NEED_NETDEV_UP,
216 + .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
217 + NL80211_FLAG_NO_WIPHY_MTX,
218 },
219 {
220 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,