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_ABANDON,
43 CFG80211_CONN_CONNECTED,
45 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
48 bool auto_auth, prev_bssid_valid;
51 static void cfg80211_sme_free(struct wireless_dev *wdev)
56 kfree(wdev->conn->ie);
61 static int cfg80211_conn_scan(struct wireless_dev *wdev)
63 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
64 struct cfg80211_scan_request *request;
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_rdev(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 if (WARN_ON(!rdev->ops->auth))
155 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
156 return cfg80211_mlme_auth(rdev, wdev->netdev,
157 params->channel, params->auth_type,
159 params->ssid, params->ssid_len,
161 params->key, params->key_len,
162 params->key_idx, NULL, 0);
163 case CFG80211_CONN_AUTH_FAILED:
165 case CFG80211_CONN_ASSOCIATE_NEXT:
166 if (WARN_ON(!rdev->ops->assoc))
168 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
169 if (wdev->conn->prev_bssid_valid)
170 req.prev_bssid = wdev->conn->prev_bssid;
172 req.ie_len = params->ie_len;
173 req.use_mfp = params->mfp != NL80211_MFP_NO;
174 req.crypto = params->crypto;
175 req.flags = params->flags;
176 req.ht_capa = params->ht_capa;
177 req.ht_capa_mask = params->ht_capa_mask;
178 req.vht_capa = params->vht_capa;
179 req.vht_capa_mask = params->vht_capa_mask;
181 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
182 params->bssid, params->ssid,
183 params->ssid_len, &req);
185 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
187 WLAN_REASON_DEAUTH_LEAVING,
190 case CFG80211_CONN_ASSOC_FAILED:
191 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
193 WLAN_REASON_DEAUTH_LEAVING, false);
195 case CFG80211_CONN_DEAUTH:
196 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
198 WLAN_REASON_DEAUTH_LEAVING, false);
200 case CFG80211_CONN_ABANDON:
201 /* free directly, disconnected event already sent */
202 cfg80211_sme_free(wdev);
209 void cfg80211_conn_work(struct work_struct *work)
211 struct cfg80211_registered_device *rdev =
212 container_of(work, struct cfg80211_registered_device, conn_work);
213 struct wireless_dev *wdev;
214 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
218 list_for_each_entry(wdev, &rdev->wdev_list, list) {
223 if (!netif_running(wdev->netdev)) {
228 wdev->conn->state == CFG80211_CONN_CONNECTED) {
232 if (wdev->conn->params.bssid) {
233 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
236 if (cfg80211_conn_do_work(wdev)) {
237 __cfg80211_connect_result(
240 WLAN_STATUS_UNSPECIFIED_FAILURE,
249 /* Returned bss is reference counted and must be cleaned up appropriately. */
250 static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
252 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
253 struct cfg80211_bss *bss;
254 u16 capa = WLAN_CAPABILITY_ESS;
256 ASSERT_WDEV_LOCK(wdev);
258 if (wdev->conn->params.privacy)
259 capa |= WLAN_CAPABILITY_PRIVACY;
261 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
262 wdev->conn->params.bssid,
263 wdev->conn->params.ssid,
264 wdev->conn->params.ssid_len,
265 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
270 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
271 wdev->conn->params.bssid = wdev->conn->bssid;
272 wdev->conn->params.channel = bss->channel;
273 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
274 schedule_work(&rdev->conn_work);
279 static void __cfg80211_sme_scan_done(struct net_device *dev)
281 struct wireless_dev *wdev = dev->ieee80211_ptr;
282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
283 struct cfg80211_bss *bss;
285 ASSERT_WDEV_LOCK(wdev);
290 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
291 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
294 bss = cfg80211_get_conn_bss(wdev);
296 cfg80211_put_bss(&rdev->wiphy, bss);
298 schedule_work(&rdev->conn_work);
301 void cfg80211_sme_scan_done(struct net_device *dev)
303 struct wireless_dev *wdev = dev->ieee80211_ptr;
306 __cfg80211_sme_scan_done(dev);
310 void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
312 struct wiphy *wiphy = wdev->wiphy;
313 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
314 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
315 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
317 ASSERT_WDEV_LOCK(wdev);
319 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
322 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
323 wdev->conn->auto_auth &&
324 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
325 /* select automatically between only open, shared, leap */
326 switch (wdev->conn->params.auth_type) {
327 case NL80211_AUTHTYPE_OPEN_SYSTEM:
328 if (wdev->connect_keys)
329 wdev->conn->params.auth_type =
330 NL80211_AUTHTYPE_SHARED_KEY;
332 wdev->conn->params.auth_type =
333 NL80211_AUTHTYPE_NETWORK_EAP;
335 case NL80211_AUTHTYPE_SHARED_KEY:
336 wdev->conn->params.auth_type =
337 NL80211_AUTHTYPE_NETWORK_EAP;
341 wdev->conn->params.auth_type =
342 NL80211_AUTHTYPE_OPEN_SYSTEM;
345 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
346 schedule_work(&rdev->conn_work);
347 } else if (status_code != WLAN_STATUS_SUCCESS) {
348 __cfg80211_connect_result(wdev->netdev, mgmt->bssid,
350 status_code, false, NULL);
351 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
352 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
353 schedule_work(&rdev->conn_work);
357 bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
359 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
364 if (status == WLAN_STATUS_SUCCESS) {
365 wdev->conn->state = CFG80211_CONN_CONNECTED;
369 if (wdev->conn->prev_bssid_valid) {
371 * Some stupid APs don't accept reassoc, so we
372 * need to fall back to trying regular assoc;
373 * return true so no event is sent to userspace.
375 wdev->conn->prev_bssid_valid = false;
376 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
377 schedule_work(&rdev->conn_work);
381 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
382 schedule_work(&rdev->conn_work);
386 void cfg80211_sme_deauth(struct wireless_dev *wdev)
388 cfg80211_sme_free(wdev);
391 void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
393 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
398 wdev->conn->state = CFG80211_CONN_AUTH_FAILED;
399 schedule_work(&rdev->conn_work);
402 void cfg80211_sme_disassoc(struct wireless_dev *wdev)
404 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
409 wdev->conn->state = CFG80211_CONN_DEAUTH;
410 schedule_work(&rdev->conn_work);
413 void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
415 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
420 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
421 schedule_work(&rdev->conn_work);
424 void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev)
426 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
431 wdev->conn->state = CFG80211_CONN_ABANDON;
432 schedule_work(&rdev->conn_work);
435 static int cfg80211_sme_connect(struct wireless_dev *wdev,
436 struct cfg80211_connect_params *connect,
437 const u8 *prev_bssid)
439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
440 struct cfg80211_bss *bss;
443 if (!rdev->ops->auth || !rdev->ops->assoc)
446 if (wdev->current_bss)
449 if (WARN_ON(wdev->conn))
452 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
457 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
459 memcpy(&wdev->conn->params, connect, sizeof(*connect));
460 if (connect->bssid) {
461 wdev->conn->params.bssid = wdev->conn->bssid;
462 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
466 wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
468 wdev->conn->params.ie = wdev->conn->ie;
469 if (!wdev->conn->ie) {
476 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
477 wdev->conn->auto_auth = true;
478 /* start with open system ... should mostly work */
479 wdev->conn->params.auth_type =
480 NL80211_AUTHTYPE_OPEN_SYSTEM;
482 wdev->conn->auto_auth = false;
485 wdev->conn->params.ssid = wdev->ssid;
486 wdev->conn->params.ssid_len = wdev->ssid_len;
488 /* see if we have the bss already */
489 bss = cfg80211_get_conn_bss(wdev);
492 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
493 wdev->conn->prev_bssid_valid = true;
496 /* we're good if we have a matching bss struct */
498 err = cfg80211_conn_do_work(wdev);
499 cfg80211_put_bss(wdev->wiphy, bss);
501 /* otherwise we'll need to scan for the AP first */
502 err = cfg80211_conn_scan(wdev);
505 * If we can't scan right now, then we need to scan again
506 * after the current scan finished, since the parameters
507 * changed (unless we find a good AP anyway).
511 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
516 cfg80211_sme_free(wdev);
521 static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
523 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
529 if (!rdev->ops->deauth)
532 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
533 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
538 /* wdev->conn->params.bssid must be set if > SCANNING */
539 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
540 wdev->conn->params.bssid,
541 NULL, 0, reason, false);
543 cfg80211_sme_free(wdev);
548 * code shared for in-device and software SME
551 static bool cfg80211_is_all_idle(void)
553 struct cfg80211_registered_device *rdev;
554 struct wireless_dev *wdev;
555 bool is_all_idle = true;
558 * All devices must be idle as otherwise if you are actively
559 * scanning some new beacon hints could be learned and would
560 * count as new regulatory hints.
562 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
563 list_for_each_entry(wdev, &rdev->wdev_list, list) {
565 if (wdev->conn || wdev->current_bss)
574 static void disconnect_work(struct work_struct *work)
577 if (cfg80211_is_all_idle())
578 regulatory_hint_disconnect();
582 static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
586 * API calls for drivers implementing connect/disconnect and
590 /* This method must consume bss one way or another */
591 void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
592 const u8 *req_ie, size_t req_ie_len,
593 const u8 *resp_ie, size_t resp_ie_len,
594 u16 status, bool wextev,
595 struct cfg80211_bss *bss)
597 struct wireless_dev *wdev = dev->ieee80211_ptr;
598 const u8 *country_ie;
599 #ifdef CONFIG_CFG80211_WEXT
600 union iwreq_data wrqu;
603 ASSERT_WDEV_LOCK(wdev);
605 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
606 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
607 cfg80211_put_bss(wdev->wiphy, bss);
611 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev,
612 bssid, req_ie, req_ie_len,
613 resp_ie, resp_ie_len,
616 #ifdef CONFIG_CFG80211_WEXT
618 if (req_ie && status == WLAN_STATUS_SUCCESS) {
619 memset(&wrqu, 0, sizeof(wrqu));
620 wrqu.data.length = req_ie_len;
621 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
624 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
625 memset(&wrqu, 0, sizeof(wrqu));
626 wrqu.data.length = resp_ie_len;
627 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
630 memset(&wrqu, 0, sizeof(wrqu));
631 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
632 if (bssid && status == WLAN_STATUS_SUCCESS) {
633 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
634 memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN);
635 wdev->wext.prev_bssid_valid = true;
637 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
641 if (!bss && (status == WLAN_STATUS_SUCCESS)) {
642 WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect);
643 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
644 wdev->ssid, wdev->ssid_len,
646 WLAN_CAPABILITY_ESS);
648 cfg80211_hold_bss(bss_from_pub(bss));
651 if (wdev->current_bss) {
652 cfg80211_unhold_bss(wdev->current_bss);
653 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
654 wdev->current_bss = NULL;
657 if (status != WLAN_STATUS_SUCCESS) {
658 kfree(wdev->connect_keys);
659 wdev->connect_keys = NULL;
662 cfg80211_unhold_bss(bss_from_pub(bss));
663 cfg80211_put_bss(wdev->wiphy, bss);
665 cfg80211_sme_free(wdev);
672 wdev->current_bss = bss_from_pub(bss);
674 cfg80211_upload_connect_keys(wdev);
677 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
683 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
690 * ieee80211_bss_get_ie() ensures we can access:
691 * - country_ie + 2, the start of the country ie data, and
692 * - and country_ie[1] which is the IE length
694 regulatory_hint_country_ie(wdev->wiphy, bss->channel->band,
695 country_ie + 2, country_ie[1]);
699 void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
700 const u8 *req_ie, size_t req_ie_len,
701 const u8 *resp_ie, size_t resp_ie_len,
702 u16 status, gfp_t gfp)
704 struct wireless_dev *wdev = dev->ieee80211_ptr;
705 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
706 struct cfg80211_event *ev;
709 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
713 ev->type = EVENT_CONNECT_RESULT;
715 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
717 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
718 ev->cr.req_ie_len = req_ie_len;
719 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
722 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
723 ev->cr.resp_ie_len = resp_ie_len;
724 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
726 ev->cr.status = status;
728 spin_lock_irqsave(&wdev->event_lock, flags);
729 list_add_tail(&ev->list, &wdev->event_list);
730 spin_unlock_irqrestore(&wdev->event_lock, flags);
731 queue_work(cfg80211_wq, &rdev->event_work);
733 EXPORT_SYMBOL(cfg80211_connect_result);
735 /* Consumes bss object one way or another */
736 void __cfg80211_roamed(struct wireless_dev *wdev,
737 struct cfg80211_bss *bss,
738 const u8 *req_ie, size_t req_ie_len,
739 const u8 *resp_ie, size_t resp_ie_len)
741 #ifdef CONFIG_CFG80211_WEXT
742 union iwreq_data wrqu;
744 ASSERT_WDEV_LOCK(wdev);
746 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
747 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
750 if (WARN_ON(!wdev->current_bss))
753 cfg80211_unhold_bss(wdev->current_bss);
754 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
755 wdev->current_bss = NULL;
757 cfg80211_hold_bss(bss_from_pub(bss));
758 wdev->current_bss = bss_from_pub(bss);
760 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
761 wdev->netdev, bss->bssid,
762 req_ie, req_ie_len, resp_ie, resp_ie_len,
765 #ifdef CONFIG_CFG80211_WEXT
767 memset(&wrqu, 0, sizeof(wrqu));
768 wrqu.data.length = req_ie_len;
769 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
774 memset(&wrqu, 0, sizeof(wrqu));
775 wrqu.data.length = resp_ie_len;
776 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
780 memset(&wrqu, 0, sizeof(wrqu));
781 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
782 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
783 memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN);
784 wdev->wext.prev_bssid_valid = true;
785 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
790 cfg80211_put_bss(wdev->wiphy, bss);
793 void cfg80211_roamed(struct net_device *dev,
794 struct ieee80211_channel *channel,
796 const u8 *req_ie, size_t req_ie_len,
797 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
799 struct wireless_dev *wdev = dev->ieee80211_ptr;
800 struct cfg80211_bss *bss;
802 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
803 wdev->ssid_len, WLAN_CAPABILITY_ESS,
804 WLAN_CAPABILITY_ESS);
808 cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie,
811 EXPORT_SYMBOL(cfg80211_roamed);
813 /* Consumes bss object one way or another */
814 void cfg80211_roamed_bss(struct net_device *dev,
815 struct cfg80211_bss *bss, const u8 *req_ie,
816 size_t req_ie_len, const u8 *resp_ie,
817 size_t resp_ie_len, gfp_t gfp)
819 struct wireless_dev *wdev = dev->ieee80211_ptr;
820 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
821 struct cfg80211_event *ev;
827 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
829 cfg80211_put_bss(wdev->wiphy, bss);
833 ev->type = EVENT_ROAMED;
834 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
835 ev->rm.req_ie_len = req_ie_len;
836 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
837 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
838 ev->rm.resp_ie_len = resp_ie_len;
839 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
842 spin_lock_irqsave(&wdev->event_lock, flags);
843 list_add_tail(&ev->list, &wdev->event_list);
844 spin_unlock_irqrestore(&wdev->event_lock, flags);
845 queue_work(cfg80211_wq, &rdev->event_work);
847 EXPORT_SYMBOL(cfg80211_roamed_bss);
849 void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
850 size_t ie_len, u16 reason, bool from_ap)
852 struct wireless_dev *wdev = dev->ieee80211_ptr;
853 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
855 #ifdef CONFIG_CFG80211_WEXT
856 union iwreq_data wrqu;
859 ASSERT_WDEV_LOCK(wdev);
861 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
862 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
865 if (wdev->current_bss) {
866 cfg80211_unhold_bss(wdev->current_bss);
867 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
870 wdev->current_bss = NULL;
873 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
876 * Delete all the keys ... pairwise keys can't really
877 * exist any more anyway, but default keys might.
879 if (rdev->ops->del_key)
880 for (i = 0; i < 6; i++)
881 rdev_del_key(rdev, dev, i, false, NULL);
883 rdev_set_qos_map(rdev, dev, NULL);
885 #ifdef CONFIG_CFG80211_WEXT
886 memset(&wrqu, 0, sizeof(wrqu));
887 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
888 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
889 wdev->wext.connect.ssid_len = 0;
892 schedule_work(&cfg80211_disconnect_work);
895 void cfg80211_disconnected(struct net_device *dev, u16 reason,
896 const u8 *ie, size_t ie_len, gfp_t gfp)
898 struct wireless_dev *wdev = dev->ieee80211_ptr;
899 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
900 struct cfg80211_event *ev;
903 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
907 ev->type = EVENT_DISCONNECTED;
908 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
909 ev->dc.ie_len = ie_len;
910 memcpy((void *)ev->dc.ie, ie, ie_len);
911 ev->dc.reason = reason;
913 spin_lock_irqsave(&wdev->event_lock, flags);
914 list_add_tail(&ev->list, &wdev->event_list);
915 spin_unlock_irqrestore(&wdev->event_lock, flags);
916 queue_work(cfg80211_wq, &rdev->event_work);
918 EXPORT_SYMBOL(cfg80211_disconnected);
921 * API calls for nl80211/wext compatibility code
923 int cfg80211_connect(struct cfg80211_registered_device *rdev,
924 struct net_device *dev,
925 struct cfg80211_connect_params *connect,
926 struct cfg80211_cached_keys *connkeys,
927 const u8 *prev_bssid)
929 struct wireless_dev *wdev = dev->ieee80211_ptr;
932 ASSERT_WDEV_LOCK(wdev);
934 if (WARN_ON(wdev->connect_keys)) {
935 kfree(wdev->connect_keys);
936 wdev->connect_keys = NULL;
939 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
940 rdev->wiphy.ht_capa_mod_mask);
942 if (connkeys && connkeys->def >= 0) {
947 cipher = connkeys->params[idx].cipher;
948 /* If given a WEP key we may need it for shared key auth */
949 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
950 cipher == WLAN_CIPHER_SUITE_WEP104) {
951 connect->key_idx = idx;
952 connect->key = connkeys->params[idx].key;
953 connect->key_len = connkeys->params[idx].key_len;
956 * If ciphers are not set (e.g. when going through
957 * iwconfig), we have to set them appropriately here.
959 if (connect->crypto.cipher_group == 0)
960 connect->crypto.cipher_group = cipher;
962 if (connect->crypto.n_ciphers_pairwise == 0) {
963 connect->crypto.n_ciphers_pairwise = 1;
964 connect->crypto.ciphers_pairwise[0] = cipher;
969 wdev->connect_keys = connkeys;
970 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
971 wdev->ssid_len = connect->ssid_len;
973 if (!rdev->ops->connect)
974 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
976 err = rdev_connect(rdev, dev, connect);
979 wdev->connect_keys = NULL;
987 int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
988 struct net_device *dev, u16 reason, bool wextev)
990 struct wireless_dev *wdev = dev->ieee80211_ptr;
993 ASSERT_WDEV_LOCK(wdev);
995 kfree(wdev->connect_keys);
996 wdev->connect_keys = NULL;
999 err = cfg80211_sme_disconnect(wdev, reason);
1000 else if (!rdev->ops->disconnect)
1001 cfg80211_mlme_down(rdev, dev);
1002 else if (wdev->current_bss)
1003 err = rdev_disconnect(rdev, dev, reason);