cfg80211: remove dead variable
[linux-2.6.git] / net / wireless / mlme.c
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>
11 #include <linux/wireless.h>
12 #include <net/cfg80211.h>
13 #include <net/iw_handler.h>
14 #include "core.h"
15 #include "nl80211.h"
16
17 void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
18 {
19         struct wireless_dev *wdev = dev->ieee80211_ptr;
20         struct wiphy *wiphy = wdev->wiphy;
21         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
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
28         wdev_lock(wdev);
29
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);
47
48         nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
49         cfg80211_sme_rx_auth(dev, buf, len);
50
51         wdev_unlock(wdev);
52 }
53 EXPORT_SYMBOL(cfg80211_send_rx_auth);
54
55 void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
56 {
57         u16 status_code;
58         struct wireless_dev *wdev = dev->ieee80211_ptr;
59         struct wiphy *wiphy = wdev->wiphy;
60         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
61         struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
62         u8 *ie = mgmt->u.assoc_resp.variable;
63         int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
64         struct cfg80211_internal_bss *bss = NULL;
65
66         wdev_lock(wdev);
67
68         status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
69
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
80         nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
81
82         if (status_code == WLAN_STATUS_SUCCESS) {
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];
89                                 wdev->auth_bsses[i] = NULL;
90                                 /* additional reference to drop hold */
91                                 cfg80211_ref_bss(bss);
92                                 break;
93                         }
94                 }
95
96                 WARN_ON(!bss);
97         } else if (wdev->conn) {
98                 cfg80211_sme_failed_assoc(wdev);
99                 /*
100                  * do not call connect_result() now because the
101                  * sme will schedule work that does it later.
102                  */
103                 goto out;
104         }
105
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
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);
124         }
125
126  out:
127         wdev_unlock(wdev);
128 }
129 EXPORT_SYMBOL(cfg80211_send_rx_assoc);
130
131 void __cfg80211_send_deauth(struct net_device *dev,
132                                    const u8 *buf, size_t len)
133 {
134         struct wireless_dev *wdev = dev->ieee80211_ptr;
135         struct wiphy *wiphy = wdev->wiphy;
136         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
137         struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
138         const u8 *bssid = mgmt->bssid;
139         int i;
140
141         ASSERT_WDEV_LOCK(wdev);
142
143         nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
144
145         if (wdev->current_bss &&
146             memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
147                 cfg80211_unhold_bss(wdev->current_bss);
148                 cfg80211_put_bss(&wdev->current_bss->pub);
149                 wdev->current_bss = NULL;
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;
156                         break;
157                 }
158                 if (wdev->authtry_bsses[i] &&
159                     memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
160                         cfg80211_unhold_bss(wdev->authtry_bsses[i]);
161                         cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
162                         wdev->authtry_bsses[i] = NULL;
163                         break;
164                 }
165         }
166
167         if (wdev->sme_state == CFG80211_SME_CONNECTED) {
168                 u16 reason_code;
169                 bool from_ap;
170
171                 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
172
173                 from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0;
174                 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
175         } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
176                 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
177                                           WLAN_STATUS_UNSPECIFIED_FAILURE,
178                                           false, NULL);
179         }
180 }
181 EXPORT_SYMBOL(__cfg80211_send_deauth);
182
183 void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
184 {
185         struct wireless_dev *wdev = dev->ieee80211_ptr;
186
187         wdev_lock(wdev);
188         __cfg80211_send_deauth(dev, buf, len);
189         wdev_unlock(wdev);
190 }
191 EXPORT_SYMBOL(cfg80211_send_deauth);
192
193 void __cfg80211_send_disassoc(struct net_device *dev,
194                                      const u8 *buf, size_t len)
195 {
196         struct wireless_dev *wdev = dev->ieee80211_ptr;
197         struct wiphy *wiphy = wdev->wiphy;
198         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
199         struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
200         const u8 *bssid = mgmt->bssid;
201         int i;
202         u16 reason_code;
203         bool from_ap;
204         bool done = false;
205
206         ASSERT_WDEV_LOCK(wdev);
207
208         nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
209
210         if (wdev->sme_state != CFG80211_SME_CONNECTED)
211                 return;
212
213         if (wdev->current_bss &&
214             memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
215                 for (i = 0; i < MAX_AUTH_BSSES; i++) {
216                         if (wdev->authtry_bsses[i] || wdev->auth_bsses[i])
217                                 continue;
218                         wdev->auth_bsses[i] = wdev->current_bss;
219                         wdev->current_bss = NULL;
220                         done = true;
221                         cfg80211_sme_disassoc(dev, i);
222                         break;
223                 }
224                 WARN_ON(!done);
225         } else
226                 WARN_ON(1);
227
228
229         reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
230
231         from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0;
232         __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
233 }
234 EXPORT_SYMBOL(__cfg80211_send_disassoc);
235
236 void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
237 {
238         struct wireless_dev *wdev = dev->ieee80211_ptr;
239
240         wdev_lock(wdev);
241         __cfg80211_send_disassoc(dev, buf, len);
242         wdev_unlock(wdev);
243 }
244 EXPORT_SYMBOL(cfg80211_send_disassoc);
245
246 void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
247 {
248         struct wireless_dev *wdev = dev->ieee80211_ptr;
249         struct wiphy *wiphy = wdev->wiphy;
250         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
251         int i;
252         bool done = false;
253
254         wdev_lock(wdev);
255
256         nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
257         if (wdev->sme_state == CFG80211_SME_CONNECTING)
258                 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
259                                           WLAN_STATUS_UNSPECIFIED_FAILURE,
260                                           false, NULL);
261
262         for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
263                 if (wdev->authtry_bsses[i] &&
264                     memcmp(wdev->authtry_bsses[i]->pub.bssid,
265                            addr, ETH_ALEN) == 0) {
266                         cfg80211_unhold_bss(wdev->authtry_bsses[i]);
267                         cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
268                         wdev->authtry_bsses[i] = NULL;
269                         done = true;
270                         break;
271                 }
272         }
273
274         WARN_ON(!done);
275
276         wdev_unlock(wdev);
277 }
278 EXPORT_SYMBOL(cfg80211_send_auth_timeout);
279
280 void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
281 {
282         struct wireless_dev *wdev = dev->ieee80211_ptr;
283         struct wiphy *wiphy = wdev->wiphy;
284         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
285         int i;
286         bool done = false;
287
288         wdev_lock(wdev);
289
290         nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
291         if (wdev->sme_state == CFG80211_SME_CONNECTING)
292                 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
293                                           WLAN_STATUS_UNSPECIFIED_FAILURE,
294                                           false, NULL);
295
296         for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
297                 if (wdev->auth_bsses[i] &&
298                     memcmp(wdev->auth_bsses[i]->pub.bssid,
299                            addr, ETH_ALEN) == 0) {
300                         cfg80211_unhold_bss(wdev->auth_bsses[i]);
301                         cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
302                         wdev->auth_bsses[i] = NULL;
303                         done = true;
304                         break;
305                 }
306         }
307
308         WARN_ON(!done);
309
310         wdev_unlock(wdev);
311 }
312 EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
313
314 void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
315                                   enum nl80211_key_type key_type, int key_id,
316                                   const u8 *tsc, gfp_t gfp)
317 {
318         struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
319         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
320 #ifdef CONFIG_CFG80211_WEXT
321         union iwreq_data wrqu;
322         char *buf = kmalloc(128, gfp);
323
324         if (buf) {
325                 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
326                         "keyid=%d %scast addr=%pM)", key_id,
327                         key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
328                         addr);
329                 memset(&wrqu, 0, sizeof(wrqu));
330                 wrqu.data.length = strlen(buf);
331                 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
332                 kfree(buf);
333         }
334 #endif
335
336         nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
337 }
338 EXPORT_SYMBOL(cfg80211_michael_mic_failure);
339
340 /* some MLME handling for userspace SME */
341 int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
342                          struct net_device *dev,
343                          struct ieee80211_channel *chan,
344                          enum nl80211_auth_type auth_type,
345                          const u8 *bssid,
346                          const u8 *ssid, int ssid_len,
347                          const u8 *ie, int ie_len,
348                          const u8 *key, int key_len, int key_idx)
349 {
350         struct wireless_dev *wdev = dev->ieee80211_ptr;
351         struct cfg80211_auth_request req;
352         struct cfg80211_internal_bss *bss;
353         int i, err, slot = -1, nfree = 0;
354
355         ASSERT_WDEV_LOCK(wdev);
356
357         if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
358                 if (!key || !key_len || key_idx < 0 || key_idx > 4)
359                         return -EINVAL;
360
361         if (wdev->current_bss &&
362             memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0)
363                 return -EALREADY;
364
365         for (i = 0; i < MAX_AUTH_BSSES; i++) {
366                 if (wdev->authtry_bsses[i] &&
367                     memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid,
368                                                 ETH_ALEN) == 0)
369                         return -EALREADY;
370                 if (wdev->auth_bsses[i] &&
371                     memcmp(bssid, wdev->auth_bsses[i]->pub.bssid,
372                                                 ETH_ALEN) == 0)
373                         return -EALREADY;
374         }
375
376         memset(&req, 0, sizeof(req));
377
378         req.ie = ie;
379         req.ie_len = ie_len;
380         req.auth_type = auth_type;
381         req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
382                                    WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
383         req.key = key;
384         req.key_len = key_len;
385         req.key_idx = key_idx;
386         if (!req.bss)
387                 return -ENOENT;
388
389         bss = bss_from_pub(req.bss);
390
391         for (i = 0; i < MAX_AUTH_BSSES; i++) {
392                 if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) {
393                         slot = i;
394                         nfree++;
395                 }
396         }
397
398         /* we need one free slot for disassoc and one for this auth */
399         if (nfree < 2) {
400                 err = -ENOSPC;
401                 goto out;
402         }
403
404         wdev->authtry_bsses[slot] = bss;
405         cfg80211_hold_bss(bss);
406
407         err = rdev->ops->auth(&rdev->wiphy, dev, &req);
408         if (err) {
409                 wdev->authtry_bsses[slot] = NULL;
410                 cfg80211_unhold_bss(bss);
411         }
412
413  out:
414         if (err)
415                 cfg80211_put_bss(req.bss);
416         return err;
417 }
418
419 int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
420                        struct net_device *dev, struct ieee80211_channel *chan,
421                        enum nl80211_auth_type auth_type, const u8 *bssid,
422                        const u8 *ssid, int ssid_len,
423                        const u8 *ie, int ie_len,
424                        const u8 *key, int key_len, int key_idx)
425 {
426         int err;
427
428         wdev_lock(dev->ieee80211_ptr);
429         err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
430                                    ssid, ssid_len, ie, ie_len,
431                                    key, key_len, key_idx);
432         wdev_unlock(dev->ieee80211_ptr);
433
434         return err;
435 }
436
437 int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
438                           struct net_device *dev,
439                           struct ieee80211_channel *chan,
440                           const u8 *bssid, const u8 *prev_bssid,
441                           const u8 *ssid, int ssid_len,
442                           const u8 *ie, int ie_len, bool use_mfp,
443                           struct cfg80211_crypto_settings *crypt)
444 {
445         struct wireless_dev *wdev = dev->ieee80211_ptr;
446         struct cfg80211_assoc_request req;
447         struct cfg80211_internal_bss *bss;
448         int i, err, slot = -1;
449
450         ASSERT_WDEV_LOCK(wdev);
451
452         memset(&req, 0, sizeof(req));
453
454         if (wdev->current_bss)
455                 return -EALREADY;
456
457         req.ie = ie;
458         req.ie_len = ie_len;
459         memcpy(&req.crypto, crypt, sizeof(req.crypto));
460         req.use_mfp = use_mfp;
461         req.prev_bssid = prev_bssid;
462         req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
463                                    WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
464         if (!req.bss)
465                 return -ENOENT;
466
467         bss = bss_from_pub(req.bss);
468
469         for (i = 0; i < MAX_AUTH_BSSES; i++) {
470                 if (bss == wdev->auth_bsses[i]) {
471                         slot = i;
472                         break;
473                 }
474         }
475
476         if (slot < 0) {
477                 err = -ENOTCONN;
478                 goto out;
479         }
480
481         err = rdev->ops->assoc(&rdev->wiphy, dev, &req);
482  out:
483         /* still a reference in wdev->auth_bsses[slot] */
484         cfg80211_put_bss(req.bss);
485         return err;
486 }
487
488 int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
489                         struct net_device *dev,
490                         struct ieee80211_channel *chan,
491                         const u8 *bssid, const u8 *prev_bssid,
492                         const u8 *ssid, int ssid_len,
493                         const u8 *ie, int ie_len, bool use_mfp,
494                         struct cfg80211_crypto_settings *crypt)
495 {
496         struct wireless_dev *wdev = dev->ieee80211_ptr;
497         int err;
498
499         wdev_lock(wdev);
500         err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
501                                     ssid, ssid_len, ie, ie_len, use_mfp, crypt);
502         wdev_unlock(wdev);
503
504         return err;
505 }
506
507 int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
508                            struct net_device *dev, const u8 *bssid,
509                            const u8 *ie, int ie_len, u16 reason)
510 {
511         struct wireless_dev *wdev = dev->ieee80211_ptr;
512         struct cfg80211_deauth_request req;
513         int i;
514
515         ASSERT_WDEV_LOCK(wdev);
516
517         memset(&req, 0, sizeof(req));
518         req.reason_code = reason;
519         req.ie = ie;
520         req.ie_len = ie_len;
521         if (wdev->current_bss &&
522             memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
523                 req.bss = &wdev->current_bss->pub;
524         } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
525                 if (wdev->auth_bsses[i] &&
526                     memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
527                         req.bss = &wdev->auth_bsses[i]->pub;
528                         break;
529                 }
530                 if (wdev->authtry_bsses[i] &&
531                     memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
532                         req.bss = &wdev->authtry_bsses[i]->pub;
533                         break;
534                 }
535         }
536
537         if (!req.bss)
538                 return -ENOTCONN;
539
540         return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
541 }
542
543 int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
544                          struct net_device *dev, const u8 *bssid,
545                          const u8 *ie, int ie_len, u16 reason)
546 {
547         struct wireless_dev *wdev = dev->ieee80211_ptr;
548         int err;
549
550         wdev_lock(wdev);
551         err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason);
552         wdev_unlock(wdev);
553
554         return err;
555 }
556
557 static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
558                                     struct net_device *dev, const u8 *bssid,
559                                     const u8 *ie, int ie_len, u16 reason)
560 {
561         struct wireless_dev *wdev = dev->ieee80211_ptr;
562         struct cfg80211_disassoc_request req;
563
564         ASSERT_WDEV_LOCK(wdev);
565
566         if (wdev->sme_state != CFG80211_SME_CONNECTED)
567                 return -ENOTCONN;
568
569         if (WARN_ON(!wdev->current_bss))
570                 return -ENOTCONN;
571
572         memset(&req, 0, sizeof(req));
573         req.reason_code = reason;
574         req.ie = ie;
575         req.ie_len = ie_len;
576         if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0)
577                 req.bss = &wdev->current_bss->pub;
578         else
579                 return -ENOTCONN;
580
581         return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev);
582 }
583
584 int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
585                            struct net_device *dev, const u8 *bssid,
586                            const u8 *ie, int ie_len, u16 reason)
587 {
588         struct wireless_dev *wdev = dev->ieee80211_ptr;
589         int err;
590
591         wdev_lock(wdev);
592         err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason);
593         wdev_unlock(wdev);
594
595         return err;
596 }
597
598 void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
599                         struct net_device *dev)
600 {
601         struct wireless_dev *wdev = dev->ieee80211_ptr;
602         struct cfg80211_deauth_request req;
603         int i;
604
605         ASSERT_WDEV_LOCK(wdev);
606
607         if (!rdev->ops->deauth)
608                 return;
609
610         memset(&req, 0, sizeof(req));
611         req.reason_code = WLAN_REASON_DEAUTH_LEAVING;
612         req.ie = NULL;
613         req.ie_len = 0;
614
615         if (wdev->current_bss) {
616                 req.bss = &wdev->current_bss->pub;
617                 rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
618                 if (wdev->current_bss) {
619                         cfg80211_unhold_bss(wdev->current_bss);
620                         cfg80211_put_bss(&wdev->current_bss->pub);
621                         wdev->current_bss = NULL;
622                 }
623         }
624
625         for (i = 0; i < MAX_AUTH_BSSES; i++) {
626                 if (wdev->auth_bsses[i]) {
627                         req.bss = &wdev->auth_bsses[i]->pub;
628                         rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
629                         if (wdev->auth_bsses[i]) {
630                                 cfg80211_unhold_bss(wdev->auth_bsses[i]);
631                                 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
632                                 wdev->auth_bsses[i] = NULL;
633                         }
634                 }
635                 if (wdev->authtry_bsses[i]) {
636                         req.bss = &wdev->authtry_bsses[i]->pub;
637                         rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
638                         if (wdev->authtry_bsses[i]) {
639                                 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
640                                 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
641                                 wdev->authtry_bsses[i] = NULL;
642                         }
643                 }
644         }
645 }