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_rdev(wdev->wiphy);
63 struct cfg80211_scan_request *request;
67 ASSERT_WDEV_LOCK(wdev);
69 if (rdev->scan_req || rdev->scan_msg)
72 if (wdev->conn->params.channel)
75 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
77 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
78 sizeof(request->channels[0]) * n_channels,
83 if (wdev->conn->params.channel) {
84 enum nl80211_band band = wdev->conn->params.channel->band;
85 struct ieee80211_supported_band *sband =
86 wdev->wiphy->bands[band];
92 request->channels[0] = wdev->conn->params.channel;
93 request->rates[band] = (1 << sband->n_bitrates) - 1;
96 enum nl80211_band band;
97 struct ieee80211_supported_band *bands;
98 struct ieee80211_channel *channel;
100 for (band = 0; band < NUM_NL80211_BANDS; band++) {
101 bands = wdev->wiphy->bands[band];
104 for (j = 0; j < bands->n_channels; j++) {
105 channel = &bands->channels[j];
106 if (channel->flags & IEEE80211_CHAN_DISABLED)
108 request->channels[i++] = channel;
110 request->rates[band] = (1 << bands->n_bitrates) - 1;
114 request->n_channels = n_channels;
115 request->ssids = (void *)&request->channels[n_channels];
116 request->n_ssids = 1;
118 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
119 wdev->conn->params.ssid_len);
120 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
122 eth_broadcast_addr(request->bssid);
124 request->wdev = wdev;
125 request->wiphy = &rdev->wiphy;
126 request->scan_start = jiffies;
128 rdev->scan_req = request;
130 err = rdev_scan(rdev, request);
132 wdev->conn->state = CFG80211_CONN_SCANNING;
133 nl80211_send_scan_start(rdev, wdev);
134 dev_hold(wdev->netdev);
136 rdev->scan_req = NULL;
142 static int cfg80211_conn_do_work(struct wireless_dev *wdev)
144 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
145 struct cfg80211_connect_params *params;
146 struct cfg80211_assoc_request req = {};
149 ASSERT_WDEV_LOCK(wdev);
154 params = &wdev->conn->params;
156 switch (wdev->conn->state) {
157 case CFG80211_CONN_SCANNING:
158 /* didn't find it during scan ... */
160 case CFG80211_CONN_SCAN_AGAIN:
161 return cfg80211_conn_scan(wdev);
162 case CFG80211_CONN_AUTHENTICATE_NEXT:
163 if (WARN_ON(!rdev->ops->auth))
165 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
166 return cfg80211_mlme_auth(rdev, wdev->netdev,
167 params->channel, params->auth_type,
169 params->ssid, params->ssid_len,
171 params->key, params->key_len,
172 params->key_idx, NULL, 0);
173 case CFG80211_CONN_AUTH_FAILED:
175 case CFG80211_CONN_ASSOCIATE_NEXT:
176 if (WARN_ON(!rdev->ops->assoc))
178 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
179 if (wdev->conn->prev_bssid_valid)
180 req.prev_bssid = wdev->conn->prev_bssid;
182 req.ie_len = params->ie_len;
183 req.use_mfp = params->mfp != NL80211_MFP_NO;
184 req.crypto = params->crypto;
185 req.flags = params->flags;
186 req.ht_capa = params->ht_capa;
187 req.ht_capa_mask = params->ht_capa_mask;
188 req.vht_capa = params->vht_capa;
189 req.vht_capa_mask = params->vht_capa_mask;
191 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
192 params->bssid, params->ssid,
193 params->ssid_len, &req);
195 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
197 WLAN_REASON_DEAUTH_LEAVING,
200 case CFG80211_CONN_ASSOC_FAILED:
201 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
203 WLAN_REASON_DEAUTH_LEAVING, false);
205 case CFG80211_CONN_DEAUTH:
206 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
208 WLAN_REASON_DEAUTH_LEAVING, false);
209 /* free directly, disconnected event already sent */
210 cfg80211_sme_free(wdev);
217 void cfg80211_conn_work(struct work_struct *work)
219 struct cfg80211_registered_device *rdev =
220 container_of(work, struct cfg80211_registered_device, conn_work);
221 struct wireless_dev *wdev;
222 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
226 list_for_each_entry(wdev, &rdev->wdev_list, list) {
231 if (!netif_running(wdev->netdev)) {
236 wdev->conn->state == CFG80211_CONN_CONNECTED) {
240 if (wdev->conn->params.bssid) {
241 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
244 if (cfg80211_conn_do_work(wdev)) {
245 __cfg80211_connect_result(
248 WLAN_STATUS_UNSPECIFIED_FAILURE,
257 /* Returned bss is reference counted and must be cleaned up appropriately. */
258 static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
260 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
261 struct cfg80211_bss *bss;
263 ASSERT_WDEV_LOCK(wdev);
265 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
266 wdev->conn->params.bssid,
267 wdev->conn->params.ssid,
268 wdev->conn->params.ssid_len,
270 IEEE80211_PRIVACY(wdev->conn->params.privacy));
274 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
275 wdev->conn->params.bssid = wdev->conn->bssid;
276 wdev->conn->params.channel = bss->channel;
277 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
278 schedule_work(&rdev->conn_work);
283 static void __cfg80211_sme_scan_done(struct net_device *dev)
285 struct wireless_dev *wdev = dev->ieee80211_ptr;
286 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
287 struct cfg80211_bss *bss;
289 ASSERT_WDEV_LOCK(wdev);
294 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
295 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
298 bss = cfg80211_get_conn_bss(wdev);
300 cfg80211_put_bss(&rdev->wiphy, bss);
302 schedule_work(&rdev->conn_work);
305 void cfg80211_sme_scan_done(struct net_device *dev)
307 struct wireless_dev *wdev = dev->ieee80211_ptr;
310 __cfg80211_sme_scan_done(dev);
314 void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
316 struct wiphy *wiphy = wdev->wiphy;
317 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
318 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
319 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
321 ASSERT_WDEV_LOCK(wdev);
323 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
326 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
327 wdev->conn->auto_auth &&
328 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
329 /* select automatically between only open, shared, leap */
330 switch (wdev->conn->params.auth_type) {
331 case NL80211_AUTHTYPE_OPEN_SYSTEM:
332 if (wdev->connect_keys)
333 wdev->conn->params.auth_type =
334 NL80211_AUTHTYPE_SHARED_KEY;
336 wdev->conn->params.auth_type =
337 NL80211_AUTHTYPE_NETWORK_EAP;
339 case NL80211_AUTHTYPE_SHARED_KEY:
340 wdev->conn->params.auth_type =
341 NL80211_AUTHTYPE_NETWORK_EAP;
345 wdev->conn->params.auth_type =
346 NL80211_AUTHTYPE_OPEN_SYSTEM;
349 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
350 schedule_work(&rdev->conn_work);
351 } else if (status_code != WLAN_STATUS_SUCCESS) {
352 __cfg80211_connect_result(wdev->netdev, mgmt->bssid,
354 status_code, false, NULL);
355 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
356 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
357 schedule_work(&rdev->conn_work);
361 bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
363 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
368 if (status == WLAN_STATUS_SUCCESS) {
369 wdev->conn->state = CFG80211_CONN_CONNECTED;
373 if (wdev->conn->prev_bssid_valid) {
375 * Some stupid APs don't accept reassoc, so we
376 * need to fall back to trying regular assoc;
377 * return true so no event is sent to userspace.
379 wdev->conn->prev_bssid_valid = false;
380 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
381 schedule_work(&rdev->conn_work);
385 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
386 schedule_work(&rdev->conn_work);
390 void cfg80211_sme_deauth(struct wireless_dev *wdev)
392 cfg80211_sme_free(wdev);
395 void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
397 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
402 wdev->conn->state = CFG80211_CONN_AUTH_FAILED;
403 schedule_work(&rdev->conn_work);
406 void cfg80211_sme_disassoc(struct wireless_dev *wdev)
408 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
413 wdev->conn->state = CFG80211_CONN_DEAUTH;
414 schedule_work(&rdev->conn_work);
417 void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
424 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
425 schedule_work(&rdev->conn_work);
428 static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev,
429 const u8 *ies, size_t ies_len,
430 const u8 **out_ies, size_t *out_ies_len)
432 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
436 if (!rdev->wiphy.extended_capabilities_len ||
437 (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) {
438 *out_ies = kmemdup(ies, ies_len, GFP_KERNEL);
441 *out_ies_len = ies_len;
445 buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2,
451 static const u8 before_extcapa[] = {
452 /* not listing IEs expected to be created by driver */
455 WLAN_EID_RRM_ENABLED_CAPABILITIES,
456 WLAN_EID_MOBILITY_DOMAIN,
457 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
458 WLAN_EID_BSS_COEX_2040,
461 offs = ieee80211_ie_split(ies, ies_len, before_extcapa,
462 ARRAY_SIZE(before_extcapa), 0);
463 memcpy(buf, ies, offs);
464 /* leave a whole for extended capabilities IE */
465 memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2,
466 ies + offs, ies_len - offs);
471 /* place extended capabilities IE (with only driver capabilities) */
472 buf[offs] = WLAN_EID_EXT_CAPABILITY;
473 buf[offs + 1] = rdev->wiphy.extended_capabilities_len;
474 memcpy(buf + offs + 2,
475 rdev->wiphy.extended_capabilities,
476 rdev->wiphy.extended_capabilities_len);
479 *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2;
484 static int cfg80211_sme_connect(struct wireless_dev *wdev,
485 struct cfg80211_connect_params *connect,
486 const u8 *prev_bssid)
488 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
489 struct cfg80211_bss *bss;
492 if (!rdev->ops->auth || !rdev->ops->assoc)
495 if (wdev->current_bss) {
499 !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid))
501 cfg80211_unhold_bss(wdev->current_bss);
502 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
503 wdev->current_bss = NULL;
505 cfg80211_sme_free(wdev);
508 if (WARN_ON(wdev->conn))
511 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
516 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
518 memcpy(&wdev->conn->params, connect, sizeof(*connect));
519 if (connect->bssid) {
520 wdev->conn->params.bssid = wdev->conn->bssid;
521 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
524 if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len,
526 &wdev->conn->params.ie_len)) {
531 wdev->conn->params.ie = wdev->conn->ie;
533 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
534 wdev->conn->auto_auth = true;
535 /* start with open system ... should mostly work */
536 wdev->conn->params.auth_type =
537 NL80211_AUTHTYPE_OPEN_SYSTEM;
539 wdev->conn->auto_auth = false;
542 wdev->conn->params.ssid = wdev->ssid;
543 wdev->conn->params.ssid_len = wdev->ssid_len;
545 /* see if we have the bss already */
546 bss = cfg80211_get_conn_bss(wdev);
549 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
550 wdev->conn->prev_bssid_valid = true;
553 /* we're good if we have a matching bss struct */
555 err = cfg80211_conn_do_work(wdev);
556 cfg80211_put_bss(wdev->wiphy, bss);
558 /* otherwise we'll need to scan for the AP first */
559 err = cfg80211_conn_scan(wdev);
562 * If we can't scan right now, then we need to scan again
563 * after the current scan finished, since the parameters
564 * changed (unless we find a good AP anyway).
568 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
573 cfg80211_sme_free(wdev);
578 static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
580 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
586 if (!rdev->ops->deauth)
589 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
590 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
595 /* wdev->conn->params.bssid must be set if > SCANNING */
596 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
597 wdev->conn->params.bssid,
598 NULL, 0, reason, false);
600 cfg80211_sme_free(wdev);
605 * code shared for in-device and software SME
608 static bool cfg80211_is_all_idle(void)
610 struct cfg80211_registered_device *rdev;
611 struct wireless_dev *wdev;
612 bool is_all_idle = true;
615 * All devices must be idle as otherwise if you are actively
616 * scanning some new beacon hints could be learned and would
617 * count as new regulatory hints.
619 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
620 list_for_each_entry(wdev, &rdev->wdev_list, list) {
622 if (wdev->conn || wdev->current_bss)
631 static void disconnect_work(struct work_struct *work)
634 if (cfg80211_is_all_idle())
635 regulatory_hint_disconnect();
639 static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
643 * API calls for drivers implementing connect/disconnect and
647 /* This method must consume bss one way or another */
648 void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
649 const u8 *req_ie, size_t req_ie_len,
650 const u8 *resp_ie, size_t resp_ie_len,
651 u16 status, bool wextev,
652 struct cfg80211_bss *bss)
654 struct wireless_dev *wdev = dev->ieee80211_ptr;
655 const u8 *country_ie;
656 #ifdef CONFIG_CFG80211_WEXT
657 union iwreq_data wrqu;
660 ASSERT_WDEV_LOCK(wdev);
662 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
663 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
664 cfg80211_put_bss(wdev->wiphy, bss);
668 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev,
669 bssid, req_ie, req_ie_len,
670 resp_ie, resp_ie_len,
673 #ifdef CONFIG_CFG80211_WEXT
675 if (req_ie && status == WLAN_STATUS_SUCCESS) {
676 memset(&wrqu, 0, sizeof(wrqu));
677 wrqu.data.length = req_ie_len;
678 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
681 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
682 memset(&wrqu, 0, sizeof(wrqu));
683 wrqu.data.length = resp_ie_len;
684 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
687 memset(&wrqu, 0, sizeof(wrqu));
688 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
689 if (bssid && status == WLAN_STATUS_SUCCESS) {
690 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
691 memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN);
692 wdev->wext.prev_bssid_valid = true;
694 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
698 if (!bss && (status == WLAN_STATUS_SUCCESS)) {
699 WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect);
700 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
701 wdev->ssid, wdev->ssid_len,
703 IEEE80211_PRIVACY_ANY);
705 cfg80211_hold_bss(bss_from_pub(bss));
708 if (wdev->current_bss) {
709 cfg80211_unhold_bss(wdev->current_bss);
710 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
711 wdev->current_bss = NULL;
714 if (status != WLAN_STATUS_SUCCESS) {
715 kzfree(wdev->connect_keys);
716 wdev->connect_keys = NULL;
719 cfg80211_unhold_bss(bss_from_pub(bss));
720 cfg80211_put_bss(wdev->wiphy, bss);
722 cfg80211_sme_free(wdev);
729 wdev->current_bss = bss_from_pub(bss);
731 cfg80211_upload_connect_keys(wdev);
734 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
740 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
747 * ieee80211_bss_get_ie() ensures we can access:
748 * - country_ie + 2, the start of the country ie data, and
749 * - and country_ie[1] which is the IE length
751 regulatory_hint_country_ie(wdev->wiphy, bss->channel->band,
752 country_ie + 2, country_ie[1]);
756 void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
757 const u8 *req_ie, size_t req_ie_len,
758 const u8 *resp_ie, size_t resp_ie_len,
759 u16 status, gfp_t gfp)
761 struct wireless_dev *wdev = dev->ieee80211_ptr;
762 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
763 struct cfg80211_event *ev;
766 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
770 ev->type = EVENT_CONNECT_RESULT;
772 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
774 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
775 ev->cr.req_ie_len = req_ie_len;
776 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
779 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
780 ev->cr.resp_ie_len = resp_ie_len;
781 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
783 ev->cr.status = status;
785 spin_lock_irqsave(&wdev->event_lock, flags);
786 list_add_tail(&ev->list, &wdev->event_list);
787 spin_unlock_irqrestore(&wdev->event_lock, flags);
788 queue_work(cfg80211_wq, &rdev->event_work);
790 EXPORT_SYMBOL(cfg80211_connect_result);
792 /* Consumes bss object one way or another */
793 void __cfg80211_roamed(struct wireless_dev *wdev,
794 struct cfg80211_bss *bss,
795 const u8 *req_ie, size_t req_ie_len,
796 const u8 *resp_ie, size_t resp_ie_len)
798 #ifdef CONFIG_CFG80211_WEXT
799 union iwreq_data wrqu;
801 ASSERT_WDEV_LOCK(wdev);
803 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
804 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
807 if (WARN_ON(!wdev->current_bss))
810 cfg80211_unhold_bss(wdev->current_bss);
811 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
812 wdev->current_bss = NULL;
814 cfg80211_hold_bss(bss_from_pub(bss));
815 wdev->current_bss = bss_from_pub(bss);
817 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
818 wdev->netdev, bss->bssid,
819 req_ie, req_ie_len, resp_ie, resp_ie_len,
822 #ifdef CONFIG_CFG80211_WEXT
824 memset(&wrqu, 0, sizeof(wrqu));
825 wrqu.data.length = req_ie_len;
826 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
831 memset(&wrqu, 0, sizeof(wrqu));
832 wrqu.data.length = resp_ie_len;
833 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
837 memset(&wrqu, 0, sizeof(wrqu));
838 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
839 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
840 memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN);
841 wdev->wext.prev_bssid_valid = true;
842 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
847 cfg80211_put_bss(wdev->wiphy, bss);
850 void cfg80211_roamed(struct net_device *dev,
851 struct ieee80211_channel *channel,
853 const u8 *req_ie, size_t req_ie_len,
854 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
856 struct wireless_dev *wdev = dev->ieee80211_ptr;
857 struct cfg80211_bss *bss;
859 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
861 wdev->conn_bss_type, IEEE80211_PRIVACY_ANY);
865 cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie,
868 EXPORT_SYMBOL(cfg80211_roamed);
870 /* Consumes bss object one way or another */
871 void cfg80211_roamed_bss(struct net_device *dev,
872 struct cfg80211_bss *bss, const u8 *req_ie,
873 size_t req_ie_len, const u8 *resp_ie,
874 size_t resp_ie_len, gfp_t gfp)
876 struct wireless_dev *wdev = dev->ieee80211_ptr;
877 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
878 struct cfg80211_event *ev;
884 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
886 cfg80211_put_bss(wdev->wiphy, bss);
890 ev->type = EVENT_ROAMED;
891 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
892 ev->rm.req_ie_len = req_ie_len;
893 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
894 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
895 ev->rm.resp_ie_len = resp_ie_len;
896 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
899 spin_lock_irqsave(&wdev->event_lock, flags);
900 list_add_tail(&ev->list, &wdev->event_list);
901 spin_unlock_irqrestore(&wdev->event_lock, flags);
902 queue_work(cfg80211_wq, &rdev->event_work);
904 EXPORT_SYMBOL(cfg80211_roamed_bss);
906 void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
907 size_t ie_len, u16 reason, bool from_ap)
909 struct wireless_dev *wdev = dev->ieee80211_ptr;
910 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
912 #ifdef CONFIG_CFG80211_WEXT
913 union iwreq_data wrqu;
916 ASSERT_WDEV_LOCK(wdev);
918 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
919 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
922 if (wdev->current_bss) {
923 cfg80211_unhold_bss(wdev->current_bss);
924 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
927 wdev->current_bss = NULL;
930 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
932 /* stop critical protocol if supported */
933 if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) {
934 rdev->crit_proto_nlportid = 0;
935 rdev_crit_proto_stop(rdev, wdev);
939 * Delete all the keys ... pairwise keys can't really
940 * exist any more anyway, but default keys might.
942 if (rdev->ops->del_key)
943 for (i = 0; i < 6; i++)
944 rdev_del_key(rdev, dev, i, false, NULL);
946 rdev_set_qos_map(rdev, dev, NULL);
948 #ifdef CONFIG_CFG80211_WEXT
949 memset(&wrqu, 0, sizeof(wrqu));
950 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
951 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
952 wdev->wext.connect.ssid_len = 0;
955 schedule_work(&cfg80211_disconnect_work);
958 void cfg80211_disconnected(struct net_device *dev, u16 reason,
959 const u8 *ie, size_t ie_len,
960 bool locally_generated, gfp_t gfp)
962 struct wireless_dev *wdev = dev->ieee80211_ptr;
963 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
964 struct cfg80211_event *ev;
967 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
971 ev->type = EVENT_DISCONNECTED;
972 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
973 ev->dc.ie_len = ie_len;
974 memcpy((void *)ev->dc.ie, ie, ie_len);
975 ev->dc.reason = reason;
976 ev->dc.locally_generated = locally_generated;
978 spin_lock_irqsave(&wdev->event_lock, flags);
979 list_add_tail(&ev->list, &wdev->event_list);
980 spin_unlock_irqrestore(&wdev->event_lock, flags);
981 queue_work(cfg80211_wq, &rdev->event_work);
983 EXPORT_SYMBOL(cfg80211_disconnected);
986 * API calls for nl80211/wext compatibility code
988 int cfg80211_connect(struct cfg80211_registered_device *rdev,
989 struct net_device *dev,
990 struct cfg80211_connect_params *connect,
991 struct cfg80211_cached_keys *connkeys,
992 const u8 *prev_bssid)
994 struct wireless_dev *wdev = dev->ieee80211_ptr;
997 ASSERT_WDEV_LOCK(wdev);
999 if (WARN_ON(wdev->connect_keys)) {
1000 kzfree(wdev->connect_keys);
1001 wdev->connect_keys = NULL;
1004 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
1005 rdev->wiphy.ht_capa_mod_mask);
1007 if (connkeys && connkeys->def >= 0) {
1011 idx = connkeys->def;
1012 cipher = connkeys->params[idx].cipher;
1013 /* If given a WEP key we may need it for shared key auth */
1014 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
1015 cipher == WLAN_CIPHER_SUITE_WEP104) {
1016 connect->key_idx = idx;
1017 connect->key = connkeys->params[idx].key;
1018 connect->key_len = connkeys->params[idx].key_len;
1021 * If ciphers are not set (e.g. when going through
1022 * iwconfig), we have to set them appropriately here.
1024 if (connect->crypto.cipher_group == 0)
1025 connect->crypto.cipher_group = cipher;
1027 if (connect->crypto.n_ciphers_pairwise == 0) {
1028 connect->crypto.n_ciphers_pairwise = 1;
1029 connect->crypto.ciphers_pairwise[0] = cipher;
1034 wdev->connect_keys = connkeys;
1035 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
1036 wdev->ssid_len = connect->ssid_len;
1038 wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS :
1039 IEEE80211_BSS_TYPE_ESS;
1041 if (!rdev->ops->connect)
1042 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
1044 err = rdev_connect(rdev, dev, connect);
1047 wdev->connect_keys = NULL;
1055 int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
1056 struct net_device *dev, u16 reason, bool wextev)
1058 struct wireless_dev *wdev = dev->ieee80211_ptr;
1061 ASSERT_WDEV_LOCK(wdev);
1063 kzfree(wdev->connect_keys);
1064 wdev->connect_keys = NULL;
1067 err = cfg80211_sme_disconnect(wdev, reason);
1068 else if (!rdev->ops->disconnect)
1069 cfg80211_mlme_down(rdev, dev);
1070 else if (wdev->current_bss)
1071 err = rdev_disconnect(rdev, dev, reason);