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