cfg80211: Clean up connect params and channel fetching

Addition of the frequency hints showed up couple of places in cfg80211
where pointers could be marked const and a shared function could be used
to fetch a valid channel.

Signed-off-by: Jouni Malinen <j@w1.fi>
[fix mwifiex]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Jouni Malinen 2014-01-15 00:01:44 +02:00 committed by Johannes Berg
parent b43504cf75
commit 664834dee6
3 changed files with 30 additions and 21 deletions

View file

@ -1583,8 +1583,9 @@ static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
* the function notifies the CFG802.11 subsystem of the new BSS connection. * the function notifies the CFG802.11 subsystem of the new BSS connection.
*/ */
static int static int
mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid, mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
u8 *bssid, int mode, struct ieee80211_channel *channel, const u8 *ssid, const u8 *bssid, int mode,
struct ieee80211_channel *channel,
struct cfg80211_connect_params *sme, bool privacy) struct cfg80211_connect_params *sme, bool privacy)
{ {
struct cfg80211_ssid req_ssid; struct cfg80211_ssid req_ssid;

View file

@ -1732,9 +1732,9 @@ struct cfg80211_ibss_params {
struct cfg80211_connect_params { struct cfg80211_connect_params {
struct ieee80211_channel *channel; struct ieee80211_channel *channel;
struct ieee80211_channel *channel_hint; struct ieee80211_channel *channel_hint;
u8 *bssid; const u8 *bssid;
const u8 *bssid_hint; const u8 *bssid_hint;
u8 *ssid; const u8 *ssid;
size_t ssid_len; size_t ssid_len;
enum nl80211_auth_type auth_type; enum nl80211_auth_type auth_type;
u8 *ie; u8 *ie;

View file

@ -857,6 +857,19 @@ static int nl80211_key_allowed(struct wireless_dev *wdev)
return 0; return 0;
} }
static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
struct nlattr *tb)
{
struct ieee80211_channel *chan;
if (tb == NULL)
return NULL;
chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
return NULL;
return chan;
}
static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
{ {
struct nlattr *nl_modes = nla_nest_start(msg, attr); struct nlattr *nl_modes = nla_nest_start(msg, attr);
@ -6199,9 +6212,9 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
return -EOPNOTSUPP; return -EOPNOTSUPP;
bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
chan = ieee80211_get_channel(&rdev->wiphy, chan = nl80211_get_valid_chan(&rdev->wiphy,
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); info->attrs[NL80211_ATTR_WIPHY_FREQ]);
if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) if (!chan)
return -EINVAL; return -EINVAL;
ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
@ -6354,9 +6367,9 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
chan = ieee80211_get_channel(&rdev->wiphy, chan = nl80211_get_valid_chan(&rdev->wiphy,
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); info->attrs[NL80211_ATTR_WIPHY_FREQ]);
if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) if (!chan)
return -EINVAL; return -EINVAL;
ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
@ -7013,19 +7026,14 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
} }
if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
connect.channel = connect.channel = nl80211_get_valid_chan(
ieee80211_get_channel(wiphy, wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); if (!connect.channel)
if (!connect.channel ||
connect.channel->flags & IEEE80211_CHAN_DISABLED)
return -EINVAL; return -EINVAL;
} else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
connect.channel_hint = connect.channel_hint = nl80211_get_valid_chan(
ieee80211_get_channel(wiphy, wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
nla_get_u32( if (!connect.channel_hint)
info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]));
if (!connect.channel_hint ||
connect.channel_hint->flags & IEEE80211_CHAN_DISABLED)
return -EINVAL; return -EINVAL;
} }