@@ -406,6 +406,7 @@ cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev,
enum nl80211_iftype iftype)
{
+ /* Channel is NULL, no need for radar detection */
return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL,
CHAN_MODE_UNDEFINED, 0);
}
@@ -426,6 +427,11 @@ cfg80211_can_use_chan(struct cfg80211_registered_device *rdev,
struct ieee80211_channel *chan,
enum cfg80211_chan_mode chanmode)
{
+ /*
+ * The only place that could call us without checking whether
+ * radar detection is needed is cfg80211_set_mesh_channel() --
+ * and for libertas only -- but we added a WARN_ON there.
+ */
return cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
chan, chanmode, 0);
}
@@ -127,15 +127,18 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
wdev->wext.ibss.chandef = params->chandef;
#endif
check_chan = params->chandef.chan;
- if (params->userspace_handles_dfs) {
- /* use channel NULL to check for radar even if the current
- * channel is not a radar channel - it might decide to change
- * to DFS channel later.
+ if (params->userspace_handles_dfs)
+ /*
+ * Check for radar even if the current channel is not
+ * a radar channel - it might decide to change to DFS
+ * channel later.
*/
radar_detect_width = BIT(params->chandef.width);
- check_chan = NULL;
- }
+ /*
+ * We're guaranteeing with the code above that radar detection
+ * will always be enabled if the userspace can handle DFS.
+ */
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
check_chan,
(params->channel_fixed &&
@@ -184,6 +184,7 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
if (err)
radar_detect_width = BIT(setup->chandef.width);
+ /* We're checking if radar detection is needed above */
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
setup->chandef.chan,
CHAN_MODE_SHARED,
@@ -236,6 +237,13 @@ int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
if (!netif_running(wdev->netdev))
return -ENETDOWN;
+ /*
+ * cfg80211_can_use_chan() calls
+ * cfg80211_can_use_iftype_chan() with no radar
+ * detection, so if we're trying to use a radar
+ * channel here, something is wrong.
+ */
+ WARN_ON_ONCE(chandef->chan->flags & IEEE80211_CHAN_RADAR);
err = cfg80211_can_use_chan(rdev, wdev, chandef->chan,
CHAN_MODE_SHARED);
if (err)
@@ -233,6 +233,12 @@ int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
if (!req.bss)
return -ENOENT;
+ /*
+ * For managed mode, we don't have to check for radar, so
+ * there's no problem to call cfg80211+can_use_channel() which
+ * calls cfg80211_can_use_iftype_chan() with no radar
+ * detection.
+ */
err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
CHAN_MODE_SHARED);
if (err)
@@ -306,6 +312,12 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
if (!req->bss)
return -ENOENT;
+ /*
+ * For managed mode, we don't have to check for radar, so
+ * there's no problem to call cfg80211+can_use_channel() which
+ * calls cfg80211_can_use_iftype_chan() with no radar
+ * detection.
+ */
err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
if (err)
goto out;
@@ -3263,6 +3263,7 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
params.radar_required = true;
}
+ /* We're checking if radar detection is needed above */
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
params.chandef.chan,
CHAN_MODE_SHARED,
@@ -5794,6 +5795,10 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
if (!rdev->ops->start_radar_detection)
return -EOPNOTSUPP;
+ /*
+ * This is only called if radar detection is required and we
+ * pass the radar_detect_width properly below.
+ */
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
chandef.chan, CHAN_MODE_SHARED,
BIT(chandef.width));
@@ -5924,6 +5929,10 @@ skip_beacons:
}
}
+ /*
+ * We guarantee with the code above that radar_detect_width is
+ * correctly set for the interface types that need it.
+ */
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
params.chandef.chan,
CHAN_MODE_SHARED,
@@ -1269,45 +1269,14 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
enum cfg80211_chan_mode chmode;
int num_different_channels = 0;
int total = 1;
- bool radar_required = false;
int i, j;
+ int ret;
ASSERT_RTNL();
if (WARN_ON(hweight32(radar_detect) > 1))
return -EINVAL;
- switch (iftype) {
- case NL80211_IFTYPE_ADHOC:
- case NL80211_IFTYPE_AP:
- case NL80211_IFTYPE_AP_VLAN:
- case NL80211_IFTYPE_MESH_POINT:
- case NL80211_IFTYPE_P2P_GO:
- case NL80211_IFTYPE_WDS:
- /* if the interface could potentially choose a DFS channel,
- * then mark DFS as required.
- */
- if (!chan) {
- if (chanmode != CHAN_MODE_UNDEFINED && radar_detect)
- radar_required = true;
- break;
- }
- radar_required = !!(chan->flags & IEEE80211_CHAN_RADAR);
- break;
- case NL80211_IFTYPE_P2P_CLIENT:
- case NL80211_IFTYPE_STATION:
- case NL80211_IFTYPE_P2P_DEVICE:
- case NL80211_IFTYPE_MONITOR:
- break;
- case NUM_NL80211_IFTYPES:
- case NL80211_IFTYPE_UNSPECIFIED:
- default:
- return -EINVAL;
- }
-
- if (radar_required && !radar_detect)
- return -EINVAL;
-
/* Always allow software iftypes */
if (rdev->wiphy.software_iftypes & BIT(iftype)) {
if (radar_detect)