blob: e8f7019a226a94e62b4aca0e7e5958de760c1472 [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 Kushwahadf935062017-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 Kushwahadf935062017-01-13 01:12:21 +020041 CFG80211_CONN_ASSOC_FAILED_TIMEOUT,
Johannes Bergceca7b72013-05-16 00:55:45 +020042 CFG80211_CONN_DEAUTH,
Johannes Berg1976c762016-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
Sachin Ahuja4216dfb2014-04-28 15:26:53 +053052static bool cfg80211_is_all_countryie_ignore(void)
53{
54 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *wdev;
56 bool is_all_countryie_ignore = true;
57
58 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
59 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
60 wdev_lock(wdev);
61 if (!(wdev->wiphy->regulatory_flags &
62 REGULATORY_COUNTRY_IE_IGNORE)) {
63 is_all_countryie_ignore = false;
64 wdev_unlock(wdev);
65 goto out;
66 }
67 wdev_unlock(wdev);
68 }
69 }
70
71out:
72 return is_all_countryie_ignore;
73}
74
Johannes Bergceca7b72013-05-16 00:55:45 +020075static void cfg80211_sme_free(struct wireless_dev *wdev)
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050076{
Johannes Bergceca7b72013-05-16 00:55:45 +020077 if (!wdev->conn)
78 return;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050079
Johannes Bergceca7b72013-05-16 00:55:45 +020080 kfree(wdev->conn->ie);
81 kfree(wdev->conn);
82 wdev->conn = NULL;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050083}
84
Johannes Berg6829c872009-07-02 09:13:27 +020085static int cfg80211_conn_scan(struct wireless_dev *wdev)
86{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080087 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020088 struct cfg80211_scan_request *request;
89 int n_channels, err;
90
91 ASSERT_RTNL();
Johannes Berg667503dd2009-07-07 03:56:11 +020092 ASSERT_WDEV_LOCK(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +020093
Johannes Bergf9d15d12014-01-22 11:14:19 +020094 if (rdev->scan_req || rdev->scan_msg)
Johannes Berg6829c872009-07-02 09:13:27 +020095 return -EBUSY;
96
Ilan Peerbdfbec22014-01-09 11:37:23 +020097 if (wdev->conn->params.channel)
Johannes Berg6829c872009-07-02 09:13:27 +020098 n_channels = 1;
Ilan Peerbdfbec22014-01-09 11:37:23 +020099 else
100 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200101
Johannes Berg6829c872009-07-02 09:13:27 +0200102 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
103 sizeof(request->channels[0]) * n_channels,
104 GFP_KERNEL);
105 if (!request)
106 return -ENOMEM;
107
Karl Beldan2a84ee82014-10-07 11:42:18 +0200108 if (wdev->conn->params.channel) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200109 enum nl80211_band band = wdev->conn->params.channel->band;
Karl Beldan2a84ee82014-10-07 11:42:18 +0200110 struct ieee80211_supported_band *sband =
111 wdev->wiphy->bands[band];
112
113 if (!sband) {
114 kfree(request);
115 return -EINVAL;
116 }
Johannes Berg6829c872009-07-02 09:13:27 +0200117 request->channels[0] = wdev->conn->params.channel;
Karl Beldan2a84ee82014-10-07 11:42:18 +0200118 request->rates[band] = (1 << sband->n_bitrates) - 1;
119 } else {
Johannes Berg6829c872009-07-02 09:13:27 +0200120 int i = 0, j;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200121 enum nl80211_band band;
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530122 struct ieee80211_supported_band *bands;
123 struct ieee80211_channel *channel;
Johannes Berg6829c872009-07-02 09:13:27 +0200124
Johannes Berg57fbcce2016-04-12 15:56:15 +0200125 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530126 bands = wdev->wiphy->bands[band];
127 if (!bands)
Johannes Berg6829c872009-07-02 09:13:27 +0200128 continue;
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530129 for (j = 0; j < bands->n_channels; j++) {
130 channel = &bands->channels[j];
131 if (channel->flags & IEEE80211_CHAN_DISABLED)
132 continue;
133 request->channels[i++] = channel;
134 }
135 request->rates[band] = (1 << bands->n_bitrates) - 1;
Johannes Berg6829c872009-07-02 09:13:27 +0200136 }
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530137 n_channels = i;
Johannes Berg6829c872009-07-02 09:13:27 +0200138 }
139 request->n_channels = n_channels;
Johannes Berg5ba63532009-08-07 17:54:07 +0200140 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg6829c872009-07-02 09:13:27 +0200141 request->n_ssids = 1;
142
143 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
144 wdev->conn->params.ssid_len);
145 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
146
Jouni Malinen818965d2016-02-26 22:12:47 +0200147 eth_broadcast_addr(request->bssid);
148
Johannes Bergfd014282012-06-18 19:17:03 +0200149 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +0200150 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -0700151 request->scan_start = jiffies;
Johannes Berg6829c872009-07-02 09:13:27 +0200152
Johannes Berg79c97e92009-07-07 03:56:12 +0200153 rdev->scan_req = request;
Johannes Berg6829c872009-07-02 09:13:27 +0200154
Hila Gonene35e4d22012-06-27 17:19:42 +0300155 err = rdev_scan(rdev, request);
Johannes Berg6829c872009-07-02 09:13:27 +0200156 if (!err) {
157 wdev->conn->state = CFG80211_CONN_SCANNING;
Johannes Bergfd014282012-06-18 19:17:03 +0200158 nl80211_send_scan_start(rdev, wdev);
Johannes Berg463d0182009-07-14 00:33:35 +0200159 dev_hold(wdev->netdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200160 } else {
Johannes Berg79c97e92009-07-07 03:56:12 +0200161 rdev->scan_req = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200162 kfree(request);
163 }
164 return err;
165}
166
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200167static int cfg80211_conn_do_work(struct wireless_dev *wdev,
168 enum nl80211_timeout_reason *treason)
Johannes Berg6829c872009-07-02 09:13:27 +0200169{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800170 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200171 struct cfg80211_connect_params *params;
Johannes Bergf62fab72013-02-21 20:09:09 +0100172 struct cfg80211_assoc_request req = {};
Johannes Berg19957bb2009-07-02 17:20:43 +0200173 int err;
Johannes Berg6829c872009-07-02 09:13:27 +0200174
Johannes Berg667503dd2009-07-07 03:56:11 +0200175 ASSERT_WDEV_LOCK(wdev);
176
Johannes Berg6829c872009-07-02 09:13:27 +0200177 if (!wdev->conn)
178 return 0;
179
Johannes Berg19957bb2009-07-02 17:20:43 +0200180 params = &wdev->conn->params;
181
Johannes Berg6829c872009-07-02 09:13:27 +0200182 switch (wdev->conn->state) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200183 case CFG80211_CONN_SCANNING:
184 /* didn't find it during scan ... */
185 return -ENOENT;
Johannes Berg6829c872009-07-02 09:13:27 +0200186 case CFG80211_CONN_SCAN_AGAIN:
187 return cfg80211_conn_scan(wdev);
188 case CFG80211_CONN_AUTHENTICATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200189 if (WARN_ON(!rdev->ops->auth))
190 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200191 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
Johannes Berg91bf9b22013-05-15 17:44:01 +0200192 return cfg80211_mlme_auth(rdev, wdev->netdev,
193 params->channel, params->auth_type,
194 params->bssid,
195 params->ssid, params->ssid_len,
196 NULL, 0,
197 params->key, params->key_len,
198 params->key_idx, NULL, 0);
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200199 case CFG80211_CONN_AUTH_FAILED_TIMEOUT:
200 *treason = NL80211_TIMEOUT_AUTH;
Johannes Berg923a0e72013-06-28 11:38:54 +0200201 return -ENOTCONN;
Johannes Berg6829c872009-07-02 09:13:27 +0200202 case CFG80211_CONN_ASSOCIATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200203 if (WARN_ON(!rdev->ops->assoc))
204 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200205 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200206 if (wdev->conn->prev_bssid_valid)
Johannes Bergf62fab72013-02-21 20:09:09 +0100207 req.prev_bssid = wdev->conn->prev_bssid;
208 req.ie = params->ie;
209 req.ie_len = params->ie_len;
210 req.use_mfp = params->mfp != NL80211_MFP_NO;
211 req.crypto = params->crypto;
212 req.flags = params->flags;
213 req.ht_capa = params->ht_capa;
214 req.ht_capa_mask = params->ht_capa_mask;
215 req.vht_capa = params->vht_capa;
216 req.vht_capa_mask = params->vht_capa_mask;
217
Johannes Berg91bf9b22013-05-15 17:44:01 +0200218 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
219 params->bssid, params->ssid,
220 params->ssid_len, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200221 if (err)
Johannes Berg91bf9b22013-05-15 17:44:01 +0200222 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
223 NULL, 0,
224 WLAN_REASON_DEAUTH_LEAVING,
225 false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200226 return err;
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200227 case CFG80211_CONN_ASSOC_FAILED_TIMEOUT:
228 *treason = NL80211_TIMEOUT_ASSOC;
229 /* fall through */
Johannes Berg923a0e72013-06-28 11:38:54 +0200230 case CFG80211_CONN_ASSOC_FAILED:
231 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
232 NULL, 0,
233 WLAN_REASON_DEAUTH_LEAVING, false);
234 return -ENOTCONN;
Johannes Bergceca7b72013-05-16 00:55:45 +0200235 case CFG80211_CONN_DEAUTH:
Johannes Berg91bf9b22013-05-15 17:44:01 +0200236 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
237 NULL, 0,
238 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berg1976c762016-12-08 17:22:09 +0100239 /* fall through */
240 case CFG80211_CONN_ABANDON:
Johannes Berg923a0e72013-06-28 11:38:54 +0200241 /* free directly, disconnected event already sent */
242 cfg80211_sme_free(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200243 return 0;
Johannes Berg6829c872009-07-02 09:13:27 +0200244 default:
245 return 0;
246 }
247}
248
249void cfg80211_conn_work(struct work_struct *work)
250{
Johannes Berg79c97e92009-07-07 03:56:12 +0200251 struct cfg80211_registered_device *rdev =
Johannes Berg6829c872009-07-02 09:13:27 +0200252 container_of(work, struct cfg80211_registered_device, conn_work);
253 struct wireless_dev *wdev;
Johannes Berg7400f422009-10-31 07:40:37 +0100254 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200255 enum nl80211_timeout_reason treason;
Johannes Berg6829c872009-07-02 09:13:27 +0200256
257 rtnl_lock();
Johannes Berg6829c872009-07-02 09:13:27 +0200258
Johannes Berg53873f12016-05-03 16:52:04 +0300259 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergc8157972013-05-23 18:10:21 +0200260 if (!wdev->netdev)
261 continue;
262
Johannes Berg667503dd2009-07-07 03:56:11 +0200263 wdev_lock(wdev);
264 if (!netif_running(wdev->netdev)) {
265 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200266 continue;
Johannes Berg667503dd2009-07-07 03:56:11 +0200267 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200268 if (!wdev->conn ||
269 wdev->conn->state == CFG80211_CONN_CONNECTED) {
Johannes Berg667503dd2009-07-07 03:56:11 +0200270 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200271 continue;
Johannes Berg667503dd2009-07-07 03:56:11 +0200272 }
Johannes Berg7400f422009-10-31 07:40:37 +0100273 if (wdev->conn->params.bssid) {
274 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
275 bssid = bssid_buf;
276 }
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200277 treason = NL80211_TIMEOUT_UNSPECIFIED;
278 if (cfg80211_conn_do_work(wdev, &treason)) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300279 struct cfg80211_connect_resp_params cr;
280
281 memset(&cr, 0, sizeof(cr));
282 cr.status = -1;
283 cr.bssid = bssid;
284 cr.timeout_reason = treason;
285 __cfg80211_connect_result(wdev->netdev, &cr, false);
Johannes Bergceca7b72013-05-16 00:55:45 +0200286 }
Johannes Berg667503dd2009-07-07 03:56:11 +0200287 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200288 }
289
Johannes Berg6829c872009-07-02 09:13:27 +0200290 rtnl_unlock();
291}
292
Ben Greear0e3a39b2013-06-19 14:06:27 -0700293/* Returned bss is reference counted and must be cleaned up appropriately. */
Johannes Bergbbac31f2009-09-16 09:04:26 -0700294static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
Johannes Berg6829c872009-07-02 09:13:27 +0200295{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800296 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200297 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200298
Johannes Berg667503dd2009-07-07 03:56:11 +0200299 ASSERT_WDEV_LOCK(wdev);
300
Jouni Malinened9d0102011-05-16 19:40:15 +0300301 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
302 wdev->conn->params.bssid,
Johannes Berg6829c872009-07-02 09:13:27 +0200303 wdev->conn->params.ssid,
304 wdev->conn->params.ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200305 wdev->conn_bss_type,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200306 IEEE80211_PRIVACY(wdev->conn->params.privacy));
Johannes Berg6829c872009-07-02 09:13:27 +0200307 if (!bss)
Johannes Bergbbac31f2009-09-16 09:04:26 -0700308 return NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200309
310 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
311 wdev->conn->params.bssid = wdev->conn->bssid;
312 wdev->conn->params.channel = bss->channel;
313 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
Johannes Berg79c97e92009-07-07 03:56:12 +0200314 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200315
Johannes Bergbbac31f2009-09-16 09:04:26 -0700316 return bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200317}
318
Johannes Berg667503dd2009-07-07 03:56:11 +0200319static void __cfg80211_sme_scan_done(struct net_device *dev)
Johannes Berg6829c872009-07-02 09:13:27 +0200320{
321 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800322 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergbbac31f2009-09-16 09:04:26 -0700323 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200324
Johannes Berg667503dd2009-07-07 03:56:11 +0200325 ASSERT_WDEV_LOCK(wdev);
326
Zhu Yid4b1a682009-07-16 17:34:14 +0800327 if (!wdev->conn)
Johannes Berg6829c872009-07-02 09:13:27 +0200328 return;
329
330 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
331 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
332 return;
333
Johannes Bergbbac31f2009-09-16 09:04:26 -0700334 bss = cfg80211_get_conn_bss(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200335 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100336 cfg80211_put_bss(&rdev->wiphy, bss);
Johannes Bergceca7b72013-05-16 00:55:45 +0200337 else
338 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200339}
340
Johannes Berg667503dd2009-07-07 03:56:11 +0200341void cfg80211_sme_scan_done(struct net_device *dev)
342{
343 struct wireless_dev *wdev = dev->ieee80211_ptr;
344
345 wdev_lock(wdev);
346 __cfg80211_sme_scan_done(dev);
347 wdev_unlock(wdev);
348}
349
Johannes Bergceca7b72013-05-16 00:55:45 +0200350void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
Johannes Berg6829c872009-07-02 09:13:27 +0200351{
Johannes Berg6829c872009-07-02 09:13:27 +0200352 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800353 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200354 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
355 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
356
Johannes Berg667503dd2009-07-07 03:56:11 +0200357 ASSERT_WDEV_LOCK(wdev);
358
Johannes Bergceca7b72013-05-16 00:55:45 +0200359 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
Johannes Berg6829c872009-07-02 09:13:27 +0200360 return;
361
362 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
363 wdev->conn->auto_auth &&
364 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
365 /* select automatically between only open, shared, leap */
366 switch (wdev->conn->params.auth_type) {
367 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Johannes Bergfffd0932009-07-08 14:22:54 +0200368 if (wdev->connect_keys)
369 wdev->conn->params.auth_type =
370 NL80211_AUTHTYPE_SHARED_KEY;
371 else
372 wdev->conn->params.auth_type =
373 NL80211_AUTHTYPE_NETWORK_EAP;
Johannes Berg6829c872009-07-02 09:13:27 +0200374 break;
375 case NL80211_AUTHTYPE_SHARED_KEY:
376 wdev->conn->params.auth_type =
377 NL80211_AUTHTYPE_NETWORK_EAP;
378 break;
379 default:
380 /* huh? */
381 wdev->conn->params.auth_type =
382 NL80211_AUTHTYPE_OPEN_SYSTEM;
383 break;
384 }
385 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
386 schedule_work(&rdev->conn_work);
Johannes Berg19957bb2009-07-02 17:20:43 +0200387 } else if (status_code != WLAN_STATUS_SUCCESS) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300388 struct cfg80211_connect_resp_params cr;
389
390 memset(&cr, 0, sizeof(cr));
391 cr.status = status_code;
392 cr.bssid = mgmt->bssid;
393 cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED;
394 __cfg80211_connect_result(wdev->netdev, &cr, false);
Johannes Bergceca7b72013-05-16 00:55:45 +0200395 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
Johannes Berg6829c872009-07-02 09:13:27 +0200396 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
397 schedule_work(&rdev->conn_work);
398 }
399}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200400
Johannes Bergceca7b72013-05-16 00:55:45 +0200401bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200402{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200404
Johannes Bergceca7b72013-05-16 00:55:45 +0200405 if (!wdev->conn)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200406 return false;
407
Johannes Bergceca7b72013-05-16 00:55:45 +0200408 if (status == WLAN_STATUS_SUCCESS) {
409 wdev->conn->state = CFG80211_CONN_CONNECTED;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200410 return false;
Johannes Bergceca7b72013-05-16 00:55:45 +0200411 }
412
413 if (wdev->conn->prev_bssid_valid) {
414 /*
415 * Some stupid APs don't accept reassoc, so we
416 * need to fall back to trying regular assoc;
417 * return true so no event is sent to userspace.
418 */
419 wdev->conn->prev_bssid_valid = false;
420 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
421 schedule_work(&rdev->conn_work);
422 return true;
423 }
424
Johannes Berg923a0e72013-06-28 11:38:54 +0200425 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
Johannes Bergceca7b72013-05-16 00:55:45 +0200426 schedule_work(&rdev->conn_work);
427 return false;
428}
429
430void cfg80211_sme_deauth(struct wireless_dev *wdev)
431{
432 cfg80211_sme_free(wdev);
433}
434
435void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
436{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800437 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200438
439 if (!wdev->conn)
440 return;
441
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200442 wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200443 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200444}
445
446void cfg80211_sme_disassoc(struct wireless_dev *wdev)
447{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800448 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200449
450 if (!wdev->conn)
451 return;
452
453 wdev->conn->state = CFG80211_CONN_DEAUTH;
454 schedule_work(&rdev->conn_work);
455}
456
457void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
458{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800459 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200460
461 if (!wdev->conn)
462 return;
463
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200464 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200465 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200466}
467
Johannes Berg1976c762016-12-08 17:22:09 +0100468void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev)
469{
470 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
471
472 if (!wdev->conn)
473 return;
474
475 wdev->conn->state = CFG80211_CONN_ABANDON;
476 schedule_work(&rdev->conn_work);
477}
478
Johannes Berg46b9d182015-03-31 16:09:13 +0200479static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev,
480 const u8 *ies, size_t ies_len,
481 const u8 **out_ies, size_t *out_ies_len)
482{
483 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
484 u8 *buf;
485 size_t offs;
486
487 if (!rdev->wiphy.extended_capabilities_len ||
488 (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) {
489 *out_ies = kmemdup(ies, ies_len, GFP_KERNEL);
490 if (!*out_ies)
491 return -ENOMEM;
492 *out_ies_len = ies_len;
493 return 0;
494 }
495
496 buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2,
497 GFP_KERNEL);
498 if (!buf)
499 return -ENOMEM;
500
501 if (ies_len) {
502 static const u8 before_extcapa[] = {
503 /* not listing IEs expected to be created by driver */
504 WLAN_EID_RSN,
505 WLAN_EID_QOS_CAPA,
506 WLAN_EID_RRM_ENABLED_CAPABILITIES,
507 WLAN_EID_MOBILITY_DOMAIN,
508 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
509 WLAN_EID_BSS_COEX_2040,
510 };
511
512 offs = ieee80211_ie_split(ies, ies_len, before_extcapa,
513 ARRAY_SIZE(before_extcapa), 0);
514 memcpy(buf, ies, offs);
515 /* leave a whole for extended capabilities IE */
516 memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2,
517 ies + offs, ies_len - offs);
518 } else {
519 offs = 0;
520 }
521
522 /* place extended capabilities IE (with only driver capabilities) */
523 buf[offs] = WLAN_EID_EXT_CAPABILITY;
524 buf[offs + 1] = rdev->wiphy.extended_capabilities_len;
525 memcpy(buf + offs + 2,
526 rdev->wiphy.extended_capabilities,
527 rdev->wiphy.extended_capabilities_len);
528
529 *out_ies = buf;
530 *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2;
531
532 return 0;
533}
534
Johannes Bergceca7b72013-05-16 00:55:45 +0200535static int cfg80211_sme_connect(struct wireless_dev *wdev,
536 struct cfg80211_connect_params *connect,
537 const u8 *prev_bssid)
538{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200540 struct cfg80211_bss *bss;
541 int err;
542
543 if (!rdev->ops->auth || !rdev->ops->assoc)
544 return -EOPNOTSUPP;
545
Jouni Malinen4ce2bd92016-03-29 13:53:28 +0300546 if (wdev->current_bss) {
547 if (!prev_bssid)
548 return -EALREADY;
549 if (prev_bssid &&
550 !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid))
551 return -ENOTCONN;
552 cfg80211_unhold_bss(wdev->current_bss);
553 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
554 wdev->current_bss = NULL;
555
556 cfg80211_sme_free(wdev);
557 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200558
559 if (WARN_ON(wdev->conn))
560 return -EINPROGRESS;
561
562 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
563 if (!wdev->conn)
564 return -ENOMEM;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200565
566 /*
Johannes Bergceca7b72013-05-16 00:55:45 +0200567 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
Johannes Bergf401a6f2009-08-07 14:51:05 +0200568 */
Johannes Bergceca7b72013-05-16 00:55:45 +0200569 memcpy(&wdev->conn->params, connect, sizeof(*connect));
570 if (connect->bssid) {
571 wdev->conn->params.bssid = wdev->conn->bssid;
572 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
573 }
Johannes Bergf401a6f2009-08-07 14:51:05 +0200574
Johannes Berg46b9d182015-03-31 16:09:13 +0200575 if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len,
576 &wdev->conn->ie,
577 &wdev->conn->params.ie_len)) {
578 kfree(wdev->conn);
579 wdev->conn = NULL;
580 return -ENOMEM;
Johannes Bergceca7b72013-05-16 00:55:45 +0200581 }
Johannes Berg46b9d182015-03-31 16:09:13 +0200582 wdev->conn->params.ie = wdev->conn->ie;
Johannes Bergceca7b72013-05-16 00:55:45 +0200583
584 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
585 wdev->conn->auto_auth = true;
586 /* start with open system ... should mostly work */
587 wdev->conn->params.auth_type =
588 NL80211_AUTHTYPE_OPEN_SYSTEM;
589 } else {
590 wdev->conn->auto_auth = false;
591 }
592
593 wdev->conn->params.ssid = wdev->ssid;
Zhao, Gangbabd3a22014-03-19 23:02:21 +0800594 wdev->conn->params.ssid_len = wdev->ssid_len;
Johannes Bergceca7b72013-05-16 00:55:45 +0200595
596 /* see if we have the bss already */
597 bss = cfg80211_get_conn_bss(wdev);
598
599 if (prev_bssid) {
600 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
601 wdev->conn->prev_bssid_valid = true;
602 }
603
604 /* we're good if we have a matching bss struct */
605 if (bss) {
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200606 enum nl80211_timeout_reason treason;
607
608 err = cfg80211_conn_do_work(wdev, &treason);
Johannes Bergceca7b72013-05-16 00:55:45 +0200609 cfg80211_put_bss(wdev->wiphy, bss);
610 } else {
611 /* otherwise we'll need to scan for the AP first */
612 err = cfg80211_conn_scan(wdev);
613
614 /*
615 * If we can't scan right now, then we need to scan again
616 * after the current scan finished, since the parameters
617 * changed (unless we find a good AP anyway).
618 */
619 if (err == -EBUSY) {
620 err = 0;
621 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
622 }
623 }
624
625 if (err)
626 cfg80211_sme_free(wdev);
627
628 return err;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200629}
630
Johannes Bergceca7b72013-05-16 00:55:45 +0200631static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
Johannes Berg7d930bc2009-10-20 15:08:53 +0900632{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800633 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200634 int err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900635
Johannes Bergceca7b72013-05-16 00:55:45 +0200636 if (!wdev->conn)
637 return 0;
638
639 if (!rdev->ops->deauth)
640 return -EOPNOTSUPP;
641
642 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
643 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
644 err = 0;
645 goto out;
646 }
647
648 /* wdev->conn->params.bssid must be set if > SCANNING */
649 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
650 wdev->conn->params.bssid,
651 NULL, 0, reason, false);
652 out:
653 cfg80211_sme_free(wdev);
654 return err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900655}
656
Johannes Bergceca7b72013-05-16 00:55:45 +0200657/*
658 * code shared for in-device and software SME
659 */
660
661static bool cfg80211_is_all_idle(void)
662{
663 struct cfg80211_registered_device *rdev;
664 struct wireless_dev *wdev;
665 bool is_all_idle = true;
666
667 /*
668 * All devices must be idle as otherwise if you are actively
669 * scanning some new beacon hints could be learned and would
670 * count as new regulatory hints.
671 */
672 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
Johannes Berg53873f12016-05-03 16:52:04 +0300673 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200674 wdev_lock(wdev);
675 if (wdev->conn || wdev->current_bss)
676 is_all_idle = false;
677 wdev_unlock(wdev);
678 }
679 }
680
681 return is_all_idle;
682}
683
684static void disconnect_work(struct work_struct *work)
685{
686 rtnl_lock();
Sachin Ahuja4216dfb2014-04-28 15:26:53 +0530687 if (cfg80211_is_all_idle() &&
688 !cfg80211_is_all_countryie_ignore())
Johannes Bergceca7b72013-05-16 00:55:45 +0200689 regulatory_hint_disconnect();
690 rtnl_unlock();
691}
692
693static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
694
695
696/*
697 * API calls for drivers implementing connect/disconnect and
698 * SME event handling
699 */
700
Ben Greear6f390902013-06-19 14:06:25 -0700701/* This method must consume bss one way or another */
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300702void __cfg80211_connect_result(struct net_device *dev,
703 struct cfg80211_connect_resp_params *cr,
704 bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200705{
706 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg9caf0362012-11-29 01:25:20 +0100707 const u8 *country_ie;
Johannes Berg3d23e342009-09-29 23:27:28 +0200708#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200709 union iwreq_data wrqu;
710#endif
711
Johannes Berg667503dd2009-07-07 03:56:11 +0200712 ASSERT_WDEV_LOCK(wdev);
713
Johannes Berg074ac8d2010-09-16 14:58:22 +0200714 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
Ben Greear6f390902013-06-19 14:06:25 -0700715 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300716 cfg80211_put_bss(wdev->wiphy, cr->bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200717 return;
Ben Greear6f390902013-06-19 14:06:25 -0700718 }
Samuel Ortizb23aa672009-07-01 21:26:54 +0200719
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300720 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, cr,
721 GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200722
Johannes Berg3d23e342009-09-29 23:27:28 +0200723#ifdef CONFIG_CFG80211_WEXT
Johannes Berge45cd822009-07-02 09:58:04 +0200724 if (wextev) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300725 if (cr->req_ie && cr->status == WLAN_STATUS_SUCCESS) {
Johannes Berge45cd822009-07-02 09:58:04 +0200726 memset(&wrqu, 0, sizeof(wrqu));
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300727 wrqu.data.length = cr->req_ie_len;
728 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu,
729 cr->req_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200730 }
731
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300732 if (cr->resp_ie && cr->status == WLAN_STATUS_SUCCESS) {
Johannes Berge45cd822009-07-02 09:58:04 +0200733 memset(&wrqu, 0, sizeof(wrqu));
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300734 wrqu.data.length = cr->resp_ie_len;
735 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu,
736 cr->resp_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200737 }
738
739 memset(&wrqu, 0, sizeof(wrqu));
740 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300741 if (cr->bssid && cr->status == WLAN_STATUS_SUCCESS) {
742 memcpy(wrqu.ap_addr.sa_data, cr->bssid, ETH_ALEN);
743 memcpy(wdev->wext.prev_bssid, cr->bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200744 wdev->wext.prev_bssid_valid = true;
745 }
Johannes Berge45cd822009-07-02 09:58:04 +0200746 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
747 }
748#endif
749
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300750 if (!cr->bss && (cr->status == WLAN_STATUS_SUCCESS)) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800751 WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect);
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300752 cr->bss = cfg80211_get_bss(wdev->wiphy, NULL, cr->bssid,
753 wdev->ssid, wdev->ssid_len,
754 wdev->conn_bss_type,
755 IEEE80211_PRIVACY_ANY);
756 if (cr->bss)
757 cfg80211_hold_bss(bss_from_pub(cr->bss));
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530758 }
759
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200760 if (wdev->current_bss) {
761 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100762 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200763 wdev->current_bss = NULL;
764 }
765
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300766 if (cr->status != WLAN_STATUS_SUCCESS) {
Johannes Bergb47f6102014-09-10 13:39:54 +0300767 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200769 wdev->ssid_len = 0;
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300770 if (cr->bss) {
771 cfg80211_unhold_bss(bss_from_pub(cr->bss));
772 cfg80211_put_bss(wdev->wiphy, cr->bss);
Johannes Bergf1940c52013-06-19 13:21:15 +0200773 }
Eliad Pellerc1fbb252014-04-30 15:58:13 +0300774 cfg80211_sme_free(wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200775 return;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200776 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200777
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300778 if (WARN_ON(!cr->bss))
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530779 return;
Johannes Bergfffd0932009-07-08 14:22:54 +0200780
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300781 wdev->current_bss = bss_from_pub(cr->bss);
Johannes Bergfffd0932009-07-08 14:22:54 +0200782
David Spinadelb8676222016-09-22 23:16:50 +0300783 if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP))
784 cfg80211_upload_connect_keys(wdev);
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700785
Johannes Berg9caf0362012-11-29 01:25:20 +0100786 rcu_read_lock();
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300787 country_ie = ieee80211_bss_get_ie(cr->bss, WLAN_EID_COUNTRY);
Johannes Berg9caf0362012-11-29 01:25:20 +0100788 if (!country_ie) {
789 rcu_read_unlock();
790 return;
791 }
792
793 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
794 rcu_read_unlock();
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700795
796 if (!country_ie)
797 return;
798
799 /*
800 * ieee80211_bss_get_ie() ensures we can access:
801 * - country_ie + 2, the start of the country ie data, and
802 * - and country_ie[1] which is the IE length
803 */
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300804 regulatory_hint_country_ie(wdev->wiphy, cr->bss->channel->band,
Luis R. Rodriguez789fd032013-10-04 18:07:24 -0700805 country_ie + 2, country_ie[1]);
Johannes Berg9caf0362012-11-29 01:25:20 +0100806 kfree(country_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200807}
Johannes Bergf2129352009-07-01 21:26:56 +0200808
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530809/* Consumes bss object one way or another */
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300810void cfg80211_connect_done(struct net_device *dev,
811 struct cfg80211_connect_resp_params *params,
812 gfp_t gfp)
Johannes Bergf2129352009-07-01 21:26:56 +0200813{
Johannes Berg667503dd2009-07-07 03:56:11 +0200814 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800815 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503dd2009-07-07 03:56:11 +0200816 struct cfg80211_event *ev;
817 unsigned long flags;
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300818 u8 *next;
Johannes Berg667503dd2009-07-07 03:56:11 +0200819
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300820 if (params->bss) {
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530821 /* Make sure the bss entry provided by the driver is valid. */
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300822 struct cfg80211_internal_bss *ibss = bss_from_pub(params->bss);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530823
824 if (WARN_ON(list_empty(&ibss->list))) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300825 cfg80211_put_bss(wdev->wiphy, params->bss);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530826 return;
827 }
828 }
829
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300830 ev = kzalloc(sizeof(*ev) + (params->bssid ? ETH_ALEN : 0) +
831 params->req_ie_len + params->resp_ie_len, gfp);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530832 if (!ev) {
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300833 cfg80211_put_bss(wdev->wiphy, params->bss);
Johannes Berg667503dd2009-07-07 03:56:11 +0200834 return;
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530835 }
Johannes Berg667503dd2009-07-07 03:56:11 +0200836
837 ev->type = EVENT_CONNECT_RESULT;
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300838 next = ((u8 *)ev) + sizeof(*ev);
839 if (params->bssid) {
840 ev->cr.bssid = next;
841 memcpy((void *)ev->cr.bssid, params->bssid, ETH_ALEN);
842 next += ETH_ALEN;
Nishant Sarmukadam7834704b2010-04-14 22:03:02 -0700843 }
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300844 if (params->req_ie_len) {
845 ev->cr.req_ie = next;
846 ev->cr.req_ie_len = params->req_ie_len;
847 memcpy((void *)ev->cr.req_ie, params->req_ie,
848 params->req_ie_len);
849 next += params->req_ie_len;
Nishant Sarmukadam7834704b2010-04-14 22:03:02 -0700850 }
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300851 if (params->resp_ie_len) {
852 ev->cr.resp_ie = next;
853 ev->cr.resp_ie_len = params->resp_ie_len;
854 memcpy((void *)ev->cr.resp_ie, params->resp_ie,
855 params->resp_ie_len);
856 next += params->resp_ie_len;
857 }
858 if (params->bss)
859 cfg80211_hold_bss(bss_from_pub(params->bss));
860 ev->cr.bss = params->bss;
861 ev->cr.status = params->status;
862 ev->cr.timeout_reason = params->timeout_reason;
Johannes Berg667503dd2009-07-07 03:56:11 +0200863
864 spin_lock_irqsave(&wdev->event_lock, flags);
865 list_add_tail(&ev->list, &wdev->event_list);
866 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100867 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Bergf2129352009-07-01 21:26:56 +0200868}
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +0300869EXPORT_SYMBOL(cfg80211_connect_done);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200870
Ben Greear0e3a39b2013-06-19 14:06:27 -0700871/* Consumes bss object one way or another */
Jouni Malinened9d0102011-05-16 19:40:15 +0300872void __cfg80211_roamed(struct wireless_dev *wdev,
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530873 struct cfg80211_bss *bss,
Johannes Berg667503dd2009-07-07 03:56:11 +0200874 const u8 *req_ie, size_t req_ie_len,
875 const u8 *resp_ie, size_t resp_ie_len)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200876{
Johannes Berg3d23e342009-09-29 23:27:28 +0200877#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200878 union iwreq_data wrqu;
879#endif
Johannes Berg667503dd2009-07-07 03:56:11 +0200880 ASSERT_WDEV_LOCK(wdev);
881
Johannes Berg074ac8d2010-09-16 14:58:22 +0200882 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
883 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530884 goto out;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200885
Johannes Bergceca7b72013-05-16 00:55:45 +0200886 if (WARN_ON(!wdev->current_bss))
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530887 goto out;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200888
Samuel Ortizb23aa672009-07-01 21:26:54 +0200889 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100890 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200891 wdev->current_bss = NULL;
892
Johannes Berg19957bb2009-07-02 17:20:43 +0200893 cfg80211_hold_bss(bss_from_pub(bss));
894 wdev->current_bss = bss_from_pub(bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200895
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800896 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
897 wdev->netdev, bss->bssid,
Johannes Berg667503dd2009-07-07 03:56:11 +0200898 req_ie, req_ie_len, resp_ie, resp_ie_len,
899 GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200900
Johannes Berg3d23e342009-09-29 23:27:28 +0200901#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200902 if (req_ie) {
903 memset(&wrqu, 0, sizeof(wrqu));
904 wrqu.data.length = req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800905 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
Johannes Berg667503dd2009-07-07 03:56:11 +0200906 &wrqu, req_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200907 }
908
909 if (resp_ie) {
910 memset(&wrqu, 0, sizeof(wrqu));
911 wrqu.data.length = resp_ie_len;
Johannes Berg667503dd2009-07-07 03:56:11 +0200912 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
913 &wrqu, resp_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200914 }
915
916 memset(&wrqu, 0, sizeof(wrqu));
917 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530918 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
919 memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200920 wdev->wext.prev_bssid_valid = true;
Johannes Berg667503dd2009-07-07 03:56:11 +0200921 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200922#endif
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530923
924 return;
925out:
Johannes Berg5b112d32013-02-01 01:49:58 +0100926 cfg80211_put_bss(wdev->wiphy, bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200927}
Johannes Berg667503dd2009-07-07 03:56:11 +0200928
Jouni Malinened9d0102011-05-16 19:40:15 +0300929void cfg80211_roamed(struct net_device *dev,
930 struct ieee80211_channel *channel,
931 const u8 *bssid,
Johannes Berg667503dd2009-07-07 03:56:11 +0200932 const u8 *req_ie, size_t req_ie_len,
933 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
934{
935 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530936 struct cfg80211_bss *bss;
937
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530938 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200939 wdev->ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200940 wdev->conn_bss_type, IEEE80211_PRIVACY_ANY);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530941 if (WARN_ON(!bss))
942 return;
943
944 cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie,
945 resp_ie_len, gfp);
946}
947EXPORT_SYMBOL(cfg80211_roamed);
948
Ben Greear0e3a39b2013-06-19 14:06:27 -0700949/* Consumes bss object one way or another */
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530950void cfg80211_roamed_bss(struct net_device *dev,
951 struct cfg80211_bss *bss, const u8 *req_ie,
952 size_t req_ie_len, const u8 *resp_ie,
953 size_t resp_ie_len, gfp_t gfp)
954{
955 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800956 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503dd2009-07-07 03:56:11 +0200957 struct cfg80211_event *ev;
958 unsigned long flags;
959
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530960 if (WARN_ON(!bss))
Johannes Berg667503dd2009-07-07 03:56:11 +0200961 return;
962
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530963 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
964 if (!ev) {
Johannes Berg5b112d32013-02-01 01:49:58 +0100965 cfg80211_put_bss(wdev->wiphy, bss);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530966 return;
967 }
968
Johannes Berg667503dd2009-07-07 03:56:11 +0200969 ev->type = EVENT_ROAMED;
Johannes Berg667503dd2009-07-07 03:56:11 +0200970 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
971 ev->rm.req_ie_len = req_ie_len;
972 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
973 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
974 ev->rm.resp_ie_len = resp_ie_len;
975 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530976 ev->rm.bss = bss;
Johannes Berg667503dd2009-07-07 03:56:11 +0200977
978 spin_lock_irqsave(&wdev->event_lock, flags);
979 list_add_tail(&ev->list, &wdev->event_list);
980 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100981 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Berg667503dd2009-07-07 03:56:11 +0200982}
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530983EXPORT_SYMBOL(cfg80211_roamed_bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200984
Johannes Berg667503dd2009-07-07 03:56:11 +0200985void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
Johannes Berg6829c872009-07-02 09:13:27 +0200986 size_t ie_len, u16 reason, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200987{
988 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800989 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergfffd0932009-07-08 14:22:54 +0200990 int i;
Johannes Berg3d23e342009-09-29 23:27:28 +0200991#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200992 union iwreq_data wrqu;
993#endif
994
Johannes Berg667503dd2009-07-07 03:56:11 +0200995 ASSERT_WDEV_LOCK(wdev);
996
Johannes Berg074ac8d2010-09-16 14:58:22 +0200997 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
998 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
Samuel Ortizb23aa672009-07-01 21:26:54 +0200999 return;
1000
Samuel Ortizb23aa672009-07-01 21:26:54 +02001001 if (wdev->current_bss) {
1002 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +01001003 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001004 }
1005
1006 wdev->current_bss = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +02001007 wdev->ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001008
Johannes Bergfffd0932009-07-08 14:22:54 +02001009 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
1010
Arend van Sprielb8607152016-02-15 14:35:53 +01001011 /* stop critical protocol if supported */
1012 if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) {
1013 rdev->crit_proto_nlportid = 0;
1014 rdev_crit_proto_stop(rdev, wdev);
1015 }
1016
Johannes Bergfffd0932009-07-08 14:22:54 +02001017 /*
1018 * Delete all the keys ... pairwise keys can't really
1019 * exist any more anyway, but default keys might.
1020 */
1021 if (rdev->ops->del_key)
1022 for (i = 0; i < 6; i++)
Hila Gonene35e4d22012-06-27 17:19:42 +03001023 rdev_del_key(rdev, dev, i, false, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001024
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001025 rdev_set_qos_map(rdev, dev, NULL);
1026
Johannes Berg3d23e342009-09-29 23:27:28 +02001027#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +02001028 memset(&wrqu, 0, sizeof(wrqu));
1029 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1030 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Abhijeet Kolekar5f612032010-01-13 13:23:14 -08001031 wdev->wext.connect.ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001032#endif
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -05001033
1034 schedule_work(&cfg80211_disconnect_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001035}
1036
1037void cfg80211_disconnected(struct net_device *dev, u16 reason,
Johannes Berg80279fb2015-05-22 16:22:20 +02001038 const u8 *ie, size_t ie_len,
1039 bool locally_generated, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001040{
Johannes Berg667503dd2009-07-07 03:56:11 +02001041 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001042 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503dd2009-07-07 03:56:11 +02001043 struct cfg80211_event *ev;
1044 unsigned long flags;
1045
1046 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
1047 if (!ev)
1048 return;
1049
1050 ev->type = EVENT_DISCONNECTED;
1051 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
1052 ev->dc.ie_len = ie_len;
1053 memcpy((void *)ev->dc.ie, ie, ie_len);
1054 ev->dc.reason = reason;
Johannes Berg80279fb2015-05-22 16:22:20 +02001055 ev->dc.locally_generated = locally_generated;
Johannes Berg667503dd2009-07-07 03:56:11 +02001056
1057 spin_lock_irqsave(&wdev->event_lock, flags);
1058 list_add_tail(&ev->list, &wdev->event_list);
1059 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +01001060 queue_work(cfg80211_wq, &rdev->event_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001061}
1062EXPORT_SYMBOL(cfg80211_disconnected);
1063
Johannes Bergceca7b72013-05-16 00:55:45 +02001064/*
1065 * API calls for nl80211/wext compatibility code
1066 */
Johannes Berg83739b02013-05-15 17:44:01 +02001067int cfg80211_connect(struct cfg80211_registered_device *rdev,
1068 struct net_device *dev,
1069 struct cfg80211_connect_params *connect,
1070 struct cfg80211_cached_keys *connkeys,
1071 const u8 *prev_bssid)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001072{
Samuel Ortizb23aa672009-07-01 21:26:54 +02001073 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg667503dd2009-07-07 03:56:11 +02001074 int err;
1075
1076 ASSERT_WDEV_LOCK(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001077
Johannes Bergfffd0932009-07-08 14:22:54 +02001078 if (WARN_ON(wdev->connect_keys)) {
Johannes Bergb47f6102014-09-10 13:39:54 +03001079 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001080 wdev->connect_keys = NULL;
1081 }
1082
Ben Greear7e7c8922011-11-18 11:31:59 -08001083 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
1084 rdev->wiphy.ht_capa_mod_mask);
1085
Johannes Bergfffd0932009-07-08 14:22:54 +02001086 if (connkeys && connkeys->def >= 0) {
1087 int idx;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001088 u32 cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001089
1090 idx = connkeys->def;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001091 cipher = connkeys->params[idx].cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001092 /* If given a WEP key we may need it for shared key auth */
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001093 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
1094 cipher == WLAN_CIPHER_SUITE_WEP104) {
Johannes Bergfffd0932009-07-08 14:22:54 +02001095 connect->key_idx = idx;
1096 connect->key = connkeys->params[idx].key;
1097 connect->key_len = connkeys->params[idx].key_len;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001098
1099 /*
1100 * If ciphers are not set (e.g. when going through
1101 * iwconfig), we have to set them appropriately here.
1102 */
1103 if (connect->crypto.cipher_group == 0)
1104 connect->crypto.cipher_group = cipher;
1105
1106 if (connect->crypto.n_ciphers_pairwise == 0) {
1107 connect->crypto.n_ciphers_pairwise = 1;
1108 connect->crypto.ciphers_pairwise[0] = cipher;
1109 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001110 }
David Spinadelb8676222016-09-22 23:16:50 +03001111
1112 connect->crypto.wep_keys = connkeys->params;
1113 connect->crypto.wep_tx_key = connkeys->def;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001114 } else {
1115 if (WARN_ON(connkeys))
1116 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001117 }
1118
Johannes Bergceca7b72013-05-16 00:55:45 +02001119 wdev->connect_keys = connkeys;
1120 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
1121 wdev->ssid_len = connect->ssid_len;
Johannes Berg6829c872009-07-02 09:13:27 +02001122
Lior David34d50512016-01-28 10:58:25 +02001123 wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS :
1124 IEEE80211_BSS_TYPE_ESS;
1125
Johannes Bergceca7b72013-05-16 00:55:45 +02001126 if (!rdev->ops->connect)
1127 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
1128 else
Hila Gonene35e4d22012-06-27 17:19:42 +03001129 err = rdev_connect(rdev, dev, connect);
Johannes Berg6829c872009-07-02 09:13:27 +02001130
Johannes Bergceca7b72013-05-16 00:55:45 +02001131 if (err) {
1132 wdev->connect_keys = NULL;
1133 wdev->ssid_len = 0;
1134 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001135 }
Johannes Bergceca7b72013-05-16 00:55:45 +02001136
1137 return 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001138}
1139
Johannes Berg83739b02013-05-15 17:44:01 +02001140int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
1141 struct net_device *dev, u16 reason, bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001142{
Johannes Berg6829c872009-07-02 09:13:27 +02001143 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergdee8a972013-08-13 09:23:57 +02001144 int err = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001145
Johannes Berg667503dd2009-07-07 03:56:11 +02001146 ASSERT_WDEV_LOCK(wdev);
1147
Johannes Bergb47f6102014-09-10 13:39:54 +03001148 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001149 wdev->connect_keys = NULL;
1150
Johannes Bergdee8a972013-08-13 09:23:57 +02001151 if (wdev->conn)
Johannes Bergceca7b72013-05-16 00:55:45 +02001152 err = cfg80211_sme_disconnect(wdev, reason);
Johannes Bergdee8a972013-08-13 09:23:57 +02001153 else if (!rdev->ops->disconnect)
Johannes Bergceca7b72013-05-16 00:55:45 +02001154 cfg80211_mlme_down(rdev, dev);
Johannes Bergdee8a972013-08-13 09:23:57 +02001155 else if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +03001156 err = rdev_disconnect(rdev, dev, reason);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001157
Johannes Bergceca7b72013-05-16 00:55:45 +02001158 return err;
Johannes Berg19957bb2009-07-02 17:20:43 +02001159}