blob: 589f6d2c548a7ba0167598def59daab5b7eb13c4 [file] [log] [blame]
Johannes Berg4855d252006-01-12 21:12:59 +01001/*
2 * This file contains the softmac's association 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
29/*
30 * Overview
31 *
32 * Before you can associate, you have to authenticate.
33 *
34 */
35
36/* Sends out an association request to the desired AP */
37static void
38ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net)
39{
40 unsigned long flags;
John W. Linville9a107aa2006-03-22 17:29:32 -050041
Johannes Berg370121e2006-01-04 16:32:16 +010042 /* Switch to correct channel for this network */
43 mac->set_channel(mac->dev, net->channel);
44
45 /* Send association request */
46 ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_ASSOC_REQ, 0);
47
48 dprintk(KERN_INFO PFX "sent association request!\n");
49
Johannes Berg370121e2006-01-04 16:32:16 +010050 spin_lock_irqsave(&mac->lock, flags);
Johannes Berg370121e2006-01-04 16:32:16 +010051 mac->associated = 0; /* just to make sure */
Johannes Berg370121e2006-01-04 16:32:16 +010052
53 /* Set a timer for timeout */
54 /* FIXME: make timeout configurable */
Daniel Draked57336e2006-04-30 22:09:07 +010055 if (likely(mac->running))
56 schedule_delayed_work(&mac->associnfo.timeout, 5 * HZ);
57 spin_unlock_irqrestore(&mac->lock, flags);
Johannes Berg370121e2006-01-04 16:32:16 +010058}
59
60void
61ieee80211softmac_assoc_timeout(void *d)
62{
63 struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
Joseph Jezak9f101fc2006-06-11 12:01:03 -040064 struct ieee80211softmac_network *n;
Johannes Berg370121e2006-01-04 16:32:16 +010065 unsigned long flags;
66
Johannes Berg370121e2006-01-04 16:32:16 +010067 spin_lock_irqsave(&mac->lock, flags);
68 /* we might race against ieee80211softmac_handle_assoc_response,
69 * so make sure only one of us does something */
70 if (!mac->associnfo.associating) {
71 spin_unlock_irqrestore(&mac->lock, flags);
72 return;
73 }
74 mac->associnfo.associating = 0;
75 mac->associnfo.bssvalid = 0;
76 mac->associated = 0;
Joseph Jezak9f101fc2006-06-11 12:01:03 -040077
78 n = ieee80211softmac_get_network_by_bssid_locked(mac, mac->associnfo.bssid);
Johannes Berg370121e2006-01-04 16:32:16 +010079 spin_unlock_irqrestore(&mac->lock, flags);
80
81 dprintk(KERN_INFO PFX "assoc request timed out!\n");
Joseph Jezak9f101fc2006-06-11 12:01:03 -040082 ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, n);
Johannes Berg370121e2006-01-04 16:32:16 +010083}
84
Johannes Berg9a1771e82006-04-20 20:02:02 +020085void
Daniel Drake6d92f832006-05-01 22:23:27 +010086ieee80211softmac_disassoc(struct ieee80211softmac_device *mac)
Johannes Berg370121e2006-01-04 16:32:16 +010087{
88 unsigned long flags;
Daniel Drake6d92f832006-05-01 22:23:27 +010089
90 spin_lock_irqsave(&mac->lock, flags);
91 if (mac->associnfo.associating)
92 cancel_delayed_work(&mac->associnfo.timeout);
93
94 netif_carrier_off(mac->dev);
95
96 mac->associated = 0;
97 mac->associnfo.bssvalid = 0;
98 mac->associnfo.associating = 0;
Daniel Drake5acd0c412006-07-18 21:33:27 +010099 ieee80211softmac_init_bss(mac);
Daniel Drake6d92f832006-05-01 22:23:27 +0100100 ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL);
101 spin_unlock_irqrestore(&mac->lock, flags);
102}
103
104/* Sends out a disassociation request to the desired AP */
105void
106ieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reason)
107{
Johannes Berg370121e2006-01-04 16:32:16 +0100108 struct ieee80211softmac_network *found;
Johannes Berg370121e2006-01-04 16:32:16 +0100109
110 if (mac->associnfo.bssvalid && mac->associated) {
111 found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
112 if (found)
113 ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason);
Johannes Berg370121e2006-01-04 16:32:16 +0100114 }
115
Daniel Drake6d92f832006-05-01 22:23:27 +0100116 ieee80211softmac_disassoc(mac);
Johannes Berg370121e2006-01-04 16:32:16 +0100117}
118
119static inline int
120we_support_all_basic_rates(struct ieee80211softmac_device *mac, u8 *from, u8 from_len)
121{
Daniel Drake8462fe32006-05-01 22:45:50 +0100122 int idx;
123 u8 rate;
Johannes Berg370121e2006-01-04 16:32:16 +0100124
125 for (idx = 0; idx < (from_len); idx++) {
126 rate = (from)[idx];
127 if (!(rate & IEEE80211_BASIC_RATE_MASK))
128 continue;
Johannes Berg370121e2006-01-04 16:32:16 +0100129 rate &= ~IEEE80211_BASIC_RATE_MASK;
Daniel Drake8462fe32006-05-01 22:45:50 +0100130 if (!ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate))
Johannes Berg370121e2006-01-04 16:32:16 +0100131 return 0;
132 }
133 return 1;
134}
135
136static int
137network_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_network *net)
138{
139 /* we cannot associate to networks whose name we don't know */
140 if (ieee80211_is_empty_essid(net->ssid, net->ssid_len))
141 return 0;
142 /* do not associate to a network whose BSSBasicRateSet we cannot support */
143 if (!we_support_all_basic_rates(mac, net->rates, net->rates_len))
144 return 0;
145 /* do we really need to check the ex rates? */
146 if (!we_support_all_basic_rates(mac, net->rates_ex, net->rates_ex_len))
147 return 0;
148
Johannes Berg818667f2006-04-20 20:02:03 +0200149 /* assume that users know what they're doing ...
150 * (note we don't let them select a net we're incompatible with) */
151 if (mac->associnfo.bssfixed) {
152 return !memcmp(mac->associnfo.bssid, net->bssid, ETH_ALEN);
153 }
154
Johannes Berg370121e2006-01-04 16:32:16 +0100155 /* if 'ANY' network requested, take any that doesn't have privacy enabled */
156 if (mac->associnfo.req_essid.len == 0
157 && !(net->capability & WLAN_CAPABILITY_PRIVACY))
158 return 1;
159 if (net->ssid_len != mac->associnfo.req_essid.len)
160 return 0;
161 if (!memcmp(net->ssid, mac->associnfo.req_essid.data, mac->associnfo.req_essid.len))
162 return 1;
163 return 0;
164}
165
166static void
Daniel Drake6ae15df2006-06-01 15:37:22 +0100167ieee80211softmac_assoc_notify_scan(struct net_device *dev, int event_type, void *context)
Johannes Berg370121e2006-01-04 16:32:16 +0100168{
169 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
170 ieee80211softmac_assoc_work((void*)mac);
171}
172
Daniel Drake6ae15df2006-06-01 15:37:22 +0100173static void
174ieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void *context)
175{
176 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
177
178 switch (event_type) {
179 case IEEE80211SOFTMAC_EVENT_AUTHENTICATED:
180 ieee80211softmac_assoc_work((void*)mac);
181 break;
182 case IEEE80211SOFTMAC_EVENT_AUTH_FAILED:
183 case IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT:
184 ieee80211softmac_disassoc(mac);
185 break;
186 }
187}
188
Johannes Berg370121e2006-01-04 16:32:16 +0100189/* This function is called to handle userspace requests (asynchronously) */
190void
191ieee80211softmac_assoc_work(void *d)
192{
193 struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
194 struct ieee80211softmac_network *found = NULL;
195 struct ieee80211_network *net = NULL, *best = NULL;
Daniel Drake6d92f832006-05-01 22:23:27 +0100196 int bssvalid;
Johannes Berg370121e2006-01-04 16:32:16 +0100197 unsigned long flags;
Daniel Drake6d92f832006-05-01 22:23:27 +0100198
199 /* ieee80211_disassoc might clear this */
200 bssvalid = mac->associnfo.bssvalid;
201
Johannes Berg370121e2006-01-04 16:32:16 +0100202 /* meh */
203 if (mac->associated)
Daniel Drake6d92f832006-05-01 22:23:27 +0100204 ieee80211softmac_send_disassoc_req(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT);
Johannes Berg370121e2006-01-04 16:32:16 +0100205
Joseph Jezakcb74c432006-06-11 12:00:37 -0400206 spin_lock_irqsave(&mac->lock, flags);
207 mac->associnfo.associating = 1;
208 spin_unlock_irqrestore(&mac->lock, flags);
209
Johannes Berg370121e2006-01-04 16:32:16 +0100210 /* try to find the requested network in our list, if we found one already */
Daniel Drake6d92f832006-05-01 22:23:27 +0100211 if (bssvalid || mac->associnfo.bssfixed)
Johannes Berg370121e2006-01-04 16:32:16 +0100212 found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
213
Johannes Berg1dc09772006-01-11 10:46:16 +0100214 /* Search the ieee80211 networks for this network if we didn't find it by bssid,
215 * but only if we've scanned at least once (to get a better list of networks to
216 * select from). If we have not scanned before, the !found logic below will be
217 * invoked and will scan. */
218 if (!found && (mac->associnfo.scan_retry < IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT))
Johannes Berg370121e2006-01-04 16:32:16 +0100219 {
Johannes Berg78e4f362006-01-10 18:56:32 +0100220 s8 rssi = -128; /* if I don't initialise, gcc emits an invalid warning
221 because it cannot follow the best pointer logic. */
Johannes Berg370121e2006-01-04 16:32:16 +0100222 spin_lock_irqsave(&mac->ieee->lock, flags);
223 list_for_each_entry(net, &mac->ieee->network_list, list) {
224 /* we're supposed to find the network with
225 * the best signal here, as we're asked to join
226 * any network with a specific ESSID, and many
227 * different ones could have that.
228 *
Johannes Berg78e4f362006-01-10 18:56:32 +0100229 * I'll for now just go with the reported rssi.
Johannes Berg370121e2006-01-04 16:32:16 +0100230 *
231 * We also should take into account the rateset
232 * here to find the best BSSID to try.
233 */
234 if (network_matches_request(mac, net)) {
235 if (!best) {
236 best = net;
Johannes Berg78e4f362006-01-10 18:56:32 +0100237 rssi = best->stats.rssi;
Johannes Berg370121e2006-01-04 16:32:16 +0100238 continue;
239 }
240 /* we already had a matching network, so
241 * compare their properties to get the
242 * better of the two ... (see above)
243 */
Johannes Berg78e4f362006-01-10 18:56:32 +0100244 if (rssi < net->stats.rssi) {
245 best = net;
246 rssi = best->stats.rssi;
247 }
Johannes Berg370121e2006-01-04 16:32:16 +0100248 }
249 }
250 /* if we unlock here, we might get interrupted and the `best'
251 * pointer could go stale */
252 if (best) {
253 found = ieee80211softmac_create_network(mac, best);
254 /* if found is still NULL, then we got -ENOMEM somewhere */
255 if (found)
256 ieee80211softmac_add_network(mac, found);
257 }
258 spin_unlock_irqrestore(&mac->ieee->lock, flags);
259 }
260
261 if (!found) {
262 if (mac->associnfo.scan_retry > 0) {
263 spin_lock_irqsave(&mac->lock, flags);
264 mac->associnfo.scan_retry--;
265 spin_unlock_irqrestore(&mac->lock, flags);
266
267 /* We know of no such network. Let's scan.
268 * NB: this also happens if we had no memory to copy the network info...
269 * Maybe we can hope to have more memory after scanning finishes ;)
270 */
Johannes Berg1dc09772006-01-11 10:46:16 +0100271 dprintk(KERN_INFO PFX "Associate: Scanning for networks first.\n");
Daniel Drake6ae15df2006-06-01 15:37:22 +0100272 ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify_scan, NULL);
Johannes Berg370121e2006-01-04 16:32:16 +0100273 if (ieee80211softmac_start_scan(mac))
Johannes Berg1dc09772006-01-11 10:46:16 +0100274 dprintk(KERN_INFO PFX "Associate: failed to initiate scan. Is device up?\n");
Johannes Berg370121e2006-01-04 16:32:16 +0100275 return;
Johannes Berg818667f2006-04-20 20:02:03 +0200276 } else {
Johannes Berg370121e2006-01-04 16:32:16 +0100277 spin_lock_irqsave(&mac->lock, flags);
278 mac->associnfo.associating = 0;
279 mac->associated = 0;
280 spin_unlock_irqrestore(&mac->lock, flags);
281
Johannes Berg1dc09772006-01-11 10:46:16 +0100282 dprintk(KERN_INFO PFX "Unable to find matching network after scan!\n");
Johannes Berg818667f2006-04-20 20:02:03 +0200283 /* reset the retry counter for the next user request since we
284 * break out and don't reschedule ourselves after this point. */
285 mac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT;
Johannes Berg370121e2006-01-04 16:32:16 +0100286 ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND, NULL);
287 return;
288 }
289 }
Johannes Berg818667f2006-04-20 20:02:03 +0200290
291 /* reset the retry counter for the next user request since we
292 * now found a net and will try to associate to it, but not
293 * schedule this function again. */
294 mac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT;
Johannes Berg370121e2006-01-04 16:32:16 +0100295 mac->associnfo.bssvalid = 1;
296 memcpy(mac->associnfo.bssid, found->bssid, ETH_ALEN);
297 /* copy the ESSID for displaying it */
298 mac->associnfo.associate_essid.len = found->essid.len;
299 memcpy(mac->associnfo.associate_essid.data, found->essid.data, IW_ESSID_MAX_SIZE + 1);
300
301 /* we found a network! authenticate (if necessary) and associate to it. */
Joseph Jezakcb74c432006-06-11 12:00:37 -0400302 if (found->authenticating) {
303 dprintk(KERN_INFO PFX "Already requested authentication, waiting...\n");
304 if(!mac->associnfo.assoc_wait) {
305 mac->associnfo.assoc_wait = 1;
John W. Linville4a232e72006-06-26 16:34:29 -0400306 ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL);
Joseph Jezakcb74c432006-06-11 12:00:37 -0400307 }
308 return;
309 }
310 if (!found->authenticated && !found->authenticating) {
Johannes Berg370121e2006-01-04 16:32:16 +0100311 /* This relies on the fact that _auth_req only queues the work,
312 * otherwise adding the notification would be racy. */
313 if (!ieee80211softmac_auth_req(mac, found)) {
Joseph Jezakcb74c432006-06-11 12:00:37 -0400314 if(!mac->associnfo.assoc_wait) {
315 dprintk(KERN_INFO PFX "Cannot associate without being authenticated, requested authentication\n");
316 mac->associnfo.assoc_wait = 1;
John W. Linville4a232e72006-06-26 16:34:29 -0400317 ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL);
Joseph Jezakcb74c432006-06-11 12:00:37 -0400318 }
Johannes Berg370121e2006-01-04 16:32:16 +0100319 } else {
320 printkl(KERN_WARNING PFX "Not authenticated, but requesting authentication failed. Giving up to associate\n");
Joseph Jezakcb74c432006-06-11 12:00:37 -0400321 mac->associnfo.assoc_wait = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100322 ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, found);
323 }
324 return;
325 }
326 /* finally! now we can start associating */
Joseph Jezakcb74c432006-06-11 12:00:37 -0400327 mac->associnfo.assoc_wait = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100328 ieee80211softmac_assoc(mac, found);
329}
330
331/* call this to do whatever is necessary when we're associated */
332static void
333ieee80211softmac_associated(struct ieee80211softmac_device *mac,
334 struct ieee80211_assoc_response * resp,
335 struct ieee80211softmac_network *net)
336{
Daniel Drake5acd0c412006-07-18 21:33:27 +0100337 u16 cap = le16_to_cpu(resp->capability);
338 u8 erp_value = net->erp_value;
339
Johannes Berg370121e2006-01-04 16:32:16 +0100340 mac->associnfo.associating = 0;
Daniel Drake5acd0c412006-07-18 21:33:27 +0100341 mac->bssinfo.supported_rates = net->supported_rates;
Daniel Drake8462fe32006-05-01 22:45:50 +0100342 ieee80211softmac_recalc_txrates(mac);
343
Johannes Berg370121e2006-01-04 16:32:16 +0100344 mac->associated = 1;
Daniel Drake5acd0c412006-07-18 21:33:27 +0100345
346 mac->associnfo.short_preamble_available =
347 (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0;
348 ieee80211softmac_process_erp(mac, erp_value);
349
Johannes Berg370121e2006-01-04 16:32:16 +0100350 if (mac->set_bssid_filter)
351 mac->set_bssid_filter(mac->dev, net->bssid);
352 memcpy(mac->ieee->bssid, net->bssid, ETH_ALEN);
Johannes Berg2dd50802006-01-06 18:11:23 +0100353 netif_carrier_on(mac->dev);
Johannes Berg370121e2006-01-04 16:32:16 +0100354
355 mac->association_id = le16_to_cpup(&resp->aid);
356}
357
358/* received frame handling functions */
359int
360ieee80211softmac_handle_assoc_response(struct net_device * dev,
361 struct ieee80211_assoc_response * resp,
Daniel Drake5acd0c412006-07-18 21:33:27 +0100362 struct ieee80211_network * _ieee80211_network)
Johannes Berg370121e2006-01-04 16:32:16 +0100363{
Daniel Drake5acd0c412006-07-18 21:33:27 +0100364 /* NOTE: the network parameter has to be mostly ignored by
Johannes Berg370121e2006-01-04 16:32:16 +0100365 * this code because it is the ieee80211's pointer
366 * to the struct, not ours (we made a copy)
367 */
368 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
369 u16 status = le16_to_cpup(&resp->status);
370 struct ieee80211softmac_network *network = NULL;
371 unsigned long flags;
Daniel Draked57336e2006-04-30 22:09:07 +0100372
373 if (unlikely(!mac->running))
374 return -ENODEV;
Johannes Berg370121e2006-01-04 16:32:16 +0100375
376 spin_lock_irqsave(&mac->lock, flags);
377
378 if (!mac->associnfo.associating) {
379 /* we race against the timeout function, so make sure
380 * only one of us can do work */
381 spin_unlock_irqrestore(&mac->lock, flags);
382 return 0;
383 }
384 network = ieee80211softmac_get_network_by_bssid_locked(mac, resp->header.addr3);
385
386 /* someone sending us things without us knowing him? Ignore. */
387 if (!network) {
388 dprintk(KERN_INFO PFX "Received unrequested assocation response from " MAC_FMT "\n", MAC_ARG(resp->header.addr3));
389 spin_unlock_irqrestore(&mac->lock, flags);
390 return 0;
391 }
392
393 /* now that we know it was for us, we can cancel the timeout */
394 cancel_delayed_work(&mac->associnfo.timeout);
395
Daniel Drake5acd0c412006-07-18 21:33:27 +0100396 /* if the association response included an ERP IE, update our saved
397 * copy */
398 if (_ieee80211_network->flags & NETWORK_HAS_ERP_VALUE)
399 network->erp_value = _ieee80211_network->erp_value;
400
Johannes Berg370121e2006-01-04 16:32:16 +0100401 switch (status) {
402 case 0:
403 dprintk(KERN_INFO PFX "associated!\n");
404 ieee80211softmac_associated(mac, resp, network);
405 ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATED, network);
406 break;
407 case WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH:
408 if (!network->auth_desynced_once) {
409 /* there seem to be a few rare cases where our view of
410 * the world is obscured, or buggy APs that don't DEAUTH
411 * us properly. So we handle that, but allow it only once.
412 */
413 printkl(KERN_INFO PFX "We were not authenticated during association, retrying...\n");
414 network->authenticated = 0;
415 /* we don't want to do this more than once ... */
416 network->auth_desynced_once = 1;
Johannes Berg5c4df6d2006-01-06 01:43:45 +0100417 schedule_work(&mac->associnfo.work);
Johannes Berg370121e2006-01-04 16:32:16 +0100418 break;
419 }
420 default:
421 dprintk(KERN_INFO PFX "associating failed (reason: 0x%x)!\n", status);
422 mac->associnfo.associating = 0;
423 mac->associnfo.bssvalid = 0;
424 mac->associated = 0;
425 ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, network);
426 }
427
428 spin_unlock_irqrestore(&mac->lock, flags);
429 return 0;
430}
431
432int
433ieee80211softmac_handle_disassoc(struct net_device * dev,
434 struct ieee80211_disassoc *disassoc)
435{
436 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
Daniel Draked57336e2006-04-30 22:09:07 +0100437
438 if (unlikely(!mac->running))
439 return -ENODEV;
440
Johannes Berg48b2e4c2006-01-10 19:12:19 +0100441 if (memcmp(disassoc->header.addr2, mac->associnfo.bssid, ETH_ALEN))
442 return 0;
Daniel Draked57336e2006-04-30 22:09:07 +0100443
Johannes Berg48b2e4c2006-01-10 19:12:19 +0100444 if (memcmp(disassoc->header.addr1, mac->dev->dev_addr, ETH_ALEN))
445 return 0;
Daniel Draked57336e2006-04-30 22:09:07 +0100446
Johannes Berg370121e2006-01-04 16:32:16 +0100447 dprintk(KERN_INFO PFX "got disassoc frame\n");
Daniel Drake6d92f832006-05-01 22:23:27 +0100448 ieee80211softmac_disassoc(mac);
449
450 /* try to reassociate */
Johannes Bergd1469cf2006-01-10 15:47:06 +0100451 schedule_work(&mac->associnfo.work);
Daniel Drake6d92f832006-05-01 22:23:27 +0100452
Johannes Berg370121e2006-01-04 16:32:16 +0100453 return 0;
454}
Johannes Bergb6c76582006-01-31 19:49:42 +0100455
456int
457ieee80211softmac_handle_reassoc_req(struct net_device * dev,
458 struct ieee80211_reassoc_request * resp)
459{
460 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
461 struct ieee80211softmac_network *network;
462
Daniel Draked57336e2006-04-30 22:09:07 +0100463 if (unlikely(!mac->running))
464 return -ENODEV;
465
Johannes Bergb6c76582006-01-31 19:49:42 +0100466 network = ieee80211softmac_get_network_by_bssid(mac, resp->header.addr3);
467 if (!network) {
468 dprintkl(KERN_INFO PFX "reassoc request from unknown network\n");
469 return 0;
470 }
Michael Buesch9b0b4d82006-04-07 01:42:55 +0200471 schedule_work(&mac->associnfo.work);
472
Johannes Bergb6c76582006-01-31 19:49:42 +0100473 return 0;
474}