blob: 37cea4d98879979a013a5507a99bb2c6c79b917c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Samuel Ortizb23aa672009-07-01 21:26:54 +02002/*
Johannes Bergceca7b72013-05-16 00:55:45 +02003 * SME code for cfg80211
4 * both driver SME event handling and the SME implementation
5 * (for nl80211's connect() and wext)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006 *
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
8 * Copyright (C) 2009 Intel Corporation. All rights reserved.
Avraham Stern29ce6ec2017-04-26 10:58:49 +03009 * Copyright 2017 Intel Deutschland GmbH
Samuel Ortizb23aa672009-07-01 21:26:54 +020010 */
11
12#include <linux/etherdevice.h>
13#include <linux/if_arp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Samuel Ortizb23aa672009-07-01 21:26:54 +020015#include <linux/workqueue.h>
Johannes Berga9a11622009-07-27 12:01:53 +020016#include <linux/wireless.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040017#include <linux/export.h>
Johannes Berga9a11622009-07-27 12:01:53 +020018#include <net/iw_handler.h>
Samuel Ortizb23aa672009-07-01 21:26:54 +020019#include <net/cfg80211.h>
20#include <net/rtnetlink.h>
21#include "nl80211.h"
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -070022#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030023#include "rdev-ops.h"
Samuel Ortizb23aa672009-07-01 21:26:54 +020024
Johannes Bergceca7b72013-05-16 00:55:45 +020025/*
26 * Software SME in cfg80211, using auth/assoc/deauth calls to the
27 * driver. This is is for implementing nl80211's connect/disconnect
28 * and wireless extensions (if configured.)
29 */
30
Johannes Berg6829c872009-07-02 09:13:27 +020031struct cfg80211_conn {
32 struct cfg80211_connect_params params;
33 /* these are sub-states of the _CONNECTING sme_state */
34 enum {
Johannes Berg6829c872009-07-02 09:13:27 +020035 CFG80211_CONN_SCANNING,
36 CFG80211_CONN_SCAN_AGAIN,
37 CFG80211_CONN_AUTHENTICATE_NEXT,
38 CFG80211_CONN_AUTHENTICATING,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020039 CFG80211_CONN_AUTH_FAILED_TIMEOUT,
Johannes Berg6829c872009-07-02 09:13:27 +020040 CFG80211_CONN_ASSOCIATE_NEXT,
41 CFG80211_CONN_ASSOCIATING,
Johannes Berg923a0e72013-06-28 11:38:54 +020042 CFG80211_CONN_ASSOC_FAILED,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020043 CFG80211_CONN_ASSOC_FAILED_TIMEOUT,
Johannes Bergceca7b72013-05-16 00:55:45 +020044 CFG80211_CONN_DEAUTH,
Johannes Berge6f462d2016-12-08 17:22:09 +010045 CFG80211_CONN_ABANDON,
Johannes Bergceca7b72013-05-16 00:55:45 +020046 CFG80211_CONN_CONNECTED,
Johannes Berg6829c872009-07-02 09:13:27 +020047 } state;
Johannes Bergf401a6f2009-08-07 14:51:05 +020048 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
Johannes Berg46b9d182015-03-31 16:09:13 +020049 const u8 *ie;
Johannes Berg6829c872009-07-02 09:13:27 +020050 size_t ie_len;
Johannes Bergf401a6f2009-08-07 14:51:05 +020051 bool auto_auth, prev_bssid_valid;
Johannes Berg6829c872009-07-02 09:13:27 +020052};
53
Johannes Bergceca7b72013-05-16 00:55:45 +020054static void cfg80211_sme_free(struct wireless_dev *wdev)
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050055{
Johannes Bergceca7b72013-05-16 00:55:45 +020056 if (!wdev->conn)
57 return;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050058
Johannes Bergceca7b72013-05-16 00:55:45 +020059 kfree(wdev->conn->ie);
60 kfree(wdev->conn);
61 wdev->conn = NULL;
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050062}
63
Johannes Berg6829c872009-07-02 09:13:27 +020064static int cfg80211_conn_scan(struct wireless_dev *wdev)
65{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080066 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020067 struct cfg80211_scan_request *request;
68 int n_channels, err;
69
70 ASSERT_RTNL();
Johannes Berg667503d2009-07-07 03:56:11 +020071 ASSERT_WDEV_LOCK(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +020072
Johannes Bergf9d15d12014-01-22 11:14:19 +020073 if (rdev->scan_req || rdev->scan_msg)
Johannes Berg6829c872009-07-02 09:13:27 +020074 return -EBUSY;
75
Ilan Peerbdfbec22014-01-09 11:37:23 +020076 if (wdev->conn->params.channel)
Johannes Berg6829c872009-07-02 09:13:27 +020077 n_channels = 1;
Ilan Peerbdfbec22014-01-09 11:37:23 +020078 else
79 n_channels = ieee80211_get_num_supported_channels(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +020080
Johannes Berg6829c872009-07-02 09:13:27 +020081 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
82 sizeof(request->channels[0]) * n_channels,
83 GFP_KERNEL);
84 if (!request)
85 return -ENOMEM;
86
Karl Beldan2a84ee82014-10-07 11:42:18 +020087 if (wdev->conn->params.channel) {
Johannes Berg57fbcce2016-04-12 15:56:15 +020088 enum nl80211_band band = wdev->conn->params.channel->band;
Karl Beldan2a84ee82014-10-07 11:42:18 +020089 struct ieee80211_supported_band *sband =
90 wdev->wiphy->bands[band];
91
92 if (!sband) {
93 kfree(request);
94 return -EINVAL;
95 }
Johannes Berg6829c872009-07-02 09:13:27 +020096 request->channels[0] = wdev->conn->params.channel;
Karl Beldan2a84ee82014-10-07 11:42:18 +020097 request->rates[band] = (1 << sband->n_bitrates) - 1;
98 } else {
Johannes Berg6829c872009-07-02 09:13:27 +020099 int i = 0, j;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200100 enum nl80211_band band;
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530101 struct ieee80211_supported_band *bands;
102 struct ieee80211_channel *channel;
Johannes Berg6829c872009-07-02 09:13:27 +0200103
Johannes Berg57fbcce2016-04-12 15:56:15 +0200104 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530105 bands = wdev->wiphy->bands[band];
106 if (!bands)
Johannes Berg6829c872009-07-02 09:13:27 +0200107 continue;
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530108 for (j = 0; j < bands->n_channels; j++) {
109 channel = &bands->channels[j];
110 if (channel->flags & IEEE80211_CHAN_DISABLED)
111 continue;
112 request->channels[i++] = channel;
113 }
114 request->rates[band] = (1 << bands->n_bitrates) - 1;
Johannes Berg6829c872009-07-02 09:13:27 +0200115 }
Rajkumar Manoharane3081502011-09-15 17:40:50 +0530116 n_channels = i;
Johannes Berg6829c872009-07-02 09:13:27 +0200117 }
118 request->n_channels = n_channels;
Johannes Berg5ba63532009-08-07 17:54:07 +0200119 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg6829c872009-07-02 09:13:27 +0200120 request->n_ssids = 1;
121
122 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
123 wdev->conn->params.ssid_len);
124 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
125
Jouni Malinen818965d2016-02-26 22:12:47 +0200126 eth_broadcast_addr(request->bssid);
127
Johannes Bergfd014282012-06-18 19:17:03 +0200128 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +0200129 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -0700130 request->scan_start = jiffies;
Johannes Berg6829c872009-07-02 09:13:27 +0200131
Johannes Berg79c97e92009-07-07 03:56:12 +0200132 rdev->scan_req = request;
Johannes Berg6829c872009-07-02 09:13:27 +0200133
Hila Gonene35e4d22012-06-27 17:19:42 +0300134 err = rdev_scan(rdev, request);
Johannes Berg6829c872009-07-02 09:13:27 +0200135 if (!err) {
136 wdev->conn->state = CFG80211_CONN_SCANNING;
Johannes Bergfd014282012-06-18 19:17:03 +0200137 nl80211_send_scan_start(rdev, wdev);
Johannes Berg463d0182009-07-14 00:33:35 +0200138 dev_hold(wdev->netdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200139 } else {
Johannes Berg79c97e92009-07-07 03:56:12 +0200140 rdev->scan_req = NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200141 kfree(request);
142 }
143 return err;
144}
145
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200146static int cfg80211_conn_do_work(struct wireless_dev *wdev,
147 enum nl80211_timeout_reason *treason)
Johannes Berg6829c872009-07-02 09:13:27 +0200148{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800149 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg19957bb2009-07-02 17:20:43 +0200150 struct cfg80211_connect_params *params;
Johannes Bergf62fab72013-02-21 20:09:09 +0100151 struct cfg80211_assoc_request req = {};
Johannes Berg19957bb2009-07-02 17:20:43 +0200152 int err;
Johannes Berg6829c872009-07-02 09:13:27 +0200153
Johannes Berg667503d2009-07-07 03:56:11 +0200154 ASSERT_WDEV_LOCK(wdev);
155
Johannes Berg6829c872009-07-02 09:13:27 +0200156 if (!wdev->conn)
157 return 0;
158
Johannes Berg19957bb2009-07-02 17:20:43 +0200159 params = &wdev->conn->params;
160
Johannes Berg6829c872009-07-02 09:13:27 +0200161 switch (wdev->conn->state) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200162 case CFG80211_CONN_SCANNING:
163 /* didn't find it during scan ... */
164 return -ENOENT;
Johannes Berg6829c872009-07-02 09:13:27 +0200165 case CFG80211_CONN_SCAN_AGAIN:
166 return cfg80211_conn_scan(wdev);
167 case CFG80211_CONN_AUTHENTICATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200168 if (WARN_ON(!rdev->ops->auth))
169 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200170 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
Johannes Berg91bf9b22013-05-15 17:44:01 +0200171 return cfg80211_mlme_auth(rdev, wdev->netdev,
172 params->channel, params->auth_type,
173 params->bssid,
174 params->ssid, params->ssid_len,
175 NULL, 0,
176 params->key, params->key_len,
177 params->key_idx, NULL, 0);
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200178 case CFG80211_CONN_AUTH_FAILED_TIMEOUT:
179 *treason = NL80211_TIMEOUT_AUTH;
Johannes Berg923a0e72013-06-28 11:38:54 +0200180 return -ENOTCONN;
Johannes Berg6829c872009-07-02 09:13:27 +0200181 case CFG80211_CONN_ASSOCIATE_NEXT:
Johannes Berg2fd05112014-04-29 17:52:36 +0200182 if (WARN_ON(!rdev->ops->assoc))
183 return -EOPNOTSUPP;
Johannes Berg19957bb2009-07-02 17:20:43 +0200184 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200185 if (wdev->conn->prev_bssid_valid)
Johannes Bergf62fab72013-02-21 20:09:09 +0100186 req.prev_bssid = wdev->conn->prev_bssid;
187 req.ie = params->ie;
188 req.ie_len = params->ie_len;
189 req.use_mfp = params->mfp != NL80211_MFP_NO;
190 req.crypto = params->crypto;
191 req.flags = params->flags;
192 req.ht_capa = params->ht_capa;
193 req.ht_capa_mask = params->ht_capa_mask;
194 req.vht_capa = params->vht_capa;
195 req.vht_capa_mask = params->vht_capa_mask;
196
Johannes Berg91bf9b22013-05-15 17:44:01 +0200197 err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
198 params->bssid, params->ssid,
199 params->ssid_len, &req);
Johannes Berg19957bb2009-07-02 17:20:43 +0200200 if (err)
Johannes Berg91bf9b22013-05-15 17:44:01 +0200201 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
202 NULL, 0,
203 WLAN_REASON_DEAUTH_LEAVING,
204 false);
Johannes Berg19957bb2009-07-02 17:20:43 +0200205 return err;
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200206 case CFG80211_CONN_ASSOC_FAILED_TIMEOUT:
207 *treason = NL80211_TIMEOUT_ASSOC;
208 /* fall through */
Johannes Berg923a0e72013-06-28 11:38:54 +0200209 case CFG80211_CONN_ASSOC_FAILED:
210 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
211 NULL, 0,
212 WLAN_REASON_DEAUTH_LEAVING, false);
213 return -ENOTCONN;
Johannes Bergceca7b72013-05-16 00:55:45 +0200214 case CFG80211_CONN_DEAUTH:
Johannes Berg91bf9b22013-05-15 17:44:01 +0200215 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
216 NULL, 0,
217 WLAN_REASON_DEAUTH_LEAVING, false);
Johannes Berge6f462d2016-12-08 17:22:09 +0100218 /* fall through */
219 case CFG80211_CONN_ABANDON:
Johannes Berg923a0e72013-06-28 11:38:54 +0200220 /* free directly, disconnected event already sent */
221 cfg80211_sme_free(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200222 return 0;
Johannes Berg6829c872009-07-02 09:13:27 +0200223 default:
224 return 0;
225 }
226}
227
228void cfg80211_conn_work(struct work_struct *work)
229{
Johannes Berg79c97e92009-07-07 03:56:12 +0200230 struct cfg80211_registered_device *rdev =
Johannes Berg6829c872009-07-02 09:13:27 +0200231 container_of(work, struct cfg80211_registered_device, conn_work);
232 struct wireless_dev *wdev;
Johannes Berg7400f422009-10-31 07:40:37 +0100233 u8 bssid_buf[ETH_ALEN], *bssid = NULL;
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200234 enum nl80211_timeout_reason treason;
Johannes Berg6829c872009-07-02 09:13:27 +0200235
236 rtnl_lock();
Johannes Berg6829c872009-07-02 09:13:27 +0200237
Johannes Berg53873f12016-05-03 16:52:04 +0300238 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergc8157972013-05-23 18:10:21 +0200239 if (!wdev->netdev)
240 continue;
241
Johannes Berg667503d2009-07-07 03:56:11 +0200242 wdev_lock(wdev);
243 if (!netif_running(wdev->netdev)) {
244 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200245 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200246 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200247 if (!wdev->conn ||
248 wdev->conn->state == CFG80211_CONN_CONNECTED) {
Johannes Berg667503d2009-07-07 03:56:11 +0200249 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200250 continue;
Johannes Berg667503d2009-07-07 03:56:11 +0200251 }
Johannes Berg7400f422009-10-31 07:40:37 +0100252 if (wdev->conn->params.bssid) {
253 memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN);
254 bssid = bssid_buf;
255 }
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200256 treason = NL80211_TIMEOUT_UNSPECIFIED;
257 if (cfg80211_conn_do_work(wdev, &treason)) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300258 struct cfg80211_connect_resp_params cr;
259
260 memset(&cr, 0, sizeof(cr));
261 cr.status = -1;
262 cr.bssid = bssid;
263 cr.timeout_reason = treason;
264 __cfg80211_connect_result(wdev->netdev, &cr, false);
Johannes Bergceca7b72013-05-16 00:55:45 +0200265 }
Johannes Berg667503d2009-07-07 03:56:11 +0200266 wdev_unlock(wdev);
Johannes Berg6829c872009-07-02 09:13:27 +0200267 }
268
Johannes Berg6829c872009-07-02 09:13:27 +0200269 rtnl_unlock();
270}
271
Ben Greear0e3a39b2013-06-19 14:06:27 -0700272/* Returned bss is reference counted and must be cleaned up appropriately. */
Johannes Bergbbac31f2009-09-16 09:04:26 -0700273static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev)
Johannes Berg6829c872009-07-02 09:13:27 +0200274{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800275 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200276 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200277
Johannes Berg667503d2009-07-07 03:56:11 +0200278 ASSERT_WDEV_LOCK(wdev);
279
Jouni Malinened9d0102011-05-16 19:40:15 +0300280 bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel,
281 wdev->conn->params.bssid,
Johannes Berg6829c872009-07-02 09:13:27 +0200282 wdev->conn->params.ssid,
283 wdev->conn->params.ssid_len,
Lior David34d50512016-01-28 10:58:25 +0200284 wdev->conn_bss_type,
Dedy Lansky6eb18132015-02-08 15:52:03 +0200285 IEEE80211_PRIVACY(wdev->conn->params.privacy));
Johannes Berg6829c872009-07-02 09:13:27 +0200286 if (!bss)
Johannes Bergbbac31f2009-09-16 09:04:26 -0700287 return NULL;
Johannes Berg6829c872009-07-02 09:13:27 +0200288
289 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
290 wdev->conn->params.bssid = wdev->conn->bssid;
291 wdev->conn->params.channel = bss->channel;
292 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
Johannes Berg79c97e92009-07-07 03:56:12 +0200293 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200294
Johannes Bergbbac31f2009-09-16 09:04:26 -0700295 return bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200296}
297
Johannes Berg667503d2009-07-07 03:56:11 +0200298static void __cfg80211_sme_scan_done(struct net_device *dev)
Johannes Berg6829c872009-07-02 09:13:27 +0200299{
300 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800301 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergbbac31f2009-09-16 09:04:26 -0700302 struct cfg80211_bss *bss;
Johannes Berg6829c872009-07-02 09:13:27 +0200303
Johannes Berg667503d2009-07-07 03:56:11 +0200304 ASSERT_WDEV_LOCK(wdev);
305
Zhu Yid4b1a682009-07-16 17:34:14 +0800306 if (!wdev->conn)
Johannes Berg6829c872009-07-02 09:13:27 +0200307 return;
308
309 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
310 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
311 return;
312
Johannes Bergbbac31f2009-09-16 09:04:26 -0700313 bss = cfg80211_get_conn_bss(wdev);
Johannes Bergceca7b72013-05-16 00:55:45 +0200314 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100315 cfg80211_put_bss(&rdev->wiphy, bss);
Johannes Bergceca7b72013-05-16 00:55:45 +0200316 else
317 schedule_work(&rdev->conn_work);
Johannes Berg6829c872009-07-02 09:13:27 +0200318}
319
Johannes Berg667503d2009-07-07 03:56:11 +0200320void cfg80211_sme_scan_done(struct net_device *dev)
321{
322 struct wireless_dev *wdev = dev->ieee80211_ptr;
323
324 wdev_lock(wdev);
325 __cfg80211_sme_scan_done(dev);
326 wdev_unlock(wdev);
327}
328
Johannes Bergceca7b72013-05-16 00:55:45 +0200329void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len)
Johannes Berg6829c872009-07-02 09:13:27 +0200330{
Johannes Berg6829c872009-07-02 09:13:27 +0200331 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6829c872009-07-02 09:13:27 +0200333 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
334 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
335
Johannes Berg667503d2009-07-07 03:56:11 +0200336 ASSERT_WDEV_LOCK(wdev);
337
Johannes Bergceca7b72013-05-16 00:55:45 +0200338 if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED)
Johannes Berg6829c872009-07-02 09:13:27 +0200339 return;
340
341 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
342 wdev->conn->auto_auth &&
343 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
344 /* select automatically between only open, shared, leap */
345 switch (wdev->conn->params.auth_type) {
346 case NL80211_AUTHTYPE_OPEN_SYSTEM:
Johannes Bergfffd0932009-07-08 14:22:54 +0200347 if (wdev->connect_keys)
348 wdev->conn->params.auth_type =
349 NL80211_AUTHTYPE_SHARED_KEY;
350 else
351 wdev->conn->params.auth_type =
352 NL80211_AUTHTYPE_NETWORK_EAP;
Johannes Berg6829c872009-07-02 09:13:27 +0200353 break;
354 case NL80211_AUTHTYPE_SHARED_KEY:
355 wdev->conn->params.auth_type =
356 NL80211_AUTHTYPE_NETWORK_EAP;
357 break;
358 default:
359 /* huh? */
360 wdev->conn->params.auth_type =
361 NL80211_AUTHTYPE_OPEN_SYSTEM;
362 break;
363 }
364 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
365 schedule_work(&rdev->conn_work);
Johannes Berg19957bb2009-07-02 17:20:43 +0200366 } else if (status_code != WLAN_STATUS_SUCCESS) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300367 struct cfg80211_connect_resp_params cr;
368
369 memset(&cr, 0, sizeof(cr));
370 cr.status = status_code;
371 cr.bssid = mgmt->bssid;
372 cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED;
373 __cfg80211_connect_result(wdev->netdev, &cr, false);
Johannes Bergceca7b72013-05-16 00:55:45 +0200374 } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
Johannes Berg6829c872009-07-02 09:13:27 +0200375 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
376 schedule_work(&rdev->conn_work);
377 }
378}
Samuel Ortizb23aa672009-07-01 21:26:54 +0200379
Johannes Bergceca7b72013-05-16 00:55:45 +0200380bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200381{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800382 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200383
Johannes Bergceca7b72013-05-16 00:55:45 +0200384 if (!wdev->conn)
Johannes Bergf401a6f2009-08-07 14:51:05 +0200385 return false;
386
Johannes Bergceca7b72013-05-16 00:55:45 +0200387 if (status == WLAN_STATUS_SUCCESS) {
388 wdev->conn->state = CFG80211_CONN_CONNECTED;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200389 return false;
Johannes Bergceca7b72013-05-16 00:55:45 +0200390 }
391
392 if (wdev->conn->prev_bssid_valid) {
393 /*
394 * Some stupid APs don't accept reassoc, so we
395 * need to fall back to trying regular assoc;
396 * return true so no event is sent to userspace.
397 */
398 wdev->conn->prev_bssid_valid = false;
399 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
400 schedule_work(&rdev->conn_work);
401 return true;
402 }
403
Johannes Berg923a0e72013-06-28 11:38:54 +0200404 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
Johannes Bergceca7b72013-05-16 00:55:45 +0200405 schedule_work(&rdev->conn_work);
406 return false;
407}
408
409void cfg80211_sme_deauth(struct wireless_dev *wdev)
410{
411 cfg80211_sme_free(wdev);
412}
413
414void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
415{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800416 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200417
418 if (!wdev->conn)
419 return;
420
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200421 wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200422 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200423}
424
425void cfg80211_sme_disassoc(struct wireless_dev *wdev)
426{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800427 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200428
429 if (!wdev->conn)
430 return;
431
432 wdev->conn->state = CFG80211_CONN_DEAUTH;
433 schedule_work(&rdev->conn_work);
434}
435
436void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
437{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800438 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg923a0e72013-06-28 11:38:54 +0200439
440 if (!wdev->conn)
441 return;
442
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200443 wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT;
Johannes Berg923a0e72013-06-28 11:38:54 +0200444 schedule_work(&rdev->conn_work);
Johannes Bergceca7b72013-05-16 00:55:45 +0200445}
446
Johannes Berge6f462d2016-12-08 17:22:09 +0100447void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev)
448{
449 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
450
451 if (!wdev->conn)
452 return;
453
454 wdev->conn->state = CFG80211_CONN_ABANDON;
455 schedule_work(&rdev->conn_work);
456}
457
Johannes Berg46b9d182015-03-31 16:09:13 +0200458static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev,
459 const u8 *ies, size_t ies_len,
460 const u8 **out_ies, size_t *out_ies_len)
461{
462 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
463 u8 *buf;
464 size_t offs;
465
466 if (!rdev->wiphy.extended_capabilities_len ||
467 (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) {
468 *out_ies = kmemdup(ies, ies_len, GFP_KERNEL);
469 if (!*out_ies)
470 return -ENOMEM;
471 *out_ies_len = ies_len;
472 return 0;
473 }
474
475 buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2,
476 GFP_KERNEL);
477 if (!buf)
478 return -ENOMEM;
479
480 if (ies_len) {
481 static const u8 before_extcapa[] = {
482 /* not listing IEs expected to be created by driver */
483 WLAN_EID_RSN,
484 WLAN_EID_QOS_CAPA,
485 WLAN_EID_RRM_ENABLED_CAPABILITIES,
486 WLAN_EID_MOBILITY_DOMAIN,
487 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
488 WLAN_EID_BSS_COEX_2040,
489 };
490
491 offs = ieee80211_ie_split(ies, ies_len, before_extcapa,
492 ARRAY_SIZE(before_extcapa), 0);
493 memcpy(buf, ies, offs);
494 /* leave a whole for extended capabilities IE */
495 memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2,
496 ies + offs, ies_len - offs);
497 } else {
498 offs = 0;
499 }
500
501 /* place extended capabilities IE (with only driver capabilities) */
502 buf[offs] = WLAN_EID_EXT_CAPABILITY;
503 buf[offs + 1] = rdev->wiphy.extended_capabilities_len;
504 memcpy(buf + offs + 2,
505 rdev->wiphy.extended_capabilities,
506 rdev->wiphy.extended_capabilities_len);
507
508 *out_ies = buf;
509 *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2;
510
511 return 0;
512}
513
Johannes Bergceca7b72013-05-16 00:55:45 +0200514static int cfg80211_sme_connect(struct wireless_dev *wdev,
515 struct cfg80211_connect_params *connect,
516 const u8 *prev_bssid)
517{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800518 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200519 struct cfg80211_bss *bss;
520 int err;
521
522 if (!rdev->ops->auth || !rdev->ops->assoc)
523 return -EOPNOTSUPP;
524
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +0300525 if (wdev->current_bss) {
526 if (!prev_bssid)
527 return -EALREADY;
528 if (prev_bssid &&
529 !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid))
530 return -ENOTCONN;
531 cfg80211_unhold_bss(wdev->current_bss);
532 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
533 wdev->current_bss = NULL;
534
535 cfg80211_sme_free(wdev);
536 }
Johannes Bergceca7b72013-05-16 00:55:45 +0200537
538 if (WARN_ON(wdev->conn))
539 return -EINPROGRESS;
540
541 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
542 if (!wdev->conn)
543 return -ENOMEM;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200544
545 /*
Johannes Bergceca7b72013-05-16 00:55:45 +0200546 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
Johannes Bergf401a6f2009-08-07 14:51:05 +0200547 */
Johannes Bergceca7b72013-05-16 00:55:45 +0200548 memcpy(&wdev->conn->params, connect, sizeof(*connect));
549 if (connect->bssid) {
550 wdev->conn->params.bssid = wdev->conn->bssid;
551 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
552 }
Johannes Bergf401a6f2009-08-07 14:51:05 +0200553
Johannes Berg46b9d182015-03-31 16:09:13 +0200554 if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len,
555 &wdev->conn->ie,
556 &wdev->conn->params.ie_len)) {
557 kfree(wdev->conn);
558 wdev->conn = NULL;
559 return -ENOMEM;
Johannes Bergceca7b72013-05-16 00:55:45 +0200560 }
Johannes Berg46b9d182015-03-31 16:09:13 +0200561 wdev->conn->params.ie = wdev->conn->ie;
Johannes Bergceca7b72013-05-16 00:55:45 +0200562
563 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
564 wdev->conn->auto_auth = true;
565 /* start with open system ... should mostly work */
566 wdev->conn->params.auth_type =
567 NL80211_AUTHTYPE_OPEN_SYSTEM;
568 } else {
569 wdev->conn->auto_auth = false;
570 }
571
572 wdev->conn->params.ssid = wdev->ssid;
Zhao, Gangbabd3a22014-03-19 23:02:21 +0800573 wdev->conn->params.ssid_len = wdev->ssid_len;
Johannes Bergceca7b72013-05-16 00:55:45 +0200574
575 /* see if we have the bss already */
576 bss = cfg80211_get_conn_bss(wdev);
577
578 if (prev_bssid) {
579 memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN);
580 wdev->conn->prev_bssid_valid = true;
581 }
582
583 /* we're good if we have a matching bss struct */
584 if (bss) {
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200585 enum nl80211_timeout_reason treason;
586
587 err = cfg80211_conn_do_work(wdev, &treason);
Johannes Bergceca7b72013-05-16 00:55:45 +0200588 cfg80211_put_bss(wdev->wiphy, bss);
589 } else {
590 /* otherwise we'll need to scan for the AP first */
591 err = cfg80211_conn_scan(wdev);
592
593 /*
594 * If we can't scan right now, then we need to scan again
595 * after the current scan finished, since the parameters
596 * changed (unless we find a good AP anyway).
597 */
598 if (err == -EBUSY) {
599 err = 0;
600 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
601 }
602 }
603
604 if (err)
605 cfg80211_sme_free(wdev);
606
607 return err;
Johannes Bergf401a6f2009-08-07 14:51:05 +0200608}
609
Johannes Bergceca7b72013-05-16 00:55:45 +0200610static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason)
Johannes Berg7d930bc2009-10-20 15:08:53 +0900611{
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800612 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergceca7b72013-05-16 00:55:45 +0200613 int err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900614
Johannes Bergceca7b72013-05-16 00:55:45 +0200615 if (!wdev->conn)
616 return 0;
617
618 if (!rdev->ops->deauth)
619 return -EOPNOTSUPP;
620
621 if (wdev->conn->state == CFG80211_CONN_SCANNING ||
622 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) {
623 err = 0;
624 goto out;
625 }
626
627 /* wdev->conn->params.bssid must be set if > SCANNING */
628 err = cfg80211_mlme_deauth(rdev, wdev->netdev,
629 wdev->conn->params.bssid,
630 NULL, 0, reason, false);
631 out:
632 cfg80211_sme_free(wdev);
633 return err;
Johannes Berg7d930bc2009-10-20 15:08:53 +0900634}
635
Johannes Bergceca7b72013-05-16 00:55:45 +0200636/*
637 * code shared for in-device and software SME
638 */
639
640static bool cfg80211_is_all_idle(void)
641{
642 struct cfg80211_registered_device *rdev;
643 struct wireless_dev *wdev;
644 bool is_all_idle = true;
645
646 /*
647 * All devices must be idle as otherwise if you are actively
648 * scanning some new beacon hints could be learned and would
649 * count as new regulatory hints.
650 */
651 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
Johannes Berg53873f12016-05-03 16:52:04 +0300652 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergceca7b72013-05-16 00:55:45 +0200653 wdev_lock(wdev);
654 if (wdev->conn || wdev->current_bss)
655 is_all_idle = false;
656 wdev_unlock(wdev);
657 }
658 }
659
660 return is_all_idle;
661}
662
663static void disconnect_work(struct work_struct *work)
664{
665 rtnl_lock();
666 if (cfg80211_is_all_idle())
667 regulatory_hint_disconnect();
668 rtnl_unlock();
669}
670
671static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
672
673
674/*
675 * API calls for drivers implementing connect/disconnect and
676 * SME event handling
677 */
678
Ben Greear6f390902013-06-19 14:06:25 -0700679/* This method must consume bss one way or another */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300680void __cfg80211_connect_result(struct net_device *dev,
681 struct cfg80211_connect_resp_params *cr,
682 bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200683{
684 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg9caf0362012-11-29 01:25:20 +0100685 const u8 *country_ie;
Johannes Berg3d23e342009-09-29 23:27:28 +0200686#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200687 union iwreq_data wrqu;
688#endif
689
Johannes Berg667503d2009-07-07 03:56:11 +0200690 ASSERT_WDEV_LOCK(wdev);
691
Johannes Berg074ac8d2010-09-16 14:58:22 +0200692 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
Ben Greear6f390902013-06-19 14:06:25 -0700693 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300694 cfg80211_put_bss(wdev->wiphy, cr->bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200695 return;
Ben Greear6f390902013-06-19 14:06:25 -0700696 }
Samuel Ortizb23aa672009-07-01 21:26:54 +0200697
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300698 nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, cr,
699 GFP_KERNEL);
Johannes Berge45cd822009-07-02 09:58:04 +0200700
Johannes Berg3d23e342009-09-29 23:27:28 +0200701#ifdef CONFIG_CFG80211_WEXT
Johannes Berge45cd822009-07-02 09:58:04 +0200702 if (wextev) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300703 if (cr->req_ie && cr->status == WLAN_STATUS_SUCCESS) {
Johannes Berge45cd822009-07-02 09:58:04 +0200704 memset(&wrqu, 0, sizeof(wrqu));
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300705 wrqu.data.length = cr->req_ie_len;
706 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu,
707 cr->req_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200708 }
709
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300710 if (cr->resp_ie && cr->status == WLAN_STATUS_SUCCESS) {
Johannes Berge45cd822009-07-02 09:58:04 +0200711 memset(&wrqu, 0, sizeof(wrqu));
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300712 wrqu.data.length = cr->resp_ie_len;
713 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu,
714 cr->resp_ie);
Johannes Berge45cd822009-07-02 09:58:04 +0200715 }
716
717 memset(&wrqu, 0, sizeof(wrqu));
718 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300719 if (cr->bssid && cr->status == WLAN_STATUS_SUCCESS) {
720 memcpy(wrqu.ap_addr.sa_data, cr->bssid, ETH_ALEN);
721 memcpy(wdev->wext.prev_bssid, cr->bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200722 wdev->wext.prev_bssid_valid = true;
723 }
Johannes Berge45cd822009-07-02 09:58:04 +0200724 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
725 }
726#endif
727
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300728 if (!cr->bss && (cr->status == WLAN_STATUS_SUCCESS)) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800729 WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect);
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300730 cr->bss = cfg80211_get_bss(wdev->wiphy, NULL, cr->bssid,
731 wdev->ssid, wdev->ssid_len,
732 wdev->conn_bss_type,
733 IEEE80211_PRIVACY_ANY);
734 if (cr->bss)
735 cfg80211_hold_bss(bss_from_pub(cr->bss));
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530736 }
737
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200738 if (wdev->current_bss) {
739 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100740 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Johannes Bergdf7fc0f2009-07-29 11:23:49 +0200741 wdev->current_bss = NULL;
742 }
743
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300744 if (cr->status != WLAN_STATUS_SUCCESS) {
Johannes Bergb47f6102014-09-10 13:39:54 +0300745 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +0200746 wdev->connect_keys = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200747 wdev->ssid_len = 0;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500748 wdev->conn_owner_nlportid = 0;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300749 if (cr->bss) {
750 cfg80211_unhold_bss(bss_from_pub(cr->bss));
751 cfg80211_put_bss(wdev->wiphy, cr->bss);
Johannes Bergf1940c52013-06-19 13:21:15 +0200752 }
Eliad Pellerc1fbb252014-04-30 15:58:13 +0300753 cfg80211_sme_free(wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200754 return;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200755 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200756
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300757 if (WARN_ON(!cr->bss))
Ujjal Roy4c4d6842013-12-04 17:27:34 +0530758 return;
Johannes Bergfffd0932009-07-08 14:22:54 +0200759
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300760 wdev->current_bss = bss_from_pub(cr->bss);
Johannes Bergfffd0932009-07-08 14:22:54 +0200761
David Spinadelb8676222016-09-22 23:16:50 +0300762 if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP))
763 cfg80211_upload_connect_keys(wdev);
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700764
Johannes Berg9caf0362012-11-29 01:25:20 +0100765 rcu_read_lock();
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300766 country_ie = ieee80211_bss_get_ie(cr->bss, WLAN_EID_COUNTRY);
Johannes Berg9caf0362012-11-29 01:25:20 +0100767 if (!country_ie) {
768 rcu_read_unlock();
769 return;
770 }
771
772 country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC);
773 rcu_read_unlock();
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -0700774
775 if (!country_ie)
776 return;
777
778 /*
779 * ieee80211_bss_get_ie() ensures we can access:
780 * - country_ie + 2, the start of the country ie data, and
781 * - and country_ie[1] which is the IE length
782 */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300783 regulatory_hint_country_ie(wdev->wiphy, cr->bss->channel->band,
Luis R. Rodriguez789fd032013-10-04 18:07:24 -0700784 country_ie + 2, country_ie[1]);
Johannes Berg9caf0362012-11-29 01:25:20 +0100785 kfree(country_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200786}
Johannes Bergf2129352009-07-01 21:26:56 +0200787
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530788/* Consumes bss object one way or another */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300789void cfg80211_connect_done(struct net_device *dev,
790 struct cfg80211_connect_resp_params *params,
791 gfp_t gfp)
Johannes Bergf2129352009-07-01 21:26:56 +0200792{
Johannes Berg667503d2009-07-07 03:56:11 +0200793 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800794 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +0200795 struct cfg80211_event *ev;
796 unsigned long flags;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300797 u8 *next;
Johannes Berg667503d2009-07-07 03:56:11 +0200798
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300799 if (params->bss) {
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530800 /* Make sure the bss entry provided by the driver is valid. */
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300801 struct cfg80211_internal_bss *ibss = bss_from_pub(params->bss);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530802
803 if (WARN_ON(list_empty(&ibss->list))) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300804 cfg80211_put_bss(wdev->wiphy, params->bss);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530805 return;
806 }
807 }
808
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300809 ev = kzalloc(sizeof(*ev) + (params->bssid ? ETH_ALEN : 0) +
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300810 params->req_ie_len + params->resp_ie_len +
811 params->fils_kek_len + params->pmk_len +
812 (params->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530813 if (!ev) {
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300814 cfg80211_put_bss(wdev->wiphy, params->bss);
Johannes Berg667503d2009-07-07 03:56:11 +0200815 return;
Kanchanapally, Vidyullathae7054982016-04-11 15:16:01 +0530816 }
Johannes Berg667503d2009-07-07 03:56:11 +0200817
818 ev->type = EVENT_CONNECT_RESULT;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300819 next = ((u8 *)ev) + sizeof(*ev);
820 if (params->bssid) {
821 ev->cr.bssid = next;
822 memcpy((void *)ev->cr.bssid, params->bssid, ETH_ALEN);
823 next += ETH_ALEN;
Nishant Sarmukadam7834704b2010-04-14 22:03:02 -0700824 }
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300825 if (params->req_ie_len) {
826 ev->cr.req_ie = next;
827 ev->cr.req_ie_len = params->req_ie_len;
828 memcpy((void *)ev->cr.req_ie, params->req_ie,
829 params->req_ie_len);
830 next += params->req_ie_len;
Nishant Sarmukadam7834704b2010-04-14 22:03:02 -0700831 }
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300832 if (params->resp_ie_len) {
833 ev->cr.resp_ie = next;
834 ev->cr.resp_ie_len = params->resp_ie_len;
835 memcpy((void *)ev->cr.resp_ie, params->resp_ie,
836 params->resp_ie_len);
837 next += params->resp_ie_len;
838 }
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300839 if (params->fils_kek_len) {
840 ev->cr.fils_kek = next;
841 ev->cr.fils_kek_len = params->fils_kek_len;
842 memcpy((void *)ev->cr.fils_kek, params->fils_kek,
843 params->fils_kek_len);
844 next += params->fils_kek_len;
845 }
846 if (params->pmk_len) {
847 ev->cr.pmk = next;
848 ev->cr.pmk_len = params->pmk_len;
849 memcpy((void *)ev->cr.pmk, params->pmk, params->pmk_len);
850 next += params->pmk_len;
851 }
852 if (params->pmkid) {
853 ev->cr.pmkid = next;
854 memcpy((void *)ev->cr.pmkid, params->pmkid, WLAN_PMKID_LEN);
855 next += WLAN_PMKID_LEN;
856 }
857 ev->cr.update_erp_next_seq_num = params->update_erp_next_seq_num;
858 if (params->update_erp_next_seq_num)
859 ev->cr.fils_erp_next_seq_num = params->fils_erp_next_seq_num;
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300860 if (params->bss)
861 cfg80211_hold_bss(bss_from_pub(params->bss));
862 ev->cr.bss = params->bss;
863 ev->cr.status = params->status;
864 ev->cr.timeout_reason = params->timeout_reason;
Johannes Berg667503d2009-07-07 03:56:11 +0200865
866 spin_lock_irqsave(&wdev->event_lock, flags);
867 list_add_tail(&ev->list, &wdev->event_list);
868 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100869 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Bergf2129352009-07-01 21:26:56 +0200870}
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +0300871EXPORT_SYMBOL(cfg80211_connect_done);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200872
Ben Greear0e3a39b2013-06-19 14:06:27 -0700873/* Consumes bss object one way or another */
Jouni Malinened9d0102011-05-16 19:40:15 +0300874void __cfg80211_roamed(struct wireless_dev *wdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300875 struct cfg80211_roam_info *info)
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 Berg667503d2009-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
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300893 if (WARN_ON(!info->bss))
894 return;
895
896 cfg80211_hold_bss(bss_from_pub(info->bss));
897 wdev->current_bss = bss_from_pub(info->bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200898
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800899 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy),
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300900 wdev->netdev, info, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200901
Johannes Berg3d23e342009-09-29 23:27:28 +0200902#ifdef CONFIG_CFG80211_WEXT
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300903 if (info->req_ie) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200904 memset(&wrqu, 0, sizeof(wrqu));
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300905 wrqu.data.length = info->req_ie_len;
Zhu Yi3409ff72009-07-20 11:47:44 +0800906 wireless_send_event(wdev->netdev, IWEVASSOCREQIE,
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300907 &wrqu, info->req_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200908 }
909
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300910 if (info->resp_ie) {
Samuel Ortizb23aa672009-07-01 21:26:54 +0200911 memset(&wrqu, 0, sizeof(wrqu));
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300912 wrqu.data.length = info->resp_ie_len;
Johannes Berg667503d2009-07-07 03:56:11 +0200913 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300914 &wrqu, info->resp_ie);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200915 }
916
917 memset(&wrqu, 0, sizeof(wrqu));
918 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300919 memcpy(wrqu.ap_addr.sa_data, info->bss->bssid, ETH_ALEN);
920 memcpy(wdev->wext.prev_bssid, info->bss->bssid, ETH_ALEN);
Johannes Bergf401a6f2009-08-07 14:51:05 +0200921 wdev->wext.prev_bssid_valid = true;
Johannes Berg667503d2009-07-07 03:56:11 +0200922 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200923#endif
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530924
925 return;
926out:
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300927 cfg80211_put_bss(wdev->wiphy, info->bss);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200928}
Johannes Berg667503d2009-07-07 03:56:11 +0200929
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300930/* Consumes info->bss object one way or another */
931void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info,
932 gfp_t gfp)
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530933{
934 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800935 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +0200936 struct cfg80211_event *ev;
937 unsigned long flags;
938
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300939 if (!info->bss) {
940 info->bss = cfg80211_get_bss(wdev->wiphy, info->channel,
941 info->bssid, wdev->ssid,
942 wdev->ssid_len,
943 wdev->conn_bss_type,
944 IEEE80211_PRIVACY_ANY);
945 }
946
947 if (WARN_ON(!info->bss))
Johannes Berg667503d2009-07-07 03:56:11 +0200948 return;
949
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300950 ev = kzalloc(sizeof(*ev) + info->req_ie_len + info->resp_ie_len, gfp);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530951 if (!ev) {
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300952 cfg80211_put_bss(wdev->wiphy, info->bss);
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530953 return;
954 }
955
Johannes Berg667503d2009-07-07 03:56:11 +0200956 ev->type = EVENT_ROAMED;
Johannes Berg667503d2009-07-07 03:56:11 +0200957 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300958 ev->rm.req_ie_len = info->req_ie_len;
959 memcpy((void *)ev->rm.req_ie, info->req_ie, info->req_ie_len);
960 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + info->req_ie_len;
961 ev->rm.resp_ie_len = info->resp_ie_len;
962 memcpy((void *)ev->rm.resp_ie, info->resp_ie, info->resp_ie_len);
963 ev->rm.bss = info->bss;
Avraham Sternf45cbe62017-06-09 13:08:45 +0100964 ev->rm.authorized = info->authorized;
Johannes Berg667503d2009-07-07 03:56:11 +0200965
966 spin_lock_irqsave(&wdev->event_lock, flags);
967 list_add_tail(&ev->list, &wdev->event_list);
968 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +0100969 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Berg667503d2009-07-07 03:56:11 +0200970}
Avraham Stern29ce6ec2017-04-26 10:58:49 +0300971EXPORT_SYMBOL(cfg80211_roamed);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200972
Johannes Berg667503d2009-07-07 03:56:11 +0200973void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
Johannes Berg6829c872009-07-02 09:13:27 +0200974 size_t ie_len, u16 reason, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +0200975{
976 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800977 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergfffd0932009-07-08 14:22:54 +0200978 int i;
Johannes Berg3d23e342009-09-29 23:27:28 +0200979#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +0200980 union iwreq_data wrqu;
981#endif
982
Johannes Berg667503d2009-07-07 03:56:11 +0200983 ASSERT_WDEV_LOCK(wdev);
984
Johannes Berg074ac8d2010-09-16 14:58:22 +0200985 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION &&
986 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT))
Samuel Ortizb23aa672009-07-01 21:26:54 +0200987 return;
988
Samuel Ortizb23aa672009-07-01 21:26:54 +0200989 if (wdev->current_bss) {
990 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100991 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Samuel Ortizb23aa672009-07-01 21:26:54 +0200992 }
993
994 wdev->current_bss = NULL;
Johannes Berg8dadadb2009-08-04 09:32:23 +0200995 wdev->ssid_len = 0;
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -0500996 wdev->conn_owner_nlportid = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +0200997
Johannes Bergfffd0932009-07-08 14:22:54 +0200998 nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap);
999
Arend van Sprielb8607152016-02-15 14:35:53 +01001000 /* stop critical protocol if supported */
1001 if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) {
1002 rdev->crit_proto_nlportid = 0;
1003 rdev_crit_proto_stop(rdev, wdev);
1004 }
1005
Johannes Bergfffd0932009-07-08 14:22:54 +02001006 /*
1007 * Delete all the keys ... pairwise keys can't really
1008 * exist any more anyway, but default keys might.
1009 */
1010 if (rdev->ops->del_key)
1011 for (i = 0; i < 6; i++)
Hila Gonene35e4d22012-06-27 17:19:42 +03001012 rdev_del_key(rdev, dev, i, false, NULL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001013
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001014 rdev_set_qos_map(rdev, dev, NULL);
1015
Johannes Berg3d23e342009-09-29 23:27:28 +02001016#ifdef CONFIG_CFG80211_WEXT
Samuel Ortizb23aa672009-07-01 21:26:54 +02001017 memset(&wrqu, 0, sizeof(wrqu));
1018 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1019 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Abhijeet Kolekar5f612032010-01-13 13:23:14 -08001020 wdev->wext.connect.ssid_len = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001021#endif
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -05001022
1023 schedule_work(&cfg80211_disconnect_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001024}
1025
1026void cfg80211_disconnected(struct net_device *dev, u16 reason,
Johannes Berg80279fb2015-05-22 16:22:20 +02001027 const u8 *ie, size_t ie_len,
1028 bool locally_generated, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001029{
Johannes Berg667503d2009-07-07 03:56:11 +02001030 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001031 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +02001032 struct cfg80211_event *ev;
1033 unsigned long flags;
1034
1035 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
1036 if (!ev)
1037 return;
1038
1039 ev->type = EVENT_DISCONNECTED;
1040 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
1041 ev->dc.ie_len = ie_len;
1042 memcpy((void *)ev->dc.ie, ie, ie_len);
1043 ev->dc.reason = reason;
Johannes Berg80279fb2015-05-22 16:22:20 +02001044 ev->dc.locally_generated = locally_generated;
Johannes Berg667503d2009-07-07 03:56:11 +02001045
1046 spin_lock_irqsave(&wdev->event_lock, flags);
1047 list_add_tail(&ev->list, &wdev->event_list);
1048 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +01001049 queue_work(cfg80211_wq, &rdev->event_work);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001050}
1051EXPORT_SYMBOL(cfg80211_disconnected);
1052
Johannes Bergceca7b72013-05-16 00:55:45 +02001053/*
1054 * API calls for nl80211/wext compatibility code
1055 */
Johannes Berg83739b02013-05-15 17:44:01 +02001056int cfg80211_connect(struct cfg80211_registered_device *rdev,
1057 struct net_device *dev,
1058 struct cfg80211_connect_params *connect,
1059 struct cfg80211_cached_keys *connkeys,
1060 const u8 *prev_bssid)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001061{
Samuel Ortizb23aa672009-07-01 21:26:54 +02001062 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg667503d2009-07-07 03:56:11 +02001063 int err;
1064
1065 ASSERT_WDEV_LOCK(wdev);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001066
Johannes Bergfffd0932009-07-08 14:22:54 +02001067 if (WARN_ON(wdev->connect_keys)) {
Johannes Bergb47f6102014-09-10 13:39:54 +03001068 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001069 wdev->connect_keys = NULL;
1070 }
1071
Ben Greear7e7c8922011-11-18 11:31:59 -08001072 cfg80211_oper_and_ht_capa(&connect->ht_capa_mask,
1073 rdev->wiphy.ht_capa_mod_mask);
1074
Johannes Bergfffd0932009-07-08 14:22:54 +02001075 if (connkeys && connkeys->def >= 0) {
1076 int idx;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001077 u32 cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001078
1079 idx = connkeys->def;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001080 cipher = connkeys->params[idx].cipher;
Johannes Bergfffd0932009-07-08 14:22:54 +02001081 /* If given a WEP key we may need it for shared key auth */
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001082 if (cipher == WLAN_CIPHER_SUITE_WEP40 ||
1083 cipher == WLAN_CIPHER_SUITE_WEP104) {
Johannes Bergfffd0932009-07-08 14:22:54 +02001084 connect->key_idx = idx;
1085 connect->key = connkeys->params[idx].key;
1086 connect->key_len = connkeys->params[idx].key_len;
Samuel Ortizbcba8ea2009-08-06 21:04:41 +02001087
1088 /*
1089 * If ciphers are not set (e.g. when going through
1090 * iwconfig), we have to set them appropriately here.
1091 */
1092 if (connect->crypto.cipher_group == 0)
1093 connect->crypto.cipher_group = cipher;
1094
1095 if (connect->crypto.n_ciphers_pairwise == 0) {
1096 connect->crypto.n_ciphers_pairwise = 1;
1097 connect->crypto.ciphers_pairwise[0] = cipher;
1098 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001099 }
David Spinadelb8676222016-09-22 23:16:50 +03001100
1101 connect->crypto.wep_keys = connkeys->params;
1102 connect->crypto.wep_tx_key = connkeys->def;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001103 } else {
1104 if (WARN_ON(connkeys))
1105 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001106 }
1107
Johannes Bergceca7b72013-05-16 00:55:45 +02001108 wdev->connect_keys = connkeys;
1109 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
1110 wdev->ssid_len = connect->ssid_len;
Johannes Berg6829c872009-07-02 09:13:27 +02001111
Lior David34d50512016-01-28 10:58:25 +02001112 wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS :
1113 IEEE80211_BSS_TYPE_ESS;
1114
Johannes Bergceca7b72013-05-16 00:55:45 +02001115 if (!rdev->ops->connect)
1116 err = cfg80211_sme_connect(wdev, connect, prev_bssid);
1117 else
Hila Gonene35e4d22012-06-27 17:19:42 +03001118 err = rdev_connect(rdev, dev, connect);
Johannes Berg6829c872009-07-02 09:13:27 +02001119
Johannes Bergceca7b72013-05-16 00:55:45 +02001120 if (err) {
1121 wdev->connect_keys = NULL;
1122 wdev->ssid_len = 0;
1123 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001124 }
Johannes Bergceca7b72013-05-16 00:55:45 +02001125
1126 return 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001127}
1128
Johannes Berg83739b02013-05-15 17:44:01 +02001129int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
1130 struct net_device *dev, u16 reason, bool wextev)
Samuel Ortizb23aa672009-07-01 21:26:54 +02001131{
Johannes Berg6829c872009-07-02 09:13:27 +02001132 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergdee8a972013-08-13 09:23:57 +02001133 int err = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +02001134
Johannes Berg667503d2009-07-07 03:56:11 +02001135 ASSERT_WDEV_LOCK(wdev);
1136
Johannes Bergb47f6102014-09-10 13:39:54 +03001137 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +02001138 wdev->connect_keys = NULL;
1139
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05001140 wdev->conn_owner_nlportid = 0;
1141
Johannes Bergdee8a972013-08-13 09:23:57 +02001142 if (wdev->conn)
Johannes Bergceca7b72013-05-16 00:55:45 +02001143 err = cfg80211_sme_disconnect(wdev, reason);
Johannes Bergdee8a972013-08-13 09:23:57 +02001144 else if (!rdev->ops->disconnect)
Johannes Bergceca7b72013-05-16 00:55:45 +02001145 cfg80211_mlme_down(rdev, dev);
Ilan Peer0711d632016-10-18 23:12:13 +03001146 else if (wdev->ssid_len)
Hila Gonene35e4d22012-06-27 17:19:42 +03001147 err = rdev_disconnect(rdev, dev, reason);
Samuel Ortizb23aa672009-07-01 21:26:54 +02001148
Johannes Bergceca7b72013-05-16 00:55:45 +02001149 return err;
Johannes Berg19957bb2009-07-02 17:20:43 +02001150}
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05001151
1152/*
1153 * Used to clean up after the connection / connection attempt owner socket
1154 * disconnects
1155 */
1156void cfg80211_autodisconnect_wk(struct work_struct *work)
1157{
1158 struct wireless_dev *wdev =
1159 container_of(work, struct wireless_dev, disconnect_wk);
1160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1161
1162 wdev_lock(wdev);
1163
1164 if (wdev->conn_owner_nlportid) {
1165 /*
1166 * Use disconnect_bssid if still connecting and ops->disconnect
1167 * not implemented. Otherwise we can use cfg80211_disconnect.
1168 */
1169 if (rdev->ops->disconnect || wdev->current_bss)
1170 cfg80211_disconnect(rdev, wdev->netdev,
1171 WLAN_REASON_DEAUTH_LEAVING, true);
1172 else
1173 cfg80211_mlme_deauth(rdev, wdev->netdev,
1174 wdev->disconnect_bssid, NULL, 0,
1175 WLAN_REASON_DEAUTH_LEAVING, false);
1176 }
1177
1178 wdev_unlock(wdev);
1179}