cfg80211: separate internal SME implementation

The current internal SME implementation in cfg80211 is
very mixed up with the MLME handling, which has been
causing issues for a long time. There are three things
that the implementation has to provide:
 * a basic SME implementation for nl80211's connect()
   call (for drivers implementing auth/assoc, which is
   really just mac80211) and wireless extensions
 * MLME events for the userspace SME
 * SME events (connected, disconnected etc.) for all
   different SME implementation possibilities (driver,
   cfg80211 and userspace)

To achieve these goals it isn't necessary to track the
software SME's connection status outside of it's state
(which is the part that caused many issues.) Instead,
track it only in the SME data (wdev->conn) and in the
general case only track whether the wdev is connected
or not (via wdev->current_bss.)

Also separate the internal implementation to not have
callbacks from the SME events, but rather call it from
the API functions that the driver (or rather mac80211)
calls. This separates the code better.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-05-16 00:55:45 +02:00
parent 6ff57cf888
commit ceca7b7121
8 changed files with 339 additions and 457 deletions

View File

@ -2898,11 +2898,6 @@ struct wireless_dev {
/* currently used for IBSS and SME - might be rearranged later */ /* currently used for IBSS and SME - might be rearranged later */
u8 ssid[IEEE80211_MAX_SSID_LEN]; u8 ssid[IEEE80211_MAX_SSID_LEN];
u8 ssid_len, mesh_id_len, mesh_id_up_len; u8 ssid_len, mesh_id_len, mesh_id_up_len;
enum {
CFG80211_SME_IDLE,
CFG80211_SME_CONNECTING,
CFG80211_SME_CONNECTED,
} sme_state;
struct cfg80211_conn *conn; struct cfg80211_conn *conn;
struct cfg80211_cached_keys *connect_keys; struct cfg80211_cached_keys *connect_keys;

View File

@ -821,7 +821,6 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
pr_err("failed to add phy80211 symlink to netdev!\n"); pr_err("failed to add phy80211 symlink to netdev!\n");
} }
wdev->netdev = dev; wdev->netdev = dev;
wdev->sme_state = CFG80211_SME_IDLE;
#ifdef CONFIG_CFG80211_WEXT #ifdef CONFIG_CFG80211_WEXT
wdev->wext.default_key = -1; wdev->wext.default_key = -1;
wdev->wext.default_mgmt_key = -1; wdev->wext.default_mgmt_key = -1;

View File

@ -308,11 +308,6 @@ int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
bool local_state_change); bool local_state_change);
void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
struct net_device *dev); struct net_device *dev);
void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
const u8 *req_ie, size_t req_ie_len,
const u8 *resp_ie, size_t resp_ie_len,
u16 status, bool wextev,
struct cfg80211_bss *bss);
int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid, int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
u16 frame_type, const u8 *match_data, u16 frame_type, const u8 *match_data,
int match_len); int match_len);
@ -328,12 +323,19 @@ void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa, void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
const struct ieee80211_vht_cap *vht_capa_mask); const struct ieee80211_vht_cap *vht_capa_mask);
/* SME */ /* SME events */
int cfg80211_connect(struct cfg80211_registered_device *rdev, int cfg80211_connect(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct net_device *dev,
struct cfg80211_connect_params *connect, struct cfg80211_connect_params *connect,
struct cfg80211_cached_keys *connkeys, struct cfg80211_cached_keys *connkeys,
const u8 *prev_bssid); const u8 *prev_bssid);
void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
const u8 *req_ie, size_t req_ie_len,
const u8 *resp_ie, size_t resp_ie_len,
u16 status, bool wextev,
struct cfg80211_bss *bss);
void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
size_t ie_len, u16 reason, bool from_ap);
int cfg80211_disconnect(struct cfg80211_registered_device *rdev, int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
struct net_device *dev, u16 reason, struct net_device *dev, u16 reason,
bool wextev); bool wextev);
@ -344,21 +346,21 @@ void __cfg80211_roamed(struct wireless_dev *wdev,
int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev); struct wireless_dev *wdev);
/* SME implementation */
void cfg80211_conn_work(struct work_struct *work); void cfg80211_conn_work(struct work_struct *work);
void cfg80211_sme_failed_assoc(struct wireless_dev *wdev); void cfg80211_sme_scan_done(struct net_device *dev);
bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev); bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status);
void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len);
void cfg80211_sme_disassoc(struct wireless_dev *wdev);
void cfg80211_sme_deauth(struct wireless_dev *wdev);
void cfg80211_sme_auth_timeout(struct wireless_dev *wdev);
void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev);
/* internal helpers */ /* internal helpers */
bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher); bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
struct key_params *params, int key_idx, struct key_params *params, int key_idx,
bool pairwise, const u8 *mac_addr); bool pairwise, const u8 *mac_addr);
void __cfg80211_disconnected(struct net_device *dev, const 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,
struct cfg80211_internal_bss *bss);
void __cfg80211_scan_done(struct work_struct *wk); void __cfg80211_scan_done(struct work_struct *wk);
void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak); void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak);
void __cfg80211_sched_scan_results(struct work_struct *wk); void __cfg80211_sched_scan_results(struct work_struct *wk);

View File

