Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
b23aa676 | 2 | /* |
ceca7b71 JB |
3 | * SME code for cfg80211 |
4 | * both driver SME event handling and the SME implementation | |
5 | * (for nl80211's connect() and wext) | |
b23aa676 SO |
6 | * |
7 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> | |
7b0a0e3c | 8 | * Copyright (C) 2009, 2020, 2022 Intel Corporation. All rights reserved. |
29ce6ecb | 9 | * Copyright 2017 Intel Deutschland GmbH |
b23aa676 SO |
10 | */ |
11 | ||
12 | #include <linux/etherdevice.h> | |
13 | #include <linux/if_arp.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
b23aa676 | 15 | #include <linux/workqueue.h> |
a9a11622 | 16 | #include <linux/wireless.h> |
bc3b2d7f | 17 | #include <linux/export.h> |
a9a11622 | 18 | #include <net/iw_handler.h> |
b23aa676 SO |
19 | #include <net/cfg80211.h> |
20 | #include <net/rtnetlink.h> | |
21 | #include "nl80211.h" | |
8b19e6ca | 22 | #include "reg.h" |
e35e4d28 | 23 | #include "rdev-ops.h" |
b23aa676 | 24 | |
ceca7b71 JB |
25 | /* |
26 | * Software SME in cfg80211, using auth/assoc/deauth calls to the | |
54f65de0 | 27 | * driver. This is for implementing nl80211's connect/disconnect |
ceca7b71 JB |
28 | * and wireless extensions (if configured.) |
29 | */ | |
30 | ||
6829c878 JB |
31 | struct cfg80211_conn { |
32 | struct cfg80211_connect_params params; | |
33 | /* these are sub-states of the _CONNECTING sme_state */ | |
34 | enum { | |
6829c878 JB |
35 | CFG80211_CONN_SCANNING, |
36 | CFG80211_CONN_SCAN_AGAIN, | |
37 | CFG80211_CONN_AUTHENTICATE_NEXT, | |
38 | CFG80211_CONN_AUTHENTICATING, | |
3093ebbe | 39 | CFG80211_CONN_AUTH_FAILED_TIMEOUT, |
6829c878 JB |
40 | CFG80211_CONN_ASSOCIATE_NEXT, |
41 | CFG80211_CONN_ASSOCIATING, | |
923a0e7d | 42 | CFG80211_CONN_ASSOC_FAILED, |
3093ebbe | 43 | CFG80211_CONN_ASSOC_FAILED_TIMEOUT, |
ceca7b71 | 44 | CFG80211_CONN_DEAUTH, |
e6f462df | 45 | CFG80211_CONN_ABANDON, |
ceca7b71 | 46 | CFG80211_CONN_CONNECTED, |
6829c878 | 47 | } state; |
f401a6f7 | 48 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
46b9d180 | 49 | const u8 *ie; |
6829c878 | 50 | size_t ie_len; |
f401a6f7 | 51 | bool auto_auth, prev_bssid_valid; |
6829c878 JB |
52 | }; |
53 | ||
ceca7b71 | 54 | static void cfg80211_sme_free(struct wireless_dev *wdev) |
09d989d1 | 55 | { |
ceca7b71 JB |
56 | if (!wdev->conn) |
57 | return; | |
09d989d1 | 58 | |
ceca7b71 JB |
59 | kfree(wdev->conn->ie); |
60 | kfree(wdev->conn); | |
61 | wdev->conn = NULL; | |
09d989d1 LR |
62 | } |
63 | ||
6829c878 JB |
64 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
65 | { | |
f26cbf40 | 66 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
6829c878 JB |
67 | struct cfg80211_scan_request *request; |
68 | int n_channels, err; | |
69 | ||
667503dd | 70 | ASSERT_WDEV_LOCK(wdev); |
6829c878 | 71 | |
f9d15d16 | 72 | if (rdev->scan_req || rdev->scan_msg) |
6829c878 JB |
73 | return -EBUSY; |
74 | ||
bdfbec2d | 75 | if (wdev->conn->params.channel) |
6829c878 | 76 | n_channels = 1; |
bdfbec2d IP |
77 | else |
78 | n_channels = ieee80211_get_num_supported_channels(wdev->wiphy); | |
6829c878 | 79 | |
6829c878 JB |
80 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
81 | sizeof(request->channels[0]) * n_channels, | |
82 | GFP_KERNEL); | |
83 | if (!request) | |
84 | return -ENOMEM; | |
85 | ||
2a84ee86 | 86 | if (wdev->conn->params.channel) { |
57fbcce3 | 87 | enum nl80211_band band = wdev->conn->params.channel->band; |
2a84ee86 KB |
88 | struct ieee80211_supported_band *sband = |
89 | wdev->wiphy->bands[band]; | |
90 | ||
91 | if (!sband) { | |
92 | kfree(request); | |
93 | return -EINVAL; | |
94 | } | |
6829c878 | 95 | request->channels[0] = wdev->conn->params.channel; |
2a84ee86 KB |
96 | request->rates[band] = (1 << sband->n_bitrates) - 1; |
97 | } else { | |
6829c878 | 98 | int i = 0, j; |
57fbcce3 | 99 | enum nl80211_band band; |
e3081501 RM |
100 | struct ieee80211_supported_band *bands; |
101 | struct ieee80211_channel *channel; | |
6829c878 | 102 | |
57fbcce3 | 103 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
e3081501 RM |
104 | bands = wdev->wiphy->bands[band]; |
105 | if (!bands) | |
6829c878 | 106 | continue; |
e3081501 RM |
107 | for (j = 0; j < bands->n_channels; j++) { |
108 | channel = &bands->channels[j]; | |
109 | if (channel->flags & IEEE80211_CHAN_DISABLED) | |
110 | continue; | |
111 | request->channels[i++] = channel; | |
112 | } | |
113 | request->rates[band] = (1 << bands->n_bitrates) - 1; | |
6829c878 | 114 | } |
e3081501 | 115 | n_channels = i; |
6829c878 JB |
116 | } |
117 | request->n_channels = n_channels; | |
5ba63533 | 118 | request->ssids = (void *)&request->channels[n_channels]; |
6829c878 JB |
119 | request->n_ssids = 1; |
120 | ||
121 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, | |
122 | wdev->conn->params.ssid_len); | |
123 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; | |
124 | ||
818965d3 JM |
125 | eth_broadcast_addr(request->bssid); |
126 | ||
fd014284 | 127 | request->wdev = wdev; |
79c97e97 | 128 | request->wiphy = &rdev->wiphy; |
15d6030b | 129 | request->scan_start = jiffies; |
6829c878 | 130 | |
79c97e97 | 131 | rdev->scan_req = request; |
6829c878 | 132 | |
e35e4d28 | 133 | err = rdev_scan(rdev, request); |
6829c878 JB |
134 | if (!err) { |
135 | wdev->conn->state = CFG80211_CONN_SCANNING; | |
fd014284 | 136 | nl80211_send_scan_start(rdev, wdev); |
463d0183 | 137 | dev_hold(wdev->netdev); |
6829c878 | 138 | } else { |
79c97e97 | 139 | rdev->scan_req = NULL; |
6829c878 JB |
140 | kfree(request); |
141 | } | |
142 | return err; | |
143 | } | |
144 | ||
3093ebbe PK |
145 | static int cfg80211_conn_do_work(struct wireless_dev *wdev, |
146 | enum nl80211_timeout_reason *treason) | |
6829c878 | 147 | { |
f26cbf40 | 148 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
19957bb3 | 149 | struct cfg80211_connect_params *params; |
325839da | 150 | struct cfg80211_auth_request auth_req = {}; |
f62fab73 | 151 | struct cfg80211_assoc_request req = {}; |
19957bb3 | 152 | int err; |
6829c878 | 153 | |
667503dd JB |
154 | ASSERT_WDEV_LOCK(wdev); |
155 | ||
6829c878 JB |
156 | if (!wdev->conn) |
157 | return 0; | |
158 | ||
19957bb3 JB |
159 | params = &wdev->conn->params; |
160 | ||
6829c878 | 161 | switch (wdev->conn->state) { |
ceca7b71 JB |
162 | case CFG80211_CONN_SCANNING: |
163 | /* didn't find it during scan ... */ | |
164 | return -ENOENT; | |
6829c878 JB |
165 | case CFG80211_CONN_SCAN_AGAIN: |
166 | return cfg80211_conn_scan(wdev); | |
167 | case CFG80211_CONN_AUTHENTICATE_NEXT: | |
2fd05115 JB |
168 | if (WARN_ON(!rdev->ops->auth)) |
169 | return -EOPNOTSUPP; | |
19957bb3 | 170 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
325839da JB |
171 | auth_req.key = params->key; |
172 | auth_req.key_len = params->key_len; | |
173 | auth_req.key_idx = params->key_idx; | |
174 | auth_req.auth_type = params->auth_type; | |
175 | auth_req.bss = cfg80211_get_bss(&rdev->wiphy, params->channel, | |
176 | params->bssid, | |
177 | params->ssid, params->ssid_len, | |
178 | IEEE80211_BSS_TYPE_ESS, | |
179 | IEEE80211_PRIVACY_ANY); | |
d648c230 | 180 | auth_req.link_id = -1; |
325839da JB |
181 | err = cfg80211_mlme_auth(rdev, wdev->netdev, &auth_req); |
182 | cfg80211_put_bss(&rdev->wiphy, auth_req.bss); | |
183 | return err; | |
3093ebbe PK |
184 | case CFG80211_CONN_AUTH_FAILED_TIMEOUT: |
185 | *treason = NL80211_TIMEOUT_AUTH; | |
923a0e7d | 186 | return -ENOTCONN; |
6829c878 | 187 | case CFG80211_CONN_ASSOCIATE_NEXT: |
2fd05115 JB |
188 | if (WARN_ON(!rdev->ops->assoc)) |
189 | return -EOPNOTSUPP; | |
19957bb3 | 190 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
f401a6f7 | 191 | if (wdev->conn->prev_bssid_valid) |
f62fab73 JB |
192 | req.prev_bssid = wdev->conn->prev_bssid; |
193 | req.ie = params->ie; | |
194 | req.ie_len = params->ie_len; | |
195 | req.use_mfp = params->mfp != NL80211_MFP_NO; | |
196 | req.crypto = params->crypto; | |
197 | req.flags = params->flags; | |
198 | req.ht_capa = params->ht_capa; | |
199 | req.ht_capa_mask = params->ht_capa_mask; | |
200 | req.vht_capa = params->vht_capa; | |
201 | req.vht_capa_mask = params->vht_capa_mask; | |
d648c230 | 202 | req.link_id = -1; |
f62fab73 | 203 | |
0f759448 JB |
204 | req.bss = cfg80211_get_bss(&rdev->wiphy, params->channel, |
205 | params->bssid, | |
206 | params->ssid, params->ssid_len, | |
207 | IEEE80211_BSS_TYPE_ESS, | |
208 | IEEE80211_PRIVACY_ANY); | |
209 | if (!req.bss) { | |
210 | err = -ENOENT; | |
211 | } else { | |
212 | err = cfg80211_mlme_assoc(rdev, wdev->netdev, &req); | |
213 | cfg80211_put_bss(&rdev->wiphy, req.bss); | |
214 | } | |
215 | ||
19957bb3 | 216 | if (err) |
91bf9b26 JB |
217 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
218 | NULL, 0, | |
219 | WLAN_REASON_DEAUTH_LEAVING, | |
220 | false); | |
19957bb3 | 221 | return err; |
3093ebbe PK |
222 | case CFG80211_CONN_ASSOC_FAILED_TIMEOUT: |
223 | *treason = NL80211_TIMEOUT_ASSOC; | |
7b506ff6 | 224 | fallthrough; |
923a0e7d JB |
225 | case CFG80211_CONN_ASSOC_FAILED: |
226 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, | |
227 | NULL, 0, | |
228 | WLAN_REASON_DEAUTH_LEAVING, false); | |
229 | return -ENOTCONN; | |
ceca7b71 | 230 | case CFG80211_CONN_DEAUTH: |
91bf9b26 JB |
231 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
232 | NULL, 0, | |
233 | WLAN_REASON_DEAUTH_LEAVING, false); | |
7b506ff6 | 234 | fallthrough; |
e6f462df | 235 | case CFG80211_CONN_ABANDON: |
923a0e7d JB |
236 | /* free directly, disconnected event already sent */ |
237 | cfg80211_sme_free(wdev); | |
ceca7b71 | 238 | return 0; |
6829c878 JB |
239 | default: |
240 | return 0; | |
241 | } | |
242 | } | |
243 | ||
244 | void cfg80211_conn_work(struct work_struct *work) | |
245 | { | |
79c97e97 | 246 | struct cfg80211_registered_device *rdev = |
6829c878 JB |
247 | container_of(work, struct cfg80211_registered_device, conn_work); |
248 | struct wireless_dev *wdev; | |
7400f42e | 249 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
3093ebbe | 250 | enum nl80211_timeout_reason treason; |
6829c878 | 251 | |
a05829a7 | 252 | wiphy_lock(&rdev->wiphy); |
6829c878 | 253 | |
53873f13 | 254 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
c8157976 JB |
255 | if (!wdev->netdev) |
256 | continue; | |
257 | ||
667503dd JB |
258 | wdev_lock(wdev); |
259 | if (!netif_running(wdev->netdev)) { | |
260 | wdev_unlock(wdev); | |
6829c878 | 261 | continue; |
667503dd | 262 | } |
ceca7b71 JB |
263 | if (!wdev->conn || |
264 | wdev->conn->state == CFG80211_CONN_CONNECTED) { | |
667503dd | 265 | wdev_unlock(wdev); |
6829c878 | 266 | continue; |
667503dd | 267 | } |
7400f42e JB |
268 | if (wdev->conn->params.bssid) { |
269 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); | |
270 | bssid = bssid_buf; | |
271 | } | |
3093ebbe PK |
272 | treason = NL80211_TIMEOUT_UNSPECIFIED; |
273 | if (cfg80211_conn_do_work(wdev, &treason)) { | |
5349a0f7 VK |
274 | struct cfg80211_connect_resp_params cr; |
275 | ||
276 | memset(&cr, 0, sizeof(cr)); | |
277 | cr.status = -1; | |
efbabc11 | 278 | cr.links[0].bssid = bssid; |
5349a0f7 VK |
279 | cr.timeout_reason = treason; |
280 | __cfg80211_connect_result(wdev->netdev, &cr, false); | |
ceca7b71 | 281 | } |
667503dd | 282 | wdev_unlock(wdev); |
6829c878 JB |
283 | } |
284 | ||
a05829a7 | 285 | wiphy_unlock(&rdev->wiphy); |
6829c878 JB |
286 | } |
287 | ||
0e3a39b5 | 288 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
bbac31f4 | 289 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
6829c878 | 290 | { |
f26cbf40 | 291 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
6829c878 | 292 | struct cfg80211_bss *bss; |
6829c878 | 293 | |
667503dd JB |
294 | ASSERT_WDEV_LOCK(wdev); |
295 | ||
ed9d0102 JM |
296 | bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel, |
297 | wdev->conn->params.bssid, | |
6829c878 JB |
298 | wdev->conn->params.ssid, |
299 | wdev->conn->params.ssid_len, | |
34d50519 | 300 | wdev->conn_bss_type, |
6eb18137 | 301 | IEEE80211_PRIVACY(wdev->conn->params.privacy)); |
6829c878 | 302 | if (!bss) |
bbac31f4 | 303 | return NULL; |
6829c878 JB |
304 | |
305 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); | |
306 | wdev->conn->params.bssid = wdev->conn->bssid; | |
307 | wdev->conn->params.channel = bss->channel; | |
308 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; | |
79c97e97 | 309 | schedule_work(&rdev->conn_work); |
6829c878 | 310 | |
bbac31f4 | 311 | return bss; |
6829c878 JB |
312 | } |
313 | ||
667503dd | 314 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
6829c878 JB |
315 | { |
316 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 317 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
bbac31f4 | 318 | struct cfg80211_bss *bss; |
6829c878 | 319 | |
667503dd JB |
320 | ASSERT_WDEV_LOCK(wdev); |
321 | ||
d4b1a687 | 322 | if (!wdev->conn) |
6829c878 JB |
323 | return; |
324 | ||
325 | if (wdev->conn->state != CFG80211_CONN_SCANNING && | |
326 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) | |
327 | return; | |
328 | ||
bbac31f4 | 329 | bss = cfg80211_get_conn_bss(wdev); |
ceca7b71 | 330 | if (bss) |
5b112d3d | 331 | cfg80211_put_bss(&rdev->wiphy, bss); |
ceca7b71 JB |
332 | else |
333 | schedule_work(&rdev->conn_work); | |
6829c878 JB |
334 | } |
335 | ||
667503dd JB |
336 | void cfg80211_sme_scan_done(struct net_device *dev) |
337 | { | |
338 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
339 | ||
340 | wdev_lock(wdev); | |
341 | __cfg80211_sme_scan_done(dev); | |
342 | wdev_unlock(wdev); | |
343 | } | |
344 | ||
ceca7b71 | 345 | void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len) |
6829c878 | 346 | { |
6829c878 | 347 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 348 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6829c878 JB |
349 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
350 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
351 | ||
667503dd JB |
352 | ASSERT_WDEV_LOCK(wdev); |
353 | ||
ceca7b71 | 354 | if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED) |
6829c878 JB |
355 | return; |
356 | ||
357 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && | |
358 | wdev->conn->auto_auth && | |
359 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { | |
360 | /* select automatically between only open, shared, leap */ | |
361 | switch (wdev->conn->params.auth_type) { | |
362 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
fffd0934 JB |
363 | if (wdev->connect_keys) |
364 | wdev->conn->params.auth_type = | |
365 | NL80211_AUTHTYPE_SHARED_KEY; | |
366 | else | |
367 | wdev->conn->params.auth_type = | |
368 | NL80211_AUTHTYPE_NETWORK_EAP; | |
6829c878 JB |
369 | break; |
370 | case NL80211_AUTHTYPE_SHARED_KEY: | |
371 | wdev->conn->params.auth_type = | |
372 | NL80211_AUTHTYPE_NETWORK_EAP; | |
373 | break; | |
374 | default: | |
375 | /* huh? */ | |
376 | wdev->conn->params.auth_type = | |
377 | NL80211_AUTHTYPE_OPEN_SYSTEM; | |
378 | break; | |
379 | } | |
380 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; | |
381 | schedule_work(&rdev->conn_work); | |
19957bb3 | 382 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
5349a0f7 VK |
383 | struct cfg80211_connect_resp_params cr; |
384 | ||
385 | memset(&cr, 0, sizeof(cr)); | |
386 | cr.status = status_code; | |
efbabc11 | 387 | cr.links[0].bssid = mgmt->bssid; |
5349a0f7 VK |
388 | cr.timeout_reason = NL80211_TIMEOUT_UNSPECIFIED; |
389 | __cfg80211_connect_result(wdev->netdev, &cr, false); | |
ceca7b71 | 390 | } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
6829c878 JB |
391 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
392 | schedule_work(&rdev->conn_work); | |
393 | } | |
394 | } | |
b23aa676 | 395 | |
ceca7b71 | 396 | bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status) |
f401a6f7 | 397 | { |
f26cbf40 | 398 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
f401a6f7 | 399 | |
ceca7b71 | 400 | if (!wdev->conn) |
f401a6f7 JB |
401 | return false; |
402 | ||
ceca7b71 JB |
403 | if (status == WLAN_STATUS_SUCCESS) { |
404 | wdev->conn->state = CFG80211_CONN_CONNECTED; | |
f401a6f7 | 405 | return false; |
ceca7b71 | 406 | } |
f401a6f7 | 407 | |
ceca7b71 JB |
408 | if (wdev->conn->prev_bssid_valid) { |
409 | /* | |
410 | * Some stupid APs don't accept reassoc, so we | |
411 | * need to fall back to trying regular assoc; | |
412 | * return true so no event is sent to userspace. | |
413 | */ | |
414 | wdev->conn->prev_bssid_valid = false; | |
415 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; | |
416 | schedule_work(&rdev->conn_work); | |
417 | return true; | |
418 | } | |
419 | ||
923a0e7d | 420 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; |
f401a6f7 | 421 | schedule_work(&rdev->conn_work); |
ceca7b71 JB |
422 | return false; |
423 | } | |
f401a6f7 | 424 | |
ceca7b71 JB |
425 | void cfg80211_sme_deauth(struct wireless_dev *wdev) |
426 | { | |
427 | cfg80211_sme_free(wdev); | |
f401a6f7 JB |
428 | } |
429 | ||
ceca7b71 | 430 | void cfg80211_sme_auth_timeout(struct wireless_dev *wdev) |
7d930bc3 | 431 | { |
f26cbf40 | 432 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
923a0e7d JB |
433 | |
434 | if (!wdev->conn) | |
435 | return; | |
436 | ||
3093ebbe | 437 | wdev->conn->state = CFG80211_CONN_AUTH_FAILED_TIMEOUT; |
923a0e7d | 438 | schedule_work(&rdev->conn_work); |
ceca7b71 | 439 | } |
7d930bc3 | 440 | |
ceca7b71 JB |
441 | void cfg80211_sme_disassoc(struct wireless_dev *wdev) |
442 | { | |
f26cbf40 | 443 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
444 | |
445 | if (!wdev->conn) | |
446 | return; | |
447 | ||
448 | wdev->conn->state = CFG80211_CONN_DEAUTH; | |
7d930bc3 JB |
449 | schedule_work(&rdev->conn_work); |
450 | } | |
451 | ||
ceca7b71 JB |
452 | void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev) |
453 | { | |
f26cbf40 | 454 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
923a0e7d JB |
455 | |
456 | if (!wdev->conn) | |
457 | return; | |
458 | ||
3093ebbe | 459 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED_TIMEOUT; |
923a0e7d | 460 | schedule_work(&rdev->conn_work); |
ceca7b71 JB |
461 | } |
462 | ||
e6f462df JB |
463 | void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev) |
464 | { | |
465 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
466 | ||
467 | if (!wdev->conn) | |
468 | return; | |
469 | ||
470 | wdev->conn->state = CFG80211_CONN_ABANDON; | |
471 | schedule_work(&rdev->conn_work); | |
472 | } | |
473 | ||
7b0a0e3c JB |
474 | static void cfg80211_wdev_release_bsses(struct wireless_dev *wdev) |
475 | { | |
476 | unsigned int link; | |
477 | ||
478 | for_each_valid_link(wdev, link) { | |
479 | if (!wdev->links[link].client.current_bss) | |
480 | continue; | |
481 | cfg80211_unhold_bss(wdev->links[link].client.current_bss); | |
482 | cfg80211_put_bss(wdev->wiphy, | |
483 | &wdev->links[link].client.current_bss->pub); | |
484 | wdev->links[link].client.current_bss = NULL; | |
485 | } | |
486 | } | |
487 | ||
46b9d180 JB |
488 | static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev, |
489 | const u8 *ies, size_t ies_len, | |
490 | const u8 **out_ies, size_t *out_ies_len) | |
491 | { | |
492 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
493 | u8 *buf; | |
494 | size_t offs; | |
495 | ||
496 | if (!rdev->wiphy.extended_capabilities_len || | |
497 | (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) { | |
498 | *out_ies = kmemdup(ies, ies_len, GFP_KERNEL); | |
499 | if (!*out_ies) | |
500 | return -ENOMEM; | |
501 | *out_ies_len = ies_len; | |
502 | return 0; | |
503 | } | |
504 | ||
505 | buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2, | |
506 | GFP_KERNEL); | |
507 | if (!buf) | |
508 | return -ENOMEM; | |
509 | ||
510 | if (ies_len) { | |
511 | static const u8 before_extcapa[] = { | |
512 | /* not listing IEs expected to be created by driver */ | |
513 | WLAN_EID_RSN, | |
514 | WLAN_EID_QOS_CAPA, | |
515 | WLAN_EID_RRM_ENABLED_CAPABILITIES, | |
516 | WLAN_EID_MOBILITY_DOMAIN, | |
517 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
518 | WLAN_EID_BSS_COEX_2040, | |
519 | }; | |
520 | ||
521 | offs = ieee80211_ie_split(ies, ies_len, before_extcapa, | |
522 | ARRAY_SIZE(before_extcapa), 0); | |
523 | memcpy(buf, ies, offs); | |
524 | /* leave a whole for extended capabilities IE */ | |
525 | memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2, | |
526 | ies + offs, ies_len - offs); | |
527 | } else { | |
528 | offs = 0; | |
529 | } | |
530 | ||
531 | /* place extended capabilities IE (with only driver capabilities) */ | |
532 | buf[offs] = WLAN_EID_EXT_CAPABILITY; | |
533 | buf[offs + 1] = rdev->wiphy.extended_capabilities_len; | |
534 | memcpy(buf + offs + 2, | |
535 | rdev->wiphy.extended_capabilities, | |
536 | rdev->wiphy.extended_capabilities_len); | |
537 | ||
538 | *out_ies = buf; | |
539 | *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2; | |
540 | ||
541 | return 0; | |
542 | } | |
543 | ||
ceca7b71 JB |
544 | static int cfg80211_sme_connect(struct wireless_dev *wdev, |
545 | struct cfg80211_connect_params *connect, | |
546 | const u8 *prev_bssid) | |
547 | { | |
f26cbf40 | 548 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
549 | struct cfg80211_bss *bss; |
550 | int err; | |
551 | ||
552 | if (!rdev->ops->auth || !rdev->ops->assoc) | |
553 | return -EOPNOTSUPP; | |
554 | ||
7b0a0e3c | 555 | cfg80211_wdev_release_bsses(wdev); |
4ce2bd9c | 556 | |
7b0a0e3c | 557 | if (wdev->connected) { |
4ce2bd9c | 558 | cfg80211_sme_free(wdev); |
7b0a0e3c | 559 | wdev->connected = false; |
4ce2bd9c | 560 | } |
ceca7b71 | 561 | |
1b5ab825 | 562 | if (wdev->conn) |
ceca7b71 JB |
563 | return -EINPROGRESS; |
564 | ||
565 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); | |
566 | if (!wdev->conn) | |
567 | return -ENOMEM; | |
568 | ||
569 | /* | |
570 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. | |
571 | */ | |
572 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); | |
573 | if (connect->bssid) { | |
574 | wdev->conn->params.bssid = wdev->conn->bssid; | |
575 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); | |
576 | } | |
577 | ||
46b9d180 JB |
578 | if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len, |
579 | &wdev->conn->ie, | |
580 | &wdev->conn->params.ie_len)) { | |
581 | kfree(wdev->conn); | |
582 | wdev->conn = NULL; | |
583 | return -ENOMEM; | |
ceca7b71 | 584 | } |
46b9d180 | 585 | wdev->conn->params.ie = wdev->conn->ie; |
ceca7b71 JB |
586 | |
587 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { | |
588 | wdev->conn->auto_auth = true; | |
589 | /* start with open system ... should mostly work */ | |
590 | wdev->conn->params.auth_type = | |
591 | NL80211_AUTHTYPE_OPEN_SYSTEM; | |
592 | } else { | |
593 | wdev->conn->auto_auth = false; | |
594 | } | |
595 | ||
7b0a0e3c JB |
596 | wdev->conn->params.ssid = wdev->u.client.ssid; |
597 | wdev->conn->params.ssid_len = wdev->u.client.ssid_len; | |
ceca7b71 JB |
598 | |
599 | /* see if we have the bss already */ | |
600 | bss = cfg80211_get_conn_bss(wdev); | |
601 | ||
602 | if (prev_bssid) { | |
603 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); | |
604 | wdev->conn->prev_bssid_valid = true; | |
605 | } | |
606 | ||
607 | /* we're good if we have a matching bss struct */ | |
608 | if (bss) { | |
3093ebbe PK |
609 | enum nl80211_timeout_reason treason; |
610 | ||
611 | err = cfg80211_conn_do_work(wdev, &treason); | |
ceca7b71 JB |
612 | cfg80211_put_bss(wdev->wiphy, bss); |
613 | } else { | |
614 | /* otherwise we'll need to scan for the AP first */ | |
615 | err = cfg80211_conn_scan(wdev); | |
616 | ||
617 | /* | |
618 | * If we can't scan right now, then we need to scan again | |
619 | * after the current scan finished, since the parameters | |
620 | * changed (unless we find a good AP anyway). | |
621 | */ | |
622 | if (err == -EBUSY) { | |
623 | err = 0; | |
624 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; | |
625 | } | |
626 | } | |
627 | ||
628 | if (err) | |
629 | cfg80211_sme_free(wdev); | |
630 | ||
631 | return err; | |
632 | } | |
633 | ||
634 | static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason) | |
635 | { | |
f26cbf40 | 636 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
637 | int err; |
638 | ||
639 | if (!wdev->conn) | |
640 | return 0; | |
641 | ||
642 | if (!rdev->ops->deauth) | |
643 | return -EOPNOTSUPP; | |
644 | ||
645 | if (wdev->conn->state == CFG80211_CONN_SCANNING || | |
646 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) { | |
647 | err = 0; | |
648 | goto out; | |
649 | } | |
650 | ||
651 | /* wdev->conn->params.bssid must be set if > SCANNING */ | |
652 | err = cfg80211_mlme_deauth(rdev, wdev->netdev, | |
653 | wdev->conn->params.bssid, | |
654 | NULL, 0, reason, false); | |
655 | out: | |
656 | cfg80211_sme_free(wdev); | |
657 | return err; | |
658 | } | |
659 | ||
660 | /* | |
661 | * code shared for in-device and software SME | |
662 | */ | |
663 | ||
664 | static bool cfg80211_is_all_idle(void) | |
665 | { | |
666 | struct cfg80211_registered_device *rdev; | |
667 | struct wireless_dev *wdev; | |
668 | bool is_all_idle = true; | |
669 | ||
670 | /* | |
671 | * All devices must be idle as otherwise if you are actively | |
672 | * scanning some new beacon hints could be learned and would | |
673 | * count as new regulatory hints. | |
113f3aaa S |
674 | * Also if there is any other active beaconing interface we |
675 | * need not issue a disconnect hint and reset any info such | |
676 | * as chan dfs state, etc. | |
ceca7b71 JB |
677 | */ |
678 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
53873f13 | 679 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
ceca7b71 | 680 | wdev_lock(wdev); |
7b0a0e3c | 681 | if (wdev->conn || wdev->connected || |
113f3aaa | 682 | cfg80211_beaconing_iface_active(wdev)) |
ceca7b71 JB |
683 | is_all_idle = false; |
684 | wdev_unlock(wdev); | |
685 | } | |
686 | } | |
687 | ||
688 | return is_all_idle; | |
689 | } | |
690 | ||
691 | static void disconnect_work(struct work_struct *work) | |
692 | { | |
693 | rtnl_lock(); | |
694 | if (cfg80211_is_all_idle()) | |
695 | regulatory_hint_disconnect(); | |
696 | rtnl_unlock(); | |
697 | } | |
698 | ||
e005bd7d | 699 | DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); |
ceca7b71 | 700 | |
efbabc11 VJ |
701 | static void |
702 | cfg80211_connect_result_release_bsses(struct wireless_dev *wdev, | |
703 | struct cfg80211_connect_resp_params *cr) | |
704 | { | |
705 | unsigned int link; | |
706 | ||
707 | for_each_valid_link(cr, link) { | |
708 | if (!cr->links[link].bss) | |
709 | continue; | |
710 | cfg80211_unhold_bss(bss_from_pub(cr->links[link].bss)); | |
711 | cfg80211_put_bss(wdev->wiphy, cr->links[link].bss); | |
712 | } | |
713 | } | |
714 | ||
ceca7b71 JB |
715 | /* |
716 | * API calls for drivers implementing connect/disconnect and | |
717 | * SME event handling | |
718 | */ | |
719 | ||
6f390908 | 720 | /* This method must consume bss one way or another */ |
5349a0f7 VK |
721 | void __cfg80211_connect_result(struct net_device *dev, |
722 | struct cfg80211_connect_resp_params *cr, | |
723 | bool wextev) | |
b23aa676 SO |
724 | { |
725 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
e3d331c9 | 726 | const struct element *country_elem = NULL; |
fb8b53ac JB |
727 | const u8 *country_data; |
728 | u8 country_datalen; | |
3d23e349 | 729 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
730 | union iwreq_data wrqu; |
731 | #endif | |
efbabc11 VJ |
732 | unsigned int link; |
733 | const u8 *connected_addr; | |
734 | bool bss_not_found = false; | |
b23aa676 | 735 | |
667503dd JB |
736 | ASSERT_WDEV_LOCK(wdev); |
737 | ||
074ac8df | 738 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
efbabc11 VJ |
739 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) |
740 | goto out; | |
741 | ||
742 | if (cr->valid_links) { | |
743 | if (WARN_ON(!cr->ap_mld_addr)) | |
744 | goto out; | |
745 | ||
746 | for_each_valid_link(cr, link) { | |
747 | if (WARN_ON(!cr->links[link].addr)) | |
748 | goto out; | |
749 | } | |
5ec245e4 VJ |
750 | |
751 | if (WARN_ON(wdev->connect_keys)) | |
752 | goto out; | |
6f390908 | 753 | } |
b23aa676 | 754 | |
4d797fce | 755 | wdev->unprot_beacon_reported = 0; |
5349a0f7 VK |
756 | nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, cr, |
757 | GFP_KERNEL); | |
efbabc11 | 758 | connected_addr = cr->valid_links ? cr->ap_mld_addr : cr->links[0].bssid; |
e45cd82a | 759 | |
3d23e349 | 760 | #ifdef CONFIG_CFG80211_WEXT |
efbabc11 | 761 | if (wextev && !cr->valid_links) { |
5349a0f7 | 762 | if (cr->req_ie && cr->status == WLAN_STATUS_SUCCESS) { |
e45cd82a | 763 | memset(&wrqu, 0, sizeof(wrqu)); |
5349a0f7 VK |
764 | wrqu.data.length = cr->req_ie_len; |
765 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, | |
766 | cr->req_ie); | |
e45cd82a JB |
767 | } |
768 | ||
5349a0f7 | 769 | if (cr->resp_ie && cr->status == WLAN_STATUS_SUCCESS) { |
e45cd82a | 770 | memset(&wrqu, 0, sizeof(wrqu)); |
5349a0f7 VK |
771 | wrqu.data.length = cr->resp_ie_len; |
772 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, | |
773 | cr->resp_ie); | |
e45cd82a JB |
774 | } |
775 | ||
776 | memset(&wrqu, 0, sizeof(wrqu)); | |
777 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
efbabc11 VJ |
778 | if (connected_addr && cr->status == WLAN_STATUS_SUCCESS) { |
779 | memcpy(wrqu.ap_addr.sa_data, connected_addr, ETH_ALEN); | |
780 | memcpy(wdev->wext.prev_bssid, connected_addr, ETH_ALEN); | |
f401a6f7 JB |
781 | wdev->wext.prev_bssid_valid = true; |
782 | } | |
e45cd82a JB |
783 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
784 | } | |
785 | #endif | |
786 | ||
efbabc11 VJ |
787 | if (cr->status == WLAN_STATUS_SUCCESS) { |
788 | for_each_valid_link(cr, link) { | |
789 | if (WARN_ON_ONCE(!cr->links[link].bss)) | |
790 | break; | |
791 | } | |
792 | ||
793 | for_each_valid_link(cr, link) { | |
794 | if (cr->links[link].bss) | |
795 | continue; | |
796 | ||
797 | cr->links[link].bss = | |
798 | cfg80211_get_bss(wdev->wiphy, NULL, | |
799 | cr->links[link].bssid, | |
800 | wdev->u.client.ssid, | |
801 | wdev->u.client.ssid_len, | |
802 | wdev->conn_bss_type, | |
803 | IEEE80211_PRIVACY_ANY); | |
804 | if (!cr->links[link].bss) { | |
805 | bss_not_found = true; | |
806 | break; | |
807 | } | |
808 | cfg80211_hold_bss(bss_from_pub(cr->links[link].bss)); | |
809 | } | |
4c4d684a UR |
810 | } |
811 | ||
7b0a0e3c | 812 | cfg80211_wdev_release_bsses(wdev); |
df7fc0f9 | 813 | |
5349a0f7 | 814 | if (cr->status != WLAN_STATUS_SUCCESS) { |
453431a5 | 815 | kfree_sensitive(wdev->connect_keys); |
fffd0934 | 816 | wdev->connect_keys = NULL; |
7b0a0e3c | 817 | wdev->u.client.ssid_len = 0; |
bd2522b1 | 818 | wdev->conn_owner_nlportid = 0; |
efbabc11 | 819 | cfg80211_connect_result_release_bsses(wdev, cr); |
c1fbb258 | 820 | cfg80211_sme_free(wdev); |
fffd0934 | 821 | return; |
b23aa676 | 822 | } |
fffd0934 | 823 | |
efbabc11 VJ |
824 | if (WARN_ON(bss_not_found)) { |
825 | cfg80211_connect_result_release_bsses(wdev, cr); | |
4c4d684a | 826 | return; |
efbabc11 | 827 | } |
fffd0934 | 828 | |
efbabc11 VJ |
829 | memset(wdev->links, 0, sizeof(wdev->links)); |
830 | wdev->valid_links = cr->valid_links; | |
831 | for_each_valid_link(cr, link) | |
832 | wdev->links[link].client.current_bss = | |
833 | bss_from_pub(cr->links[link].bss); | |
7b0a0e3c | 834 | wdev->connected = true; |
efbabc11 VJ |
835 | ether_addr_copy(wdev->u.client.connected_addr, connected_addr); |
836 | if (cr->valid_links) { | |
837 | for_each_valid_link(cr, link) | |
838 | memcpy(wdev->links[link].addr, cr->links[link].addr, | |
839 | ETH_ALEN); | |
840 | } | |
fffd0934 | 841 | |
b8676221 DS |
842 | if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP)) |
843 | cfg80211_upload_connect_keys(wdev); | |
8b19e6ca | 844 | |
9caf0364 | 845 | rcu_read_lock(); |
efbabc11 VJ |
846 | for_each_valid_link(cr, link) { |
847 | country_elem = | |
848 | ieee80211_bss_get_elem(cr->links[link].bss, | |
849 | WLAN_EID_COUNTRY); | |
850 | if (country_elem) | |
851 | break; | |
852 | } | |
fb8b53ac | 853 | if (!country_elem) { |
9caf0364 JB |
854 | rcu_read_unlock(); |
855 | return; | |
856 | } | |
857 | ||
fb8b53ac JB |
858 | country_datalen = country_elem->datalen; |
859 | country_data = kmemdup(country_elem->data, country_datalen, GFP_ATOMIC); | |
9caf0364 | 860 | rcu_read_unlock(); |
8b19e6ca | 861 | |
fb8b53ac | 862 | if (!country_data) |
8b19e6ca LR |
863 | return; |
864 | ||
efbabc11 VJ |
865 | regulatory_hint_country_ie(wdev->wiphy, |
866 | cr->links[link].bss->channel->band, | |
fb8b53ac JB |
867 | country_data, country_datalen); |
868 | kfree(country_data); | |
efbabc11 VJ |
869 | |
870 | return; | |
871 | out: | |
872 | for_each_valid_link(cr, link) | |
873 | cfg80211_put_bss(wdev->wiphy, cr->links[link].bss); | |
b23aa676 | 874 | } |
f2129354 | 875 | |
efbabc11 VJ |
876 | static void cfg80211_update_link_bss(struct wireless_dev *wdev, |
877 | struct cfg80211_bss **bss) | |
878 | { | |
879 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
880 | struct cfg80211_internal_bss *ibss; | |
881 | ||
882 | if (!*bss) | |
883 | return; | |
884 | ||
885 | ibss = bss_from_pub(*bss); | |
886 | if (list_empty(&ibss->list)) { | |
887 | struct cfg80211_bss *found = NULL, *tmp = *bss; | |
888 | ||
889 | found = cfg80211_get_bss(wdev->wiphy, NULL, | |
890 | (*bss)->bssid, | |
891 | wdev->u.client.ssid, | |
892 | wdev->u.client.ssid_len, | |
893 | wdev->conn_bss_type, | |
894 | IEEE80211_PRIVACY_ANY); | |
895 | if (found) { | |
896 | /* The same BSS is already updated so use it | |
897 | * instead, as it has latest info. | |
898 | */ | |
899 | *bss = found; | |
900 | } else { | |
901 | /* Update with BSS provided by driver, it will | |
902 | * be freshly added and ref cnted, we can free | |
903 | * the old one. | |
904 | * | |
905 | * signal_valid can be false, as we are not | |
906 | * expecting the BSS to be found. | |
907 | * | |
908 | * keep the old timestamp to avoid confusion | |
909 | */ | |
910 | cfg80211_bss_update(rdev, ibss, false, | |
911 | ibss->ts); | |
912 | } | |
913 | ||
914 | cfg80211_put_bss(wdev->wiphy, tmp); | |
915 | } | |
916 | } | |
917 | ||
918 | /* Consumes bss object(s) one way or another */ | |
5349a0f7 VK |
919 | void cfg80211_connect_done(struct net_device *dev, |
920 | struct cfg80211_connect_resp_params *params, | |
921 | gfp_t gfp) | |
f2129354 | 922 | { |
667503dd | 923 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 924 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
925 | struct cfg80211_event *ev; |
926 | unsigned long flags; | |
5349a0f7 | 927 | u8 *next; |
efbabc11 VJ |
928 | size_t link_info_size = 0; |
929 | unsigned int link; | |
667503dd | 930 | |
efbabc11 VJ |
931 | for_each_valid_link(params, link) { |
932 | cfg80211_update_link_bss(wdev, ¶ms->links[link].bss); | |
933 | link_info_size += params->links[link].bssid ? ETH_ALEN : 0; | |
934 | link_info_size += params->links[link].addr ? ETH_ALEN : 0; | |
e7054989 KV |
935 | } |
936 | ||
efbabc11 | 937 | ev = kzalloc(sizeof(*ev) + (params->ap_mld_addr ? ETH_ALEN : 0) + |
a3caf744 | 938 | params->req_ie_len + params->resp_ie_len + |
76804d28 | 939 | params->fils.kek_len + params->fils.pmk_len + |
efbabc11 VJ |
940 | (params->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size, |
941 | gfp); | |
942 | ||
e7054989 | 943 | if (!ev) { |
efbabc11 VJ |
944 | for_each_valid_link(params, link) |
945 | cfg80211_put_bss(wdev->wiphy, | |
946 | params->links[link].bss); | |
667503dd | 947 | return; |
e7054989 | 948 | } |
667503dd JB |
949 | |
950 | ev->type = EVENT_CONNECT_RESULT; | |
5349a0f7 | 951 | next = ((u8 *)ev) + sizeof(*ev); |
efbabc11 VJ |
952 | if (params->ap_mld_addr) { |
953 | ev->cr.ap_mld_addr = next; | |
954 | memcpy((void *)ev->cr.ap_mld_addr, params->ap_mld_addr, | |
955 | ETH_ALEN); | |
5349a0f7 | 956 | next += ETH_ALEN; |
7834704b | 957 | } |
5349a0f7 VK |
958 | if (params->req_ie_len) { |
959 | ev->cr.req_ie = next; | |
960 | ev->cr.req_ie_len = params->req_ie_len; | |
961 | memcpy((void *)ev->cr.req_ie, params->req_ie, | |
962 | params->req_ie_len); | |
963 | next += params->req_ie_len; | |
7834704b | 964 | } |
5349a0f7 VK |
965 | if (params->resp_ie_len) { |
966 | ev->cr.resp_ie = next; | |
967 | ev->cr.resp_ie_len = params->resp_ie_len; | |
968 | memcpy((void *)ev->cr.resp_ie, params->resp_ie, | |
969 | params->resp_ie_len); | |
970 | next += params->resp_ie_len; | |
971 | } | |
76804d28 AVS |
972 | if (params->fils.kek_len) { |
973 | ev->cr.fils.kek = next; | |
974 | ev->cr.fils.kek_len = params->fils.kek_len; | |
975 | memcpy((void *)ev->cr.fils.kek, params->fils.kek, | |
976 | params->fils.kek_len); | |
977 | next += params->fils.kek_len; | |
a3caf744 | 978 | } |
76804d28 AVS |
979 | if (params->fils.pmk_len) { |
980 | ev->cr.fils.pmk = next; | |
981 | ev->cr.fils.pmk_len = params->fils.pmk_len; | |
982 | memcpy((void *)ev->cr.fils.pmk, params->fils.pmk, | |
983 | params->fils.pmk_len); | |
984 | next += params->fils.pmk_len; | |
a3caf744 | 985 | } |
76804d28 AVS |
986 | if (params->fils.pmkid) { |
987 | ev->cr.fils.pmkid = next; | |
988 | memcpy((void *)ev->cr.fils.pmkid, params->fils.pmkid, | |
989 | WLAN_PMKID_LEN); | |
a3caf744 VK |
990 | next += WLAN_PMKID_LEN; |
991 | } | |
76804d28 AVS |
992 | ev->cr.fils.update_erp_next_seq_num = params->fils.update_erp_next_seq_num; |
993 | if (params->fils.update_erp_next_seq_num) | |
994 | ev->cr.fils.erp_next_seq_num = params->fils.erp_next_seq_num; | |
efbabc11 VJ |
995 | ev->cr.valid_links = params->valid_links; |
996 | for_each_valid_link(params, link) { | |
997 | if (params->links[link].bss) | |
998 | cfg80211_hold_bss( | |
999 | bss_from_pub(params->links[link].bss)); | |
1000 | ev->cr.links[link].bss = params->links[link].bss; | |
1001 | ||
1002 | if (params->links[link].addr) { | |
1003 | ev->cr.links[link].addr = next; | |
1004 | memcpy((void *)ev->cr.links[link].addr, | |
1005 | params->links[link].addr, | |
1006 | ETH_ALEN); | |
1007 | next += ETH_ALEN; | |
1008 | } | |
1009 | if (params->links[link].bssid) { | |
1010 | ev->cr.links[link].bssid = next; | |
1011 | memcpy((void *)ev->cr.links[link].bssid, | |
1012 | params->links[link].bssid, | |
1013 | ETH_ALEN); | |
1014 | next += ETH_ALEN; | |
1015 | } | |
1016 | } | |
5349a0f7 VK |
1017 | ev->cr.status = params->status; |
1018 | ev->cr.timeout_reason = params->timeout_reason; | |
667503dd JB |
1019 | |
1020 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1021 | list_add_tail(&ev->list, &wdev->event_list); | |
1022 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 1023 | queue_work(cfg80211_wq, &rdev->event_work); |
f2129354 | 1024 | } |
5349a0f7 | 1025 | EXPORT_SYMBOL(cfg80211_connect_done); |
b23aa676 | 1026 | |
0e3a39b5 | 1027 | /* Consumes bss object one way or another */ |
ed9d0102 | 1028 | void __cfg80211_roamed(struct wireless_dev *wdev, |
29ce6ecb | 1029 | struct cfg80211_roam_info *info) |
b23aa676 | 1030 | { |
3d23e349 | 1031 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
1032 | union iwreq_data wrqu; |
1033 | #endif | |
efbabc11 VJ |
1034 | unsigned int link; |
1035 | const u8 *connected_addr; | |
1036 | ||
667503dd JB |
1037 | ASSERT_WDEV_LOCK(wdev); |
1038 | ||
074ac8df JB |
1039 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
1040 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) | |
adbde344 | 1041 | goto out; |
b23aa676 | 1042 | |
7b0a0e3c | 1043 | if (WARN_ON(!wdev->connected)) |
adbde344 | 1044 | goto out; |
b23aa676 | 1045 | |
efbabc11 VJ |
1046 | if (info->valid_links) { |
1047 | if (WARN_ON(!info->ap_mld_addr)) | |
1048 | goto out; | |
1049 | ||
1050 | for_each_valid_link(info, link) { | |
1051 | if (WARN_ON(!info->links[link].addr)) | |
1052 | goto out; | |
1053 | } | |
1054 | } | |
1055 | ||
7b0a0e3c | 1056 | cfg80211_wdev_release_bsses(wdev); |
b23aa676 | 1057 | |
efbabc11 VJ |
1058 | for_each_valid_link(info, link) { |
1059 | if (WARN_ON(!info->links[link].bss)) | |
1060 | goto out; | |
1061 | } | |
29ce6ecb | 1062 | |
efbabc11 VJ |
1063 | memset(wdev->links, 0, sizeof(wdev->links)); |
1064 | wdev->valid_links = info->valid_links; | |
1065 | for_each_valid_link(info, link) { | |
1066 | cfg80211_hold_bss(bss_from_pub(info->links[link].bss)); | |
1067 | wdev->links[link].client.current_bss = | |
1068 | bss_from_pub(info->links[link].bss); | |
1069 | } | |
b23aa676 | 1070 | |
efbabc11 VJ |
1071 | connected_addr = info->valid_links ? |
1072 | info->ap_mld_addr : | |
1073 | info->links[0].bss->bssid; | |
1074 | ether_addr_copy(wdev->u.client.connected_addr, connected_addr); | |
1075 | if (info->valid_links) { | |
1076 | for_each_valid_link(info, link) | |
1077 | memcpy(wdev->links[link].addr, info->links[link].addr, | |
1078 | ETH_ALEN); | |
1079 | } | |
4d797fce | 1080 | wdev->unprot_beacon_reported = 0; |
f26cbf40 | 1081 | nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy), |
29ce6ecb | 1082 | wdev->netdev, info, GFP_KERNEL); |
b23aa676 | 1083 | |
3d23e349 | 1084 | #ifdef CONFIG_CFG80211_WEXT |
efbabc11 VJ |
1085 | if (!info->valid_links) { |
1086 | if (info->req_ie) { | |
1087 | memset(&wrqu, 0, sizeof(wrqu)); | |
1088 | wrqu.data.length = info->req_ie_len; | |
1089 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, | |
1090 | &wrqu, info->req_ie); | |
1091 | } | |
1092 | ||
1093 | if (info->resp_ie) { | |
1094 | memset(&wrqu, 0, sizeof(wrqu)); | |
1095 | wrqu.data.length = info->resp_ie_len; | |
1096 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, | |
1097 | &wrqu, info->resp_ie); | |
1098 | } | |
b23aa676 | 1099 | |
b23aa676 | 1100 | memset(&wrqu, 0, sizeof(wrqu)); |
efbabc11 VJ |
1101 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
1102 | memcpy(wrqu.ap_addr.sa_data, connected_addr, ETH_ALEN); | |
1103 | memcpy(wdev->wext.prev_bssid, connected_addr, ETH_ALEN); | |
1104 | wdev->wext.prev_bssid_valid = true; | |
1105 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); | |
b23aa676 | 1106 | } |
b23aa676 | 1107 | #endif |
adbde344 VT |
1108 | |
1109 | return; | |
1110 | out: | |
efbabc11 VJ |
1111 | for_each_valid_link(info, link) |
1112 | cfg80211_put_bss(wdev->wiphy, info->links[link].bss); | |
adbde344 | 1113 | } |
adbde344 | 1114 | |
efbabc11 | 1115 | /* Consumes info->links.bss object(s) one way or another */ |
29ce6ecb AS |
1116 | void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info, |
1117 | gfp_t gfp) | |
667503dd JB |
1118 | { |
1119 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 1120 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
1121 | struct cfg80211_event *ev; |
1122 | unsigned long flags; | |
e841b7b1 | 1123 | u8 *next; |
efbabc11 VJ |
1124 | unsigned int link; |
1125 | size_t link_info_size = 0; | |
1126 | bool bss_not_found = false; | |
1127 | ||
1128 | for_each_valid_link(info, link) { | |
1129 | link_info_size += info->links[link].addr ? ETH_ALEN : 0; | |
1130 | link_info_size += info->links[link].bssid ? ETH_ALEN : 0; | |
1131 | ||
1132 | if (info->links[link].bss) | |
1133 | continue; | |
667503dd | 1134 | |
efbabc11 VJ |
1135 | info->links[link].bss = |
1136 | cfg80211_get_bss(wdev->wiphy, | |
1137 | info->links[link].channel, | |
1138 | info->links[link].bssid, | |
1139 | wdev->u.client.ssid, | |
1140 | wdev->u.client.ssid_len, | |
1141 | wdev->conn_bss_type, | |
1142 | IEEE80211_PRIVACY_ANY); | |
1143 | ||
1144 | if (!info->links[link].bss) { | |
1145 | bss_not_found = true; | |
1146 | break; | |
1147 | } | |
29ce6ecb AS |
1148 | } |
1149 | ||
efbabc11 VJ |
1150 | if (WARN_ON(bss_not_found)) |
1151 | goto out; | |
adbde344 | 1152 | |
e841b7b1 AVS |
1153 | ev = kzalloc(sizeof(*ev) + info->req_ie_len + info->resp_ie_len + |
1154 | info->fils.kek_len + info->fils.pmk_len + | |
efbabc11 VJ |
1155 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0) + |
1156 | (info->ap_mld_addr ? ETH_ALEN : 0) + link_info_size, gfp); | |
1157 | if (!ev) | |
1158 | goto out; | |
667503dd JB |
1159 | |
1160 | ev->type = EVENT_ROAMED; | |
e841b7b1 AVS |
1161 | next = ((u8 *)ev) + sizeof(*ev); |
1162 | if (info->req_ie_len) { | |
1163 | ev->rm.req_ie = next; | |
1164 | ev->rm.req_ie_len = info->req_ie_len; | |
1165 | memcpy((void *)ev->rm.req_ie, info->req_ie, info->req_ie_len); | |
1166 | next += info->req_ie_len; | |
1167 | } | |
1168 | if (info->resp_ie_len) { | |
1169 | ev->rm.resp_ie = next; | |
1170 | ev->rm.resp_ie_len = info->resp_ie_len; | |
1171 | memcpy((void *)ev->rm.resp_ie, info->resp_ie, | |
1172 | info->resp_ie_len); | |
1173 | next += info->resp_ie_len; | |
1174 | } | |
1175 | if (info->fils.kek_len) { | |
1176 | ev->rm.fils.kek = next; | |
1177 | ev->rm.fils.kek_len = info->fils.kek_len; | |
1178 | memcpy((void *)ev->rm.fils.kek, info->fils.kek, | |
1179 | info->fils.kek_len); | |
1180 | next += info->fils.kek_len; | |
1181 | } | |
1182 | if (info->fils.pmk_len) { | |
1183 | ev->rm.fils.pmk = next; | |
1184 | ev->rm.fils.pmk_len = info->fils.pmk_len; | |
1185 | memcpy((void *)ev->rm.fils.pmk, info->fils.pmk, | |
1186 | info->fils.pmk_len); | |
1187 | next += info->fils.pmk_len; | |
1188 | } | |
1189 | if (info->fils.pmkid) { | |
1190 | ev->rm.fils.pmkid = next; | |
1191 | memcpy((void *)ev->rm.fils.pmkid, info->fils.pmkid, | |
1192 | WLAN_PMKID_LEN); | |
1193 | next += WLAN_PMKID_LEN; | |
1194 | } | |
1195 | ev->rm.fils.update_erp_next_seq_num = info->fils.update_erp_next_seq_num; | |
1196 | if (info->fils.update_erp_next_seq_num) | |
1197 | ev->rm.fils.erp_next_seq_num = info->fils.erp_next_seq_num; | |
efbabc11 VJ |
1198 | if (info->ap_mld_addr) { |
1199 | ev->rm.ap_mld_addr = next; | |
1200 | memcpy((void *)ev->rm.ap_mld_addr, info->ap_mld_addr, | |
1201 | ETH_ALEN); | |
1202 | next += ETH_ALEN; | |
1203 | } | |
1204 | ev->rm.valid_links = info->valid_links; | |
1205 | for_each_valid_link(info, link) { | |
1206 | ev->rm.links[link].bss = info->links[link].bss; | |
1207 | ||
1208 | if (info->links[link].addr) { | |
1209 | ev->rm.links[link].addr = next; | |
1210 | memcpy((void *)ev->rm.links[link].addr, | |
1211 | info->links[link].addr, | |
1212 | ETH_ALEN); | |
1213 | next += ETH_ALEN; | |
1214 | } | |
1215 | ||
1216 | if (info->links[link].bssid) { | |
1217 | ev->rm.links[link].bssid = next; | |
1218 | memcpy((void *)ev->rm.links[link].bssid, | |
1219 | info->links[link].bssid, | |
1220 | ETH_ALEN); | |
1221 | next += ETH_ALEN; | |
1222 | } | |
1223 | } | |
667503dd JB |
1224 | |
1225 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1226 | list_add_tail(&ev->list, &wdev->event_list); | |
1227 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 1228 | queue_work(cfg80211_wq, &rdev->event_work); |
efbabc11 VJ |
1229 | |
1230 | return; | |
1231 | out: | |
1232 | for_each_valid_link(info, link) | |
1233 | cfg80211_put_bss(wdev->wiphy, info->links[link].bss); | |
1234 | ||
667503dd | 1235 | } |
29ce6ecb | 1236 | EXPORT_SYMBOL(cfg80211_roamed); |
b23aa676 | 1237 | |
503c1fb9 AS |
1238 | void __cfg80211_port_authorized(struct wireless_dev *wdev, const u8 *bssid) |
1239 | { | |
1240 | ASSERT_WDEV_LOCK(wdev); | |
1241 | ||
8d70f33e VY |
1242 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
1243 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) | |
503c1fb9 AS |
1244 | return; |
1245 | ||
7b0a0e3c JB |
1246 | if (WARN_ON(!wdev->connected) || |
1247 | WARN_ON(!ether_addr_equal(wdev->u.client.connected_addr, bssid))) | |
503c1fb9 AS |
1248 | return; |
1249 | ||
1250 | nl80211_send_port_authorized(wiphy_to_rdev(wdev->wiphy), wdev->netdev, | |
1251 | bssid); | |
1252 | } | |
1253 | ||
1254 | void cfg80211_port_authorized(struct net_device *dev, const u8 *bssid, | |
1255 | gfp_t gfp) | |
1256 | { | |
1257 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1258 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
1259 | struct cfg80211_event *ev; | |
1260 | unsigned long flags; | |
1261 | ||
1262 | if (WARN_ON(!bssid)) | |
1263 | return; | |
1264 | ||
1265 | ev = kzalloc(sizeof(*ev), gfp); | |
1266 | if (!ev) | |
1267 | return; | |
1268 | ||
1269 | ev->type = EVENT_PORT_AUTHORIZED; | |
1270 | memcpy(ev->pa.bssid, bssid, ETH_ALEN); | |
1271 | ||
1272 | /* | |
1273 | * Use the wdev event list so that if there are pending | |
1274 | * connected/roamed events, they will be reported first. | |
1275 | */ | |
1276 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1277 | list_add_tail(&ev->list, &wdev->event_list); | |
1278 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
1279 | queue_work(cfg80211_wq, &rdev->event_work); | |
1280 | } | |
1281 | EXPORT_SYMBOL(cfg80211_port_authorized); | |
1282 | ||
667503dd | 1283 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
6829c878 | 1284 | size_t ie_len, u16 reason, bool from_ap) |
b23aa676 SO |
1285 | { |
1286 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 1287 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
fffd0934 | 1288 | int i; |
3d23e349 | 1289 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
1290 | union iwreq_data wrqu; |
1291 | #endif | |
1292 | ||
667503dd JB |
1293 | ASSERT_WDEV_LOCK(wdev); |
1294 | ||
074ac8df JB |
1295 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
1296 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) | |
b23aa676 SO |
1297 | return; |
1298 | ||
7b0a0e3c JB |
1299 | cfg80211_wdev_release_bsses(wdev); |
1300 | wdev->connected = false; | |
1301 | wdev->u.client.ssid_len = 0; | |
bd2522b1 | 1302 | wdev->conn_owner_nlportid = 0; |
453431a5 | 1303 | kfree_sensitive(wdev->connect_keys); |
3027a8e7 | 1304 | wdev->connect_keys = NULL; |
b23aa676 | 1305 | |
fffd0934 JB |
1306 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
1307 | ||
b8607152 AS |
1308 | /* stop critical protocol if supported */ |
1309 | if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) { | |
1310 | rdev->crit_proto_nlportid = 0; | |
1311 | rdev_crit_proto_stop(rdev, wdev); | |
1312 | } | |
1313 | ||
fffd0934 JB |
1314 | /* |
1315 | * Delete all the keys ... pairwise keys can't really | |
1316 | * exist any more anyway, but default keys might. | |
1317 | */ | |
56be393f JM |
1318 | if (rdev->ops->del_key) { |
1319 | int max_key_idx = 5; | |
1320 | ||
1321 | if (wiphy_ext_feature_isset( | |
1322 | wdev->wiphy, | |
0e47901d JB |
1323 | NL80211_EXT_FEATURE_BEACON_PROTECTION) || |
1324 | wiphy_ext_feature_isset( | |
1325 | wdev->wiphy, | |
1326 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) | |
56be393f JM |
1327 | max_key_idx = 7; |
1328 | for (i = 0; i <= max_key_idx; i++) | |
e7a7b84e | 1329 | rdev_del_key(rdev, dev, -1, i, false, NULL); |
56be393f | 1330 | } |
b23aa676 | 1331 | |
fa9ffc74 KP |
1332 | rdev_set_qos_map(rdev, dev, NULL); |
1333 | ||
3d23e349 | 1334 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
1335 | memset(&wrqu, 0, sizeof(wrqu)); |
1336 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1337 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | |
5f612033 | 1338 | wdev->wext.connect.ssid_len = 0; |
b23aa676 | 1339 | #endif |
09d989d1 LR |
1340 | |
1341 | schedule_work(&cfg80211_disconnect_work); | |
b23aa676 SO |
1342 | } |
1343 | ||
1344 | void cfg80211_disconnected(struct net_device *dev, u16 reason, | |
80279fb7 JB |
1345 | const u8 *ie, size_t ie_len, |
1346 | bool locally_generated, gfp_t gfp) | |
b23aa676 | 1347 | { |
667503dd | 1348 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 1349 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
1350 | struct cfg80211_event *ev; |
1351 | unsigned long flags; | |
1352 | ||
1353 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); | |
1354 | if (!ev) | |
1355 | return; | |
1356 | ||
1357 | ev->type = EVENT_DISCONNECTED; | |
1358 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); | |
1359 | ev->dc.ie_len = ie_len; | |
1360 | memcpy((void *)ev->dc.ie, ie, ie_len); | |
1361 | ev->dc.reason = reason; | |
80279fb7 | 1362 | ev->dc.locally_generated = locally_generated; |
667503dd JB |
1363 | |
1364 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1365 | list_add_tail(&ev->list, &wdev->event_list); | |
1366 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 1367 | queue_work(cfg80211_wq, &rdev->event_work); |
b23aa676 SO |
1368 | } |
1369 | EXPORT_SYMBOL(cfg80211_disconnected); | |
1370 | ||
ceca7b71 JB |
1371 | /* |
1372 | * API calls for nl80211/wext compatibility code | |
1373 | */ | |
83739b03 JB |
1374 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
1375 | struct net_device *dev, | |
1376 | struct cfg80211_connect_params *connect, | |
1377 | struct cfg80211_cached_keys *connkeys, | |
1378 | const u8 *prev_bssid) | |
b23aa676 | 1379 | { |
b23aa676 | 1380 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
667503dd JB |
1381 | int err; |
1382 | ||
1383 | ASSERT_WDEV_LOCK(wdev); | |
b23aa676 | 1384 | |
51e13359 JB |
1385 | /* |
1386 | * If we have an ssid_len, we're trying to connect or are | |
1387 | * already connected, so reject a new SSID unless it's the | |
1388 | * same (which is the case for re-association.) | |
1389 | */ | |
7b0a0e3c JB |
1390 | if (wdev->u.client.ssid_len && |
1391 | (wdev->u.client.ssid_len != connect->ssid_len || | |
1392 | memcmp(wdev->u.client.ssid, connect->ssid, wdev->u.client.ssid_len))) | |
51e13359 JB |
1393 | return -EALREADY; |
1394 | ||
1395 | /* | |
1396 | * If connected, reject (re-)association unless prev_bssid | |
1397 | * matches the current BSSID. | |
1398 | */ | |
7b0a0e3c | 1399 | if (wdev->connected) { |
51e13359 JB |
1400 | if (!prev_bssid) |
1401 | return -EALREADY; | |
7b0a0e3c JB |
1402 | if (!ether_addr_equal(prev_bssid, |
1403 | wdev->u.client.connected_addr)) | |
51e13359 | 1404 | return -ENOTCONN; |
fffd0934 JB |
1405 | } |
1406 | ||
51e13359 JB |
1407 | /* |
1408 | * Reject if we're in the process of connecting with WEP, | |
1409 | * this case isn't very interesting and trying to handle | |
1410 | * it would make the code much more complex. | |
1411 | */ | |
1412 | if (wdev->connect_keys) | |
1413 | return -EINPROGRESS; | |
1414 | ||
7e7c8926 BG |
1415 | cfg80211_oper_and_ht_capa(&connect->ht_capa_mask, |
1416 | rdev->wiphy.ht_capa_mod_mask); | |
81c5dce2 SM |
1417 | cfg80211_oper_and_vht_capa(&connect->vht_capa_mask, |
1418 | rdev->wiphy.vht_capa_mod_mask); | |
7e7c8926 | 1419 | |
fffd0934 JB |
1420 | if (connkeys && connkeys->def >= 0) { |
1421 | int idx; | |
bcba8eae | 1422 | u32 cipher; |
fffd0934 JB |
1423 | |
1424 | idx = connkeys->def; | |
bcba8eae | 1425 | cipher = connkeys->params[idx].cipher; |
fffd0934 | 1426 | /* If given a WEP key we may need it for shared key auth */ |
bcba8eae SO |
1427 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
1428 | cipher == WLAN_CIPHER_SUITE_WEP104) { | |
fffd0934 JB |
1429 | connect->key_idx = idx; |
1430 | connect->key = connkeys->params[idx].key; | |
1431 | connect->key_len = connkeys->params[idx].key_len; | |
bcba8eae SO |
1432 | |
1433 | /* | |
1434 | * If ciphers are not set (e.g. when going through | |
1435 | * iwconfig), we have to set them appropriately here. | |
1436 | */ | |
1437 | if (connect->crypto.cipher_group == 0) | |
1438 | connect->crypto.cipher_group = cipher; | |
1439 | ||
1440 | if (connect->crypto.n_ciphers_pairwise == 0) { | |
1441 | connect->crypto.n_ciphers_pairwise = 1; | |
1442 | connect->crypto.ciphers_pairwise[0] = cipher; | |
1443 | } | |
fffd0934 | 1444 | } |
b8676221 DS |
1445 | |
1446 | connect->crypto.wep_keys = connkeys->params; | |
1447 | connect->crypto.wep_tx_key = connkeys->def; | |
f1c1f17a JB |
1448 | } else { |
1449 | if (WARN_ON(connkeys)) | |
1450 | return -EINVAL; | |
fffd0934 JB |
1451 | } |
1452 | ||
ceca7b71 | 1453 | wdev->connect_keys = connkeys; |
7b0a0e3c JB |
1454 | memcpy(wdev->u.client.ssid, connect->ssid, connect->ssid_len); |
1455 | wdev->u.client.ssid_len = connect->ssid_len; | |
6829c878 | 1456 | |
34d50519 LD |
1457 | wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS : |
1458 | IEEE80211_BSS_TYPE_ESS; | |
1459 | ||
ceca7b71 JB |
1460 | if (!rdev->ops->connect) |
1461 | err = cfg80211_sme_connect(wdev, connect, prev_bssid); | |
1462 | else | |
e35e4d28 | 1463 | err = rdev_connect(rdev, dev, connect); |
b23aa676 | 1464 | |
ceca7b71 JB |
1465 | if (err) { |
1466 | wdev->connect_keys = NULL; | |
51e13359 JB |
1467 | /* |
1468 | * This could be reassoc getting refused, don't clear | |
1469 | * ssid_len in that case. | |
1470 | */ | |
7b0a0e3c JB |
1471 | if (!wdev->connected) |
1472 | wdev->u.client.ssid_len = 0; | |
ceca7b71 | 1473 | return err; |
6829c878 | 1474 | } |
ceca7b71 JB |
1475 | |
1476 | return 0; | |
b23aa676 SO |
1477 | } |
1478 | ||
83739b03 JB |
1479 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
1480 | struct net_device *dev, u16 reason, bool wextev) | |
b23aa676 | 1481 | { |
6829c878 | 1482 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
dee8a973 | 1483 | int err = 0; |
b23aa676 | 1484 | |
667503dd JB |
1485 | ASSERT_WDEV_LOCK(wdev); |
1486 | ||
453431a5 | 1487 | kfree_sensitive(wdev->connect_keys); |
fffd0934 JB |
1488 | wdev->connect_keys = NULL; |
1489 | ||
bd2522b1 AZ |
1490 | wdev->conn_owner_nlportid = 0; |
1491 | ||
dee8a973 | 1492 | if (wdev->conn) |
ceca7b71 | 1493 | err = cfg80211_sme_disconnect(wdev, reason); |
dee8a973 | 1494 | else if (!rdev->ops->disconnect) |
ceca7b71 | 1495 | cfg80211_mlme_down(rdev, dev); |
7b0a0e3c | 1496 | else if (wdev->u.client.ssid_len) |
e35e4d28 | 1497 | err = rdev_disconnect(rdev, dev, reason); |
b23aa676 | 1498 | |
51e13359 JB |
1499 | /* |
1500 | * Clear ssid_len unless we actually were fully connected, | |
1501 | * in which case cfg80211_disconnected() will take care of | |
1502 | * this later. | |
1503 | */ | |
7b0a0e3c JB |
1504 | if (!wdev->connected) |
1505 | wdev->u.client.ssid_len = 0; | |
51e13359 | 1506 | |
ceca7b71 | 1507 | return err; |
19957bb3 | 1508 | } |
bd2522b1 AZ |
1509 | |
1510 | /* | |
1511 | * Used to clean up after the connection / connection attempt owner socket | |
1512 | * disconnects | |
1513 | */ | |
1514 | void cfg80211_autodisconnect_wk(struct work_struct *work) | |
1515 | { | |
1516 | struct wireless_dev *wdev = | |
1517 | container_of(work, struct wireless_dev, disconnect_wk); | |
1518 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
1519 | ||
1520 | wdev_lock(wdev); | |
1521 | ||
1522 | if (wdev->conn_owner_nlportid) { | |
37b1c004 DK |
1523 | switch (wdev->iftype) { |
1524 | case NL80211_IFTYPE_ADHOC: | |
5a128a08 | 1525 | __cfg80211_leave_ibss(rdev, wdev->netdev, false); |
37b1c004 DK |
1526 | break; |
1527 | case NL80211_IFTYPE_AP: | |
1528 | case NL80211_IFTYPE_P2P_GO: | |
7b0a0e3c | 1529 | __cfg80211_stop_ap(rdev, wdev->netdev, -1, false); |
37b1c004 DK |
1530 | break; |
1531 | case NL80211_IFTYPE_MESH_POINT: | |
5a128a08 | 1532 | __cfg80211_leave_mesh(rdev, wdev->netdev); |
37b1c004 DK |
1533 | break; |
1534 | case NL80211_IFTYPE_STATION: | |
1535 | case NL80211_IFTYPE_P2P_CLIENT: | |
1536 | /* | |
1537 | * Use disconnect_bssid if still connecting and | |
1538 | * ops->disconnect not implemented. Otherwise we can | |
1539 | * use cfg80211_disconnect. | |
1540 | */ | |
7b0a0e3c | 1541 | if (rdev->ops->disconnect || wdev->connected) |
37b1c004 DK |
1542 | cfg80211_disconnect(rdev, wdev->netdev, |
1543 | WLAN_REASON_DEAUTH_LEAVING, | |
1544 | true); | |
1545 | else | |
1546 | cfg80211_mlme_deauth(rdev, wdev->netdev, | |
1547 | wdev->disconnect_bssid, | |
1548 | NULL, 0, | |
1549 | WLAN_REASON_DEAUTH_LEAVING, | |
1550 | false); | |
1551 | break; | |
1552 | default: | |
1553 | break; | |
1554 | } | |
bd2522b1 AZ |
1555 | } |
1556 | ||
1557 | wdev_unlock(wdev); | |
1558 | } |