blob: b347e63d7aaa6814f524d3b080a005a88966d65d [file] [log] [blame]
Samuel Ortizb23aa672009-07-01 21:26:54 +02001/*
Johannes Bergceca7b72013-05-16 00:55:45 +02002 * SME code for cfg80211
3 * both driver SME event handling and the SME implementation
4 * (for nl80211's connect() and wext)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005 *
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (C) 2009 Intel Corporation. All rights reserved.
8 */
9
10#include <linux/etherdevice.h>
11#include <linux/if_arp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Samuel Ortizb23aa672009-07-01 21:26:54 +020013#include <linux/workqueue.h>
Johannes Berga9a11622009-07-27 12:01:53 +020014#include <linux/wireless.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040015#include <linux/export.h>
Johannes Berga9a11622009-07-27 12:01:53 +020016#include <net/iw_handler.h>
Samuel Ortizb23aa672009-07-01 21:26:54 +020017#include <net/cfg80211.h>
18#include <net/rtnetlink.h>
19#include "nl80211.h"
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -070020#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030021#include "rdev-ops.h"
Samuel Ortizb23aa672009-07-01 21:26:54 +020022
Johannes Bergceca7b72013-05-16 00:55:45 +020023/*
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.)
27 */
28
Johannes Berg6829c872009-07-02 09:13:27 +020029struct cfg80211_conn {
30 struct cfg80211_connect_params params;
31 /* these are sub-states of the _CONNECTING sme_state */
32 enum {
Johannes Berg6829c872009-07-02 09:13:27 +020033 CFG80211_CONN_SCANNING,
34 CFG80211_CONN_SCAN_AGAIN,
35 CFG80211_CONN_AUTHENTICATE_NEXT,
36 CFG80211_CONN_AUTHENTICATING,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020037 CFG80211_CONN_AUTH_FAILED_TIMEOUT,
Johannes Berg6829c872009-07-02 09:13:27 +020038 CFG80211_CONN_ASSOCIATE_NEXT,
39 CFG80211_CONN_ASSOCIATING,
Johannes Berg923a0e72013-06-28 11:38:54 +020040 CFG80211_CONN_ASSOC_FAILED,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020041 CFG80211_CONN_ASSOC_FAILED_TIMEOUT,
Johannes Bergceca7b72013-05-16 00:55:45 +020042 CFG80211_CONN_DEAUTH,
Johannes Berge6f462d2016-12-08 17:22:09 +010043 CFG80211_CONN_ABANDON,
Johannes Bergceca7b72013-05-16 00:55:45 +020044 CFG80211_CONN_CONNECTED,
Johannes Berg6829c872009-07-02 09:13:27 +020045 } state;
Johannes Bergf401a6f2009-08-07 14:51:05 +020046 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
Johannes Berg46b9d182015-03-31 16:09:13 +020047 const u8 *ie;
Johannes Berg6829c872009-07-02 09:13:27 +020048 size_t ie_len;
Johannes Bergf401a6f2009-08-07 14:51:05 +020049 bool auto_auth, prev_bssid_valid;
Johannes Berg6829c872009-07-02 09:13:27 +020050};
51
Johannes Bergceca7b72013-05-16 00:55:45 +020052static void cfg80211_sme_free(struct wireless_dev *wdev)
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050053{
Johannes Bergceca7b72013-05-16 00:55:45 +020054 if (!wdev->conn)
55 return;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050056
Johannes Bergceca7b72013-05-16 00:55:45 +020057 kfree(wdev->conn->ie);
58 kfree(wdev->conn);
59 wdev->conn = NULL;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050060}
61
Johannes Berg6829c872009-07-02 09:13:27 +020062static int cfg80211_conn_scan(struct wireless_dev *wdev)
63{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080064 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020065 struct cfg80211_scan_request *request;
66 int n_channels, err;
67
68 ASSERT_RTNL();
Johannes Berg667503d2009-07-07 03:56:11 +020069 ASSERT_WDEV_LOCK(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +020070
Johannes Bergf9d15d12014-01-22 11:14:19 +020071 if (rdev->scan_req || rdev->scan_msg)
Johannes Berg6829c872009-07-02 09:13:27 +020072 return -EBUSY;
73
Ilan Peerbdfbec22014-01-09 11:37:23 +020074 if (wdev->conn->params.channel)
Johannes Berg6829c872009-07-02 09:13:27 +020075 n_channels = 1;
Ilan Peerbdfbec22014-01-09 11:37:23 +020076 else
77 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020078
Johannes Berg6829c872009-07-02 09:13:27 +020079 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
80 sizeof(request->channels[0]) * n_channels,
81 GFP_KERNEL);
82 if (!request)
83 return -ENOMEM;
84
Karl Beldan2a84ee82014-10-07 11:42:18 +020085 if (wdev->conn->params.channel) {
Johannes Berg57fbcce2016-04-12 15:56:15 +020086 enum nl80211_band band = wdev->conn->params.channel->band;
Karl Beldan2a84ee82014-10-07 11:42:18 +020087 struct ieee80211_supported_band *sband =
88 wdev->wiphy->bands[band];
89
90 if (!sband) {
91 kfree(request);
92 return -EINVAL;
93 }
Johannes Berg6829c872009-07-02 09:13:27 +020094 request->channels[0] = wdev->conn->params.channel;
Karl Beldan2a84ee82014-10-07 11:42:18 +020095 request->rates[band] = (1 << sband->n_bitrates) - 1;
96 } else {
Johannes Berg6829c872009-07-02 09:13:27 +020097 int i = 0, j;
Johannes Berg57fbcce2016-04-12 15:56:15 +020098 enum nl80211_band band;
Rajkumar Manoharane3081502011-09-15 17:40:50 +053099 struct ieee80211_supported_band *bands;
100 struct ieee80211_channel *channel;
Johannes Berg6829c872009-07-02 09:13:27 +0200101
Johannes Berg57fbcce2016-04-12 15:56:15 +0200102 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530103 bands = wdev->wiphy->bands[band];
104 if (!bands)
Johannes Berg6829c872009-07-02 09:13:27 +0200105 continue;
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530106 for (j = 0; j < bands->n_channels; j++) {
107 channel = &bands->channels[j];
108 if (channel->flags & IEEE80211_CHAN_DISABLED)
109 continue;
110 request->channels[i++] = channel;
111 }
112 request->rates[band] = (1 << bands->n_bitrates) - 1;
Johannes Berg6829c872009-07-02 09:13:27 +0200113 }
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530114 n_channels = i;
Johannes Berg6829c872009-07-02 09:13:27 +0200115 }
116 request->n_channels = n_channels;
Johannes Berg5ba63532009-08-07 17:54:07 +0200117 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg6829c872009-07-02 09:13:27 +0200118 request->n_ssids = 1;
119
120 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
121 wdev->conn->params.ssid_len);
122 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
123
Jouni Malinen818965d2016-02-26 22:12:47 +0200124 eth_broadcast_addr(request->bssid);
125
Johannes Bergfd014282012-06-18 19:17:03 +0200126 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +0200127 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -0700128 request->scan_start = jiffies;
Johannes Berg6829c872009-07-02 09:13:27 +0200129
Johannes Berg79c97e92009-07-07 03:56:12 +0200130 rdev->scan_req = request;
Johannes Berg6829c872009-07-02 09:13:27 +0200131
Hila Gonene35e4d22012-06-27 17:19:42 +0300132 err = rdev_scan(rdev, request);
Johannes Berg6829c872009-07-02 09:13:27 +0200133 if (!err) {
134 wdev->conn->state = CFG80211_CONN_SCANNING;
Johannes Bergfd014282012-06-18 19:17:03 +0200135 nl80211_send_scan_start(rdev, wdev);
Johannes Berg463d0182009-07-14 00:33:35 +0200136 dev_hold(wdev->netdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200137 } else {
Johannes Berg79c97e92009-07-07 03:56:12 +0200138 rdev->scan_req = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200139 kfree(request);
140 }
141 return err;
142}
143
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200144static int cfg80211_conn_do_work(struct wireless_dev *wdev,
145 enum nl80211_timeout_reason *treason)
Johannes Berg6829c872009-07-02 09:13:27 +0200146{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800147 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200148 struct cfg80211_connect_params *params;
Johannes Bergf62fab72013-02-21 20:09:09 +0100149 struct cfg80211_assoc_request req = {};
Johannes Berg19957bb2009-07-02 17:20:43 +0200150 int err;
Johannes Berg6829c872009-07-02 09:13:27 +0200151
Johannes Berg667503d2009-07-07 03:56:11 +0200152 ASSERT_WDEV_LOCK(wdev);
153
Johannes Berg6829c872009-07-02 09:13:27 +0200154 if (!wdev->conn)
155 return 0;
156
Johannes Berg19957bb2009-07-02 17:20:43 +0200157 params = &wdev->conn->params;
158
Johannes Berg6829c872009-07-02 09:13:27 +0200159 switch (wdev->conn->state) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200160 case CFG80211_CONN_SCANNING:
161 /* didn't find it during scan ... */
162 return -ENOENT;
Johannes Berg6829c872009-07-02 09:13:27 +0200163 case CFG80211_CONN_SCAN_AGAIN:
164 return cfg80211_conn_scan(wdev);
165 case CFG80211_CONN_AUTHENTICATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200166 if (WARN_ON(!rdev->ops->auth))
167 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200168 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
Johannes Berg91bf9b22013-05-15 17:44:01 +0200169 return cfg80211_mlme_auth(rdev, wdev->netdev,
170 params->channel, params->auth_type,
171 params->bssid,
172 params->ssid, params->ssid_len,
173 NULL, 0,
174 params->key, params->key_len,
175 params->key_idx, NULL, 0);
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200176 case CFG80211_CONN_AUTH_FAILED_TIMEOUT:
177 *treason = NL80211_TIMEOUT_AUTH;
Johannes Berg923a0e72013-06-28 11:38:54 +0200178 return -ENOTCONN;
Johannes Berg6829c872009-07-02 09:13:27 +0200179 case CFG80211_CONN_ASSOCIATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200180 if (WARN_ON(!rdev->ops->assoc))
181 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200182 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200183 if (wdev->conn->prev_bssid_valid)
Johannes Bergf62fab72013-02-21 20:09:09 +0100184 req.prev_bssid = wdev->conn->prev_bssid;
185 req.ie = params->ie;
186 req.ie_len = params->ie_len;
187 req.use_mfp = params->mfp != NL80211_MFP_NO;
188 req.crypto = params->crypto;
189 req.flags = params->flags;
190 req.ht_capa = params->ht_capa;
191 req.ht_capa_mask = params->ht_capa_mask;
192 req.vht_capa = params->vht_capa;
193 req.vht_capa_mask = params->vht_capa_mask;
194
Johannes Berg91bf9b22013-05-15 17:44:01 +0200195 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
196 params->bssid, params->ssid,
197 params->ssid_len, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200198 if (err)
Johannes Berg91bf9b22013-05-15 17:44:01 +0200199 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
200 NULL, 0,
201 WLAN_REASON_DEAUTH_LEAVING,
202 false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200203 return err;
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200204 case CFG80211_CONN_ASSOC_FAILED_TIMEOUT:
205 *treason = NL80211_TIMEOUT_ASSOC;
206 /* fall through */
Johannes Berg923a0e72013-06-28 11:38:54 +0200207 case CFG80211_CONN_ASSOC_FAILED:
208 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
209 NULL, 0,
210 WLAN_REASON_DEAUTH_LEAVING, false);
211 return -ENOTCONN;
Johannes Bergceca7b72013-05-16 00:55:45 +0200212 case CFG80211_CONN_DEAUTH:
Johannes Berg91bf9b22013-05-15 17:44:01 +0200213 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
214 NULL, 0,
215 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berge6f462d2016-12-08 17:22:09 +0100216 /* fall through */
217 case CFG80211_CONN_ABANDON:
Johannes Berg923a0e72013-06-28 11:38:54 +0200218 /* free directly, disconnected event already sent */
219 cfg80211_sme_free(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200220 return 0;
Johannes Berg6829c872009-07-02 09:13:27 +0200221 default:
222 return 0;
223 }
224}
225
226void cfg80211_conn_work(struct work_struct *work)
227{
Johannes Berg79c97e92009-07-07 03:56:12 +0200228 struct cfg80211_registered_device *rdev =
Johannes Berg6829c872009-07-02 09:13:27 +0200229 container_of(work, struct cfg80211_registered_device, conn_work);
230 struct wireless_dev *wdev;
Johannes Berg7400f422009-10-31 07:40:37 +0100231 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200232 enum nl80211_timeout_reason treason;
Johannes Berg6829c872009-07-02 09:13:27 +0200233
234 rtnl_lock();
Johannes Berg6829c872009-07-02 09:13:27 +0200235
Johannes Berg53873f12016-05-03 16:52:04 +0300236 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergc8157972013-05-23 18:10:21 +0200237 if (!wdev->netdev)
238 continue;
239
Johannes Berg667503d2009-07-07 03:56:11 +0200240 wdev_lock(wdev);
241 if (!netif_running(wdev->netdev)) {
242 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200243 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200244 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200245 if (!wdev->conn ||
246 wdev->conn->state == CFG80211_CONN_CONNECTED) {
Johannes Berg667503d2009-07-07 03:56:11 +0200247 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200248 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200249 }
Johannes Berg7400f422009-10-31 07:40:37 +0100250 if (wdev->conn->params.bssid) {
251 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
252 bssid = bssid_buf;
253 }
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200254 treason = NL80211_TIMEOUT_UNSPECIFIED;
255 if (cfg80211_conn_do_work(wdev, &treason)) {
Johannes Berg667503d2009-07-07 03:56:11 +0200256 __cfg80211_connect_result(
Johannes Berg7d930bc2009-10-20 15:08:53 +0900257 wdev->netdev, bssid,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200258 NULL, 0, NULL, 0, -1, false, NULL,
259 treason);
Johannes Bergceca7b72013-05-16 00:55:45 +0200260 }
Johannes Berg667503d2009-07-07 03:56:11 +0200261 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200262 }
263
Johannes Berg6829c872009-07-02 09:13:27 +0200264 rtnl_unlock();
265}
266
Ben Greear0e3a39b2013-06-19 14:06:27 -0700267/* Returned bss is reference counted and must be cleaned up appropriately. */
Johannes Bergbbac31f2009-09-16 09:04:26 -0700268static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
Johannes Berg6829c872009-07-02 09:13:27 +0200269{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800270 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200271 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200272
Johannes Berg667503d2009-07-07 03:56:11 +0200273 ASSERT_WDEV_LOCK(wdev);
274
Jouni Malinened9d0102011-05-16 19:40:15 +0300275 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
276 wdev->conn->params.bssid,
Johannes Berg6829c872009-07-02 09:13:27 +0200277 wdev->conn->params.ssid,
278 wdev->conn->params.ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200279 wdev->conn_bss_type,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200280 IEEE80211_PRIVACY(wdev->conn->params.privacy));
Johannes Berg6829c872009-07-02 09:13:27 +0200281 if (!bss)
Johannes Bergbbac31f2009-09-16 09:04:26 -0700282 return NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200283
284 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
285 wdev->conn->params.bssid = wdev->conn->bssid;
286 wdev->conn->params.channel = bss->channel;
287 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
Johannes Berg79c97e92009-07-07 03:56:12 +0200288 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200289
Johannes Bergbbac31f2009-09-16 09:04:26 -0700290 return bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200291}
292
Johannes Berg667503d2009-07-07 03:56:11 +0200293static void __cfg80211_sme_scan_done(struct net_device *dev)
Johannes Berg6829c872009-07-02 09:13:27 +0200294{
295 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800296 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergbbac31f2009-09-16 09:04:26 -0700297 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200298
Johannes Berg667503d2009-07-07 03:56:11 +0200299 ASSERT_WDEV_LOCK(wdev);
300
Zhu Yid4b1a682009-07-16 17:34:14 +0800301 if (!wdev->conn)
Johannes Berg6829c872009-07-02 09:13:27 +0200302 return;
303
304 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
305 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
306 return;
307
Johannes Bergbbac31f2009-09-16 09:04:26 -0700308 bss = cfg80211_get_conn_bss(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200309 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100310 cfg80211_put_bss(&rdev->wiphy, bss);
Johannes Bergceca7b72013-05-16 00:55:45 +0200311 else
312 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200313}
314
Johannes Berg667503d2009-07-07 03:56:11 +0200315void cfg80211_sme_scan_done(struct net_device *dev)
316{
317 struct wireless_dev *wdev = dev->ieee80211_ptr;
318
319 wdev_lock(wdev);
320 __cfg80211_sme_scan_done(dev);
321 wdev_unlock(wdev);
322}
323
Johannes Bergceca7b72013-05-16 00:55:45 +0200324void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
Johannes Berg6829c872009-07-02 09:13:27 +0200325{
Johannes Berg6829c872009-07-02 09:13:27 +0200326 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800327 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200328 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
329 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
330
Johannes Berg667503d2009-07-07 03:56:11 +0200331 ASSERT_WDEV_LOCK(wdev);
332
Johannes Bergceca7b72013-05-16 00:55:45 +0200333 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
Johannes Berg6829c872009-07-02 09:13:27 +0200334 return;
335
336 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
337 wdev->conn->auto_auth &&
338 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
339 /* select automatically between only open, shared, leap */
340 switch (wdev->conn->params.auth_type) {
341 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Johannes Bergfffd0932009-07-08 14:22:54 +0200342 if (wdev->connect_keys)
343 wdev->conn->params.auth_type =
344 NL80211_AUTHTYPE_SHARED_KEY;
345 else
346 wdev->conn->params.auth_type =
347 NL80211_AUTHTYPE_NETWORK_EAP;
Johannes Berg6829c872009-07-02 09:13:27 +0200348 break;
349 case NL80211_AUTHTYPE_SHARED_KEY:
350 wdev->conn->params.auth_type =
351 NL80211_AUTHTYPE_NETWORK_EAP;
352 break;
353 default:
354 /* huh? */
355 wdev->conn->params.auth_type =
356 NL80211_AUTHTYPE_OPEN_SYSTEM;
357 break;
358 }
359 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
360 schedule_work(&rdev->conn_work);
Johannes Berg19957bb2009-07-02 17:20:43 +0200361 } else if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200362 __cfg80211_connect_result(wdev->netdev, mgmt->bssid,
363 NULL, 0, NULL, 0,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200364 status_code, false, NULL,
365 NL80211_TIMEOUT_UNSPECIFIED);
Johannes Bergceca7b72013-05-16 00:55:45 +0200366 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
Johannes Berg6829c872009-07-02 09:13:27 +0200367 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
368 schedule_work(&rdev->conn_work);
369 }
370}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200371
Johannes Bergceca7b72013-05-16 00:55:45 +0200372bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200373{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800374 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200375
Johannes Bergceca7b72013-05-16 00:55:45 +0200376 if (!wdev->conn)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200377 return false;
378
Johannes Bergceca7b72013-05-16 00:55:45 +0200379 if (status == WLAN_STATUS_SUCCESS) {
380 wdev->conn->state = CFG80211_CONN_CONNECTED;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200381 return false;
Johannes Bergceca7b72013-05-16 00:55:45 +0200382 }
383
384 if (wdev->conn->prev_bssid_valid) {
385 /*
386 * Some stupid APs don't accept reassoc, so we
387 * need to fall back to trying regular assoc;
388 * return true so no event is sent to userspace.
389 */
390 wdev->conn->prev_bssid_valid = false;
391 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
392 schedule_work(&rdev->conn_work);
393 return true;
394 }
395
Johannes Berg923a0e72013-06-28 11:38:54 +0200396 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
Johannes Bergceca7b72013-05-16 00:55:45 +0200397 schedule_work(&rdev->conn_work);
398 return false;
399}
400
401void cfg80211_sme_deauth(struct wireless_dev *wdev)
402{
403 cfg80211_sme_free(wdev);
404}
405
406void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
407{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800408 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200409
410 if (!wdev->conn)
411 return;
412
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200413 wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200414 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200415}
416
417void cfg80211_sme_disassoc(struct wireless_dev *wdev)
418{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200420
421 if (!wdev->conn)
422 return;
423
424 wdev->conn->state = CFG80211_CONN_DEAUTH;
425 schedule_work(&rdev->conn_work);
426}
427
428void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
429{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800430 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200431
432 if (!wdev->conn)
433 return;
434
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200435 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200436 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200437}
438
Johannes Berge6f462d2016-12-08 17:22:09 +0100439void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev)
440{
441 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
442
443 if (!wdev->conn)
444 return;
445
446 wdev->conn->state = CFG80211_CONN_ABANDON;
447 schedule_work(&rdev->conn_work);
448}
449
Johannes Berg46b9d182015-03-31 16:09:13 +0200450static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev,
451 const u8 *ies, size_t ies_len,
452 const u8 **out_ies, size_t *out_ies_len)
453{
454 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
455 u8 *buf;
456 size_t offs;
457
458 if (!rdev->wiphy.extended_capabilities_len ||
459 (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) {
460 *out_ies = kmemdup(ies, ies_len, GFP_KERNEL);
461 if (!*out_ies)
462 return -ENOMEM;
463 *out_ies_len = ies_len;
464 return 0;
465 }
466
467 buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2,
468 GFP_KERNEL);
469 if (!buf)
470 return -ENOMEM;
471
472 if (ies_len) {
473 static const u8 before_extcapa[] = {
474 /* not listing IEs expected to be created by driver */
475 WLAN_EID_RSN,
476 WLAN_EID_QOS_CAPA,
477 WLAN_EID_RRM_ENABLED_CAPABILITIES,
478 WLAN_EID_MOBILITY_DOMAIN,
479 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
480 WLAN_EID_BSS_COEX_2040,
481 };
482
483 offs = ieee80211_ie_split(ies, ies_len, before_extcapa,
484 ARRAY_SIZE(before_extcapa), 0);
485 memcpy(buf, ies, offs);
486 /* leave a whole for extended capabilities IE */
487 memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2,
488 ies + offs, ies_len - offs);
489 } else {
490 offs = 0;
491 }
492
493 /* place extended capabilities IE (with only driver capabilities) */
494 buf[offs] = WLAN_EID_EXT_CAPABILITY;
495 buf[offs + 1] = rdev->wiphy.extended_capabilities_len;
496 memcpy(buf + offs + 2,
497 rdev->wiphy.extended_capabilities,
498 rdev->wiphy.extended_capabilities_len);
499
500 *out_ies = buf;
501 *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2;
502
503 return 0;
504}
505
Johannes Bergceca7b72013-05-16 00:55:45 +0200506static int cfg80211_sme_connect(struct wireless_dev *wdev,
507 struct cfg80211_connect_params *connect,
508 const u8 *prev_bssid)
509{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800510 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200511 struct cfg80211_bss *bss;
512 int err;
513
514 if (!rdev->ops->auth || !rdev->ops->assoc)
515 return -EOPNOTSUPP;
516
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +0300517 if (wdev->current_bss) {
518 if (!prev_bssid)
519 return -EALREADY;
520 if (prev_bssid &&
521 !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid))
522 return -ENOTCONN;
523 cfg80211_unhold_bss(wdev->current_bss);
524 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
525 wdev->current_bss = NULL;
526
527 cfg80211_sme_free(wdev);
528 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200529
530 if (WARN_ON(wdev->conn))
531 return -EINPROGRESS;
532
533 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
534 if (!wdev->conn)
535 return -ENOMEM;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200536
537 /*
Johannes Bergceca7b72013-05-16 00:55:45 +0200538 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
Johannes Bergf401a6f2009-08-07 14:51:05 +0200539 */
Johannes Bergceca7b72013-05-16 00:55:45 +0200540 memcpy(&wdev->conn->params, connect, sizeof(*connect));
541 if (connect->bssid) {
542 wdev->conn->params.bssid = wdev->conn->bssid;
543 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
544 }
Johannes Bergf401a6f2009-08-07 14:51:05 +0200545
Johannes Berg46b9d182015-03-31 16:09:13 +0200546 if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len,
547 &wdev->conn->ie,
548 &wdev->conn->params.ie_len)) {
549 kfree(wdev->conn);
550 wdev->conn = NULL;
551 return -ENOMEM;
Johannes Bergceca7b72013-05-16 00:55:45 +0200552 }
Johannes Berg46b9d182015-03-31 16:09:13 +0200553 wdev->conn->params.ie = wdev->conn->ie;
Johannes Bergceca7b72013-05-16 00:55:45 +0200554
555 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
556 wdev->conn->auto_auth = true;
557 /* start with open system ... should mostly work */
558 wdev->conn->params.auth_type =
559 NL80211_AUTHTYPE_OPEN_SYSTEM;
560 } else {
561 wdev->conn->auto_auth = false;
562 }
563
564 wdev->conn->params.ssid = wdev->ssid;
Zhao, Gangbabd3a22014-03-19 23:02:21 +0800565 wdev->conn->params.ssid_len = wdev->ssid_len;
Johannes Bergceca7b72013-05-16 00:55:45 +0200566
567 /* see if we have the bss already */
568 bss = cfg80211_get_conn_bss(wdev);
569
570 if (prev_bssid) {
571 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
572 wdev->conn->prev_bssid_valid = true;
573 }
574
575 /* we're good if we have a matching bss struct */
576 if (bss) {
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200577 enum nl80211_timeout_reason treason;
578
579 err = cfg80211_conn_do_work(wdev, &treason);
Johannes Bergceca7b72013-05-16 00:55:45 +0200580 cfg80211_put_bss(wdev->wiphy, bss);
581 } else {
582 /* otherwise we'll need to scan for the AP first */
583 err = cfg80211_conn_scan(wdev);
584
585 /*
586 * If we can't scan right now, then we need to scan again
587 * after the current scan finished, since the parameters
588 * changed (unless we find a good AP anyway).
589 */
590 if (err == -EBUSY) {
591 err = 0;
592 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
593 }
594 }
595
596 if (err)
597 cfg80211_sme_free(wdev);
598
599 return err;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200600}
601
Johannes Bergceca7b72013-05-16 00:55:45 +0200602static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
Johannes Berg7d930bc2009-10-20 15:08:53 +0900603{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800604 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200605 int err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900606
Johannes Bergceca7b72013-05-16 00:55:45 +0200607 if (!wdev->conn)
608 return 0;
609
610 if (!rdev->ops->deauth)
611 return -EOPNOTSUPP;
612
613 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
614 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
615 err = 0;
616 goto out;
617 }
618
619 /* wdev->conn->params.bssid must be set if > SCANNING */
620 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
621 wdev->conn->params.bssid,
622 NULL, 0, reason, false);
623 out:
624 cfg80211_sme_free(wdev);
625 return err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900626}
627
Johannes Bergceca7b72013-05-16 00:55:45 +0200628/*
629 * code shared for in-device and software SME
630 */
631
632static bool cfg80211_is_all_idle(void)
633{
634 struct cfg80211_registered_device *rdev;
635 struct wireless_dev *wdev;
636 bool is_all_idle = true;
637
638 /*
639 * All devices must be idle as otherwise if you are actively
640 * scanning some new beacon hints could be learned and would
641 * count as new regulatory hints.
642 */
643 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
Johannes Berg53873f12016-05-03 16:52:04 +0300644 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200645 wdev_lock(wdev);
646 if (wdev->conn || wdev->current_bss)
647 is_all_idle = false;
648 wdev_unlock(wdev);
649 }
650 }
651
652 return is_all_idle;
653}
654
655static void disconnect_work(struct work_struct *work)
656{
657 rtnl_lock();
658 if (cfg80211_is_all_idle())
659 regulatory_hint_disconnect();
660 rtnl_unlock();
661}
662
663static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
664
665
666/*
667 * API calls for drivers implementing connect/disconnect and
668 * SME event handling
669 */
670
Ben Greear6f390902013-06-19 14:06:25 -0700671/* This method must consume bss one way or another */
Johannes Berg667503d2009-07-07 03:56:11 +0200672void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
673 const u8 *req_ie, size_t req_ie_len,
674 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +0300675 int status, bool wextev,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200676 struct cfg80211_bss *bss,
677 enum nl80211_timeout_reason timeout_reason)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200678{
679 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg9caf0362012-11-29 01:25:20 +0100680 const u8 *country_ie;
Johannes Berg3d23e342009-09-29 23:27:28 +0200681#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200682 union iwreq_data wrqu;
683#endif
684
Johannes Berg667503d2009-07-07 03:56:11 +0200685 ASSERT_WDEV_LOCK(wdev);
686
Johannes Berg074ac8d2010-09-16 14:58:22 +0200687 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
Ben Greear6f390902013-06-19 14:06:25 -0700688 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
689 cfg80211_put_bss(wdev->wiphy, bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200690 return;
Ben Greear6f390902013-06-19 14:06:25 -0700691 }
Samuel Ortizb23aa672009-07-01 21:26:54 +0200692
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800693 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev,
Johannes Berge45cd822009-07-02 09:58:04 +0200694 bssid, req_ie, req_ie_len,
Johannes Bergea416a72009-08-17 12:22:14 +0200695 resp_ie, resp_ie_len,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200696 status, timeout_reason, GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200697
Johannes Berg3d23e342009-09-29 23:27:28 +0200698#ifdef CONFIG_CFG80211_WEXT
Johannes Berge45cd822009-07-02 09:58:04 +0200699 if (wextev) {
700 if (req_ie && status == WLAN_STATUS_SUCCESS) {
701 memset(&wrqu, 0, sizeof(wrqu));
702 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800703 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200704 }
705
706 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
707 memset(&wrqu, 0, sizeof(wrqu));
708 wrqu.data.length = resp_ie_len;
709 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
710 }
711
712 memset(&wrqu, 0, sizeof(wrqu));
713 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200714 if (bssid && status == WLAN_STATUS_SUCCESS) {
Johannes Berge45cd822009-07-02 09:58:04 +0200715 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200716 memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN);
717 wdev->wext.prev_bssid_valid = true;
718 }
Johannes Berge45cd822009-07-02 09:58:04 +0200719 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
720 }
721#endif
722
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530723 if (!bss && (status == WLAN_STATUS_SUCCESS)) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800724 WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect);
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530725 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
726 wdev->ssid, wdev->ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200727 wdev->conn_bss_type,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200728 IEEE80211_PRIVACY_ANY);
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530729 if (bss)
730 cfg80211_hold_bss(bss_from_pub(bss));
731 }
732
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200733 if (wdev->current_bss) {
734 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100735 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200736 wdev->current_bss = NULL;
737 }
738
Johannes Bergfffd0932009-07-08 14:22:54 +0200739 if (status != WLAN_STATUS_SUCCESS) {
Johannes Bergb47f6102014-09-10 13:39:54 +0300740 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +0200741 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200742 wdev->ssid_len = 0;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500743 wdev->conn_owner_nlportid = 0;
Johannes Bergf1940c52013-06-19 13:21:15 +0200744 if (bss) {
745 cfg80211_unhold_bss(bss_from_pub(bss));
746 cfg80211_put_bss(wdev->wiphy, bss);
747 }
Eliad Pellerc1fbb252014-04-30 15:58:13 +0300748 cfg80211_sme_free(wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200749 return;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200750 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200751
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530752 if (WARN_ON(!bss))
753 return;
Johannes Bergfffd0932009-07-08 14:22:54 +0200754
Johannes Bergfffd0932009-07-08 14:22:54 +0200755 wdev->current_bss = bss_from_pub(bss);
756
David Spinadelb8676222016-09-22 23:16:50 +0300757 if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP))
758 cfg80211_upload_connect_keys(wdev);
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700759
Johannes Berg9caf0362012-11-29 01:25:20 +0100760 rcu_read_lock();
761 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
762 if (!country_ie) {
763 rcu_read_unlock();
764 return;
765 }
766
767 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
768 rcu_read_unlock();
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700769
770 if (!country_ie)
771 return;
772
773 /*
774 * ieee80211_bss_get_ie() ensures we can access:
775 * - country_ie + 2, the start of the country ie data, and
776 * - and country_ie[1] which is the IE length
777 */
Luis R. Rodriguez789fd032013-10-04 18:07:24 -0700778 regulatory_hint_country_ie(wdev->wiphy, bss->channel->band,
779 country_ie + 2, country_ie[1]);
Johannes Berg9caf0362012-11-29 01:25:20 +0100780 kfree(country_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200781}
Johannes Bergf2129352009-07-01 21:26:56 +0200782
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530783/* Consumes bss object one way or another */
784void cfg80211_connect_bss(struct net_device *dev, const u8 *bssid,
785 struct cfg80211_bss *bss, const u8 *req_ie,
786 size_t req_ie_len, const u8 *resp_ie,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200787 size_t resp_ie_len, int status, gfp_t gfp,
788 enum nl80211_timeout_reason timeout_reason)
Johannes Bergf2129352009-07-01 21:26:56 +0200789{
Johannes Berg667503d2009-07-07 03:56:11 +0200790 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800791 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +0200792 struct cfg80211_event *ev;
793 unsigned long flags;
794
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530795 if (bss) {
796 /* Make sure the bss entry provided by the driver is valid. */
797 struct cfg80211_internal_bss *ibss = bss_from_pub(bss);
798
799 if (WARN_ON(list_empty(&ibss->list))) {
800 cfg80211_put_bss(wdev->wiphy, bss);
801 return;
802 }
803 }
804
Johannes Berg667503d2009-07-07 03:56:11 +0200805 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530806 if (!ev) {
807 cfg80211_put_bss(wdev->wiphy, bss);
Johannes Berg667503d2009-07-07 03:56:11 +0200808 return;
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530809 }
Johannes Berg667503d2009-07-07 03:56:11 +0200810
811 ev->type = EVENT_CONNECT_RESULT;
Zhu Yi16a832e2009-08-19 16:08:22 +0800812 if (bssid)
813 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
Nishant Sarmukadam7834704b2010-04-14 22:03:02 -0700814 if (req_ie_len) {
815 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
816 ev->cr.req_ie_len = req_ie_len;
817 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
818 }
819 if (resp_ie_len) {
820 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
821 ev->cr.resp_ie_len = resp_ie_len;
822 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
823 }
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530824 if (bss)
825 cfg80211_hold_bss(bss_from_pub(bss));
826 ev->cr.bss = bss;
Johannes Berg667503d2009-07-07 03:56:11 +0200827 ev->cr.status = status;
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200828 ev->cr.timeout_reason = timeout_reason;
Johannes Berg667503d2009-07-07 03:56:11 +0200829
830 spin_lock_irqsave(&wdev->event_lock, flags);
831 list_add_tail(&ev->list, &wdev->event_list);
832 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100833 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Bergf2129352009-07-01 21:26:56 +0200834}
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530835EXPORT_SYMBOL(cfg80211_connect_bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200836
Ben Greear0e3a39b2013-06-19 14:06:27 -0700837/* Consumes bss object one way or another */
Jouni Malinened9d0102011-05-16 19:40:15 +0300838void __cfg80211_roamed(struct wireless_dev *wdev,
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530839 struct cfg80211_bss *bss,
Johannes Berg667503d2009-07-07 03:56:11 +0200840 const u8 *req_ie, size_t req_ie_len,
841 const u8 *resp_ie, size_t resp_ie_len)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200842{
Johannes Berg3d23e342009-09-29 23:27:28 +0200843#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200844 union iwreq_data wrqu;
845#endif
Johannes Berg667503d2009-07-07 03:56:11 +0200846 ASSERT_WDEV_LOCK(wdev);
847
Johannes Berg074ac8d2010-09-16 14:58:22 +0200848 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
849 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530850 goto out;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200851
Johannes Bergceca7b72013-05-16 00:55:45 +0200852 if (WARN_ON(!wdev->current_bss))
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530853 goto out;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200854
Samuel Ortizb23aa672009-07-01 21:26:54 +0200855 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100856 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200857 wdev->current_bss = NULL;
858
Johannes Berg19957bb2009-07-02 17:20:43 +0200859 cfg80211_hold_bss(bss_from_pub(bss));
860 wdev->current_bss = bss_from_pub(bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200861
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800862 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
863 wdev->netdev, bss->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +0200864 req_ie, req_ie_len, resp_ie, resp_ie_len,
865 GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200866
Johannes Berg3d23e342009-09-29 23:27:28 +0200867#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200868 if (req_ie) {
869 memset(&wrqu, 0, sizeof(wrqu));
870 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800871 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
Johannes Berg667503d2009-07-07 03:56:11 +0200872 &wrqu, req_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200873 }
874
875 if (resp_ie) {
876 memset(&wrqu, 0, sizeof(wrqu));
877 wrqu.data.length = resp_ie_len;
Johannes Berg667503d2009-07-07 03:56:11 +0200878 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
879 &wrqu, resp_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200880 }
881
882 memset(&wrqu, 0, sizeof(wrqu));
883 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530884 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
885 memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200886 wdev->wext.prev_bssid_valid = true;
Johannes Berg667503d2009-07-07 03:56:11 +0200887 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200888#endif
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530889
890 return;
891out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100892 cfg80211_put_bss(wdev->wiphy, bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200893}
Johannes Berg667503d2009-07-07 03:56:11 +0200894
Jouni Malinened9d0102011-05-16 19:40:15 +0300895void cfg80211_roamed(struct net_device *dev,
896 struct ieee80211_channel *channel,
897 const u8 *bssid,
Johannes Berg667503d2009-07-07 03:56:11 +0200898 const u8 *req_ie, size_t req_ie_len,
899 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
900{
901 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530902 struct cfg80211_bss *bss;
903
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530904 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200905 wdev->ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200906 wdev->conn_bss_type, IEEE80211_PRIVACY_ANY);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530907 if (WARN_ON(!bss))
908 return;
909
910 cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie,
911 resp_ie_len, gfp);
912}
913EXPORT_SYMBOL(cfg80211_roamed);
914
Ben Greear0e3a39b2013-06-19 14:06:27 -0700915/* Consumes bss object one way or another */
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530916void cfg80211_roamed_bss(struct net_device *dev,
917 struct cfg80211_bss *bss, const u8 *req_ie,
918 size_t req_ie_len, const u8 *resp_ie,
919 size_t resp_ie_len, gfp_t gfp)
920{
921 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800922 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +0200923 struct cfg80211_event *ev;
924 unsigned long flags;
925
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530926 if (WARN_ON(!bss))
Johannes Berg667503d2009-07-07 03:56:11 +0200927 return;
928
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530929 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
930 if (!ev) {
Johannes Berg5b112d32013-02-01 01:49:58 +0100931 cfg80211_put_bss(wdev->wiphy, bss);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530932 return;
933 }
934
Johannes Berg667503d2009-07-07 03:56:11 +0200935 ev->type = EVENT_ROAMED;
Johannes Berg667503d2009-07-07 03:56:11 +0200936 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
937 ev->rm.req_ie_len = req_ie_len;
938 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
939 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
940 ev->rm.resp_ie_len = resp_ie_len;
941 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530942 ev->rm.bss = bss;
Johannes Berg667503d2009-07-07 03:56:11 +0200943
944 spin_lock_irqsave(&wdev->event_lock, flags);
945 list_add_tail(&ev->list, &wdev->event_list);
946 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100947 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Berg667503d2009-07-07 03:56:11 +0200948}
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530949EXPORT_SYMBOL(cfg80211_roamed_bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200950
Johannes Berg667503d2009-07-07 03:56:11 +0200951void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
Johannes Berg6829c872009-07-02 09:13:27 +0200952 size_t ie_len, u16 reason, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200953{
954 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800955 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergfffd0932009-07-08 14:22:54 +0200956 int i;
Johannes Berg3d23e342009-09-29 23:27:28 +0200957#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200958 union iwreq_data wrqu;
959#endif
960
Johannes Berg667503d2009-07-07 03:56:11 +0200961 ASSERT_WDEV_LOCK(wdev);
962
Johannes Berg074ac8d2010-09-16 14:58:22 +0200963 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
964 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
Samuel Ortizb23aa672009-07-01 21:26:54 +0200965 return;
966
Samuel Ortizb23aa672009-07-01 21:26:54 +0200967 if (wdev->current_bss) {
968 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100969 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200970 }
971
972 wdev->current_bss = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200973 wdev->ssid_len = 0;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500974 wdev->conn_owner_nlportid = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200975
Johannes Bergfffd0932009-07-08 14:22:54 +0200976 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
977
Arend van Sprielb8607152016-02-15 14:35:53 +0100978 /* stop critical protocol if supported */
979 if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) {
980 rdev->crit_proto_nlportid = 0;
981 rdev_crit_proto_stop(rdev, wdev);
982 }
983
Johannes Bergfffd0932009-07-08 14:22:54 +0200984 /*
985 * Delete all the keys ... pairwise keys can't really
986 * exist any more anyway, but default keys might.
987 */
988 if (rdev->ops->del_key)
989 for (i = 0; i < 6; i++)
Hila Gonene35e4d22012-06-27 17:19:42 +0300990 rdev_del_key(rdev, dev, i, false, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200991
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800992 rdev_set_qos_map(rdev, dev, NULL);
993
Johannes Berg3d23e342009-09-29 23:27:28 +0200994#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200995 memset(&wrqu, 0, sizeof(wrqu));
996 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
997 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Abhijeet Kolekar5f612032010-01-13 13:23:14 -0800998 wdev->wext.connect.ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200999#endif
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -05001000
1001 schedule_work(&cfg80211_disconnect_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001002}
1003
1004void cfg80211_disconnected(struct net_device *dev, u16 reason,
Johannes Berg80279fb2015-05-22 16:22:20 +02001005 const u8 *ie, size_t ie_len,
1006 bool locally_generated, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001007{
Johannes Berg667503d2009-07-07 03:56:11 +02001008 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +02001010 struct cfg80211_event *ev;
1011 unsigned long flags;
1012
1013 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
1014 if (!ev)
1015 return;
1016
1017 ev->type = EVENT_DISCONNECTED;
1018 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
1019 ev->dc.ie_len = ie_len;
1020 memcpy((void *)ev->dc.ie, ie, ie_len);
1021 ev->dc.reason = reason;
Johannes Berg80279fb2015-05-22 16:22:20 +02001022 ev->dc.locally_generated = locally_generated;
Johannes Berg667503d2009-07-07 03:56:11 +02001023
1024 spin_lock_irqsave(&wdev->event_lock, flags);
1025 list_add_tail(&ev->list, &wdev->event_list);
1026 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +01001027 queue_work(cfg80211_wq, &rdev->event_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001028}
1029EXPORT_SYMBOL(cfg80211_disconnected);
1030
Johannes Bergceca7b72013-05-16 00:55:45 +02001031/*
1032 * API calls for nl80211/wext compatibility code
1033 */
Johannes Berg83739b02013-05-15 17:44:01 +02001034int cfg80211_connect(struct cfg80211_registered_device *rdev,
1035 struct net_device *dev,
1036 struct cfg80211_connect_params *connect,
1037 struct cfg80211_cached_keys *connkeys,
1038 const u8 *prev_bssid)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001039{
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg667503d2009-07-07 03:56:11 +02001041 int err;
1042
1043 ASSERT_WDEV_LOCK(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001044
Johannes Bergfffd0932009-07-08 14:22:54 +02001045 if (WARN_ON(wdev->connect_keys)) {
Johannes Bergb47f6102014-09-10 13:39:54 +03001046 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001047 wdev->connect_keys = NULL;
1048 }
1049
Ben Greear7e7c8922011-11-18 11:31:59 -08001050 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
1051 rdev->wiphy.ht_capa_mod_mask);
1052
Johannes Bergfffd0932009-07-08 14:22:54 +02001053 if (connkeys && connkeys->def >= 0) {
1054 int idx;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001055 u32 cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001056
1057 idx = connkeys->def;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001058 cipher = connkeys->params[idx].cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001059 /* If given a WEP key we may need it for shared key auth */
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001060 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
1061 cipher == WLAN_CIPHER_SUITE_WEP104) {
Johannes Bergfffd0932009-07-08 14:22:54 +02001062 connect->key_idx = idx;
1063 connect->key = connkeys->params[idx].key;
1064 connect->key_len = connkeys->params[idx].key_len;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001065
1066 /*
1067 * If ciphers are not set (e.g. when going through
1068 * iwconfig), we have to set them appropriately here.
1069 */
1070 if (connect->crypto.cipher_group == 0)
1071 connect->crypto.cipher_group = cipher;
1072
1073 if (connect->crypto.n_ciphers_pairwise == 0) {
1074 connect->crypto.n_ciphers_pairwise = 1;
1075 connect->crypto.ciphers_pairwise[0] = cipher;
1076 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001077 }
David Spinadelb8676222016-09-22 23:16:50 +03001078
1079 connect->crypto.wep_keys = connkeys->params;
1080 connect->crypto.wep_tx_key = connkeys->def;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001081 } else {
1082 if (WARN_ON(connkeys))
1083 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001084 }
1085
Johannes Bergceca7b72013-05-16 00:55:45 +02001086 wdev->connect_keys = connkeys;
1087 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
1088 wdev->ssid_len = connect->ssid_len;
Johannes Berg6829c872009-07-02 09:13:27 +02001089
Lior David34d50512016-01-28 10:58:25 +02001090 wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS :
1091 IEEE80211_BSS_TYPE_ESS;
1092
Johannes Bergceca7b72013-05-16 00:55:45 +02001093 if (!rdev->ops->connect)
1094 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
1095 else
Hila Gonene35e4d22012-06-27 17:19:42 +03001096 err = rdev_connect(rdev, dev, connect);
Johannes Berg6829c872009-07-02 09:13:27 +02001097
Johannes Bergceca7b72013-05-16 00:55:45 +02001098 if (err) {
1099 wdev->connect_keys = NULL;
1100 wdev->ssid_len = 0;
1101 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001102 }
Johannes Bergceca7b72013-05-16 00:55:45 +02001103
1104 return 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001105}
1106
Johannes Berg83739b02013-05-15 17:44:01 +02001107int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
1108 struct net_device *dev, u16 reason, bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001109{
Johannes Berg6829c872009-07-02 09:13:27 +02001110 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergdee8a972013-08-13 09:23:57 +02001111 int err = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001112
Johannes Berg667503d2009-07-07 03:56:11 +02001113 ASSERT_WDEV_LOCK(wdev);
1114
Johannes Bergb47f6102014-09-10 13:39:54 +03001115 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001116 wdev->connect_keys = NULL;
1117
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05001118 wdev->conn_owner_nlportid = 0;
1119
Johannes Bergdee8a972013-08-13 09:23:57 +02001120 if (wdev->conn)
Johannes Bergceca7b72013-05-16 00:55:45 +02001121 err = cfg80211_sme_disconnect(wdev, reason);
Johannes Bergdee8a972013-08-13 09:23:57 +02001122 else if (!rdev->ops->disconnect)
Johannes Bergceca7b72013-05-16 00:55:45 +02001123 cfg80211_mlme_down(rdev, dev);
Ilan Peer0711d632016-10-18 23:12:13 +03001124 else if (wdev->ssid_len)
Hila Gonene35e4d22012-06-27 17:19:42 +03001125 err = rdev_disconnect(rdev, dev, reason);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001126
Johannes Bergceca7b72013-05-16 00:55:45 +02001127 return err;
Johannes Berg19957bb2009-07-02 17:20:43 +02001128}
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05001129
1130/*
1131 * Used to clean up after the connection / connection attempt owner socket
1132 * disconnects
1133 */
1134void cfg80211_autodisconnect_wk(struct work_struct *work)
1135{
1136 struct wireless_dev *wdev =
1137 container_of(work, struct wireless_dev, disconnect_wk);
1138 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1139
1140 wdev_lock(wdev);
1141
1142 if (wdev->conn_owner_nlportid) {
1143 /*
1144 * Use disconnect_bssid if still connecting and ops->disconnect
1145 * not implemented. Otherwise we can use cfg80211_disconnect.
1146 */
1147 if (rdev->ops->disconnect || wdev->current_bss)
1148 cfg80211_disconnect(rdev, wdev->netdev,
1149 WLAN_REASON_DEAUTH_LEAVING, true);
1150 else
1151 cfg80211_mlme_deauth(rdev, wdev->netdev,
1152 wdev->disconnect_bssid, NULL, 0,
1153 WLAN_REASON_DEAUTH_LEAVING, false);
1154 }
1155
1156 wdev_unlock(wdev);
1157}