]>
Commit | Line | Data |
---|---|---|
6039f6d2 JM |
1 | /* |
2 | * cfg80211 MLME SAP interface | |
3 | * | |
4 | * Copyright (c) 2009, Jouni Malinen <j@w1.fi> | |
5 | */ | |
6 | ||
7 | #include <linux/kernel.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/netdevice.h> | |
10 | #include <linux/nl80211.h> | |
a9a11622 | 11 | #include <linux/wireless.h> |
6039f6d2 | 12 | #include <net/cfg80211.h> |
a9a11622 | 13 | #include <net/iw_handler.h> |
6039f6d2 JM |
14 | #include "core.h" |
15 | #include "nl80211.h" | |
16 | ||
cb0b4beb | 17 | void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len) |
6039f6d2 | 18 | { |
19957bb3 JB |
19 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
20 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 21 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
19957bb3 JB |
22 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
23 | u8 *bssid = mgmt->bssid; | |
24 | int i; | |
25 | u16 status = le16_to_cpu(mgmt->u.auth.status_code); | |
26 | bool done = false; | |
27 | ||
667503dd | 28 | wdev_lock(wdev); |
cb0b4beb | 29 | |
19957bb3 JB |
30 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
31 | if (wdev->authtry_bsses[i] && | |
32 | memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, | |
33 | ETH_ALEN) == 0) { | |
34 | if (status == WLAN_STATUS_SUCCESS) { | |
35 | wdev->auth_bsses[i] = wdev->authtry_bsses[i]; | |
36 | } else { | |
37 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); | |
38 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); | |
39 | } | |
40 | wdev->authtry_bsses[i] = NULL; | |
41 | done = true; | |
42 | break; | |
43 | } | |
44 | } | |
45 | ||
46 | WARN_ON(!done); | |
6829c878 | 47 | |
cb0b4beb | 48 | nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL); |
6829c878 | 49 | cfg80211_sme_rx_auth(dev, buf, len); |
667503dd JB |
50 | |
51 | wdev_unlock(wdev); | |
6039f6d2 JM |
52 | } |
53 | EXPORT_SYMBOL(cfg80211_send_rx_auth); | |
54 | ||
cb0b4beb | 55 | void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len) |
6039f6d2 | 56 | { |
6829c878 JB |
57 | u16 status_code; |
58 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 60 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 JB |
61 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
62 | u8 *ie = mgmt->u.assoc_resp.variable; | |
19957bb3 | 63 | int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); |
df7fc0f9 | 64 | struct cfg80211_internal_bss *bss = NULL; |
6829c878 | 65 | |
667503dd | 66 | wdev_lock(wdev); |
cb0b4beb | 67 | |
6829c878 JB |
68 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
69 | ||
f401a6f7 JB |
70 | /* |
71 | * This is a bit of a hack, we don't notify userspace of | |
72 | * a (re-)association reply if we tried to send a reassoc | |
73 | * and got a reject -- we only try again with an assoc | |
74 | * frame instead of reassoc. | |
75 | */ | |
76 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn && | |
77 | cfg80211_sme_failed_reassoc(wdev)) | |
78 | goto out; | |
79 | ||
cb0b4beb | 80 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); |
6829c878 | 81 | |
19957bb3 | 82 | if (status_code == WLAN_STATUS_SUCCESS) { |
df7fc0f9 JB |
83 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
84 | if (!wdev->auth_bsses[i]) | |
85 | continue; | |
86 | if (memcmp(wdev->auth_bsses[i]->pub.bssid, mgmt->bssid, | |
87 | ETH_ALEN) == 0) { | |
88 | bss = wdev->auth_bsses[i]; | |
19957bb3 | 89 | wdev->auth_bsses[i] = NULL; |
df7fc0f9 JB |
90 | /* additional reference to drop hold */ |
91 | cfg80211_ref_bss(bss); | |
19957bb3 JB |
92 | break; |
93 | } | |
94 | } | |
95 | ||
df7fc0f9 | 96 | WARN_ON(!bss); |
7d930bc3 JB |
97 | } else if (wdev->conn) { |
98 | cfg80211_sme_failed_assoc(wdev); | |
7d930bc3 JB |
99 | /* |
100 | * do not call connect_result() now because the | |
101 | * sme will schedule work that does it later. | |
102 | */ | |
103 | goto out; | |
df7fc0f9 JB |
104 | } |
105 | ||
ea416a79 JB |
106 | if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) { |
107 | /* | |
108 | * This is for the userspace SME, the CONNECTING | |
109 | * state will be changed to CONNECTED by | |
110 | * __cfg80211_connect_result() below. | |
111 | */ | |
112 | wdev->sme_state = CFG80211_SME_CONNECTING; | |
113 | } | |
114 | ||
df7fc0f9 JB |
115 | /* this consumes one bss reference (unless bss is NULL) */ |
116 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, | |
117 | status_code, | |
118 | status_code == WLAN_STATUS_SUCCESS, | |
119 | bss ? &bss->pub : NULL); | |
120 | /* drop hold now, and also reference acquired above */ | |
121 | if (bss) { | |
122 | cfg80211_unhold_bss(bss); | |
123 | cfg80211_put_bss(&bss->pub); | |
19957bb3 | 124 | } |
667503dd | 125 | |
f401a6f7 | 126 | out: |
667503dd | 127 | wdev_unlock(wdev); |
6039f6d2 JM |
128 | } |
129 | EXPORT_SYMBOL(cfg80211_send_rx_assoc); | |
130 | ||
ce470613 | 131 | void __cfg80211_send_deauth(struct net_device *dev, |
667503dd | 132 | const u8 *buf, size_t len) |
6039f6d2 | 133 | { |
6829c878 JB |
134 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
135 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 136 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 | 137 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
19957bb3 JB |
138 | const u8 *bssid = mgmt->bssid; |
139 | int i; | |
5fba4af3 | 140 | bool found = false; |
6829c878 | 141 | |
667503dd | 142 | ASSERT_WDEV_LOCK(wdev); |
cb0b4beb | 143 | |
19957bb3 JB |
144 | if (wdev->current_bss && |
145 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { | |
19957bb3 JB |
146 | cfg80211_unhold_bss(wdev->current_bss); |
147 | cfg80211_put_bss(&wdev->current_bss->pub); | |
148 | wdev->current_bss = NULL; | |
5fba4af3 | 149 | found = true; |
19957bb3 JB |
150 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
151 | if (wdev->auth_bsses[i] && | |
152 | memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { | |
153 | cfg80211_unhold_bss(wdev->auth_bsses[i]); | |
154 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); | |
155 | wdev->auth_bsses[i] = NULL; | |
5fba4af3 | 156 | found = true; |
19957bb3 JB |
157 | break; |
158 | } | |
159 | if (wdev->authtry_bsses[i] && | |
160 | memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { | |
161 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); | |
162 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); | |
163 | wdev->authtry_bsses[i] = NULL; | |
5fba4af3 | 164 | found = true; |
19957bb3 JB |
165 | break; |
166 | } | |
167 | } | |
19957bb3 | 168 | |
5fba4af3 JB |
169 | if (!found) |
170 | return; | |
171 | ||
172 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); | |
173 | ||
6829c878 JB |
174 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { |
175 | u16 reason_code; | |
176 | bool from_ap; | |
177 | ||
178 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
179 | ||
e458b8a2 | 180 | from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0; |
667503dd | 181 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
6829c878 | 182 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING) { |
667503dd JB |
183 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
184 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
df7fc0f9 | 185 | false, NULL); |
667503dd JB |
186 | } |
187 | } | |
ce470613 | 188 | EXPORT_SYMBOL(__cfg80211_send_deauth); |
667503dd | 189 | |
ce470613 | 190 | void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len) |
667503dd JB |
191 | { |
192 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
193 | ||
ce470613 HS |
194 | wdev_lock(wdev); |
195 | __cfg80211_send_deauth(dev, buf, len); | |
196 | wdev_unlock(wdev); | |
6039f6d2 | 197 | } |
53b46b84 | 198 | EXPORT_SYMBOL(cfg80211_send_deauth); |
6039f6d2 | 199 | |
ce470613 | 200 | void __cfg80211_send_disassoc(struct net_device *dev, |
667503dd | 201 | const u8 *buf, size_t len) |
6039f6d2 | 202 | { |
6829c878 JB |
203 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
204 | struct wiphy *wiphy = wdev->wiphy; | |
6039f6d2 | 205 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
6829c878 | 206 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
19957bb3 JB |
207 | const u8 *bssid = mgmt->bssid; |
208 | int i; | |
209 | u16 reason_code; | |
210 | bool from_ap; | |
211 | bool done = false; | |
6829c878 | 212 | |
596a07c1 | 213 | ASSERT_WDEV_LOCK(wdev); |
cb0b4beb JB |
214 | |
215 | nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); | |
a3b8b056 | 216 | |
596a07c1 JB |
217 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
218 | return; | |
6829c878 | 219 | |
19957bb3 | 220 | if (wdev->current_bss && |
b935df01 | 221 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
19957bb3 JB |
222 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
223 | if (wdev->authtry_bsses[i] || wdev->auth_bsses[i]) | |
224 | continue; | |
225 | wdev->auth_bsses[i] = wdev->current_bss; | |
226 | wdev->current_bss = NULL; | |
227 | done = true; | |
228 | cfg80211_sme_disassoc(dev, i); | |
229 | break; | |
230 | } | |
231 | WARN_ON(!done); | |
232 | } else | |
233 | WARN_ON(1); | |
6829c878 | 234 | |
6829c878 | 235 | |
19957bb3 JB |
236 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
237 | ||
e458b8a2 | 238 | from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0; |
667503dd | 239 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
667503dd | 240 | } |
ce470613 | 241 | EXPORT_SYMBOL(__cfg80211_send_disassoc); |
667503dd | 242 | |
ce470613 | 243 | void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len) |
667503dd JB |
244 | { |
245 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
246 | ||
ce470613 HS |
247 | wdev_lock(wdev); |
248 | __cfg80211_send_disassoc(dev, buf, len); | |
249 | wdev_unlock(wdev); | |
1965c853 | 250 | } |
6829c878 | 251 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
1965c853 | 252 | |
a58ce43f | 253 | static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr) |
1965c853 | 254 | { |
19957bb3 JB |
255 | int i; |
256 | bool done = false; | |
257 | ||
a58ce43f | 258 | ASSERT_WDEV_LOCK(wdev); |
19957bb3 JB |
259 | |
260 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { | |
261 | if (wdev->authtry_bsses[i] && | |
262 | memcmp(wdev->authtry_bsses[i]->pub.bssid, | |
263 | addr, ETH_ALEN) == 0) { | |
264 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); | |
265 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); | |
266 | wdev->authtry_bsses[i] = NULL; | |
267 | done = true; | |
268 | break; | |
269 | } | |
270 | } | |
271 | ||
272 | WARN_ON(!done); | |
a58ce43f JB |
273 | } |
274 | ||
275 | void __cfg80211_auth_canceled(struct net_device *dev, const u8 *addr) | |
276 | { | |
277 | __cfg80211_auth_remove(dev->ieee80211_ptr, addr); | |
278 | } | |
279 | EXPORT_SYMBOL(__cfg80211_auth_canceled); | |
280 | ||
281 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) | |
282 | { | |
283 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
284 | struct wiphy *wiphy = wdev->wiphy; | |
285 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
286 | ||
287 | wdev_lock(wdev); | |
288 | ||
289 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); | |
290 | if (wdev->sme_state == CFG80211_SME_CONNECTING) | |
291 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, | |
292 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
293 | false, NULL); | |
294 | ||
295 | __cfg80211_auth_remove(wdev, addr); | |
667503dd JB |
296 | |
297 | wdev_unlock(wdev); | |
1965c853 JM |
298 | } |
299 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); | |
300 | ||
cb0b4beb | 301 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
1965c853 | 302 | { |
6829c878 JB |
303 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
304 | struct wiphy *wiphy = wdev->wiphy; | |
1965c853 | 305 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
19957bb3 JB |
306 | int i; |
307 | bool done = false; | |
308 | ||
667503dd | 309 | wdev_lock(wdev); |
cb0b4beb JB |
310 | |
311 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); | |
6829c878 | 312 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
667503dd JB |
313 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
314 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
df7fc0f9 | 315 | false, NULL); |
19957bb3 JB |
316 | |
317 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { | |
318 | if (wdev->auth_bsses[i] && | |
319 | memcmp(wdev->auth_bsses[i]->pub.bssid, | |
320 | addr, ETH_ALEN) == 0) { | |
321 | cfg80211_unhold_bss(wdev->auth_bsses[i]); | |
322 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); | |
323 | wdev->auth_bsses[i] = NULL; | |
324 | done = true; | |
325 | break; | |
326 | } | |
327 | } | |
328 | ||
329 | WARN_ON(!done); | |
667503dd JB |
330 | |
331 | wdev_unlock(wdev); | |
1965c853 JM |
332 | } |
333 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); | |
334 | ||
a3b8b056 JM |
335 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
336 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 337 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
338 | { |
339 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | |
340 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
3d23e349 | 341 | #ifdef CONFIG_CFG80211_WEXT |
f58d4ed9 | 342 | union iwreq_data wrqu; |
e6d6e342 | 343 | char *buf = kmalloc(128, gfp); |
f58d4ed9 JB |
344 | |
345 | if (buf) { | |
346 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" | |
347 | "keyid=%d %scast addr=%pM)", key_id, | |
348 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", | |
349 | addr); | |
350 | memset(&wrqu, 0, sizeof(wrqu)); | |
351 | wrqu.data.length = strlen(buf); | |
352 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); | |
353 | kfree(buf); | |
354 | } | |
355 | #endif | |
356 | ||
e6d6e342 | 357 | nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp); |
a3b8b056 JM |
358 | } |
359 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); | |
19957bb3 JB |
360 | |
361 | /* some MLME handling for userspace SME */ | |
667503dd JB |
362 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
363 | struct net_device *dev, | |
364 | struct ieee80211_channel *chan, | |
365 | enum nl80211_auth_type auth_type, | |
366 | const u8 *bssid, | |
367 | const u8 *ssid, int ssid_len, | |
fffd0934 JB |
368 | const u8 *ie, int ie_len, |
369 | const u8 *key, int key_len, int key_idx) | |
19957bb3 JB |
370 | { |
371 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
372 | struct cfg80211_auth_request req; | |
373 | struct cfg80211_internal_bss *bss; | |
374 | int i, err, slot = -1, nfree = 0; | |
375 | ||
667503dd JB |
376 | ASSERT_WDEV_LOCK(wdev); |
377 | ||
fffd0934 JB |
378 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
379 | if (!key || !key_len || key_idx < 0 || key_idx > 4) | |
380 | return -EINVAL; | |
381 | ||
0a9b5e17 JB |
382 | if (wdev->current_bss && |
383 | memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0) | |
384 | return -EALREADY; | |
385 | ||
386 | for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
387 | if (wdev->authtry_bsses[i] && | |
388 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, | |
389 | ETH_ALEN) == 0) | |
390 | return -EALREADY; | |
391 | if (wdev->auth_bsses[i] && | |
392 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, | |
393 | ETH_ALEN) == 0) | |
394 | return -EALREADY; | |
395 | } | |
396 | ||
19957bb3 JB |
397 | memset(&req, 0, sizeof(req)); |
398 | ||
399 | req.ie = ie; | |
400 | req.ie_len = ie_len; | |
401 | req.auth_type = auth_type; | |
402 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, | |
403 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); | |
fffd0934 JB |
404 | req.key = key; |
405 | req.key_len = key_len; | |
406 | req.key_idx = key_idx; | |
19957bb3 JB |
407 | if (!req.bss) |
408 | return -ENOENT; | |
409 | ||
410 | bss = bss_from_pub(req.bss); | |
411 | ||
19957bb3 JB |
412 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
413 | if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) { | |
414 | slot = i; | |
415 | nfree++; | |
416 | } | |
417 | } | |
418 | ||
419 | /* we need one free slot for disassoc and one for this auth */ | |
420 | if (nfree < 2) { | |
421 | err = -ENOSPC; | |
422 | goto out; | |
423 | } | |
424 | ||
425 | wdev->authtry_bsses[slot] = bss; | |
426 | cfg80211_hold_bss(bss); | |
427 | ||
428 | err = rdev->ops->auth(&rdev->wiphy, dev, &req); | |
429 | if (err) { | |
430 | wdev->authtry_bsses[slot] = NULL; | |
431 | cfg80211_unhold_bss(bss); | |
432 | } | |
433 | ||
434 | out: | |
435 | if (err) | |
436 | cfg80211_put_bss(req.bss); | |
437 | return err; | |
438 | } | |
439 | ||
667503dd JB |
440 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
441 | struct net_device *dev, struct ieee80211_channel *chan, | |
442 | enum nl80211_auth_type auth_type, const u8 *bssid, | |
443 | const u8 *ssid, int ssid_len, | |
fffd0934 JB |
444 | const u8 *ie, int ie_len, |
445 | const u8 *key, int key_len, int key_idx) | |
667503dd JB |
446 | { |
447 | int err; | |
448 | ||
449 | wdev_lock(dev->ieee80211_ptr); | |
450 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
fffd0934 JB |
451 | ssid, ssid_len, ie, ie_len, |
452 | key, key_len, key_idx); | |
667503dd JB |
453 | wdev_unlock(dev->ieee80211_ptr); |
454 | ||
455 | return err; | |
456 | } | |
457 | ||
458 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, | |
459 | struct net_device *dev, | |
460 | struct ieee80211_channel *chan, | |
461 | const u8 *bssid, const u8 *prev_bssid, | |
462 | const u8 *ssid, int ssid_len, | |
463 | const u8 *ie, int ie_len, bool use_mfp, | |
464 | struct cfg80211_crypto_settings *crypt) | |
19957bb3 JB |
465 | { |
466 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
467 | struct cfg80211_assoc_request req; | |
468 | struct cfg80211_internal_bss *bss; | |
469 | int i, err, slot = -1; | |
24b6b15f | 470 | bool was_connected = false; |
19957bb3 | 471 | |
667503dd JB |
472 | ASSERT_WDEV_LOCK(wdev); |
473 | ||
19957bb3 JB |
474 | memset(&req, 0, sizeof(req)); |
475 | ||
24b6b15f JM |
476 | if (wdev->current_bss && prev_bssid && |
477 | memcmp(wdev->current_bss->pub.bssid, prev_bssid, ETH_ALEN) == 0) { | |
478 | /* | |
479 | * Trying to reassociate: Allow this to proceed and let the old | |
480 | * association to be dropped when the new one is completed. | |
481 | */ | |
482 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { | |
483 | was_connected = true; | |
484 | wdev->sme_state = CFG80211_SME_CONNECTING; | |
485 | } | |
486 | } else if (wdev->current_bss) | |
19957bb3 JB |
487 | return -EALREADY; |
488 | ||
489 | req.ie = ie; | |
490 | req.ie_len = ie_len; | |
491 | memcpy(&req.crypto, crypt, sizeof(req.crypto)); | |
492 | req.use_mfp = use_mfp; | |
3e5d7649 | 493 | req.prev_bssid = prev_bssid; |
19957bb3 JB |
494 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
495 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); | |
24b6b15f JM |
496 | if (!req.bss) { |
497 | if (was_connected) | |
498 | wdev->sme_state = CFG80211_SME_CONNECTED; | |
19957bb3 | 499 | return -ENOENT; |
24b6b15f | 500 | } |
19957bb3 JB |
501 | |
502 | bss = bss_from_pub(req.bss); | |
503 | ||
504 | for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
505 | if (bss == wdev->auth_bsses[i]) { | |
506 | slot = i; | |
507 | break; | |
508 | } | |
509 | } | |
510 | ||
511 | if (slot < 0) { | |
512 | err = -ENOTCONN; | |
513 | goto out; | |
514 | } | |
515 | ||
516 | err = rdev->ops->assoc(&rdev->wiphy, dev, &req); | |
517 | out: | |
24b6b15f JM |
518 | if (err && was_connected) |
519 | wdev->sme_state = CFG80211_SME_CONNECTED; | |
19957bb3 JB |
520 | /* still a reference in wdev->auth_bsses[slot] */ |
521 | cfg80211_put_bss(req.bss); | |
522 | return err; | |
523 | } | |
524 | ||
667503dd JB |
525 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
526 | struct net_device *dev, | |
527 | struct ieee80211_channel *chan, | |
528 | const u8 *bssid, const u8 *prev_bssid, | |
529 | const u8 *ssid, int ssid_len, | |
530 | const u8 *ie, int ie_len, bool use_mfp, | |
531 | struct cfg80211_crypto_settings *crypt) | |
532 | { | |
533 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
534 | int err; | |
535 | ||
536 | wdev_lock(wdev); | |
537 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, | |
538 | ssid, ssid_len, ie, ie_len, use_mfp, crypt); | |
539 | wdev_unlock(wdev); | |
540 | ||
541 | return err; | |
542 | } | |
543 | ||
544 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, | |
545 | struct net_device *dev, const u8 *bssid, | |
546 | const u8 *ie, int ie_len, u16 reason) | |
19957bb3 JB |
547 | { |
548 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
549 | struct cfg80211_deauth_request req; | |
550 | int i; | |
551 | ||
667503dd JB |
552 | ASSERT_WDEV_LOCK(wdev); |
553 | ||
19957bb3 JB |
554 | memset(&req, 0, sizeof(req)); |
555 | req.reason_code = reason; | |
556 | req.ie = ie; | |
557 | req.ie_len = ie_len; | |
558 | if (wdev->current_bss && | |
559 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { | |
560 | req.bss = &wdev->current_bss->pub; | |
561 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
562 | if (wdev->auth_bsses[i] && | |
563 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) { | |
564 | req.bss = &wdev->auth_bsses[i]->pub; | |
565 | break; | |
566 | } | |
567 | if (wdev->authtry_bsses[i] && | |
568 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) { | |
569 | req.bss = &wdev->authtry_bsses[i]->pub; | |
570 | break; | |
571 | } | |
572 | } | |
573 | ||
574 | if (!req.bss) | |
575 | return -ENOTCONN; | |
576 | ||
667503dd | 577 | return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
19957bb3 JB |
578 | } |
579 | ||
667503dd JB |
580 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
581 | struct net_device *dev, const u8 *bssid, | |
582 | const u8 *ie, int ie_len, u16 reason) | |
583 | { | |
584 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
585 | int err; | |
586 | ||
587 | wdev_lock(wdev); | |
588 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason); | |
589 | wdev_unlock(wdev); | |
590 | ||
591 | return err; | |
592 | } | |
593 | ||
594 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, | |
595 | struct net_device *dev, const u8 *bssid, | |
596 | const u8 *ie, int ie_len, u16 reason) | |
19957bb3 JB |
597 | { |
598 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
599 | struct cfg80211_disassoc_request req; | |
600 | ||
667503dd JB |
601 | ASSERT_WDEV_LOCK(wdev); |
602 | ||
f9d6b402 JB |
603 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
604 | return -ENOTCONN; | |
605 | ||
606 | if (WARN_ON(!wdev->current_bss)) | |
607 | return -ENOTCONN; | |
608 | ||
19957bb3 JB |
609 | memset(&req, 0, sizeof(req)); |
610 | req.reason_code = reason; | |
611 | req.ie = ie; | |
612 | req.ie_len = ie_len; | |
613 | if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) | |
614 | req.bss = &wdev->current_bss->pub; | |
615 | else | |
616 | return -ENOTCONN; | |
617 | ||
667503dd JB |
618 | return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev); |
619 | } | |
620 | ||
621 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, | |
622 | struct net_device *dev, const u8 *bssid, | |
623 | const u8 *ie, int ie_len, u16 reason) | |
624 | { | |
625 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
626 | int err; | |
627 | ||
628 | wdev_lock(wdev); | |
629 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason); | |
630 | wdev_unlock(wdev); | |
631 | ||
632 | return err; | |
19957bb3 JB |
633 | } |
634 | ||
635 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, | |
636 | struct net_device *dev) | |
637 | { | |
638 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
639 | struct cfg80211_deauth_request req; | |
640 | int i; | |
641 | ||
667503dd JB |
642 | ASSERT_WDEV_LOCK(wdev); |
643 | ||
19957bb3 JB |
644 | if (!rdev->ops->deauth) |
645 | return; | |
646 | ||
647 | memset(&req, 0, sizeof(req)); | |
648 | req.reason_code = WLAN_REASON_DEAUTH_LEAVING; | |
649 | req.ie = NULL; | |
650 | req.ie_len = 0; | |
651 | ||
652 | if (wdev->current_bss) { | |
653 | req.bss = &wdev->current_bss->pub; | |
667503dd | 654 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
19957bb3 JB |
655 | if (wdev->current_bss) { |
656 | cfg80211_unhold_bss(wdev->current_bss); | |
657 | cfg80211_put_bss(&wdev->current_bss->pub); | |
658 | wdev->current_bss = NULL; | |
659 | } | |
660 | } | |
661 | ||
662 | for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
663 | if (wdev->auth_bsses[i]) { | |
664 | req.bss = &wdev->auth_bsses[i]->pub; | |
667503dd | 665 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
19957bb3 JB |
666 | if (wdev->auth_bsses[i]) { |
667 | cfg80211_unhold_bss(wdev->auth_bsses[i]); | |
668 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); | |
669 | wdev->auth_bsses[i] = NULL; | |
670 | } | |
671 | } | |
672 | if (wdev->authtry_bsses[i]) { | |
673 | req.bss = &wdev->authtry_bsses[i]->pub; | |
667503dd | 674 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
19957bb3 JB |
675 | if (wdev->authtry_bsses[i]) { |
676 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); | |
677 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); | |
678 | wdev->authtry_bsses[i] = NULL; | |
679 | } | |
680 | } | |
681 | } | |
682 | } | |
9588bbd5 JM |
683 | |
684 | void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie, | |
685 | struct ieee80211_channel *chan, | |
686 | enum nl80211_channel_type channel_type, | |
687 | unsigned int duration, gfp_t gfp) | |
688 | { | |
689 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | |
690 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
691 | ||
692 | nl80211_send_remain_on_channel(rdev, dev, cookie, chan, channel_type, | |
693 | duration, gfp); | |
694 | } | |
695 | EXPORT_SYMBOL(cfg80211_ready_on_channel); | |
696 | ||
697 | void cfg80211_remain_on_channel_expired(struct net_device *dev, | |
698 | u64 cookie, | |
699 | struct ieee80211_channel *chan, | |
700 | enum nl80211_channel_type channel_type, | |
701 | gfp_t gfp) | |
702 | { | |
703 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | |
704 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
705 | ||
706 | nl80211_send_remain_on_channel_cancel(rdev, dev, cookie, chan, | |
707 | channel_type, gfp); | |
708 | } | |
709 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |