Skip to content

Commit

Permalink
cfg80211: keep track of BSSes
Browse files Browse the repository at this point in the history
In order to avoid problems with BSS structs going away
while they're in use, I've long wanted to make cfg80211
keep track of them. Without the SME, that wasn't doable
but now that we have the SME we can do this too. It can
keep track of up to four separate authentications and
one association, regardless of whether it's controlled
by the cfg80211 SME or the userspace SME.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed Jul 10, 2009
1 parent 517357c commit 19957bb
Show file tree
Hide file tree
Showing 11 changed files with 589 additions and 275 deletions.
86 changes: 22 additions & 64 deletions include/net/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ enum cfg80211_signal_type {
* is no guarantee that these are well-formed!)
* @len_information_elements: total length of the information elements
* @signal: signal strength value (type depends on the wiphy's signal_type)
* @hold: BSS should not expire
* @free_priv: function pointer to free private data
* @priv: private area for driver use, has at least wiphy->bss_priv_size bytes
*/
Expand Down Expand Up @@ -642,66 +641,36 @@ struct cfg80211_crypto_settings {
*
* This structure provides information needed to complete IEEE 802.11
* authentication.
* NOTE: This structure will likely change when more code from mac80211 is
* moved into cfg80211 so that non-mac80211 drivers can benefit from it, too.
* Before using this in a driver that does not use mac80211, it would be better
* to check the status of that work and better yet, volunteer to work on it.
*
* @chan: The channel to use or %NULL if not specified (auto-select based on
* scan results)
* @peer_addr: The address of the peer STA (AP BSSID in infrastructure case);
* this field is required to be present; if the driver wants to help with
* BSS selection, it should use (yet to be added) MLME event to allow user
* space SME to be notified of roaming candidate, so that the SME can then
* use the authentication request with the recommended BSSID and whatever
* other data may be needed for authentication/association
* @ssid: SSID or %NULL if not yet available
* @ssid_len: Length of ssid in octets
*
* @bss: The BSS to authenticate with.
* @auth_type: Authentication type (algorithm)
* @ie: Extra IEs to add to Authentication frame or %NULL
* @ie_len: Length of ie buffer in octets
*/
struct cfg80211_auth_request {
struct ieee80211_channel *chan;
u8 *peer_addr;
const u8 *ssid;
size_t ssid_len;
enum nl80211_auth_type auth_type;
struct cfg80211_bss *bss;
const u8 *ie;
size_t ie_len;
enum nl80211_auth_type auth_type;
};

/**
* struct cfg80211_assoc_request - (Re)Association request data
*
* This structure provides information needed to complete IEEE 802.11
* (re)association.
* NOTE: This structure will likely change when more code from mac80211 is
* moved into cfg80211 so that non-mac80211 drivers can benefit from it, too.
* Before using this in a driver that does not use mac80211, it would be better
* to check the status of that work and better yet, volunteer to work on it.
*
* @chan: The channel to use or %NULL if not specified (auto-select based on
* scan results)
* @peer_addr: The address of the peer STA (AP BSSID); this field is required
* to be present and the STA must be in State 2 (authenticated) with the
* peer STA
* @ssid: SSID
* @ssid_len: Length of ssid in octets
* @bss: The BSS to associate with.
* @ie: Extra IEs to add to (Re)Association Request frame or %NULL
* @ie_len: Length of ie buffer in octets
* @use_mfp: Use management frame protection (IEEE 802.11w) in this association
* @crypto: crypto settings
*/
struct cfg80211_assoc_request {
struct ieee80211_channel *chan;
u8 *peer_addr;
const u8 *ssid;
size_t ssid_len;
struct cfg80211_bss *bss;
const u8 *ie;
size_t ie_len;
bool use_mfp;
struct cfg80211_crypto_settings crypto;
bool use_mfp;
};

/**
Expand All @@ -710,16 +679,16 @@ struct cfg80211_assoc_request {
* This structure provides information needed to complete IEEE 802.11
* deauthentication.
*
* @peer_addr: The address of the peer STA (AP BSSID); this field is required
* to be present and the STA must be authenticated with the peer STA
* @bss: the BSS to deauthenticate from
* @ie: Extra IEs to add to Deauthentication frame or %NULL
* @ie_len: Length of ie buffer in octets
* @reason_code: The reason code for the deauthentication
*/
struct cfg80211_deauth_request {
u8 *peer_addr;
u16 reason_code;
struct cfg80211_bss *bss;
const u8 *ie;
size_t ie_len;
u16 reason_code;
};

/**
Expand All @@ -728,16 +697,16 @@ struct cfg80211_deauth_request {
* This structure provides information needed to complete IEEE 802.11
* disassocation.
*
* @peer_addr: The address of the peer STA (AP BSSID); this field is required
* to be present and the STA must be associated with the peer STA
* @bss: the BSS to disassociate from
* @ie: Extra IEs to add to Disassociation frame or %NULL
* @ie_len: Length of ie buffer in octets
* @reason_code: The reason code for the disassociation
*/
struct cfg80211_disassoc_request {
u8 *peer_addr;
u16 reason_code;
struct cfg80211_bss *bss;
const u8 *ie;
size_t ie_len;
u16 reason_code;
};

/**
Expand Down Expand Up @@ -1252,6 +1221,9 @@ extern void wiphy_free(struct wiphy *wiphy);

/* internal struct */
struct cfg80211_conn;
struct cfg80211_internal_bss;

#define MAX_AUTH_BSSES 4

/**
* struct wireless_dev - wireless per-netdev state
Expand Down Expand Up @@ -1281,7 +1253,6 @@ struct wireless_dev {
struct net_device *netdev;

/* currently used for IBSS and SME - might be rearranged later */
struct cfg80211_bss *current_bss;
u8 ssid[IEEE80211_MAX_SSID_LEN];
u8 ssid_len;
enum {
Expand All @@ -1291,6 +1262,10 @@ struct wireless_dev {
} sme_state;
struct cfg80211_conn *conn;

struct cfg80211_internal_bss *authtry_bsses[MAX_AUTH_BSSES];
struct cfg80211_internal_bss *auth_bsses[MAX_AUTH_BSSES];
struct cfg80211_internal_bss *current_bss; /* associated / joined */

#ifdef CONFIG_WIRELESS_EXT
/* wext data */
struct {
Expand Down Expand Up @@ -1812,23 +1787,6 @@ void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len, gfp
*/
void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len, gfp_t gfp);

/**
* cfg80211_hold_bss - exclude bss from expiration
* @bss: bss which should not expire
*
* In a case when the BSS is not updated but it shouldn't expire this
* function can be used to mark the BSS to be excluded from expiration.
*/
void cfg80211_hold_bss(struct cfg80211_bss *bss);

/**
* cfg80211_unhold_bss - remove expiration exception from the BSS
* @bss: bss which can expire again
*
* This function marks the BSS to be expirable again.
*/
void cfg80211_unhold_bss(struct cfg80211_bss *bss);

/**
* cfg80211_michael_mic_failure - notification of Michael MIC failure (TKIP)
* @dev: network device
Expand Down
22 changes: 9 additions & 13 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_auth_request *req)
{
struct ieee80211_sub_if_data *sdata;
const u8 *ssid;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

Expand All @@ -1193,15 +1194,16 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
return -EOPNOTSUPP;
}

memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
memcpy(sdata->u.mgd.bssid, req->bss->bssid, ETH_ALEN);

sdata->local->oper_channel = req->chan;
sdata->local->oper_channel = req->bss->channel;
ieee80211_hw_config(sdata->local, 0);

if (!req->ssid)
ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
if (!ssid)
return -EINVAL;
memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
sdata->u.mgd.ssid_len = req->ssid_len;
sdata->u.mgd.ssid_len = *(ssid + 1);
memcpy(sdata->u.mgd.ssid, ssid + 2, sdata->u.mgd.ssid_len);

kfree(sdata->u.mgd.sme_auth_ie);
sdata->u.mgd.sme_auth_ie = NULL;
Expand All @@ -1227,7 +1229,7 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
if (memcmp(sdata->u.mgd.bssid, req->bss->bssid, ETH_ALEN) != 0 ||
!(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
return -ENOLINK; /* not authenticated */

Expand All @@ -1239,15 +1241,9 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
sdata->u.mgd.flags |= IEEE80211_STA_DISABLE_11N;

sdata->local->oper_channel = req->chan;
sdata->local->oper_channel = req->bss->channel;
ieee80211_hw_config(sdata->local, 0);

if (!req->ssid)
return -EINVAL;

memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
sdata->u.mgd.ssid_len = req->ssid_len;

ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
if (ret && ret != -EALREADY)
return ret;
Expand Down
6 changes: 1 addition & 5 deletions net/mac80211/mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,6 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
bss_info_changed |= ieee80211_handle_bss_capability(sdata,
bss->cbss.capability, bss->has_erp_value, bss->erp_value);

cfg80211_hold_bss(&bss->cbss);

ieee80211_rx_bss_put(local, bss);
}

Expand Down Expand Up @@ -1031,10 +1029,8 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
conf->channel->center_freq,
ifmgd->ssid, ifmgd->ssid_len);

if (bss) {
cfg80211_unhold_bss(&bss->cbss);
if (bss)
ieee80211_rx_bss_put(local, bss);
}

if (self_disconnected) {
if (deauth)
Expand Down
5 changes: 1 addition & 4 deletions net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,12 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
#endif
cfg80211_disconnect(rdev, dev,
WLAN_REASON_DEAUTH_LEAVING, true);
cfg80211_mlme_down(rdev, dev);
break;
default:
break;
}
break;
case NETDEV_DOWN:
kfree(wdev->conn);
wdev->conn = NULL;
break;
case NETDEV_UP:
#ifdef CONFIG_WIRELESS_EXT
switch (wdev->iftype) {
Expand Down
41 changes: 40 additions & 1 deletion net/wireless/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,30 @@ struct cfg80211_internal_bss {
struct rb_node rbn;
unsigned long ts;
struct kref ref;
bool hold, ies_allocated;
atomic_t hold;
bool ies_allocated;

/* must be last because of priv member */
struct cfg80211_bss pub;
};

static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
{
return container_of(pub, struct cfg80211_internal_bss, pub);
}

static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
{
atomic_inc(&bss->hold);
}

static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
{
int r = atomic_dec_return(&bss->hold);
WARN_ON(r < 0);
}


struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx);
int get_wiphy_idx(struct wiphy *wiphy);

Expand Down Expand Up @@ -176,6 +194,26 @@ void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
struct net_device *dev, bool nowext);

/* MLME */
int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct ieee80211_channel *chan,
enum nl80211_auth_type auth_type, const u8 *bssid,
const u8 *ssid, int ssid_len,
const u8 *ie, int ie_len);
int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct ieee80211_channel *chan,
const u8 *bssid, const u8 *ssid, int ssid_len,
const u8 *ie, int ie_len, bool use_mfp,
struct cfg80211_crypto_settings *crypt);
int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
struct net_device *dev, const u8 *bssid,
const u8 *ie, int ie_len, u16 reason);
int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
struct net_device *dev, const u8 *bssid,
const u8 *ie, int ie_len, u16 reason);
void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
struct net_device *dev);

/* SME */
int cfg80211_connect(struct cfg80211_registered_device *rdev,
struct net_device *dev,
Expand All @@ -193,5 +231,6 @@ void __cfg80211_disconnected(struct net_device *dev, gfp_t gfp, u8 *ie,
size_t ie_len, u16 reason, bool from_ap);
void cfg80211_sme_scan_done(struct net_device *dev);
void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
void cfg80211_sme_disassoc(struct net_device *dev, int idx);

#endif /* __NET_WIRELESS_CORE_H */
12 changes: 6 additions & 6 deletions net/wireless/ibss.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)

if (wdev->current_bss) {
cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wdev->current_bss);
cfg80211_put_bss(&wdev->current_bss->pub);
}

