blob: 1a96c2572578603d2959b667b26807e8f4e4e667 [file] [log] [blame]
Johannes Berg4855d252006-01-12 21:12:59 +01001/*
2 * This file contains the softmac's authentication logic.
3 *
Johannes Berg79859052006-01-31 19:31:41 +01004 * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net>
5 * Joseph Jezak <josejx@gentoo.org>
6 * Larry Finger <Larry.Finger@lwfinger.net>
7 * Danny van Dyk <kugelfang@gentoo.org>
8 * Michael Buesch <mbuesch@freenet.de>
Johannes Berg4855d252006-01-12 21:12:59 +01009 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
25 */
26
Johannes Berg370121e2006-01-04 16:32:16 +010027#include "ieee80211softmac_priv.h"
28
David Howellsc4028952006-11-22 14:57:56 +000029static void ieee80211softmac_auth_queue(struct work_struct *work);
Johannes Berg370121e2006-01-04 16:32:16 +010030
31/* Queues an auth request to the desired AP */
32int
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090033ieee80211softmac_auth_req(struct ieee80211softmac_device *mac,
Johannes Berg370121e2006-01-04 16:32:16 +010034 struct ieee80211softmac_network *net)
35{
36 struct ieee80211softmac_auth_queue_item *auth;
37 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -070038 DECLARE_MAC_BUF(mac2);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090039
Joseph Jezakcb74c432006-06-11 12:00:37 -040040 if (net->authenticating || net->authenticated)
Johannes Berg370121e2006-01-04 16:32:16 +010041 return 0;
Joseph Jezakcb74c432006-06-11 12:00:37 -040042 net->authenticating = 1;
Johannes Berg370121e2006-01-04 16:32:16 +010043
44 /* Add the network if it's not already added */
45 ieee80211softmac_add_network(mac, net);
46
Joe Perches0795af52007-10-03 17:59:30 -070047 dprintk(KERN_NOTICE PFX "Queueing Authentication Request to %s\n", print_mac(mac2, net->bssid));
Johannes Berg370121e2006-01-04 16:32:16 +010048 /* Queue the auth request */
49 auth = (struct ieee80211softmac_auth_queue_item *)
50 kmalloc(sizeof(struct ieee80211softmac_auth_queue_item), GFP_KERNEL);
51 if(auth == NULL)
52 return -ENOMEM;
53
54 auth->net = net;
55 auth->mac = mac;
56 auth->retry = IEEE80211SOFTMAC_AUTH_RETRY_LIMIT;
57 auth->state = IEEE80211SOFTMAC_AUTH_OPEN_REQUEST;
David Howellsc4028952006-11-22 14:57:56 +000058 INIT_DELAYED_WORK(&auth->work, ieee80211softmac_auth_queue);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090059
Johannes Berg370121e2006-01-04 16:32:16 +010060 /* Lock (for list) */
61 spin_lock_irqsave(&mac->lock, flags);
62
63 /* add to list */
64 list_add_tail(&auth->list, &mac->auth_queue);
Johannes Berg501d8572007-10-03 18:14:23 -070065 queue_delayed_work(mac->wq, &auth->work, 0);
Johannes Berg370121e2006-01-04 16:32:16 +010066 spin_unlock_irqrestore(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090067
Johannes Berg370121e2006-01-04 16:32:16 +010068 return 0;
69}
70
71
72/* Sends an auth request to the desired AP and handles timeouts */
73static void
David Howellsc4028952006-11-22 14:57:56 +000074ieee80211softmac_auth_queue(struct work_struct *work)
Johannes Berg370121e2006-01-04 16:32:16 +010075{
76 struct ieee80211softmac_device *mac;
77 struct ieee80211softmac_auth_queue_item *auth;
78 struct ieee80211softmac_network *net;
79 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -070080 DECLARE_MAC_BUF(mac2);
Johannes Berg370121e2006-01-04 16:32:16 +010081
David Howellsc4028952006-11-22 14:57:56 +000082 auth = container_of(work, struct ieee80211softmac_auth_queue_item,
83 work.work);
Johannes Berg370121e2006-01-04 16:32:16 +010084 net = auth->net;
85 mac = auth->mac;
86
87 if(auth->retry > 0) {
88 /* Switch to correct channel for this network */
89 mac->set_channel(mac->dev, net->channel);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090090
Johannes Berg370121e2006-01-04 16:32:16 +010091 /* Lock and set flags */
92 spin_lock_irqsave(&mac->lock, flags);
Daniel Draked57336e2006-04-30 22:09:07 +010093 if (unlikely(!mac->running)) {
94 /* Prevent reschedule on workqueue flush */
95 spin_unlock_irqrestore(&mac->lock, flags);
96 return;
97 }
Johannes Berg370121e2006-01-04 16:32:16 +010098 net->authenticated = 0;
Johannes Berg370121e2006-01-04 16:32:16 +010099 /* add a timeout call so we eventually give up waiting for an auth reply */
Johannes Berg501d8572007-10-03 18:14:23 -0700100 queue_delayed_work(mac->wq, &auth->work, IEEE80211SOFTMAC_AUTH_TIMEOUT);
Johannes Berg370121e2006-01-04 16:32:16 +0100101 auth->retry--;
102 spin_unlock_irqrestore(&mac->lock, flags);
103 if (ieee80211softmac_send_mgt_frame(mac, auth->net, IEEE80211_STYPE_AUTH, auth->state))
Joe Perches0795af52007-10-03 17:59:30 -0700104 dprintk(KERN_NOTICE PFX "Sending Authentication Request to %s failed (this shouldn't happen, wait for the timeout).\n",
105 print_mac(mac2, net->bssid));
Johannes Berg370121e2006-01-04 16:32:16 +0100106 else
Joe Perches0795af52007-10-03 17:59:30 -0700107 dprintk(KERN_NOTICE PFX "Sent Authentication Request to %s.\n", print_mac(mac2, net->bssid));
Johannes Berg370121e2006-01-04 16:32:16 +0100108 return;
109 }
110
Joe Perches0795af52007-10-03 17:59:30 -0700111 printkl(KERN_WARNING PFX "Authentication timed out with %s\n", print_mac(mac2, net->bssid));
Johannes Berg370121e2006-01-04 16:32:16 +0100112 /* Remove this item from the queue */
113 spin_lock_irqsave(&mac->lock, flags);
Daniel Drake76ea4c72006-06-01 15:34:26 +0100114 net->authenticating = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100115 ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT, net);
116 cancel_delayed_work(&auth->work); /* just to make sure... */
117 list_del(&auth->list);
118 spin_unlock_irqrestore(&mac->lock, flags);
119 /* Free it */
120 kfree(auth);
121}
122
Daniel Drake345f6b82006-07-11 23:16:34 +0100123/* Sends a response to an auth challenge (for shared key auth). */
124static void
David Howellsc4028952006-11-22 14:57:56 +0000125ieee80211softmac_auth_challenge_response(struct work_struct *work)
Daniel Drake345f6b82006-07-11 23:16:34 +0100126{
David Howellsc4028952006-11-22 14:57:56 +0000127 struct ieee80211softmac_auth_queue_item *aq =
128 container_of(work, struct ieee80211softmac_auth_queue_item,
129 work.work);
Daniel Drake345f6b82006-07-11 23:16:34 +0100130
131 /* Send our response */
132 ieee80211softmac_send_mgt_frame(aq->mac, aq->net, IEEE80211_STYPE_AUTH, aq->state);
133}
134
Johannes Berg370121e2006-01-04 16:32:16 +0100135/* Handle the auth response from the AP
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900136 * This should be registered with ieee80211 as handle_auth
Johannes Berg370121e2006-01-04 16:32:16 +0100137 */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900138int
Johannes Berg370121e2006-01-04 16:32:16 +0100139ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth)
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900140{
Johannes Berg370121e2006-01-04 16:32:16 +0100141
142 struct list_head *list_ptr;
143 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
144 struct ieee80211softmac_auth_queue_item *aq = NULL;
145 struct ieee80211softmac_network *net = NULL;
146 unsigned long flags;
147 u8 * data;
Joe Perches0795af52007-10-03 17:59:30 -0700148 DECLARE_MAC_BUF(mac2);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900149
Daniel Draked57336e2006-04-30 22:09:07 +0100150 if (unlikely(!mac->running))
151 return -ENODEV;
152
Johannes Berg370121e2006-01-04 16:32:16 +0100153 /* Find correct auth queue item */
154 spin_lock_irqsave(&mac->lock, flags);
155 list_for_each(list_ptr, &mac->auth_queue) {
156 aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list);
157 net = aq->net;
158 if (!memcmp(net->bssid, auth->header.addr2, ETH_ALEN))
159 break;
160 else
161 aq = NULL;
162 }
163 spin_unlock_irqrestore(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900164
Johannes Berg370121e2006-01-04 16:32:16 +0100165 /* Make sure that we've got an auth queue item for this request */
166 if(aq == NULL)
167 {
Joe Perches0795af52007-10-03 17:59:30 -0700168 dprintkl(KERN_DEBUG PFX "Authentication response received from %s but no queue item exists.\n", print_mac(mac2, auth->header.addr2));
Johannes Berg370121e2006-01-04 16:32:16 +0100169 /* Error #? */
170 return -1;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900171 }
172
Johannes Berg370121e2006-01-04 16:32:16 +0100173 /* Check for out of order authentication */
174 if(!net->authenticating)
175 {
Joe Perches0795af52007-10-03 17:59:30 -0700176 dprintkl(KERN_DEBUG PFX "Authentication response received from %s but did not request authentication.\n",print_mac(mac2, auth->header.addr2));
Johannes Berg370121e2006-01-04 16:32:16 +0100177 return -1;
178 }
179
180 /* Parse the auth packet */
Al Viroc414e842007-12-29 04:58:39 -0500181 switch(le16_to_cpu(auth->algorithm)) {
Johannes Berg370121e2006-01-04 16:32:16 +0100182 case WLAN_AUTH_OPEN:
183 /* Check the status code of the response */
184
Al Viroc414e842007-12-29 04:58:39 -0500185 switch(le16_to_cpu(auth->status)) {
Johannes Berg370121e2006-01-04 16:32:16 +0100186 case WLAN_STATUS_SUCCESS:
187 /* Update the status to Authenticated */
188 spin_lock_irqsave(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900189 net->authenticating = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100190 net->authenticated = 1;
191 spin_unlock_irqrestore(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900192
Johannes Berg370121e2006-01-04 16:32:16 +0100193 /* Send event */
Joe Perches0795af52007-10-03 17:59:30 -0700194 printkl(KERN_NOTICE PFX "Open Authentication completed with %s\n", print_mac(mac2, net->bssid));
Johannes Berg370121e2006-01-04 16:32:16 +0100195 ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_AUTHENTICATED, net);
196 break;
197 default:
198 /* Lock and reset flags */
199 spin_lock_irqsave(&mac->lock, flags);
200 net->authenticated = 0;
201 net->authenticating = 0;
202 spin_unlock_irqrestore(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900203
Joe Perches0795af52007-10-03 17:59:30 -0700204 printkl(KERN_NOTICE PFX "Open Authentication with %s failed, error code: %i\n",
205 print_mac(mac2, net->bssid), le16_to_cpup(&auth->status));
Johannes Berg370121e2006-01-04 16:32:16 +0100206 /* Count the error? */
207 break;
208 }
209 goto free_aq;
210 break;
211 case WLAN_AUTH_SHARED_KEY:
212 /* Figure out where we are in the process */
Al Viroc414e842007-12-29 04:58:39 -0500213 switch(le16_to_cpu(auth->transaction)) {
Johannes Berg370121e2006-01-04 16:32:16 +0100214 case IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE:
215 /* Check to make sure we have a challenge IE */
216 data = (u8 *)auth->info_element;
Daniel Drake345f6b82006-07-11 23:16:34 +0100217 if (*data++ != MFIE_TYPE_CHALLENGE) {
Johannes Berg370121e2006-01-04 16:32:16 +0100218 printkl(KERN_NOTICE PFX "Shared Key Authentication failed due to a missing challenge.\n");
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900219 break;
Johannes Berg370121e2006-01-04 16:32:16 +0100220 }
221 /* Save the challenge */
222 spin_lock_irqsave(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900223 net->challenge_len = *data++;
Daniel Drake345f6b82006-07-11 23:16:34 +0100224 if (net->challenge_len > WLAN_AUTH_CHALLENGE_LEN)
Johannes Berg370121e2006-01-04 16:32:16 +0100225 net->challenge_len = WLAN_AUTH_CHALLENGE_LEN;
Arnaldo Carvalho de Melo571d6ee2006-11-21 01:26:49 -0200226 kfree(net->challenge);
227 net->challenge = kmemdup(data, net->challenge_len,
228 GFP_ATOMIC);
229 if (net->challenge == NULL) {
230 printkl(KERN_NOTICE PFX "Shared Key "
231 "Authentication failed due to "
232 "memory shortage.\n");
233 spin_unlock_irqrestore(&mac->lock, flags);
234 break;
235 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900236 aq->state = IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE;
Johannes Berg370121e2006-01-04 16:32:16 +0100237
Daniel Drake345f6b82006-07-11 23:16:34 +0100238 /* We reuse the work struct from the auth request here.
239 * It is safe to do so as each one is per-request, and
240 * at this point (dealing with authentication response)
241 * we have obviously already sent the initial auth
242 * request. */
243 cancel_delayed_work(&aq->work);
David Howellsc4028952006-11-22 14:57:56 +0000244 INIT_DELAYED_WORK(&aq->work, &ieee80211softmac_auth_challenge_response);
Johannes Berg501d8572007-10-03 18:14:23 -0700245 queue_delayed_work(mac->wq, &aq->work, 0);
Daniel Drake345f6b82006-07-11 23:16:34 +0100246 spin_unlock_irqrestore(&mac->lock, flags);
Daniel Drake76ea4c72006-06-01 15:34:26 +0100247 return 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100248 case IEEE80211SOFTMAC_AUTH_SHARED_PASS:
Daniel Drake76ea4c72006-06-01 15:34:26 +0100249 kfree(net->challenge);
250 net->challenge = NULL;
251 net->challenge_len = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100252 /* Check the status code of the response */
253 switch(auth->status) {
254 case WLAN_STATUS_SUCCESS:
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900255 /* Update the status to Authenticated */
Johannes Berg370121e2006-01-04 16:32:16 +0100256 spin_lock_irqsave(&mac->lock, flags);
257 net->authenticating = 0;
258 net->authenticated = 1;
259 spin_unlock_irqrestore(&mac->lock, flags);
Joe Perches0795af52007-10-03 17:59:30 -0700260 printkl(KERN_NOTICE PFX "Shared Key Authentication completed with %s\n",
261 print_mac(mac2, net->bssid));
Daniel Drake76ea4c72006-06-01 15:34:26 +0100262 ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_AUTHENTICATED, net);
Johannes Berg370121e2006-01-04 16:32:16 +0100263 break;
264 default:
Joe Perches0795af52007-10-03 17:59:30 -0700265 printkl(KERN_NOTICE PFX "Shared Key Authentication with %s failed, error code: %i\n",
266 print_mac(mac2, net->bssid), le16_to_cpup(&auth->status));
Johannes Berg370121e2006-01-04 16:32:16 +0100267 /* Lock and reset flags */
268 spin_lock_irqsave(&mac->lock, flags);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900269 net->authenticating = 0;
270 net->authenticated = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100271 spin_unlock_irqrestore(&mac->lock, flags);
272 /* Count the error? */
273 break;
274 }
275 goto free_aq;
276 break;
277 default:
278 printkl(KERN_WARNING PFX "Unhandled Authentication Step: %i\n", auth->transaction);
279 break;
280 }
281 goto free_aq;
282 break;
283 default:
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900284 /* ERROR */
Johannes Berg370121e2006-01-04 16:32:16 +0100285 goto free_aq;
286 break;
287 }
288 return 0;
289free_aq:
290 /* Cancel the timeout */
291 spin_lock_irqsave(&mac->lock, flags);
292 cancel_delayed_work(&aq->work);
293 /* Remove this item from the queue */
294 list_del(&aq->list);
295 spin_unlock_irqrestore(&mac->lock, flags);
296
297 /* Free it */
298 kfree(aq);
299 return 0;
300}
301
302/*
303 * Handle deauthorization
304 */
Johannes Berg714e1a52006-01-04 21:06:28 +0100305static void
Johannes Berg370121e2006-01-04 16:32:16 +0100306ieee80211softmac_deauth_from_net(struct ieee80211softmac_device *mac,
307 struct ieee80211softmac_network *net)
308{
309 struct ieee80211softmac_auth_queue_item *aq = NULL;
310 struct list_head *list_ptr;
311 unsigned long flags;
312
Daniel Drake6d92f832006-05-01 22:23:27 +0100313 /* deauthentication implies disassociation */
314 ieee80211softmac_disassoc(mac);
315
Johannes Berg370121e2006-01-04 16:32:16 +0100316 /* Lock and reset status flags */
317 spin_lock_irqsave(&mac->lock, flags);
318 net->authenticating = 0;
319 net->authenticated = 0;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900320
Johannes Berg370121e2006-01-04 16:32:16 +0100321 /* Find correct auth queue item, if it exists */
322 list_for_each(list_ptr, &mac->auth_queue) {
323 aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list);
324 if (!memcmp(net->bssid, aq->net->bssid, ETH_ALEN))
325 break;
326 else
327 aq = NULL;
328 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900329
Johannes Berg370121e2006-01-04 16:32:16 +0100330 /* Cancel pending work */
331 if(aq != NULL)
332 /* Not entirely safe? What about running work? */
333 cancel_delayed_work(&aq->work);
334
335 /* Free our network ref */
336 ieee80211softmac_del_network_locked(mac, net);
337 if(net->challenge != NULL)
338 kfree(net->challenge);
339 kfree(net);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900340
Johannes Berg2dd50802006-01-06 18:11:23 +0100341 /* can't transmit data right now... */
342 netif_carrier_off(mac->dev);
Johannes Berg370121e2006-01-04 16:32:16 +0100343 spin_unlock_irqrestore(&mac->lock, flags);
Ulrich Kunitz2b50c242006-12-03 16:32:00 +0100344
345 ieee80211softmac_try_reassoc(mac);
Johannes Berg370121e2006-01-04 16:32:16 +0100346}
347
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900348/*
Johannes Berg370121e2006-01-04 16:32:16 +0100349 * Sends a deauth request to the desired AP
350 */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900351int
352ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac,
Johannes Berg370121e2006-01-04 16:32:16 +0100353 struct ieee80211softmac_network *net, int reason)
354{
355 int ret;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900356
Johannes Berg370121e2006-01-04 16:32:16 +0100357 /* Make sure the network is authenticated */
358 if (!net->authenticated)
359 {
Larry Finger5398d592006-11-04 13:29:50 -0600360 dprintkl(KERN_DEBUG PFX "Can't send deauthentication packet, network is not authenticated.\n");
Johannes Berg370121e2006-01-04 16:32:16 +0100361 /* Error okay? */
362 return -EPERM;
363 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900364
Johannes Berg370121e2006-01-04 16:32:16 +0100365 /* Send the de-auth packet */
366 if((ret = ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_DEAUTH, reason)))
367 return ret;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900368
Johannes Berg370121e2006-01-04 16:32:16 +0100369 ieee80211softmac_deauth_from_net(mac, net);
370 return 0;
371}
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900372
Johannes Berg370121e2006-01-04 16:32:16 +0100373/*
374 * This should be registered with ieee80211 as handle_deauth
375 */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900376int
Johannes Bergb10c9912006-01-31 19:48:06 +0100377ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_deauth *deauth)
Johannes Berg370121e2006-01-04 16:32:16 +0100378{
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900379
Johannes Berg370121e2006-01-04 16:32:16 +0100380 struct ieee80211softmac_network *net = NULL;
381 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
Joe Perches0795af52007-10-03 17:59:30 -0700382 DECLARE_MAC_BUF(mac2);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900383
Daniel Draked57336e2006-04-30 22:09:07 +0100384 if (unlikely(!mac->running))
385 return -ENODEV;
386
Johannes Bergb10c9912006-01-31 19:48:06 +0100387 if (!deauth) {
Johannes Berg370121e2006-01-04 16:32:16 +0100388 dprintk("deauth without deauth packet. eek!\n");
389 return 0;
390 }
391
Johannes Bergb10c9912006-01-31 19:48:06 +0100392 net = ieee80211softmac_get_network_by_bssid(mac, deauth->header.addr2);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900393
Johannes Berg370121e2006-01-04 16:32:16 +0100394 if (net == NULL) {
Joe Perches0795af52007-10-03 17:59:30 -0700395 dprintkl(KERN_DEBUG PFX "Received deauthentication packet from %s, but that network is unknown.\n",
396 print_mac(mac2, deauth->header.addr2));
Johannes Berg370121e2006-01-04 16:32:16 +0100397 return 0;
398 }
399
400 /* Make sure the network is authenticated */
401 if(!net->authenticated)
402 {
Larry Finger5398d592006-11-04 13:29:50 -0600403 dprintkl(KERN_DEBUG PFX "Can't perform deauthentication, network is not authenticated.\n");
Johannes Berg370121e2006-01-04 16:32:16 +0100404 /* Error okay? */
405 return -EPERM;
406 }
407
408 ieee80211softmac_deauth_from_net(mac, net);
Daniel Drake995c9922006-04-30 19:49:30 +0100409
410 /* let's try to re-associate */
Johannes Berg501d8572007-10-03 18:14:23 -0700411 queue_delayed_work(mac->wq, &mac->associnfo.work, 0);
Johannes Berg370121e2006-01-04 16:32:16 +0100412 return 0;
413}