@ -43,7 +43,6 @@ void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
cfg80211_hold_bss(bss_from_pub(bss)); cfg80211_hold_bss(bss_from_pub(bss));
wdev->current_bss = bss_from_pub(bss); wdev->current_bss = bss_from_pub(bss);
wdev->sme_state = CFG80211_SME_CONNECTED;
cfg80211_upload_connect_keys(wdev); cfg80211_upload_connect_keys(wdev);
nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid,
@ -64,8 +63,6 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
trace_cfg80211_ibss_joined(dev, bssid); trace_cfg80211_ibss_joined(dev, bssid);
CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING);
ev = kzalloc(sizeof(*ev), gfp); ev = kzalloc(sizeof(*ev), gfp);
if (!ev) if (!ev)
return; return;
@ -120,7 +117,6 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
#ifdef CONFIG_CFG80211_WEXT #ifdef CONFIG_CFG80211_WEXT
wdev->wext.ibss.chandef = params->chandef; wdev->wext.ibss.chandef = params->chandef;
#endif #endif
wdev->sme_state = CFG80211_SME_CONNECTING;
err = cfg80211_can_use_chan(rdev, wdev, params->chandef.chan, err = cfg80211_can_use_chan(rdev, wdev, params->chandef.chan,
params->channel_fixed params->channel_fixed
@ -134,7 +130,6 @@ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
err = rdev_join_ibss(rdev, dev, params); err = rdev_join_ibss(rdev, dev, params);
if (err) { if (err) {
wdev->connect_keys = NULL; wdev->connect_keys = NULL;
wdev->sme_state = CFG80211_SME_IDLE;
return err; return err;
} }
@ -186,7 +181,6 @@ static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)
} }
wdev->current_bss = NULL; wdev->current_bss = NULL;
wdev->sme_state = CFG80211_SME_IDLE;
wdev->ssid_len = 0; wdev->ssid_len = 0;
#ifdef CONFIG_CFG80211_WEXT #ifdef CONFIG_CFG80211_WEXT
if (!nowext) if (!nowext)

View File

@ -21,129 +21,85 @@
void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss, void cfg80211_rx_assoc_resp(struct net_device *dev, struct cfg80211_bss *bss,
const u8 *buf, size_t len) const u8 *buf, size_t len)
{ {
u16 status_code;
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct wiphy *wiphy = wdev->wiphy; struct wiphy *wiphy = wdev->wiphy;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
u8 *ie = mgmt->u.assoc_resp.variable; u8 *ie = mgmt->u.assoc_resp.variable;
int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
u16 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
trace_cfg80211_send_rx_assoc(dev, bss); trace_cfg80211_send_rx_assoc(dev, bss);
status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
/* /*
* This is a bit of a hack, we don't notify userspace of * This is a bit of a hack, we don't notify userspace of
* a (re-)association reply if we tried to send a reassoc * a (re-)association reply if we tried to send a reassoc
* and got a reject -- we only try again with an assoc * and got a reject -- we only try again with an assoc
* frame instead of reassoc. * frame instead of reassoc.
*/ */
if (status_code != WLAN_STATUS_SUCCESS && wdev->conn && if (cfg80211_sme_rx_assoc_resp(wdev, status_code)) {
cfg80211_sme_failed_reassoc(wdev)) {
cfg80211_put_bss(wiphy, bss); cfg80211_put_bss(wiphy, bss);
return; return;
} }
nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
/* update current_bss etc., consumes the bss reference */
if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) {
cfg80211_sme_failed_assoc(wdev);
/*
* do not call connect_result() now because the
* sme will schedule work that does it later.
*/
cfg80211_put_bss(wiphy, bss);
return;
}
if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) {
/*
* This is for the userspace SME, the CONNECTING
* state will be changed to CONNECTED by
* __cfg80211_connect_result() below.
*/
wdev->sme_state = CFG80211_SME_CONNECTING;
}
/* this consumes the bss reference */
__cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
status_code, status_code,
status_code == WLAN_STATUS_SUCCESS, bss); status_code == WLAN_STATUS_SUCCESS, bss);
} }
EXPORT_SYMBOL(cfg80211_rx_assoc_resp); EXPORT_SYMBOL(cfg80211_rx_assoc_resp);
static void cfg80211_process_deauth(struct net_device *dev, static void cfg80211_process_auth(struct wireless_dev *wdev,
const u8 *buf, size_t len) const u8 *buf, size_t len)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct wiphy *wiphy = wdev->wiphy;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
const u8 *bssid = mgmt->bssid;
bool was_current = false;
if (wdev->current_bss && nl80211_send_rx_auth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { cfg80211_sme_rx_auth(wdev, buf, len);
cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wiphy, &wdev->current_bss->pub);
wdev->current_bss = NULL;
was_current = true;
}
nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
u16 reason_code;
bool from_ap;
reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr);
__cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
} else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
__cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE,
false, NULL);
}
} }
static void cfg80211_process_disassoc(struct net_device *dev, static void cfg80211_process_deauth(struct wireless_dev *wdev,
const u8 *buf, size_t len) const u8 *buf, size_t len)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct wiphy *wiphy = wdev->wiphy;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
const u8 *bssid = mgmt->bssid; const u8 *bssid = mgmt->bssid;
u16 reason_code; u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
bool from_ap; bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
if (wdev->sme_state != CFG80211_SME_CONNECTED) if (!wdev->current_bss ||
!ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
return; return;
if (wdev->current_bss && __cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) { cfg80211_sme_deauth(wdev);
cfg80211_sme_disassoc(dev, wdev->current_bss); }
cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wiphy, &wdev->current_bss->pub);
wdev->current_bss = NULL;
} else
WARN_ON(1);
reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); static void cfg80211_process_disassoc(struct wireless_dev *wdev,
const u8 *buf, size_t len)
{
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
const u8 *bssid = mgmt->bssid;
u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
from_ap = !ether_addr_equal(mgmt->sa, dev->dev_addr); nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL);
__cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
if (WARN_ON(!wdev->current_bss ||
!ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
return;
__cfg80211_disconnected(wdev->netdev, NULL, 0, reason_code, from_ap);
cfg80211_sme_disassoc(wdev);
} }
void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len) void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct wiphy *wiphy = wdev->wiphy;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
struct ieee80211_mgmt *mgmt = (void *)buf; struct ieee80211_mgmt *mgmt = (void *)buf;
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
@ -153,14 +109,12 @@ void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
if (WARN_ON(len < 2)) if (WARN_ON(len < 2))
return; return;
if (ieee80211_is_auth(mgmt->frame_control)) { if (ieee80211_is_auth(mgmt->frame_control))
nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL); cfg80211_process_auth(wdev, buf, len);
cfg80211_sme_rx_auth(dev, buf, len); else if (ieee80211_is_deauth(mgmt->frame_control))
} else if (ieee80211_is_deauth(mgmt->frame_control)) { cfg80211_process_deauth(wdev, buf, len);
cfg80211_process_deauth(dev, buf, len); else if (ieee80211_is_disassoc(mgmt->frame_control))
} else if (ieee80211_is_disassoc(mgmt->frame_control)) { cfg80211_process_disassoc(wdev, buf, len);
cfg80211_process_disassoc(dev, buf, len);
}
} }
EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt); EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
@ -173,10 +127,7 @@ void cfg80211_auth_timeout(struct net_device *dev, const u8 *addr)
trace_cfg80211_send_auth_timeout(dev, addr); trace_cfg80211_send_auth_timeout(dev, addr);
nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
if (wdev->sme_state == CFG80211_SME_CONNECTING) cfg80211_sme_auth_timeout(wdev);
__cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE,
false, NULL);
} }
EXPORT_SYMBOL(cfg80211_auth_timeout); EXPORT_SYMBOL(cfg80211_auth_timeout);
@ -189,10 +140,7 @@ void cfg80211_assoc_timeout(struct net_device *dev, const u8 *addr)
trace_cfg80211_send_assoc_timeout(dev, addr); trace_cfg80211_send_assoc_timeout(dev, addr);
nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
if (wdev->sme_state == CFG80211_SME_CONNECTING) cfg80211_sme_assoc_timeout(wdev);
__cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE,
false, NULL);
} }
EXPORT_SYMBOL(cfg80211_assoc_timeout); EXPORT_SYMBOL(cfg80211_assoc_timeout);
@ -209,9 +157,9 @@ void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
return; return;
if (ieee80211_is_deauth(mgmt->frame_control)) if (ieee80211_is_deauth(mgmt->frame_control))
cfg80211_process_deauth(dev, buf, len); cfg80211_process_deauth(wdev, buf, len);
else else
cfg80211_process_disassoc(dev, buf, len); cfg80211_process_disassoc(wdev, buf, len);
} }
EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt); EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt);
@ -336,21 +284,12 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
int err; int err;
bool was_connected = false;
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (wdev->current_bss && req->prev_bssid && if (wdev->current_bss &&
ether_addr_equal(wdev->current_bss->pub.bssid, req->prev_bssid)) { (!req->prev_bssid || !ether_addr_equal(wdev->current_bss->pub.bssid,
/* req->prev_bssid)))
* Trying to reassociate: Allow this to proceed and let the old
* association to be dropped when the new one is completed.
*/
if (wdev->sme_state == CFG80211_SME_CONNECTED) {
was_connected = true;
wdev->sme_state = CFG80211_SME_CONNECTING;
}
} else if (wdev->current_bss)
return -EALREADY; return -EALREADY;
cfg80211_oper_and_ht_capa(&req->ht_capa_mask, cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
@ -360,11 +299,8 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
if (!req->bss) { if (!req->bss)
if (was_connected)
wdev->sme_state = CFG80211_SME_CONNECTED;
return -ENOENT; return -ENOENT;
}
err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED); err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
if (err) if (err)
@ -373,11 +309,8 @@ int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
err = rdev_assoc(rdev, dev, req); err = rdev_assoc(rdev, dev, req);
out: out:
if (err) { if (err)
if (was_connected)
wdev->sme_state = CFG80211_SME_CONNECTED;
cfg80211_put_bss(&rdev->wiphy, req->bss); cfg80211_put_bss(&rdev->wiphy, req->bss);
}
return err; return err;
} }
@ -398,8 +331,9 @@ int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (local_state_change && (!wdev->current_bss || if (local_state_change &&
!ether_addr_equal(wdev->current_bss->pub.bssid, bssid))) (!wdev->current_bss ||
!ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
return 0; return 0;
return rdev_deauth(rdev, dev, &req); return rdev_deauth(rdev, dev, &req);
@ -417,13 +351,11 @@ int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
.ie = ie, .ie = ie,
.ie_len = ie_len, .ie_len = ie_len,
}; };
int err;
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (wdev->sme_state != CFG80211_SME_CONNECTED) if (!wdev->current_bss)
return -ENOTCONN;
if (WARN(!wdev->current_bss, "sme_state=%d\n", wdev->sme_state))
return -ENOTCONN; return -ENOTCONN;
if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid)) if (ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
@ -431,7 +363,13 @@ int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
else else
return -ENOTCONN; return -ENOTCONN;
return rdev_disassoc(rdev, dev, &req); err = rdev_disassoc(rdev, dev, &req);
if (err)
return err;
/* driver should have reported the disassoc */
WARN_ON(wdev->current_bss);
return 0;
} }
void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
@ -439,10 +377,6 @@ void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
u8 bssid[ETH_ALEN]; u8 bssid[ETH_ALEN];
struct cfg80211_deauth_request req = {
.reason_code = WLAN_REASON_DEAUTH_LEAVING,
.bssid = bssid,
};
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
@ -453,13 +387,8 @@ void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
return; return;
memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
rdev_deauth(rdev, dev, &req); cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
WLAN_REASON_DEAUTH_LEAVING, false);
if (wdev->current_bss) {
cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(&rdev->wiphy, &wdev->current_bss->pub);
wdev->current_bss = NULL;
}
} }
struct cfg80211_mgmt_registration { struct cfg80211_mgmt_registration {

View File

@ -800,12 +800,9 @@ static int nl80211_key_allowed(struct wireless_dev *wdev)
case NL80211_IFTYPE_MESH_POINT: case NL80211_IFTYPE_MESH_POINT:
break; break;
case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_ADHOC:
if (!wdev->current_bss)
return -ENOLINK;
break;
case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT: case NL80211_IFTYPE_P2P_CLIENT:
if (wdev->sme_state != CFG80211_SME_CONNECTED) if (!wdev->current_bss)
return -ENOLINK; return -ENOLINK;
break; break;
default: default:

View File

@ -1,5 +1,7 @@
/* /*
* SME code for cfg80211's connect emulation. * SME code for cfg80211
* both driver SME event handling and the SME implementation
* (for nl80211's connect() and wext)
* *
* Copyright 2009 Johannes Berg <johannes@sipsolutions.net> * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
* Copyright (C) 2009 Intel Corporation. All rights reserved. * Copyright (C) 2009 Intel Corporation. All rights reserved.
@ -18,18 +20,24 @@
#include "reg.h" #include "reg.h"
#include "rdev-ops.h" #include "rdev-ops.h"
/*
* Software SME in cfg80211, using auth/assoc/deauth calls to the
* driver. This is is for implementing nl80211's connect/disconnect
* and wireless extensions (if configured.)
*/
struct cfg80211_conn { struct cfg80211_conn {
struct cfg80211_connect_params params; struct cfg80211_connect_params params;
/* these are sub-states of the _CONNECTING sme_state */ /* these are sub-states of the _CONNECTING sme_state */
enum { enum {
CFG80211_CONN_IDLE,
CFG80211_CONN_SCANNING, CFG80211_CONN_SCANNING,
CFG80211_CONN_SCAN_AGAIN, CFG80211_CONN_SCAN_AGAIN,
CFG80211_CONN_AUTHENTICATE_NEXT, CFG80211_CONN_AUTHENTICATE_NEXT,
CFG80211_CONN_AUTHENTICATING, CFG80211_CONN_AUTHENTICATING,
CFG80211_CONN_ASSOCIATE_NEXT, CFG80211_CONN_ASSOCIATE_NEXT,
CFG80211_CONN_ASSOCIATING, CFG80211_CONN_ASSOCIATING,
CFG80211_CONN_DEAUTH_ASSOC_FAIL, CFG80211_CONN_DEAUTH,
CFG80211_CONN_CONNECTED,
} state; } state;
u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
u8 *ie; u8 *ie;
@ -37,39 +45,16 @@ struct cfg80211_conn {
bool auto_auth, prev_bssid_valid; bool auto_auth, prev_bssid_valid;
}; };
static bool cfg80211_is_all_idle(void) static void cfg80211_sme_free(struct wireless_dev *wdev)
{ {
struct cfg80211_registered_device *rdev; if (!wdev->conn)
struct wireless_dev *wdev; return;
bool is_all_idle = true;
/* kfree(wdev->conn->ie);
* All devices must be idle as otherwise if you are actively kfree(wdev->conn);
* scanning some new beacon hints could be learned and would wdev->conn = NULL;
* count as new regulatory hints.
*/
list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
list_for_each_entry(wdev, &rdev->wdev_list, list) {
wdev_lock(wdev);
if (wdev->sme_state != CFG80211_SME_IDLE)
is_all_idle = false;
wdev_unlock(wdev);
}
}
return is_all_idle;
} }
static void disconnect_work(struct work_struct *work)
{
rtnl_lock();
if (cfg80211_is_all_idle())
regulatory_hint_disconnect();
rtnl_unlock();
}
static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
static int cfg80211_conn_scan(struct wireless_dev *wdev) static int cfg80211_conn_scan(struct wireless_dev *wdev)
{ {
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
@ -164,6 +149,9 @@ static int cfg80211_conn_do_work(struct wireless_dev *wdev)
params = &wdev->conn->params; params = &wdev->conn->params;
switch (wdev->conn->state) { switch (wdev->conn->state) {
case CFG80211_CONN_SCANNING:
/* didn't find it during scan ... */
return -ENOENT;
case CFG80211_CONN_SCAN_AGAIN: case CFG80211_CONN_SCAN_AGAIN:
return cfg80211_conn_scan(wdev); return cfg80211_conn_scan(wdev);
case CFG80211_CONN_AUTHENTICATE_NEXT: case CFG80211_CONN_AUTHENTICATE_NEXT:
@ -200,12 +188,11 @@ static int cfg80211_conn_do_work(struct wireless_dev *wdev)
WLAN_REASON_DEAUTH_LEAVING, WLAN_REASON_DEAUTH_LEAVING,
false); false);
return err; return err;
case CFG80211_CONN_DEAUTH_ASSOC_FAIL: case CFG80211_CONN_DEAUTH:
cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
NULL, 0, NULL, 0,
WLAN_REASON_DEAUTH_LEAVING, false); WLAN_REASON_DEAUTH_LEAVING, false);
/* return an error so that we call __cfg80211_connect_result() */ return 0;
return -EINVAL;
default: default:
return 0; return 0;
} }
@ -229,7 +216,8 @@ void cfg80211_conn_work(struct work_struct *work)
wdev_unlock(wdev); wdev_unlock(wdev);
continue; continue;
} }
if (wdev->sme_state != CFG80211_SME_CONNECTING || !wdev->conn) { if (!wdev->conn ||
wdev->conn->state == CFG80211_CONN_CONNECTED) {
wdev_unlock(wdev); wdev_unlock(wdev);
continue; continue;
} }
@ -237,12 +225,14 @@ void cfg80211_conn_work(struct work_struct *work)
memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
bssid = bssid_buf; bssid = bssid_buf;
} }
if (cfg80211_conn_do_work(wdev)) if (cfg80211_conn_do_work(wdev)) {
__cfg80211_connect_result( __cfg80211_connect_result(
wdev->netdev, bssid, wdev->netdev, bssid,
NULL, 0, NULL, 0, NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE, WLAN_STATUS_UNSPECIFIED_FAILURE,
false, NULL); false, NULL);
cfg80211_sme_free(wdev);
}
wdev_unlock(wdev); wdev_unlock(wdev);
} }
@ -286,9 +276,6 @@ static void __cfg80211_sme_scan_done(struct net_device *dev)
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (wdev->sme_state != CFG80211_SME_CONNECTING)
return;
if (!wdev->conn) if (!wdev->conn)
return; return;
@ -297,20 +284,10 @@ static void __cfg80211_sme_scan_done(struct net_device *dev)
return; return;
bss = cfg80211_get_conn_bss(wdev); bss = cfg80211_get_conn_bss(wdev);
if (bss) { if (bss)
cfg80211_put_bss(&rdev->wiphy, bss); cfg80211_put_bss(&rdev->wiphy, bss);
} else { else
/* not found */ schedule_work(&rdev->conn_work);
if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)
schedule_work(&rdev->conn_work);
else
__cfg80211_connect_result(
wdev->netdev,
wdev->conn->params.bssid,
NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE,
false, NULL);
}
} }
void cfg80211_sme_scan_done(struct net_device *dev) void cfg80211_sme_scan_done(struct net_device *dev)
@ -322,10 +299,8 @@ void cfg80211_sme_scan_done(struct net_device *dev)
wdev_unlock(wdev); wdev_unlock(wdev);
} }
void cfg80211_sme_rx_auth(struct net_device *dev, void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
const u8 *buf, size_t len)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr;
struct wiphy *wiphy = wdev->wiphy; struct wiphy *wiphy = wdev->wiphy;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
@ -333,11 +308,7 @@ void cfg80211_sme_rx_auth(struct net_device *dev,
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
/* should only RX auth frames when connecting */ if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
if (wdev->sme_state != CFG80211_SME_CONNECTING)
return;
if (WARN_ON(!wdev->conn))
return; return;
if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
@ -366,46 +337,226 @@ void cfg80211_sme_rx_auth(struct net_device *dev,
wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
schedule_work(&rdev->conn_work); schedule_work(&rdev->conn_work);
} else if (status_code != WLAN_STATUS_SUCCESS) { } else if (status_code != WLAN_STATUS_SUCCESS) {
__cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, __cfg80211_connect_result(wdev->netdev, mgmt->bssid,
NULL, 0, NULL, 0,
status_code, false, NULL); status_code, false, NULL);
} else if (wdev->sme_state == CFG80211_SME_CONNECTING && } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
schedule_work(&rdev->conn_work); schedule_work(&rdev->conn_work);
} }
} }
bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev) bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
{ {
struct wiphy *wiphy = wdev->wiphy; struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
if (WARN_ON(!wdev->conn)) if (!wdev->conn)
return false; return false;
if (!wdev->conn->prev_bssid_valid) if (status == WLAN_STATUS_SUCCESS) {
wdev->conn->state = CFG80211_CONN_CONNECTED;
return false; return false;
}
if (wdev->conn->prev_bssid_valid) {
/*
* Some stupid APs don't accept reassoc, so we
* need to fall back to trying regular assoc;
* return true so no event is sent to userspace.
*/
wdev->conn->prev_bssid_valid = false;
wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
schedule_work(&rdev->conn_work);
return true;
}
wdev->conn->state = CFG80211_CONN_DEAUTH;
schedule_work(&rdev->conn_work);
return false;
}
void cfg80211_sme_deauth(struct wireless_dev *wdev)
{
cfg80211_sme_free(wdev);
}
void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
{
cfg80211_sme_free(wdev);
}
void cfg80211_sme_disassoc(struct wireless_dev *wdev)
{
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
if (!wdev->conn)
return;
wdev->conn->state = CFG80211_CONN_DEAUTH;
schedule_work(&rdev->conn_work);
}
void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
{
cfg80211_sme_disassoc(wdev);
}
static int cfg80211_sme_connect(struct wireless_dev *wdev,
struct cfg80211_connect_params *connect,
const u8 *prev_bssid)
{
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct cfg80211_bss *bss;
int err;
if (!rdev->ops->auth || !rdev->ops->assoc)
return -EOPNOTSUPP;
if (wdev->current_bss)
return -EALREADY;
if (WARN_ON(wdev->conn))
return -EINPROGRESS;
wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
if (!wdev->conn)
return -ENOMEM;
/* /*
* Some stupid APs don't accept reassoc, so we * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
* need to fall back to trying regular assoc.
*/ */
wdev->conn->prev_bssid_valid = false; memcpy(&wdev->conn->params, connect, sizeof(*connect));
wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; if (connect->bssid) {
schedule_work(&rdev->conn_work); wdev->conn->params.bssid = wdev->conn->bssid;
memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
}
return true; if (connect->ie) {
wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
GFP_KERNEL);
wdev->conn->params.ie = wdev->conn->ie;
if (!wdev->conn->ie) {
kfree(wdev->conn);
wdev->conn = NULL;
return -ENOMEM;
}
}
if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
wdev->conn->auto_auth = true;
/* start with open system ... should mostly work */
wdev->conn->params.auth_type =
NL80211_AUTHTYPE_OPEN_SYSTEM;
} else {
wdev->conn->auto_auth = false;
}
wdev->conn->params.ssid = wdev->ssid;
wdev->conn->params.ssid_len = connect->ssid_len;
/* see if we have the bss already */
bss = cfg80211_get_conn_bss(wdev);
if (prev_bssid) {
memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
wdev->conn->prev_bssid_valid = true;
}
/* we're good if we have a matching bss struct */
if (bss) {
wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
err = cfg80211_conn_do_work(wdev);
cfg80211_put_bss(wdev->wiphy, bss);
} else {
/* otherwise we'll need to scan for the AP first */
err = cfg80211_conn_scan(wdev);
/*
* If we can't scan right now, then we need to scan again
* after the current scan finished, since the parameters
* changed (unless we find a good AP anyway).
*/
if (err == -EBUSY) {
err = 0;
wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
}
}
if (err)
cfg80211_sme_free(wdev);
return err;
} }
void cfg80211_sme_failed_assoc(struct wireless_dev *wdev) static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
{ {
struct wiphy *wiphy = wdev->wiphy; struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); int err;
wdev->conn->state = CFG80211_CONN_DEAUTH_ASSOC_FAIL; if (!wdev->conn)
schedule_work(&rdev->conn_work); return 0;
if (!rdev->ops->deauth)
return -EOPNOTSUPP;
if (wdev->conn->state == CFG80211_CONN_SCANNING ||
wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
err = 0;
goto out;
}
/* wdev->conn->params.bssid must be set if > SCANNING */
err = cfg80211_mlme_deauth(rdev, wdev->netdev,
wdev->conn->params.bssid,
NULL, 0, reason, false);
out:
cfg80211_sme_free(wdev);
return err;
} }
/*
* code shared for in-device and software SME
*/
static bool cfg80211_is_all_idle(void)
{
struct cfg80211_registered_device *rdev;
struct wireless_dev *wdev;
bool is_all_idle = true;
/*
* All devices must be idle as otherwise if you are actively
* scanning some new beacon hints could be learned and would
* count as new regulatory hints.
*/
list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
list_for_each_entry(wdev, &rdev->wdev_list, list) {
wdev_lock(wdev);
if (wdev->conn || wdev->current_bss)
is_all_idle = false;
wdev_unlock(wdev);
}
}
return is_all_idle;
}
static void disconnect_work(struct work_struct *work)
{
rtnl_lock();
if (cfg80211_is_all_idle())
regulatory_hint_disconnect();
rtnl_unlock();
}
static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
/*
* API calls for drivers implementing connect/disconnect and
* SME event handling
*/
void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
const u8 *req_ie, size_t req_ie_len, const u8 *req_ie, size_t req_ie_len,
const u8 *resp_ie, size_t resp_ie_len, const u8 *resp_ie, size_t resp_ie_len,
@ -424,9 +575,6 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
return; return;
if (wdev->sme_state != CFG80211_SME_CONNECTING)
return;
nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev,
bssid, req_ie, req_ie_len, bssid, req_ie, req_ie_len,
resp_ie, resp_ie_len, resp_ie, resp_ie_len,
@ -463,15 +611,7 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
wdev->current_bss = NULL; wdev->current_bss = NULL;
} }
if (wdev->conn)
wdev->conn->state = CFG80211_CONN_IDLE;
if (status != WLAN_STATUS_SUCCESS) { if (status != WLAN_STATUS_SUCCESS) {
wdev->sme_state = CFG80211_SME_IDLE;
if (wdev->conn)
kfree(wdev->conn->ie);
kfree(wdev->conn);
wdev->conn = NULL;
kfree(wdev->connect_keys); kfree(wdev->connect_keys);
wdev->connect_keys = NULL; wdev->connect_keys = NULL;
wdev->ssid_len = 0; wdev->ssid_len = 0;
@ -480,21 +620,16 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
} }
if (!bss) if (!bss)
bss = cfg80211_get_bss(wdev->wiphy, bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
wdev->conn ? wdev->conn->params.channel :
NULL,
bssid,
wdev->ssid, wdev->ssid_len, wdev->ssid, wdev->ssid_len,
WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS,
WLAN_CAPABILITY_ESS); WLAN_CAPABILITY_ESS);
if (WARN_ON(!bss)) if (WARN_ON(!bss))
return; return;
cfg80211_hold_bss(bss_from_pub(bss)); cfg80211_hold_bss(bss_from_pub(bss));
wdev->current_bss = bss_from_pub(bss); wdev->current_bss = bss_from_pub(bss);
wdev->sme_state = CFG80211_SME_CONNECTED;
cfg80211_upload_connect_keys(wdev); cfg80211_upload_connect_keys(wdev);
rcu_read_lock(); rcu_read_lock();
@ -530,8 +665,6 @@ void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
struct cfg80211_event *ev; struct cfg80211_event *ev;
unsigned long flags; unsigned long flags;
CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING);
ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
if (!ev) if (!ev)
return; return;
@ -572,14 +705,9 @@ void __cfg80211_roamed(struct wireless_dev *wdev,
wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
goto out; goto out;
if (wdev->sme_state != CFG80211_SME_CONNECTED) if (WARN_ON(!wdev->current_bss))
goto out; goto out;
/* internal error -- how did we get to CONNECTED w/o BSS? */
if (WARN_ON(!wdev->current_bss)) {
goto out;
}
cfg80211_unhold_bss(wdev->current_bss); cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
wdev->current_bss = NULL; wdev->current_bss = NULL;
@ -628,8 +756,6 @@ void cfg80211_roamed(struct net_device *dev,
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_bss *bss; struct cfg80211_bss *bss;
CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED);
bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid, bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
wdev->ssid_len, WLAN_CAPABILITY_ESS, wdev->ssid_len, WLAN_CAPABILITY_ESS,
WLAN_CAPABILITY_ESS); WLAN_CAPABILITY_ESS);
@ -651,8 +777,6 @@ void cfg80211_roamed_bss(struct net_device *dev,
struct cfg80211_event *ev; struct cfg80211_event *ev;
unsigned long flags; unsigned long flags;
CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED);
if (WARN_ON(!bss)) if (WARN_ON(!bss))
return; return;
@ -694,25 +818,14 @@ void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
return; return;
if (wdev->sme_state != CFG80211_SME_CONNECTED)
return;
if (wdev->current_bss) { if (wdev->current_bss) {
cfg80211_unhold_bss(wdev->current_bss); cfg80211_unhold_bss(wdev->current_bss);
cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
} }
wdev->current_bss = NULL; wdev->current_bss = NULL;
wdev->sme_state = CFG80211_SME_IDLE;
wdev->ssid_len = 0; wdev->ssid_len = 0;
if (wdev->conn) {
kfree(wdev->conn->ie);
wdev->conn->ie = NULL;
kfree(wdev->conn);
wdev->conn = NULL;
}
nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
/* /*
@ -741,8 +854,6 @@ void cfg80211_disconnected(struct net_device *dev, u16 reason,
struct cfg80211_event *ev; struct cfg80211_event *ev;
unsigned long flags; unsigned long flags;
CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED);
ev = kzalloc(sizeof(*ev) + ie_len, gfp); ev = kzalloc(sizeof(*ev) + ie_len, gfp);
if (!ev) if (!ev)
return; return;
@ -760,6 +871,9 @@ void cfg80211_disconnected(struct net_device *dev, u16 reason,
} }
EXPORT_SYMBOL(cfg80211_disconnected); EXPORT_SYMBOL(cfg80211_disconnected);
/*
* API calls for nl80211/wext compatibility code
*/
int cfg80211_connect(struct cfg80211_registered_device *rdev, int cfg80211_connect(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct net_device *dev,
struct cfg80211_connect_params *connect, struct cfg80211_connect_params *connect,
@ -767,14 +881,10 @@ int cfg80211_connect(struct cfg80211_registered_device *rdev,
const u8 *prev_bssid) const u8 *prev_bssid)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_bss *bss = NULL;
int err; int err;
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (wdev->sme_state != CFG80211_SME_IDLE)
return -EALREADY;
if (WARN_ON(wdev->connect_keys)) { if (WARN_ON(wdev->connect_keys)) {
kfree(wdev->connect_keys); kfree(wdev->connect_keys);
wdev->connect_keys = NULL; wdev->connect_keys = NULL;
@ -810,105 +920,22 @@ int cfg80211_connect(struct cfg80211_registered_device *rdev,
} }
} }
if (!rdev->ops->connect) { wdev->connect_keys = connkeys;
if (!rdev->ops->auth || !rdev->ops->assoc) memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
return -EOPNOTSUPP; wdev->ssid_len = connect->ssid_len;
if (WARN_ON(wdev->conn)) if (!rdev->ops->connect)
return -EINPROGRESS; err = cfg80211_sme_connect(wdev, connect, prev_bssid);
else
wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
if (!wdev->conn)
return -ENOMEM;
/*
* Copy all parameters, and treat explicitly IEs, BSSID, SSID.
*/
memcpy(&wdev->conn->params, connect, sizeof(*connect));
if (connect->bssid) {
wdev->conn->params.bssid = wdev->conn->bssid;
memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
}
if (connect->ie) {
wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
GFP_KERNEL);
wdev->conn->params.ie = wdev->conn->ie;
if (!wdev->conn->ie) {
kfree(wdev->conn);
wdev->conn = NULL;
return -ENOMEM;
}
}
if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
wdev->conn->auto_auth = true;
/* start with open system ... should mostly work */
wdev->conn->params.auth_type =
NL80211_AUTHTYPE_OPEN_SYSTEM;
} else {
wdev->conn->auto_auth = false;
}
memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
wdev->ssid_len = connect->ssid_len;
wdev->conn->params.ssid = wdev->ssid;
wdev->conn->params.ssid_len = connect->ssid_len;
/* see if we have the bss already */
bss = cfg80211_get_conn_bss(wdev);
wdev->sme_state = CFG80211_SME_CONNECTING;
wdev->connect_keys = connkeys;
if (prev_bssid) {
memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
wdev->conn->prev_bssid_valid = true;
}
/* we're good if we have a matching bss struct */
if (bss) {
wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
err = cfg80211_conn_do_work(wdev);
cfg80211_put_bss(wdev->wiphy, bss);
} else {
/* otherwise we'll need to scan for the AP first */
err = cfg80211_conn_scan(wdev);
/*
* If we can't scan right now, then we need to scan again
* after the current scan finished, since the parameters
* changed (unless we find a good AP anyway).
*/
if (err == -EBUSY) {
err = 0;
wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
}
}
if (err) {
kfree(wdev->conn->ie);
kfree(wdev->conn);
wdev->conn = NULL;
wdev->sme_state = CFG80211_SME_IDLE;
wdev->connect_keys = NULL;
wdev->ssid_len = 0;
}
return err;
} else {
wdev->sme_state = CFG80211_SME_CONNECTING;
wdev->connect_keys = connkeys;
err = rdev_connect(rdev, dev, connect); err = rdev_connect(rdev, dev, connect);
if (err) {
wdev->connect_keys = NULL;
wdev->sme_state = CFG80211_SME_IDLE;
return err;
}
memcpy(wdev->ssid, connect->ssid, connect->ssid_len); if (err) {
wdev->ssid_len = connect->ssid_len; wdev->connect_keys = NULL;
wdev->ssid_len = 0;
return 0; return err;
} }
return 0;
} }
int cfg80211_disconnect(struct cfg80211_registered_device *rdev, int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
@ -919,78 +946,17 @@ int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
ASSERT_WDEV_LOCK(wdev); ASSERT_WDEV_LOCK(wdev);
if (wdev->sme_state == CFG80211_SME_IDLE)
return -EINVAL;
kfree(wdev->connect_keys); kfree(wdev->connect_keys);
wdev->connect_keys = NULL; wdev->connect_keys = NULL;
if (!rdev->ops->disconnect) { if (wdev->conn) {
if (!rdev->ops->deauth) err = cfg80211_sme_disconnect(wdev, reason);
return -EOPNOTSUPP; } else if (!rdev->ops->disconnect) {
cfg80211_mlme_down(rdev, dev);
/* was it connected by userspace SME? */ err = 0;
if (!wdev->conn) {
cfg80211_mlme_down(rdev, dev);
goto disconnect;
}
if (wdev->sme_state == CFG80211_SME_CONNECTING &&
(wdev->conn->state == CFG80211_CONN_SCANNING ||
wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) {
wdev->sme_state = CFG80211_SME_IDLE;
kfree(wdev->conn->ie);
kfree(wdev->conn);
wdev->conn = NULL;
wdev->ssid_len = 0;
return 0;
}
/* wdev->conn->params.bssid must be set if > SCANNING */
err = cfg80211_mlme_deauth(rdev, dev,
wdev->conn->params.bssid,
NULL, 0, reason, false);
if (err)
return err;
} else { } else {
err = rdev_disconnect(rdev, dev, reason); err = rdev_disconnect(rdev, dev, reason);
if (err)
return err;
} }
disconnect: return err;
if (wdev->sme_state == CFG80211_SME_CONNECTED)
__cfg80211_disconnected(dev, NULL, 0, 0, false);
else if (wdev->sme_state == CFG80211_SME_CONNECTING)
__cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0,
WLAN_STATUS_UNSPECIFIED_FAILURE,
wextev, NULL);
return 0;
}
void cfg80211_sme_disassoc(struct net_device *dev,
struct cfg80211_internal_bss *bss)
{
struct wireless_dev *wdev = dev->ieee80211_ptr;
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
u8 bssid[ETH_ALEN];
ASSERT_WDEV_LOCK(wdev);
if (!wdev->conn)
return;
if (wdev->conn->state == CFG80211_CONN_IDLE)
return;
/*
* Ok, so the association was made by this SME -- we don't
* want it any more so deauthenticate too.
*/
memcpy(bssid, bss->pub.bssid, ETH_ALEN);
cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0,
WLAN_REASON_DEAUTH_LEAVING, false);
} }

