blob: 798a8555fbd70e26f0deb615c14788c72ca5b67d [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001/*
2 * Intersil Prism2 driver with Host AP (software access point) support
3 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
4 * <jkmaline@cc.hut.fi>
Jouni Malinen62fe7e32005-07-30 20:43:20 -07005 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
Jouni Malinenff1d2762005-05-12 22:54:16 -04006 *
7 * This file is to be included into hostap.c when S/W AP functionality is
8 * compiled.
9 *
10 * AP: FIX:
11 * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
12 * unauthenticated STA, send deauth. frame (8802.11: 5.5)
13 * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
14 * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
15 * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
16 * (8802.11: 5.5)
17 */
18
Adrian Bunk5fad5a22006-01-14 03:09:34 +010019#include <linux/proc_fs.h>
20#include <linux/delay.h>
21#include <linux/random.h>
22
23#include "hostap_wlan.h"
24#include "hostap.h"
25#include "hostap_ap.h"
26
Jouni Malinenff1d2762005-05-12 22:54:16 -040027static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
28 DEF_INTS };
29module_param_array(other_ap_policy, int, NULL, 0444);
30MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
31
32static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
33 DEF_INTS };
34module_param_array(ap_max_inactivity, int, NULL, 0444);
35MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
36 "inactivity");
37
38static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
39module_param_array(ap_bridge_packets, int, NULL, 0444);
40MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
41 "stations");
42
43static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
44module_param_array(autom_ap_wds, int, NULL, 0444);
45MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
46 "automatically");
47
48
49static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
50static void hostap_event_expired_sta(struct net_device *dev,
51 struct sta_info *sta);
52static void handle_add_proc_queue(void *data);
53
54#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
55static void handle_wds_oper_queue(void *data);
56static void prism2_send_mgmt(struct net_device *dev,
Jouni Malinen4339d322005-08-14 19:08:44 -070057 u16 type_subtype, char *body,
Jouni Malinenff1d2762005-05-12 22:54:16 -040058 int body_len, u8 *addr, u16 tx_cb_idx);
59#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
60
61
62#ifndef PRISM2_NO_PROCFS_DEBUG
63static int ap_debug_proc_read(char *page, char **start, off_t off,
64 int count, int *eof, void *data)
65{
66 char *p = page;
67 struct ap_data *ap = (struct ap_data *) data;
68
69 if (off != 0) {
70 *eof = 1;
71 return 0;
72 }
73
74 p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
75 p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
76 p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
77 p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
78 p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
79 p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
80 p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
81 p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
82
83 return (p - page);
84}
85#endif /* PRISM2_NO_PROCFS_DEBUG */
86
87
88static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
89{
90 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
91 ap->sta_hash[STA_HASH(sta->addr)] = sta;
92}
93
94static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
95{
96 struct sta_info *s;
97
98 s = ap->sta_hash[STA_HASH(sta->addr)];
99 if (s == NULL) return;
100 if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
101 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
102 return;
103 }
104
105 while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
106 != 0)
107 s = s->hnext;
108 if (s->hnext != NULL)
109 s->hnext = s->hnext->hnext;
110 else
111 printk("AP: could not remove STA " MACSTR " from hash table\n",
112 MAC2STR(sta->addr));
113}
114
115static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
116{
117 if (sta->ap && sta->local)
118 hostap_event_expired_sta(sta->local->dev, sta);
119
120 if (ap->proc != NULL) {
121 char name[20];
122 sprintf(name, MACSTR, MAC2STR(sta->addr));
123 remove_proc_entry(name, ap->proc);
124 }
125
126 if (sta->crypt) {
127 sta->crypt->ops->deinit(sta->crypt->priv);
128 kfree(sta->crypt);
129 sta->crypt = NULL;
130 }
131
132 skb_queue_purge(&sta->tx_buf);
133
134 ap->num_sta--;
135#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
136 if (sta->aid > 0)
137 ap->sta_aid[sta->aid - 1] = NULL;
138
139 if (!sta->ap && sta->u.sta.challenge)
140 kfree(sta->u.sta.challenge);
141 del_timer(&sta->timer);
142#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
143
144 kfree(sta);
145}
146
147
148static void hostap_set_tim(local_info_t *local, int aid, int set)
149{
150 if (local->func->set_tim)
151 local->func->set_tim(local->dev, aid, set);
152}
153
154
155static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
156{
157 union iwreq_data wrqu;
158 memset(&wrqu, 0, sizeof(wrqu));
159 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
160 wrqu.addr.sa_family = ARPHRD_ETHER;
161 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
162}
163
164
165static void hostap_event_expired_sta(struct net_device *dev,
166 struct sta_info *sta)
167{
168 union iwreq_data wrqu;
169 memset(&wrqu, 0, sizeof(wrqu));
170 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
171 wrqu.addr.sa_family = ARPHRD_ETHER;
172 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
173}
174
175
176#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
177
178static void ap_handle_timer(unsigned long data)
179{
180 struct sta_info *sta = (struct sta_info *) data;
181 local_info_t *local;
182 struct ap_data *ap;
183 unsigned long next_time = 0;
184 int was_assoc;
185
186 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
187 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
188 return;
189 }
190
191 local = sta->local;
192 ap = local->ap;
193 was_assoc = sta->flags & WLAN_STA_ASSOC;
194
195 if (atomic_read(&sta->users) != 0)
196 next_time = jiffies + HZ;
197 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
198 next_time = jiffies + ap->max_inactivity;
199
200 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
201 /* station activity detected; reset timeout state */
202 sta->timeout_next = STA_NULLFUNC;
203 next_time = sta->last_rx + ap->max_inactivity;
204 } else if (sta->timeout_next == STA_DISASSOC &&
205 !(sta->flags & WLAN_STA_PENDING_POLL)) {
206 /* STA ACKed data nullfunc frame poll */
207 sta->timeout_next = STA_NULLFUNC;
208 next_time = jiffies + ap->max_inactivity;
209 }
210
211 if (next_time) {
212 sta->timer.expires = next_time;
213 add_timer(&sta->timer);
214 return;
215 }
216
217 if (sta->ap)
218 sta->timeout_next = STA_DEAUTH;
219
220 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
221 spin_lock(&ap->sta_table_lock);
222 ap_sta_hash_del(ap, sta);
223 list_del(&sta->list);
224 spin_unlock(&ap->sta_table_lock);
225 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
226 } else if (sta->timeout_next == STA_DISASSOC)
227 sta->flags &= ~WLAN_STA_ASSOC;
228
229 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
230 hostap_event_expired_sta(local->dev, sta);
231
232 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
233 !skb_queue_empty(&sta->tx_buf)) {
234 hostap_set_tim(local, sta->aid, 0);
235 sta->flags &= ~WLAN_STA_TIM;
236 }
237
238 if (sta->ap) {
239 if (ap->autom_ap_wds) {
240 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
241 "connection to AP " MACSTR "\n",
242 local->dev->name, MAC2STR(sta->addr));
243 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
244 }
245 } else if (sta->timeout_next == STA_NULLFUNC) {
246 /* send data frame to poll STA and check whether this frame
247 * is ACKed */
Jouni Malinen4339d322005-08-14 19:08:44 -0700248 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
Jouni Malinenff1d2762005-05-12 22:54:16 -0400249 * it is apparently not retried so TX Exc events are not
250 * received for it */
251 sta->flags |= WLAN_STA_PENDING_POLL;
Jouni Malinen4339d322005-08-14 19:08:44 -0700252 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
253 IEEE80211_STYPE_DATA, NULL, 0,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400254 sta->addr, ap->tx_callback_poll);
255 } else {
256 int deauth = sta->timeout_next == STA_DEAUTH;
257 u16 resp;
258 PDEBUG(DEBUG_AP, "%s: sending %s info to STA " MACSTR
259 "(last=%lu, jiffies=%lu)\n",
260 local->dev->name,
261 deauth ? "deauthentication" : "disassociation",
262 MAC2STR(sta->addr), sta->last_rx, jiffies);
263
264 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
265 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Jouni Malinen4339d322005-08-14 19:08:44 -0700266 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
267 (deauth ? IEEE80211_STYPE_DEAUTH :
268 IEEE80211_STYPE_DISASSOC),
Jouni Malinenff1d2762005-05-12 22:54:16 -0400269 (char *) &resp, 2, sta->addr, 0);
270 }
271
272 if (sta->timeout_next == STA_DEAUTH) {
273 if (sta->flags & WLAN_STA_PERM) {
274 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " would have been "
275 "removed, but it has 'perm' flag\n",
276 local->dev->name, MAC2STR(sta->addr));
277 } else
278 ap_free_sta(ap, sta);
279 return;
280 }
281
282 if (sta->timeout_next == STA_NULLFUNC) {
283 sta->timeout_next = STA_DISASSOC;
284 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
285 } else {
286 sta->timeout_next = STA_DEAUTH;
287 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
288 }
289
290 add_timer(&sta->timer);
291}
292
293
294void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
295 int resend)
296{
297 u8 addr[ETH_ALEN];
298 u16 resp;
299 int i;
300
301 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
302 memset(addr, 0xff, ETH_ALEN);
303
304 resp = __constant_cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
305
306 /* deauth message sent; try to resend it few times; the message is
307 * broadcast, so it may be delayed until next DTIM; there is not much
308 * else we can do at this point since the driver is going to be shut
309 * down */
310 for (i = 0; i < 5; i++) {
Jouni Malinen4339d322005-08-14 19:08:44 -0700311 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
312 IEEE80211_STYPE_DEAUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400313 (char *) &resp, 2, addr, 0);
314
315 if (!resend || ap->num_sta <= 0)
316 return;
317
318 mdelay(50);
319 }
320}
321
322
323static int ap_control_proc_read(char *page, char **start, off_t off,
324 int count, int *eof, void *data)
325{
326 char *p = page;
327 struct ap_data *ap = (struct ap_data *) data;
328 char *policy_txt;
329 struct list_head *ptr;
330 struct mac_entry *entry;
331
332 if (off != 0) {
333 *eof = 1;
334 return 0;
335 }
336
337 switch (ap->mac_restrictions.policy) {
338 case MAC_POLICY_OPEN:
339 policy_txt = "open";
340 break;
341 case MAC_POLICY_ALLOW:
342 policy_txt = "allow";
343 break;
344 case MAC_POLICY_DENY:
345 policy_txt = "deny";
346 break;
347 default:
348 policy_txt = "unknown";
349 break;
350 };
351 p += sprintf(p, "MAC policy: %s\n", policy_txt);
352 p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
353 p += sprintf(p, "MAC list:\n");
354 spin_lock_bh(&ap->mac_restrictions.lock);
355 for (ptr = ap->mac_restrictions.mac_list.next;
356 ptr != &ap->mac_restrictions.mac_list; ptr = ptr->next) {
357 if (p - page > PAGE_SIZE - 80) {
358 p += sprintf(p, "All entries did not fit one page.\n");
359 break;
360 }
361
362 entry = list_entry(ptr, struct mac_entry, list);
363 p += sprintf(p, MACSTR "\n", MAC2STR(entry->addr));
364 }
365 spin_unlock_bh(&ap->mac_restrictions.lock);
366
367 return (p - page);
368}
369
370
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100371int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400372{
373 struct mac_entry *entry;
374
375 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
376 if (entry == NULL)
377 return -1;
378
379 memcpy(entry->addr, mac, ETH_ALEN);
380
381 spin_lock_bh(&mac_restrictions->lock);
382 list_add_tail(&entry->list, &mac_restrictions->mac_list);
383 mac_restrictions->entries++;
384 spin_unlock_bh(&mac_restrictions->lock);
385
386 return 0;
387}
388
389
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100390int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400391{
392 struct list_head *ptr;
393 struct mac_entry *entry;
394
395 spin_lock_bh(&mac_restrictions->lock);
396 for (ptr = mac_restrictions->mac_list.next;
397 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
398 entry = list_entry(ptr, struct mac_entry, list);
399
400 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
401 list_del(ptr);
402 kfree(entry);
403 mac_restrictions->entries--;
404 spin_unlock_bh(&mac_restrictions->lock);
405 return 0;
406 }
407 }
408 spin_unlock_bh(&mac_restrictions->lock);
409 return -1;
410}
411
412
413static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
414 u8 *mac)
415{
416 struct list_head *ptr;
417 struct mac_entry *entry;
418 int found = 0;
419
420 if (mac_restrictions->policy == MAC_POLICY_OPEN)
421 return 0;
422
423 spin_lock_bh(&mac_restrictions->lock);
424 for (ptr = mac_restrictions->mac_list.next;
425 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
426 entry = list_entry(ptr, struct mac_entry, list);
427
428 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
429 found = 1;
430 break;
431 }
432 }
433 spin_unlock_bh(&mac_restrictions->lock);
434
435 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
436 return !found;
437 else
438 return found;
439}
440
441
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100442void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400443{
444 struct list_head *ptr, *n;
445 struct mac_entry *entry;
446
447 if (mac_restrictions->entries == 0)
448 return;
449
450 spin_lock_bh(&mac_restrictions->lock);
451 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
452 ptr != &mac_restrictions->mac_list;
453 ptr = n, n = ptr->next) {
454 entry = list_entry(ptr, struct mac_entry, list);
455 list_del(ptr);
456 kfree(entry);
457 }
458 mac_restrictions->entries = 0;
459 spin_unlock_bh(&mac_restrictions->lock);
460}
461
462
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100463int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400464{
465 struct sta_info *sta;
466 u16 resp;
467
468 spin_lock_bh(&ap->sta_table_lock);
469 sta = ap_get_sta(ap, mac);
470 if (sta) {
471 ap_sta_hash_del(ap, sta);
472 list_del(&sta->list);
473 }
474 spin_unlock_bh(&ap->sta_table_lock);
475
476 if (!sta)
477 return -EINVAL;
478
479 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
Jouni Malinen4339d322005-08-14 19:08:44 -0700480 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400481 (char *) &resp, 2, sta->addr, 0);
482
483 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
484 hostap_event_expired_sta(dev, sta);
485
486 ap_free_sta(ap, sta);
487
488 return 0;
489}
490
491#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
492
493
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100494void ap_control_kickall(struct ap_data *ap)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400495{
496 struct list_head *ptr, *n;
497 struct sta_info *sta;
Jeff Garzik74fae822005-07-31 13:08:32 -0400498
Jouni Malinenff1d2762005-05-12 22:54:16 -0400499 spin_lock_bh(&ap->sta_table_lock);
500 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
501 ptr = n, n = ptr->next) {
502 sta = list_entry(ptr, struct sta_info, list);
503 ap_sta_hash_del(ap, sta);
504 list_del(&sta->list);
505 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
506 hostap_event_expired_sta(sta->local->dev, sta);
507 ap_free_sta(ap, sta);
508 }
509 spin_unlock_bh(&ap->sta_table_lock);
510}
511
512
513#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
514
515#define PROC_LIMIT (PAGE_SIZE - 80)
516
517static int prism2_ap_proc_read(char *page, char **start, off_t off,
518 int count, int *eof, void *data)
519{
520 char *p = page;
521 struct ap_data *ap = (struct ap_data *) data;
522 struct list_head *ptr;
523 int i;
524
525 if (off > PROC_LIMIT) {
526 *eof = 1;
527 return 0;
528 }
529
530 p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
531 spin_lock_bh(&ap->sta_table_lock);
532 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
533 struct sta_info *sta = (struct sta_info *) ptr;
534
535 if (!sta->ap)
536 continue;
537
538 p += sprintf(p, MACSTR " %d %d %d %d '", MAC2STR(sta->addr),
539 sta->u.ap.channel, sta->last_rx_signal,
540 sta->last_rx_silence, sta->last_rx_rate);
541 for (i = 0; i < sta->u.ap.ssid_len; i++)
542 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
543 sta->u.ap.ssid[i] < 127) ?
544 "%c" : "<%02x>"),
545 sta->u.ap.ssid[i]);
546 p += sprintf(p, "'");
547 if (sta->capability & WLAN_CAPABILITY_ESS)
548 p += sprintf(p, " [ESS]");
549 if (sta->capability & WLAN_CAPABILITY_IBSS)
550 p += sprintf(p, " [IBSS]");
551 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
552 p += sprintf(p, " [WEP]");
553 p += sprintf(p, "\n");
554
555 if ((p - page) > PROC_LIMIT) {
556 printk(KERN_DEBUG "hostap: ap proc did not fit\n");
557 break;
558 }
559 }
560 spin_unlock_bh(&ap->sta_table_lock);
561
562 if ((p - page) <= off) {
563 *eof = 1;
564 return 0;
565 }
566
567 *start = page + off;
568
569 return (p - page - off);
570}
571#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
572
573
574void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
575{
576 if (!ap)
577 return;
578
579 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
580 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
581 "firmware upgrade recommended\n");
582 ap->nullfunc_ack = 1;
583 } else
584 ap->nullfunc_ack = 0;
585
586 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
587 printk(KERN_WARNING "%s: Warning: secondary station firmware "
588 "version 1.4.2 does not seem to work in Host AP mode\n",
589 ap->local->dev->name);
590 }
591}
592
593
594/* Called only as a tasklet (software IRQ) */
595static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
596{
597 struct ap_data *ap = data;
598 u16 fc;
James Ketrenosd0416742005-09-21 12:23:49 -0500599 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400600
601 if (!ap->local->hostapd || !ap->local->apdev) {
602 dev_kfree_skb(skb);
603 return;
604 }
605
James Ketrenosd0416742005-09-21 12:23:49 -0500606 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700607 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400608
609 /* Pass the TX callback frame to the hostapd; use 802.11 header version
610 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
611
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700612 fc &= ~IEEE80211_FCTL_VERS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400613 fc |= ok ? BIT(1) : BIT(0);
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700614 hdr->frame_ctl = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400615
616 skb->dev = ap->local->apdev;
617 skb_pull(skb, hostap_80211_get_hdrlen(fc));
618 skb->pkt_type = PACKET_OTHERHOST;
619 skb->protocol = __constant_htons(ETH_P_802_2);
620 memset(skb->cb, 0, sizeof(skb->cb));
621 netif_rx(skb);
622}
623
624
625#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
626/* Called only as a tasklet (software IRQ) */
627static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
628{
629 struct ap_data *ap = data;
630 struct net_device *dev = ap->local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -0500631 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400632 u16 fc, *pos, auth_alg, auth_transaction, status;
633 struct sta_info *sta = NULL;
634 char *txt = NULL;
635
636 if (ap->local->hostapd) {
637 dev_kfree_skb(skb);
638 return;
639 }
640
James Ketrenosd0416742005-09-21 12:23:49 -0500641 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700642 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinen4339d322005-08-14 19:08:44 -0700643 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
644 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_AUTH ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400645 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
646 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
647 "frame\n", dev->name);
648 dev_kfree_skb(skb);
649 return;
650 }
651
652 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
653 auth_alg = le16_to_cpu(*pos++);
654 auth_transaction = le16_to_cpu(*pos++);
655 status = le16_to_cpu(*pos++);
656
657 if (!ok) {
658 txt = "frame was not ACKed";
659 goto done;
660 }
661
662 spin_lock(&ap->sta_table_lock);
663 sta = ap_get_sta(ap, hdr->addr1);
664 if (sta)
665 atomic_inc(&sta->users);
666 spin_unlock(&ap->sta_table_lock);
667
668 if (!sta) {
669 txt = "STA not found";
670 goto done;
671 }
672
673 if (status == WLAN_STATUS_SUCCESS &&
674 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
675 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
676 txt = "STA authenticated";
677 sta->flags |= WLAN_STA_AUTH;
678 sta->last_auth = jiffies;
679 } else if (status != WLAN_STATUS_SUCCESS)
680 txt = "authentication failed";
681
682 done:
683 if (sta)
684 atomic_dec(&sta->users);
685 if (txt) {
686 PDEBUG(DEBUG_AP, "%s: " MACSTR " auth_cb - alg=%d trans#=%d "
687 "status=%d - %s\n",
688 dev->name, MAC2STR(hdr->addr1), auth_alg,
689 auth_transaction, status, txt);
690 }
691 dev_kfree_skb(skb);
692}
693
694
695/* Called only as a tasklet (software IRQ) */
696static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
697{
698 struct ap_data *ap = data;
699 struct net_device *dev = ap->local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -0500700 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400701 u16 fc, *pos, status;
702 struct sta_info *sta = NULL;
703 char *txt = NULL;
704
705 if (ap->local->hostapd) {
706 dev_kfree_skb(skb);
707 return;
708 }
709
James Ketrenosd0416742005-09-21 12:23:49 -0500710 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700711 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinen4339d322005-08-14 19:08:44 -0700712 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
713 (WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_ASSOC_RESP &&
714 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_REASSOC_RESP) ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400715 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
716 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
717 "frame\n", dev->name);
718 dev_kfree_skb(skb);
719 return;
720 }
721
722 if (!ok) {
723 txt = "frame was not ACKed";
724 goto done;
725 }
726
727 spin_lock(&ap->sta_table_lock);
728 sta = ap_get_sta(ap, hdr->addr1);
729 if (sta)
730 atomic_inc(&sta->users);
731 spin_unlock(&ap->sta_table_lock);
732
733 if (!sta) {
734 txt = "STA not found";
735 goto done;
736 }
737
738 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
739 pos++;
740 status = le16_to_cpu(*pos++);
741 if (status == WLAN_STATUS_SUCCESS) {
742 if (!(sta->flags & WLAN_STA_ASSOC))
743 hostap_event_new_sta(dev, sta);
744 txt = "STA associated";
745 sta->flags |= WLAN_STA_ASSOC;
746 sta->last_assoc = jiffies;
747 } else
748 txt = "association failed";
749
750 done:
751 if (sta)
752 atomic_dec(&sta->users);
753 if (txt) {
754 PDEBUG(DEBUG_AP, "%s: " MACSTR " assoc_cb - %s\n",
755 dev->name, MAC2STR(hdr->addr1), txt);
756 }
757 dev_kfree_skb(skb);
758}
759
760/* Called only as a tasklet (software IRQ); TX callback for poll frames used
761 * in verifying whether the STA is still present. */
762static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
763{
764 struct ap_data *ap = data;
James Ketrenosd0416742005-09-21 12:23:49 -0500765 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400766 struct sta_info *sta;
767
768 if (skb->len < 24)
769 goto fail;
James Ketrenosd0416742005-09-21 12:23:49 -0500770 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400771 if (ok) {
772 spin_lock(&ap->sta_table_lock);
773 sta = ap_get_sta(ap, hdr->addr1);
774 if (sta)
775 sta->flags &= ~WLAN_STA_PENDING_POLL;
776 spin_unlock(&ap->sta_table_lock);
777 } else {
778 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " did not ACK activity "
779 "poll frame\n", ap->local->dev->name,
780 MAC2STR(hdr->addr1));
781 }
782
783 fail:
784 dev_kfree_skb(skb);
785}
786#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
787
788
789void hostap_init_data(local_info_t *local)
790{
791 struct ap_data *ap = local->ap;
792
793 if (ap == NULL) {
794 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
795 return;
796 }
797 memset(ap, 0, sizeof(struct ap_data));
798 ap->local = local;
799
800 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
801 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
802 ap->max_inactivity =
803 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
804 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
805
806 spin_lock_init(&ap->sta_table_lock);
807 INIT_LIST_HEAD(&ap->sta_list);
808
809 /* Initialize task queue structure for AP management */
810 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue, ap);
811
812 ap->tx_callback_idx =
813 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
814 if (ap->tx_callback_idx == 0)
815 printk(KERN_WARNING "%s: failed to register TX callback for "
816 "AP\n", local->dev->name);
817#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
818 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue, local);
819
820 ap->tx_callback_auth =
821 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
822 ap->tx_callback_assoc =
823 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
824 ap->tx_callback_poll =
825 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
826 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
827 ap->tx_callback_poll == 0)
828 printk(KERN_WARNING "%s: failed to register TX callback for "
829 "AP\n", local->dev->name);
830
831 spin_lock_init(&ap->mac_restrictions.lock);
832 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
833#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
834
835 ap->initialized = 1;
836}
837
838
839void hostap_init_ap_proc(local_info_t *local)
840{
841 struct ap_data *ap = local->ap;
842
843 ap->proc = local->proc;
844 if (ap->proc == NULL)
845 return;
846
847#ifndef PRISM2_NO_PROCFS_DEBUG
848 create_proc_read_entry("ap_debug", 0, ap->proc,
849 ap_debug_proc_read, ap);
850#endif /* PRISM2_NO_PROCFS_DEBUG */
851
852#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
853 create_proc_read_entry("ap_control", 0, ap->proc,
854 ap_control_proc_read, ap);
855 create_proc_read_entry("ap", 0, ap->proc,
856 prism2_ap_proc_read, ap);
857#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
858
859}
860
861
862void hostap_free_data(struct ap_data *ap)
863{
864 struct list_head *n, *ptr;
865
866 if (ap == NULL || !ap->initialized) {
867 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
868 "initialized - skip resource freeing\n");
869 return;
870 }
871
872#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
873 if (ap->crypt)
874 ap->crypt->deinit(ap->crypt_priv);
875 ap->crypt = ap->crypt_priv = NULL;
876#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
877
878 list_for_each_safe(ptr, n, &ap->sta_list) {
879 struct sta_info *sta = list_entry(ptr, struct sta_info, list);
880 ap_sta_hash_del(ap, sta);
881 list_del(&sta->list);
882 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
883 hostap_event_expired_sta(sta->local->dev, sta);
884 ap_free_sta(ap, sta);
885 }
886
887#ifndef PRISM2_NO_PROCFS_DEBUG
888 if (ap->proc != NULL) {
889 remove_proc_entry("ap_debug", ap->proc);
890 }
891#endif /* PRISM2_NO_PROCFS_DEBUG */
892
893#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
894 if (ap->proc != NULL) {
895 remove_proc_entry("ap", ap->proc);
896 remove_proc_entry("ap_control", ap->proc);
897 }
898 ap_control_flush_macs(&ap->mac_restrictions);
899#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
900
901 ap->initialized = 0;
902}
903
904
905/* caller should have mutex for AP STA list handling */
906static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
907{
908 struct sta_info *s;
909
910 s = ap->sta_hash[STA_HASH(sta)];
911 while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
912 s = s->hnext;
913 return s;
914}
915
916
917#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
918
919/* Called from timer handler and from scheduled AP queue handlers */
920static void prism2_send_mgmt(struct net_device *dev,
Jouni Malinen4339d322005-08-14 19:08:44 -0700921 u16 type_subtype, char *body,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400922 int body_len, u8 *addr, u16 tx_cb_idx)
923{
924 struct hostap_interface *iface;
925 local_info_t *local;
James Ketrenosd0416742005-09-21 12:23:49 -0500926 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400927 u16 fc;
928 struct sk_buff *skb;
929 struct hostap_skb_tx_data *meta;
930 int hdrlen;
931
932 iface = netdev_priv(dev);
933 local = iface->local;
934 dev = local->dev; /* always use master radio device */
935 iface = netdev_priv(dev);
936
937 if (!(dev->flags & IFF_UP)) {
938 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
939 "cannot send frame\n", dev->name);
940 return;
941 }
942
943 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
944 if (skb == NULL) {
945 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
946 "skb\n", dev->name);
947 return;
948 }
949
Jouni Malinen4339d322005-08-14 19:08:44 -0700950 fc = type_subtype;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400951 hdrlen = hostap_80211_get_hdrlen(fc);
James Ketrenosd0416742005-09-21 12:23:49 -0500952 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, hdrlen);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400953 if (body)
954 memcpy(skb_put(skb, body_len), body, body_len);
955
956 memset(hdr, 0, hdrlen);
957
958 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
959 * tx_control instead of using local->tx_control */
960
961
962 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
Jouni Malinen4339d322005-08-14 19:08:44 -0700963 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700964 fc |= IEEE80211_FCTL_FROMDS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400965 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
966 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
Jouni Malinen4339d322005-08-14 19:08:44 -0700967 } else if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_CTL) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400968 /* control:ACK does not have addr2 or addr3 */
969 memset(hdr->addr2, 0, ETH_ALEN);
970 memset(hdr->addr3, 0, ETH_ALEN);
971 } else {
972 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
973 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
974 }
975
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700976 hdr->frame_ctl = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400977
978 meta = (struct hostap_skb_tx_data *) skb->cb;
979 memset(meta, 0, sizeof(*meta));
980 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
981 meta->iface = iface;
982 meta->tx_cb_idx = tx_cb_idx;
983
984 skb->dev = dev;
985 skb->mac.raw = skb->nh.raw = skb->data;
986 dev_queue_xmit(skb);
987}
988#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
989
990
991static int prism2_sta_proc_read(char *page, char **start, off_t off,
992 int count, int *eof, void *data)
993{
994 char *p = page;
995 struct sta_info *sta = (struct sta_info *) data;
996 int i;
997
998 /* FIX: possible race condition.. the STA data could have just expired,
999 * but proc entry was still here so that the read could have started;
1000 * some locking should be done here.. */
1001
1002 if (off != 0) {
1003 *eof = 1;
1004 return 0;
1005 }
1006
1007 p += sprintf(p, "%s=" MACSTR "\nusers=%d\naid=%d\n"
1008 "flags=0x%04x%s%s%s%s%s%s%s\n"
1009 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1010 sta->ap ? "AP" : "STA",
1011 MAC2STR(sta->addr), atomic_read(&sta->users), sta->aid,
1012 sta->flags,
1013 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1014 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1015 sta->flags & WLAN_STA_PS ? " PS" : "",
1016 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1017 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1018 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1019 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1020 sta->capability, sta->listen_interval);
1021 /* supported_rates: 500 kbit/s units with msb ignored */
1022 for (i = 0; i < sizeof(sta->supported_rates); i++)
1023 if (sta->supported_rates[i] != 0)
1024 p += sprintf(p, "%d%sMbps ",
1025 (sta->supported_rates[i] & 0x7f) / 2,
1026 sta->supported_rates[i] & 1 ? ".5" : "");
1027 p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1028 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1029 "tx_packets=%lu\n"
1030 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1031 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1032 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1033 "tx[11M]=%d\n"
1034 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1035 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1036 sta->last_tx,
1037 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1038 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1039 sta->last_rx_silence,
1040 sta->last_rx_signal, sta->last_rx_rate / 10,
1041 sta->last_rx_rate % 10 ? ".5" : "",
1042 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1043 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1044 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1045 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1046 p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
1047#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1048 if (sta->ap) {
1049 if (sta->u.ap.channel >= 0)
1050 p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
1051 p += sprintf(p, "ssid=");
1052 for (i = 0; i < sta->u.ap.ssid_len; i++)
1053 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
1054 sta->u.ap.ssid[i] < 127) ?
1055 "%c" : "<%02x>"),
1056 sta->u.ap.ssid[i]);
1057 p += sprintf(p, "\n");
1058 }
1059#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1060
1061 return (p - page);
1062}
1063
1064
1065static void handle_add_proc_queue(void *data)
1066{
1067 struct ap_data *ap = (struct ap_data *) data;
1068 struct sta_info *sta;
1069 char name[20];
1070 struct add_sta_proc_data *entry, *prev;
1071
1072 entry = ap->add_sta_proc_entries;
1073 ap->add_sta_proc_entries = NULL;
1074
1075 while (entry) {
1076 spin_lock_bh(&ap->sta_table_lock);
1077 sta = ap_get_sta(ap, entry->addr);
1078 if (sta)
1079 atomic_inc(&sta->users);
1080 spin_unlock_bh(&ap->sta_table_lock);
1081
1082 if (sta) {
1083 sprintf(name, MACSTR, MAC2STR(sta->addr));
1084 sta->proc = create_proc_read_entry(
1085 name, 0, ap->proc,
1086 prism2_sta_proc_read, sta);
1087
1088 atomic_dec(&sta->users);
1089 }
1090
1091 prev = entry;
1092 entry = entry->next;
1093 kfree(prev);
1094 }
1095}
1096
1097
1098static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1099{
1100 struct sta_info *sta;
1101
Yan Burmanb0471bb72006-12-02 13:33:40 +02001102 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001103 if (sta == NULL) {
1104 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1105 return NULL;
1106 }
1107
1108 /* initialize STA info data */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001109 sta->local = ap->local;
1110 skb_queue_head_init(&sta->tx_buf);
1111 memcpy(sta->addr, addr, ETH_ALEN);
1112
1113 atomic_inc(&sta->users);
1114 spin_lock_bh(&ap->sta_table_lock);
1115 list_add(&sta->list, &ap->sta_list);
1116 ap->num_sta++;
1117 ap_sta_hash_add(ap, sta);
1118 spin_unlock_bh(&ap->sta_table_lock);
1119
1120 if (ap->proc) {
1121 struct add_sta_proc_data *entry;
1122 /* schedule a non-interrupt context process to add a procfs
1123 * entry for the STA since procfs code use GFP_KERNEL */
1124 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1125 if (entry) {
1126 memcpy(entry->addr, sta->addr, ETH_ALEN);
1127 entry->next = ap->add_sta_proc_entries;
1128 ap->add_sta_proc_entries = entry;
1129 schedule_work(&ap->add_sta_proc_queue);
1130 } else
1131 printk(KERN_DEBUG "Failed to add STA proc data\n");
1132 }
1133
1134#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1135 init_timer(&sta->timer);
1136 sta->timer.expires = jiffies + ap->max_inactivity;
1137 sta->timer.data = (unsigned long) sta;
1138 sta->timer.function = ap_handle_timer;
1139 if (!ap->local->hostapd)
1140 add_timer(&sta->timer);
1141#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1142
1143 return sta;
1144}
1145
1146
1147static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1148 local_info_t *local)
1149{
1150 if (rateidx > sta->tx_max_rate ||
1151 !(sta->tx_supp_rates & (1 << rateidx)))
1152 return 0;
1153
1154 if (local->tx_rate_control != 0 &&
1155 !(local->tx_rate_control & (1 << rateidx)))
1156 return 0;
1157
1158 return 1;
1159}
1160
1161
1162static void prism2_check_tx_rates(struct sta_info *sta)
1163{
1164 int i;
1165
1166 sta->tx_supp_rates = 0;
1167 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1168 if ((sta->supported_rates[i] & 0x7f) == 2)
1169 sta->tx_supp_rates |= WLAN_RATE_1M;
1170 if ((sta->supported_rates[i] & 0x7f) == 4)
1171 sta->tx_supp_rates |= WLAN_RATE_2M;
1172 if ((sta->supported_rates[i] & 0x7f) == 11)
1173 sta->tx_supp_rates |= WLAN_RATE_5M5;
1174 if ((sta->supported_rates[i] & 0x7f) == 22)
1175 sta->tx_supp_rates |= WLAN_RATE_11M;
1176 }
1177 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1178 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1179 sta->tx_max_rate = 0;
1180 if (ap_tx_rate_ok(0, sta, sta->local)) {
1181 sta->tx_rate = 10;
1182 sta->tx_rate_idx = 0;
1183 }
1184 }
1185 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1186 sta->tx_max_rate = 1;
1187 if (ap_tx_rate_ok(1, sta, sta->local)) {
1188 sta->tx_rate = 20;
1189 sta->tx_rate_idx = 1;
1190 }
1191 }
1192 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1193 sta->tx_max_rate = 2;
1194 if (ap_tx_rate_ok(2, sta, sta->local)) {
1195 sta->tx_rate = 55;
1196 sta->tx_rate_idx = 2;
1197 }
1198 }
1199 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1200 sta->tx_max_rate = 3;
1201 if (ap_tx_rate_ok(3, sta, sta->local)) {
1202 sta->tx_rate = 110;
1203 sta->tx_rate_idx = 3;
1204 }
1205 }
1206}
1207
1208
1209#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1210
1211static void ap_crypt_init(struct ap_data *ap)
1212{
Jouni Malinen62fe7e32005-07-30 20:43:20 -07001213 ap->crypt = ieee80211_get_crypto_ops("WEP");
Jouni Malinenff1d2762005-05-12 22:54:16 -04001214
1215 if (ap->crypt) {
1216 if (ap->crypt->init) {
1217 ap->crypt_priv = ap->crypt->init(0);
1218 if (ap->crypt_priv == NULL)
1219 ap->crypt = NULL;
1220 else {
1221 u8 key[WEP_KEY_LEN];
1222 get_random_bytes(key, WEP_KEY_LEN);
1223 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1224 ap->crypt_priv);
1225 }
1226 }
1227 }
1228
1229 if (ap->crypt == NULL) {
1230 printk(KERN_WARNING "AP could not initialize WEP: load module "
Jouni Malinen62fe7e32005-07-30 20:43:20 -07001231 "ieee80211_crypt_wep.ko\n");
Jouni Malinenff1d2762005-05-12 22:54:16 -04001232 }
1233}
1234
1235
1236/* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1237 * that WEP algorithm is used for generating challange. This should be unique,
1238 * but otherwise there is not really need for randomness etc. Initialize WEP
1239 * with pseudo random key and then use increasing IV to get unique challenge
1240 * streams.
1241 *
1242 * Called only as a scheduled task for pending AP frames.
1243 */
1244static char * ap_auth_make_challenge(struct ap_data *ap)
1245{
1246 char *tmpbuf;
1247 struct sk_buff *skb;
1248
1249 if (ap->crypt == NULL) {
1250 ap_crypt_init(ap);
1251 if (ap->crypt == NULL)
1252 return NULL;
1253 }
1254
1255 tmpbuf = (char *) kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1256 if (tmpbuf == NULL) {
1257 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1258 return NULL;
1259 }
1260
1261 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
James Ketrenos5bfc8192005-09-21 12:23:51 -05001262 ap->crypt->extra_mpdu_prefix_len +
1263 ap->crypt->extra_mpdu_postfix_len);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001264 if (skb == NULL) {
1265 kfree(tmpbuf);
1266 return NULL;
1267 }
1268
James Ketrenos5bfc8192005-09-21 12:23:51 -05001269 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001270 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
1271 WLAN_AUTH_CHALLENGE_LEN);
1272 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1273 dev_kfree_skb(skb);
1274 kfree(tmpbuf);
1275 return NULL;
1276 }
1277
James Ketrenos5bfc8192005-09-21 12:23:51 -05001278 memcpy(tmpbuf, skb->data + ap->crypt->extra_mpdu_prefix_len,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001279 WLAN_AUTH_CHALLENGE_LEN);
1280 dev_kfree_skb(skb);
1281
1282 return tmpbuf;
1283}
1284
1285
1286/* Called only as a scheduled task for pending AP frames. */
1287static void handle_authen(local_info_t *local, struct sk_buff *skb,
1288 struct hostap_80211_rx_status *rx_stats)
1289{
1290 struct net_device *dev = local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -05001291 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001292 size_t hdrlen;
1293 struct ap_data *ap = local->ap;
1294 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1295 int len, olen;
1296 u16 auth_alg, auth_transaction, status_code, *pos;
1297 u16 resp = WLAN_STATUS_SUCCESS, fc;
1298 struct sta_info *sta = NULL;
Jouni Malinen62fe7e32005-07-30 20:43:20 -07001299 struct ieee80211_crypt_data *crypt;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001300 char *txt = "";
1301
1302 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1303
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07001304 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001305 hdrlen = hostap_80211_get_hdrlen(fc);
1306
1307 if (len < 6) {
1308 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1309 "(len=%d) from " MACSTR "\n", dev->name, len,
1310 MAC2STR(hdr->addr2));
1311 return;
1312 }
1313
1314 spin_lock_bh(&local->ap->sta_table_lock);
1315 sta = ap_get_sta(local->ap, hdr->addr2);
1316 if (sta)
1317 atomic_inc(&sta->users);
1318 spin_unlock_bh(&local->ap->sta_table_lock);
1319
1320 if (sta && sta->crypt)
1321 crypt = sta->crypt;
1322 else {
1323 int idx = 0;
1324 if (skb->len >= hdrlen + 3)
1325 idx = skb->data[hdrlen + 3] >> 6;
1326 crypt = local->crypt[idx];
1327 }
1328
1329 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1330 auth_alg = __le16_to_cpu(*pos);
1331 pos++;
1332 auth_transaction = __le16_to_cpu(*pos);
1333 pos++;
1334 status_code = __le16_to_cpu(*pos);
1335 pos++;
1336
1337 if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
1338 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1339 txt = "authentication denied";
1340 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1341 goto fail;
1342 }
1343
1344 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1345 auth_alg == WLAN_AUTH_OPEN) ||
1346 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1347 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1348 } else {
1349 txt = "unsupported algorithm";
1350 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1351 goto fail;
1352 }
1353
1354 if (len >= 8) {
1355 u8 *u = (u8 *) pos;
1356 if (*u == WLAN_EID_CHALLENGE) {
1357 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1358 txt = "invalid challenge len";
1359 resp = WLAN_STATUS_CHALLENGE_FAIL;
1360 goto fail;
1361 }
1362 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1363 txt = "challenge underflow";
1364 resp = WLAN_STATUS_CHALLENGE_FAIL;
1365 goto fail;
1366 }
1367 challenge = (char *) (u + 2);
1368 }
1369 }
1370
1371 if (sta && sta->ap) {
1372 if (time_after(jiffies, sta->u.ap.last_beacon +
1373 (10 * sta->listen_interval * HZ) / 1024)) {
1374 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1375 " assuming AP " MACSTR " is now STA\n",
1376 dev->name, MAC2STR(sta->addr));
1377 sta->ap = 0;
1378 sta->flags = 0;
1379 sta->u.sta.challenge = NULL;
1380 } else {
1381 txt = "AP trying to authenticate?";
1382 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1383 goto fail;
1384 }
1385 }
1386
1387 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1388 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1389 (auth_transaction == 1 ||
1390 (auth_transaction == 3 && sta != NULL &&
1391 sta->u.sta.challenge != NULL)))) {
1392 } else {
1393 txt = "unknown authentication transaction number";
1394 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1395 goto fail;
1396 }
1397
1398 if (sta == NULL) {
1399 txt = "new STA";
1400
1401 if (local->ap->num_sta >= MAX_STA_COUNT) {
1402 /* FIX: might try to remove some old STAs first? */
1403 txt = "no more room for new STAs";
1404 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1405 goto fail;
1406 }
1407
1408 sta = ap_add_sta(local->ap, hdr->addr2);
1409 if (sta == NULL) {
1410 txt = "ap_add_sta failed";
1411 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1412 goto fail;
1413 }
1414 }
1415
1416 switch (auth_alg) {
1417 case WLAN_AUTH_OPEN:
1418 txt = "authOK";
1419 /* IEEE 802.11 standard is not completely clear about
1420 * whether STA is considered authenticated after
1421 * authentication OK frame has been send or after it
1422 * has been ACKed. In order to reduce interoperability
1423 * issues, mark the STA authenticated before ACK. */
1424 sta->flags |= WLAN_STA_AUTH;
1425 break;
1426
1427 case WLAN_AUTH_SHARED_KEY:
1428 if (auth_transaction == 1) {
1429 if (sta->u.sta.challenge == NULL) {
1430 sta->u.sta.challenge =
1431 ap_auth_make_challenge(local->ap);
1432 if (sta->u.sta.challenge == NULL) {
1433 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1434 goto fail;
1435 }
1436 }
1437 } else {
1438 if (sta->u.sta.challenge == NULL ||
1439 challenge == NULL ||
1440 memcmp(sta->u.sta.challenge, challenge,
1441 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
Jeff Garzik831a1792005-08-25 20:59:10 -04001442 !(fc & IEEE80211_FCTL_PROTECTED)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04001443 txt = "challenge response incorrect";
1444 resp = WLAN_STATUS_CHALLENGE_FAIL;
1445 goto fail;
1446 }
1447
1448 txt = "challenge OK - authOK";
1449 /* IEEE 802.11 standard is not completely clear about
1450 * whether STA is considered authenticated after
1451 * authentication OK frame has been send or after it
1452 * has been ACKed. In order to reduce interoperability
1453 * issues, mark the STA authenticated before ACK. */
1454 sta->flags |= WLAN_STA_AUTH;
1455 kfree(sta->u.sta.challenge);
1456 sta->u.sta.challenge = NULL;
1457 }
1458 break;
1459 }
1460
1461 fail:
1462 pos = (u16 *) body;
1463 *pos = cpu_to_le16(auth_alg);
1464 pos++;
1465 *pos = cpu_to_le16(auth_transaction + 1);
1466 pos++;
1467 *pos = cpu_to_le16(resp); /* status_code */
1468 pos++;
1469 olen = 6;
1470
1471 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1472 sta->u.sta.challenge != NULL &&
1473 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1474 u8 *tmp = (u8 *) pos;
1475 *tmp++ = WLAN_EID_CHALLENGE;
1476 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1477 pos++;
1478 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1479 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1480 }
1481
Jouni Malinen4339d322005-08-14 19:08:44 -07001482 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001483 body, olen, hdr->addr2, ap->tx_callback_auth);
1484
1485 if (sta) {
1486 sta->last_rx = jiffies;
1487 atomic_dec(&sta->users);
1488 }
1489
1490 if (resp) {
1491 PDEBUG(DEBUG_AP, "%s: " MACSTR " auth (alg=%d trans#=%d "
1492 "stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1493 dev->name, MAC2STR(hdr->addr2), auth_alg,
1494 auth_transaction, status_code, len, fc, resp, txt);
1495 }
1496}
1497
1498
1499/* Called only as a scheduled task for pending AP frames. */
1500static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1501 struct hostap_80211_rx_status *rx_stats, int reassoc)
1502{
1503 struct net_device *dev = local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -05001504 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001505 char body[12], *p, *lpos;
1506 int len, left;
1507 u16 *pos;
1508 u16 resp = WLAN_STATUS_SUCCESS;
1509 struct sta_info *sta = NULL;
1510 int send_deauth = 0;
1511 char *txt = "";
1512 u8 prev_ap[ETH_ALEN];
1513
1514 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1515
1516 if (len < (reassoc ? 10 : 4)) {
1517 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1518 "(len=%d, reassoc=%d) from " MACSTR "\n",
1519 dev->name, len, reassoc, MAC2STR(hdr->addr2));
1520 return;
1521 }
1522
1523 spin_lock_bh(&local->ap->sta_table_lock);
1524 sta = ap_get_sta(local->ap, hdr->addr2);
1525 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1526 spin_unlock_bh(&local->ap->sta_table_lock);
1527 txt = "trying to associate before authentication";
1528 send_deauth = 1;
1529 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1530 sta = NULL; /* do not decrement sta->users */
1531 goto fail;
1532 }
1533 atomic_inc(&sta->users);
1534 spin_unlock_bh(&local->ap->sta_table_lock);
1535
1536 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1537 sta->capability = __le16_to_cpu(*pos);
1538 pos++; left -= 2;
1539 sta->listen_interval = __le16_to_cpu(*pos);
1540 pos++; left -= 2;
1541
1542 if (reassoc) {
1543 memcpy(prev_ap, pos, ETH_ALEN);
1544 pos++; pos++; pos++; left -= 6;
1545 } else
1546 memset(prev_ap, 0, ETH_ALEN);
1547
1548 if (left >= 2) {
1549 unsigned int ileft;
1550 unsigned char *u = (unsigned char *) pos;
1551
1552 if (*u == WLAN_EID_SSID) {
1553 u++; left--;
1554 ileft = *u;
1555 u++; left--;
1556
1557 if (ileft > left || ileft > MAX_SSID_LEN) {
1558 txt = "SSID overflow";
1559 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1560 goto fail;
1561 }
1562
1563 if (ileft != strlen(local->essid) ||
1564 memcmp(local->essid, u, ileft) != 0) {
1565 txt = "not our SSID";
1566 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1567 goto fail;
1568 }
1569
1570 u += ileft;
1571 left -= ileft;
1572 }
1573
1574 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1575 u++; left--;
1576 ileft = *u;
1577 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04001578
Jouni Malinenff1d2762005-05-12 22:54:16 -04001579 if (ileft > left || ileft == 0 ||
1580 ileft > WLAN_SUPP_RATES_MAX) {
1581 txt = "SUPP_RATES len error";
1582 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1583 goto fail;
1584 }
1585
1586 memset(sta->supported_rates, 0,
1587 sizeof(sta->supported_rates));
1588 memcpy(sta->supported_rates, u, ileft);
1589 prism2_check_tx_rates(sta);
1590
1591 u += ileft;
1592 left -= ileft;
1593 }
1594
1595 if (left > 0) {
1596 PDEBUG(DEBUG_AP, "%s: assoc from " MACSTR " with extra"
1597 " data (%d bytes) [",
1598 dev->name, MAC2STR(hdr->addr2), left);
1599 while (left > 0) {
1600 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1601 u++; left--;
1602 }
1603 PDEBUG2(DEBUG_AP, "]\n");
1604 }
1605 } else {
1606 txt = "frame underflow";
1607 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1608 goto fail;
1609 }
1610
1611 /* get a unique AID */
1612 if (sta->aid > 0)
1613 txt = "OK, old AID";
1614 else {
1615 spin_lock_bh(&local->ap->sta_table_lock);
1616 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1617 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1618 break;
1619 if (sta->aid > MAX_AID_TABLE_SIZE) {
1620 sta->aid = 0;
1621 spin_unlock_bh(&local->ap->sta_table_lock);
1622 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1623 txt = "no room for more AIDs";
1624 } else {
1625 local->ap->sta_aid[sta->aid - 1] = sta;
1626 spin_unlock_bh(&local->ap->sta_table_lock);
1627 txt = "OK, new AID";
1628 }
1629 }
1630
1631 fail:
1632 pos = (u16 *) body;
1633
1634 if (send_deauth) {
1635 *pos = __constant_cpu_to_le16(
1636 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1637 pos++;
1638 } else {
1639 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1640 * values in beacons/probe responses */
1641 /* FIX: how about privacy and WEP? */
1642 /* capability */
1643 *pos = __constant_cpu_to_le16(WLAN_CAPABILITY_ESS);
1644 pos++;
1645
1646 /* status_code */
1647 *pos = __cpu_to_le16(resp);
1648 pos++;
1649
1650 *pos = __cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1651 BIT(14) | BIT(15)); /* AID */
1652 pos++;
1653
1654 /* Supported rates (Information element) */
1655 p = (char *) pos;
1656 *p++ = WLAN_EID_SUPP_RATES;
1657 lpos = p;
1658 *p++ = 0; /* len */
1659 if (local->tx_rate_control & WLAN_RATE_1M) {
1660 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1661 (*lpos)++;
1662 }
1663 if (local->tx_rate_control & WLAN_RATE_2M) {
1664 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1665 (*lpos)++;
1666 }
1667 if (local->tx_rate_control & WLAN_RATE_5M5) {
1668 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1669 0x8b : 0x0b;
1670 (*lpos)++;
1671 }
1672 if (local->tx_rate_control & WLAN_RATE_11M) {
1673 *p++ = local->basic_rates & WLAN_RATE_11M ?
1674 0x96 : 0x16;
1675 (*lpos)++;
1676 }
1677 pos = (u16 *) p;
1678 }
1679
Jouni Malinen4339d322005-08-14 19:08:44 -07001680 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1681 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1682 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1683 IEEE80211_STYPE_ASSOC_RESP)),
Jouni Malinenff1d2762005-05-12 22:54:16 -04001684 body, (u8 *) pos - (u8 *) body,
1685 hdr->addr2,
1686 send_deauth ? 0 : local->ap->tx_callback_assoc);
1687
1688 if (sta) {
1689 if (resp == WLAN_STATUS_SUCCESS) {
1690 sta->last_rx = jiffies;
1691 /* STA will be marked associated from TX callback, if
1692 * AssocResp is ACKed */
1693 }
1694 atomic_dec(&sta->users);
1695 }
1696
1697#if 0
1698 PDEBUG(DEBUG_AP, "%s: " MACSTR " %sassoc (len=%d prev_ap=" MACSTR
1699 ") => %d(%d) (%s)\n",
1700 dev->name, MAC2STR(hdr->addr2), reassoc ? "re" : "", len,
1701 MAC2STR(prev_ap), resp, send_deauth, txt);
1702#endif
1703}
1704
1705
1706/* Called only as a scheduled task for pending AP frames. */
1707static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1708 struct hostap_80211_rx_status *rx_stats)
1709{
1710 struct net_device *dev = local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -05001711 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001712 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1713 int len;
1714 u16 reason_code, *pos;
1715 struct sta_info *sta = NULL;
1716
1717 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1718
1719 if (len < 2) {
1720 printk("handle_deauth - too short payload (len=%d)\n", len);
1721 return;
1722 }
1723
1724 pos = (u16 *) body;
1725 reason_code = __le16_to_cpu(*pos);
1726
1727 PDEBUG(DEBUG_AP, "%s: deauthentication: " MACSTR " len=%d, "
1728 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1729 reason_code);
1730
1731 spin_lock_bh(&local->ap->sta_table_lock);
1732 sta = ap_get_sta(local->ap, hdr->addr2);
1733 if (sta != NULL) {
1734 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1735 hostap_event_expired_sta(local->dev, sta);
1736 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1737 }
1738 spin_unlock_bh(&local->ap->sta_table_lock);
1739 if (sta == NULL) {
1740 printk("%s: deauthentication from " MACSTR ", "
1741 "reason_code=%d, but STA not authenticated\n", dev->name,
1742 MAC2STR(hdr->addr2), reason_code);
1743 }
1744}
1745
1746
1747/* Called only as a scheduled task for pending AP frames. */
1748static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1749 struct hostap_80211_rx_status *rx_stats)
1750{
1751 struct net_device *dev = local->dev;
James Ketrenosd0416742005-09-21 12:23:49 -05001752 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001753 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1754 int len;
1755 u16 reason_code, *pos;
1756 struct sta_info *sta = NULL;
1757
1758 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1759
1760 if (len < 2) {
1761 printk("handle_disassoc - too short payload (len=%d)\n", len);
1762 return;
1763 }
1764
1765 pos = (u16 *) body;
1766 reason_code = __le16_to_cpu(*pos);
1767
1768 PDEBUG(DEBUG_AP, "%s: disassociation: " MACSTR " len=%d, "
1769 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1770 reason_code);
1771
1772 spin_lock_bh(&local->ap->sta_table_lock);
1773 sta = ap_get_sta(local->ap, hdr->addr2);
1774 if (sta != NULL) {
1775 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1776 hostap_event_expired_sta(local->dev, sta);
1777 sta->flags &= ~WLAN_STA_ASSOC;
1778 }
1779 spin_unlock_bh(&local->ap->sta_table_lock);
1780 if (sta == NULL) {
1781 printk("%s: disassociation from " MACSTR ", "
1782 "reason_code=%d, but STA not authenticated\n",
1783 dev->name, MAC2STR(hdr->addr2), reason_code);
1784 }
1785}
1786
1787
1788/* Called only as a scheduled task for pending AP frames. */
1789static void ap_handle_data_nullfunc(local_info_t *local,
James Ketrenosd0416742005-09-21 12:23:49 -05001790 struct ieee80211_hdr_4addr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001791{
1792 struct net_device *dev = local->dev;
1793
1794 /* some STA f/w's seem to require control::ACK frame for
1795 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1796 * not send this..
1797 * send control::ACK for the data::nullfunc */
1798
1799 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
Jouni Malinen4339d322005-08-14 19:08:44 -07001800 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001801 NULL, 0, hdr->addr2, 0);
1802}
1803
1804
1805/* Called only as a scheduled task for pending AP frames. */
1806static void ap_handle_dropped_data(local_info_t *local,
James Ketrenosd0416742005-09-21 12:23:49 -05001807 struct ieee80211_hdr_4addr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001808{
1809 struct net_device *dev = local->dev;
1810 struct sta_info *sta;
1811 u16 reason;
1812
1813 spin_lock_bh(&local->ap->sta_table_lock);
1814 sta = ap_get_sta(local->ap, hdr->addr2);
1815 if (sta)
1816 atomic_inc(&sta->users);
1817 spin_unlock_bh(&local->ap->sta_table_lock);
1818
1819 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1820 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1821 atomic_dec(&sta->users);
1822 return;
1823 }
1824
1825 reason = __constant_cpu_to_le16(
1826 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
Jouni Malinen4339d322005-08-14 19:08:44 -07001827 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
Jouni Malinenff1d2762005-05-12 22:54:16 -04001828 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
Jouni Malinen4339d322005-08-14 19:08:44 -07001829 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
Jouni Malinenff1d2762005-05-12 22:54:16 -04001830 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1831
1832 if (sta)
1833 atomic_dec(&sta->users);
1834}
1835
1836#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1837
1838
1839/* Called only as a scheduled task for pending AP frames. */
1840static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1841 struct sk_buff *skb)
1842{
Jouni Malinen5bee7202005-08-14 19:08:39 -07001843 struct hostap_skb_tx_data *meta;
1844
Jouni Malinenff1d2762005-05-12 22:54:16 -04001845 if (!(sta->flags & WLAN_STA_PS)) {
1846 /* Station has moved to non-PS mode, so send all buffered
1847 * frames using normal device queue. */
1848 dev_queue_xmit(skb);
1849 return;
1850 }
1851
1852 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1853 * be passed through even though STA is using PS */
Jouni Malinen5bee7202005-08-14 19:08:39 -07001854 meta = (struct hostap_skb_tx_data *) skb->cb;
1855 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001856 if (!skb_queue_empty(&sta->tx_buf)) {
1857 /* indicate to STA that more frames follow */
Jouni Malinen5bee7202005-08-14 19:08:39 -07001858 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001859 }
1860 dev_queue_xmit(skb);
1861}
1862
1863
1864/* Called only as a scheduled task for pending AP frames. */
1865static void handle_pspoll(local_info_t *local,
James Ketrenosd0416742005-09-21 12:23:49 -05001866 struct ieee80211_hdr_4addr *hdr,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001867 struct hostap_80211_rx_status *rx_stats)
1868{
1869 struct net_device *dev = local->dev;
1870 struct sta_info *sta;
1871 u16 aid;
1872 struct sk_buff *skb;
1873
1874 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=" MACSTR ", TA=" MACSTR
1875 " PWRMGT=%d\n",
1876 MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07001877 !!(le16_to_cpu(hdr->frame_ctl) & IEEE80211_FCTL_PM));
Jouni Malinenff1d2762005-05-12 22:54:16 -04001878
1879 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
1880 PDEBUG(DEBUG_AP, "handle_pspoll - addr1(BSSID)=" MACSTR
1881 " not own MAC\n", MAC2STR(hdr->addr1));
1882 return;
1883 }
1884
1885 aid = __le16_to_cpu(hdr->duration_id);
1886 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1887 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1888 return;
1889 }
1890 aid &= ~BIT(15) & ~BIT(14);
1891 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1892 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1893 return;
1894 }
1895 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1896
1897 spin_lock_bh(&local->ap->sta_table_lock);
1898 sta = ap_get_sta(local->ap, hdr->addr2);
1899 if (sta)
1900 atomic_inc(&sta->users);
1901 spin_unlock_bh(&local->ap->sta_table_lock);
1902
1903 if (sta == NULL) {
1904 PDEBUG(DEBUG_PS, " STA not found\n");
1905 return;
1906 }
1907 if (sta->aid != aid) {
1908 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1909 "assoc.aid=%d\n", aid, sta->aid);
1910 return;
1911 }
1912
1913 /* FIX: todo:
1914 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1915 * out (expiry time must be longer than ListenInterval for
1916 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1917 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1918 * sta; store buffer for later use and leave TIM aid bit set? use
1919 * TX event to check whether frame was ACKed?
1920 */
1921
1922 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1923 /* send buffered frame .. */
1924 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1925 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1926
1927 pspoll_send_buffered(local, sta, skb);
1928
1929 if (sta->flags & WLAN_STA_PS) {
1930 /* send only one buffered packet per PS Poll */
1931 /* FIX: should ignore further PS Polls until the
1932 * buffered packet that was just sent is acknowledged
1933 * (Tx or TxExc event) */
1934 break;
1935 }
1936 }
1937
1938 if (skb_queue_empty(&sta->tx_buf)) {
1939 /* try to clear aid from TIM */
1940 if (!(sta->flags & WLAN_STA_TIM))
1941 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1942 aid);
1943 hostap_set_tim(local, aid, 0);
1944 sta->flags &= ~WLAN_STA_TIM;
1945 }
1946
1947 atomic_dec(&sta->users);
1948}
1949
1950
1951#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1952
1953static void handle_wds_oper_queue(void *data)
1954{
1955 local_info_t *local = data;
1956 struct wds_oper_data *entry, *prev;
1957
1958 spin_lock_bh(&local->lock);
1959 entry = local->ap->wds_oper_entries;
1960 local->ap->wds_oper_entries = NULL;
1961 spin_unlock_bh(&local->lock);
1962
1963 while (entry) {
1964 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
1965 "to AP " MACSTR "\n",
1966 local->dev->name,
1967 entry->type == WDS_ADD ? "adding" : "removing",
1968 MAC2STR(entry->addr));
1969 if (entry->type == WDS_ADD)
1970 prism2_wds_add(local, entry->addr, 0);
1971 else if (entry->type == WDS_DEL)
1972 prism2_wds_del(local, entry->addr, 0, 1);
1973
1974 prev = entry;
1975 entry = entry->next;
1976 kfree(prev);
1977 }
1978}
1979
1980
1981/* Called only as a scheduled task for pending AP frames. */
1982static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1983 struct hostap_80211_rx_status *rx_stats)
1984{
James Ketrenosd0416742005-09-21 12:23:49 -05001985 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001986 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1987 int len, left;
1988 u16 *pos, beacon_int, capability;
1989 char *ssid = NULL;
1990 unsigned char *supp_rates = NULL;
1991 int ssid_len = 0, supp_rates_len = 0;
1992 struct sta_info *sta = NULL;
1993 int new_sta = 0, channel = -1;
1994
1995 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1996
1997 if (len < 8 + 2 + 2) {
1998 printk(KERN_DEBUG "handle_beacon - too short payload "
1999 "(len=%d)\n", len);
2000 return;
2001 }
2002
2003 pos = (u16 *) body;
2004 left = len;
2005
2006 /* Timestamp (8 octets) */
2007 pos += 4; left -= 8;
2008 /* Beacon interval (2 octets) */
2009 beacon_int = __le16_to_cpu(*pos);
2010 pos++; left -= 2;
2011 /* Capability information (2 octets) */
2012 capability = __le16_to_cpu(*pos);
2013 pos++; left -= 2;
2014
2015 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2016 capability & WLAN_CAPABILITY_IBSS)
2017 return;
2018
2019 if (left >= 2) {
2020 unsigned int ileft;
2021 unsigned char *u = (unsigned char *) pos;
2022
2023 if (*u == WLAN_EID_SSID) {
2024 u++; left--;
2025 ileft = *u;
2026 u++; left--;
2027
2028 if (ileft > left || ileft > MAX_SSID_LEN) {
2029 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2030 return;
2031 }
2032
2033 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2034 (ileft != strlen(local->essid) ||
2035 memcmp(local->essid, u, ileft) != 0)) {
2036 /* not our SSID */
2037 return;
2038 }
2039
2040 ssid = u;
2041 ssid_len = ileft;
2042
2043 u += ileft;
2044 left -= ileft;
2045 }
2046
2047 if (*u == WLAN_EID_SUPP_RATES) {
2048 u++; left--;
2049 ileft = *u;
2050 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04002051
Jouni Malinenff1d2762005-05-12 22:54:16 -04002052 if (ileft > left || ileft == 0 || ileft > 8) {
2053 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2054 return;
2055 }
2056
2057 supp_rates = u;
2058 supp_rates_len = ileft;
2059
2060 u += ileft;
2061 left -= ileft;
2062 }
2063
2064 if (*u == WLAN_EID_DS_PARAMS) {
2065 u++; left--;
2066 ileft = *u;
2067 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04002068
Jouni Malinenff1d2762005-05-12 22:54:16 -04002069 if (ileft > left || ileft != 1) {
2070 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2071 return;
2072 }
2073
2074 channel = *u;
2075
2076 u += ileft;
2077 left -= ileft;
2078 }
2079 }
2080
2081 spin_lock_bh(&local->ap->sta_table_lock);
2082 sta = ap_get_sta(local->ap, hdr->addr2);
2083 if (sta != NULL)
2084 atomic_inc(&sta->users);
2085 spin_unlock_bh(&local->ap->sta_table_lock);
2086
2087 if (sta == NULL) {
2088 /* add new AP */
2089 new_sta = 1;
2090 sta = ap_add_sta(local->ap, hdr->addr2);
2091 if (sta == NULL) {
2092 printk(KERN_INFO "prism2: kmalloc failed for AP "
2093 "data structure\n");
2094 return;
2095 }
2096 hostap_event_new_sta(local->dev, sta);
2097
2098 /* mark APs authentication and associated for pseudo ad-hoc
2099 * style communication */
2100 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2101
2102 if (local->ap->autom_ap_wds) {
2103 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2104 }
2105 }
2106
2107 sta->ap = 1;
2108 if (ssid) {
2109 sta->u.ap.ssid_len = ssid_len;
2110 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2111 sta->u.ap.ssid[ssid_len] = '\0';
2112 } else {
2113 sta->u.ap.ssid_len = 0;
2114 sta->u.ap.ssid[0] = '\0';
2115 }
2116 sta->u.ap.channel = channel;
2117 sta->rx_packets++;
2118 sta->rx_bytes += len;
2119 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2120 sta->capability = capability;
2121 sta->listen_interval = beacon_int;
2122
2123 atomic_dec(&sta->users);
2124
2125 if (new_sta) {
2126 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2127 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2128 prism2_check_tx_rates(sta);
2129 }
2130}
2131
2132#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2133
2134
2135/* Called only as a tasklet. */
2136static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2137 struct hostap_80211_rx_status *rx_stats)
2138{
2139#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2140 struct net_device *dev = local->dev;
2141#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2142 u16 fc, type, stype;
James Ketrenosd0416742005-09-21 12:23:49 -05002143 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002144
2145 /* FIX: should give skb->len to handler functions and check that the
2146 * buffer is long enough */
James Ketrenosd0416742005-09-21 12:23:49 -05002147 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002148 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinen4339d322005-08-14 19:08:44 -07002149 type = WLAN_FC_GET_TYPE(fc);
2150 stype = WLAN_FC_GET_STYPE(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002151
2152#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinen4339d322005-08-14 19:08:44 -07002153 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002154 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2155
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002156 if (!(fc & IEEE80211_FCTL_TODS) ||
2157 (fc & IEEE80211_FCTL_FROMDS)) {
Jouni Malinen4339d322005-08-14 19:08:44 -07002158 if (stype == IEEE80211_STYPE_NULLFUNC) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002159 /* no ToDS nullfunc seems to be used to check
2160 * AP association; so send reject message to
2161 * speed up re-association */
2162 ap_handle_dropped_data(local, hdr);
2163 goto done;
2164 }
2165 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2166 fc);
2167 goto done;
2168 }
2169
2170 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2171 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)="
2172 MACSTR " not own MAC\n",
2173 MAC2STR(hdr->addr1));
2174 goto done;
2175 }
2176
Jouni Malinen4339d322005-08-14 19:08:44 -07002177 if (local->ap->nullfunc_ack &&
2178 stype == IEEE80211_STYPE_NULLFUNC)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002179 ap_handle_data_nullfunc(local, hdr);
2180 else
2181 ap_handle_dropped_data(local, hdr);
2182 goto done;
2183 }
2184
Jouni Malinen4339d322005-08-14 19:08:44 -07002185 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002186 handle_beacon(local, skb, rx_stats);
2187 goto done;
2188 }
2189#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2190
Jouni Malinen4339d322005-08-14 19:08:44 -07002191 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002192 handle_pspoll(local, hdr, rx_stats);
2193 goto done;
2194 }
2195
2196 if (local->hostapd) {
2197 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2198 "subtype=0x%02x\n", type, stype);
2199 goto done;
2200 }
2201
2202#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinen4339d322005-08-14 19:08:44 -07002203 if (type != IEEE80211_FTYPE_MGMT) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002204 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2205 goto done;
2206 }
2207
2208 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2209 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=" MACSTR
2210 " not own MAC\n", MAC2STR(hdr->addr1));
2211 goto done;
2212 }
2213
2214 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
2215 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=" MACSTR
2216 " not own MAC\n", MAC2STR(hdr->addr3));
2217 goto done;
2218 }
2219
2220 switch (stype) {
Jouni Malinen4339d322005-08-14 19:08:44 -07002221 case IEEE80211_STYPE_ASSOC_REQ:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002222 handle_assoc(local, skb, rx_stats, 0);
2223 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002224 case IEEE80211_STYPE_ASSOC_RESP:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002225 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2226 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002227 case IEEE80211_STYPE_REASSOC_REQ:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002228 handle_assoc(local, skb, rx_stats, 1);
2229 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002230 case IEEE80211_STYPE_REASSOC_RESP:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002231 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2232 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002233 case IEEE80211_STYPE_ATIM:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002234 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2235 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002236 case IEEE80211_STYPE_DISASSOC:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002237 handle_disassoc(local, skb, rx_stats);
2238 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002239 case IEEE80211_STYPE_AUTH:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002240 handle_authen(local, skb, rx_stats);
2241 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002242 case IEEE80211_STYPE_DEAUTH:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002243 handle_deauth(local, skb, rx_stats);
2244 break;
2245 default:
Jouni Malinen4339d322005-08-14 19:08:44 -07002246 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2247 stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002248 break;
2249 }
2250#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2251
2252 done:
2253 dev_kfree_skb(skb);
2254}
2255
2256
2257/* Called only as a tasklet (software IRQ) */
2258void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2259 struct hostap_80211_rx_status *rx_stats)
2260{
2261 struct hostap_interface *iface;
2262 local_info_t *local;
2263 u16 fc;
James Ketrenosd0416742005-09-21 12:23:49 -05002264 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002265
2266 iface = netdev_priv(dev);
2267 local = iface->local;
2268
2269 if (skb->len < 16)
2270 goto drop;
2271
2272 local->stats.rx_packets++;
2273
James Ketrenosd0416742005-09-21 12:23:49 -05002274 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002275 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002276
2277 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
Jouni Malinen4339d322005-08-14 19:08:44 -07002278 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_MGMT &&
2279 WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_BEACON)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002280 goto drop;
2281
2282 skb->protocol = __constant_htons(ETH_P_HOSTAP);
2283 handle_ap_item(local, skb, rx_stats);
2284 return;
2285
2286 drop:
2287 dev_kfree_skb(skb);
2288}
2289
2290
2291/* Called only as a tasklet (software IRQ) */
2292static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2293{
2294 struct sk_buff *skb;
James Ketrenosd0416742005-09-21 12:23:49 -05002295 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002296 struct hostap_80211_rx_status rx_stats;
2297
2298 if (skb_queue_empty(&sta->tx_buf))
2299 return;
2300
2301 skb = dev_alloc_skb(16);
2302 if (skb == NULL) {
2303 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2304 "failed\n", local->dev->name);
2305 return;
2306 }
2307
James Ketrenosd0416742005-09-21 12:23:49 -05002308 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, 16);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002309
2310 /* Generate a fake pspoll frame to start packet delivery */
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002311 hdr->frame_ctl = __constant_cpu_to_le16(
Jouni Malinen4339d322005-08-14 19:08:44 -07002312 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002313 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2314 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2315 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2316
2317 PDEBUG(DEBUG_PS2, "%s: Scheduling buffered packet delivery for "
2318 "STA " MACSTR "\n", local->dev->name, MAC2STR(sta->addr));
2319
2320 skb->dev = local->dev;
2321
2322 memset(&rx_stats, 0, sizeof(rx_stats));
2323 hostap_rx(local->dev, skb, &rx_stats);
2324}
2325
2326
Adrian Bunk5fad5a22006-01-14 03:09:34 +01002327int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2328 struct iw_quality qual[], int buf_size,
2329 int aplist)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002330{
2331 struct ap_data *ap = local->ap;
2332 struct list_head *ptr;
2333 int count = 0;
2334
2335 spin_lock_bh(&ap->sta_table_lock);
2336
2337 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2338 ptr = ptr->next) {
2339 struct sta_info *sta = (struct sta_info *) ptr;
2340
2341 if (aplist && !sta->ap)
2342 continue;
2343 addr[count].sa_family = ARPHRD_ETHER;
2344 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2345 if (sta->last_rx_silence == 0)
2346 qual[count].qual = sta->last_rx_signal < 27 ?
2347 0 : (sta->last_rx_signal - 27) * 92 / 127;
2348 else
2349 qual[count].qual = sta->last_rx_signal -
2350 sta->last_rx_silence - 35;
2351 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2352 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2353 qual[count].updated = sta->last_rx_updated;
2354
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07002355 sta->last_rx_updated = IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002356
2357 count++;
2358 if (count >= buf_size)
2359 break;
2360 }
2361 spin_unlock_bh(&ap->sta_table_lock);
2362
2363 return count;
2364}
2365
2366
2367/* Translate our list of Access Points & Stations to a card independant
2368 * format that the Wireless Tools will understand - Jean II */
Adrian Bunk5fad5a22006-01-14 03:09:34 +01002369int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002370{
2371 struct hostap_interface *iface;
2372 local_info_t *local;
2373 struct ap_data *ap;
2374 struct list_head *ptr;
2375 struct iw_event iwe;
2376 char *current_ev = buffer;
2377 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2378#if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2379 char buf[64];
2380#endif
2381
2382 iface = netdev_priv(dev);
2383 local = iface->local;
2384 ap = local->ap;
2385
2386 spin_lock_bh(&ap->sta_table_lock);
2387
2388 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2389 ptr = ptr->next) {
2390 struct sta_info *sta = (struct sta_info *) ptr;
2391
2392 /* First entry *MUST* be the AP MAC address */
2393 memset(&iwe, 0, sizeof(iwe));
2394 iwe.cmd = SIOCGIWAP;
2395 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2396 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2397 iwe.len = IW_EV_ADDR_LEN;
2398 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2399 IW_EV_ADDR_LEN);
2400
2401 /* Use the mode to indicate if it's a station or
2402 * an Access Point */
2403 memset(&iwe, 0, sizeof(iwe));
2404 iwe.cmd = SIOCGIWMODE;
2405 if (sta->ap)
2406 iwe.u.mode = IW_MODE_MASTER;
2407 else
2408 iwe.u.mode = IW_MODE_INFRA;
2409 iwe.len = IW_EV_UINT_LEN;
2410 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2411 IW_EV_UINT_LEN);
2412
2413 /* Some quality */
2414 memset(&iwe, 0, sizeof(iwe));
2415 iwe.cmd = IWEVQUAL;
2416 if (sta->last_rx_silence == 0)
2417 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2418 0 : (sta->last_rx_signal - 27) * 92 / 127;
2419 else
2420 iwe.u.qual.qual = sta->last_rx_signal -
2421 sta->last_rx_silence - 35;
2422 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2423 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2424 iwe.u.qual.updated = sta->last_rx_updated;
2425 iwe.len = IW_EV_QUAL_LEN;
2426 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2427 IW_EV_QUAL_LEN);
2428
2429#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2430 if (sta->ap) {
2431 memset(&iwe, 0, sizeof(iwe));
2432 iwe.cmd = SIOCGIWESSID;
2433 iwe.u.data.length = sta->u.ap.ssid_len;
2434 iwe.u.data.flags = 1;
2435 current_ev = iwe_stream_add_point(current_ev, end_buf,
2436 &iwe,
2437 sta->u.ap.ssid);
2438
2439 memset(&iwe, 0, sizeof(iwe));
2440 iwe.cmd = SIOCGIWENCODE;
2441 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2442 iwe.u.data.flags =
2443 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2444 else
2445 iwe.u.data.flags = IW_ENCODE_DISABLED;
2446 current_ev = iwe_stream_add_point(current_ev, end_buf,
2447 &iwe,
2448 sta->u.ap.ssid
2449 /* 0 byte memcpy */);
2450
2451 if (sta->u.ap.channel > 0 &&
2452 sta->u.ap.channel <= FREQ_COUNT) {
2453 memset(&iwe, 0, sizeof(iwe));
2454 iwe.cmd = SIOCGIWFREQ;
2455 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2456 * 100000;
2457 iwe.u.freq.e = 1;
2458 current_ev = iwe_stream_add_event(
2459 current_ev, end_buf, &iwe,
2460 IW_EV_FREQ_LEN);
2461 }
2462
2463 memset(&iwe, 0, sizeof(iwe));
2464 iwe.cmd = IWEVCUSTOM;
2465 sprintf(buf, "beacon_interval=%d",
2466 sta->listen_interval);
2467 iwe.u.data.length = strlen(buf);
2468 current_ev = iwe_stream_add_point(current_ev, end_buf,
2469 &iwe, buf);
2470 }
2471#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2472
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07002473 sta->last_rx_updated = IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002474
2475 /* To be continued, we should make good use of IWEVCUSTOM */
2476 }
2477
2478 spin_unlock_bh(&ap->sta_table_lock);
2479
2480 return current_ev - buffer;
2481}
2482
2483
2484static int prism2_hostapd_add_sta(struct ap_data *ap,
2485 struct prism2_hostapd_param *param)
2486{
2487 struct sta_info *sta;
2488
2489 spin_lock_bh(&ap->sta_table_lock);
2490 sta = ap_get_sta(ap, param->sta_addr);
2491 if (sta)
2492 atomic_inc(&sta->users);
2493 spin_unlock_bh(&ap->sta_table_lock);
2494
2495 if (sta == NULL) {
2496 sta = ap_add_sta(ap, param->sta_addr);
2497 if (sta == NULL)
2498 return -1;
2499 }
2500
2501 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2502 hostap_event_new_sta(sta->local->dev, sta);
2503
2504 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2505 sta->last_rx = jiffies;
2506 sta->aid = param->u.add_sta.aid;
2507 sta->capability = param->u.add_sta.capability;
2508 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2509 if (sta->tx_supp_rates & WLAN_RATE_1M)
2510 sta->supported_rates[0] = 2;
2511 if (sta->tx_supp_rates & WLAN_RATE_2M)
2512 sta->supported_rates[1] = 4;
2513 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2514 sta->supported_rates[2] = 11;
2515 if (sta->tx_supp_rates & WLAN_RATE_11M)
2516 sta->supported_rates[3] = 22;
2517 prism2_check_tx_rates(sta);
2518 atomic_dec(&sta->users);
2519 return 0;
2520}
2521
2522
2523static int prism2_hostapd_remove_sta(struct ap_data *ap,
2524 struct prism2_hostapd_param *param)
2525{
2526 struct sta_info *sta;
2527
2528 spin_lock_bh(&ap->sta_table_lock);
2529 sta = ap_get_sta(ap, param->sta_addr);
2530 if (sta) {
2531 ap_sta_hash_del(ap, sta);
2532 list_del(&sta->list);
2533 }
2534 spin_unlock_bh(&ap->sta_table_lock);
2535
2536 if (!sta)
2537 return -ENOENT;
2538
2539 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2540 hostap_event_expired_sta(sta->local->dev, sta);
2541 ap_free_sta(ap, sta);
2542
2543 return 0;
2544}
2545
2546
2547static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2548 struct prism2_hostapd_param *param)
2549{
2550 struct sta_info *sta;
2551
2552 spin_lock_bh(&ap->sta_table_lock);
2553 sta = ap_get_sta(ap, param->sta_addr);
2554 if (sta)
2555 atomic_inc(&sta->users);
2556 spin_unlock_bh(&ap->sta_table_lock);
2557
2558 if (!sta)
2559 return -ENOENT;
2560
2561 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2562
2563 atomic_dec(&sta->users);
2564
2565 return 1;
2566}
2567
2568
2569static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2570 struct prism2_hostapd_param *param)
2571{
2572 struct sta_info *sta;
2573
2574 spin_lock_bh(&ap->sta_table_lock);
2575 sta = ap_get_sta(ap, param->sta_addr);
2576 if (sta) {
2577 sta->flags |= param->u.set_flags_sta.flags_or;
2578 sta->flags &= param->u.set_flags_sta.flags_and;
2579 }
2580 spin_unlock_bh(&ap->sta_table_lock);
2581
2582 if (!sta)
2583 return -ENOENT;
2584
2585 return 0;
2586}
2587
2588
2589static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2590 struct prism2_hostapd_param *param)
2591{
2592 struct sta_info *sta;
2593 int rate;
2594
2595 spin_lock_bh(&ap->sta_table_lock);
2596 sta = ap_get_sta(ap, param->sta_addr);
2597 if (sta) {
2598 sta->rx_packets = sta->tx_packets = 0;
2599 sta->rx_bytes = sta->tx_bytes = 0;
2600 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2601 sta->tx_count[rate] = 0;
2602 sta->rx_count[rate] = 0;
2603 }
2604 }
2605 spin_unlock_bh(&ap->sta_table_lock);
2606
2607 if (!sta)
2608 return -ENOENT;
2609
2610 return 0;
2611}
2612
2613
Adrian Bunk5fad5a22006-01-14 03:09:34 +01002614int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002615{
2616 switch (param->cmd) {
2617 case PRISM2_HOSTAPD_FLUSH:
2618 ap_control_kickall(ap);
2619 return 0;
2620 case PRISM2_HOSTAPD_ADD_STA:
2621 return prism2_hostapd_add_sta(ap, param);
2622 case PRISM2_HOSTAPD_REMOVE_STA:
2623 return prism2_hostapd_remove_sta(ap, param);
2624 case PRISM2_HOSTAPD_GET_INFO_STA:
2625 return prism2_hostapd_get_info_sta(ap, param);
2626 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2627 return prism2_hostapd_set_flags_sta(ap, param);
2628 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2629 return prism2_hostapd_sta_clear_stats(ap, param);
2630 default:
2631 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2632 param->cmd);
2633 return -EOPNOTSUPP;
2634 }
2635}
2636
2637
2638/* Update station info for host-based TX rate control and return current
2639 * TX rate */
2640static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2641{
2642 int ret = sta->tx_rate;
2643 struct hostap_interface *iface;
2644 local_info_t *local;
2645
2646 iface = netdev_priv(dev);
2647 local = iface->local;
2648
2649 sta->tx_count[sta->tx_rate_idx]++;
2650 sta->tx_since_last_failure++;
2651 sta->tx_consecutive_exc = 0;
2652 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2653 sta->tx_rate_idx < sta->tx_max_rate) {
2654 /* use next higher rate */
2655 int old_rate, new_rate;
2656 old_rate = new_rate = sta->tx_rate_idx;
2657 while (new_rate < sta->tx_max_rate) {
2658 new_rate++;
2659 if (ap_tx_rate_ok(new_rate, sta, local)) {
2660 sta->tx_rate_idx = new_rate;
2661 break;
2662 }
2663 }
2664 if (old_rate != sta->tx_rate_idx) {
2665 switch (sta->tx_rate_idx) {
2666 case 0: sta->tx_rate = 10; break;
2667 case 1: sta->tx_rate = 20; break;
2668 case 2: sta->tx_rate = 55; break;
2669 case 3: sta->tx_rate = 110; break;
2670 default: sta->tx_rate = 0; break;
2671 }
2672 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate raised to"
2673 " %d\n", dev->name, MAC2STR(sta->addr),
2674 sta->tx_rate);
2675 }
2676 sta->tx_since_last_failure = 0;
2677 }
2678
2679 return ret;
2680}
2681
2682
2683/* Called only from software IRQ. Called for each TX frame prior possible
2684 * encryption and transmit. */
2685ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2686{
2687 struct sta_info *sta = NULL;
2688 struct sk_buff *skb = tx->skb;
2689 int set_tim, ret;
James Ketrenosd0416742005-09-21 12:23:49 -05002690 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002691 struct hostap_skb_tx_data *meta;
2692
2693 meta = (struct hostap_skb_tx_data *) skb->cb;
2694 ret = AP_TX_CONTINUE;
2695 if (local->ap == NULL || skb->len < 10 ||
2696 meta->iface->type == HOSTAP_INTERFACE_STA)
2697 goto out;
2698
James Ketrenosd0416742005-09-21 12:23:49 -05002699 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002700
2701 if (hdr->addr1[0] & 0x01) {
2702 /* broadcast/multicast frame - no AP related processing */
2703 goto out;
2704 }
2705
2706 /* unicast packet - check whether destination STA is associated */
2707 spin_lock(&local->ap->sta_table_lock);
2708 sta = ap_get_sta(local->ap, hdr->addr1);
2709 if (sta)
2710 atomic_inc(&sta->users);
2711 spin_unlock(&local->ap->sta_table_lock);
2712
Jouni Malinen5bee7202005-08-14 19:08:39 -07002713 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2714 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -04002715 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2716 meta->iface->type != HOSTAP_INTERFACE_AP) {
2717#if 0
2718 /* This can happen, e.g., when wlan0 is added to a bridge and
2719 * bridging code does not know which port is the correct target
2720 * for a unicast frame. In this case, the packet is send to all
2721 * ports of the bridge. Since this is a valid scenario, do not
2722 * print out any errors here. */
2723 if (net_ratelimit()) {
2724 printk(KERN_DEBUG "AP: drop packet to non-associated "
2725 "STA " MACSTR "\n", MAC2STR(hdr->addr1));
2726 }
2727#endif
2728 local->ap->tx_drop_nonassoc++;
2729 ret = AP_TX_DROP;
2730 goto out;
2731 }
2732
2733 if (sta == NULL)
2734 goto out;
2735
2736 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2737 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2738
2739 /* Set tx_rate if using host-based TX rate control */
2740 if (!local->fw_tx_rate_control)
2741 local->ap->last_tx_rate = meta->rate =
2742 ap_update_sta_tx_rate(sta, local->dev);
2743
2744 if (local->iw_mode != IW_MODE_MASTER)
2745 goto out;
2746
2747 if (!(sta->flags & WLAN_STA_PS))
2748 goto out;
2749
Jouni Malinen5bee7202005-08-14 19:08:39 -07002750 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2751 /* indicate to STA that more frames follow */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002752 hdr->frame_ctl |=
2753 __constant_cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Jouni Malinen5bee7202005-08-14 19:08:39 -07002754 }
Jouni Malinenff1d2762005-05-12 22:54:16 -04002755
Jouni Malinen5bee7202005-08-14 19:08:39 -07002756 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2757 /* packet was already buffered and now send due to
2758 * PS poll, so do not rebuffer it */
2759 goto out;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002760 }
2761
2762 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2763 PDEBUG(DEBUG_PS, "%s: No more space in STA (" MACSTR ")'s PS "
2764 "mode buffer\n", local->dev->name, MAC2STR(sta->addr));
2765 /* Make sure that TIM is set for the station (it might not be
2766 * after AP wlan hw reset). */
2767 /* FIX: should fix hw reset to restore bits based on STA
2768 * buffer state.. */
2769 hostap_set_tim(local, sta->aid, 1);
2770 sta->flags |= WLAN_STA_TIM;
2771 ret = AP_TX_DROP;
2772 goto out;
2773 }
2774
2775 /* STA in PS mode, buffer frame for later delivery */
2776 set_tim = skb_queue_empty(&sta->tx_buf);
2777 skb_queue_tail(&sta->tx_buf, skb);
2778 /* FIX: could save RX time to skb and expire buffered frames after
2779 * some time if STA does not poll for them */
2780
2781 if (set_tim) {
2782 if (sta->flags & WLAN_STA_TIM)
2783 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2784 sta->aid);
2785 hostap_set_tim(local, sta->aid, 1);
2786 sta->flags |= WLAN_STA_TIM;
2787 }
2788
2789 ret = AP_TX_BUFFERED;
2790
2791 out:
2792 if (sta != NULL) {
2793 if (ret == AP_TX_CONTINUE ||
2794 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2795 sta->tx_packets++;
2796 sta->tx_bytes += skb->len;
2797 sta->last_tx = jiffies;
2798 }
2799
2800 if ((ret == AP_TX_CONTINUE ||
2801 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2802 sta->crypt && tx->host_encrypt) {
2803 tx->crypt = sta->crypt;
2804 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2805 * be called to release sta info
2806 * later */
2807 } else
2808 atomic_dec(&sta->users);
2809 }
2810
2811 return ret;
2812}
2813
2814
2815void hostap_handle_sta_release(void *ptr)
2816{
2817 struct sta_info *sta = ptr;
2818 atomic_dec(&sta->users);
2819}
2820
2821
2822/* Called only as a tasklet (software IRQ) */
2823void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2824{
2825 struct sta_info *sta;
James Ketrenosd0416742005-09-21 12:23:49 -05002826 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002827 struct hostap_skb_tx_data *meta;
2828
James Ketrenosd0416742005-09-21 12:23:49 -05002829 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002830 meta = (struct hostap_skb_tx_data *) skb->cb;
2831
2832 spin_lock(&local->ap->sta_table_lock);
2833 sta = ap_get_sta(local->ap, hdr->addr1);
2834 if (!sta) {
2835 spin_unlock(&local->ap->sta_table_lock);
2836 PDEBUG(DEBUG_AP, "%s: Could not find STA " MACSTR " for this "
2837 "TX error (@%lu)\n",
2838 local->dev->name, MAC2STR(hdr->addr1), jiffies);
2839 return;
2840 }
2841
2842 sta->tx_since_last_failure = 0;
2843 sta->tx_consecutive_exc++;
Jeff Garzik74fae822005-07-31 13:08:32 -04002844
Jouni Malinenff1d2762005-05-12 22:54:16 -04002845 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2846 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2847 /* use next lower rate */
2848 int old, rate;
2849 old = rate = sta->tx_rate_idx;
2850 while (rate > 0) {
2851 rate--;
2852 if (ap_tx_rate_ok(rate, sta, local)) {
2853 sta->tx_rate_idx = rate;
2854 break;
2855 }
2856 }
2857 if (old != sta->tx_rate_idx) {
2858 switch (sta->tx_rate_idx) {
2859 case 0: sta->tx_rate = 10; break;
2860 case 1: sta->tx_rate = 20; break;
2861 case 2: sta->tx_rate = 55; break;
2862 case 3: sta->tx_rate = 110; break;
2863 default: sta->tx_rate = 0; break;
2864 }
2865 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate lowered "
2866 "to %d\n", local->dev->name, MAC2STR(sta->addr),
2867 sta->tx_rate);
2868 }
2869 sta->tx_consecutive_exc = 0;
2870 }
2871 spin_unlock(&local->ap->sta_table_lock);
2872}
2873
2874
2875static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2876 int pwrmgt, int type, int stype)
2877{
2878 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2879 sta->flags |= WLAN_STA_PS;
2880 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to use PS "
2881 "mode (type=0x%02X, stype=0x%02X)\n",
Jouni Malinen4339d322005-08-14 19:08:44 -07002882 MAC2STR(sta->addr), type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002883 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2884 sta->flags &= ~WLAN_STA_PS;
2885 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to not use "
2886 "PS mode (type=0x%02X, stype=0x%02X)\n",
Jouni Malinen4339d322005-08-14 19:08:44 -07002887 MAC2STR(sta->addr), type >> 2, stype >> 4);
2888 if (type != IEEE80211_FTYPE_CTL ||
2889 stype != IEEE80211_STYPE_PSPOLL)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002890 schedule_packet_send(local, sta);
2891 }
2892}
2893
2894
2895/* Called only as a tasklet (software IRQ). Called for each RX frame to update
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002896 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
James Ketrenosd0416742005-09-21 12:23:49 -05002897int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002898{
2899 struct sta_info *sta;
2900 u16 fc;
2901
2902 spin_lock(&local->ap->sta_table_lock);
2903 sta = ap_get_sta(local->ap, hdr->addr2);
2904 if (sta)
2905 atomic_inc(&sta->users);
2906 spin_unlock(&local->ap->sta_table_lock);
2907
2908 if (!sta)
2909 return -1;
2910
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002911 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002912 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
Jouni Malinen4339d322005-08-14 19:08:44 -07002913 WLAN_FC_GET_TYPE(fc), WLAN_FC_GET_STYPE(fc));
Jouni Malinenff1d2762005-05-12 22:54:16 -04002914
2915 atomic_dec(&sta->users);
2916 return 0;
2917}
2918
2919
2920/* Called only as a tasklet (software IRQ). Called for each RX frame after
2921 * getting RX header and payload from hardware. */
2922ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2923 struct sk_buff *skb,
2924 struct hostap_80211_rx_status *rx_stats,
2925 int wds)
2926{
2927 int ret;
2928 struct sta_info *sta;
2929 u16 fc, type, stype;
James Ketrenosd0416742005-09-21 12:23:49 -05002930 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002931
2932 if (local->ap == NULL)
2933 return AP_RX_CONTINUE;
2934
James Ketrenosd0416742005-09-21 12:23:49 -05002935 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002936
Jouni Malinenc0f72ca2005-08-14 19:08:43 -07002937 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinen4339d322005-08-14 19:08:44 -07002938 type = WLAN_FC_GET_TYPE(fc);
2939 stype = WLAN_FC_GET_STYPE(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002940
2941 spin_lock(&local->ap->sta_table_lock);
2942 sta = ap_get_sta(local->ap, hdr->addr2);
2943 if (sta)
2944 atomic_inc(&sta->users);
2945 spin_unlock(&local->ap->sta_table_lock);
2946
2947 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2948 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2949 else
2950 ret = AP_RX_CONTINUE;
2951
2952
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002953 if (fc & IEEE80211_FCTL_TODS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002954 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2955 if (local->hostapd) {
2956 prism2_rx_80211(local->apdev, skb, rx_stats,
2957 PRISM2_RX_NON_ASSOC);
2958#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2959 } else {
2960 printk(KERN_DEBUG "%s: dropped received packet"
2961 " from non-associated STA " MACSTR
2962 " (type=0x%02x, subtype=0x%02x)\n",
Jouni Malinen4339d322005-08-14 19:08:44 -07002963 dev->name, MAC2STR(hdr->addr2),
2964 type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002965 hostap_rx(dev, skb, rx_stats);
2966#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2967 }
2968 ret = AP_RX_EXIT;
2969 goto out;
2970 }
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002971 } else if (fc & IEEE80211_FCTL_FROMDS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002972 if (!wds) {
2973 /* FromDS frame - not for us; probably
2974 * broadcast/multicast in another BSS - drop */
2975 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2976 printk(KERN_DEBUG "Odd.. FromDS packet "
2977 "received with own BSSID\n");
2978 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2979 }
2980 ret = AP_RX_DROP;
2981 goto out;
2982 }
Jouni Malinen4339d322005-08-14 19:08:44 -07002983 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
Jouni Malinenff1d2762005-05-12 22:54:16 -04002984 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2985
2986 if (local->hostapd) {
2987 prism2_rx_80211(local->apdev, skb, rx_stats,
2988 PRISM2_RX_NON_ASSOC);
2989#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2990 } else {
2991 /* At least Lucent f/w seems to send data::nullfunc
2992 * frames with no ToDS flag when the current AP returns
2993 * after being unavailable for some time. Speed up
2994 * re-association by informing the station about it not
2995 * being associated. */
2996 printk(KERN_DEBUG "%s: rejected received nullfunc "
2997 "frame without ToDS from not associated STA "
2998 MACSTR "\n",
2999 dev->name, MAC2STR(hdr->addr2));
3000 hostap_rx(dev, skb, rx_stats);
3001#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3002 }
3003 ret = AP_RX_EXIT;
3004 goto out;
Jouni Malinen4339d322005-08-14 19:08:44 -07003005 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003006 /* At least Lucent cards seem to send periodic nullfunc
3007 * frames with ToDS. Let these through to update SQ
3008 * stats and PS state. Nullfunc frames do not contain
3009 * any data and they will be dropped below. */
3010 } else {
3011 /* If BSSID (Addr3) is foreign, this frame is a normal
3012 * broadcast frame from an IBSS network. Drop it silently.
3013 * If BSSID is own, report the dropping of this frame. */
3014 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
3015 printk(KERN_DEBUG "%s: dropped received packet from "
3016 MACSTR " with no ToDS flag (type=0x%02x, "
3017 "subtype=0x%02x)\n", dev->name,
Jouni Malinen4339d322005-08-14 19:08:44 -07003018 MAC2STR(hdr->addr2), type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003019 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3020 }
3021 ret = AP_RX_DROP;
3022 goto out;
3023 }
3024
3025 if (sta) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07003026 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
Jouni Malinenff1d2762005-05-12 22:54:16 -04003027 type, stype);
3028
3029 sta->rx_packets++;
3030 sta->rx_bytes += skb->len;
3031 sta->last_rx = jiffies;
3032 }
3033
Jouni Malinen4339d322005-08-14 19:08:44 -07003034 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07003035 fc & IEEE80211_FCTL_TODS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003036 if (local->hostapd) {
3037 prism2_rx_80211(local->apdev, skb, rx_stats,
3038 PRISM2_RX_NULLFUNC_ACK);
3039#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3040 } else {
3041 /* some STA f/w's seem to require control::ACK frame
3042 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3043 * from Compaq) does not send this.. Try to generate
3044 * ACK for these frames from the host driver to make
3045 * power saving work with, e.g., Lucent WaveLAN f/w */
3046 hostap_rx(dev, skb, rx_stats);
3047#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3048 }
3049 ret = AP_RX_EXIT;
3050 goto out;
3051 }
3052
3053 out:
3054 if (sta)
3055 atomic_dec(&sta->users);
3056
3057 return ret;
3058}
3059
3060
3061/* Called only as a tasklet (software IRQ) */
3062int hostap_handle_sta_crypto(local_info_t *local,
James Ketrenosd0416742005-09-21 12:23:49 -05003063 struct ieee80211_hdr_4addr *hdr,
Jouni Malinen62fe7e32005-07-30 20:43:20 -07003064 struct ieee80211_crypt_data **crypt,
3065 void **sta_ptr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04003066{
3067 struct sta_info *sta;
3068
3069 spin_lock(&local->ap->sta_table_lock);
3070 sta = ap_get_sta(local->ap, hdr->addr2);
3071 if (sta)
3072 atomic_inc(&sta->users);
3073 spin_unlock(&local->ap->sta_table_lock);
3074
3075 if (!sta)
3076 return -1;
3077
3078 if (sta->crypt) {
3079 *crypt = sta->crypt;
3080 *sta_ptr = sta;
3081 /* hostap_handle_sta_release() will be called to release STA
3082 * info */
3083 } else
3084 atomic_dec(&sta->users);
3085
3086 return 0;
3087}
3088
3089
3090/* Called only as a tasklet (software IRQ) */
3091int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3092{
3093 struct sta_info *sta;
3094 int ret = 0;
3095
3096 spin_lock(&ap->sta_table_lock);
3097 sta = ap_get_sta(ap, sta_addr);
3098 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3099 ret = 1;
3100 spin_unlock(&ap->sta_table_lock);
3101
3102 return ret;
3103}
3104
3105
3106/* Called only as a tasklet (software IRQ) */
3107int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3108{
3109 struct sta_info *sta;
3110 int ret = 0;
3111
3112 spin_lock(&ap->sta_table_lock);
3113 sta = ap_get_sta(ap, sta_addr);
3114 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3115 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3116 ap->local->ieee_802_1x == 0))
3117 ret = 1;
3118 spin_unlock(&ap->sta_table_lock);
3119
3120 return ret;
3121}
3122
3123
3124/* Called only as a tasklet (software IRQ) */
3125int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3126{
3127 struct sta_info *sta;
3128 int ret = 1;
3129
3130 if (!ap)
3131 return -1;
3132
3133 spin_lock(&ap->sta_table_lock);
3134 sta = ap_get_sta(ap, sta_addr);
3135 if (sta)
3136 ret = 0;
3137 spin_unlock(&ap->sta_table_lock);
3138
3139 if (ret == 1) {
3140 sta = ap_add_sta(ap, sta_addr);
3141 if (!sta)
Adrian Bunk54b85f42006-03-19 19:21:45 -08003142 return -1;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003143 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3144 sta->ap = 1;
3145 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3146 /* No way of knowing which rates are supported since we did not
3147 * get supported rates element from beacon/assoc req. Assume
3148 * that remote end supports all 802.11b rates. */
3149 sta->supported_rates[0] = 0x82;
3150 sta->supported_rates[1] = 0x84;
3151 sta->supported_rates[2] = 0x0b;
3152 sta->supported_rates[3] = 0x16;
3153 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3154 WLAN_RATE_5M5 | WLAN_RATE_11M;
3155 sta->tx_rate = 110;
3156 sta->tx_max_rate = sta->tx_rate_idx = 3;
3157 }
3158
3159 return ret;
3160}
3161
3162
3163/* Called only as a tasklet (software IRQ) */
3164int hostap_update_rx_stats(struct ap_data *ap,
James Ketrenosd0416742005-09-21 12:23:49 -05003165 struct ieee80211_hdr_4addr *hdr,
Jouni Malinenff1d2762005-05-12 22:54:16 -04003166 struct hostap_80211_rx_status *rx_stats)
3167{
3168 struct sta_info *sta;
3169
3170 if (!ap)
3171 return -1;
3172
3173 spin_lock(&ap->sta_table_lock);
3174 sta = ap_get_sta(ap, hdr->addr2);
3175 if (sta) {
3176 sta->last_rx_silence = rx_stats->noise;
3177 sta->last_rx_signal = rx_stats->signal;
3178 sta->last_rx_rate = rx_stats->rate;
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07003179 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003180 if (rx_stats->rate == 10)
3181 sta->rx_count[0]++;
3182 else if (rx_stats->rate == 20)
3183 sta->rx_count[1]++;
3184 else if (rx_stats->rate == 55)
3185 sta->rx_count[2]++;
3186 else if (rx_stats->rate == 110)
3187 sta->rx_count[3]++;
3188 }
3189 spin_unlock(&ap->sta_table_lock);
3190
3191 return sta ? 0 : -1;
3192}
3193
3194
3195void hostap_update_rates(local_info_t *local)
3196{
3197 struct list_head *ptr;
3198 struct ap_data *ap = local->ap;
3199
3200 if (!ap)
3201 return;
3202
3203 spin_lock_bh(&ap->sta_table_lock);
3204 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
3205 struct sta_info *sta = (struct sta_info *) ptr;
3206 prism2_check_tx_rates(sta);
3207 }
3208 spin_unlock_bh(&ap->sta_table_lock);
3209}
3210
3211
Adrian Bunk5fad5a22006-01-14 03:09:34 +01003212void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3213 struct ieee80211_crypt_data ***crypt)
Jouni Malinenff1d2762005-05-12 22:54:16 -04003214{
3215 struct sta_info *sta;
3216
3217 spin_lock_bh(&ap->sta_table_lock);
3218 sta = ap_get_sta(ap, addr);
3219 if (sta)
3220 atomic_inc(&sta->users);
3221 spin_unlock_bh(&ap->sta_table_lock);
3222
3223 if (!sta && permanent)
3224 sta = ap_add_sta(ap, addr);
3225
3226 if (!sta)
3227 return NULL;
3228
3229 if (permanent)
3230 sta->flags |= WLAN_STA_PERM;
3231
3232 *crypt = &sta->crypt;
3233
3234 return sta;
3235}
3236
3237
3238void hostap_add_wds_links(local_info_t *local)
3239{
3240 struct ap_data *ap = local->ap;
3241 struct list_head *ptr;
3242
3243 spin_lock_bh(&ap->sta_table_lock);
3244 list_for_each(ptr, &ap->sta_list) {
3245 struct sta_info *sta = list_entry(ptr, struct sta_info, list);
3246 if (sta->ap)
3247 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3248 }
3249 spin_unlock_bh(&ap->sta_table_lock);
3250
3251 schedule_work(&local->ap->wds_oper_queue);
3252}
3253
3254
3255void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3256{
3257 struct wds_oper_data *entry;
3258
3259 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3260 if (!entry)
3261 return;
3262 memcpy(entry->addr, addr, ETH_ALEN);
3263 entry->type = type;
3264 spin_lock_bh(&local->lock);
3265 entry->next = local->ap->wds_oper_entries;
3266 local->ap->wds_oper_entries = entry;
3267 spin_unlock_bh(&local->lock);
3268
3269 schedule_work(&local->ap->wds_oper_queue);
3270}
3271
3272
3273EXPORT_SYMBOL(hostap_init_data);
3274EXPORT_SYMBOL(hostap_init_ap_proc);
3275EXPORT_SYMBOL(hostap_free_data);
3276EXPORT_SYMBOL(hostap_check_sta_fw_version);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003277EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003278#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinenff1d2762005-05-12 22:54:16 -04003279#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */