]>
Commit | Line | Data |
---|---|---|
b23aa676 | 1 | /* |
ceca7b71 JB |
2 | * SME code for cfg80211 |
3 | * both driver SME event handling and the SME implementation | |
4 | * (for nl80211's connect() and wext) | |
b23aa676 SO |
5 | * |
6 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> | |
7 | * Copyright (C) 2009 Intel Corporation. All rights reserved. | |
8 | */ | |
9 | ||
10 | #include <linux/etherdevice.h> | |
11 | #include <linux/if_arp.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
b23aa676 | 13 | #include <linux/workqueue.h> |
a9a11622 | 14 | #include <linux/wireless.h> |
bc3b2d7f | 15 | #include <linux/export.h> |
a9a11622 | 16 | #include <net/iw_handler.h> |
b23aa676 SO |
17 | #include <net/cfg80211.h> |
18 | #include <net/rtnetlink.h> | |
19 | #include "nl80211.h" | |
8b19e6ca | 20 | #include "reg.h" |
e35e4d28 | 21 | #include "rdev-ops.h" |
b23aa676 | 22 | |
ceca7b71 JB |
23 | /* |
24 | * Software SME in cfg80211, using auth/assoc/deauth calls to the | |
25 | * driver. This is is for implementing nl80211's connect/disconnect | |
26 | * and wireless extensions (if configured.) | |
27 | */ | |
28 | ||
6829c878 JB |
29 | struct cfg80211_conn { |
30 | struct cfg80211_connect_params params; | |
31 | /* these are sub-states of the _CONNECTING sme_state */ | |
32 | enum { | |
6829c878 JB |
33 | CFG80211_CONN_SCANNING, |
34 | CFG80211_CONN_SCAN_AGAIN, | |
35 | CFG80211_CONN_AUTHENTICATE_NEXT, | |
36 | CFG80211_CONN_AUTHENTICATING, | |
923a0e7d | 37 | CFG80211_CONN_AUTH_FAILED, |
6829c878 JB |
38 | CFG80211_CONN_ASSOCIATE_NEXT, |
39 | CFG80211_CONN_ASSOCIATING, | |
923a0e7d | 40 | CFG80211_CONN_ASSOC_FAILED, |
ceca7b71 JB |
41 | CFG80211_CONN_DEAUTH, |
42 | CFG80211_CONN_CONNECTED, | |
6829c878 | 43 | } state; |
f401a6f7 | 44 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
46b9d180 | 45 | const u8 *ie; |
6829c878 | 46 | size_t ie_len; |
f401a6f7 | 47 | bool auto_auth, prev_bssid_valid; |
6829c878 JB |
48 | }; |
49 | ||
ceca7b71 | 50 | static void cfg80211_sme_free(struct wireless_dev *wdev) |
09d989d1 | 51 | { |
ceca7b71 JB |
52 | if (!wdev->conn) |
53 | return; | |
09d989d1 | 54 | |
ceca7b71 JB |
55 | kfree(wdev->conn->ie); |
56 | kfree(wdev->conn); | |
57 | wdev->conn = NULL; | |
09d989d1 LR |
58 | } |
59 | ||
6829c878 JB |
60 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
61 | { | |
f26cbf40 | 62 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
6829c878 JB |
63 | struct cfg80211_scan_request *request; |
64 | int n_channels, err; | |
65 | ||
66 | ASSERT_RTNL(); | |
667503dd | 67 | ASSERT_WDEV_LOCK(wdev); |
6829c878 | 68 | |
f9d15d16 | 69 | if (rdev->scan_req || rdev->scan_msg) |
6829c878 JB |
70 | return -EBUSY; |
71 | ||
bdfbec2d | 72 | if (wdev->conn->params.channel) |
6829c878 | 73 | n_channels = 1; |
bdfbec2d IP |
74 | else |
75 | n_channels = ieee80211_get_num_supported_channels(wdev->wiphy); | |
6829c878 | 76 | |
6829c878 JB |
77 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
78 | sizeof(request->channels[0]) * n_channels, | |
79 | GFP_KERNEL); | |
80 | if (!request) | |
81 | return -ENOMEM; | |
82 | ||
2a84ee86 | 83 | if (wdev->conn->params.channel) { |
57fbcce3 | 84 | enum nl80211_band band = wdev->conn->params.channel->band; |
2a84ee86 KB |
85 | struct ieee80211_supported_band *sband = |
86 | wdev->wiphy->bands[band]; | |
87 | ||
88 | if (!sband) { | |
89 | kfree(request); | |
90 | return -EINVAL; | |
91 | } | |
6829c878 | 92 | request->channels[0] = wdev->conn->params.channel; |
2a84ee86 KB |
93 | request->rates[band] = (1 << sband->n_bitrates) - 1; |
94 | } else { | |
6829c878 | 95 | int i = 0, j; |
57fbcce3 | 96 | enum nl80211_band band; |
e3081501 RM |
97 | struct ieee80211_supported_band *bands; |
98 | struct ieee80211_channel *channel; | |
6829c878 | 99 | |
57fbcce3 | 100 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
e3081501 RM |
101 | bands = wdev->wiphy->bands[band]; |
102 | if (!bands) | |
6829c878 | 103 | continue; |
e3081501 RM |
104 | for (j = 0; j < bands->n_channels; j++) { |
105 | channel = &bands->channels[j]; | |
106 | if (channel->flags & IEEE80211_CHAN_DISABLED) | |
107 | continue; | |
108 | request->channels[i++] = channel; | |
109 | } | |
110 | request->rates[band] = (1 << bands->n_bitrates) - 1; | |
6829c878 | 111 | } |
e3081501 | 112 | n_channels = i; |
6829c878 JB |
113 | } |
114 | request->n_channels = n_channels; | |
5ba63533 | 115 | request->ssids = (void *)&request->channels[n_channels]; |
6829c878 JB |
116 | request->n_ssids = 1; |
117 | ||
118 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, | |
119 | wdev->conn->params.ssid_len); | |
120 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; | |
121 | ||
818965d3 JM |
122 | eth_broadcast_addr(request->bssid); |
123 | ||
fd014284 | 124 | request->wdev = wdev; |
79c97e97 | 125 | request->wiphy = &rdev->wiphy; |
15d6030b | 126 | request->scan_start = jiffies; |
6829c878 | 127 | |
79c97e97 | 128 | rdev->scan_req = request; |
6829c878 | 129 | |
e35e4d28 | 130 | err = rdev_scan(rdev, request); |
6829c878 JB |
131 | if (!err) { |
132 | wdev->conn->state = CFG80211_CONN_SCANNING; | |
fd014284 | 133 | nl80211_send_scan_start(rdev, wdev); |
463d0183 | 134 | dev_hold(wdev->netdev); |
6829c878 | 135 | } else { |
79c97e97 | 136 | rdev->scan_req = NULL; |
6829c878 JB |
137 | kfree(request); |
138 | } | |
139 | return err; | |
140 | } | |
141 | ||
142 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) | |
143 | { | |
f26cbf40 | 144 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
19957bb3 | 145 | struct cfg80211_connect_params *params; |
f62fab73 | 146 | struct cfg80211_assoc_request req = {}; |
19957bb3 | 147 | int err; |
6829c878 | 148 | |
667503dd JB |
149 | ASSERT_WDEV_LOCK(wdev); |
150 | ||
6829c878 JB |
151 | if (!wdev->conn) |
152 | return 0; | |
153 | ||
19957bb3 JB |
154 | params = &wdev->conn->params; |
155 | ||
6829c878 | 156 | switch (wdev->conn->state) { |
ceca7b71 JB |
157 | case CFG80211_CONN_SCANNING: |
158 | /* didn't find it during scan ... */ | |
159 | return -ENOENT; | |
6829c878 JB |
160 | case CFG80211_CONN_SCAN_AGAIN: |
161 | return cfg80211_conn_scan(wdev); | |
162 | case CFG80211_CONN_AUTHENTICATE_NEXT: | |
2fd05115 JB |
163 | if (WARN_ON(!rdev->ops->auth)) |
164 | return -EOPNOTSUPP; | |
19957bb3 | 165 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
91bf9b26 JB |
166 | return cfg80211_mlme_auth(rdev, wdev->netdev, |
167 | params->channel, params->auth_type, | |
168 | params->bssid, | |
169 | params->ssid, params->ssid_len, | |
170 | NULL, 0, | |
171 | params->key, params->key_len, | |
172 | params->key_idx, NULL, 0); | |
923a0e7d JB |
173 | case CFG80211_CONN_AUTH_FAILED: |
174 | return -ENOTCONN; | |
6829c878 | 175 | case CFG80211_CONN_ASSOCIATE_NEXT: |
2fd05115 JB |
176 | if (WARN_ON(!rdev->ops->assoc)) |
177 | return -EOPNOTSUPP; | |
19957bb3 | 178 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
f401a6f7 | 179 | if (wdev->conn->prev_bssid_valid) |
f62fab73 JB |
180 | req.prev_bssid = wdev->conn->prev_bssid; |
181 | req.ie = params->ie; | |
182 | req.ie_len = params->ie_len; | |
183 | req.use_mfp = params->mfp != NL80211_MFP_NO; | |
184 | req.crypto = params->crypto; | |
185 | req.flags = params->flags; | |
186 | req.ht_capa = params->ht_capa; | |
187 | req.ht_capa_mask = params->ht_capa_mask; | |
188 | req.vht_capa = params->vht_capa; | |
189 | req.vht_capa_mask = params->vht_capa_mask; | |
190 | ||
91bf9b26 JB |
191 | err = cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel, |
192 | params->bssid, params->ssid, | |
193 | params->ssid_len, &req); | |
19957bb3 | 194 | if (err) |
91bf9b26 JB |
195 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
196 | NULL, 0, | |
197 | WLAN_REASON_DEAUTH_LEAVING, | |
198 | false); | |
19957bb3 | 199 | return err; |
923a0e7d JB |
200 | case CFG80211_CONN_ASSOC_FAILED: |
201 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, | |
202 | NULL, 0, | |
203 | WLAN_REASON_DEAUTH_LEAVING, false); | |
204 | return -ENOTCONN; | |
ceca7b71 | 205 | case CFG80211_CONN_DEAUTH: |
91bf9b26 JB |
206 | cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
207 | NULL, 0, | |
208 | WLAN_REASON_DEAUTH_LEAVING, false); | |
923a0e7d JB |
209 | /* free directly, disconnected event already sent */ |
210 | cfg80211_sme_free(wdev); | |
ceca7b71 | 211 | return 0; |
6829c878 JB |
212 | default: |
213 | return 0; | |
214 | } | |
215 | } | |
216 | ||
217 | void cfg80211_conn_work(struct work_struct *work) | |
218 | { | |
79c97e97 | 219 | struct cfg80211_registered_device *rdev = |
6829c878 JB |
220 | container_of(work, struct cfg80211_registered_device, conn_work); |
221 | struct wireless_dev *wdev; | |
7400f42e | 222 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
6829c878 JB |
223 | |
224 | rtnl_lock(); | |
6829c878 | 225 | |
89a54e48 | 226 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
c8157976 JB |
227 | if (!wdev->netdev) |
228 | continue; | |
229 | ||
667503dd JB |
230 | wdev_lock(wdev); |
231 | if (!netif_running(wdev->netdev)) { | |
232 | wdev_unlock(wdev); | |
6829c878 | 233 | continue; |
667503dd | 234 | } |
ceca7b71 JB |
235 | if (!wdev->conn || |
236 | wdev->conn->state == CFG80211_CONN_CONNECTED) { | |
667503dd | 237 | wdev_unlock(wdev); |
6829c878 | 238 | continue; |
667503dd | 239 | } |
7400f42e JB |
240 | if (wdev->conn->params.bssid) { |
241 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); | |
242 | bssid = bssid_buf; | |
243 | } | |
ceca7b71 | 244 | if (cfg80211_conn_do_work(wdev)) { |
667503dd | 245 | __cfg80211_connect_result( |
7d930bc3 | 246 | wdev->netdev, bssid, |
667503dd JB |
247 | NULL, 0, NULL, 0, |
248 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
df7fc0f9 | 249 | false, NULL); |
ceca7b71 | 250 | } |
667503dd | 251 | wdev_unlock(wdev); |
6829c878 JB |
252 | } |
253 | ||
6829c878 JB |
254 | rtnl_unlock(); |
255 | } | |
256 | ||
0e3a39b5 | 257 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
bbac31f4 | 258 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
6829c878 | 259 | { |
f26cbf40 | 260 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
6829c878 | 261 | struct cfg80211_bss *bss; |
6829c878 | 262 | |
667503dd JB |
263 | ASSERT_WDEV_LOCK(wdev); |
264 | ||
ed9d0102 JM |
265 | bss = cfg80211_get_bss(wdev->wiphy, wdev->conn->params.channel, |
266 | wdev->conn->params.bssid, | |
6829c878 JB |
267 | wdev->conn->params.ssid, |
268 | wdev->conn->params.ssid_len, | |
34d50519 | 269 | wdev->conn_bss_type, |
6eb18137 | 270 | IEEE80211_PRIVACY(wdev->conn->params.privacy)); |
6829c878 | 271 | if (!bss) |
bbac31f4 | 272 | return NULL; |
6829c878 JB |
273 | |
274 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); | |
275 | wdev->conn->params.bssid = wdev->conn->bssid; | |
276 | wdev->conn->params.channel = bss->channel; | |
277 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; | |
79c97e97 | 278 | schedule_work(&rdev->conn_work); |
6829c878 | 279 | |
bbac31f4 | 280 | return bss; |
6829c878 JB |
281 | } |
282 | ||
667503dd | 283 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
6829c878 JB |
284 | { |
285 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 286 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
bbac31f4 | 287 | struct cfg80211_bss *bss; |
6829c878 | 288 | |
667503dd JB |
289 | ASSERT_WDEV_LOCK(wdev); |
290 | ||
d4b1a687 | 291 | if (!wdev->conn) |
6829c878 JB |
292 | return; |
293 | ||
294 | if (wdev->conn->state != CFG80211_CONN_SCANNING && | |
295 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) | |
296 | return; | |
297 | ||
bbac31f4 | 298 | bss = cfg80211_get_conn_bss(wdev); |
ceca7b71 | 299 | if (bss) |
5b112d3d | 300 | cfg80211_put_bss(&rdev->wiphy, bss); |
ceca7b71 JB |
301 | else |
302 | schedule_work(&rdev->conn_work); | |
6829c878 JB |
303 | } |
304 | ||
667503dd JB |
305 | void cfg80211_sme_scan_done(struct net_device *dev) |
306 | { | |
307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
308 | ||
309 | wdev_lock(wdev); | |
310 | __cfg80211_sme_scan_done(dev); | |
311 | wdev_unlock(wdev); | |
312 | } | |
313 | ||
ceca7b71 | 314 | void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len) |
6829c878 | 315 | { |
6829c878 | 316 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 317 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6829c878 JB |
318 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
319 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
320 | ||
667503dd JB |
321 | ASSERT_WDEV_LOCK(wdev); |
322 | ||
ceca7b71 | 323 | if (!wdev->conn || wdev->conn->state == CFG80211_CONN_CONNECTED) |
6829c878 JB |
324 | return; |
325 | ||
326 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && | |
327 | wdev->conn->auto_auth && | |
328 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { | |
329 | /* select automatically between only open, shared, leap */ | |
330 | switch (wdev->conn->params.auth_type) { | |
331 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
fffd0934 JB |
332 | if (wdev->connect_keys) |
333 | wdev->conn->params.auth_type = | |
334 | NL80211_AUTHTYPE_SHARED_KEY; | |
335 | else | |
336 | wdev->conn->params.auth_type = | |
337 | NL80211_AUTHTYPE_NETWORK_EAP; | |
6829c878 JB |
338 | break; |
339 | case NL80211_AUTHTYPE_SHARED_KEY: | |
340 | wdev->conn->params.auth_type = | |
341 | NL80211_AUTHTYPE_NETWORK_EAP; | |
342 | break; | |
343 | default: | |
344 | /* huh? */ | |
345 | wdev->conn->params.auth_type = | |
346 | NL80211_AUTHTYPE_OPEN_SYSTEM; | |
347 | break; | |
348 | } | |
349 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; | |
350 | schedule_work(&rdev->conn_work); | |
19957bb3 | 351 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
ceca7b71 JB |
352 | __cfg80211_connect_result(wdev->netdev, mgmt->bssid, |
353 | NULL, 0, NULL, 0, | |
df7fc0f9 | 354 | status_code, false, NULL); |
ceca7b71 | 355 | } else if (wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
6829c878 JB |
356 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
357 | schedule_work(&rdev->conn_work); | |
358 | } | |
359 | } | |
b23aa676 | 360 | |
ceca7b71 | 361 | bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status) |
f401a6f7 | 362 | { |
f26cbf40 | 363 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
f401a6f7 | 364 | |
ceca7b71 | 365 | if (!wdev->conn) |
f401a6f7 JB |
366 | return false; |
367 | ||
ceca7b71 JB |
368 | if (status == WLAN_STATUS_SUCCESS) { |
369 | wdev->conn->state = CFG80211_CONN_CONNECTED; | |
f401a6f7 | 370 | return false; |
ceca7b71 | 371 | } |
f401a6f7 | 372 | |
ceca7b71 JB |
373 | if (wdev->conn->prev_bssid_valid) { |
374 | /* | |
375 | * Some stupid APs don't accept reassoc, so we | |
376 | * need to fall back to trying regular assoc; | |
377 | * return true so no event is sent to userspace. | |
378 | */ | |
379 | wdev->conn->prev_bssid_valid = false; | |
380 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; | |
381 | schedule_work(&rdev->conn_work); | |
382 | return true; | |
383 | } | |
384 | ||
923a0e7d | 385 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; |
f401a6f7 | 386 | schedule_work(&rdev->conn_work); |
ceca7b71 JB |
387 | return false; |
388 | } | |
f401a6f7 | 389 | |
ceca7b71 JB |
390 | void cfg80211_sme_deauth(struct wireless_dev *wdev) |
391 | { | |
392 | cfg80211_sme_free(wdev); | |
f401a6f7 JB |
393 | } |
394 | ||
ceca7b71 | 395 | void cfg80211_sme_auth_timeout(struct wireless_dev *wdev) |
7d930bc3 | 396 | { |
f26cbf40 | 397 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
923a0e7d JB |
398 | |
399 | if (!wdev->conn) | |
400 | return; | |
401 | ||
402 | wdev->conn->state = CFG80211_CONN_AUTH_FAILED; | |
403 | schedule_work(&rdev->conn_work); | |
ceca7b71 | 404 | } |
7d930bc3 | 405 | |
ceca7b71 JB |
406 | void cfg80211_sme_disassoc(struct wireless_dev *wdev) |
407 | { | |
f26cbf40 | 408 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
409 | |
410 | if (!wdev->conn) | |
411 | return; | |
412 | ||
413 | wdev->conn->state = CFG80211_CONN_DEAUTH; | |
7d930bc3 JB |
414 | schedule_work(&rdev->conn_work); |
415 | } | |
416 | ||
ceca7b71 JB |
417 | void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev) |
418 | { | |
f26cbf40 | 419 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
923a0e7d JB |
420 | |
421 | if (!wdev->conn) | |
422 | return; | |
423 | ||
424 | wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; | |
425 | schedule_work(&rdev->conn_work); | |
ceca7b71 JB |
426 | } |
427 | ||
46b9d180 JB |
428 | static int cfg80211_sme_get_conn_ies(struct wireless_dev *wdev, |
429 | const u8 *ies, size_t ies_len, | |
430 | const u8 **out_ies, size_t *out_ies_len) | |
431 | { | |
432 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
433 | u8 *buf; | |
434 | size_t offs; | |
435 | ||
436 | if (!rdev->wiphy.extended_capabilities_len || | |
437 | (ies && cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, ies, ies_len))) { | |
438 | *out_ies = kmemdup(ies, ies_len, GFP_KERNEL); | |
439 | if (!*out_ies) | |
440 | return -ENOMEM; | |
441 | *out_ies_len = ies_len; | |
442 | return 0; | |
443 | } | |
444 | ||
445 | buf = kmalloc(ies_len + rdev->wiphy.extended_capabilities_len + 2, | |
446 | GFP_KERNEL); | |
447 | if (!buf) | |
448 | return -ENOMEM; | |
449 | ||
450 | if (ies_len) { | |
451 | static const u8 before_extcapa[] = { | |
452 | /* not listing IEs expected to be created by driver */ | |
453 | WLAN_EID_RSN, | |
454 | WLAN_EID_QOS_CAPA, | |
455 | WLAN_EID_RRM_ENABLED_CAPABILITIES, | |
456 | WLAN_EID_MOBILITY_DOMAIN, | |
457 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
458 | WLAN_EID_BSS_COEX_2040, | |
459 | }; | |
460 | ||
461 | offs = ieee80211_ie_split(ies, ies_len, before_extcapa, | |
462 | ARRAY_SIZE(before_extcapa), 0); | |
463 | memcpy(buf, ies, offs); | |
464 | /* leave a whole for extended capabilities IE */ | |
465 | memcpy(buf + offs + rdev->wiphy.extended_capabilities_len + 2, | |
466 | ies + offs, ies_len - offs); | |
467 | } else { | |
468 | offs = 0; | |
469 | } | |
470 | ||
471 | /* place extended capabilities IE (with only driver capabilities) */ | |
472 | buf[offs] = WLAN_EID_EXT_CAPABILITY; | |
473 | buf[offs + 1] = rdev->wiphy.extended_capabilities_len; | |
474 | memcpy(buf + offs + 2, | |
475 | rdev->wiphy.extended_capabilities, | |
476 | rdev->wiphy.extended_capabilities_len); | |
477 | ||
478 | *out_ies = buf; | |
479 | *out_ies_len = ies_len + rdev->wiphy.extended_capabilities_len + 2; | |
480 | ||
481 | return 0; | |
482 | } | |
483 | ||
ceca7b71 JB |
484 | static int cfg80211_sme_connect(struct wireless_dev *wdev, |
485 | struct cfg80211_connect_params *connect, | |
486 | const u8 *prev_bssid) | |
487 | { | |
f26cbf40 | 488 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
489 | struct cfg80211_bss *bss; |
490 | int err; | |
491 | ||
492 | if (!rdev->ops->auth || !rdev->ops->assoc) | |
493 | return -EOPNOTSUPP; | |
494 | ||
4ce2bd9c JM |
495 | if (wdev->current_bss) { |
496 | if (!prev_bssid) | |
497 | return -EALREADY; | |
498 | if (prev_bssid && | |
499 | !ether_addr_equal(prev_bssid, wdev->current_bss->pub.bssid)) | |
500 | return -ENOTCONN; | |
501 | cfg80211_unhold_bss(wdev->current_bss); | |
502 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); | |
503 | wdev->current_bss = NULL; | |
504 | ||
505 | cfg80211_sme_free(wdev); | |
506 | } | |
ceca7b71 JB |
507 | |
508 | if (WARN_ON(wdev->conn)) | |
509 | return -EINPROGRESS; | |
510 | ||
511 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); | |
512 | if (!wdev->conn) | |
513 | return -ENOMEM; | |
514 | ||
515 | /* | |
516 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. | |
517 | */ | |
518 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); | |
519 | if (connect->bssid) { | |
520 | wdev->conn->params.bssid = wdev->conn->bssid; | |
521 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); | |
522 | } | |
523 | ||
46b9d180 JB |
524 | if (cfg80211_sme_get_conn_ies(wdev, connect->ie, connect->ie_len, |
525 | &wdev->conn->ie, | |
526 | &wdev->conn->params.ie_len)) { | |
527 | kfree(wdev->conn); | |
528 | wdev->conn = NULL; | |
529 | return -ENOMEM; | |
ceca7b71 | 530 | } |
46b9d180 | 531 | wdev->conn->params.ie = wdev->conn->ie; |
ceca7b71 JB |
532 | |
533 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { | |
534 | wdev->conn->auto_auth = true; | |
535 | /* start with open system ... should mostly work */ | |
536 | wdev->conn->params.auth_type = | |
537 | NL80211_AUTHTYPE_OPEN_SYSTEM; | |
538 | } else { | |
539 | wdev->conn->auto_auth = false; | |
540 | } | |
541 | ||
542 | wdev->conn->params.ssid = wdev->ssid; | |
babd3a27 | 543 | wdev->conn->params.ssid_len = wdev->ssid_len; |
ceca7b71 JB |
544 | |
545 | /* see if we have the bss already */ | |
546 | bss = cfg80211_get_conn_bss(wdev); | |
547 | ||
548 | if (prev_bssid) { | |
549 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); | |
550 | wdev->conn->prev_bssid_valid = true; | |
551 | } | |
552 | ||
553 | /* we're good if we have a matching bss struct */ | |
554 | if (bss) { | |
ceca7b71 JB |
555 | err = cfg80211_conn_do_work(wdev); |
556 | cfg80211_put_bss(wdev->wiphy, bss); | |
557 | } else { | |
558 | /* otherwise we'll need to scan for the AP first */ | |
559 | err = cfg80211_conn_scan(wdev); | |
560 | ||
561 | /* | |
562 | * If we can't scan right now, then we need to scan again | |
563 | * after the current scan finished, since the parameters | |
564 | * changed (unless we find a good AP anyway). | |
565 | */ | |
566 | if (err == -EBUSY) { | |
567 | err = 0; | |
568 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; | |
569 | } | |
570 | } | |
571 | ||
572 | if (err) | |
573 | cfg80211_sme_free(wdev); | |
574 | ||
575 | return err; | |
576 | } | |
577 | ||
578 | static int cfg80211_sme_disconnect(struct wireless_dev *wdev, u16 reason) | |
579 | { | |
f26cbf40 | 580 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
ceca7b71 JB |
581 | int err; |
582 | ||
583 | if (!wdev->conn) | |
584 | return 0; | |
585 | ||
586 | if (!rdev->ops->deauth) | |
587 | return -EOPNOTSUPP; | |
588 | ||
589 | if (wdev->conn->state == CFG80211_CONN_SCANNING || | |
590 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) { | |
591 | err = 0; | |
592 | goto out; | |
593 | } | |
594 | ||
595 | /* wdev->conn->params.bssid must be set if > SCANNING */ | |
596 | err = cfg80211_mlme_deauth(rdev, wdev->netdev, | |
597 | wdev->conn->params.bssid, | |
598 | NULL, 0, reason, false); | |
599 | out: | |
600 | cfg80211_sme_free(wdev); | |
601 | return err; | |
602 | } | |
603 | ||
604 | /* | |
605 | * code shared for in-device and software SME | |
606 | */ | |
607 | ||
608 | static bool cfg80211_is_all_idle(void) | |
609 | { | |
610 | struct cfg80211_registered_device *rdev; | |
611 | struct wireless_dev *wdev; | |
612 | bool is_all_idle = true; | |
613 | ||
614 | /* | |
615 | * All devices must be idle as otherwise if you are actively | |
616 | * scanning some new beacon hints could be learned and would | |
617 | * count as new regulatory hints. | |
618 | */ | |
619 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
620 | list_for_each_entry(wdev, &rdev->wdev_list, list) { | |
621 | wdev_lock(wdev); | |
622 | if (wdev->conn || wdev->current_bss) | |
623 | is_all_idle = false; | |
624 | wdev_unlock(wdev); | |
625 | } | |
626 | } | |
627 | ||
628 | return is_all_idle; | |
629 | } | |
630 | ||
631 | static void disconnect_work(struct work_struct *work) | |
632 | { | |
633 | rtnl_lock(); | |
634 | if (cfg80211_is_all_idle()) | |
635 | regulatory_hint_disconnect(); | |
636 | rtnl_unlock(); | |
637 | } | |
638 | ||
639 | static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work); | |
640 | ||
641 | ||
642 | /* | |
643 | * API calls for drivers implementing connect/disconnect and | |
644 | * SME event handling | |
645 | */ | |
646 | ||
6f390908 | 647 | /* This method must consume bss one way or another */ |
667503dd JB |
648 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
649 | const u8 *req_ie, size_t req_ie_len, | |
650 | const u8 *resp_ie, size_t resp_ie_len, | |
df7fc0f9 JB |
651 | u16 status, bool wextev, |
652 | struct cfg80211_bss *bss) | |
b23aa676 SO |
653 | { |
654 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9caf0364 | 655 | const u8 *country_ie; |
3d23e349 | 656 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
657 | union iwreq_data wrqu; |
658 | #endif | |
659 | ||
667503dd JB |
660 | ASSERT_WDEV_LOCK(wdev); |
661 | ||
074ac8df | 662 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
6f390908 BG |
663 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) { |
664 | cfg80211_put_bss(wdev->wiphy, bss); | |
b23aa676 | 665 | return; |
6f390908 | 666 | } |
b23aa676 | 667 | |
f26cbf40 | 668 | nl80211_send_connect_result(wiphy_to_rdev(wdev->wiphy), dev, |
e45cd82a | 669 | bssid, req_ie, req_ie_len, |
ea416a79 JB |
670 | resp_ie, resp_ie_len, |
671 | status, GFP_KERNEL); | |
e45cd82a | 672 | |
3d23e349 | 673 | #ifdef CONFIG_CFG80211_WEXT |
e45cd82a JB |
674 | if (wextev) { |
675 | if (req_ie && status == WLAN_STATUS_SUCCESS) { | |
676 | memset(&wrqu, 0, sizeof(wrqu)); | |
677 | wrqu.data.length = req_ie_len; | |
3409ff77 | 678 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie); |
e45cd82a JB |
679 | } |
680 | ||
681 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { | |
682 | memset(&wrqu, 0, sizeof(wrqu)); | |
683 | wrqu.data.length = resp_ie_len; | |
684 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); | |
685 | } | |
686 | ||
687 | memset(&wrqu, 0, sizeof(wrqu)); | |
688 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
f401a6f7 | 689 | if (bssid && status == WLAN_STATUS_SUCCESS) { |
e45cd82a | 690 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
f401a6f7 JB |
691 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
692 | wdev->wext.prev_bssid_valid = true; | |
693 | } | |
e45cd82a JB |
694 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
695 | } | |
696 | #endif | |
697 | ||
4c4d684a | 698 | if (!bss && (status == WLAN_STATUS_SUCCESS)) { |
f26cbf40 | 699 | WARN_ON_ONCE(!wiphy_to_rdev(wdev->wiphy)->ops->connect); |
4c4d684a UR |
700 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
701 | wdev->ssid, wdev->ssid_len, | |
34d50519 | 702 | wdev->conn_bss_type, |
6eb18137 | 703 | IEEE80211_PRIVACY_ANY); |
4c4d684a UR |
704 | if (bss) |
705 | cfg80211_hold_bss(bss_from_pub(bss)); | |
706 | } | |
707 | ||
df7fc0f9 JB |
708 | if (wdev->current_bss) { |
709 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 710 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
df7fc0f9 JB |
711 | wdev->current_bss = NULL; |
712 | } | |
713 | ||
fffd0934 | 714 | if (status != WLAN_STATUS_SUCCESS) { |
b47f610b | 715 | kzfree(wdev->connect_keys); |
fffd0934 | 716 | wdev->connect_keys = NULL; |
8dadadb7 | 717 | wdev->ssid_len = 0; |
f1940c57 JB |
718 | if (bss) { |
719 | cfg80211_unhold_bss(bss_from_pub(bss)); | |
720 | cfg80211_put_bss(wdev->wiphy, bss); | |
721 | } | |
c1fbb258 | 722 | cfg80211_sme_free(wdev); |
fffd0934 | 723 | return; |
b23aa676 | 724 | } |
fffd0934 | 725 | |
4c4d684a UR |
726 | if (WARN_ON(!bss)) |
727 | return; | |
fffd0934 | 728 | |
fffd0934 JB |
729 | wdev->current_bss = bss_from_pub(bss); |
730 | ||
fffd0934 | 731 | cfg80211_upload_connect_keys(wdev); |
8b19e6ca | 732 | |
9caf0364 JB |
733 | rcu_read_lock(); |
734 | country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); | |
735 | if (!country_ie) { | |
736 | rcu_read_unlock(); | |
737 | return; | |
738 | } | |
739 | ||
740 | country_ie = kmemdup(country_ie, 2 + country_ie[1], GFP_ATOMIC); | |
741 | rcu_read_unlock(); | |
8b19e6ca LR |
742 | |
743 | if (!country_ie) | |
744 | return; | |
745 | ||
746 | /* | |
747 | * ieee80211_bss_get_ie() ensures we can access: | |
748 | * - country_ie + 2, the start of the country ie data, and | |
749 | * - and country_ie[1] which is the IE length | |
750 | */ | |
789fd033 LR |
751 | regulatory_hint_country_ie(wdev->wiphy, bss->channel->band, |
752 | country_ie + 2, country_ie[1]); | |
9caf0364 | 753 | kfree(country_ie); |
b23aa676 | 754 | } |
f2129354 JB |
755 | |
756 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, | |
757 | const u8 *req_ie, size_t req_ie_len, | |
758 | const u8 *resp_ie, size_t resp_ie_len, | |
759 | u16 status, gfp_t gfp) | |
760 | { | |
667503dd | 761 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 762 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
763 | struct cfg80211_event *ev; |
764 | unsigned long flags; | |
765 | ||
766 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); | |
767 | if (!ev) | |
768 | return; | |
769 | ||
770 | ev->type = EVENT_CONNECT_RESULT; | |
16a832e7 ZY |
771 | if (bssid) |
772 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); | |
7834704b NS |
773 | if (req_ie_len) { |
774 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); | |
775 | ev->cr.req_ie_len = req_ie_len; | |
776 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); | |
777 | } | |
778 | if (resp_ie_len) { | |
779 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; | |
780 | ev->cr.resp_ie_len = resp_ie_len; | |
781 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); | |
782 | } | |
667503dd JB |
783 | ev->cr.status = status; |
784 | ||
785 | spin_lock_irqsave(&wdev->event_lock, flags); | |
786 | list_add_tail(&ev->list, &wdev->event_list); | |
787 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 788 | queue_work(cfg80211_wq, &rdev->event_work); |
f2129354 | 789 | } |
b23aa676 SO |
790 | EXPORT_SYMBOL(cfg80211_connect_result); |
791 | ||
0e3a39b5 | 792 | /* Consumes bss object one way or another */ |
ed9d0102 | 793 | void __cfg80211_roamed(struct wireless_dev *wdev, |
adbde344 | 794 | struct cfg80211_bss *bss, |
667503dd JB |
795 | const u8 *req_ie, size_t req_ie_len, |
796 | const u8 *resp_ie, size_t resp_ie_len) | |
b23aa676 | 797 | { |
3d23e349 | 798 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
799 | union iwreq_data wrqu; |
800 | #endif | |
667503dd JB |
801 | ASSERT_WDEV_LOCK(wdev); |
802 | ||
074ac8df JB |
803 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
804 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) | |
adbde344 | 805 | goto out; |
b23aa676 | 806 | |
ceca7b71 | 807 | if (WARN_ON(!wdev->current_bss)) |
adbde344 | 808 | goto out; |
b23aa676 SO |
809 | |
810 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 811 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
b23aa676 SO |
812 | wdev->current_bss = NULL; |
813 | ||
19957bb3 JB |
814 | cfg80211_hold_bss(bss_from_pub(bss)); |
815 | wdev->current_bss = bss_from_pub(bss); | |
b23aa676 | 816 | |
f26cbf40 ZG |
817 | nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy), |
818 | wdev->netdev, bss->bssid, | |
667503dd JB |
819 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
820 | GFP_KERNEL); | |
b23aa676 | 821 | |
3d23e349 | 822 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
823 | if (req_ie) { |
824 | memset(&wrqu, 0, sizeof(wrqu)); | |
825 | wrqu.data.length = req_ie_len; | |
3409ff77 | 826 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
667503dd | 827 | &wrqu, req_ie); |
b23aa676 SO |
828 | } |
829 | ||
830 | if (resp_ie) { | |
831 | memset(&wrqu, 0, sizeof(wrqu)); | |
832 | wrqu.data.length = resp_ie_len; | |
667503dd JB |
833 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
834 | &wrqu, resp_ie); | |
b23aa676 SO |
835 | } |
836 | ||
837 | memset(&wrqu, 0, sizeof(wrqu)); | |
838 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
adbde344 VT |
839 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
840 | memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN); | |
f401a6f7 | 841 | wdev->wext.prev_bssid_valid = true; |
667503dd | 842 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
b23aa676 | 843 | #endif |
adbde344 VT |
844 | |
845 | return; | |
846 | out: | |
5b112d3d | 847 | cfg80211_put_bss(wdev->wiphy, bss); |
b23aa676 | 848 | } |
667503dd | 849 | |
ed9d0102 JM |
850 | void cfg80211_roamed(struct net_device *dev, |
851 | struct ieee80211_channel *channel, | |
852 | const u8 *bssid, | |
667503dd JB |
853 | const u8 *req_ie, size_t req_ie_len, |
854 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
adbde344 VT |
855 | { |
856 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
857 | struct cfg80211_bss *bss; | |
858 | ||
adbde344 | 859 | bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid, |
6eb18137 | 860 | wdev->ssid_len, |
34d50519 | 861 | wdev->conn_bss_type, IEEE80211_PRIVACY_ANY); |
adbde344 VT |
862 | if (WARN_ON(!bss)) |
863 | return; | |
864 | ||
865 | cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie, | |
866 | resp_ie_len, gfp); | |
867 | } | |
868 | EXPORT_SYMBOL(cfg80211_roamed); | |
869 | ||
0e3a39b5 | 870 | /* Consumes bss object one way or another */ |
adbde344 VT |
871 | void cfg80211_roamed_bss(struct net_device *dev, |
872 | struct cfg80211_bss *bss, const u8 *req_ie, | |
873 | size_t req_ie_len, const u8 *resp_ie, | |
874 | size_t resp_ie_len, gfp_t gfp) | |
667503dd JB |
875 | { |
876 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 877 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
878 | struct cfg80211_event *ev; |
879 | unsigned long flags; | |
880 | ||
adbde344 VT |
881 | if (WARN_ON(!bss)) |
882 | return; | |
883 | ||
667503dd | 884 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
adbde344 | 885 | if (!ev) { |
5b112d3d | 886 | cfg80211_put_bss(wdev->wiphy, bss); |
667503dd | 887 | return; |
adbde344 | 888 | } |
667503dd JB |
889 | |
890 | ev->type = EVENT_ROAMED; | |
667503dd JB |
891 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
892 | ev->rm.req_ie_len = req_ie_len; | |
893 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); | |
894 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; | |
895 | ev->rm.resp_ie_len = resp_ie_len; | |
896 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); | |
adbde344 | 897 | ev->rm.bss = bss; |
667503dd JB |
898 | |
899 | spin_lock_irqsave(&wdev->event_lock, flags); | |
900 | list_add_tail(&ev->list, &wdev->event_list); | |
901 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 902 | queue_work(cfg80211_wq, &rdev->event_work); |
667503dd | 903 | } |
adbde344 | 904 | EXPORT_SYMBOL(cfg80211_roamed_bss); |
b23aa676 | 905 | |
667503dd | 906 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
6829c878 | 907 | size_t ie_len, u16 reason, bool from_ap) |
b23aa676 SO |
908 | { |
909 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 910 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
fffd0934 | 911 | int i; |
3d23e349 | 912 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
913 | union iwreq_data wrqu; |
914 | #endif | |
915 | ||
667503dd JB |
916 | ASSERT_WDEV_LOCK(wdev); |
917 | ||
074ac8df JB |
918 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && |
919 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) | |
b23aa676 SO |
920 | return; |
921 | ||
b23aa676 SO |
922 | if (wdev->current_bss) { |
923 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 924 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
b23aa676 SO |
925 | } |
926 | ||
927 | wdev->current_bss = NULL; | |
8dadadb7 | 928 | wdev->ssid_len = 0; |
b23aa676 | 929 | |
fffd0934 JB |
930 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
931 | ||
b8607152 AS |
932 | /* stop critical protocol if supported */ |
933 | if (rdev->ops->crit_proto_stop && rdev->crit_proto_nlportid) { | |
934 | rdev->crit_proto_nlportid = 0; | |
935 | rdev_crit_proto_stop(rdev, wdev); | |
936 | } | |
937 | ||
fffd0934 JB |
938 | /* |
939 | * Delete all the keys ... pairwise keys can't really | |
940 | * exist any more anyway, but default keys might. | |
941 | */ | |
942 | if (rdev->ops->del_key) | |
943 | for (i = 0; i < 6; i++) | |
e35e4d28 | 944 | rdev_del_key(rdev, dev, i, false, NULL); |
b23aa676 | 945 | |
fa9ffc74 KP |
946 | rdev_set_qos_map(rdev, dev, NULL); |
947 | ||
3d23e349 | 948 | #ifdef CONFIG_CFG80211_WEXT |
b23aa676 SO |
949 | memset(&wrqu, 0, sizeof(wrqu)); |
950 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
951 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | |
5f612033 | 952 | wdev->wext.connect.ssid_len = 0; |
b23aa676 | 953 | #endif |
09d989d1 LR |
954 | |
955 | schedule_work(&cfg80211_disconnect_work); | |
b23aa676 SO |
956 | } |
957 | ||
958 | void cfg80211_disconnected(struct net_device *dev, u16 reason, | |
80279fb7 JB |
959 | const u8 *ie, size_t ie_len, |
960 | bool locally_generated, gfp_t gfp) | |
b23aa676 | 961 | { |
667503dd | 962 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 963 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
667503dd JB |
964 | struct cfg80211_event *ev; |
965 | unsigned long flags; | |
966 | ||
967 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); | |
968 | if (!ev) | |
969 | return; | |
970 | ||
971 | ev->type = EVENT_DISCONNECTED; | |
972 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); | |
973 | ev->dc.ie_len = ie_len; | |
974 | memcpy((void *)ev->dc.ie, ie, ie_len); | |
975 | ev->dc.reason = reason; | |
80279fb7 | 976 | ev->dc.locally_generated = locally_generated; |
667503dd JB |
977 | |
978 | spin_lock_irqsave(&wdev->event_lock, flags); | |
979 | list_add_tail(&ev->list, &wdev->event_list); | |
980 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 981 | queue_work(cfg80211_wq, &rdev->event_work); |
b23aa676 SO |
982 | } |
983 | EXPORT_SYMBOL(cfg80211_disconnected); | |
984 | ||
ceca7b71 JB |
985 | /* |
986 | * API calls for nl80211/wext compatibility code | |
987 | */ | |
83739b03 JB |
988 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
989 | struct net_device *dev, | |
990 | struct cfg80211_connect_params *connect, | |
991 | struct cfg80211_cached_keys *connkeys, | |
992 | const u8 *prev_bssid) | |
b23aa676 | 993 | { |
b23aa676 | 994 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
667503dd JB |
995 | int err; |
996 | ||
997 | ASSERT_WDEV_LOCK(wdev); | |
b23aa676 | 998 | |
fffd0934 | 999 | if (WARN_ON(wdev->connect_keys)) { |
b47f610b | 1000 | kzfree(wdev->connect_keys); |
fffd0934 JB |
1001 | wdev->connect_keys = NULL; |
1002 | } | |
1003 | ||
7e7c8926 BG |
1004 | cfg80211_oper_and_ht_capa(&connect->ht_capa_mask, |
1005 | rdev->wiphy.ht_capa_mod_mask); | |
1006 | ||
fffd0934 JB |
1007 | if (connkeys && connkeys->def >= 0) { |
1008 | int idx; | |
bcba8eae | 1009 | u32 cipher; |
fffd0934 JB |
1010 | |
1011 | idx = connkeys->def; | |
bcba8eae | 1012 | cipher = connkeys->params[idx].cipher; |
fffd0934 | 1013 | /* If given a WEP key we may need it for shared key auth */ |
bcba8eae SO |
1014 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
1015 | cipher == WLAN_CIPHER_SUITE_WEP104) { | |
fffd0934 JB |
1016 | connect->key_idx = idx; |
1017 | connect->key = connkeys->params[idx].key; | |
1018 | connect->key_len = connkeys->params[idx].key_len; | |
bcba8eae SO |
1019 | |
1020 | /* | |
1021 | * If ciphers are not set (e.g. when going through | |
1022 | * iwconfig), we have to set them appropriately here. | |
1023 | */ | |
1024 | if (connect->crypto.cipher_group == 0) | |
1025 | connect->crypto.cipher_group = cipher; | |
1026 | ||
1027 | if (connect->crypto.n_ciphers_pairwise == 0) { | |
1028 | connect->crypto.n_ciphers_pairwise = 1; | |
1029 | connect->crypto.ciphers_pairwise[0] = cipher; | |
1030 | } | |
fffd0934 JB |
1031 | } |
1032 | } | |
1033 | ||
ceca7b71 JB |
1034 | wdev->connect_keys = connkeys; |
1035 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); | |
1036 | wdev->ssid_len = connect->ssid_len; | |
6829c878 | 1037 | |
34d50519 LD |
1038 | wdev->conn_bss_type = connect->pbss ? IEEE80211_BSS_TYPE_PBSS : |
1039 | IEEE80211_BSS_TYPE_ESS; | |
1040 | ||
ceca7b71 JB |
1041 | if (!rdev->ops->connect) |
1042 | err = cfg80211_sme_connect(wdev, connect, prev_bssid); | |
1043 | else | |
e35e4d28 | 1044 | err = rdev_connect(rdev, dev, connect); |
b23aa676 | 1045 | |
ceca7b71 JB |
1046 | if (err) { |
1047 | wdev->connect_keys = NULL; | |
1048 | wdev->ssid_len = 0; | |
1049 | return err; | |
6829c878 | 1050 | } |
ceca7b71 JB |
1051 | |
1052 | return 0; | |
b23aa676 SO |
1053 | } |
1054 | ||
83739b03 JB |
1055 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
1056 | struct net_device *dev, u16 reason, bool wextev) | |
b23aa676 | 1057 | { |
6829c878 | 1058 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
dee8a973 | 1059 | int err = 0; |
b23aa676 | 1060 | |
667503dd JB |
1061 | ASSERT_WDEV_LOCK(wdev); |
1062 | ||
b47f610b | 1063 | kzfree(wdev->connect_keys); |
fffd0934 JB |
1064 | wdev->connect_keys = NULL; |
1065 | ||
dee8a973 | 1066 | if (wdev->conn) |
ceca7b71 | 1067 | err = cfg80211_sme_disconnect(wdev, reason); |
dee8a973 | 1068 | else if (!rdev->ops->disconnect) |
ceca7b71 | 1069 | cfg80211_mlme_down(rdev, dev); |
dee8a973 | 1070 | else if (wdev->current_bss) |
e35e4d28 | 1071 | err = rdev_disconnect(rdev, dev, reason); |
b23aa676 | 1072 | |
ceca7b71 | 1073 | return err; |
19957bb3 | 1074 | } |