View File

@ -89,7 +89,7 @@ int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
wdev_lock(wdev); wdev_lock(wdev);
if (wdev->sme_state != CFG80211_SME_IDLE) { if (wdev->conn) {
bool event = true; bool event = true;
if (wdev->wext.connect.channel == chan) { if (wdev->wext.connect.channel == chan) {
@ -188,7 +188,7 @@ int cfg80211_mgd_wext_siwessid(struct net_device *dev,
err = 0; err = 0;
if (wdev->sme_state != CFG80211_SME_IDLE) { if (wdev->conn) {
bool event = true; bool event = true;
if (wdev->wext.connect.ssid && len && if (wdev->wext.connect.ssid && len &&
@ -277,7 +277,7 @@ int cfg80211_mgd_wext_siwap(struct net_device *dev,
wdev_lock(wdev); wdev_lock(wdev);
if (wdev->sme_state != CFG80211_SME_IDLE) { if (wdev->conn) {
err = 0; err = 0;
/* both automatic */ /* both automatic */
if (!bssid && !wdev->wext.connect.bssid) if (!bssid && !wdev->wext.connect.bssid)
@ -364,7 +364,7 @@ int cfg80211_wext_siwgenie(struct net_device *dev,
wdev->wext.ie = ie; wdev->wext.ie = ie;
wdev->wext.ie_len = ie_len; wdev->wext.ie_len = ie_len;
if (wdev->sme_state != CFG80211_SME_IDLE) { if (wdev->conn) {
err = cfg80211_disconnect(rdev, dev, err = cfg80211_disconnect(rdev, dev,
WLAN_REASON_DEAUTH_LEAVING, false); WLAN_REASON_DEAUTH_LEAVING, false);
if (err) if (err)