Commit 73de86a3 authored by Luciano Coelho's avatar Luciano Coelho Committed by Johannes Berg

cfg80211/mac80211: move interface counting for combination check to mac80211

Move the counting part of the interface combination check from
cfg80211 to mac80211.

This is needed to simplify locking when the driver has to perform a
combination check by itself (eg. with channel-switch).
Signed-off-by: default avatarLuciano Coelho <luciano.coelho@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 2beb6dab
...@@ -662,7 +662,6 @@ struct cfg80211_acl_data { ...@@ -662,7 +662,6 @@ struct cfg80211_acl_data {
* @p2p_opp_ps: P2P opportunistic PS * @p2p_opp_ps: P2P opportunistic PS
* @acl: ACL configuration used by the drivers which has support for * @acl: ACL configuration used by the drivers which has support for
* MAC address based access control * MAC address based access control
* @radar_required: set if radar detection is required
*/ */
struct cfg80211_ap_settings { struct cfg80211_ap_settings {
struct cfg80211_chan_def chandef; struct cfg80211_chan_def chandef;
...@@ -680,7 +679,6 @@ struct cfg80211_ap_settings { ...@@ -680,7 +679,6 @@ struct cfg80211_ap_settings {
u8 p2p_ctwindow; u8 p2p_ctwindow;
bool p2p_opp_ps; bool p2p_opp_ps;
const struct cfg80211_acl_data *acl; const struct cfg80211_acl_data *acl;
bool radar_required;
}; };
/** /**
......
...@@ -972,7 +972,6 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, ...@@ -972,7 +972,6 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
sdata->needed_rx_chains = sdata->local->rx_chains; sdata->needed_rx_chains = sdata->local->rx_chains;
mutex_lock(&local->mtx); mutex_lock(&local->mtx);
sdata->radar_required = params->radar_required;
err = ieee80211_vif_use_channel(sdata, &params->chandef, err = ieee80211_vif_use_channel(sdata, &params->chandef,
IEEE80211_CHANCTX_SHARED); IEEE80211_CHANCTX_SHARED);
mutex_unlock(&local->mtx); mutex_unlock(&local->mtx);
...@@ -2930,7 +2929,6 @@ static int ieee80211_start_radar_detection(struct wiphy *wiphy, ...@@ -2930,7 +2929,6 @@ static int ieee80211_start_radar_detection(struct wiphy *wiphy,
/* whatever, but channel contexts should not complain about that one */ /* whatever, but channel contexts should not complain about that one */
sdata->smps_mode = IEEE80211_SMPS_OFF; sdata->smps_mode = IEEE80211_SMPS_OFF;
sdata->needed_rx_chains = local->rx_chains; sdata->needed_rx_chains = local->rx_chains;
sdata->radar_required = true;
err = ieee80211_vif_use_channel(sdata, chandef, err = ieee80211_vif_use_channel(sdata, chandef,
IEEE80211_CHANCTX_SHARED); IEEE80211_CHANCTX_SHARED);
......
...@@ -519,6 +519,7 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, ...@@ -519,6 +519,7 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
{ {
struct ieee80211_local *local = sdata->local; struct ieee80211_local *local = sdata->local;
struct ieee80211_chanctx *ctx; struct ieee80211_chanctx *ctx;
u8 radar_detect_width = 0;
int ret; int ret;
lockdep_assert_held(&local->mtx); lockdep_assert_held(&local->mtx);
...@@ -526,6 +527,22 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, ...@@ -526,6 +527,22 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev)); WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
mutex_lock(&local->chanctx_mtx); mutex_lock(&local->chanctx_mtx);
ret = cfg80211_chandef_dfs_required(local->hw.wiphy,
chandef,
sdata->wdev.iftype);
if (ret < 0)
goto out;
if (ret > 0)
radar_detect_width = BIT(chandef->width);
sdata->radar_required = ret;
ret = ieee80211_check_combinations(sdata, chandef, mode,
radar_detect_width);
if (ret < 0)
goto out;
__ieee80211_vif_release_channel(sdata); __ieee80211_vif_release_channel(sdata);
ctx = ieee80211_find_chanctx(local, chandef, mode); ctx = ieee80211_find_chanctx(local, chandef, mode);
......
...@@ -1805,6 +1805,10 @@ int ieee80211_cs_headroom(struct ieee80211_local *local, ...@@ -1805,6 +1805,10 @@ int ieee80211_cs_headroom(struct ieee80211_local *local,
enum nl80211_iftype iftype); enum nl80211_iftype iftype);
void ieee80211_recalc_dtim(struct ieee80211_local *local, void ieee80211_recalc_dtim(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata); struct ieee80211_sub_if_data *sdata);
int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
const struct cfg80211_chan_def *chandef,
enum ieee80211_chanctx_mode chanmode,
u8 radar_detect);
#ifdef CONFIG_MAC80211_NOINLINE #ifdef CONFIG_MAC80211_NOINLINE
#define debug_noinline noinline #define debug_noinline noinline
......
...@@ -2797,3 +2797,75 @@ void ieee80211_recalc_dtim(struct ieee80211_local *local, ...@@ -2797,3 +2797,75 @@ void ieee80211_recalc_dtim(struct ieee80211_local *local,
ps->dtim_count = dtim_count; ps->dtim_count = dtim_count;
} }
int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
const struct cfg80211_chan_def *chandef,
enum ieee80211_chanctx_mode chanmode,
u8 radar_detect)
{
struct ieee80211_local *local = sdata->local;
struct ieee80211_sub_if_data *sdata_iter;
enum nl80211_iftype iftype = sdata->wdev.iftype;
int num[NUM_NL80211_IFTYPES];
struct ieee80211_chanctx *ctx;
int num_different_channels = 1;
int total = 1;
lockdep_assert_held(&local->chanctx_mtx);
if (WARN_ON(hweight32(radar_detect) > 1))
return -EINVAL;
if (WARN_ON(chanmode == IEEE80211_CHANCTX_SHARED && !chandef->chan))
return -EINVAL;
if (WARN_ON(iftype >= NUM_NL80211_IFTYPES))
return -EINVAL;
/* Always allow software iftypes */
if (local->hw.wiphy->software_iftypes & BIT(iftype)) {
if (radar_detect)
return -EINVAL;
return 0;
}
memset(num, 0, sizeof(num));
if (iftype != NL80211_IFTYPE_UNSPECIFIED)
num[iftype] = 1;
list_for_each_entry(ctx, &local->chanctx_list, list) {
if (ctx->conf.radar_enabled)
radar_detect |= BIT(ctx->conf.def.width);
if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) {
num_different_channels++;
continue;
}
if ((chanmode == IEEE80211_CHANCTX_SHARED) &&
cfg80211_chandef_compatible(chandef,
&ctx->conf.def))
continue;
num_different_channels++;
}
list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) {
struct wireless_dev *wdev_iter;
wdev_iter = &sdata_iter->wdev;
if (sdata_iter == sdata ||
rcu_access_pointer(sdata_iter->vif.chanctx_conf) == NULL ||
local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype))
continue;
num[wdev_iter->iftype]++;
total++;
}
if (total == 1 && !radar_detect)
return 0;
return cfg80211_check_combinations(local->hw.wiphy,
num_different_channels,
radar_detect, num);
}
...@@ -417,6 +417,9 @@ cfg80211_can_change_interface(struct cfg80211_registered_device *rdev, ...@@ -417,6 +417,9 @@ cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev, struct wireless_dev *wdev,
enum nl80211_iftype iftype) enum nl80211_iftype iftype)
{ {
/* TODO: For this function, we'll probably need to keep some
* kind of interface combination check in cfg80211...
*/
return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL, return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL,
CHAN_MODE_UNDEFINED, 0); CHAN_MODE_UNDEFINED, 0);
} }
...@@ -431,16 +434,6 @@ cfg80211_can_add_interface(struct cfg80211_registered_device *rdev, ...@@ -431,16 +434,6 @@ cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
return cfg80211_can_change_interface(rdev, NULL, iftype); return cfg80211_can_change_interface(rdev, NULL, iftype);
} }
static inline int
cfg80211_can_use_chan(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev,
struct ieee80211_channel *chan,
enum cfg80211_chan_mode chanmode)
{
return cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
chan, chanmode, 0);
}
static inline unsigned int elapsed_jiffies_msecs(unsigned long start) static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
{ {
unsigned long end = jiffies; unsigned long end = jiffies;
......
...@@ -135,6 +135,10 @@ static int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev, ...@@ -135,6 +135,10 @@ static int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
radar_detect_width = BIT(params->chandef.width); radar_detect_width = BIT(params->chandef.width);
} }
/* TODO: We need to check the combinations at this point, we
* probably must move this call down to join_ibss() in
* mac80211.
*/
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
check_chan, check_chan,
(params->channel_fixed && (params->channel_fixed &&
......
...@@ -99,7 +99,6 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, ...@@ -99,7 +99,6 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
const struct mesh_config *conf) const struct mesh_config *conf)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
u8 radar_detect_width = 0;
int err; int err;
BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN); BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN);
...@@ -179,22 +178,6 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, ...@@ -179,22 +178,6 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
NL80211_IFTYPE_MESH_POINT)) NL80211_IFTYPE_MESH_POINT))
return -EINVAL; return -EINVAL;
err = cfg80211_chandef_dfs_required(wdev->wiphy,
&setup->chandef,
NL80211_IFTYPE_MESH_POINT);
if (err < 0)
return err;
if (err > 0)
radar_detect_width = BIT(setup->chandef.width);
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
setup->chandef.chan,
CHAN_MODE_SHARED,
radar_detect_width);
if (err)
return err;
err = rdev_join_mesh(rdev, dev, conf, setup); err = rdev_join_mesh(rdev, dev, conf, setup);
if (!err) { if (!err) {
memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len); memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
...@@ -240,17 +223,6 @@ int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev, ...@@ -240,17 +223,6 @@ int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
if (!netif_running(wdev->netdev)) if (!netif_running(wdev->netdev))
return -ENETDOWN; 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)
return err;
err = rdev_libertas_set_mesh_channel(rdev, wdev->netdev, err = rdev_libertas_set_mesh_channel(rdev, wdev->netdev,
chandef->chan); chandef->chan);
if (!err) if (!err)
......
...@@ -233,14 +233,8 @@ int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, ...@@ -233,14 +233,8 @@ int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
if (!req.bss) if (!req.bss)
return -ENOENT; return -ENOENT;
err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
CHAN_MODE_SHARED);
if (err)
goto out;
err = rdev_auth(rdev, dev, &req); err = rdev_auth(rdev, dev, &req);
out:
cfg80211_put_bss(&rdev->wiphy, req.bss); cfg80211_put_bss(&rdev->wiphy, req.bss);
return err; return err;
} }
...@@ -306,16 +300,10 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, ...@@ -306,16 +300,10 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
if (!req->bss) if (!req->bss)
return -ENOENT; return -ENOENT;
err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
if (err)
goto out;
err = rdev_assoc(rdev, dev, req); err = rdev_assoc(rdev, dev, req);
if (!err) if (!err)
cfg80211_hold_bss(bss_from_pub(req->bss)); cfg80211_hold_bss(bss_from_pub(req->bss));
else
out:
if (err)
cfg80211_put_bss(&rdev->wiphy, req->bss); cfg80211_put_bss(&rdev->wiphy, req->bss);
return err; return err;
......
...@@ -3155,7 +3155,6 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) ...@@ -3155,7 +3155,6 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_ap_settings params; struct cfg80211_ap_settings params;
int err; int err;
u8 radar_detect_width = 0;
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
...@@ -3275,24 +3274,6 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) ...@@ -3275,24 +3274,6 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
wdev->iftype)) wdev->iftype))
return -EINVAL; return -EINVAL;
err = cfg80211_chandef_dfs_required(wdev->wiphy,
&params.chandef,
NL80211_IFTYPE_AP);
if (err < 0)
return err;
if (err > 0) {
params.radar_required = true;
radar_detect_width = BIT(params.chandef.width);
}
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
params.chandef.chan,
CHAN_MODE_SHARED,
radar_detect_width);
if (err)
return err;
if (info->attrs[NL80211_ATTR_ACL_POLICY]) { if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
params.acl = parse_acl_data(&rdev->wiphy, info); params.acl = parse_acl_data(&rdev->wiphy, info);
if (IS_ERR(params.acl)) if (IS_ERR(params.acl))
...@@ -5823,12 +5804,6 @@ static int nl80211_start_radar_detection(struct sk_buff *skb, ...@@ -5823,12 +5804,6 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
if (!rdev->ops->start_radar_detection) if (!rdev->ops->start_radar_detection)
return -EOPNOTSUPP; return -EOPNOTSUPP;
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
chandef.chan, CHAN_MODE_SHARED,
BIT(chandef.width));
if (err)
return err;
cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
if (WARN_ON(!cac_time_ms)) if (WARN_ON(!cac_time_ms))
cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
...@@ -5957,6 +5932,10 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) ...@@ -5957,6 +5932,10 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
params.radar_required = true; params.radar_required = true;
} }
/* TODO: I left this here for now. With channel switch, the
* verification is a bit more complicated, because we only do
* it later when the channel switch really happens.
*/
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
params.chandef.chan, params.chandef.chan,
CHAN_MODE_SHARED, CHAN_MODE_SHARED,
......
...@@ -1375,6 +1375,11 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev, ...@@ -1375,6 +1375,11 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
num[iftype] = 1; num[iftype] = 1;
/* TODO: We'll probably not need this anymore, since this
* should only be called with CHAN_MODE_UNDEFINED. There are
* still a couple of pending calls where other chanmodes are
* used, but we should get rid of them.
*/
switch (chanmode) { switch (chanmode) {
case CHAN_MODE_UNDEFINED: case CHAN_MODE_UNDEFINED:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment