2 * SME code for cfg80211
3 * both driver SME event handling and the SME implementation
4 * (for nl80211's connect() and wext)
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (C) 2009 Intel Corporation. All rights reserved.
10 #include <linux/etherdevice.h>
11 #include <linux/if_arp.h>
12 #include <linux/slab.h>
13 #include <linux/workqueue.h>
14 #include <linux/wireless.h>
15 #include <linux/export.h>
16 #include <net/iw_handler.h>
17 #include <net/cfg80211.h>
18 #include <net/rtnetlink.h>
24 * Software SME in cfg80211, using auth/assoc/deauth calls to the
25 * driver. This is is for implementing nl80211's connect/disconnect
26 * and wireless extensions (if configured.)
29 struct cfg80211_conn {
30 struct cfg80211_connect_params params;
31 /* these are sub-states of the _CONNECTING sme_state */
33 CFG80211_CONN_SCANNING,
34 CFG80211_CONN_SCAN_AGAIN,
35 CFG80211_CONN_AUTHENTICATE_NEXT,
36 CFG80211_CONN_AUTHENTICATING,
37 CFG80211_CONN_AUTH_FAILED,
38 CFG80211_CONN_ASSOCIATE_NEXT,
39 CFG80211_CONN_ASSOCIATING,
40 CFG80211_CONN_ASSOC_FAILED,
42 CFG80211_CONN_CONNECTED,
44 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
47 bool auto_auth, prev_bssid_valid;
50 static void cfg80211_sme_free(struct wireless_dev *wdev)
55 kfree(wdev->conn->ie);
60 static int cfg80211_conn_scan(struct wireless_dev *wdev)
62 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
63 struct cfg80211_scan_request *request;
67 ASSERT_RDEV_LOCK(rdev);
68 ASSERT_WDEV_LOCK(wdev);
70 if (rdev->scan_req || rdev->scan_msg)
73 if (wdev->conn->params.channel)
76 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
78 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
79 sizeof(request->channels[0]) * n_channels,
84 if (wdev->conn->params.channel)
85 request->channels[0] = wdev->conn->params.channel;
88 enum ieee80211_band band;
89 struct ieee80211_supported_band *bands;
90 struct ieee80211_channel *channel;
92 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
93 bands = wdev->wiphy->bands[band];
96 for (j = 0; j < bands->n_channels; j++) {
97 channel = &bands->channels[j];
98 if (channel->flags & IEEE80211_CHAN_DISABLED)
100 request->channels[i++] = channel;
102 request->rates[band] = (1 << bands->n_bitrates) - 1;
106 request->n_channels = n_channels;
107 request->ssids = (void *)&request->channels[n_channels];
108 request->n_ssids = 1;
110 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
111 wdev->conn->params.ssid_len);
112 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
114 request->wdev = wdev;
115 request->wiphy = &rdev->wiphy;
116 request->scan_start = jiffies;
118 rdev->scan_req = request;
120 err = rdev_scan(rdev, request);
122 wdev->conn->state = CFG80211_CONN_SCANNING;
123 nl80211_send_scan_start(rdev, wdev);
124 dev_hold(wdev->netdev);
126 rdev->scan_req = NULL;
132 static int cfg80211_conn_do_work(struct wireless_dev *wdev)
134 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
135 struct cfg80211_connect_params *params;
136 struct cfg80211_assoc_request req = {};
139 ASSERT_WDEV_LOCK(wdev);
144 params = &wdev->conn->params;
146 switch (wdev->conn->state) {
147 case CFG80211_CONN_SCANNING:
148 /* didn't find it during scan ... */
150 case CFG80211_CONN_SCAN_AGAIN:
151 return cfg80211_conn_scan(wdev);
152 case CFG80211_CONN_AUTHENTICATE_NEXT:
153 BUG_ON(!rdev->ops->auth);
154 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
155 return cfg80211_mlme_auth(rdev, wdev->netdev,
156 params->channel, params->auth_type,
158 params->ssid, params->ssid_len,
160 params->key, params->key_len,
161 params->key_idx, NULL, 0);
162 case CFG80211_CONN_AUTH_FAILED:
164 case CFG80211_CONN_ASSOCIATE_NEXT:
165 BUG_ON(!rdev->ops->assoc);
166 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
167 if (wdev->conn->prev_bssid_valid)
168 req.prev_bssid = wdev->conn->prev_bssid;
170 req.ie_len = params->ie_len;
171 req.use_mfp = params->mfp != NL80211_MFP_NO;
172 req.crypto = params->crypto;
173 req.flags = params->flags;
174 req.ht_capa = params->ht_capa;
175 req.ht_capa_mask = params->ht_capa_mask;
176 req.vht_capa = params->vht_capa;
177 req.vht_capa_mask = params->vht_capa_mask;
179 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
180 params->bssid, params->ssid,
181 params->ssid_len, &req);
183 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
185 WLAN_REASON_DEAUTH_LEAVING,
188 case CFG80211_CONN_ASSOC_FAILED:
189 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
191 WLAN_REASON_DEAUTH_LEAVING, false);
193 case CFG80211_CONN_DEAUTH:
194 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
196 WLAN_REASON_DEAUTH_LEAVING, false);
197 /* free directly, disconnected event already sent */
198 cfg80211_sme_free(wdev);
205 void cfg80211_conn_work(struct work_struct *work)
207 struct cfg80211_registered_device *rdev =
208 container_of(work, struct cfg80211_registered_device, conn_work);
209 struct wireless_dev *wdev;
210 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
214 list_for_each_entry(wdev, &rdev->wdev_list, list) {
219 if (!netif_running(wdev->netdev)) {
224 wdev->conn->state == CFG80211_CONN_CONNECTED) {
228 if (wdev->conn->params.bssid) {
229 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
232 if (cfg80211_conn_do_work(wdev)) {
233 __cfg80211_connect_result(
236 WLAN_STATUS_UNSPECIFIED_FAILURE,
238 cfg80211_sme_free(wdev);
246 /* Returned bss is reference counted and must be cleaned up appropriately. */
247 static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
249 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
250 struct cfg80211_bss *bss;
251 u16 capa = WLAN_CAPABILITY_ESS;
253 ASSERT_WDEV_LOCK(wdev);
255 if (wdev->conn->params.privacy)
256 capa |= WLAN_CAPABILITY_PRIVACY;
258 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
259 wdev->conn->params.bssid,
260 wdev->conn->params.ssid,
261 wdev->conn->params.ssid_len,
262 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
267 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
268 wdev->conn->params.bssid = wdev->conn->bssid;
269 wdev->conn->params.channel = bss->channel;
270 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
271 schedule_work(&rdev->conn_work);
276 static void __cfg80211_sme_scan_done(struct net_device *dev)
278 struct wireless_dev *wdev = dev->ieee80211_ptr;
279 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
280 struct cfg80211_bss *bss;
282 ASSERT_WDEV_LOCK(wdev);
287 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
288 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
291 bss = cfg80211_get_conn_bss(wdev);
293 cfg80211_put_bss(&rdev->wiphy, bss);
295 schedule_work(&rdev->conn_work);
298 void cfg80211_sme_scan_done(struct net_device *dev)
300 struct wireless_dev *wdev = dev->ieee80211_ptr;
303 __cfg80211_sme_scan_done(dev);
307 void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
309 struct wiphy *wiphy = wdev->wiphy;
310 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
311 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
312 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
314 ASSERT_WDEV_LOCK(wdev);
316 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
319 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
320 wdev->conn->auto_auth &&
321 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
322 /* select automatically between only open, shared, leap */
323 switch (wdev->conn->params.auth_type) {
324 case NL80211_AUTHTYPE_OPEN_SYSTEM:
325 if (wdev->connect_keys)
326 wdev->conn->params.auth_type =
327 NL80211_AUTHTYPE_SHARED_KEY;
329 wdev->conn->params.auth_type =
330 NL80211_AUTHTYPE_NETWORK_EAP;
332 case NL80211_AUTHTYPE_SHARED_KEY:
333 wdev->conn->params.auth_type =
334 NL80211_AUTHTYPE_NETWORK_EAP;
338 wdev->conn->params.auth_type =
339 NL80211_AUTHTYPE_OPEN_SYSTEM;
342 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
343 schedule_work(&rdev->conn_work);
344 } else if (status_code != WLAN_STATUS_SUCCESS) {
345 __cfg80211_connect_result(wdev->netdev, mgmt->bssid,
347 status_code, false, NULL);
348 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
349 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
350 schedule_work(&rdev->conn_work);
354 bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
356 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
361 if (status == WLAN_STATUS_SUCCESS) {
362 wdev->conn->state = CFG80211_CONN_CONNECTED;
366 if (wdev->conn->prev_bssid_valid) {
368 * Some stupid APs don't accept reassoc, so we
369 * need to fall back to trying regular assoc;
370 * return true so no event is sent to userspace.
372 wdev->conn->prev_bssid_valid = false;
373 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
374 schedule_work(&rdev->conn_work);
378 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
379 schedule_work(&rdev->conn_work);
383 void cfg80211_sme_deauth(struct wireless_dev *wdev)
385 cfg80211_sme_free(wdev);
388 void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
390 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
395 wdev->conn->state = CFG80211_CONN_AUTH_FAILED;
396 schedule_work(&rdev->conn_work);
399 void cfg80211_sme_disassoc(struct wireless_dev *wdev)
401 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
406 wdev->conn->state = CFG80211_CONN_DEAUTH;
407 schedule_work(&rdev->conn_work);
410 void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
412 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
417 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
418 schedule_work(&rdev->conn_work);
421 static int cfg80211_sme_connect(struct wireless_dev *wdev,
422 struct cfg80211_connect_params *connect,
423 const u8 *prev_bssid)
425 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
426 struct cfg80211_bss *bss;
429 if (!rdev->ops->auth || !rdev->ops->assoc)
432 if (wdev->current_bss)
435 if (WARN_ON(wdev->conn))
438 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
443 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
445 memcpy(&wdev->conn->params, connect, sizeof(*connect));
446 if (connect->bssid) {
447 wdev->conn->params.bssid = wdev->conn->bssid;
448 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
452 wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
454 wdev->conn->params.ie = wdev->conn->ie;
455 if (!wdev->conn->ie) {
462 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
463 wdev->conn->auto_auth = true;
464 /* start with open system ... should mostly work */
465 wdev->conn->params.auth_type =
466 NL80211_AUTHTYPE_OPEN_SYSTEM;
468 wdev->conn->auto_auth = false;
471 wdev->conn->params.ssid = wdev->ssid;
472 wdev->conn->params.ssid_len = connect->ssid_len;
474 /* see if we have the bss already */
475 bss = cfg80211_get_conn_bss(wdev);
478 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
479 wdev->conn->prev_bssid_valid = true;
482 /* we're good if we have a matching bss struct */
484 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
485 err = cfg80211_conn_do_work(wdev);
486 cfg80211_put_bss(wdev->wiphy, bss);
488 /* otherwise we'll need to scan for the AP first */
489 err = cfg80211_conn_scan(wdev);
492 * If we can't scan right now, then we need to scan again
493 * after the current scan finished, since the parameters
494 * changed (unless we find a good AP anyway).
498 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
503 cfg80211_sme_free(wdev);
508 static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
510 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
516 if (!rdev->ops->deauth)
519 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
520 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
525 /* wdev->conn->params.bssid must be set if > SCANNING */
526 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
527 wdev->conn->params.bssid,
528 NULL, 0, reason, false);
530 cfg80211_sme_free(wdev);
535 * code shared for in-device and software SME
538 static bool cfg80211_is_all_idle(void)
540 struct cfg80211_registered_device *rdev;
541 struct wireless_dev *wdev;
542 bool is_all_idle = true;
545 * All devices must be idle as otherwise if you are actively
546 * scanning some new beacon hints could be learned and would
547 * count as new regulatory hints.
549 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
550 list_for_each_entry(wdev, &rdev->wdev_list, list) {
552 if (wdev->conn || wdev->current_bss)
561 static void disconnect_work(struct work_struct *work)
564 if (cfg80211_is_all_idle())
565 regulatory_hint_disconnect();
569 static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
573 * API calls for drivers implementing connect/disconnect and
577 /* This method must consume bss one way or another */
578 void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
579 const u8 *req_ie, size_t req_ie_len,
580 const u8 *resp_ie, size_t resp_ie_len,
581 u16 status, bool wextev,
582 struct cfg80211_bss *bss)
584 struct wireless_dev *wdev = dev->ieee80211_ptr;
585 const u8 *country_ie;
586 #ifdef CONFIG_CFG80211_WEXT
587 union iwreq_data wrqu;
590 ASSERT_WDEV_LOCK(wdev);
592 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
593 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
594 cfg80211_put_bss(wdev->wiphy, bss);
598 nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev,
599 bssid, req_ie, req_ie_len,
600 resp_ie, resp_ie_len,
603 #ifdef CONFIG_CFG80211_WEXT
605 if (req_ie && status == WLAN_STATUS_SUCCESS) {
606 memset(&wrqu, 0, sizeof(wrqu));
607 wrqu.data.length = req_ie_len;
608 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
611 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
612 memset(&wrqu, 0, sizeof(wrqu));
613 wrqu.data.length = resp_ie_len;
614 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
617 memset(&wrqu, 0, sizeof(wrqu));
618 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
619 if (bssid && status == WLAN_STATUS_SUCCESS) {
620 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
621 memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN);
622 wdev->wext.prev_bssid_valid = true;
624 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
628 if (!bss && (status == WLAN_STATUS_SUCCESS)) {
629 WARN_ON_ONCE(!wiphy_to_dev(wdev->wiphy)->ops->connect);
630 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
631 wdev->ssid, wdev->ssid_len,
633 WLAN_CAPABILITY_ESS);
635 cfg80211_hold_bss(bss_from_pub(bss));
638 if (wdev->current_bss) {
639 cfg80211_unhold_bss(wdev->current_bss);
640 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
641 wdev->current_bss = NULL;
644 if (status != WLAN_STATUS_SUCCESS) {
645 kfree(wdev->connect_keys);
646 wdev->connect_keys = NULL;
649 cfg80211_unhold_bss(bss_from_pub(bss));
650 cfg80211_put_bss(wdev->wiphy, bss);
658 wdev->current_bss = bss_from_pub(bss);
660 cfg80211_upload_connect_keys(wdev);
663 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
669 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
676 * ieee80211_bss_get_ie() ensures we can access:
677 * - country_ie + 2, the start of the country ie data, and
678 * - and country_ie[1] which is the IE length
680 regulatory_hint_country_ie(wdev->wiphy, bss->channel->band,
681 country_ie + 2, country_ie[1]);
685 void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
686 const u8 *req_ie, size_t req_ie_len,
687 const u8 *resp_ie, size_t resp_ie_len,
688 u16 status, gfp_t gfp)
690 struct wireless_dev *wdev = dev->ieee80211_ptr;
691 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
692 struct cfg80211_event *ev;
695 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
699 ev->type = EVENT_CONNECT_RESULT;
701 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
703 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
704 ev->cr.req_ie_len = req_ie_len;
705 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
708 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
709 ev->cr.resp_ie_len = resp_ie_len;
710 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
712 ev->cr.status = status;
714 spin_lock_irqsave(&wdev->event_lock, flags);
715 list_add_tail(&ev->list, &wdev->event_list);
716 spin_unlock_irqrestore(&wdev->event_lock, flags);
717 queue_work(cfg80211_wq, &rdev->event_work);
719 EXPORT_SYMBOL(cfg80211_connect_result);
721 /* Consumes bss object one way or another */
722 void __cfg80211_roamed(struct wireless_dev *wdev,
723 struct cfg80211_bss *bss,
724 const u8 *req_ie, size_t req_ie_len,
725 const u8 *resp_ie, size_t resp_ie_len)
727 #ifdef CONFIG_CFG80211_WEXT
728 union iwreq_data wrqu;
730 ASSERT_WDEV_LOCK(wdev);
732 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
733 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
736 if (WARN_ON(!wdev->current_bss))
739 cfg80211_unhold_bss(wdev->current_bss);
740 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
741 wdev->current_bss = NULL;
743 cfg80211_hold_bss(bss_from_pub(bss));
744 wdev->current_bss = bss_from_pub(bss);
746 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bss->bssid,
747 req_ie, req_ie_len, resp_ie, resp_ie_len,
750 #ifdef CONFIG_CFG80211_WEXT
752 memset(&wrqu, 0, sizeof(wrqu));
753 wrqu.data.length = req_ie_len;
754 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
759 memset(&wrqu, 0, sizeof(wrqu));
760 wrqu.data.length = resp_ie_len;
761 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
765 memset(&wrqu, 0, sizeof(wrqu));
766 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
767 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
768 memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN);
769 wdev->wext.prev_bssid_valid = true;
770 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
775 cfg80211_put_bss(wdev->wiphy, bss);
778 void cfg80211_roamed(struct net_device *dev,
779 struct ieee80211_channel *channel,
781 const u8 *req_ie, size_t req_ie_len,
782 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
784 struct wireless_dev *wdev = dev->ieee80211_ptr;
785 struct cfg80211_bss *bss;
787 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
788 wdev->ssid_len, WLAN_CAPABILITY_ESS,
789 WLAN_CAPABILITY_ESS);
793 cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie,
796 EXPORT_SYMBOL(cfg80211_roamed);
798 /* Consumes bss object one way or another */
799 void cfg80211_roamed_bss(struct net_device *dev,
800 struct cfg80211_bss *bss, const u8 *req_ie,
801 size_t req_ie_len, const u8 *resp_ie,
802 size_t resp_ie_len, gfp_t gfp)
804 struct wireless_dev *wdev = dev->ieee80211_ptr;
805 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
806 struct cfg80211_event *ev;
812 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
814 cfg80211_put_bss(wdev->wiphy, bss);
818 ev->type = EVENT_ROAMED;
819 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
820 ev->rm.req_ie_len = req_ie_len;
821 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
822 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
823 ev->rm.resp_ie_len = resp_ie_len;
824 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
827 spin_lock_irqsave(&wdev->event_lock, flags);
828 list_add_tail(&ev->list, &wdev->event_list);
829 spin_unlock_irqrestore(&wdev->event_lock, flags);
830 queue_work(cfg80211_wq, &rdev->event_work);
832 EXPORT_SYMBOL(cfg80211_roamed_bss);
834 void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
835 size_t ie_len, u16 reason, bool from_ap)
837 struct wireless_dev *wdev = dev->ieee80211_ptr;
838 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
840 #ifdef CONFIG_CFG80211_WEXT
841 union iwreq_data wrqu;
844 ASSERT_WDEV_LOCK(wdev);
846 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
847 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
850 if (wdev->current_bss) {
851 cfg80211_unhold_bss(wdev->current_bss);
852 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
855 wdev->current_bss = NULL;
858 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
861 * Delete all the keys ... pairwise keys can't really
862 * exist any more anyway, but default keys might.
864 if (rdev->ops->del_key)
865 for (i = 0; i < 6; i++)
866 rdev_del_key(rdev, dev, i, false, NULL);
868 rdev_set_qos_map(rdev, dev, NULL);
870 #ifdef CONFIG_CFG80211_WEXT
871 memset(&wrqu, 0, sizeof(wrqu));
872 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
873 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
874 wdev->wext.connect.ssid_len = 0;
877 schedule_work(&cfg80211_disconnect_work);
880 void cfg80211_disconnected(struct net_device *dev, u16 reason,
881 u8 *ie, size_t ie_len, gfp_t gfp)
883 struct wireless_dev *wdev = dev->ieee80211_ptr;
884 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
885 struct cfg80211_event *ev;
888 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
892 ev->type = EVENT_DISCONNECTED;
893 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
894 ev->dc.ie_len = ie_len;
895 memcpy((void *)ev->dc.ie, ie, ie_len);
896 ev->dc.reason = reason;
898 spin_lock_irqsave(&wdev->event_lock, flags);
899 list_add_tail(&ev->list, &wdev->event_list);
900 spin_unlock_irqrestore(&wdev->event_lock, flags);
901 queue_work(cfg80211_wq, &rdev->event_work);
903 EXPORT_SYMBOL(cfg80211_disconnected);
906 * API calls for nl80211/wext compatibility code
908 int cfg80211_connect(struct cfg80211_registered_device *rdev,
909 struct net_device *dev,
910 struct cfg80211_connect_params *connect,
911 struct cfg80211_cached_keys *connkeys,
912 const u8 *prev_bssid)
914 struct wireless_dev *wdev = dev->ieee80211_ptr;
917 ASSERT_WDEV_LOCK(wdev);
919 if (WARN_ON(wdev->connect_keys)) {
920 kfree(wdev->connect_keys);
921 wdev->connect_keys = NULL;
924 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
925 rdev->wiphy.ht_capa_mod_mask);
927 if (connkeys && connkeys->def >= 0) {
932 cipher = connkeys->params[idx].cipher;
933 /* If given a WEP key we may need it for shared key auth */
934 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
935 cipher == WLAN_CIPHER_SUITE_WEP104) {
936 connect->key_idx = idx;
937 connect->key = connkeys->params[idx].key;
938 connect->key_len = connkeys->params[idx].key_len;
941 * If ciphers are not set (e.g. when going through
942 * iwconfig), we have to set them appropriately here.
944 if (connect->crypto.cipher_group == 0)
945 connect->crypto.cipher_group = cipher;
947 if (connect->crypto.n_ciphers_pairwise == 0) {
948 connect->crypto.n_ciphers_pairwise = 1;
949 connect->crypto.ciphers_pairwise[0] = cipher;
954 wdev->connect_keys = connkeys;
955 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
956 wdev->ssid_len = connect->ssid_len;
958 if (!rdev->ops->connect)
959 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
961 err = rdev_connect(rdev, dev, connect);
964 wdev->connect_keys = NULL;
972 int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
973 struct net_device *dev, u16 reason, bool wextev)
975 struct wireless_dev *wdev = dev->ieee80211_ptr;
978 ASSERT_WDEV_LOCK(wdev);
980 kfree(wdev->connect_keys);
981 wdev->connect_keys = NULL;
984 err = cfg80211_sme_disconnect(wdev, reason);
985 else if (!rdev->ops->disconnect)
986 cfg80211_mlme_down(rdev, dev);
987 else if (wdev->current_bss)
988 err = rdev_disconnect(rdev, dev, reason);