1 // SPDX-License-Identifier: GPL-2.0
3 * SME code for cfg80211
4 * both driver SME event handling and the SME implementation
5 * (for nl80211's connect() and wext)
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
8 * Copyright (C) 2009, 2020, 2022-2023 Intel Corporation. All rights reserved.
9 * Copyright 2017 Intel Deutschland GmbH
12 #include <linux/etherdevice.h>
13 #include <linux/if_arp.h>
14 #include <linux/slab.h>
15 #include <linux/workqueue.h>
16 #include <linux/wireless.h>
17 #include <linux/export.h>
18 #include <net/iw_handler.h>
19 #include <net/cfg80211.h>
20 #include <net/rtnetlink.h>
26 * Software SME in cfg80211, using auth/assoc/deauth calls to the
27 * driver. This is for implementing nl80211's connect/disconnect
28 * and wireless extensions (if configured.)
31 struct cfg80211_conn {
32 struct cfg80211_connect_params params;
33 /* these are sub-states of the _CONNECTING sme_state */
35 CFG80211_CONN_SCANNING,
36 CFG80211_CONN_SCAN_AGAIN,
37 CFG80211_CONN_AUTHENTICATE_NEXT,
38 CFG80211_CONN_AUTHENTICATING,
39 CFG80211_CONN_AUTH_FAILED_TIMEOUT,
40 CFG80211_CONN_ASSOCIATE_NEXT,
41 CFG80211_CONN_ASSOCIATING,
42 CFG80211_CONN_ASSOC_FAILED,
43 CFG80211_CONN_ASSOC_FAILED_TIMEOUT,
45 CFG80211_CONN_ABANDON,
46 CFG80211_CONN_CONNECTED,
48 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
51 bool auto_auth, prev_bssid_valid;
54 static void cfg80211_sme_free(struct wireless_dev *wdev)
59 kfree(wdev->conn->ie);
64 static int cfg80211_conn_scan(struct wireless_dev *wdev)
66 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
67 struct cfg80211_scan_request *request;
70 ASSERT_WDEV_LOCK(wdev);
72 if (rdev->scan_req || rdev->scan_msg)
75 if (wdev->conn->params.channel)
78 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
80 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
81 sizeof(request->channels[0]) * n_channels,
86 if (wdev->conn->params.channel) {
87 enum nl80211_band band = wdev->conn->params.channel->band;
88 struct ieee80211_supported_band *sband =
89 wdev->wiphy->bands[band];
95 request->channels[0] = wdev->conn->params.channel;
96 request->rates[band] = (1 << sband->n_bitrates) - 1;
99 enum nl80211_band band;
100 struct ieee80211_supported_band *bands;
101 struct ieee80211_channel *channel;
103 for (band = 0; band < NUM_NL80211_BANDS; band++) {
104 bands = wdev->wiphy->bands[band];
107 for (j = 0; j < bands->n_channels; j++) {
108 channel = &bands->channels[j];
109 if (channel->flags & IEEE80211_CHAN_DISABLED)
111 request->channels[i++] = channel;
113 request->rates[band] = (1 << bands->n_bitrates) - 1;
117 request->n_channels = n_channels;
118 request->ssids = (void *)&request->channels[n_channels];
119 request->n_ssids = 1;
121 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
122 wdev->conn->params.ssid_len);
123 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
125 eth_broadcast_addr(request->bssid);
127 request->wdev = wdev;
128 request->wiphy = &rdev->wiphy;
129 request->scan_start = jiffies;
131 rdev->scan_req = request;
133 err = rdev_scan(rdev, request);
135 wdev->conn->state = CFG80211_CONN_SCANNING;
136 nl80211_send_scan_start(rdev, wdev);
137 dev_hold(wdev->netdev);
139 rdev->scan_req = NULL;
145 static int cfg80211_conn_do_work(struct wireless_dev *wdev,
146 enum nl80211_timeout_reason *treason)
148 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
149 struct cfg80211_connect_params *params;
150 struct cfg80211_auth_request auth_req = {};
151 struct cfg80211_assoc_request req = {};
154 ASSERT_WDEV_LOCK(wdev);
159 params = &wdev->conn->params;
161 switch (wdev->conn->state) {
162 case CFG80211_CONN_SCANNING:
163 /* didn't find it during scan ... */
165 case CFG80211_CONN_SCAN_AGAIN:
166 return cfg80211_conn_scan(wdev);
167 case CFG80211_CONN_AUTHENTICATE_NEXT:
168 if (WARN_ON(!rdev->ops->auth))
170 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
171 auth_req.key = params->key;
172 auth_req.key_len = params->key_len;
173 auth_req.key_idx = params->key_idx;
174 auth_req.auth_type = params->auth_type;
175 auth_req.bss = cfg80211_get_bss(&rdev->wiphy, params->channel,
177 params->ssid, params->ssid_len,
178 IEEE80211_BSS_TYPE_ESS,
179 IEEE80211_PRIVACY_ANY);
180 auth_req.link_id = -1;
181 err = cfg80211_mlme_auth(rdev, wdev->netdev, &auth_req);
182 cfg80211_put_bss(&rdev->wiphy, auth_req.bss);
184 case CFG80211_CONN_AUTH_FAILED_TIMEOUT:
185 *treason = NL80211_TIMEOUT_AUTH;
187 case CFG80211_CONN_ASSOCIATE_NEXT:
188 if (WARN_ON(!rdev->ops->assoc))
190 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
191 if (wdev->conn->prev_bssid_valid)
192 req.prev_bssid = wdev->conn->prev_bssid;
194 req.ie_len = params->ie_len;
195 req.use_mfp = params->mfp != NL80211_MFP_NO;
196 req.crypto = params->crypto;
197 req.flags = params->flags;
198 req.ht_capa = params->ht_capa;
199 req.ht_capa_mask = params->ht_capa_mask;
200 req.vht_capa = params->vht_capa;
201 req.vht_capa_mask = params->vht_capa_mask;
204 req.bss = cfg80211_get_bss(&rdev->wiphy, params->channel,
206 params->ssid, params->ssid_len,
207 IEEE80211_BSS_TYPE_ESS,
208 IEEE80211_PRIVACY_ANY);
212 err = cfg80211_mlme_assoc(rdev, wdev->netdev, &req);
213 cfg80211_put_bss(&rdev->wiphy, req.bss);
217 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
219 WLAN_REASON_DEAUTH_LEAVING,
222 case CFG80211_CONN_ASSOC_FAILED_TIMEOUT:
223 *treason = NL80211_TIMEOUT_ASSOC;
225 case CFG80211_CONN_ASSOC_FAILED:
226 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
228 WLAN_REASON_DEAUTH_LEAVING, false);
230 case CFG80211_CONN_DEAUTH:
231 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
233 WLAN_REASON_DEAUTH_LEAVING, false);
235 case CFG80211_CONN_ABANDON:
236 /* free directly, disconnected event already sent */
237 cfg80211_sme_free(wdev);
244 void cfg80211_conn_work(struct work_struct *work)
246 struct cfg80211_registered_device *rdev =
247 container_of(work, struct cfg80211_registered_device, conn_work);
248 struct wireless_dev *wdev;
249 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
250 enum nl80211_timeout_reason treason;
252 wiphy_lock(&rdev->wiphy);
254 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
259 if (!netif_running(wdev->netdev)) {
264 wdev->conn->state == CFG80211_CONN_CONNECTED) {
268 if (wdev->conn->params.bssid) {
269 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
272 treason = NL80211_TIMEOUT_UNSPECIFIED;
273 if (cfg80211_conn_do_work(wdev, &treason)) {
274 struct cfg80211_connect_resp_params cr;
276 memset(&cr, 0, sizeof(cr));
278 cr.links[0].bssid = bssid;
279 cr.timeout_reason = treason;
280 __cfg80211_connect_result(wdev->netdev, &cr, false);
285 wiphy_unlock(&rdev->wiphy);
288 static void cfg80211_step_auth_next(struct cfg80211_conn *conn,
289 struct cfg80211_bss *bss)
291 memcpy(conn->bssid, bss->bssid, ETH_ALEN);
292 conn->params.bssid = conn->bssid;
293 conn->params.channel = bss->channel;
294 conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
297 /* Returned bss is reference counted and must be cleaned up appropriately. */
298 static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
300 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
301 struct cfg80211_bss *bss;
303 ASSERT_WDEV_LOCK(wdev);
305 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
306 wdev->conn->params.bssid,
307 wdev->conn->params.ssid,
308 wdev->conn->params.ssid_len,
310 IEEE80211_PRIVACY(wdev->conn->params.privacy));
314 cfg80211_step_auth_next(wdev->conn, bss);
315 schedule_work(&rdev->conn_work);
320 static void __cfg80211_sme_scan_done(struct net_device *dev)
322 struct wireless_dev *wdev = dev->ieee80211_ptr;
323 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
324 struct cfg80211_bss *bss;
326 ASSERT_WDEV_LOCK(wdev);
331 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
332 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
335 bss = cfg80211_get_conn_bss(wdev);
337 cfg80211_put_bss(&rdev->wiphy, bss);
339 schedule_work(&rdev->conn_work);
342 void cfg80211_sme_scan_done(struct net_device *dev)
344 struct wireless_dev *wdev = dev->ieee80211_ptr;
347 __cfg80211_sme_scan_done(dev);
351 void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
353 struct wiphy *wiphy = wdev->wiphy;
354 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
355 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
356 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
358 ASSERT_WDEV_LOCK(wdev);
360 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
363 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
364 wdev->conn->auto_auth &&
365 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
366 /* select automatically between only open, shared, leap */
367 switch (wdev->conn->params.auth_type) {
368 case NL80211_AUTHTYPE_OPEN_SYSTEM:
369 if (wdev->connect_keys)
370 wdev->conn->params.auth_type =
371 NL80211_AUTHTYPE_SHARED_KEY;
373 wdev->conn->params.auth_type =
374 NL80211_AUTHTYPE_NETWORK_EAP;
376 case NL80211_AUTHTYPE_SHARED_KEY:
377 wdev->conn->params.auth_type =
378 NL80211_AUTHTYPE_NETWORK_EAP;
382 wdev->conn->params.auth_type =
383 NL80211_AUTHTYPE_OPEN_SYSTEM;
386 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
387 schedule_work(&rdev->conn_work);
388 } else if (status_code != WLAN_STATUS_SUCCESS) {
389 struct cfg80211_connect_resp_params cr;
391 memset(&cr, 0, sizeof(cr));
392 cr.status = status_code;
393 cr.links[0].bssid = mgmt->bssid;
394 cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED;
395 __cfg80211_connect_result(wdev->netdev, &cr, false);
396 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
397 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
398 schedule_work(&rdev->conn_work);
402 bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
404 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
409 if (status == WLAN_STATUS_SUCCESS) {
410 wdev->conn->state = CFG80211_CONN_CONNECTED;
414 if (wdev->conn->prev_bssid_valid) {
416 * Some stupid APs don't accept reassoc, so we
417 * need to fall back to trying regular assoc;
418 * return true so no event is sent to userspace.
420 wdev->conn->prev_bssid_valid = false;
421 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
422 schedule_work(&rdev->conn_work);
426 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
427 schedule_work(&rdev->conn_work);
431 void cfg80211_sme_deauth(struct wireless_dev *wdev)
433 cfg80211_sme_free(wdev);
436 void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
438 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
443 wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT;
444 schedule_work(&rdev->conn_work);
447 void cfg80211_sme_disassoc(struct wireless_dev *wdev)
449 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
454 wdev->conn->state = CFG80211_CONN_DEAUTH;
455 schedule_work(&rdev->conn_work);
458 void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
460 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
465 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT;
466 schedule_work(&rdev->conn_work);
469 void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev)
471 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
476 wdev->conn->state = CFG80211_CONN_ABANDON;
477 schedule_work(&rdev->conn_work);
480 static void cfg80211_wdev_release_bsses(struct wireless_dev *wdev)
484 for_each_valid_link(wdev, link) {
485 if (!wdev->links[link].client.current_bss)
487 cfg80211_unhold_bss(wdev->links[link].client.current_bss);
488 cfg80211_put_bss(wdev->wiphy,
489 &wdev->links[link].client.current_bss->pub);
490 wdev->links[link].client.current_bss = NULL;
494 void cfg80211_wdev_release_link_bsses(struct wireless_dev *wdev, u16 link_mask)
498 for_each_valid_link(wdev, link) {
499 if (!wdev->links[link].client.current_bss ||
500 !(link_mask & BIT(link)))
502 cfg80211_unhold_bss(wdev->links[link].client.current_bss);
503 cfg80211_put_bss(wdev->wiphy,
504 &wdev->links[link].client.current_bss->pub);
505 wdev->links[link].client.current_bss = NULL;
509 static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev,
510 const u8 *ies, size_t ies_len,
511 const u8 **out_ies, size_t *out_ies_len)
513 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
517 if (!rdev->wiphy.extended_capabilities_len ||
518 (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) {
519 *out_ies = kmemdup(ies, ies_len, GFP_KERNEL);
522 *out_ies_len = ies_len;
526 buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2,
532 static const u8 before_extcapa[] = {
533 /* not listing IEs expected to be created by driver */
536 WLAN_EID_RRM_ENABLED_CAPABILITIES,
537 WLAN_EID_MOBILITY_DOMAIN,
538 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
539 WLAN_EID_BSS_COEX_2040,
542 offs = ieee80211_ie_split(ies, ies_len, before_extcapa,
543 ARRAY_SIZE(before_extcapa), 0);
544 memcpy(buf, ies, offs);
545 /* leave a whole for extended capabilities IE */
546 memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2,
547 ies + offs, ies_len - offs);
552 /* place extended capabilities IE (with only driver capabilities) */
553 buf[offs] = WLAN_EID_EXT_CAPABILITY;
554 buf[offs + 1] = rdev->wiphy.extended_capabilities_len;
555 memcpy(buf + offs + 2,
556 rdev->wiphy.extended_capabilities,
557 rdev->wiphy.extended_capabilities_len);
560 *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2;
565 static int cfg80211_sme_connect(struct wireless_dev *wdev,
566 struct cfg80211_connect_params *connect,
567 const u8 *prev_bssid)
569 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
570 struct cfg80211_bss *bss;
573 if (!rdev->ops->auth || !rdev->ops->assoc)
576 cfg80211_wdev_release_bsses(wdev);
578 if (wdev->connected) {
579 cfg80211_sme_free(wdev);
580 wdev->connected = false;
586 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
591 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
593 memcpy(&wdev->conn->params, connect, sizeof(*connect));
594 if (connect->bssid) {
595 wdev->conn->params.bssid = wdev->conn->bssid;
596 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
599 if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len,
601 &wdev->conn->params.ie_len)) {
606 wdev->conn->params.ie = wdev->conn->ie;
608 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
609 wdev->conn->auto_auth = true;
610 /* start with open system ... should mostly work */
611 wdev->conn->params.auth_type =
612 NL80211_AUTHTYPE_OPEN_SYSTEM;
614 wdev->conn->auto_auth = false;
617 wdev->conn->params.ssid = wdev->u.client.ssid;
618 wdev->conn->params.ssid_len = wdev->u.client.ssid_len;
620 /* see if we have the bss already */
621 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
622 wdev->conn->params.bssid,
623 wdev->conn->params.ssid,
624 wdev->conn->params.ssid_len,
626 IEEE80211_PRIVACY(wdev->conn->params.privacy));
629 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
630 wdev->conn->prev_bssid_valid = true;
633 /* we're good if we have a matching bss struct */
635 enum nl80211_timeout_reason treason;
637 cfg80211_step_auth_next(wdev->conn, bss);
638 err = cfg80211_conn_do_work(wdev, &treason);
639 cfg80211_put_bss(wdev->wiphy, bss);
641 /* otherwise we'll need to scan for the AP first */
642 err = cfg80211_conn_scan(wdev);
645 * If we can't scan right now, then we need to scan again
646 * after the current scan finished, since the parameters
647 * changed (unless we find a good AP anyway).
651 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
656 cfg80211_sme_free(wdev);
661 static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
663 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
669 if (!rdev->ops->deauth)
672 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
673 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
678 /* wdev->conn->params.bssid must be set if > SCANNING */
679 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
680 wdev->conn->params.bssid,
681 NULL, 0, reason, false);
683 cfg80211_sme_free(wdev);
688 * code shared for in-device and software SME
691 static bool cfg80211_is_all_idle(void)
693 struct cfg80211_registered_device *rdev;
694 struct wireless_dev *wdev;
695 bool is_all_idle = true;
698 * All devices must be idle as otherwise if you are actively
699 * scanning some new beacon hints could be learned and would
700 * count as new regulatory hints.
701 * Also if there is any other active beaconing interface we
702 * need not issue a disconnect hint and reset any info such
703 * as chan dfs state, etc.
705 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
706 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
708 if (wdev->conn || wdev->connected ||
709 cfg80211_beaconing_iface_active(wdev))
718 static void disconnect_work(struct work_struct *work)
721 if (cfg80211_is_all_idle())
722 regulatory_hint_disconnect();
726 DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
729 cfg80211_connect_result_release_bsses(struct wireless_dev *wdev,
730 struct cfg80211_connect_resp_params *cr)
734 for_each_valid_link(cr, link) {
735 if (!cr->links[link].bss)
737 cfg80211_unhold_bss(bss_from_pub(cr->links[link].bss));
738 cfg80211_put_bss(wdev->wiphy, cr->links[link].bss);
743 * API calls for drivers implementing connect/disconnect and
747 /* This method must consume bss one way or another */
748 void __cfg80211_connect_result(struct net_device *dev,
749 struct cfg80211_connect_resp_params *cr,
752 struct wireless_dev *wdev = dev->ieee80211_ptr;
753 const struct element *country_elem = NULL;
754 const struct element *ssid;
755 const u8 *country_data;
757 #ifdef CONFIG_CFG80211_WEXT
758 union iwreq_data wrqu;
761 const u8 *connected_addr;
762 bool bss_not_found = false;
764 ASSERT_WDEV_LOCK(wdev);
766 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
767 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
770 if (cr->valid_links) {
771 if (WARN_ON(!cr->ap_mld_addr))
774 for_each_valid_link(cr, link) {
775 if (WARN_ON(!cr->links[link].addr))
779 if (WARN_ON(wdev->connect_keys))
783 wdev->unprot_beacon_reported = 0;
784 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, cr,
786 connected_addr = cr->valid_links ? cr->ap_mld_addr : cr->links[0].bssid;
788 #ifdef CONFIG_CFG80211_WEXT
789 if (wextev && !cr->valid_links) {
790 if (cr->req_ie && cr->status == WLAN_STATUS_SUCCESS) {
791 memset(&wrqu, 0, sizeof(wrqu));
792 wrqu.data.length = cr->req_ie_len;
793 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu,
797 if (cr->resp_ie && cr->status == WLAN_STATUS_SUCCESS) {
798 memset(&wrqu, 0, sizeof(wrqu));
799 wrqu.data.length = cr->resp_ie_len;
800 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu,
804 memset(&wrqu, 0, sizeof(wrqu));
805 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
806 if (connected_addr && cr->status == WLAN_STATUS_SUCCESS) {
807 memcpy(wrqu.ap_addr.sa_data, connected_addr, ETH_ALEN);
808 memcpy(wdev->wext.prev_bssid, connected_addr, ETH_ALEN);
809 wdev->wext.prev_bssid_valid = true;
811 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
815 if (cr->status == WLAN_STATUS_SUCCESS) {
816 if (!wiphy_to_rdev(wdev->wiphy)->ops->connect) {
817 for_each_valid_link(cr, link) {
818 if (WARN_ON_ONCE(!cr->links[link].bss))
823 for_each_valid_link(cr, link) {
824 /* don't do extra lookups for failures */
825 if (cr->links[link].status != WLAN_STATUS_SUCCESS)
828 if (cr->links[link].bss)
831 cr->links[link].bss =
832 cfg80211_get_bss(wdev->wiphy, NULL,
833 cr->links[link].bssid,
835 wdev->u.client.ssid_len,
837 IEEE80211_PRIVACY_ANY);
838 if (!cr->links[link].bss) {
839 bss_not_found = true;
842 cfg80211_hold_bss(bss_from_pub(cr->links[link].bss));
846 cfg80211_wdev_release_bsses(wdev);
848 if (cr->status != WLAN_STATUS_SUCCESS) {
849 kfree_sensitive(wdev->connect_keys);
850 wdev->connect_keys = NULL;
851 wdev->u.client.ssid_len = 0;
852 wdev->conn_owner_nlportid = 0;
853 cfg80211_connect_result_release_bsses(wdev, cr);
854 cfg80211_sme_free(wdev);
858 if (WARN_ON(bss_not_found)) {
859 cfg80211_connect_result_release_bsses(wdev, cr);
863 memset(wdev->links, 0, sizeof(wdev->links));
864 for_each_valid_link(cr, link) {
865 if (cr->links[link].status == WLAN_STATUS_SUCCESS)
867 cr->valid_links &= ~BIT(link);
868 /* don't require bss pointer for failed links */
869 if (!cr->links[link].bss)
871 cfg80211_unhold_bss(bss_from_pub(cr->links[link].bss));
872 cfg80211_put_bss(wdev->wiphy, cr->links[link].bss);
874 wdev->valid_links = cr->valid_links;
875 for_each_valid_link(cr, link)
876 wdev->links[link].client.current_bss =
877 bss_from_pub(cr->links[link].bss);
878 wdev->connected = true;
879 ether_addr_copy(wdev->u.client.connected_addr, connected_addr);
880 if (cr->valid_links) {
881 for_each_valid_link(cr, link)
882 memcpy(wdev->links[link].addr, cr->links[link].addr,
886 cfg80211_upload_connect_keys(wdev);
889 for_each_valid_link(cr, link) {
891 ieee80211_bss_get_elem(cr->links[link].bss,
901 country_datalen = country_elem->datalen;
902 country_data = kmemdup(country_elem->data, country_datalen, GFP_ATOMIC);
908 regulatory_hint_country_ie(wdev->wiphy,
909 cr->links[link].bss->channel->band,
910 country_data, country_datalen);
913 if (!wdev->u.client.ssid_len) {
915 for_each_valid_link(cr, link) {
916 ssid = ieee80211_bss_get_elem(cr->links[link].bss,
919 if (!ssid || !ssid->datalen)
922 memcpy(wdev->u.client.ssid, ssid->data, ssid->datalen);
923 wdev->u.client.ssid_len = ssid->datalen;
931 for_each_valid_link(cr, link)
932 cfg80211_put_bss(wdev->wiphy, cr->links[link].bss);
935 static void cfg80211_update_link_bss(struct wireless_dev *wdev,
936 struct cfg80211_bss **bss)
938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
939 struct cfg80211_internal_bss *ibss;
944 ibss = bss_from_pub(*bss);
945 if (list_empty(&ibss->list)) {
946 struct cfg80211_bss *found = NULL, *tmp = *bss;
948 found = cfg80211_get_bss(wdev->wiphy, NULL,
951 wdev->u.client.ssid_len,
953 IEEE80211_PRIVACY_ANY);
955 /* The same BSS is already updated so use it
956 * instead, as it has latest info.
960 /* Update with BSS provided by driver, it will
961 * be freshly added and ref cnted, we can free
964 * signal_valid can be false, as we are not
965 * expecting the BSS to be found.
967 * keep the old timestamp to avoid confusion
969 cfg80211_bss_update(rdev, ibss, false,
973 cfg80211_put_bss(wdev->wiphy, tmp);
977 /* Consumes bss object(s) one way or another */
978 void cfg80211_connect_done(struct net_device *dev,
979 struct cfg80211_connect_resp_params *params,
982 struct wireless_dev *wdev = dev->ieee80211_ptr;
983 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
984 struct cfg80211_event *ev;
987 size_t link_info_size = 0;
990 for_each_valid_link(params, link) {
991 cfg80211_update_link_bss(wdev, ¶ms->links[link].bss);
992 link_info_size += params->links[link].bssid ? ETH_ALEN : 0;
993 link_info_size += params->links[link].addr ? ETH_ALEN : 0;
996 ev = kzalloc(sizeof(*ev) + (params->ap_mld_addr ? ETH_ALEN : 0) +
997 params->req_ie_len + params->resp_ie_len +
998 params->fils.kek_len + params->fils.pmk_len +
999 (params->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size,
1003 for_each_valid_link(params, link)
1004 cfg80211_put_bss(wdev->wiphy,
1005 params->links[link].bss);
1009 ev->type = EVENT_CONNECT_RESULT;
1010 next = ((u8 *)ev) + sizeof(*ev);
1011 if (params->ap_mld_addr) {
1012 ev->cr.ap_mld_addr = next;
1013 memcpy((void *)ev->cr.ap_mld_addr, params->ap_mld_addr,
1017 if (params->req_ie_len) {
1018 ev->cr.req_ie = next;
1019 ev->cr.req_ie_len = params->req_ie_len;
1020 memcpy((void *)ev->cr.req_ie, params->req_ie,
1021 params->req_ie_len);
1022 next += params->req_ie_len;
1024 if (params->resp_ie_len) {
1025 ev->cr.resp_ie = next;
1026 ev->cr.resp_ie_len = params->resp_ie_len;
1027 memcpy((void *)ev->cr.resp_ie, params->resp_ie,
1028 params->resp_ie_len);
1029 next += params->resp_ie_len;
1031 if (params->fils.kek_len) {
1032 ev->cr.fils.kek = next;
1033 ev->cr.fils.kek_len = params->fils.kek_len;
1034 memcpy((void *)ev->cr.fils.kek, params->fils.kek,
1035 params->fils.kek_len);
1036 next += params->fils.kek_len;
1038 if (params->fils.pmk_len) {
1039 ev->cr.fils.pmk = next;
1040 ev->cr.fils.pmk_len = params->fils.pmk_len;
1041 memcpy((void *)ev->cr.fils.pmk, params->fils.pmk,
1042 params->fils.pmk_len);
1043 next += params->fils.pmk_len;
1045 if (params->fils.pmkid) {
1046 ev->cr.fils.pmkid = next;
1047 memcpy((void *)ev->cr.fils.pmkid, params->fils.pmkid,
1049 next += WLAN_PMKID_LEN;
1051 ev->cr.fils.update_erp_next_seq_num = params->fils.update_erp_next_seq_num;
1052 if (params->fils.update_erp_next_seq_num)
1053 ev->cr.fils.erp_next_seq_num = params->fils.erp_next_seq_num;
1054 ev->cr.valid_links = params->valid_links;
1055 for_each_valid_link(params, link) {
1056 if (params->links[link].bss)
1058 bss_from_pub(params->links[link].bss));
1059 ev->cr.links[link].bss = params->links[link].bss;
1061 if (params->links[link].addr) {
1062 ev->cr.links[link].addr = next;
1063 memcpy((void *)ev->cr.links[link].addr,
1064 params->links[link].addr,
1068 if (params->links[link].bssid) {
1069 ev->cr.links[link].bssid = next;
1070 memcpy((void *)ev->cr.links[link].bssid,
1071 params->links[link].bssid,
1076 ev->cr.status = params->status;
1077 ev->cr.timeout_reason = params->timeout_reason;
1079 spin_lock_irqsave(&wdev->event_lock, flags);
1080 list_add_tail(&ev->list, &wdev->event_list);
1081 spin_unlock_irqrestore(&wdev->event_lock, flags);
1082 queue_work(cfg80211_wq, &rdev->event_work);
1084 EXPORT_SYMBOL(cfg80211_connect_done);
1086 /* Consumes bss object one way or another */
1087 void __cfg80211_roamed(struct wireless_dev *wdev,
1088 struct cfg80211_roam_info *info)
1090 #ifdef CONFIG_CFG80211_WEXT
1091 union iwreq_data wrqu;
1094 const u8 *connected_addr;
1096 ASSERT_WDEV_LOCK(wdev);
1098 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
1099 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
1102 if (WARN_ON(!wdev->connected))
1105 if (info->valid_links) {
1106 if (WARN_ON(!info->ap_mld_addr))
1109 for_each_valid_link(info, link) {
1110 if (WARN_ON(!info->links[link].addr))
1115 cfg80211_wdev_release_bsses(wdev);
1117 for_each_valid_link(info, link) {
1118 if (WARN_ON(!info->links[link].bss))
1122 memset(wdev->links, 0, sizeof(wdev->links));
1123 wdev->valid_links = info->valid_links;
1124 for_each_valid_link(info, link) {
1125 cfg80211_hold_bss(bss_from_pub(info->links[link].bss));
1126 wdev->links[link].client.current_bss =
1127 bss_from_pub(info->links[link].bss);
1130 connected_addr = info->valid_links ?
1132 info->links[0].bss->bssid;
1133 ether_addr_copy(wdev->u.client.connected_addr, connected_addr);
1134 if (info->valid_links) {
1135 for_each_valid_link(info, link)
1136 memcpy(wdev->links[link].addr, info->links[link].addr,
1139 wdev->unprot_beacon_reported = 0;
1140 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
1141 wdev->netdev, info, GFP_KERNEL);
1143 #ifdef CONFIG_CFG80211_WEXT
1144 if (!info->valid_links) {
1146 memset(&wrqu, 0, sizeof(wrqu));
1147 wrqu.data.length = info->req_ie_len;
1148 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
1149 &wrqu, info->req_ie);
1152 if (info->resp_ie) {
1153 memset(&wrqu, 0, sizeof(wrqu));
1154 wrqu.data.length = info->resp_ie_len;
1155 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
1156 &wrqu, info->resp_ie);
1159 memset(&wrqu, 0, sizeof(wrqu));
1160 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1161 memcpy(wrqu.ap_addr.sa_data, connected_addr, ETH_ALEN);
1162 memcpy(wdev->wext.prev_bssid, connected_addr, ETH_ALEN);
1163 wdev->wext.prev_bssid_valid = true;
1164 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
1170 for_each_valid_link(info, link)
1171 cfg80211_put_bss(wdev->wiphy, info->links[link].bss);
1174 /* Consumes info->links.bss object(s) one way or another */
1175 void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info,
1178 struct wireless_dev *wdev = dev->ieee80211_ptr;
1179 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1180 struct cfg80211_event *ev;
1181 unsigned long flags;
1184 size_t link_info_size = 0;
1185 bool bss_not_found = false;
1187 for_each_valid_link(info, link) {
1188 link_info_size += info->links[link].addr ? ETH_ALEN : 0;
1189 link_info_size += info->links[link].bssid ? ETH_ALEN : 0;
1191 if (info->links[link].bss)
1194 info->links[link].bss =
1195 cfg80211_get_bss(wdev->wiphy,
1196 info->links[link].channel,
1197 info->links[link].bssid,
1198 wdev->u.client.ssid,
1199 wdev->u.client.ssid_len,
1200 wdev->conn_bss_type,
1201 IEEE80211_PRIVACY_ANY);
1203 if (!info->links[link].bss) {
1204 bss_not_found = true;
1209 if (WARN_ON(bss_not_found))
1212 ev = kzalloc(sizeof(*ev) + info->req_ie_len + info->resp_ie_len +
1213 info->fils.kek_len + info->fils.pmk_len +
1214 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) +
1215 (info->ap_mld_addr ? ETH_ALEN : 0) + link_info_size, gfp);
1219 ev->type = EVENT_ROAMED;
1220 next = ((u8 *)ev) + sizeof(*ev);
1221 if (info->req_ie_len) {
1222 ev->rm.req_ie = next;
1223 ev->rm.req_ie_len = info->req_ie_len;
1224 memcpy((void *)ev->rm.req_ie, info->req_ie, info->req_ie_len);
1225 next += info->req_ie_len;
1227 if (info->resp_ie_len) {
1228 ev->rm.resp_ie = next;
1229 ev->rm.resp_ie_len = info->resp_ie_len;
1230 memcpy((void *)ev->rm.resp_ie, info->resp_ie,
1232 next += info->resp_ie_len;
1234 if (info->fils.kek_len) {
1235 ev->rm.fils.kek = next;
1236 ev->rm.fils.kek_len = info->fils.kek_len;
1237 memcpy((void *)ev->rm.fils.kek, info->fils.kek,
1238 info->fils.kek_len);
1239 next += info->fils.kek_len;
1241 if (info->fils.pmk_len) {
1242 ev->rm.fils.pmk = next;
1243 ev->rm.fils.pmk_len = info->fils.pmk_len;
1244 memcpy((void *)ev->rm.fils.pmk, info->fils.pmk,
1245 info->fils.pmk_len);
1246 next += info->fils.pmk_len;
1248 if (info->fils.pmkid) {
1249 ev->rm.fils.pmkid = next;
1250 memcpy((void *)ev->rm.fils.pmkid, info->fils.pmkid,
1252 next += WLAN_PMKID_LEN;
1254 ev->rm.fils.update_erp_next_seq_num = info->fils.update_erp_next_seq_num;
1255 if (info->fils.update_erp_next_seq_num)
1256 ev->rm.fils.erp_next_seq_num = info->fils.erp_next_seq_num;
1257 if (info->ap_mld_addr) {
1258 ev->rm.ap_mld_addr = next;
1259 memcpy((void *)ev->rm.ap_mld_addr, info->ap_mld_addr,
1263 ev->rm.valid_links = info->valid_links;
1264 for_each_valid_link(info, link) {
1265 ev->rm.links[link].bss = info->links[link].bss;
1267 if (info->links[link].addr) {
1268 ev->rm.links[link].addr = next;
1269 memcpy((void *)ev->rm.links[link].addr,
1270 info->links[link].addr,
1275 if (info->links[link].bssid) {
1276 ev->rm.links[link].bssid = next;
1277 memcpy((void *)ev->rm.links[link].bssid,
1278 info->links[link].bssid,
1284 spin_lock_irqsave(&wdev->event_lock, flags);
1285 list_add_tail(&ev->list, &wdev->event_list);
1286 spin_unlock_irqrestore(&wdev->event_lock, flags);
1287 queue_work(cfg80211_wq, &rdev->event_work);
1291 for_each_valid_link(info, link)
1292 cfg80211_put_bss(wdev->wiphy, info->links[link].bss);
1295 EXPORT_SYMBOL(cfg80211_roamed);
1297 void __cfg80211_port_authorized(struct wireless_dev *wdev, const u8 *bssid,
1298 const u8 *td_bitmap, u8 td_bitmap_len)
1300 ASSERT_WDEV_LOCK(wdev);
1302 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
1303 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
1306 if (WARN_ON(!wdev->connected) ||
1307 WARN_ON(!ether_addr_equal(wdev->u.client.connected_addr, bssid)))
1310 nl80211_send_port_authorized(wiphy_to_rdev(wdev->wiphy), wdev->netdev,
1311 bssid, td_bitmap, td_bitmap_len);
1314 void cfg80211_port_authorized(struct net_device *dev, const u8 *bssid,
1315 const u8 *td_bitmap, u8 td_bitmap_len, gfp_t gfp)
1317 struct wireless_dev *wdev = dev->ieee80211_ptr;
1318 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1319 struct cfg80211_event *ev;
1320 unsigned long flags;
1322 if (WARN_ON(!bssid))
1325 ev = kzalloc(sizeof(*ev) + td_bitmap_len, gfp);
1329 ev->type = EVENT_PORT_AUTHORIZED;
1330 memcpy(ev->pa.bssid, bssid, ETH_ALEN);
1331 ev->pa.td_bitmap = ((u8 *)ev) + sizeof(*ev);
1332 ev->pa.td_bitmap_len = td_bitmap_len;
1333 memcpy((void *)ev->pa.td_bitmap, td_bitmap, td_bitmap_len);
1336 * Use the wdev event list so that if there are pending
1337 * connected/roamed events, they will be reported first.
1339 spin_lock_irqsave(&wdev->event_lock, flags);
1340 list_add_tail(&ev->list, &wdev->event_list);
1341 spin_unlock_irqrestore(&wdev->event_lock, flags);
1342 queue_work(cfg80211_wq, &rdev->event_work);
1344 EXPORT_SYMBOL(cfg80211_port_authorized);
1346 void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
1347 size_t ie_len, u16 reason, bool from_ap)
1349 struct wireless_dev *wdev = dev->ieee80211_ptr;
1350 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1352 #ifdef CONFIG_CFG80211_WEXT
1353 union iwreq_data wrqu;
1356 ASSERT_WDEV_LOCK(wdev);
1358 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
1359 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
1362 cfg80211_wdev_release_bsses(wdev);
1363 wdev->connected = false;
1364 wdev->u.client.ssid_len = 0;
1365 wdev->conn_owner_nlportid = 0;
1366 kfree_sensitive(wdev->connect_keys);
1367 wdev->connect_keys = NULL;
1369 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
1371 /* stop critical protocol if supported */
1372 if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) {
1373 rdev->crit_proto_nlportid = 0;
1374 rdev_crit_proto_stop(rdev, wdev);
1378 * Delete all the keys ... pairwise keys can't really
1379 * exist any more anyway, but default keys might.
1381 if (rdev->ops->del_key) {
1382 int max_key_idx = 5;
1384 if (wiphy_ext_feature_isset(
1386 NL80211_EXT_FEATURE_BEACON_PROTECTION) ||
1387 wiphy_ext_feature_isset(
1389 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
1391 for (i = 0; i <= max_key_idx; i++)
1392 rdev_del_key(rdev, dev, -1, i, false, NULL);
1395 rdev_set_qos_map(rdev, dev, NULL);
1397 #ifdef CONFIG_CFG80211_WEXT
1398 memset(&wrqu, 0, sizeof(wrqu));
1399 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1400 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1401 wdev->wext.connect.ssid_len = 0;
1404 schedule_work(&cfg80211_disconnect_work);
1407 void cfg80211_disconnected(struct net_device *dev, u16 reason,
1408 const u8 *ie, size_t ie_len,
1409 bool locally_generated, gfp_t gfp)
1411 struct wireless_dev *wdev = dev->ieee80211_ptr;
1412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1413 struct cfg80211_event *ev;
1414 unsigned long flags;
1416 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
1420 ev->type = EVENT_DISCONNECTED;
1421 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
1422 ev->dc.ie_len = ie_len;
1423 memcpy((void *)ev->dc.ie, ie, ie_len);
1424 ev->dc.reason = reason;
1425 ev->dc.locally_generated = locally_generated;
1427 spin_lock_irqsave(&wdev->event_lock, flags);
1428 list_add_tail(&ev->list, &wdev->event_list);
1429 spin_unlock_irqrestore(&wdev->event_lock, flags);
1430 queue_work(cfg80211_wq, &rdev->event_work);
1432 EXPORT_SYMBOL(cfg80211_disconnected);
1435 * API calls for nl80211/wext compatibility code
1437 int cfg80211_connect(struct cfg80211_registered_device *rdev,
1438 struct net_device *dev,
1439 struct cfg80211_connect_params *connect,
1440 struct cfg80211_cached_keys *connkeys,
1441 const u8 *prev_bssid)
1443 struct wireless_dev *wdev = dev->ieee80211_ptr;
1446 ASSERT_WDEV_LOCK(wdev);
1449 * If we have an ssid_len, we're trying to connect or are
1450 * already connected, so reject a new SSID unless it's the
1451 * same (which is the case for re-association.)
1453 if (wdev->u.client.ssid_len &&
1454 (wdev->u.client.ssid_len != connect->ssid_len ||
1455 memcmp(wdev->u.client.ssid, connect->ssid, wdev->u.client.ssid_len)))
1459 * If connected, reject (re-)association unless prev_bssid
1460 * matches the current BSSID.
1462 if (wdev->connected) {
1465 if (!ether_addr_equal(prev_bssid,
1466 wdev->u.client.connected_addr))
1471 * Reject if we're in the process of connecting with WEP,
1472 * this case isn't very interesting and trying to handle
1473 * it would make the code much more complex.
1475 if (wdev->connect_keys)
1476 return -EINPROGRESS;
1478 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
1479 rdev->wiphy.ht_capa_mod_mask);
1480 cfg80211_oper_and_vht_capa(&connect->vht_capa_mask,
1481 rdev->wiphy.vht_capa_mod_mask);
1483 if (connkeys && connkeys->def >= 0) {
1487 idx = connkeys->def;
1488 cipher = connkeys->params[idx].cipher;
1489 /* If given a WEP key we may need it for shared key auth */
1490 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
1491 cipher == WLAN_CIPHER_SUITE_WEP104) {
1492 connect->key_idx = idx;
1493 connect->key = connkeys->params[idx].key;
1494 connect->key_len = connkeys->params[idx].key_len;
1497 * If ciphers are not set (e.g. when going through
1498 * iwconfig), we have to set them appropriately here.
1500 if (connect->crypto.cipher_group == 0)
1501 connect->crypto.cipher_group = cipher;
1503 if (connect->crypto.n_ciphers_pairwise == 0) {
1504 connect->crypto.n_ciphers_pairwise = 1;
1505 connect->crypto.ciphers_pairwise[0] = cipher;
1509 if (WARN_ON(connkeys))
1512 /* connect can point to wdev->wext.connect which
1513 * can hold key data from a previous connection
1515 connect->key = NULL;
1516 connect->key_len = 0;
1517 connect->key_idx = 0;
1520 wdev->connect_keys = connkeys;
1521 memcpy(wdev->u.client.ssid, connect->ssid, connect->ssid_len);
1522 wdev->u.client.ssid_len = connect->ssid_len;
1524 wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS :
1525 IEEE80211_BSS_TYPE_ESS;
1527 if (!rdev->ops->connect)
1528 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
1530 err = rdev_connect(rdev, dev, connect);
1533 wdev->connect_keys = NULL;
1535 * This could be reassoc getting refused, don't clear
1536 * ssid_len in that case.
1538 if (!wdev->connected)
1539 wdev->u.client.ssid_len = 0;
1546 int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
1547 struct net_device *dev, u16 reason, bool wextev)
1549 struct wireless_dev *wdev = dev->ieee80211_ptr;
1552 ASSERT_WDEV_LOCK(wdev);
1554 kfree_sensitive(wdev->connect_keys);
1555 wdev->connect_keys = NULL;
1557 wdev->conn_owner_nlportid = 0;
1560 err = cfg80211_sme_disconnect(wdev, reason);
1561 else if (!rdev->ops->disconnect)
1562 cfg80211_mlme_down(rdev, dev);
1563 else if (wdev->u.client.ssid_len)
1564 err = rdev_disconnect(rdev, dev, reason);
1567 * Clear ssid_len unless we actually were fully connected,
1568 * in which case cfg80211_disconnected() will take care of
1571 if (!wdev->connected)
1572 wdev->u.client.ssid_len = 0;
1578 * Used to clean up after the connection / connection attempt owner socket
1581 void cfg80211_autodisconnect_wk(struct work_struct *work)
1583 struct wireless_dev *wdev =
1584 container_of(work, struct wireless_dev, disconnect_wk);
1585 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1587 wiphy_lock(wdev->wiphy);
1590 if (wdev->conn_owner_nlportid) {
1591 switch (wdev->iftype) {
1592 case NL80211_IFTYPE_ADHOC:
1593 __cfg80211_leave_ibss(rdev, wdev->netdev, false);
1595 case NL80211_IFTYPE_AP:
1596 case NL80211_IFTYPE_P2P_GO:
1597 __cfg80211_stop_ap(rdev, wdev->netdev, -1, false);
1599 case NL80211_IFTYPE_MESH_POINT:
1600 __cfg80211_leave_mesh(rdev, wdev->netdev);
1602 case NL80211_IFTYPE_STATION:
1603 case NL80211_IFTYPE_P2P_CLIENT:
1605 * Use disconnect_bssid if still connecting and
1606 * ops->disconnect not implemented. Otherwise we can
1607 * use cfg80211_disconnect.
1609 if (rdev->ops->disconnect || wdev->connected)
1610 cfg80211_disconnect(rdev, wdev->netdev,
1611 WLAN_REASON_DEAUTH_LEAVING,
1614 cfg80211_mlme_deauth(rdev, wdev->netdev,
1615 wdev->disconnect_bssid,
1617 WLAN_REASON_DEAUTH_LEAVING,
1626 wiphy_unlock(wdev->wiphy);