i2c: gpio: fault-injector: refactor incomplete transfer
[linux/fpc-iii.git] / drivers / net / wireless / intersil / hostap / hostap_ap.c
blobd1884b8913e7276e42be9f6a91b16e023482f05e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intersil Prism2 driver with Host AP (software access point) support
4 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
5 * <j@w1.fi>
6 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
8 * This file is to be included into hostap.c when S/W AP functionality is
9 * compiled.
11 * AP: FIX:
12 * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
13 * unauthenticated STA, send deauth. frame (8802.11: 5.5)
14 * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
15 * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
16 * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
17 * (8802.11: 5.5)
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/delay.h>
23 #include <linux/random.h>
24 #include <linux/if_arp.h>
25 #include <linux/slab.h>
26 #include <linux/export.h>
27 #include <linux/moduleparam.h>
28 #include <linux/etherdevice.h>
30 #include "hostap_wlan.h"
31 #include "hostap.h"
32 #include "hostap_ap.h"
34 static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
35 DEF_INTS };
36 module_param_array(other_ap_policy, int, NULL, 0444);
37 MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
39 static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
40 DEF_INTS };
41 module_param_array(ap_max_inactivity, int, NULL, 0444);
42 MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
43 "inactivity");
45 static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
46 module_param_array(ap_bridge_packets, int, NULL, 0444);
47 MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
48 "stations");
50 static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
51 module_param_array(autom_ap_wds, int, NULL, 0444);
52 MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
53 "automatically");
56 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
57 static void hostap_event_expired_sta(struct net_device *dev,
58 struct sta_info *sta);
59 static void handle_add_proc_queue(struct work_struct *work);
61 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
62 static void handle_wds_oper_queue(struct work_struct *work);
63 static void prism2_send_mgmt(struct net_device *dev,
64 u16 type_subtype, char *body,
65 int body_len, u8 *addr, u16 tx_cb_idx);
66 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
69 #ifndef PRISM2_NO_PROCFS_DEBUG
70 static int ap_debug_proc_show(struct seq_file *m, void *v)
72 struct ap_data *ap = PDE_DATA(file_inode(m->file));
74 seq_printf(m, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
75 seq_printf(m, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
76 seq_printf(m, "max_inactivity=%u\n", ap->max_inactivity / HZ);
77 seq_printf(m, "bridge_packets=%u\n", ap->bridge_packets);
78 seq_printf(m, "nullfunc_ack=%u\n", ap->nullfunc_ack);
79 seq_printf(m, "autom_ap_wds=%u\n", ap->autom_ap_wds);
80 seq_printf(m, "auth_algs=%u\n", ap->local->auth_algs);
81 seq_printf(m, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
82 return 0;
84 #endif /* PRISM2_NO_PROCFS_DEBUG */
87 static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
89 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
90 ap->sta_hash[STA_HASH(sta->addr)] = sta;
93 static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
95 struct sta_info *s;
97 s = ap->sta_hash[STA_HASH(sta->addr)];
98 if (s == NULL) return;
99 if (ether_addr_equal(s->addr, sta->addr)) {
100 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
101 return;
104 while (s->hnext != NULL && !ether_addr_equal(s->hnext->addr, sta->addr))
105 s = s->hnext;
106 if (s->hnext != NULL)
107 s->hnext = s->hnext->hnext;
108 else
109 printk("AP: could not remove STA %pM from hash table\n",
110 sta->addr);
113 static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
115 if (sta->ap && sta->local)
116 hostap_event_expired_sta(sta->local->dev, sta);
118 if (ap->proc != NULL) {
119 char name[20];
120 sprintf(name, "%pM", sta->addr);
121 remove_proc_entry(name, ap->proc);
124 if (sta->crypt) {
125 sta->crypt->ops->deinit(sta->crypt->priv);
126 kfree(sta->crypt);
127 sta->crypt = NULL;
130 skb_queue_purge(&sta->tx_buf);
132 ap->num_sta--;
133 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
134 if (sta->aid > 0)
135 ap->sta_aid[sta->aid - 1] = NULL;
137 if (!sta->ap)
138 kfree(sta->u.sta.challenge);
139 del_timer_sync(&sta->timer);
140 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
142 kfree(sta);
146 static void hostap_set_tim(local_info_t *local, int aid, int set)
148 if (local->func->set_tim)
149 local->func->set_tim(local->dev, aid, set);
153 static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
155 union iwreq_data wrqu;
156 memset(&wrqu, 0, sizeof(wrqu));
157 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
158 wrqu.addr.sa_family = ARPHRD_ETHER;
159 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
163 static void hostap_event_expired_sta(struct net_device *dev,
164 struct sta_info *sta)
166 union iwreq_data wrqu;
167 memset(&wrqu, 0, sizeof(wrqu));
168 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
169 wrqu.addr.sa_family = ARPHRD_ETHER;
170 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
174 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
176 static void ap_handle_timer(struct timer_list *t)
178 struct sta_info *sta = from_timer(sta, t, timer);
179 local_info_t *local;
180 struct ap_data *ap;
181 unsigned long next_time = 0;
182 int was_assoc;
184 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
185 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
186 return;
189 local = sta->local;
190 ap = local->ap;
191 was_assoc = sta->flags & WLAN_STA_ASSOC;
193 if (atomic_read(&sta->users) != 0)
194 next_time = jiffies + HZ;
195 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
196 next_time = jiffies + ap->max_inactivity;
198 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
199 /* station activity detected; reset timeout state */
200 sta->timeout_next = STA_NULLFUNC;
201 next_time = sta->last_rx + ap->max_inactivity;
202 } else if (sta->timeout_next == STA_DISASSOC &&
203 !(sta->flags & WLAN_STA_PENDING_POLL)) {
204 /* STA ACKed data nullfunc frame poll */
205 sta->timeout_next = STA_NULLFUNC;
206 next_time = jiffies + ap->max_inactivity;
209 if (next_time) {
210 sta->timer.expires = next_time;
211 add_timer(&sta->timer);
212 return;
215 if (sta->ap)
216 sta->timeout_next = STA_DEAUTH;
218 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
219 spin_lock(&ap->sta_table_lock);
220 ap_sta_hash_del(ap, sta);
221 list_del(&sta->list);
222 spin_unlock(&ap->sta_table_lock);
223 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
224 } else if (sta->timeout_next == STA_DISASSOC)
225 sta->flags &= ~WLAN_STA_ASSOC;
227 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
228 hostap_event_expired_sta(local->dev, sta);
230 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
231 !skb_queue_empty(&sta->tx_buf)) {
232 hostap_set_tim(local, sta->aid, 0);
233 sta->flags &= ~WLAN_STA_TIM;
236 if (sta->ap) {
237 if (ap->autom_ap_wds) {
238 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
239 "connection to AP %pM\n",
240 local->dev->name, sta->addr);
241 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
243 } else if (sta->timeout_next == STA_NULLFUNC) {
244 /* send data frame to poll STA and check whether this frame
245 * is ACKed */
246 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
247 * it is apparently not retried so TX Exc events are not
248 * received for it */
249 sta->flags |= WLAN_STA_PENDING_POLL;
250 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
251 IEEE80211_STYPE_DATA, NULL, 0,
252 sta->addr, ap->tx_callback_poll);
253 } else {
254 int deauth = sta->timeout_next == STA_DEAUTH;
255 __le16 resp;
256 PDEBUG(DEBUG_AP, "%s: sending %s info to STA %pM"
257 "(last=%lu, jiffies=%lu)\n",
258 local->dev->name,
259 deauth ? "deauthentication" : "disassociation",
260 sta->addr, sta->last_rx, jiffies);
262 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
263 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
264 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
265 (deauth ? IEEE80211_STYPE_DEAUTH :
266 IEEE80211_STYPE_DISASSOC),
267 (char *) &resp, 2, sta->addr, 0);
270 if (sta->timeout_next == STA_DEAUTH) {
271 if (sta->flags & WLAN_STA_PERM) {
272 PDEBUG(DEBUG_AP, "%s: STA %pM"
273 " would have been removed, "
274 "but it has 'perm' flag\n",
275 local->dev->name, sta->addr);
276 } else
277 ap_free_sta(ap, sta);
278 return;
281 if (sta->timeout_next == STA_NULLFUNC) {
282 sta->timeout_next = STA_DISASSOC;
283 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
284 } else {
285 sta->timeout_next = STA_DEAUTH;
286 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
289 add_timer(&sta->timer);
293 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
294 int resend)
296 u8 addr[ETH_ALEN];
297 __le16 resp;
298 int i;
300 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
301 eth_broadcast_addr(addr);
303 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
305 /* deauth message sent; try to resend it few times; the message is
306 * broadcast, so it may be delayed until next DTIM; there is not much
307 * else we can do at this point since the driver is going to be shut
308 * down */
309 for (i = 0; i < 5; i++) {
310 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
311 IEEE80211_STYPE_DEAUTH,
312 (char *) &resp, 2, addr, 0);
314 if (!resend || ap->num_sta <= 0)
315 return;
317 mdelay(50);
322 static int ap_control_proc_show(struct seq_file *m, void *v)
324 struct ap_data *ap = PDE_DATA(file_inode(m->file));
325 char *policy_txt;
326 struct mac_entry *entry;
328 if (v == SEQ_START_TOKEN) {
329 switch (ap->mac_restrictions.policy) {
330 case MAC_POLICY_OPEN:
331 policy_txt = "open";
332 break;
333 case MAC_POLICY_ALLOW:
334 policy_txt = "allow";
335 break;
336 case MAC_POLICY_DENY:
337 policy_txt = "deny";
338 break;
339 default:
340 policy_txt = "unknown";
341 break;
343 seq_printf(m, "MAC policy: %s\n", policy_txt);
344 seq_printf(m, "MAC entries: %u\n", ap->mac_restrictions.entries);
345 seq_puts(m, "MAC list:\n");
346 return 0;
349 entry = v;
350 seq_printf(m, "%pM\n", entry->addr);
351 return 0;
354 static void *ap_control_proc_start(struct seq_file *m, loff_t *_pos)
356 struct ap_data *ap = PDE_DATA(file_inode(m->file));
357 spin_lock_bh(&ap->mac_restrictions.lock);
358 return seq_list_start_head(&ap->mac_restrictions.mac_list, *_pos);
361 static void *ap_control_proc_next(struct seq_file *m, void *v, loff_t *_pos)
363 struct ap_data *ap = PDE_DATA(file_inode(m->file));
364 return seq_list_next(v, &ap->mac_restrictions.mac_list, _pos);
367 static void ap_control_proc_stop(struct seq_file *m, void *v)
369 struct ap_data *ap = PDE_DATA(file_inode(m->file));
370 spin_unlock_bh(&ap->mac_restrictions.lock);
373 static const struct seq_operations ap_control_proc_seqops = {
374 .start = ap_control_proc_start,
375 .next = ap_control_proc_next,
376 .stop = ap_control_proc_stop,
377 .show = ap_control_proc_show,
380 int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
382 struct mac_entry *entry;
384 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
385 if (entry == NULL)
386 return -ENOMEM;
388 memcpy(entry->addr, mac, ETH_ALEN);
390 spin_lock_bh(&mac_restrictions->lock);
391 list_add_tail(&entry->list, &mac_restrictions->mac_list);
392 mac_restrictions->entries++;
393 spin_unlock_bh(&mac_restrictions->lock);
395 return 0;
399 int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
401 struct list_head *ptr;
402 struct mac_entry *entry;
404 spin_lock_bh(&mac_restrictions->lock);
405 for (ptr = mac_restrictions->mac_list.next;
406 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
407 entry = list_entry(ptr, struct mac_entry, list);
409 if (ether_addr_equal(entry->addr, mac)) {
410 list_del(ptr);
411 kfree(entry);
412 mac_restrictions->entries--;
413 spin_unlock_bh(&mac_restrictions->lock);
414 return 0;
417 spin_unlock_bh(&mac_restrictions->lock);
418 return -1;
422 static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
423 u8 *mac)
425 struct mac_entry *entry;
426 int found = 0;
428 if (mac_restrictions->policy == MAC_POLICY_OPEN)
429 return 0;
431 spin_lock_bh(&mac_restrictions->lock);
432 list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
433 if (ether_addr_equal(entry->addr, mac)) {
434 found = 1;
435 break;
438 spin_unlock_bh(&mac_restrictions->lock);
440 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
441 return !found;
442 else
443 return found;
447 void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
449 struct list_head *ptr, *n;
450 struct mac_entry *entry;
452 if (mac_restrictions->entries == 0)
453 return;
455 spin_lock_bh(&mac_restrictions->lock);
456 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
457 ptr != &mac_restrictions->mac_list;
458 ptr = n, n = ptr->next) {
459 entry = list_entry(ptr, struct mac_entry, list);
460 list_del(ptr);
461 kfree(entry);
463 mac_restrictions->entries = 0;
464 spin_unlock_bh(&mac_restrictions->lock);
468 int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
470 struct sta_info *sta;
471 __le16 resp;
473 spin_lock_bh(&ap->sta_table_lock);
474 sta = ap_get_sta(ap, mac);
475 if (sta) {
476 ap_sta_hash_del(ap, sta);
477 list_del(&sta->list);
479 spin_unlock_bh(&ap->sta_table_lock);
481 if (!sta)
482 return -EINVAL;
484 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
485 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
486 (char *) &resp, 2, sta->addr, 0);
488 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
489 hostap_event_expired_sta(dev, sta);
491 ap_free_sta(ap, sta);
493 return 0;
496 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
499 void ap_control_kickall(struct ap_data *ap)
501 struct list_head *ptr, *n;
502 struct sta_info *sta;
504 spin_lock_bh(&ap->sta_table_lock);
505 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
506 ptr = n, n = ptr->next) {
507 sta = list_entry(ptr, struct sta_info, list);
508 ap_sta_hash_del(ap, sta);
509 list_del(&sta->list);
510 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
511 hostap_event_expired_sta(sta->local->dev, sta);
512 ap_free_sta(ap, sta);
514 spin_unlock_bh(&ap->sta_table_lock);
518 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
520 static int prism2_ap_proc_show(struct seq_file *m, void *v)
522 struct sta_info *sta = v;
523 int i;
525 if (v == SEQ_START_TOKEN) {
526 seq_printf(m, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
527 return 0;
530 if (!sta->ap)
531 return 0;
533 seq_printf(m, "%pM %d %d %d %d '",
534 sta->addr,
535 sta->u.ap.channel, sta->last_rx_signal,
536 sta->last_rx_silence, sta->last_rx_rate);
538 for (i = 0; i < sta->u.ap.ssid_len; i++) {
539 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
540 seq_putc(m, sta->u.ap.ssid[i]);
541 else
542 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
545 seq_putc(m, '\'');
546 if (sta->capability & WLAN_CAPABILITY_ESS)
547 seq_puts(m, " [ESS]");
548 if (sta->capability & WLAN_CAPABILITY_IBSS)
549 seq_puts(m, " [IBSS]");
550 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
551 seq_puts(m, " [WEP]");
552 seq_putc(m, '\n');
553 return 0;
556 static void *prism2_ap_proc_start(struct seq_file *m, loff_t *_pos)
558 struct ap_data *ap = PDE_DATA(file_inode(m->file));
559 spin_lock_bh(&ap->sta_table_lock);
560 return seq_list_start_head(&ap->sta_list, *_pos);
563 static void *prism2_ap_proc_next(struct seq_file *m, void *v, loff_t *_pos)
565 struct ap_data *ap = PDE_DATA(file_inode(m->file));
566 return seq_list_next(v, &ap->sta_list, _pos);
569 static void prism2_ap_proc_stop(struct seq_file *m, void *v)
571 struct ap_data *ap = PDE_DATA(file_inode(m->file));
572 spin_unlock_bh(&ap->sta_table_lock);
575 static const struct seq_operations prism2_ap_proc_seqops = {
576 .start = prism2_ap_proc_start,
577 .next = prism2_ap_proc_next,
578 .stop = prism2_ap_proc_stop,
579 .show = prism2_ap_proc_show,
581 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
584 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
586 if (!ap)
587 return;
589 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
590 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
591 "firmware upgrade recommended\n");
592 ap->nullfunc_ack = 1;
593 } else
594 ap->nullfunc_ack = 0;
596 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
597 printk(KERN_WARNING "%s: Warning: secondary station firmware "
598 "version 1.4.2 does not seem to work in Host AP mode\n",
599 ap->local->dev->name);
604 /* Called only as a tasklet (software IRQ) */
605 static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
607 struct ap_data *ap = data;
608 struct ieee80211_hdr *hdr;
610 if (!ap->local->hostapd || !ap->local->apdev) {
611 dev_kfree_skb(skb);
612 return;
615 /* Pass the TX callback frame to the hostapd; use 802.11 header version
616 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
618 hdr = (struct ieee80211_hdr *) skb->data;
619 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_VERS);
620 hdr->frame_control |= cpu_to_le16(ok ? BIT(1) : BIT(0));
622 skb->dev = ap->local->apdev;
623 skb_pull(skb, hostap_80211_get_hdrlen(hdr->frame_control));
624 skb->pkt_type = PACKET_OTHERHOST;
625 skb->protocol = cpu_to_be16(ETH_P_802_2);
626 memset(skb->cb, 0, sizeof(skb->cb));
627 netif_rx(skb);
631 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
632 /* Called only as a tasklet (software IRQ) */
633 static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
635 struct ap_data *ap = data;
636 struct net_device *dev = ap->local->dev;
637 struct ieee80211_hdr *hdr;
638 u16 auth_alg, auth_transaction, status;
639 __le16 *pos;
640 struct sta_info *sta = NULL;
641 char *txt = NULL;
643 if (ap->local->hostapd) {
644 dev_kfree_skb(skb);
645 return;
648 hdr = (struct ieee80211_hdr *) skb->data;
649 if (!ieee80211_is_auth(hdr->frame_control) ||
650 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
651 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
652 "frame\n", dev->name);
653 dev_kfree_skb(skb);
654 return;
657 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
658 auth_alg = le16_to_cpu(*pos++);
659 auth_transaction = le16_to_cpu(*pos++);
660 status = le16_to_cpu(*pos++);
662 if (!ok) {
663 txt = "frame was not ACKed";
664 goto done;
667 spin_lock(&ap->sta_table_lock);
668 sta = ap_get_sta(ap, hdr->addr1);
669 if (sta)
670 atomic_inc(&sta->users);
671 spin_unlock(&ap->sta_table_lock);
673 if (!sta) {
674 txt = "STA not found";
675 goto done;
678 if (status == WLAN_STATUS_SUCCESS &&
679 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
680 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
681 txt = "STA authenticated";
682 sta->flags |= WLAN_STA_AUTH;
683 sta->last_auth = jiffies;
684 } else if (status != WLAN_STATUS_SUCCESS)
685 txt = "authentication failed";
687 done:
688 if (sta)
689 atomic_dec(&sta->users);
690 if (txt) {
691 PDEBUG(DEBUG_AP, "%s: %pM auth_cb - alg=%d "
692 "trans#=%d status=%d - %s\n",
693 dev->name, hdr->addr1,
694 auth_alg, auth_transaction, status, txt);
696 dev_kfree_skb(skb);
700 /* Called only as a tasklet (software IRQ) */
701 static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
703 struct ap_data *ap = data;
704 struct net_device *dev = ap->local->dev;
705 struct ieee80211_hdr *hdr;
706 u16 status;
707 __le16 *pos;
708 struct sta_info *sta = NULL;
709 char *txt = NULL;
711 if (ap->local->hostapd) {
712 dev_kfree_skb(skb);
713 return;
716 hdr = (struct ieee80211_hdr *) skb->data;
717 if ((!ieee80211_is_assoc_resp(hdr->frame_control) &&
718 !ieee80211_is_reassoc_resp(hdr->frame_control)) ||
719 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
720 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
721 "frame\n", dev->name);
722 dev_kfree_skb(skb);
723 return;
726 if (!ok) {
727 txt = "frame was not ACKed";
728 goto done;
731 spin_lock(&ap->sta_table_lock);
732 sta = ap_get_sta(ap, hdr->addr1);
733 if (sta)
734 atomic_inc(&sta->users);
735 spin_unlock(&ap->sta_table_lock);
737 if (!sta) {
738 txt = "STA not found";
739 goto done;
742 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
743 pos++;
744 status = le16_to_cpu(*pos++);
745 if (status == WLAN_STATUS_SUCCESS) {
746 if (!(sta->flags & WLAN_STA_ASSOC))
747 hostap_event_new_sta(dev, sta);
748 txt = "STA associated";
749 sta->flags |= WLAN_STA_ASSOC;
750 sta->last_assoc = jiffies;
751 } else
752 txt = "association failed";
754 done:
755 if (sta)
756 atomic_dec(&sta->users);
757 if (txt) {
758 PDEBUG(DEBUG_AP, "%s: %pM assoc_cb - %s\n",
759 dev->name, hdr->addr1, txt);
761 dev_kfree_skb(skb);
764 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
765 * in verifying whether the STA is still present. */
766 static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
768 struct ap_data *ap = data;
769 struct ieee80211_hdr *hdr;
770 struct sta_info *sta;
772 if (skb->len < 24)
773 goto fail;
774 hdr = (struct ieee80211_hdr *) skb->data;
775 if (ok) {
776 spin_lock(&ap->sta_table_lock);
777 sta = ap_get_sta(ap, hdr->addr1);
778 if (sta)
779 sta->flags &= ~WLAN_STA_PENDING_POLL;
780 spin_unlock(&ap->sta_table_lock);
781 } else {
782 PDEBUG(DEBUG_AP,
783 "%s: STA %pM did not ACK activity poll frame\n",
784 ap->local->dev->name, hdr->addr1);
787 fail:
788 dev_kfree_skb(skb);
790 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
793 void hostap_init_data(local_info_t *local)
795 struct ap_data *ap = local->ap;
797 if (ap == NULL) {
798 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
799 return;
801 memset(ap, 0, sizeof(struct ap_data));
802 ap->local = local;
804 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
805 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
806 ap->max_inactivity =
807 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
808 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
810 spin_lock_init(&ap->sta_table_lock);
811 INIT_LIST_HEAD(&ap->sta_list);
813 /* Initialize task queue structure for AP management */
814 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
816 ap->tx_callback_idx =
817 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
818 if (ap->tx_callback_idx == 0)
819 printk(KERN_WARNING "%s: failed to register TX callback for "
820 "AP\n", local->dev->name);
821 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
822 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
824 ap->tx_callback_auth =
825 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
826 ap->tx_callback_assoc =
827 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
828 ap->tx_callback_poll =
829 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
830 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
831 ap->tx_callback_poll == 0)
832 printk(KERN_WARNING "%s: failed to register TX callback for "
833 "AP\n", local->dev->name);
835 spin_lock_init(&ap->mac_restrictions.lock);
836 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
837 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
839 ap->initialized = 1;
843 void hostap_init_ap_proc(local_info_t *local)
845 struct ap_data *ap = local->ap;
847 ap->proc = local->proc;
848 if (ap->proc == NULL)
849 return;
851 #ifndef PRISM2_NO_PROCFS_DEBUG
852 proc_create_single_data("ap_debug", 0, ap->proc, ap_debug_proc_show, ap);
853 #endif /* PRISM2_NO_PROCFS_DEBUG */
855 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
856 proc_create_seq_data("ap_control", 0, ap->proc, &ap_control_proc_seqops,
857 ap);
858 proc_create_seq_data("ap", 0, ap->proc, &prism2_ap_proc_seqops, ap);
859 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
864 void hostap_free_data(struct ap_data *ap)
866 struct sta_info *n, *sta;
868 if (ap == NULL || !ap->initialized) {
869 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
870 "initialized - skip resource freeing\n");
871 return;
874 flush_work(&ap->add_sta_proc_queue);
876 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
877 flush_work(&ap->wds_oper_queue);
878 if (ap->crypt)
879 ap->crypt->deinit(ap->crypt_priv);
880 ap->crypt = ap->crypt_priv = NULL;
881 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
883 list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
884 ap_sta_hash_del(ap, sta);
885 list_del(&sta->list);
886 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
887 hostap_event_expired_sta(sta->local->dev, sta);
888 ap_free_sta(ap, sta);
891 #ifndef PRISM2_NO_PROCFS_DEBUG
892 if (ap->proc != NULL) {
893 remove_proc_entry("ap_debug", ap->proc);
895 #endif /* PRISM2_NO_PROCFS_DEBUG */
897 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
898 if (ap->proc != NULL) {
899 remove_proc_entry("ap", ap->proc);
900 remove_proc_entry("ap_control", ap->proc);
902 ap_control_flush_macs(&ap->mac_restrictions);
903 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
905 ap->initialized = 0;
909 /* caller should have mutex for AP STA list handling */
910 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
912 struct sta_info *s;
914 s = ap->sta_hash[STA_HASH(sta)];
915 while (s != NULL && !ether_addr_equal(s->addr, sta))
916 s = s->hnext;
917 return s;
921 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
923 /* Called from timer handler and from scheduled AP queue handlers */
924 static void prism2_send_mgmt(struct net_device *dev,
925 u16 type_subtype, char *body,
926 int body_len, u8 *addr, u16 tx_cb_idx)
928 struct hostap_interface *iface;
929 local_info_t *local;
930 struct ieee80211_hdr *hdr;
931 u16 fc;
932 struct sk_buff *skb;
933 struct hostap_skb_tx_data *meta;
934 int hdrlen;
936 iface = netdev_priv(dev);
937 local = iface->local;
938 dev = local->dev; /* always use master radio device */
939 iface = netdev_priv(dev);
941 if (!(dev->flags & IFF_UP)) {
942 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
943 "cannot send frame\n", dev->name);
944 return;
947 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
948 if (skb == NULL) {
949 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
950 "skb\n", dev->name);
951 return;
954 fc = type_subtype;
955 hdrlen = hostap_80211_get_hdrlen(cpu_to_le16(type_subtype));
956 hdr = skb_put_zero(skb, hdrlen);
957 if (body)
958 skb_put_data(skb, body, body_len);
960 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
961 * tx_control instead of using local->tx_control */
964 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
965 if (ieee80211_is_data(hdr->frame_control)) {
966 fc |= IEEE80211_FCTL_FROMDS;
967 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
968 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
969 } else if (ieee80211_is_ctl(hdr->frame_control)) {
970 /* control:ACK does not have addr2 or addr3 */
971 eth_zero_addr(hdr->addr2);
972 eth_zero_addr(hdr->addr3);
973 } else {
974 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
975 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
978 hdr->frame_control = cpu_to_le16(fc);
980 meta = (struct hostap_skb_tx_data *) skb->cb;
981 memset(meta, 0, sizeof(*meta));
982 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
983 meta->iface = iface;
984 meta->tx_cb_idx = tx_cb_idx;
986 skb->dev = dev;
987 skb_reset_mac_header(skb);
988 skb_reset_network_header(skb);
989 dev_queue_xmit(skb);
991 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
994 static int prism2_sta_proc_show(struct seq_file *m, void *v)
996 struct sta_info *sta = m->private;
997 int i;
999 /* FIX: possible race condition.. the STA data could have just expired,
1000 * but proc entry was still here so that the read could have started;
1001 * some locking should be done here.. */
1003 seq_printf(m,
1004 "%s=%pM\nusers=%d\naid=%d\n"
1005 "flags=0x%04x%s%s%s%s%s%s%s\n"
1006 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1007 sta->ap ? "AP" : "STA",
1008 sta->addr, atomic_read(&sta->users), sta->aid,
1009 sta->flags,
1010 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1011 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1012 sta->flags & WLAN_STA_PS ? " PS" : "",
1013 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1014 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1015 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1016 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1017 sta->capability, sta->listen_interval);
1018 /* supported_rates: 500 kbit/s units with msb ignored */
1019 for (i = 0; i < sizeof(sta->supported_rates); i++)
1020 if (sta->supported_rates[i] != 0)
1021 seq_printf(m, "%d%sMbps ",
1022 (sta->supported_rates[i] & 0x7f) / 2,
1023 sta->supported_rates[i] & 1 ? ".5" : "");
1024 seq_printf(m,
1025 "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1026 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1027 "tx_packets=%lu\n"
1028 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1029 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1030 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1031 "tx[11M]=%d\n"
1032 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1033 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1034 sta->last_tx,
1035 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1036 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1037 sta->last_rx_silence,
1038 sta->last_rx_signal, sta->last_rx_rate / 10,
1039 sta->last_rx_rate % 10 ? ".5" : "",
1040 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1041 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1042 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1043 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1044 sta->crypt->ops->print_stats(m, sta->crypt->priv);
1045 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1046 if (sta->ap) {
1047 if (sta->u.ap.channel >= 0)
1048 seq_printf(m, "channel=%d\n", sta->u.ap.channel);
1049 seq_puts(m, "ssid=");
1050 for (i = 0; i < sta->u.ap.ssid_len; i++) {
1051 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
1052 seq_putc(m, sta->u.ap.ssid[i]);
1053 else
1054 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
1056 seq_putc(m, '\n');
1058 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1060 return 0;
1063 static void handle_add_proc_queue(struct work_struct *work)
1065 struct ap_data *ap = container_of(work, struct ap_data,
1066 add_sta_proc_queue);
1067 struct sta_info *sta;
1068 char name[20];
1069 struct add_sta_proc_data *entry, *prev;
1071 entry = ap->add_sta_proc_entries;
1072 ap->add_sta_proc_entries = NULL;
1074 while (entry) {
1075 spin_lock_bh(&ap->sta_table_lock);
1076 sta = ap_get_sta(ap, entry->addr);
1077 if (sta)
1078 atomic_inc(&sta->users);
1079 spin_unlock_bh(&ap->sta_table_lock);
1081 if (sta) {
1082 sprintf(name, "%pM", sta->addr);
1083 sta->proc = proc_create_single_data(
1084 name, 0, ap->proc,
1085 prism2_sta_proc_show, sta);
1087 atomic_dec(&sta->users);
1090 prev = entry;
1091 entry = entry->next;
1092 kfree(prev);
1097 static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1099 struct sta_info *sta;
1101 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
1102 if (sta == NULL) {
1103 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1104 return NULL;
1107 /* initialize STA info data */
1108 sta->local = ap->local;
1109 skb_queue_head_init(&sta->tx_buf);
1110 memcpy(sta->addr, addr, ETH_ALEN);
1112 atomic_inc(&sta->users);
1113 spin_lock_bh(&ap->sta_table_lock);
1114 list_add(&sta->list, &ap->sta_list);
1115 ap->num_sta++;
1116 ap_sta_hash_add(ap, sta);
1117 spin_unlock_bh(&ap->sta_table_lock);
1119 if (ap->proc) {
1120 struct add_sta_proc_data *entry;
1121 /* schedule a non-interrupt context process to add a procfs
1122 * entry for the STA since procfs code use GFP_KERNEL */
1123 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1124 if (entry) {
1125 memcpy(entry->addr, sta->addr, ETH_ALEN);
1126 entry->next = ap->add_sta_proc_entries;
1127 ap->add_sta_proc_entries = entry;
1128 schedule_work(&ap->add_sta_proc_queue);
1129 } else
1130 printk(KERN_DEBUG "Failed to add STA proc data\n");
1133 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1134 timer_setup(&sta->timer, ap_handle_timer, 0);
1135 sta->timer.expires = jiffies + ap->max_inactivity;
1136 if (!ap->local->hostapd)
1137 add_timer(&sta->timer);
1138 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1140 return sta;
1144 static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1145 local_info_t *local)
1147 if (rateidx > sta->tx_max_rate ||
1148 !(sta->tx_supp_rates & (1 << rateidx)))
1149 return 0;
1151 if (local->tx_rate_control != 0 &&
1152 !(local->tx_rate_control & (1 << rateidx)))
1153 return 0;
1155 return 1;
1159 static void prism2_check_tx_rates(struct sta_info *sta)
1161 int i;
1163 sta->tx_supp_rates = 0;
1164 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1165 if ((sta->supported_rates[i] & 0x7f) == 2)
1166 sta->tx_supp_rates |= WLAN_RATE_1M;
1167 if ((sta->supported_rates[i] & 0x7f) == 4)
1168 sta->tx_supp_rates |= WLAN_RATE_2M;
1169 if ((sta->supported_rates[i] & 0x7f) == 11)
1170 sta->tx_supp_rates |= WLAN_RATE_5M5;
1171 if ((sta->supported_rates[i] & 0x7f) == 22)
1172 sta->tx_supp_rates |= WLAN_RATE_11M;
1174 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1175 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1176 sta->tx_max_rate = 0;
1177 if (ap_tx_rate_ok(0, sta, sta->local)) {
1178 sta->tx_rate = 10;
1179 sta->tx_rate_idx = 0;
1182 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1183 sta->tx_max_rate = 1;
1184 if (ap_tx_rate_ok(1, sta, sta->local)) {
1185 sta->tx_rate = 20;
1186 sta->tx_rate_idx = 1;
1189 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1190 sta->tx_max_rate = 2;
1191 if (ap_tx_rate_ok(2, sta, sta->local)) {
1192 sta->tx_rate = 55;
1193 sta->tx_rate_idx = 2;
1196 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1197 sta->tx_max_rate = 3;
1198 if (ap_tx_rate_ok(3, sta, sta->local)) {
1199 sta->tx_rate = 110;
1200 sta->tx_rate_idx = 3;
1206 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1208 static void ap_crypt_init(struct ap_data *ap)
1210 ap->crypt = lib80211_get_crypto_ops("WEP");
1212 if (ap->crypt) {
1213 if (ap->crypt->init) {
1214 ap->crypt_priv = ap->crypt->init(0);
1215 if (ap->crypt_priv == NULL)
1216 ap->crypt = NULL;
1217 else {
1218 u8 key[WEP_KEY_LEN];
1219 get_random_bytes(key, WEP_KEY_LEN);
1220 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1221 ap->crypt_priv);
1226 if (ap->crypt == NULL) {
1227 printk(KERN_WARNING "AP could not initialize WEP: load module "
1228 "lib80211_crypt_wep.ko\n");
1233 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1234 * that WEP algorithm is used for generating challenge. This should be unique,
1235 * but otherwise there is not really need for randomness etc. Initialize WEP
1236 * with pseudo random key and then use increasing IV to get unique challenge
1237 * streams.
1239 * Called only as a scheduled task for pending AP frames.
1241 static char * ap_auth_make_challenge(struct ap_data *ap)
1243 char *tmpbuf;
1244 struct sk_buff *skb;
1246 if (ap->crypt == NULL) {
1247 ap_crypt_init(ap);
1248 if (ap->crypt == NULL)
1249 return NULL;
1252 tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1253 if (tmpbuf == NULL) {
1254 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1255 return NULL;
1258 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1259 ap->crypt->extra_mpdu_prefix_len +
1260 ap->crypt->extra_mpdu_postfix_len);
1261 if (skb == NULL) {
1262 kfree(tmpbuf);
1263 return NULL;
1266 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
1267 skb_put_zero(skb, WLAN_AUTH_CHALLENGE_LEN);
1268 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1269 dev_kfree_skb(skb);
1270 kfree(tmpbuf);
1271 return NULL;
1274 skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
1275 tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
1276 dev_kfree_skb(skb);
1278 return tmpbuf;
1282 /* Called only as a scheduled task for pending AP frames. */
1283 static void handle_authen(local_info_t *local, struct sk_buff *skb,
1284 struct hostap_80211_rx_status *rx_stats)
1286 struct net_device *dev = local->dev;
1287 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1288 size_t hdrlen;
1289 struct ap_data *ap = local->ap;
1290 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1291 int len, olen;
1292 u16 auth_alg, auth_transaction, status_code;
1293 __le16 *pos;
1294 u16 resp = WLAN_STATUS_SUCCESS;
1295 struct sta_info *sta = NULL;
1296 struct lib80211_crypt_data *crypt;
1297 char *txt = "";
1299 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1301 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
1303 if (len < 6) {
1304 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1305 "(len=%d) from %pM\n", dev->name, len, hdr->addr2);
1306 return;
1309 spin_lock_bh(&local->ap->sta_table_lock);
1310 sta = ap_get_sta(local->ap, hdr->addr2);
1311 if (sta)
1312 atomic_inc(&sta->users);
1313 spin_unlock_bh(&local->ap->sta_table_lock);
1315 if (sta && sta->crypt)
1316 crypt = sta->crypt;
1317 else {
1318 int idx = 0;
1319 if (skb->len >= hdrlen + 3)
1320 idx = skb->data[hdrlen + 3] >> 6;
1321 crypt = local->crypt_info.crypt[idx];
1324 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1325 auth_alg = __le16_to_cpu(*pos);
1326 pos++;
1327 auth_transaction = __le16_to_cpu(*pos);
1328 pos++;
1329 status_code = __le16_to_cpu(*pos);
1330 pos++;
1332 if (ether_addr_equal(dev->dev_addr, hdr->addr2) ||
1333 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1334 txt = "authentication denied";
1335 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1336 goto fail;
1339 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1340 auth_alg == WLAN_AUTH_OPEN) ||
1341 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1342 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1343 } else {
1344 txt = "unsupported algorithm";
1345 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1346 goto fail;
1349 if (len >= 8) {
1350 u8 *u = (u8 *) pos;
1351 if (*u == WLAN_EID_CHALLENGE) {
1352 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1353 txt = "invalid challenge len";
1354 resp = WLAN_STATUS_CHALLENGE_FAIL;
1355 goto fail;
1357 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1358 txt = "challenge underflow";
1359 resp = WLAN_STATUS_CHALLENGE_FAIL;
1360 goto fail;
1362 challenge = (char *) (u + 2);
1366 if (sta && sta->ap) {
1367 if (time_after(jiffies, sta->u.ap.last_beacon +
1368 (10 * sta->listen_interval * HZ) / 1024)) {
1369 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1370 " assuming AP %pM is now STA\n",
1371 dev->name, sta->addr);
1372 sta->ap = 0;
1373 sta->flags = 0;
1374 sta->u.sta.challenge = NULL;
1375 } else {
1376 txt = "AP trying to authenticate?";
1377 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1378 goto fail;
1382 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1383 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1384 (auth_transaction == 1 ||
1385 (auth_transaction == 3 && sta != NULL &&
1386 sta->u.sta.challenge != NULL)))) {
1387 } else {
1388 txt = "unknown authentication transaction number";
1389 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1390 goto fail;
1393 if (sta == NULL) {
1394 txt = "new STA";
1396 if (local->ap->num_sta >= MAX_STA_COUNT) {
1397 /* FIX: might try to remove some old STAs first? */
1398 txt = "no more room for new STAs";
1399 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1400 goto fail;
1403 sta = ap_add_sta(local->ap, hdr->addr2);
1404 if (sta == NULL) {
1405 txt = "ap_add_sta failed";
1406 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1407 goto fail;
1411 switch (auth_alg) {
1412 case WLAN_AUTH_OPEN:
1413 txt = "authOK";
1414 /* IEEE 802.11 standard is not completely clear about
1415 * whether STA is considered authenticated after
1416 * authentication OK frame has been send or after it
1417 * has been ACKed. In order to reduce interoperability
1418 * issues, mark the STA authenticated before ACK. */
1419 sta->flags |= WLAN_STA_AUTH;
1420 break;
1422 case WLAN_AUTH_SHARED_KEY:
1423 if (auth_transaction == 1) {
1424 if (sta->u.sta.challenge == NULL) {
1425 sta->u.sta.challenge =
1426 ap_auth_make_challenge(local->ap);
1427 if (sta->u.sta.challenge == NULL) {
1428 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1429 goto fail;
1432 } else {
1433 if (sta->u.sta.challenge == NULL ||
1434 challenge == NULL ||
1435 memcmp(sta->u.sta.challenge, challenge,
1436 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
1437 !ieee80211_has_protected(hdr->frame_control)) {
1438 txt = "challenge response incorrect";
1439 resp = WLAN_STATUS_CHALLENGE_FAIL;
1440 goto fail;
1443 txt = "challenge OK - authOK";
1444 /* IEEE 802.11 standard is not completely clear about
1445 * whether STA is considered authenticated after
1446 * authentication OK frame has been send or after it
1447 * has been ACKed. In order to reduce interoperability
1448 * issues, mark the STA authenticated before ACK. */
1449 sta->flags |= WLAN_STA_AUTH;
1450 kfree(sta->u.sta.challenge);
1451 sta->u.sta.challenge = NULL;
1453 break;
1456 fail:
1457 pos = (__le16 *) body;
1458 *pos = cpu_to_le16(auth_alg);
1459 pos++;
1460 *pos = cpu_to_le16(auth_transaction + 1);
1461 pos++;
1462 *pos = cpu_to_le16(resp); /* status_code */
1463 pos++;
1464 olen = 6;
1466 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1467 sta->u.sta.challenge != NULL &&
1468 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1469 u8 *tmp = (u8 *) pos;
1470 *tmp++ = WLAN_EID_CHALLENGE;
1471 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1472 pos++;
1473 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1474 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1477 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
1478 body, olen, hdr->addr2, ap->tx_callback_auth);
1480 if (sta) {
1481 sta->last_rx = jiffies;
1482 atomic_dec(&sta->users);
1485 if (resp) {
1486 PDEBUG(DEBUG_AP, "%s: %pM auth (alg=%d "
1487 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1488 dev->name, hdr->addr2,
1489 auth_alg, auth_transaction, status_code, len,
1490 le16_to_cpu(hdr->frame_control), resp, txt);
1495 /* Called only as a scheduled task for pending AP frames. */
1496 static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1497 struct hostap_80211_rx_status *rx_stats, int reassoc)
1499 struct net_device *dev = local->dev;
1500 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1501 char body[12], *p, *lpos;
1502 int len, left;
1503 __le16 *pos;
1504 u16 resp = WLAN_STATUS_SUCCESS;
1505 struct sta_info *sta = NULL;
1506 int send_deauth = 0;
1507 char *txt = "";
1508 u8 prev_ap[ETH_ALEN];
1510 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1512 if (len < (reassoc ? 10 : 4)) {
1513 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1514 "(len=%d, reassoc=%d) from %pM\n",
1515 dev->name, len, reassoc, hdr->addr2);
1516 return;
1519 spin_lock_bh(&local->ap->sta_table_lock);
1520 sta = ap_get_sta(local->ap, hdr->addr2);
1521 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1522 spin_unlock_bh(&local->ap->sta_table_lock);
1523 txt = "trying to associate before authentication";
1524 send_deauth = 1;
1525 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1526 sta = NULL; /* do not decrement sta->users */
1527 goto fail;
1529 atomic_inc(&sta->users);
1530 spin_unlock_bh(&local->ap->sta_table_lock);
1532 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1533 sta->capability = __le16_to_cpu(*pos);
1534 pos++; left -= 2;
1535 sta->listen_interval = __le16_to_cpu(*pos);
1536 pos++; left -= 2;
1538 if (reassoc) {
1539 memcpy(prev_ap, pos, ETH_ALEN);
1540 pos++; pos++; pos++; left -= 6;
1541 } else
1542 eth_zero_addr(prev_ap);
1544 if (left >= 2) {
1545 unsigned int ileft;
1546 unsigned char *u = (unsigned char *) pos;
1548 if (*u == WLAN_EID_SSID) {
1549 u++; left--;
1550 ileft = *u;
1551 u++; left--;
1553 if (ileft > left || ileft > MAX_SSID_LEN) {
1554 txt = "SSID overflow";
1555 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1556 goto fail;
1559 if (ileft != strlen(local->essid) ||
1560 memcmp(local->essid, u, ileft) != 0) {
1561 txt = "not our SSID";
1562 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1563 goto fail;
1566 u += ileft;
1567 left -= ileft;
1570 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1571 u++; left--;
1572 ileft = *u;
1573 u++; left--;
1575 if (ileft > left || ileft == 0 ||
1576 ileft > WLAN_SUPP_RATES_MAX) {
1577 txt = "SUPP_RATES len error";
1578 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1579 goto fail;
1582 memset(sta->supported_rates, 0,
1583 sizeof(sta->supported_rates));
1584 memcpy(sta->supported_rates, u, ileft);
1585 prism2_check_tx_rates(sta);
1587 u += ileft;
1588 left -= ileft;
1591 if (left > 0) {
1592 PDEBUG(DEBUG_AP, "%s: assoc from %pM"
1593 " with extra data (%d bytes) [",
1594 dev->name, hdr->addr2, left);
1595 while (left > 0) {
1596 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1597 u++; left--;
1599 PDEBUG2(DEBUG_AP, "]\n");
1601 } else {
1602 txt = "frame underflow";
1603 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1604 goto fail;
1607 /* get a unique AID */
1608 if (sta->aid > 0)
1609 txt = "OK, old AID";
1610 else {
1611 spin_lock_bh(&local->ap->sta_table_lock);
1612 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1613 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1614 break;
1615 if (sta->aid > MAX_AID_TABLE_SIZE) {
1616 sta->aid = 0;
1617 spin_unlock_bh(&local->ap->sta_table_lock);
1618 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1619 txt = "no room for more AIDs";
1620 } else {
1621 local->ap->sta_aid[sta->aid - 1] = sta;
1622 spin_unlock_bh(&local->ap->sta_table_lock);
1623 txt = "OK, new AID";
1627 fail:
1628 pos = (__le16 *) body;
1630 if (send_deauth) {
1631 *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1632 pos++;
1633 } else {
1634 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1635 * values in beacons/probe responses */
1636 /* FIX: how about privacy and WEP? */
1637 /* capability */
1638 *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
1639 pos++;
1641 /* status_code */
1642 *pos = cpu_to_le16(resp);
1643 pos++;
1645 *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1646 BIT(14) | BIT(15)); /* AID */
1647 pos++;
1649 /* Supported rates (Information element) */
1650 p = (char *) pos;
1651 *p++ = WLAN_EID_SUPP_RATES;
1652 lpos = p;
1653 *p++ = 0; /* len */
1654 if (local->tx_rate_control & WLAN_RATE_1M) {
1655 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1656 (*lpos)++;
1658 if (local->tx_rate_control & WLAN_RATE_2M) {
1659 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1660 (*lpos)++;
1662 if (local->tx_rate_control & WLAN_RATE_5M5) {
1663 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1664 0x8b : 0x0b;
1665 (*lpos)++;
1667 if (local->tx_rate_control & WLAN_RATE_11M) {
1668 *p++ = local->basic_rates & WLAN_RATE_11M ?
1669 0x96 : 0x16;
1670 (*lpos)++;
1672 pos = (__le16 *) p;
1675 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1676 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1677 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1678 IEEE80211_STYPE_ASSOC_RESP)),
1679 body, (u8 *) pos - (u8 *) body,
1680 hdr->addr2,
1681 send_deauth ? 0 : local->ap->tx_callback_assoc);
1683 if (sta) {
1684 if (resp == WLAN_STATUS_SUCCESS) {
1685 sta->last_rx = jiffies;
1686 /* STA will be marked associated from TX callback, if
1687 * AssocResp is ACKed */
1689 atomic_dec(&sta->users);
1692 #if 0
1693 PDEBUG(DEBUG_AP, "%s: %pM %sassoc (len=%d "
1694 "prev_ap=%pM) => %d(%d) (%s)\n",
1695 dev->name,
1696 hdr->addr2,
1697 reassoc ? "re" : "", len,
1698 prev_ap,
1699 resp, send_deauth, txt);
1700 #endif
1704 /* Called only as a scheduled task for pending AP frames. */
1705 static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1706 struct hostap_80211_rx_status *rx_stats)
1708 struct net_device *dev = local->dev;
1709 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1710 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1711 int len;
1712 u16 reason_code;
1713 __le16 *pos;
1714 struct sta_info *sta = NULL;
1716 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1718 if (len < 2) {
1719 printk("handle_deauth - too short payload (len=%d)\n", len);
1720 return;
1723 pos = (__le16 *) body;
1724 reason_code = le16_to_cpu(*pos);
1726 PDEBUG(DEBUG_AP, "%s: deauthentication: %pM len=%d, "
1727 "reason_code=%d\n", dev->name, hdr->addr2,
1728 len, reason_code);
1730 spin_lock_bh(&local->ap->sta_table_lock);
1731 sta = ap_get_sta(local->ap, hdr->addr2);
1732 if (sta != NULL) {
1733 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1734 hostap_event_expired_sta(local->dev, sta);
1735 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1737 spin_unlock_bh(&local->ap->sta_table_lock);
1738 if (sta == NULL) {
1739 printk("%s: deauthentication from %pM, "
1740 "reason_code=%d, but STA not authenticated\n", dev->name,
1741 hdr->addr2, reason_code);
1746 /* Called only as a scheduled task for pending AP frames. */
1747 static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1748 struct hostap_80211_rx_status *rx_stats)
1750 struct net_device *dev = local->dev;
1751 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1752 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1753 int len;
1754 u16 reason_code;
1755 __le16 *pos;
1756 struct sta_info *sta = NULL;
1758 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1760 if (len < 2) {
1761 printk("handle_disassoc - too short payload (len=%d)\n", len);
1762 return;
1765 pos = (__le16 *) body;
1766 reason_code = le16_to_cpu(*pos);
1768 PDEBUG(DEBUG_AP, "%s: disassociation: %pM len=%d, "
1769 "reason_code=%d\n", dev->name, hdr->addr2,
1770 len, reason_code);
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;
1779 spin_unlock_bh(&local->ap->sta_table_lock);
1780 if (sta == NULL) {
1781 printk("%s: disassociation from %pM, "
1782 "reason_code=%d, but STA not authenticated\n",
1783 dev->name, hdr->addr2, reason_code);
1788 /* Called only as a scheduled task for pending AP frames. */
1789 static void ap_handle_data_nullfunc(local_info_t *local,
1790 struct ieee80211_hdr *hdr)
1792 struct net_device *dev = local->dev;
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 */
1799 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1800 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
1801 NULL, 0, hdr->addr2, 0);
1805 /* Called only as a scheduled task for pending AP frames. */
1806 static void ap_handle_dropped_data(local_info_t *local,
1807 struct ieee80211_hdr *hdr)
1809 struct net_device *dev = local->dev;
1810 struct sta_info *sta;
1811 __le16 reason;
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);
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;
1825 reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1826 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1827 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1828 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
1829 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1831 if (sta)
1832 atomic_dec(&sta->users);
1835 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1838 /* Called only as a scheduled task for pending AP frames. */
1839 static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1840 struct sk_buff *skb)
1842 struct hostap_skb_tx_data *meta;
1844 if (!(sta->flags & WLAN_STA_PS)) {
1845 /* Station has moved to non-PS mode, so send all buffered
1846 * frames using normal device queue. */
1847 dev_queue_xmit(skb);
1848 return;
1851 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1852 * be passed through even though STA is using PS */
1853 meta = (struct hostap_skb_tx_data *) skb->cb;
1854 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
1855 if (!skb_queue_empty(&sta->tx_buf)) {
1856 /* indicate to STA that more frames follow */
1857 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
1859 dev_queue_xmit(skb);
1863 /* Called only as a scheduled task for pending AP frames. */
1864 static void handle_pspoll(local_info_t *local,
1865 struct ieee80211_hdr *hdr,
1866 struct hostap_80211_rx_status *rx_stats)
1868 struct net_device *dev = local->dev;
1869 struct sta_info *sta;
1870 u16 aid;
1871 struct sk_buff *skb;
1873 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1874 hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
1876 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
1877 PDEBUG(DEBUG_AP,
1878 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1879 hdr->addr1);
1880 return;
1883 aid = le16_to_cpu(hdr->duration_id);
1884 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1885 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1886 return;
1888 aid &= ~(BIT(15) | BIT(14));
1889 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1890 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1891 return;
1893 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1895 spin_lock_bh(&local->ap->sta_table_lock);
1896 sta = ap_get_sta(local->ap, hdr->addr2);
1897 if (sta)
1898 atomic_inc(&sta->users);
1899 spin_unlock_bh(&local->ap->sta_table_lock);
1901 if (sta == NULL) {
1902 PDEBUG(DEBUG_PS, " STA not found\n");
1903 return;
1905 if (sta->aid != aid) {
1906 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1907 "assoc.aid=%d\n", aid, sta->aid);
1908 return;
1911 /* FIX: todo:
1912 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1913 * out (expiry time must be longer than ListenInterval for
1914 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1915 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1916 * sta; store buffer for later use and leave TIM aid bit set? use
1917 * TX event to check whether frame was ACKed?
1920 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1921 /* send buffered frame .. */
1922 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1923 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1925 pspoll_send_buffered(local, sta, skb);
1927 if (sta->flags & WLAN_STA_PS) {
1928 /* send only one buffered packet per PS Poll */
1929 /* FIX: should ignore further PS Polls until the
1930 * buffered packet that was just sent is acknowledged
1931 * (Tx or TxExc event) */
1932 break;
1936 if (skb_queue_empty(&sta->tx_buf)) {
1937 /* try to clear aid from TIM */
1938 if (!(sta->flags & WLAN_STA_TIM))
1939 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1940 aid);
1941 hostap_set_tim(local, aid, 0);
1942 sta->flags &= ~WLAN_STA_TIM;
1945 atomic_dec(&sta->users);
1949 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1951 static void handle_wds_oper_queue(struct work_struct *work)
1953 struct ap_data *ap = container_of(work, struct ap_data,
1954 wds_oper_queue);
1955 local_info_t *local = ap->local;
1956 struct wds_oper_data *entry, *prev;
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);
1963 while (entry) {
1964 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
1965 "to AP %pM\n",
1966 local->dev->name,
1967 entry->type == WDS_ADD ? "adding" : "removing",
1968 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);
1974 prev = entry;
1975 entry = entry->next;
1976 kfree(prev);
1981 /* Called only as a scheduled task for pending AP frames. */
1982 static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1983 struct hostap_80211_rx_status *rx_stats)
1985 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1986 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1987 int len, left;
1988 u16 beacon_int, capability;
1989 __le16 *pos;
1990 char *ssid = NULL;
1991 unsigned char *supp_rates = NULL;
1992 int ssid_len = 0, supp_rates_len = 0;
1993 struct sta_info *sta = NULL;
1994 int new_sta = 0, channel = -1;
1996 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1998 if (len < 8 + 2 + 2) {
1999 printk(KERN_DEBUG "handle_beacon - too short payload "
2000 "(len=%d)\n", len);
2001 return;
2004 pos = (__le16 *) body;
2005 left = len;
2007 /* Timestamp (8 octets) */
2008 pos += 4; left -= 8;
2009 /* Beacon interval (2 octets) */
2010 beacon_int = le16_to_cpu(*pos);
2011 pos++; left -= 2;
2012 /* Capability information (2 octets) */
2013 capability = le16_to_cpu(*pos);
2014 pos++; left -= 2;
2016 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2017 capability & WLAN_CAPABILITY_IBSS)
2018 return;
2020 if (left >= 2) {
2021 unsigned int ileft;
2022 unsigned char *u = (unsigned char *) pos;
2024 if (*u == WLAN_EID_SSID) {
2025 u++; left--;
2026 ileft = *u;
2027 u++; left--;
2029 if (ileft > left || ileft > MAX_SSID_LEN) {
2030 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2031 return;
2034 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2035 (ileft != strlen(local->essid) ||
2036 memcmp(local->essid, u, ileft) != 0)) {
2037 /* not our SSID */
2038 return;
2041 ssid = u;
2042 ssid_len = ileft;
2044 u += ileft;
2045 left -= ileft;
2048 if (*u == WLAN_EID_SUPP_RATES) {
2049 u++; left--;
2050 ileft = *u;
2051 u++; left--;
2053 if (ileft > left || ileft == 0 || ileft > 8) {
2054 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2055 return;
2058 supp_rates = u;
2059 supp_rates_len = ileft;
2061 u += ileft;
2062 left -= ileft;
2065 if (*u == WLAN_EID_DS_PARAMS) {
2066 u++; left--;
2067 ileft = *u;
2068 u++; left--;
2070 if (ileft > left || ileft != 1) {
2071 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2072 return;
2075 channel = *u;
2077 u += ileft;
2078 left -= ileft;
2082 spin_lock_bh(&local->ap->sta_table_lock);
2083 sta = ap_get_sta(local->ap, hdr->addr2);
2084 if (sta != NULL)
2085 atomic_inc(&sta->users);
2086 spin_unlock_bh(&local->ap->sta_table_lock);
2088 if (sta == NULL) {
2089 /* add new AP */
2090 new_sta = 1;
2091 sta = ap_add_sta(local->ap, hdr->addr2);
2092 if (sta == NULL) {
2093 printk(KERN_INFO "prism2: kmalloc failed for AP "
2094 "data structure\n");
2095 return;
2097 hostap_event_new_sta(local->dev, sta);
2099 /* mark APs authentication and associated for pseudo ad-hoc
2100 * style communication */
2101 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2103 if (local->ap->autom_ap_wds) {
2104 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2108 sta->ap = 1;
2109 if (ssid) {
2110 sta->u.ap.ssid_len = ssid_len;
2111 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2112 sta->u.ap.ssid[ssid_len] = '\0';
2113 } else {
2114 sta->u.ap.ssid_len = 0;
2115 sta->u.ap.ssid[0] = '\0';
2117 sta->u.ap.channel = channel;
2118 sta->rx_packets++;
2119 sta->rx_bytes += len;
2120 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2121 sta->capability = capability;
2122 sta->listen_interval = beacon_int;
2124 atomic_dec(&sta->users);
2126 if (new_sta) {
2127 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2128 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2129 prism2_check_tx_rates(sta);
2133 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2136 /* Called only as a tasklet. */
2137 static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2138 struct hostap_80211_rx_status *rx_stats)
2140 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2141 struct net_device *dev = local->dev;
2142 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2143 u16 fc, type, stype;
2144 struct ieee80211_hdr *hdr;
2146 /* FIX: should give skb->len to handler functions and check that the
2147 * buffer is long enough */
2148 hdr = (struct ieee80211_hdr *) skb->data;
2149 fc = le16_to_cpu(hdr->frame_control);
2150 type = fc & IEEE80211_FCTL_FTYPE;
2151 stype = fc & IEEE80211_FCTL_STYPE;
2153 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2154 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
2155 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2157 if (!(fc & IEEE80211_FCTL_TODS) ||
2158 (fc & IEEE80211_FCTL_FROMDS)) {
2159 if (stype == IEEE80211_STYPE_NULLFUNC) {
2160 /* no ToDS nullfunc seems to be used to check
2161 * AP association; so send reject message to
2162 * speed up re-association */
2163 ap_handle_dropped_data(local, hdr);
2164 goto done;
2166 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2167 fc);
2168 goto done;
2171 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2172 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
2173 " not own MAC\n", hdr->addr1);
2174 goto done;
2177 if (local->ap->nullfunc_ack &&
2178 stype == IEEE80211_STYPE_NULLFUNC)
2179 ap_handle_data_nullfunc(local, hdr);
2180 else
2181 ap_handle_dropped_data(local, hdr);
2182 goto done;
2185 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
2186 handle_beacon(local, skb, rx_stats);
2187 goto done;
2189 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2191 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
2192 handle_pspoll(local, hdr, rx_stats);
2193 goto done;
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;
2202 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2203 if (type != IEEE80211_FTYPE_MGMT) {
2204 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2205 goto done;
2208 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2209 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
2210 " not own MAC\n", hdr->addr1);
2211 goto done;
2214 if (!ether_addr_equal(hdr->addr3, dev->dev_addr)) {
2215 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
2216 " not own MAC\n", hdr->addr3);
2217 goto done;
2220 switch (stype) {
2221 case IEEE80211_STYPE_ASSOC_REQ:
2222 handle_assoc(local, skb, rx_stats, 0);
2223 break;
2224 case IEEE80211_STYPE_ASSOC_RESP:
2225 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2226 break;
2227 case IEEE80211_STYPE_REASSOC_REQ:
2228 handle_assoc(local, skb, rx_stats, 1);
2229 break;
2230 case IEEE80211_STYPE_REASSOC_RESP:
2231 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2232 break;
2233 case IEEE80211_STYPE_ATIM:
2234 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2235 break;
2236 case IEEE80211_STYPE_DISASSOC:
2237 handle_disassoc(local, skb, rx_stats);
2238 break;
2239 case IEEE80211_STYPE_AUTH:
2240 handle_authen(local, skb, rx_stats);
2241 break;
2242 case IEEE80211_STYPE_DEAUTH:
2243 handle_deauth(local, skb, rx_stats);
2244 break;
2245 default:
2246 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2247 stype >> 4);
2248 break;
2250 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2252 done:
2253 dev_kfree_skb(skb);
2257 /* Called only as a tasklet (software IRQ) */
2258 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2259 struct hostap_80211_rx_status *rx_stats)
2261 struct hostap_interface *iface;
2262 local_info_t *local;
2263 struct ieee80211_hdr *hdr;
2265 iface = netdev_priv(dev);
2266 local = iface->local;
2268 if (skb->len < 16)
2269 goto drop;
2271 dev->stats.rx_packets++;
2273 hdr = (struct ieee80211_hdr *) skb->data;
2275 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2276 ieee80211_is_beacon(hdr->frame_control))
2277 goto drop;
2279 skb->protocol = cpu_to_be16(ETH_P_HOSTAP);
2280 handle_ap_item(local, skb, rx_stats);
2281 return;
2283 drop:
2284 dev_kfree_skb(skb);
2288 /* Called only as a tasklet (software IRQ) */
2289 static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2291 struct sk_buff *skb;
2292 struct ieee80211_hdr *hdr;
2293 struct hostap_80211_rx_status rx_stats;
2295 if (skb_queue_empty(&sta->tx_buf))
2296 return;
2298 skb = dev_alloc_skb(16);
2299 if (skb == NULL) {
2300 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2301 "failed\n", local->dev->name);
2302 return;
2305 hdr = skb_put(skb, 16);
2307 /* Generate a fake pspoll frame to start packet delivery */
2308 hdr->frame_control = cpu_to_le16(
2309 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
2310 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2311 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2312 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2314 PDEBUG(DEBUG_PS2,
2315 "%s: Scheduling buffered packet delivery for STA %pM\n",
2316 local->dev->name, sta->addr);
2318 skb->dev = local->dev;
2320 memset(&rx_stats, 0, sizeof(rx_stats));
2321 hostap_rx(local->dev, skb, &rx_stats);
2325 int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2326 struct iw_quality qual[], int buf_size,
2327 int aplist)
2329 struct ap_data *ap = local->ap;
2330 struct list_head *ptr;
2331 int count = 0;
2333 spin_lock_bh(&ap->sta_table_lock);
2335 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2336 ptr = ptr->next) {
2337 struct sta_info *sta = (struct sta_info *) ptr;
2339 if (aplist && !sta->ap)
2340 continue;
2341 addr[count].sa_family = ARPHRD_ETHER;
2342 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2343 if (sta->last_rx_silence == 0)
2344 qual[count].qual = sta->last_rx_signal < 27 ?
2345 0 : (sta->last_rx_signal - 27) * 92 / 127;
2346 else
2347 qual[count].qual = sta->last_rx_signal -
2348 sta->last_rx_silence - 35;
2349 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2350 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2351 qual[count].updated = sta->last_rx_updated;
2353 sta->last_rx_updated = IW_QUAL_DBM;
2355 count++;
2356 if (count >= buf_size)
2357 break;
2359 spin_unlock_bh(&ap->sta_table_lock);
2361 return count;
2365 /* Translate our list of Access Points & Stations to a card independent
2366 * format that the Wireless Tools will understand - Jean II */
2367 int prism2_ap_translate_scan(struct net_device *dev,
2368 struct iw_request_info *info, char *buffer)
2370 struct hostap_interface *iface;
2371 local_info_t *local;
2372 struct ap_data *ap;
2373 struct list_head *ptr;
2374 struct iw_event iwe;
2375 char *current_ev = buffer;
2376 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2377 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2378 char buf[64];
2379 #endif
2381 iface = netdev_priv(dev);
2382 local = iface->local;
2383 ap = local->ap;
2385 spin_lock_bh(&ap->sta_table_lock);
2387 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2388 ptr = ptr->next) {
2389 struct sta_info *sta = (struct sta_info *) ptr;
2391 /* First entry *MUST* be the AP MAC address */
2392 memset(&iwe, 0, sizeof(iwe));
2393 iwe.cmd = SIOCGIWAP;
2394 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2395 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2396 iwe.len = IW_EV_ADDR_LEN;
2397 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2398 &iwe, IW_EV_ADDR_LEN);
2400 /* Use the mode to indicate if it's a station or
2401 * an Access Point */
2402 memset(&iwe, 0, sizeof(iwe));
2403 iwe.cmd = SIOCGIWMODE;
2404 if (sta->ap)
2405 iwe.u.mode = IW_MODE_MASTER;
2406 else
2407 iwe.u.mode = IW_MODE_INFRA;
2408 iwe.len = IW_EV_UINT_LEN;
2409 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2410 &iwe, IW_EV_UINT_LEN);
2412 /* Some quality */
2413 memset(&iwe, 0, sizeof(iwe));
2414 iwe.cmd = IWEVQUAL;
2415 if (sta->last_rx_silence == 0)
2416 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2417 0 : (sta->last_rx_signal - 27) * 92 / 127;
2418 else
2419 iwe.u.qual.qual = sta->last_rx_signal -
2420 sta->last_rx_silence - 35;
2421 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2422 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2423 iwe.u.qual.updated = sta->last_rx_updated;
2424 iwe.len = IW_EV_QUAL_LEN;
2425 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2426 &iwe, IW_EV_QUAL_LEN);
2428 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2429 if (sta->ap) {
2430 memset(&iwe, 0, sizeof(iwe));
2431 iwe.cmd = SIOCGIWESSID;
2432 iwe.u.data.length = sta->u.ap.ssid_len;
2433 iwe.u.data.flags = 1;
2434 current_ev = iwe_stream_add_point(info, current_ev,
2435 end_buf, &iwe,
2436 sta->u.ap.ssid);
2438 memset(&iwe, 0, sizeof(iwe));
2439 iwe.cmd = SIOCGIWENCODE;
2440 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2441 iwe.u.data.flags =
2442 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2443 else
2444 iwe.u.data.flags = IW_ENCODE_DISABLED;
2445 current_ev = iwe_stream_add_point(info, current_ev,
2446 end_buf, &iwe,
2447 sta->u.ap.ssid);
2449 if (sta->u.ap.channel > 0 &&
2450 sta->u.ap.channel <= FREQ_COUNT) {
2451 memset(&iwe, 0, sizeof(iwe));
2452 iwe.cmd = SIOCGIWFREQ;
2453 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2454 * 100000;
2455 iwe.u.freq.e = 1;
2456 current_ev = iwe_stream_add_event(
2457 info, current_ev, end_buf, &iwe,
2458 IW_EV_FREQ_LEN);
2461 memset(&iwe, 0, sizeof(iwe));
2462 iwe.cmd = IWEVCUSTOM;
2463 sprintf(buf, "beacon_interval=%d",
2464 sta->listen_interval);
2465 iwe.u.data.length = strlen(buf);
2466 current_ev = iwe_stream_add_point(info, current_ev,
2467 end_buf, &iwe, buf);
2469 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2471 sta->last_rx_updated = IW_QUAL_DBM;
2473 /* To be continued, we should make good use of IWEVCUSTOM */
2476 spin_unlock_bh(&ap->sta_table_lock);
2478 return current_ev - buffer;
2482 static int prism2_hostapd_add_sta(struct ap_data *ap,
2483 struct prism2_hostapd_param *param)
2485 struct sta_info *sta;
2487 spin_lock_bh(&ap->sta_table_lock);
2488 sta = ap_get_sta(ap, param->sta_addr);
2489 if (sta)
2490 atomic_inc(&sta->users);
2491 spin_unlock_bh(&ap->sta_table_lock);
2493 if (sta == NULL) {
2494 sta = ap_add_sta(ap, param->sta_addr);
2495 if (sta == NULL)
2496 return -1;
2499 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2500 hostap_event_new_sta(sta->local->dev, sta);
2502 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2503 sta->last_rx = jiffies;
2504 sta->aid = param->u.add_sta.aid;
2505 sta->capability = param->u.add_sta.capability;
2506 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2507 if (sta->tx_supp_rates & WLAN_RATE_1M)
2508 sta->supported_rates[0] = 2;
2509 if (sta->tx_supp_rates & WLAN_RATE_2M)
2510 sta->supported_rates[1] = 4;
2511 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2512 sta->supported_rates[2] = 11;
2513 if (sta->tx_supp_rates & WLAN_RATE_11M)
2514 sta->supported_rates[3] = 22;
2515 prism2_check_tx_rates(sta);
2516 atomic_dec(&sta->users);
2517 return 0;
2521 static int prism2_hostapd_remove_sta(struct ap_data *ap,
2522 struct prism2_hostapd_param *param)
2524 struct sta_info *sta;
2526 spin_lock_bh(&ap->sta_table_lock);
2527 sta = ap_get_sta(ap, param->sta_addr);
2528 if (sta) {
2529 ap_sta_hash_del(ap, sta);
2530 list_del(&sta->list);
2532 spin_unlock_bh(&ap->sta_table_lock);
2534 if (!sta)
2535 return -ENOENT;
2537 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2538 hostap_event_expired_sta(sta->local->dev, sta);
2539 ap_free_sta(ap, sta);
2541 return 0;
2545 static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2546 struct prism2_hostapd_param *param)
2548 struct sta_info *sta;
2550 spin_lock_bh(&ap->sta_table_lock);
2551 sta = ap_get_sta(ap, param->sta_addr);
2552 if (sta)
2553 atomic_inc(&sta->users);
2554 spin_unlock_bh(&ap->sta_table_lock);
2556 if (!sta)
2557 return -ENOENT;
2559 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2561 atomic_dec(&sta->users);
2563 return 1;
2567 static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2568 struct prism2_hostapd_param *param)
2570 struct sta_info *sta;
2572 spin_lock_bh(&ap->sta_table_lock);
2573 sta = ap_get_sta(ap, param->sta_addr);
2574 if (sta) {
2575 sta->flags |= param->u.set_flags_sta.flags_or;
2576 sta->flags &= param->u.set_flags_sta.flags_and;
2578 spin_unlock_bh(&ap->sta_table_lock);
2580 if (!sta)
2581 return -ENOENT;
2583 return 0;
2587 static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2588 struct prism2_hostapd_param *param)
2590 struct sta_info *sta;
2591 int rate;
2593 spin_lock_bh(&ap->sta_table_lock);
2594 sta = ap_get_sta(ap, param->sta_addr);
2595 if (sta) {
2596 sta->rx_packets = sta->tx_packets = 0;
2597 sta->rx_bytes = sta->tx_bytes = 0;
2598 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2599 sta->tx_count[rate] = 0;
2600 sta->rx_count[rate] = 0;
2603 spin_unlock_bh(&ap->sta_table_lock);
2605 if (!sta)
2606 return -ENOENT;
2608 return 0;
2612 int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
2614 switch (param->cmd) {
2615 case PRISM2_HOSTAPD_FLUSH:
2616 ap_control_kickall(ap);
2617 return 0;
2618 case PRISM2_HOSTAPD_ADD_STA:
2619 return prism2_hostapd_add_sta(ap, param);
2620 case PRISM2_HOSTAPD_REMOVE_STA:
2621 return prism2_hostapd_remove_sta(ap, param);
2622 case PRISM2_HOSTAPD_GET_INFO_STA:
2623 return prism2_hostapd_get_info_sta(ap, param);
2624 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2625 return prism2_hostapd_set_flags_sta(ap, param);
2626 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2627 return prism2_hostapd_sta_clear_stats(ap, param);
2628 default:
2629 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2630 param->cmd);
2631 return -EOPNOTSUPP;
2636 /* Update station info for host-based TX rate control and return current
2637 * TX rate */
2638 static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2640 int ret = sta->tx_rate;
2641 struct hostap_interface *iface;
2642 local_info_t *local;
2644 iface = netdev_priv(dev);
2645 local = iface->local;
2647 sta->tx_count[sta->tx_rate_idx]++;
2648 sta->tx_since_last_failure++;
2649 sta->tx_consecutive_exc = 0;
2650 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2651 sta->tx_rate_idx < sta->tx_max_rate) {
2652 /* use next higher rate */
2653 int old_rate, new_rate;
2654 old_rate = new_rate = sta->tx_rate_idx;
2655 while (new_rate < sta->tx_max_rate) {
2656 new_rate++;
2657 if (ap_tx_rate_ok(new_rate, sta, local)) {
2658 sta->tx_rate_idx = new_rate;
2659 break;
2662 if (old_rate != sta->tx_rate_idx) {
2663 switch (sta->tx_rate_idx) {
2664 case 0: sta->tx_rate = 10; break;
2665 case 1: sta->tx_rate = 20; break;
2666 case 2: sta->tx_rate = 55; break;
2667 case 3: sta->tx_rate = 110; break;
2668 default: sta->tx_rate = 0; break;
2670 PDEBUG(DEBUG_AP, "%s: STA %pM TX rate raised to %d\n",
2671 dev->name, sta->addr, sta->tx_rate);
2673 sta->tx_since_last_failure = 0;
2676 return ret;
2680 /* Called only from software IRQ. Called for each TX frame prior possible
2681 * encryption and transmit. */
2682 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2684 struct sta_info *sta = NULL;
2685 struct sk_buff *skb = tx->skb;
2686 int set_tim, ret;
2687 struct ieee80211_hdr *hdr;
2688 struct hostap_skb_tx_data *meta;
2690 meta = (struct hostap_skb_tx_data *) skb->cb;
2691 ret = AP_TX_CONTINUE;
2692 if (local->ap == NULL || skb->len < 10 ||
2693 meta->iface->type == HOSTAP_INTERFACE_STA)
2694 goto out;
2696 hdr = (struct ieee80211_hdr *) skb->data;
2698 if (hdr->addr1[0] & 0x01) {
2699 /* broadcast/multicast frame - no AP related processing */
2700 if (local->ap->num_sta <= 0)
2701 ret = AP_TX_DROP;
2702 goto out;
2705 /* unicast packet - check whether destination STA is associated */
2706 spin_lock(&local->ap->sta_table_lock);
2707 sta = ap_get_sta(local->ap, hdr->addr1);
2708 if (sta)
2709 atomic_inc(&sta->users);
2710 spin_unlock(&local->ap->sta_table_lock);
2712 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2713 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
2714 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2715 meta->iface->type != HOSTAP_INTERFACE_AP) {
2716 #if 0
2717 /* This can happen, e.g., when wlan0 is added to a bridge and
2718 * bridging code does not know which port is the correct target
2719 * for a unicast frame. In this case, the packet is send to all
2720 * ports of the bridge. Since this is a valid scenario, do not
2721 * print out any errors here. */
2722 if (net_ratelimit()) {
2723 printk(KERN_DEBUG "AP: drop packet to non-associated "
2724 "STA %pM\n", hdr->addr1);
2726 #endif
2727 local->ap->tx_drop_nonassoc++;
2728 ret = AP_TX_DROP;
2729 goto out;
2732 if (sta == NULL)
2733 goto out;
2735 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2736 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2738 /* Set tx_rate if using host-based TX rate control */
2739 if (!local->fw_tx_rate_control)
2740 local->ap->last_tx_rate = meta->rate =
2741 ap_update_sta_tx_rate(sta, local->dev);
2743 if (local->iw_mode != IW_MODE_MASTER)
2744 goto out;
2746 if (!(sta->flags & WLAN_STA_PS))
2747 goto out;
2749 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2750 /* indicate to STA that more frames follow */
2751 hdr->frame_control |=
2752 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2755 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2756 /* packet was already buffered and now send due to
2757 * PS poll, so do not rebuffer it */
2758 goto out;
2761 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2762 PDEBUG(DEBUG_PS, "%s: No more space in STA (%pM)'s"
2763 "PS mode buffer\n",
2764 local->dev->name, 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;
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 */
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;
2789 ret = AP_TX_BUFFERED;
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;
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);
2811 return ret;
2815 void hostap_handle_sta_release(void *ptr)
2817 struct sta_info *sta = ptr;
2818 atomic_dec(&sta->users);
2822 /* Called only as a tasklet (software IRQ) */
2823 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2825 struct sta_info *sta;
2826 struct ieee80211_hdr *hdr;
2827 struct hostap_skb_tx_data *meta;
2829 hdr = (struct ieee80211_hdr *) skb->data;
2830 meta = (struct hostap_skb_tx_data *) skb->cb;
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 %pM"
2837 " for this TX error (@%lu)\n",
2838 local->dev->name, hdr->addr1, jiffies);
2839 return;
2842 sta->tx_since_last_failure = 0;
2843 sta->tx_consecutive_exc++;
2845 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;
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;
2865 PDEBUG(DEBUG_AP,
2866 "%s: STA %pM TX rate lowered to %d\n",
2867 local->dev->name, sta->addr, sta->tx_rate);
2869 sta->tx_consecutive_exc = 0;
2871 spin_unlock(&local->ap->sta_table_lock);
2875 static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2876 int pwrmgt, int type, int stype)
2878 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2879 sta->flags |= WLAN_STA_PS;
2880 PDEBUG(DEBUG_PS2, "STA %pM changed to use PS "
2881 "mode (type=0x%02X, stype=0x%02X)\n",
2882 sta->addr, type >> 2, stype >> 4);
2883 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2884 sta->flags &= ~WLAN_STA_PS;
2885 PDEBUG(DEBUG_PS2, "STA %pM changed to not use "
2886 "PS mode (type=0x%02X, stype=0x%02X)\n",
2887 sta->addr, type >> 2, stype >> 4);
2888 if (type != IEEE80211_FTYPE_CTL ||
2889 stype != IEEE80211_STYPE_PSPOLL)
2890 schedule_packet_send(local, sta);
2895 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2896 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2897 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr)
2899 struct sta_info *sta;
2900 u16 fc;
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);
2908 if (!sta)
2909 return -1;
2911 fc = le16_to_cpu(hdr->frame_control);
2912 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
2913 fc & IEEE80211_FCTL_FTYPE,
2914 fc & IEEE80211_FCTL_STYPE);
2916 atomic_dec(&sta->users);
2917 return 0;
2921 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2922 * getting RX header and payload from hardware. */
2923 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2924 struct sk_buff *skb,
2925 struct hostap_80211_rx_status *rx_stats,
2926 int wds)
2928 int ret;
2929 struct sta_info *sta;
2930 u16 fc, type, stype;
2931 struct ieee80211_hdr *hdr;
2933 if (local->ap == NULL)
2934 return AP_RX_CONTINUE;
2936 hdr = (struct ieee80211_hdr *) skb->data;
2938 fc = le16_to_cpu(hdr->frame_control);
2939 type = fc & IEEE80211_FCTL_FTYPE;
2940 stype = fc & IEEE80211_FCTL_STYPE;
2942 spin_lock(&local->ap->sta_table_lock);
2943 sta = ap_get_sta(local->ap, hdr->addr2);
2944 if (sta)
2945 atomic_inc(&sta->users);
2946 spin_unlock(&local->ap->sta_table_lock);
2948 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2949 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2950 else
2951 ret = AP_RX_CONTINUE;
2954 if (fc & IEEE80211_FCTL_TODS) {
2955 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2956 if (local->hostapd) {
2957 prism2_rx_80211(local->apdev, skb, rx_stats,
2958 PRISM2_RX_NON_ASSOC);
2959 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2960 } else {
2961 printk(KERN_DEBUG "%s: dropped received packet"
2962 " from non-associated STA %pM"
2963 " (type=0x%02x, subtype=0x%02x)\n",
2964 dev->name, hdr->addr2,
2965 type >> 2, stype >> 4);
2966 hostap_rx(dev, skb, rx_stats);
2967 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2969 ret = AP_RX_EXIT;
2970 goto out;
2972 } else if (fc & IEEE80211_FCTL_FROMDS) {
2973 if (!wds) {
2974 /* FromDS frame - not for us; probably
2975 * broadcast/multicast in another BSS - drop */
2976 if (ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2977 printk(KERN_DEBUG "Odd.. FromDS packet "
2978 "received with own BSSID\n");
2979 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2981 ret = AP_RX_DROP;
2982 goto out;
2984 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
2985 ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2987 if (local->hostapd) {
2988 prism2_rx_80211(local->apdev, skb, rx_stats,
2989 PRISM2_RX_NON_ASSOC);
2990 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2991 } else {
2992 /* At least Lucent f/w seems to send data::nullfunc
2993 * frames with no ToDS flag when the current AP returns
2994 * after being unavailable for some time. Speed up
2995 * re-association by informing the station about it not
2996 * being associated. */
2997 printk(KERN_DEBUG "%s: rejected received nullfunc frame"
2998 " without ToDS from not associated STA %pM\n",
2999 dev->name, hdr->addr2);
3000 hostap_rx(dev, skb, rx_stats);
3001 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3003 ret = AP_RX_EXIT;
3004 goto out;
3005 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
3006 /* 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 (ether_addr_equal(hdr->addr3, dev->dev_addr)) {
3015 printk(KERN_DEBUG "%s: dropped received packet from %pM"
3016 " with no ToDS flag "
3017 "(type=0x%02x, subtype=0x%02x)\n", dev->name,
3018 hdr->addr2, type >> 2, stype >> 4);
3019 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3021 ret = AP_RX_DROP;
3022 goto out;
3025 if (sta) {
3026 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
3027 type, stype);
3029 sta->rx_packets++;
3030 sta->rx_bytes += skb->len;
3031 sta->last_rx = jiffies;
3034 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
3035 fc & IEEE80211_FCTL_TODS) {
3036 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 */
3049 ret = AP_RX_EXIT;
3050 goto out;
3053 out:
3054 if (sta)
3055 atomic_dec(&sta->users);
3057 return ret;
3061 /* Called only as a tasklet (software IRQ) */
3062 int hostap_handle_sta_crypto(local_info_t *local,
3063 struct ieee80211_hdr *hdr,
3064 struct lib80211_crypt_data **crypt,
3065 void **sta_ptr)
3067 struct sta_info *sta;
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);
3075 if (!sta)
3076 return -1;
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);
3086 return 0;
3090 /* Called only as a tasklet (software IRQ) */
3091 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3093 struct sta_info *sta;
3094 int ret = 0;
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);
3102 return ret;
3106 /* Called only as a tasklet (software IRQ) */
3107 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3109 struct sta_info *sta;
3110 int ret = 0;
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);
3120 return ret;
3124 /* Called only as a tasklet (software IRQ) */
3125 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3127 struct sta_info *sta;
3128 int ret = 1;
3130 if (!ap)
3131 return -1;
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);
3139 if (ret == 1) {
3140 sta = ap_add_sta(ap, sta_addr);
3141 if (!sta)
3142 return -1;
3143 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;
3159 return ret;
3163 /* Called only as a tasklet (software IRQ) */
3164 int hostap_update_rx_stats(struct ap_data *ap,
3165 struct ieee80211_hdr *hdr,
3166 struct hostap_80211_rx_status *rx_stats)
3168 struct sta_info *sta;
3170 if (!ap)
3171 return -1;
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;
3179 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3180 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]++;
3189 spin_unlock(&ap->sta_table_lock);
3191 return sta ? 0 : -1;
3195 void hostap_update_rates(local_info_t *local)
3197 struct sta_info *sta;
3198 struct ap_data *ap = local->ap;
3200 if (!ap)
3201 return;
3203 spin_lock_bh(&ap->sta_table_lock);
3204 list_for_each_entry(sta, &ap->sta_list, list) {
3205 prism2_check_tx_rates(sta);
3207 spin_unlock_bh(&ap->sta_table_lock);
3211 void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3212 struct lib80211_crypt_data ***crypt)
3214 struct sta_info *sta;
3216 spin_lock_bh(&ap->sta_table_lock);
3217 sta = ap_get_sta(ap, addr);
3218 if (sta)
3219 atomic_inc(&sta->users);
3220 spin_unlock_bh(&ap->sta_table_lock);
3222 if (!sta && permanent)
3223 sta = ap_add_sta(ap, addr);
3225 if (!sta)
3226 return NULL;
3228 if (permanent)
3229 sta->flags |= WLAN_STA_PERM;
3231 *crypt = &sta->crypt;
3233 return sta;
3237 void hostap_add_wds_links(local_info_t *local)
3239 struct ap_data *ap = local->ap;
3240 struct sta_info *sta;
3242 spin_lock_bh(&ap->sta_table_lock);
3243 list_for_each_entry(sta, &ap->sta_list, list) {
3244 if (sta->ap)
3245 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3247 spin_unlock_bh(&ap->sta_table_lock);
3249 schedule_work(&local->ap->wds_oper_queue);
3253 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3255 struct wds_oper_data *entry;
3257 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3258 if (!entry)
3259 return;
3260 memcpy(entry->addr, addr, ETH_ALEN);
3261 entry->type = type;
3262 spin_lock_bh(&local->lock);
3263 entry->next = local->ap->wds_oper_entries;
3264 local->ap->wds_oper_entries = entry;
3265 spin_unlock_bh(&local->lock);
3267 schedule_work(&local->ap->wds_oper_queue);
3271 EXPORT_SYMBOL(hostap_init_data);
3272 EXPORT_SYMBOL(hostap_init_ap_proc);
3273 EXPORT_SYMBOL(hostap_free_data);
3274 EXPORT_SYMBOL(hostap_check_sta_fw_version);
3275 EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3276 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3277 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */