netfilter: Convert compare_ether_addr to ether_addr_equal
[deliverable/linux.git] / net / wireless / mlme.c
CommitLineData
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>
c6fb08aa 9#include <linux/etherdevice.h>
6039f6d2
JM
10#include <linux/netdevice.h>
11#include <linux/nl80211.h>
5a0e3ad6 12#include <linux/slab.h>
a9a11622 13#include <linux/wireless.h>
6039f6d2 14#include <net/cfg80211.h>
a9a11622 15#include <net/iw_handler.h>
6039f6d2
JM
16#include "core.h"
17#include "nl80211.h"
18
cb0b4beb 19void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
6039f6d2 20{
19957bb3
JB
21 struct wireless_dev *wdev = dev->ieee80211_ptr;
22 struct wiphy *wiphy = wdev->wiphy;
6039f6d2 23 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
19957bb3 24
667503dd 25 wdev_lock(wdev);
cb0b4beb 26
95de817b
JB
27 nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
28 cfg80211_sme_rx_auth(dev, buf, len);
667503dd
JB
29
30 wdev_unlock(wdev);
6039f6d2
JM
31}
32EXPORT_SYMBOL(cfg80211_send_rx_auth);
33
95de817b
JB
34void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss,
35 const u8 *buf, size_t len)
6039f6d2 36{
6829c878
JB
37 u16 status_code;
38 struct wireless_dev *wdev = dev->ieee80211_ptr;
39 struct wiphy *wiphy = wdev->wiphy;
6039f6d2 40 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6829c878
JB
41 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
42 u8 *ie = mgmt->u.assoc_resp.variable;
95de817b 43 int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
6829c878 44
667503dd 45 wdev_lock(wdev);
cb0b4beb 46
6829c878
JB
47 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
48
f401a6f7
JB
49 /*
50 * This is a bit of a hack, we don't notify userspace of
51 * a (re-)association reply if we tried to send a reassoc
52 * and got a reject -- we only try again with an assoc
53 * frame instead of reassoc.
54 */
55 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn &&
95de817b
JB
56 cfg80211_sme_failed_reassoc(wdev)) {
57 cfg80211_put_bss(bss);
f401a6f7 58 goto out;
95de817b 59 }
f401a6f7 60
cb0b4beb 61 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
6829c878 62
95de817b 63 if (status_code != WLAN_STATUS_SUCCESS && wdev->conn) {
7d930bc3 64 cfg80211_sme_failed_assoc(wdev);
7d930bc3
JB
65 /*
66 * do not call connect_result() now because the
67 * sme will schedule work that does it later.
68 */
95de817b 69 cfg80211_put_bss(bss);
7d930bc3 70 goto out;
df7fc0f9
JB
71 }
72
ea416a79
JB
73 if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) {
74 /*
75 * This is for the userspace SME, the CONNECTING
76 * state will be changed to CONNECTED by
77 * __cfg80211_connect_result() below.
78 */
79 wdev->sme_state = CFG80211_SME_CONNECTING;
80 }
81
95de817b 82 /* this consumes the bss reference */
df7fc0f9
JB
83 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
84 status_code,
95de817b 85 status_code == WLAN_STATUS_SUCCESS, bss);
f401a6f7 86 out:
667503dd 87 wdev_unlock(wdev);
6039f6d2
JM
88}
89EXPORT_SYMBOL(cfg80211_send_rx_assoc);
90
ce470613 91void __cfg80211_send_deauth(struct net_device *dev,
667503dd 92 const u8 *buf, size_t len)
6039f6d2 93{
6829c878
JB
94 struct wireless_dev *wdev = dev->ieee80211_ptr;
95 struct wiphy *wiphy = wdev->wiphy;
6039f6d2 96 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6829c878 97 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
19957bb3 98 const u8 *bssid = mgmt->bssid;
95de817b 99 bool was_current = false;
6829c878 100
667503dd 101 ASSERT_WDEV_LOCK(wdev);
cb0b4beb 102
19957bb3 103 if (wdev->current_bss &&
c6fb08aa 104 compare_ether_addr(wdev->current_bss->pub.bssid, bssid) == 0) {
19957bb3
JB
105 cfg80211_unhold_bss(wdev->current_bss);
106 cfg80211_put_bss(&wdev->current_bss->pub);
107 wdev->current_bss = NULL;
3f3b6a8d 108 was_current = true;
19957bb3 109 }
19957bb3 110
5fba4af3
JB
111 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
112
3f3b6a8d 113 if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) {
6829c878
JB
114 u16 reason_code;
115 bool from_ap;
116
117 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
118
c6fb08aa 119 from_ap = compare_ether_addr(mgmt->sa, dev->dev_addr) != 0;
667503dd 120 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
6829c878 121 } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
667503dd
JB
122 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
123 WLAN_STATUS_UNSPECIFIED_FAILURE,
df7fc0f9 124 false, NULL);
667503dd
JB
125 }
126}
ce470613 127EXPORT_SYMBOL(__cfg80211_send_deauth);
667503dd 128
ce470613 129void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
667503dd
JB
130{
131 struct wireless_dev *wdev = dev->ieee80211_ptr;
132
ce470613
HS
133 wdev_lock(wdev);
134 __cfg80211_send_deauth(dev, buf, len);
135 wdev_unlock(wdev);
6039f6d2 136}
53b46b84 137EXPORT_SYMBOL(cfg80211_send_deauth);
6039f6d2 138
ce470613 139void __cfg80211_send_disassoc(struct net_device *dev,
667503dd 140 const u8 *buf, size_t len)
6039f6d2 141{
6829c878
JB
142 struct wireless_dev *wdev = dev->ieee80211_ptr;
143 struct wiphy *wiphy = wdev->wiphy;
6039f6d2 144 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6829c878 145 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
19957bb3 146 const u8 *bssid = mgmt->bssid;
19957bb3
JB
147 u16 reason_code;
148 bool from_ap;
6829c878 149
596a07c1 150 ASSERT_WDEV_LOCK(wdev);
cb0b4beb
JB
151
152 nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
a3b8b056 153
596a07c1
JB
154 if (wdev->sme_state != CFG80211_SME_CONNECTED)
155 return;
6829c878 156
19957bb3 157 if (wdev->current_bss &&
c6fb08aa 158 compare_ether_addr(wdev->current_bss->pub.bssid, bssid) == 0) {
95de817b
JB
159 cfg80211_sme_disassoc(dev, wdev->current_bss);
160 cfg80211_unhold_bss(wdev->current_bss);
161 cfg80211_put_bss(&wdev->current_bss->pub);
162 wdev->current_bss = NULL;
19957bb3
JB
163 } else
164 WARN_ON(1);
6829c878 165
6829c878 166
19957bb3
JB
167 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
168
c6fb08aa 169 from_ap = compare_ether_addr(mgmt->sa, dev->dev_addr) != 0;
667503dd 170 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
667503dd 171}
ce470613 172EXPORT_SYMBOL(__cfg80211_send_disassoc);
667503dd 173
ce470613 174void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
667503dd
JB
175{
176 struct wireless_dev *wdev = dev->ieee80211_ptr;
177
ce470613
HS
178 wdev_lock(wdev);
179 __cfg80211_send_disassoc(dev, buf, len);
180 wdev_unlock(wdev);
1965c853 181}
6829c878 182EXPORT_SYMBOL(cfg80211_send_disassoc);
1965c853 183
cf4e594e
JM
184void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf,
185 size_t len)
186{
187 struct wireless_dev *wdev = dev->ieee80211_ptr;
188 struct wiphy *wiphy = wdev->wiphy;
189 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
190
191 nl80211_send_unprot_deauth(rdev, dev, buf, len, GFP_ATOMIC);
192}
193EXPORT_SYMBOL(cfg80211_send_unprot_deauth);
194
195void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf,
196 size_t len)
197{
198 struct wireless_dev *wdev = dev->ieee80211_ptr;
199 struct wiphy *wiphy = wdev->wiphy;
200 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
201
202 nl80211_send_unprot_disassoc(rdev, dev, buf, len, GFP_ATOMIC);
203}
204EXPORT_SYMBOL(cfg80211_send_unprot_disassoc);
205
a58ce43f
JB
206void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
207{
208 struct wireless_dev *wdev = dev->ieee80211_ptr;
209 struct wiphy *wiphy = wdev->wiphy;
210 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
211
212 wdev_lock(wdev);
213
214 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
215 if (wdev->sme_state == CFG80211_SME_CONNECTING)
216 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
217 WLAN_STATUS_UNSPECIFIED_FAILURE,
218 false, NULL);
219
667503dd 220 wdev_unlock(wdev);
1965c853
JM
221}
222EXPORT_SYMBOL(cfg80211_send_auth_timeout);
223
cb0b4beb 224void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
1965c853 225{
6829c878
JB
226 struct wireless_dev *wdev = dev->ieee80211_ptr;
227 struct wiphy *wiphy = wdev->wiphy;
1965c853 228 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
19957bb3 229
667503dd 230 wdev_lock(wdev);
cb0b4beb
JB
231
232 nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
6829c878 233 if (wdev->sme_state == CFG80211_SME_CONNECTING)
667503dd
JB
234 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
235 WLAN_STATUS_UNSPECIFIED_FAILURE,
df7fc0f9 236 false, NULL);
19957bb3 237
667503dd 238 wdev_unlock(wdev);
1965c853
JM
239}
240EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
241
a3b8b056
JM
242void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
243 enum nl80211_key_type key_type, int key_id,
e6d6e342 244 const u8 *tsc, gfp_t gfp)
a3b8b056
JM
245{
246 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
247 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3d23e349 248#ifdef CONFIG_CFG80211_WEXT
f58d4ed9 249 union iwreq_data wrqu;
e6d6e342 250 char *buf = kmalloc(128, gfp);
f58d4ed9
JB
251
252 if (buf) {
253 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
254 "keyid=%d %scast addr=%pM)", key_id,
255 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
256 addr);
257 memset(&wrqu, 0, sizeof(wrqu));
258 wrqu.data.length = strlen(buf);
259 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
260 kfree(buf);
261 }
262#endif
263
e6d6e342 264 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
a3b8b056
JM
265}
266EXPORT_SYMBOL(cfg80211_michael_mic_failure);
19957bb3
JB
267
268/* some MLME handling for userspace SME */
667503dd
JB
269int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
270 struct net_device *dev,
271 struct ieee80211_channel *chan,
272 enum nl80211_auth_type auth_type,
273 const u8 *bssid,
274 const u8 *ssid, int ssid_len,
fffd0934 275 const u8 *ie, int ie_len,
95de817b 276 const u8 *key, int key_len, int key_idx)
19957bb3
JB
277{
278 struct wireless_dev *wdev = dev->ieee80211_ptr;
279 struct cfg80211_auth_request req;
95de817b 280 int err;
19957bb3 281
667503dd
JB
282 ASSERT_WDEV_LOCK(wdev);
283
fffd0934
JB
284 if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
285 if (!key || !key_len || key_idx < 0 || key_idx > 4)
286 return -EINVAL;
287
0a9b5e17 288 if (wdev->current_bss &&
c6fb08aa 289 compare_ether_addr(bssid, wdev->current_bss->pub.bssid) == 0)
0a9b5e17
JB
290 return -EALREADY;
291
19957bb3
JB
292 memset(&req, 0, sizeof(req));
293
294 req.ie = ie;
295 req.ie_len = ie_len;
296 req.auth_type = auth_type;
297 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
298 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
fffd0934
JB
299 req.key = key;
300 req.key_len = key_len;
301 req.key_idx = key_idx;
19957bb3
JB
302 if (!req.bss)
303 return -ENOENT;
304
19957bb3 305 err = rdev->ops->auth(&rdev->wiphy, dev, &req);
19957bb3 306
95de817b 307 cfg80211_put_bss(req.bss);
19957bb3
JB
308 return err;
309}
310
667503dd
JB
311int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
312 struct net_device *dev, struct ieee80211_channel *chan,
313 enum nl80211_auth_type auth_type, const u8 *bssid,
314 const u8 *ssid, int ssid_len,
fffd0934 315 const u8 *ie, int ie_len,
95de817b 316 const u8 *key, int key_len, int key_idx)
667503dd
JB
317{
318 int err;
319
320 wdev_lock(dev->ieee80211_ptr);
321 err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
fffd0934 322 ssid, ssid_len, ie, ie_len,
95de817b 323 key, key_len, key_idx);
667503dd
JB
324 wdev_unlock(dev->ieee80211_ptr);
325
326 return err;
327}
328
7e7c8926
BG
329/* Do a logical ht_capa &= ht_capa_mask. */
330void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
331 const struct ieee80211_ht_cap *ht_capa_mask)
332{
333 int i;
334 u8 *p1, *p2;
335 if (!ht_capa_mask) {
336 memset(ht_capa, 0, sizeof(*ht_capa));
337 return;
338 }
339
340 p1 = (u8*)(ht_capa);
341 p2 = (u8*)(ht_capa_mask);
342 for (i = 0; i<sizeof(*ht_capa); i++)
343 p1[i] &= p2[i];
344}
345
667503dd
JB
346int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
347 struct net_device *dev,
348 struct ieee80211_channel *chan,
349 const u8 *bssid, const u8 *prev_bssid,
350 const u8 *ssid, int ssid_len,
351 const u8 *ie, int ie_len, bool use_mfp,
7e7c8926
BG
352 struct cfg80211_crypto_settings *crypt,
353 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
354 struct ieee80211_ht_cap *ht_capa_mask)
19957bb3
JB
355{
356 struct wireless_dev *wdev = dev->ieee80211_ptr;
357 struct cfg80211_assoc_request req;
95de817b 358 int err;
24b6b15f 359 bool was_connected = false;
19957bb3 360
667503dd
JB
361 ASSERT_WDEV_LOCK(wdev);
362
19957bb3
JB
363 memset(&req, 0, sizeof(req));
364
24b6b15f 365 if (wdev->current_bss && prev_bssid &&
c6fb08aa 366 compare_ether_addr(wdev->current_bss->pub.bssid, prev_bssid) == 0) {
24b6b15f
JM
367 /*
368 * Trying to reassociate: Allow this to proceed and let the old
369 * association to be dropped when the new one is completed.
370 */
371 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
372 was_connected = true;
373 wdev->sme_state = CFG80211_SME_CONNECTING;
374 }
375 } else if (wdev->current_bss)
19957bb3
JB
376 return -EALREADY;
377
378 req.ie = ie;
379 req.ie_len = ie_len;
380 memcpy(&req.crypto, crypt, sizeof(req.crypto));
381 req.use_mfp = use_mfp;
3e5d7649 382 req.prev_bssid = prev_bssid;
7e7c8926
BG
383 req.flags = assoc_flags;
384 if (ht_capa)
385 memcpy(&req.ht_capa, ht_capa, sizeof(req.ht_capa));
386 if (ht_capa_mask)
387 memcpy(&req.ht_capa_mask, ht_capa_mask,
388 sizeof(req.ht_capa_mask));
389 cfg80211_oper_and_ht_capa(&req.ht_capa_mask,
390 rdev->wiphy.ht_capa_mod_mask);
391
19957bb3
JB
392 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
393 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
24b6b15f
JM
394 if (!req.bss) {
395 if (was_connected)
396 wdev->sme_state = CFG80211_SME_CONNECTED;
19957bb3 397 return -ENOENT;
24b6b15f 398 }
19957bb3 399
95de817b 400 err = rdev->ops->assoc(&rdev->wiphy, dev, &req);
19957bb3 401
95de817b
JB
402 if (err) {
403 if (was_connected)
404 wdev->sme_state = CFG80211_SME_CONNECTED;
405 cfg80211_put_bss(req.bss);
19957bb3
JB
406 }
407
19957bb3
JB
408 return err;
409}
410
667503dd
JB
411int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
412 struct net_device *dev,
413 struct ieee80211_channel *chan,
414 const u8 *bssid, const u8 *prev_bssid,
415 const u8 *ssid, int ssid_len,
416 const u8 *ie, int ie_len, bool use_mfp,
7e7c8926
BG
417 struct cfg80211_crypto_settings *crypt,
418 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
419 struct ieee80211_ht_cap *ht_capa_mask)
667503dd
JB
420{
421 struct wireless_dev *wdev = dev->ieee80211_ptr;
422 int err;
423
424 wdev_lock(wdev);
425 err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
7e7c8926
BG
426 ssid, ssid_len, ie, ie_len, use_mfp, crypt,
427 assoc_flags, ht_capa, ht_capa_mask);
667503dd
JB
428 wdev_unlock(wdev);
429
430 return err;
431}
432
433int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
434 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
435 const u8 *ie, int ie_len, u16 reason,
436 bool local_state_change)
19957bb3
JB
437{
438 struct wireless_dev *wdev = dev->ieee80211_ptr;
95de817b
JB
439 struct cfg80211_deauth_request req = {
440 .bssid = bssid,
441 .reason_code = reason,
442 .ie = ie,
443 .ie_len = ie_len,
444 };
19957bb3 445
667503dd
JB
446 ASSERT_WDEV_LOCK(wdev);
447
95de817b
JB
448 if (local_state_change) {
449 if (wdev->current_bss &&
c6fb08aa
FF
450 compare_ether_addr(wdev->current_bss->pub.bssid, bssid)
451 == 0) {
95de817b
JB
452 cfg80211_unhold_bss(wdev->current_bss);
453 cfg80211_put_bss(&wdev->current_bss->pub);
454 wdev->current_bss = NULL;
19957bb3 455 }
19957bb3 456
95de817b
JB
457 return 0;
458 }
19957bb3 459
63c9c5e7 460 return rdev->ops->deauth(&rdev->wiphy, dev, &req);
19957bb3
JB
461}
462
667503dd
JB
463int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
464 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
465 const u8 *ie, int ie_len, u16 reason,
466 bool local_state_change)
667503dd
JB
467{
468 struct wireless_dev *wdev = dev->ieee80211_ptr;
469 int err;
470
471 wdev_lock(wdev);
d5cdfacb
JM
472 err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason,
473 local_state_change);
667503dd
JB
474 wdev_unlock(wdev);
475
476 return err;
477}
478
479static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
480 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
481 const u8 *ie, int ie_len, u16 reason,
482 bool local_state_change)
19957bb3
JB
483{
484 struct wireless_dev *wdev = dev->ieee80211_ptr;
485 struct cfg80211_disassoc_request req;
486
667503dd
JB
487 ASSERT_WDEV_LOCK(wdev);
488
f9d6b402
JB
489 if (wdev->sme_state != CFG80211_SME_CONNECTED)
490 return -ENOTCONN;
491
492 if (WARN_ON(!wdev->current_bss))
493 return -ENOTCONN;
494
19957bb3
JB
495 memset(&req, 0, sizeof(req));
496 req.reason_code = reason;
d5cdfacb 497 req.local_state_change = local_state_change;
19957bb3
JB
498 req.ie = ie;
499 req.ie_len = ie_len;
c6fb08aa 500 if (compare_ether_addr(wdev->current_bss->pub.bssid, bssid) == 0)
19957bb3
JB
501 req.bss = &wdev->current_bss->pub;
502 else
503 return -ENOTCONN;
504
63c9c5e7 505 return rdev->ops->disassoc(&rdev->wiphy, dev, &req);
667503dd
JB
506}
507
508int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
509 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
510 const u8 *ie, int ie_len, u16 reason,
511 bool local_state_change)
667503dd
JB
512{
513 struct wireless_dev *wdev = dev->ieee80211_ptr;
514 int err;
515
516 wdev_lock(wdev);
d5cdfacb
JM
517 err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason,
518 local_state_change);
667503dd
JB
519 wdev_unlock(wdev);
520
521 return err;
19957bb3
JB
522}
523
524void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
525 struct net_device *dev)
526{
527 struct wireless_dev *wdev = dev->ieee80211_ptr;
528 struct cfg80211_deauth_request req;
95de817b 529 u8 bssid[ETH_ALEN];
19957bb3 530
667503dd
JB
531 ASSERT_WDEV_LOCK(wdev);
532
19957bb3
JB
533 if (!rdev->ops->deauth)
534 return;
535
536 memset(&req, 0, sizeof(req));
537 req.reason_code = WLAN_REASON_DEAUTH_LEAVING;
538 req.ie = NULL;
539 req.ie_len = 0;
540
95de817b
JB
541 if (!wdev->current_bss)
542 return;
19957bb3 543
95de817b
JB
544 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
545 req.bssid = bssid;
63c9c5e7 546 rdev->ops->deauth(&rdev->wiphy, dev, &req);
95de817b
JB
547
548 if (wdev->current_bss) {
549 cfg80211_unhold_bss(wdev->current_bss);
550 cfg80211_put_bss(&wdev->current_bss->pub);
551 wdev->current_bss = NULL;
19957bb3
JB
552 }
553}
9588bbd5
JM
554
555void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie,
556 struct ieee80211_channel *chan,
557 enum nl80211_channel_type channel_type,
558 unsigned int duration, gfp_t gfp)
559{
560 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
561 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
562
563 nl80211_send_remain_on_channel(rdev, dev, cookie, chan, channel_type,
564 duration, gfp);
565}
566EXPORT_SYMBOL(cfg80211_ready_on_channel);
567
568void cfg80211_remain_on_channel_expired(struct net_device *dev,
569 u64 cookie,
570 struct ieee80211_channel *chan,
571 enum nl80211_channel_type channel_type,
572 gfp_t gfp)
573{
574 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
575 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
576
577 nl80211_send_remain_on_channel_cancel(rdev, dev, cookie, chan,
578 channel_type, gfp);
579}
580EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
98b62183
JB
581
582void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
583 struct station_info *sinfo, gfp_t gfp)
584{
585 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
586 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
587
588 nl80211_send_sta_event(rdev, dev, mac_addr, sinfo, gfp);
589}
590EXPORT_SYMBOL(cfg80211_new_sta);
026331c4 591
ec15e68b
JM
592void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
593{
594 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
595 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
596
597 nl80211_send_sta_del_event(rdev, dev, mac_addr, gfp);
598}
599EXPORT_SYMBOL(cfg80211_del_sta);
600
2e161f78 601struct cfg80211_mgmt_registration {
026331c4
JM
602 struct list_head list;
603
604 u32 nlpid;
605
606 int match_len;
607
2e161f78
JB
608 __le16 frame_type;
609
026331c4
JM
610 u8 match[];
611};
612
2e161f78
JB
613int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
614 u16 frame_type, const u8 *match_data,
615 int match_len)
026331c4 616{
271733cf
JB
617 struct wiphy *wiphy = wdev->wiphy;
618 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
2e161f78 619 struct cfg80211_mgmt_registration *reg, *nreg;
026331c4 620 int err = 0;
2e161f78
JB
621 u16 mgmt_type;
622
623 if (!wdev->wiphy->mgmt_stypes)
624 return -EOPNOTSUPP;
625
626 if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
627 return -EINVAL;
628
629 if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
630 return -EINVAL;
631
632 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
633 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type)))
634 return -EINVAL;
026331c4
JM
635
636 nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL);
637 if (!nreg)
638 return -ENOMEM;
639
2e161f78 640 spin_lock_bh(&wdev->mgmt_registrations_lock);
026331c4 641
2e161f78 642 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
026331c4
JM
643 int mlen = min(match_len, reg->match_len);
644
2e161f78
JB
645 if (frame_type != le16_to_cpu(reg->frame_type))
646 continue;
647
026331c4
JM
648 if (memcmp(reg->match, match_data, mlen) == 0) {
649 err = -EALREADY;
650 break;
651 }
652 }
653
654 if (err) {
655 kfree(nreg);
656 goto out;
657 }
658
659 memcpy(nreg->match, match_data, match_len);
660 nreg->match_len = match_len;
661 nreg->nlpid = snd_pid;
2e161f78
JB
662 nreg->frame_type = cpu_to_le16(frame_type);
663 list_add(&nreg->list, &wdev->mgmt_registrations);
026331c4 664
271733cf
JB
665 if (rdev->ops->mgmt_frame_register)
666 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
667 frame_type, true);
668
026331c4 669 out:
2e161f78 670 spin_unlock_bh(&wdev->mgmt_registrations_lock);
271733cf 671
026331c4
JM
672 return err;
673}
674
2e161f78 675void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid)
026331c4 676{
271733cf
JB
677 struct wiphy *wiphy = wdev->wiphy;
678 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
2e161f78 679 struct cfg80211_mgmt_registration *reg, *tmp;
026331c4 680
2e161f78 681 spin_lock_bh(&wdev->mgmt_registrations_lock);
026331c4 682
2e161f78 683 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
271733cf
JB
684 if (reg->nlpid != nlpid)
685 continue;
686
687 if (rdev->ops->mgmt_frame_register) {
688 u16 frame_type = le16_to_cpu(reg->frame_type);
689
690 rdev->ops->mgmt_frame_register(wiphy, wdev->netdev,
691 frame_type, false);
026331c4 692 }
271733cf
JB
693
694 list_del(&reg->list);
695 kfree(reg);
026331c4
JM
696 }
697
2e161f78 698 spin_unlock_bh(&wdev->mgmt_registrations_lock);
28946da7
JB
699
700 if (nlpid == wdev->ap_unexpected_nlpid)
701 wdev->ap_unexpected_nlpid = 0;
026331c4
JM
702}
703
2e161f78 704void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev)
026331c4 705{
2e161f78 706 struct cfg80211_mgmt_registration *reg, *tmp;
026331c4 707
2e161f78 708 spin_lock_bh(&wdev->mgmt_registrations_lock);
026331c4 709
2e161f78 710 list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) {
026331c4
JM
711 list_del(&reg->list);
712 kfree(reg);
713 }
714
2e161f78 715 spin_unlock_bh(&wdev->mgmt_registrations_lock);
026331c4
JM
716}
717
2e161f78
JB
718int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
719 struct net_device *dev,
f7ca38df 720 struct ieee80211_channel *chan, bool offchan,
2e161f78 721 enum nl80211_channel_type channel_type,
f7ca38df 722 bool channel_type_valid, unsigned int wait,
e9f935e3 723 const u8 *buf, size_t len, bool no_cck,
e247bd90 724 bool dont_wait_for_ack, u64 *cookie)
026331c4
JM
725{
726 struct wireless_dev *wdev = dev->ieee80211_ptr;
727 const struct ieee80211_mgmt *mgmt;
2e161f78
JB
728 u16 stype;
729
730 if (!wdev->wiphy->mgmt_stypes)
731 return -EOPNOTSUPP;
026331c4 732
2e161f78 733 if (!rdev->ops->mgmt_tx)
026331c4 734 return -EOPNOTSUPP;
2e161f78 735
026331c4
JM
736 if (len < 24 + 1)
737 return -EINVAL;
738
739 mgmt = (const struct ieee80211_mgmt *) buf;
2e161f78
JB
740
741 if (!ieee80211_is_mgmt(mgmt->frame_control))
026331c4 742 return -EINVAL;
2e161f78
JB
743
744 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
745 if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4)))
746 return -EINVAL;
747
748 if (ieee80211_is_action(mgmt->frame_control) &&
749 mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
663fcafd
JB
750 int err = 0;
751
fe100acd
JB
752 wdev_lock(wdev);
753
663fcafd
JB
754 switch (wdev->iftype) {
755 case NL80211_IFTYPE_ADHOC:
756 case NL80211_IFTYPE_STATION:
757 case NL80211_IFTYPE_P2P_CLIENT:
758 if (!wdev->current_bss) {
759 err = -ENOTCONN;
760 break;
761 }
762
c6fb08aa
FF
763 if (compare_ether_addr(wdev->current_bss->pub.bssid,
764 mgmt->bssid)) {
663fcafd
JB
765 err = -ENOTCONN;
766 break;
767 }
768
769 /*
770 * check for IBSS DA must be done by driver as
771 * cfg80211 doesn't track the stations
772 */
773 if (wdev->iftype == NL80211_IFTYPE_ADHOC)
774 break;
fe100acd 775
663fcafd 776 /* for station, check that DA is the AP */
c6fb08aa
FF
777 if (compare_ether_addr(wdev->current_bss->pub.bssid,
778 mgmt->da)) {
663fcafd
JB
779 err = -ENOTCONN;
780 break;
781 }
782 break;
783 case NL80211_IFTYPE_AP:
784 case NL80211_IFTYPE_P2P_GO:
785 case NL80211_IFTYPE_AP_VLAN:
c6fb08aa 786 if (compare_ether_addr(mgmt->bssid, dev->dev_addr))
663fcafd
JB
787 err = -EINVAL;
788 break;
0778a6a3 789 case NL80211_IFTYPE_MESH_POINT:
c6fb08aa 790 if (compare_ether_addr(mgmt->sa, mgmt->bssid)) {
0778a6a3
JC
791 err = -EINVAL;
792 break;
793 }
794 /*
795 * check for mesh DA must be done by driver as
796 * cfg80211 doesn't track the stations
797 */
798 break;
663fcafd
JB
799 default:
800 err = -EOPNOTSUPP;
801 break;
802 }
fe100acd 803 wdev_unlock(wdev);
663fcafd
JB
804
805 if (err)
806 return err;
026331c4
JM
807 }
808
c6fb08aa 809 if (compare_ether_addr(mgmt->sa, dev->dev_addr) != 0)
026331c4
JM
810 return -EINVAL;
811
812 /* Transmit the Action frame as requested by user space */
f7ca38df
JB
813 return rdev->ops->mgmt_tx(&rdev->wiphy, dev, chan, offchan,
814 channel_type, channel_type_valid,
e247bd90
JB
815 wait, buf, len, no_cck, dont_wait_for_ack,
816 cookie);
026331c4
JM
817}
818
804483e9
JB
819bool cfg80211_rx_mgmt(struct net_device *dev, int freq, int sig_mbm,
820 const u8 *buf, size_t len, gfp_t gfp)
026331c4
JM
821{
822 struct wireless_dev *wdev = dev->ieee80211_ptr;
823 struct wiphy *wiphy = wdev->wiphy;
824 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
2e161f78
JB
825 struct cfg80211_mgmt_registration *reg;
826 const struct ieee80211_txrx_stypes *stypes =
827 &wiphy->mgmt_stypes[wdev->iftype];
828 struct ieee80211_mgmt *mgmt = (void *)buf;
829 const u8 *data;
830 int data_len;
026331c4 831 bool result = false;
2e161f78
JB
832 __le16 ftype = mgmt->frame_control &
833 cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE);
834 u16 stype;
026331c4 835
2e161f78 836 stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4;
026331c4 837
2e161f78
JB
838 if (!(stypes->rx & BIT(stype)))
839 return false;
026331c4 840
2e161f78
JB
841 data = buf + ieee80211_hdrlen(mgmt->frame_control);
842 data_len = len - ieee80211_hdrlen(mgmt->frame_control);
843
844 spin_lock_bh(&wdev->mgmt_registrations_lock);
845
846 list_for_each_entry(reg, &wdev->mgmt_registrations, list) {
847 if (reg->frame_type != ftype)
848 continue;
026331c4 849
2e161f78 850 if (reg->match_len > data_len)
026331c4
JM
851 continue;
852
2e161f78 853 if (memcmp(reg->match, data, reg->match_len))
026331c4
JM
854 continue;
855
856 /* found match! */
857
858 /* Indicate the received Action frame to user space */
804483e9
JB
859 if (nl80211_send_mgmt(rdev, dev, reg->nlpid,
860 freq, sig_mbm,
2e161f78 861 buf, len, gfp))
026331c4
JM
862 continue;
863
864 result = true;
865 break;
866 }
867
2e161f78 868 spin_unlock_bh(&wdev->mgmt_registrations_lock);
026331c4
JM
869
870 return result;
871}
2e161f78 872EXPORT_SYMBOL(cfg80211_rx_mgmt);
026331c4 873
2e161f78
JB
874void cfg80211_mgmt_tx_status(struct net_device *dev, u64 cookie,
875 const u8 *buf, size_t len, bool ack, gfp_t gfp)
026331c4
JM
876{
877 struct wireless_dev *wdev = dev->ieee80211_ptr;
878 struct wiphy *wiphy = wdev->wiphy;
879 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
880
881 /* Indicate TX status of the Action frame to user space */
2e161f78 882 nl80211_send_mgmt_tx_status(rdev, dev, cookie, buf, len, ack, gfp);
026331c4 883}
2e161f78 884EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
d6dc1a38
JO
885
886void cfg80211_cqm_rssi_notify(struct net_device *dev,
887 enum nl80211_cqm_rssi_threshold_event rssi_event,
888 gfp_t gfp)
889{
890 struct wireless_dev *wdev = dev->ieee80211_ptr;
891 struct wiphy *wiphy = wdev->wiphy;
892 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
893
894 /* Indicate roaming trigger event to user space */
895 nl80211_send_cqm_rssi_notify(rdev, dev, rssi_event, gfp);
896}
897EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
c063dbf5
JB
898
899void cfg80211_cqm_pktloss_notify(struct net_device *dev,
900 const u8 *peer, u32 num_packets, gfp_t gfp)
901{
902 struct wireless_dev *wdev = dev->ieee80211_ptr;
903 struct wiphy *wiphy = wdev->wiphy;
904 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
905
906 /* Indicate roaming trigger event to user space */
907 nl80211_send_cqm_pktloss_notify(rdev, dev, peer, num_packets, gfp);
908}
909EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
e5497d76
JB
910
911void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
912 const u8 *replay_ctr, gfp_t gfp)
913{
914 struct wireless_dev *wdev = dev->ieee80211_ptr;
915 struct wiphy *wiphy = wdev->wiphy;
916 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
917
918 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
919}
920EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
c9df56b4
JM
921
922void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
923 const u8 *bssid, bool preauth, gfp_t gfp)
924{
925 struct wireless_dev *wdev = dev->ieee80211_ptr;
926 struct wiphy *wiphy = wdev->wiphy;
927 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
928
929 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
930}
931EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
28946da7 932
5314526b
TP
933void cfg80211_ch_switch_notify(struct net_device *dev, int freq,
934 enum nl80211_channel_type type)
935{
936 struct wireless_dev *wdev = dev->ieee80211_ptr;
937 struct wiphy *wiphy = wdev->wiphy;
938 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
939 struct ieee80211_channel *chan;
940
941 wdev_lock(wdev);
942
943 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
944 wdev->iftype != NL80211_IFTYPE_P2P_GO))
945 goto out;
946
947 chan = rdev_freq_to_chan(rdev, freq, type);
948 if (WARN_ON(!chan))
949 goto out;
950
951 wdev->channel = chan;
952
953 nl80211_ch_switch_notify(rdev, dev, freq, type, GFP_KERNEL);
954out:
955 wdev_unlock(wdev);
956 return;
957}
958EXPORT_SYMBOL(cfg80211_ch_switch_notify);
959
28946da7
JB
960bool cfg80211_rx_spurious_frame(struct net_device *dev,
961 const u8 *addr, gfp_t gfp)
962{
963 struct wireless_dev *wdev = dev->ieee80211_ptr;
964
965 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
966 wdev->iftype != NL80211_IFTYPE_P2P_GO))
967 return false;
968
969 return nl80211_unexpected_frame(dev, addr, gfp);
970}
971EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
b92ab5d8
JB
972
973bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
974 const u8 *addr, gfp_t gfp)
975{
976 struct wireless_dev *wdev = dev->ieee80211_ptr;
977
978 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
979 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
980 wdev->iftype != NL80211_IFTYPE_AP_VLAN))
981 return false;
982
983 return nl80211_unexpected_4addr_frame(dev, addr, gfp);
984}
985EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
This page took 0.302596 seconds and 5 git commands to generate.