cfg80211_hold_bss(bss);
wdev->current_bss = bss;
cfg80211_hold_bss(bss_from_pub(bss));
wdev->current_bss = bss_from_pub(bss);

nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, gfp);
#ifdef CONFIG_WIRELESS_EXT
Expand Down Expand Up @@ -78,7 +78,7 @@ void cfg80211_clear_ibss(struct net_device *dev, bool nowext)

if (wdev->current_bss) {
cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wdev->current_bss);
cfg80211_put_bss(&wdev->current_bss->pub);
}

wdev->current_bss = NULL;
Expand Down Expand Up @@ -212,7 +212,7 @@ int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
return -EINVAL;

if (wdev->current_bss)
chan = wdev->current_bss->channel;
chan = wdev->current_bss->pub.channel;
else if (wdev->wext.ibss.channel)
chan = wdev->wext.ibss.channel;

Expand Down Expand Up @@ -352,7 +352,7 @@ int cfg80211_ibss_wext_giwap(struct net_device *dev,
ap_addr->sa_family = ARPHRD_ETHER;

if (wdev->current_bss)
memcpy(ap_addr->sa_data, wdev->current_bss->bssid, ETH_ALEN);
memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
else
memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN);
return 0;
Expand Down
Loading

0 comments on commit 19957bb

Please sign in to comment.