9 #include <linux/if_arp.h>
10 #include <linux/slab.h>
12 #include <linux/wireless.h>
13 #include <linux/export.h>
39 static bool cfg80211_is_all_idle(
void)
43 bool is_all_idle =
true;
53 cfg80211_lock_rdev(rdev);
60 cfg80211_unlock_rdev(rdev);
70 if (!cfg80211_is_all_idle())
76 static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
91 if (wdev->
conn->params.channel) {
98 if (!wdev->
wiphy->bands[band])
100 n_channels += wdev->
wiphy->bands[band]->n_channels;
103 request = kzalloc(
sizeof(*request) +
sizeof(request->
ssids[0]) +
104 sizeof(request->
channels[0]) * n_channels,
109 if (wdev->
conn->params.channel)
136 wdev->
conn->params.ssid_len);
137 request->
ssids[0].ssid_len = wdev->
conn->params.ssid_len;
139 request->
wdev = wdev;
140 request->
wiphy = &rdev->wiphy;
144 err = rdev->
ops->scan(wdev->
wiphy, request);
146 wdev->
conn->state = CFG80211_CONN_SCANNING;
156 static int cfg80211_conn_do_work(
struct wireless_dev *wdev)
160 const u8 *prev_bssid =
NULL;
168 params = &wdev->
conn->params;
170 switch (wdev->
conn->state) {
171 case CFG80211_CONN_SCAN_AGAIN:
172 return cfg80211_conn_scan(wdev);
173 case CFG80211_CONN_AUTHENTICATE_NEXT:
175 wdev->
conn->state = CFG80211_CONN_AUTHENTICATING;
183 case CFG80211_CONN_ASSOCIATE_NEXT:
185 wdev->
conn->state = CFG80211_CONN_ASSOCIATING;
186 if (wdev->
conn->prev_bssid_valid)
187 prev_bssid = wdev->
conn->prev_bssid;
202 case CFG80211_CONN_DEAUTH_ASSOC_FAIL:
221 cfg80211_lock_rdev(rdev);
226 if (!netif_running(wdev->
netdev)) {
234 if (wdev->
conn->params.bssid) {
238 if (cfg80211_conn_do_work(wdev))
248 cfg80211_unlock_rdev(rdev);
260 if (wdev->
conn->params.privacy)
264 wdev->
conn->params.bssid,
265 wdev->
conn->params.ssid,
266 wdev->
conn->params.ssid_len,
273 wdev->
conn->params.bssid = wdev->
conn->bssid;
275 wdev->
conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
289 if (wdev->
sme_state != CFG80211_SME_CONNECTING)
295 if (wdev->
conn->state != CFG80211_CONN_SCANNING &&
296 wdev->
conn->state != CFG80211_CONN_SCAN_AGAIN)
299 bss = cfg80211_get_conn_bss(wdev);
304 if (wdev->
conn->state == CFG80211_CONN_SCAN_AGAIN)
309 wdev->
conn->params.bssid,
322 __cfg80211_sme_scan_done(dev);
328 const u8 *
buf,
size_t len)
339 if (wdev->
sme_state != CFG80211_SME_CONNECTING)
346 wdev->
conn->auto_auth &&
349 switch (wdev->
conn->params.auth_type) {
352 wdev->
conn->params.auth_type =
355 wdev->
conn->params.auth_type =
359 wdev->
conn->params.auth_type =
364 wdev->
conn->params.auth_type =
368 wdev->
conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
372 status_code,
false,
NULL);
373 }
else if (wdev->
sme_state == CFG80211_SME_CONNECTING &&
374 wdev->
conn->state == CFG80211_CONN_AUTHENTICATING) {
375 wdev->
conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
388 if (!wdev->
conn->prev_bssid_valid)
395 wdev->
conn->prev_bssid_valid =
false;
396 wdev->
conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
407 wdev->
conn->state = CFG80211_CONN_DEAUTH_ASSOC_FAIL;
412 const u8 *req_ie,
size_t req_ie_len,
413 const u8 *resp_ie,
size_t resp_ie_len,
419 #ifdef CONFIG_CFG80211_WEXT
429 if (wdev->
sme_state != CFG80211_SME_CONNECTING)
433 bssid, req_ie, req_ie_len,
434 resp_ie, resp_ie_len,
437 #ifdef CONFIG_CFG80211_WEXT
440 memset(&wrqu, 0,
sizeof(wrqu));
441 wrqu.
data.length = req_ie_len;
446 memset(&wrqu, 0,
sizeof(wrqu));
447 wrqu.
data.length = resp_ie_len;
451 memset(&wrqu, 0,
sizeof(wrqu));
456 wdev->wext.prev_bssid_valid =
true;
469 wdev->
conn->state = CFG80211_CONN_IDLE;
486 wdev->
conn ? wdev->
conn->params.channel :
496 cfg80211_hold_bss(bss_from_pub(bss));
499 wdev->
sme_state = CFG80211_SME_CONNECTED;
519 const u8 *req_ie,
size_t req_ie_len,
520 const u8 *resp_ie,
size_t resp_ie_len,
530 ev = kzalloc(
sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
538 ev->
cr.req_ie = ((
u8 *)ev) +
sizeof(*ev);
540 memcpy((
void *)ev->
cr.req_ie, req_ie, req_ie_len);
545 memcpy((
void *)ev->
cr.resp_ie, resp_ie, resp_ie_len);
551 spin_unlock_irqrestore(&wdev->
event_lock, flags);
561 #ifdef CONFIG_CFG80211_WEXT
570 if (wdev->
sme_state != CFG80211_SME_CONNECTED)
582 cfg80211_hold_bss(bss_from_pub(bss));
586 req_ie, req_ie_len, resp_ie, resp_ie_len,
589 #ifdef CONFIG_CFG80211_WEXT
591 memset(&wrqu, 0,
sizeof(wrqu));
592 wrqu.
data.length = req_ie_len;
598 memset(&wrqu, 0,
sizeof(wrqu));
599 wrqu.
data.length = resp_ie_len;
604 memset(&wrqu, 0,
sizeof(wrqu));
608 wdev->wext.prev_bssid_valid =
true;
620 const u8 *req_ie,
size_t req_ie_len,
621 const u8 *resp_ie,
size_t resp_ie_len,
gfp_t gfp)
641 size_t req_ie_len,
const u8 *resp_ie,
642 size_t resp_ie_len,
gfp_t gfp)
654 ev = kzalloc(
sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
661 ev->
rm.req_ie = ((
u8 *)ev) +
sizeof(*ev);
663 memcpy((
void *)ev->
rm.req_ie, req_ie, req_ie_len);
666 memcpy((
void *)ev->
rm.resp_ie, resp_ie, resp_ie_len);
671 spin_unlock_irqrestore(&wdev->
event_lock, flags);
682 #ifdef CONFIG_CFG80211_WEXT
692 if (wdev->
sme_state != CFG80211_SME_CONNECTED)
717 if (rdev->
ops->del_key)
718 for (i = 0; i < 6; i++)
721 #ifdef CONFIG_CFG80211_WEXT
722 memset(&wrqu, 0,
sizeof(wrqu));
741 ev = kzalloc(
sizeof(*ev) + ie_len, gfp);
746 ev->
dc.ie = ((
u8 *)ev) +
sizeof(*ev);
748 memcpy((
void *)ev->
dc.ie, ie, ie_len);
753 spin_unlock_irqrestore(&wdev->
event_lock, flags);
762 const u8 *prev_bssid)
770 if (wdev->
sme_state != CFG80211_SME_IDLE)
779 rdev->wiphy.ht_capa_mod_mask);
781 if (connkeys && connkeys->
def >= 0) {
798 if (connect->
crypto.cipher_group == 0)
801 if (connect->
crypto.n_ciphers_pairwise == 0) {
802 connect->
crypto.n_ciphers_pairwise = 1;
808 if (!rdev->
ops->connect) {
809 if (!rdev->
ops->auth || !rdev->
ops->assoc)
822 memcpy(&wdev->
conn->params, connect,
sizeof(*connect));
823 if (connect->
bssid) {
824 wdev->
conn->params.bssid = wdev->
conn->bssid;
831 wdev->
conn->params.ie = wdev->
conn->ie;
832 if (!wdev->
conn->ie) {
840 wdev->
conn->auto_auth =
true;
842 wdev->
conn->params.auth_type =
845 wdev->
conn->auto_auth =
false;
850 wdev->
conn->params.ssid = wdev->
ssid;
854 bss = cfg80211_get_conn_bss(wdev);
856 wdev->
sme_state = CFG80211_SME_CONNECTING;
861 wdev->
conn->prev_bssid_valid =
true;
866 wdev->
conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
867 err = cfg80211_conn_do_work(wdev);
871 err = cfg80211_conn_scan(wdev);
879 wdev->
conn->state = CFG80211_CONN_SCAN_AGAIN;
893 wdev->
sme_state = CFG80211_SME_CONNECTING;
895 err = rdev->
ops->connect(&rdev->wiphy, dev, connect);
939 if (!rdev->
ops->disconnect) {
940 if (!rdev->
ops->deauth)
950 (wdev->
conn->state == CFG80211_CONN_SCANNING ||
951 wdev->
conn->state == CFG80211_CONN_SCAN_AGAIN)) {
962 wdev->
conn->params.bssid,
963 NULL, 0, reason,
false);
967 err = rdev->
ops->disconnect(&rdev->wiphy, dev, reason);
1007 if (wdev->
conn->state == CFG80211_CONN_IDLE)