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
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.
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>
16 --- a/net/wireless/chan.c
17 +++ b/net/wireless/chan.c
18 @@ -712,6 +712,19 @@ static bool cfg80211_is_wiphy_oper_chan(
23 +cfg80211_offchan_chain_is_active(struct cfg80211_registered_device *rdev,
24 + struct ieee80211_channel *channel)
26 + if (!rdev->offchan_radar_wdev)
29 + if (!cfg80211_chandef_valid(&rdev->offchan_radar_chandef))
32 + return cfg80211_is_sub_chan(&rdev->offchan_radar_chandef, channel);
35 bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
36 struct ieee80211_channel *chan)
38 @@ -728,6 +741,9 @@ bool cfg80211_any_wiphy_oper_chan(struct
40 if (cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan))
43 + if (cfg80211_offchan_chain_is_active(rdev, chan))
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))
54 - if (event != NL80211_RADAR_CAC_STARTED && !rdev->offchan_radar_wdev)
55 + if (!rdev->offchan_radar_wdev)
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;
65 case NL80211_RADAR_CAC_ABORTED:
66 if (!cancel_delayed_work(&rdev->offchan_cac_done_wk))
68 wdev = rdev->offchan_radar_wdev;
69 - rdev->offchan_radar_wdev = NULL;
71 case NL80211_RADAR_CAC_STARTED:
73 - rdev->offchan_radar_wdev = wdev;
77 @@ -1024,7 +1020,8 @@ cfg80211_offchan_cac_event(struct cfg802
78 enum nl80211_radar_event event)
80 wiphy_lock(&rdev->wiphy);
81 - __cfg80211_offchan_cac_event(rdev, NULL, chandef, event);
82 + __cfg80211_offchan_cac_event(rdev, rdev->offchan_radar_wdev,
84 wiphy_unlock(&rdev->wiphy);
87 @@ -1071,7 +1068,13 @@ cfg80211_start_offchan_radar_detection(s
88 NL80211_EXT_FEATURE_RADAR_OFFCHAN))
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)
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))
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;
105 rdev->offchan_radar_chandef = *chandef;
106 + rdev->offchan_radar_wdev = wdev; /* Get offchain ownership */
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
114 rdev_set_radar_offchan(rdev, NULL);
115 + rdev->offchan_radar_wdev = NULL; /* Release offchain ownership */
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 @@ -9263,42 +9263,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;
128 + flush_delayed_work(&rdev->dfs_update_channels_wk);
132 dfs_region = reg_get_dfs_region(wiphy);
133 if (dfs_region == NL80211_DFS_UNSET)
137 err = nl80211_parse_chandef(rdev, info, &chandef);
142 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
154 - if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
156 + if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) {
161 - if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_OFFCHAN]))
162 - return cfg80211_start_offchan_radar_detection(rdev, wdev,
164 + if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_OFFCHAN])) {
165 + err = cfg80211_start_offchan_radar_detection(rdev, wdev,
170 - if (netif_carrier_ok(dev))
172 + if (netif_carrier_ok(dev)) {
177 - if (wdev->cac_started)
179 + if (wdev->cac_started) {
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)) {
192 - if (!rdev->ops->start_radar_detection)
193 - return -EOPNOTSUPP;
194 + if (!rdev->ops->start_radar_detection) {
199 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
200 if (WARN_ON(!cac_time_ms))
201 @@ -9311,6 +9329,9 @@ static int nl80211_start_radar_detection
202 wdev->cac_start_time = jiffies;
203 wdev->cac_time_ms = cac_time_ms;
206 + wiphy_unlock(wiphy);
211 @@ -15941,7 +15962,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,
220 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,