1 // SPDX-License-Identifier: GPL-2.0
3 * Intersil Prism2 driver with Host AP (software access point) support
4 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
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
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
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"
32 #include "hostap_ap.h"
34 static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
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,
41 module_param_array(ap_max_inactivity, int, NULL, 0444);
42 MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
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 "
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 "
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 = m->private;
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);
85 static int ap_debug_proc_open(struct inode *inode, struct file *file)
87 return single_open(file, ap_debug_proc_show, PDE_DATA(inode));
90 static const struct file_operations ap_debug_proc_fops = {
91 .open = ap_debug_proc_open,
94 .release = single_release,
96 #endif /* PRISM2_NO_PROCFS_DEBUG */
99 static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
101 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
102 ap->sta_hash[STA_HASH(sta->addr)] = sta;
105 static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
109 s = ap->sta_hash[STA_HASH(sta->addr)];
110 if (s == NULL) return;
111 if (ether_addr_equal(s->addr, sta->addr)) {
112 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
116 while (s->hnext != NULL && !ether_addr_equal(s->hnext->addr, sta->addr))
118 if (s->hnext != NULL)
119 s->hnext = s->hnext->hnext;
121 printk("AP: could not remove STA %pM from hash table\n",
125 static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
127 if (sta->ap && sta->local)
128 hostap_event_expired_sta(sta->local->dev, sta);
130 if (ap->proc != NULL) {
132 sprintf(name, "%pM", sta->addr);
133 remove_proc_entry(name, ap->proc);
137 sta->crypt->ops->deinit(sta->crypt->priv);
142 skb_queue_purge(&sta->tx_buf);
145 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
147 ap->sta_aid[sta->aid - 1] = NULL;
150 kfree(sta->u.sta.challenge);
151 del_timer_sync(&sta->timer);
152 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
158 static void hostap_set_tim(local_info_t *local, int aid, int set)
160 if (local->func->set_tim)
161 local->func->set_tim(local->dev, aid, set);
165 static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
167 union iwreq_data wrqu;
168 memset(&wrqu, 0, sizeof(wrqu));
169 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
170 wrqu.addr.sa_family = ARPHRD_ETHER;
171 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
175 static void hostap_event_expired_sta(struct net_device *dev,
176 struct sta_info *sta)
178 union iwreq_data wrqu;
179 memset(&wrqu, 0, sizeof(wrqu));
180 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
181 wrqu.addr.sa_family = ARPHRD_ETHER;
182 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
186 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
188 static void ap_handle_timer(struct timer_list *t)
190 struct sta_info *sta = from_timer(sta, t, timer);
193 unsigned long next_time = 0;
196 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
197 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
203 was_assoc = sta->flags & WLAN_STA_ASSOC;
205 if (atomic_read(&sta->users) != 0)
206 next_time = jiffies + HZ;
207 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
208 next_time = jiffies + ap->max_inactivity;
210 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
211 /* station activity detected; reset timeout state */
212 sta->timeout_next = STA_NULLFUNC;
213 next_time = sta->last_rx + ap->max_inactivity;
214 } else if (sta->timeout_next == STA_DISASSOC &&
215 !(sta->flags & WLAN_STA_PENDING_POLL)) {
216 /* STA ACKed data nullfunc frame poll */
217 sta->timeout_next = STA_NULLFUNC;
218 next_time = jiffies + ap->max_inactivity;
222 sta->timer.expires = next_time;
223 add_timer(&sta->timer);
228 sta->timeout_next = STA_DEAUTH;
230 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
231 spin_lock(&ap->sta_table_lock);
232 ap_sta_hash_del(ap, sta);
233 list_del(&sta->list);
234 spin_unlock(&ap->sta_table_lock);
235 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
236 } else if (sta->timeout_next == STA_DISASSOC)
237 sta->flags &= ~WLAN_STA_ASSOC;
239 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
240 hostap_event_expired_sta(local->dev, sta);
242 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
243 !skb_queue_empty(&sta->tx_buf)) {
244 hostap_set_tim(local, sta->aid, 0);
245 sta->flags &= ~WLAN_STA_TIM;
249 if (ap->autom_ap_wds) {
250 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
251 "connection to AP %pM\n",
252 local->dev->name, sta->addr);
253 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
255 } else if (sta->timeout_next == STA_NULLFUNC) {
256 /* send data frame to poll STA and check whether this frame
258 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
259 * it is apparently not retried so TX Exc events are not
261 sta->flags |= WLAN_STA_PENDING_POLL;
262 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
263 IEEE80211_STYPE_DATA, NULL, 0,
264 sta->addr, ap->tx_callback_poll);
266 int deauth = sta->timeout_next == STA_DEAUTH;
268 PDEBUG(DEBUG_AP, "%s: sending %s info to STA %pM"
269 "(last=%lu, jiffies=%lu)\n",
271 deauth ? "deauthentication" : "disassociation",
272 sta->addr, sta->last_rx, jiffies);
274 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
275 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
276 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
277 (deauth ? IEEE80211_STYPE_DEAUTH :
278 IEEE80211_STYPE_DISASSOC),
279 (char *) &resp, 2, sta->addr, 0);
282 if (sta->timeout_next == STA_DEAUTH) {
283 if (sta->flags & WLAN_STA_PERM) {
284 PDEBUG(DEBUG_AP, "%s: STA %pM"
285 " would have been removed, "
286 "but it has 'perm' flag\n",
287 local->dev->name, sta->addr);
289 ap_free_sta(ap, sta);
293 if (sta->timeout_next == STA_NULLFUNC) {
294 sta->timeout_next = STA_DISASSOC;
295 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
297 sta->timeout_next = STA_DEAUTH;
298 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
301 add_timer(&sta->timer);
305 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
312 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
313 eth_broadcast_addr(addr);
315 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
317 /* deauth message sent; try to resend it few times; the message is
318 * broadcast, so it may be delayed until next DTIM; there is not much
319 * else we can do at this point since the driver is going to be shut
321 for (i = 0; i < 5; i++) {
322 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
323 IEEE80211_STYPE_DEAUTH,
324 (char *) &resp, 2, addr, 0);
326 if (!resend || ap->num_sta <= 0)
334 static int ap_control_proc_show(struct seq_file *m, void *v)
336 struct ap_data *ap = m->private;
338 struct mac_entry *entry;
340 if (v == SEQ_START_TOKEN) {
341 switch (ap->mac_restrictions.policy) {
342 case MAC_POLICY_OPEN:
345 case MAC_POLICY_ALLOW:
346 policy_txt = "allow";
348 case MAC_POLICY_DENY:
352 policy_txt = "unknown";
355 seq_printf(m, "MAC policy: %s\n", policy_txt);
356 seq_printf(m, "MAC entries: %u\n", ap->mac_restrictions.entries);
357 seq_puts(m, "MAC list:\n");
362 seq_printf(m, "%pM\n", entry->addr);
366 static void *ap_control_proc_start(struct seq_file *m, loff_t *_pos)
368 struct ap_data *ap = m->private;
369 spin_lock_bh(&ap->mac_restrictions.lock);
370 return seq_list_start_head(&ap->mac_restrictions.mac_list, *_pos);
373 static void *ap_control_proc_next(struct seq_file *m, void *v, loff_t *_pos)
375 struct ap_data *ap = m->private;
376 return seq_list_next(v, &ap->mac_restrictions.mac_list, _pos);
379 static void ap_control_proc_stop(struct seq_file *m, void *v)
381 struct ap_data *ap = m->private;
382 spin_unlock_bh(&ap->mac_restrictions.lock);
385 static const struct seq_operations ap_control_proc_seqops = {
386 .start = ap_control_proc_start,
387 .next = ap_control_proc_next,
388 .stop = ap_control_proc_stop,
389 .show = ap_control_proc_show,
392 static int ap_control_proc_open(struct inode *inode, struct file *file)
394 int ret = seq_open(file, &ap_control_proc_seqops);
396 struct seq_file *m = file->private_data;
397 m->private = PDE_DATA(inode);
402 static const struct file_operations ap_control_proc_fops = {
403 .open = ap_control_proc_open,
406 .release = seq_release,
410 int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
412 struct mac_entry *entry;
414 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
418 memcpy(entry->addr, mac, ETH_ALEN);
420 spin_lock_bh(&mac_restrictions->lock);
421 list_add_tail(&entry->list, &mac_restrictions->mac_list);
422 mac_restrictions->entries++;
423 spin_unlock_bh(&mac_restrictions->lock);
429 int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
431 struct list_head *ptr;
432 struct mac_entry *entry;
434 spin_lock_bh(&mac_restrictions->lock);
435 for (ptr = mac_restrictions->mac_list.next;
436 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
437 entry = list_entry(ptr, struct mac_entry, list);
439 if (ether_addr_equal(entry->addr, mac)) {
442 mac_restrictions->entries--;
443 spin_unlock_bh(&mac_restrictions->lock);
447 spin_unlock_bh(&mac_restrictions->lock);
452 static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
455 struct mac_entry *entry;
458 if (mac_restrictions->policy == MAC_POLICY_OPEN)
461 spin_lock_bh(&mac_restrictions->lock);
462 list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
463 if (ether_addr_equal(entry->addr, mac)) {
468 spin_unlock_bh(&mac_restrictions->lock);
470 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
477 void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
479 struct list_head *ptr, *n;
480 struct mac_entry *entry;
482 if (mac_restrictions->entries == 0)
485 spin_lock_bh(&mac_restrictions->lock);
486 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
487 ptr != &mac_restrictions->mac_list;
488 ptr = n, n = ptr->next) {
489 entry = list_entry(ptr, struct mac_entry, list);
493 mac_restrictions->entries = 0;
494 spin_unlock_bh(&mac_restrictions->lock);
498 int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
500 struct sta_info *sta;
503 spin_lock_bh(&ap->sta_table_lock);
504 sta = ap_get_sta(ap, mac);
506 ap_sta_hash_del(ap, sta);
507 list_del(&sta->list);
509 spin_unlock_bh(&ap->sta_table_lock);
514 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
515 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
516 (char *) &resp, 2, sta->addr, 0);
518 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
519 hostap_event_expired_sta(dev, sta);
521 ap_free_sta(ap, sta);
526 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
529 void ap_control_kickall(struct ap_data *ap)
531 struct list_head *ptr, *n;
532 struct sta_info *sta;
534 spin_lock_bh(&ap->sta_table_lock);
535 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
536 ptr = n, n = ptr->next) {
537 sta = list_entry(ptr, struct sta_info, list);
538 ap_sta_hash_del(ap, sta);
539 list_del(&sta->list);
540 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
541 hostap_event_expired_sta(sta->local->dev, sta);
542 ap_free_sta(ap, sta);
544 spin_unlock_bh(&ap->sta_table_lock);
548 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
550 static int prism2_ap_proc_show(struct seq_file *m, void *v)
552 struct sta_info *sta = v;
555 if (v == SEQ_START_TOKEN) {
556 seq_printf(m, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
563 seq_printf(m, "%pM %d %d %d %d '",
565 sta->u.ap.channel, sta->last_rx_signal,
566 sta->last_rx_silence, sta->last_rx_rate);
568 for (i = 0; i < sta->u.ap.ssid_len; i++) {
569 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
570 seq_putc(m, sta->u.ap.ssid[i]);
572 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
576 if (sta->capability & WLAN_CAPABILITY_ESS)
577 seq_puts(m, " [ESS]");
578 if (sta->capability & WLAN_CAPABILITY_IBSS)
579 seq_puts(m, " [IBSS]");
580 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
581 seq_puts(m, " [WEP]");
586 static void *prism2_ap_proc_start(struct seq_file *m, loff_t *_pos)
588 struct ap_data *ap = m->private;
589 spin_lock_bh(&ap->sta_table_lock);
590 return seq_list_start_head(&ap->sta_list, *_pos);
593 static void *prism2_ap_proc_next(struct seq_file *m, void *v, loff_t *_pos)
595 struct ap_data *ap = m->private;
596 return seq_list_next(v, &ap->sta_list, _pos);
599 static void prism2_ap_proc_stop(struct seq_file *m, void *v)
601 struct ap_data *ap = m->private;
602 spin_unlock_bh(&ap->sta_table_lock);
605 static const struct seq_operations prism2_ap_proc_seqops = {
606 .start = prism2_ap_proc_start,
607 .next = prism2_ap_proc_next,
608 .stop = prism2_ap_proc_stop,
609 .show = prism2_ap_proc_show,
612 static int prism2_ap_proc_open(struct inode *inode, struct file *file)
614 int ret = seq_open(file, &prism2_ap_proc_seqops);
616 struct seq_file *m = file->private_data;
617 m->private = PDE_DATA(inode);
622 static const struct file_operations prism2_ap_proc_fops = {
623 .open = prism2_ap_proc_open,
626 .release = seq_release,
628 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
631 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
636 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
637 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
638 "firmware upgrade recommended\n");
639 ap->nullfunc_ack = 1;
641 ap->nullfunc_ack = 0;
643 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
644 printk(KERN_WARNING "%s: Warning: secondary station firmware "
645 "version 1.4.2 does not seem to work in Host AP mode\n",
646 ap->local->dev->name);
651 /* Called only as a tasklet (software IRQ) */
652 static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
654 struct ap_data *ap = data;
655 struct ieee80211_hdr *hdr;
657 if (!ap->local->hostapd || !ap->local->apdev) {
662 /* Pass the TX callback frame to the hostapd; use 802.11 header version
663 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
665 hdr = (struct ieee80211_hdr *) skb->data;
666 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_VERS);
667 hdr->frame_control |= cpu_to_le16(ok ? BIT(1) : BIT(0));
669 skb->dev = ap->local->apdev;
670 skb_pull(skb, hostap_80211_get_hdrlen(hdr->frame_control));
671 skb->pkt_type = PACKET_OTHERHOST;
672 skb->protocol = cpu_to_be16(ETH_P_802_2);
673 memset(skb->cb, 0, sizeof(skb->cb));
678 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
679 /* Called only as a tasklet (software IRQ) */
680 static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
682 struct ap_data *ap = data;
683 struct net_device *dev = ap->local->dev;
684 struct ieee80211_hdr *hdr;
685 u16 auth_alg, auth_transaction, status;
687 struct sta_info *sta = NULL;
690 if (ap->local->hostapd) {
695 hdr = (struct ieee80211_hdr *) skb->data;
696 if (!ieee80211_is_auth(hdr->frame_control) ||
697 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
698 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
699 "frame\n", dev->name);
704 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
705 auth_alg = le16_to_cpu(*pos++);
706 auth_transaction = le16_to_cpu(*pos++);
707 status = le16_to_cpu(*pos++);
710 txt = "frame was not ACKed";
714 spin_lock(&ap->sta_table_lock);
715 sta = ap_get_sta(ap, hdr->addr1);
717 atomic_inc(&sta->users);
718 spin_unlock(&ap->sta_table_lock);
721 txt = "STA not found";
725 if (status == WLAN_STATUS_SUCCESS &&
726 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
727 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
728 txt = "STA authenticated";
729 sta->flags |= WLAN_STA_AUTH;
730 sta->last_auth = jiffies;
731 } else if (status != WLAN_STATUS_SUCCESS)
732 txt = "authentication failed";
736 atomic_dec(&sta->users);
738 PDEBUG(DEBUG_AP, "%s: %pM auth_cb - alg=%d "
739 "trans#=%d status=%d - %s\n",
740 dev->name, hdr->addr1,
741 auth_alg, auth_transaction, status, txt);
747 /* Called only as a tasklet (software IRQ) */
748 static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
750 struct ap_data *ap = data;
751 struct net_device *dev = ap->local->dev;
752 struct ieee80211_hdr *hdr;
755 struct sta_info *sta = NULL;
758 if (ap->local->hostapd) {
763 hdr = (struct ieee80211_hdr *) skb->data;
764 if ((!ieee80211_is_assoc_resp(hdr->frame_control) &&
765 !ieee80211_is_reassoc_resp(hdr->frame_control)) ||
766 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
767 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
768 "frame\n", dev->name);
774 txt = "frame was not ACKed";
778 spin_lock(&ap->sta_table_lock);
779 sta = ap_get_sta(ap, hdr->addr1);
781 atomic_inc(&sta->users);
782 spin_unlock(&ap->sta_table_lock);
785 txt = "STA not found";
789 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
791 status = le16_to_cpu(*pos++);
792 if (status == WLAN_STATUS_SUCCESS) {
793 if (!(sta->flags & WLAN_STA_ASSOC))
794 hostap_event_new_sta(dev, sta);
795 txt = "STA associated";
796 sta->flags |= WLAN_STA_ASSOC;
797 sta->last_assoc = jiffies;
799 txt = "association failed";
803 atomic_dec(&sta->users);
805 PDEBUG(DEBUG_AP, "%s: %pM assoc_cb - %s\n",
806 dev->name, hdr->addr1, txt);
811 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
812 * in verifying whether the STA is still present. */
813 static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
815 struct ap_data *ap = data;
816 struct ieee80211_hdr *hdr;
817 struct sta_info *sta;
821 hdr = (struct ieee80211_hdr *) skb->data;
823 spin_lock(&ap->sta_table_lock);
824 sta = ap_get_sta(ap, hdr->addr1);
826 sta->flags &= ~WLAN_STA_PENDING_POLL;
827 spin_unlock(&ap->sta_table_lock);
830 "%s: STA %pM did not ACK activity poll frame\n",
831 ap->local->dev->name, hdr->addr1);
837 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
840 void hostap_init_data(local_info_t *local)
842 struct ap_data *ap = local->ap;
845 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
848 memset(ap, 0, sizeof(struct ap_data));
851 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
852 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
854 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
855 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
857 spin_lock_init(&ap->sta_table_lock);
858 INIT_LIST_HEAD(&ap->sta_list);
860 /* Initialize task queue structure for AP management */
861 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
863 ap->tx_callback_idx =
864 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
865 if (ap->tx_callback_idx == 0)
866 printk(KERN_WARNING "%s: failed to register TX callback for "
867 "AP\n", local->dev->name);
868 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
869 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
871 ap->tx_callback_auth =
872 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
873 ap->tx_callback_assoc =
874 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
875 ap->tx_callback_poll =
876 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
877 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
878 ap->tx_callback_poll == 0)
879 printk(KERN_WARNING "%s: failed to register TX callback for "
880 "AP\n", local->dev->name);
882 spin_lock_init(&ap->mac_restrictions.lock);
883 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
884 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
890 void hostap_init_ap_proc(local_info_t *local)
892 struct ap_data *ap = local->ap;
894 ap->proc = local->proc;
895 if (ap->proc == NULL)
898 #ifndef PRISM2_NO_PROCFS_DEBUG
899 proc_create_data("ap_debug", 0, ap->proc, &ap_debug_proc_fops, ap);
900 #endif /* PRISM2_NO_PROCFS_DEBUG */
902 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
903 proc_create_data("ap_control", 0, ap->proc, &ap_control_proc_fops, ap);
904 proc_create_data("ap", 0, ap->proc, &prism2_ap_proc_fops, ap);
905 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
910 void hostap_free_data(struct ap_data *ap)
912 struct sta_info *n, *sta;
914 if (ap == NULL || !ap->initialized) {
915 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
916 "initialized - skip resource freeing\n");
920 flush_work(&ap->add_sta_proc_queue);
922 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
923 flush_work(&ap->wds_oper_queue);
925 ap->crypt->deinit(ap->crypt_priv);
926 ap->crypt = ap->crypt_priv = NULL;
927 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
929 list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
930 ap_sta_hash_del(ap, sta);
931 list_del(&sta->list);
932 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
933 hostap_event_expired_sta(sta->local->dev, sta);
934 ap_free_sta(ap, sta);
937 #ifndef PRISM2_NO_PROCFS_DEBUG
938 if (ap->proc != NULL) {
939 remove_proc_entry("ap_debug", ap->proc);
941 #endif /* PRISM2_NO_PROCFS_DEBUG */
943 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
944 if (ap->proc != NULL) {
945 remove_proc_entry("ap", ap->proc);
946 remove_proc_entry("ap_control", ap->proc);
948 ap_control_flush_macs(&ap->mac_restrictions);
949 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
955 /* caller should have mutex for AP STA list handling */
956 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
960 s = ap->sta_hash[STA_HASH(sta)];
961 while (s != NULL && !ether_addr_equal(s->addr, sta))
967 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
969 /* Called from timer handler and from scheduled AP queue handlers */
970 static void prism2_send_mgmt(struct net_device *dev,
971 u16 type_subtype, char *body,
972 int body_len, u8 *addr, u16 tx_cb_idx)
974 struct hostap_interface *iface;
976 struct ieee80211_hdr *hdr;
979 struct hostap_skb_tx_data *meta;
982 iface = netdev_priv(dev);
983 local = iface->local;
984 dev = local->dev; /* always use master radio device */
985 iface = netdev_priv(dev);
987 if (!(dev->flags & IFF_UP)) {
988 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
989 "cannot send frame\n", dev->name);
993 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
995 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
1001 hdrlen = hostap_80211_get_hdrlen(cpu_to_le16(type_subtype));
1002 hdr = skb_put_zero(skb, hdrlen);
1004 skb_put_data(skb, body, body_len);
1006 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
1007 * tx_control instead of using local->tx_control */
1010 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
1011 if (ieee80211_is_data(hdr->frame_control)) {
1012 fc |= IEEE80211_FCTL_FROMDS;
1013 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
1014 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
1015 } else if (ieee80211_is_ctl(hdr->frame_control)) {
1016 /* control:ACK does not have addr2 or addr3 */
1017 eth_zero_addr(hdr->addr2);
1018 eth_zero_addr(hdr->addr3);
1020 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
1021 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
1024 hdr->frame_control = cpu_to_le16(fc);
1026 meta = (struct hostap_skb_tx_data *) skb->cb;
1027 memset(meta, 0, sizeof(*meta));
1028 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1029 meta->iface = iface;
1030 meta->tx_cb_idx = tx_cb_idx;
1033 skb_reset_mac_header(skb);
1034 skb_reset_network_header(skb);
1035 dev_queue_xmit(skb);
1037 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1040 static int prism2_sta_proc_show(struct seq_file *m, void *v)
1042 struct sta_info *sta = m->private;
1045 /* FIX: possible race condition.. the STA data could have just expired,
1046 * but proc entry was still here so that the read could have started;
1047 * some locking should be done here.. */
1050 "%s=%pM\nusers=%d\naid=%d\n"
1051 "flags=0x%04x%s%s%s%s%s%s%s\n"
1052 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1053 sta->ap ? "AP" : "STA",
1054 sta->addr, atomic_read(&sta->users), sta->aid,
1056 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1057 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1058 sta->flags & WLAN_STA_PS ? " PS" : "",
1059 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1060 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1061 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1062 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1063 sta->capability, sta->listen_interval);
1064 /* supported_rates: 500 kbit/s units with msb ignored */
1065 for (i = 0; i < sizeof(sta->supported_rates); i++)
1066 if (sta->supported_rates[i] != 0)
1067 seq_printf(m, "%d%sMbps ",
1068 (sta->supported_rates[i] & 0x7f) / 2,
1069 sta->supported_rates[i] & 1 ? ".5" : "");
1071 "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1072 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1074 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1075 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1076 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1078 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1079 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1081 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1082 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1083 sta->last_rx_silence,
1084 sta->last_rx_signal, sta->last_rx_rate / 10,
1085 sta->last_rx_rate % 10 ? ".5" : "",
1086 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1087 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1088 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1089 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1090 sta->crypt->ops->print_stats(m, sta->crypt->priv);
1091 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1093 if (sta->u.ap.channel >= 0)
1094 seq_printf(m, "channel=%d\n", sta->u.ap.channel);
1095 seq_puts(m, "ssid=");
1096 for (i = 0; i < sta->u.ap.ssid_len; i++) {
1097 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
1098 seq_putc(m, sta->u.ap.ssid[i]);
1100 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
1104 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1109 static void handle_add_proc_queue(struct work_struct *work)
1111 struct ap_data *ap = container_of(work, struct ap_data,
1112 add_sta_proc_queue);
1113 struct sta_info *sta;
1115 struct add_sta_proc_data *entry, *prev;
1117 entry = ap->add_sta_proc_entries;
1118 ap->add_sta_proc_entries = NULL;
1121 spin_lock_bh(&ap->sta_table_lock);
1122 sta = ap_get_sta(ap, entry->addr);
1124 atomic_inc(&sta->users);
1125 spin_unlock_bh(&ap->sta_table_lock);
1128 sprintf(name, "%pM", sta->addr);
1129 sta->proc = proc_create_single_data(
1131 prism2_sta_proc_show, sta);
1133 atomic_dec(&sta->users);
1137 entry = entry->next;
1143 static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1145 struct sta_info *sta;
1147 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
1149 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1153 /* initialize STA info data */
1154 sta->local = ap->local;
1155 skb_queue_head_init(&sta->tx_buf);
1156 memcpy(sta->addr, addr, ETH_ALEN);
1158 atomic_inc(&sta->users);
1159 spin_lock_bh(&ap->sta_table_lock);
1160 list_add(&sta->list, &ap->sta_list);
1162 ap_sta_hash_add(ap, sta);
1163 spin_unlock_bh(&ap->sta_table_lock);
1166 struct add_sta_proc_data *entry;
1167 /* schedule a non-interrupt context process to add a procfs
1168 * entry for the STA since procfs code use GFP_KERNEL */
1169 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1171 memcpy(entry->addr, sta->addr, ETH_ALEN);
1172 entry->next = ap->add_sta_proc_entries;
1173 ap->add_sta_proc_entries = entry;
1174 schedule_work(&ap->add_sta_proc_queue);
1176 printk(KERN_DEBUG "Failed to add STA proc data\n");
1179 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1180 timer_setup(&sta->timer, ap_handle_timer, 0);
1181 sta->timer.expires = jiffies + ap->max_inactivity;
1182 if (!ap->local->hostapd)
1183 add_timer(&sta->timer);
1184 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1190 static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1191 local_info_t *local)
1193 if (rateidx > sta->tx_max_rate ||
1194 !(sta->tx_supp_rates & (1 << rateidx)))
1197 if (local->tx_rate_control != 0 &&
1198 !(local->tx_rate_control & (1 << rateidx)))
1205 static void prism2_check_tx_rates(struct sta_info *sta)
1209 sta->tx_supp_rates = 0;
1210 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1211 if ((sta->supported_rates[i] & 0x7f) == 2)
1212 sta->tx_supp_rates |= WLAN_RATE_1M;
1213 if ((sta->supported_rates[i] & 0x7f) == 4)
1214 sta->tx_supp_rates |= WLAN_RATE_2M;
1215 if ((sta->supported_rates[i] & 0x7f) == 11)
1216 sta->tx_supp_rates |= WLAN_RATE_5M5;
1217 if ((sta->supported_rates[i] & 0x7f) == 22)
1218 sta->tx_supp_rates |= WLAN_RATE_11M;
1220 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1221 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1222 sta->tx_max_rate = 0;
1223 if (ap_tx_rate_ok(0, sta, sta->local)) {
1225 sta->tx_rate_idx = 0;
1228 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1229 sta->tx_max_rate = 1;
1230 if (ap_tx_rate_ok(1, sta, sta->local)) {
1232 sta->tx_rate_idx = 1;
1235 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1236 sta->tx_max_rate = 2;
1237 if (ap_tx_rate_ok(2, sta, sta->local)) {
1239 sta->tx_rate_idx = 2;
1242 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1243 sta->tx_max_rate = 3;
1244 if (ap_tx_rate_ok(3, sta, sta->local)) {
1246 sta->tx_rate_idx = 3;
1252 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1254 static void ap_crypt_init(struct ap_data *ap)
1256 ap->crypt = lib80211_get_crypto_ops("WEP");
1259 if (ap->crypt->init) {
1260 ap->crypt_priv = ap->crypt->init(0);
1261 if (ap->crypt_priv == NULL)
1264 u8 key[WEP_KEY_LEN];
1265 get_random_bytes(key, WEP_KEY_LEN);
1266 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1272 if (ap->crypt == NULL) {
1273 printk(KERN_WARNING "AP could not initialize WEP: load module "
1274 "lib80211_crypt_wep.ko\n");
1279 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1280 * that WEP algorithm is used for generating challenge. This should be unique,
1281 * but otherwise there is not really need for randomness etc. Initialize WEP
1282 * with pseudo random key and then use increasing IV to get unique challenge
1285 * Called only as a scheduled task for pending AP frames.
1287 static char * ap_auth_make_challenge(struct ap_data *ap)
1290 struct sk_buff *skb;
1292 if (ap->crypt == NULL) {
1294 if (ap->crypt == NULL)
1298 tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1299 if (tmpbuf == NULL) {
1300 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1304 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1305 ap->crypt->extra_mpdu_prefix_len +
1306 ap->crypt->extra_mpdu_postfix_len);
1312 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
1313 skb_put_zero(skb, WLAN_AUTH_CHALLENGE_LEN);
1314 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1320 skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
1321 tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
1328 /* Called only as a scheduled task for pending AP frames. */
1329 static void handle_authen(local_info_t *local, struct sk_buff *skb,
1330 struct hostap_80211_rx_status *rx_stats)
1332 struct net_device *dev = local->dev;
1333 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1335 struct ap_data *ap = local->ap;
1336 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1338 u16 auth_alg, auth_transaction, status_code;
1340 u16 resp = WLAN_STATUS_SUCCESS;
1341 struct sta_info *sta = NULL;
1342 struct lib80211_crypt_data *crypt;
1345 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1347 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
1350 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1351 "(len=%d) from %pM\n", dev->name, len, hdr->addr2);
1355 spin_lock_bh(&local->ap->sta_table_lock);
1356 sta = ap_get_sta(local->ap, hdr->addr2);
1358 atomic_inc(&sta->users);
1359 spin_unlock_bh(&local->ap->sta_table_lock);
1361 if (sta && sta->crypt)
1365 if (skb->len >= hdrlen + 3)
1366 idx = skb->data[hdrlen + 3] >> 6;
1367 crypt = local->crypt_info.crypt[idx];
1370 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1371 auth_alg = __le16_to_cpu(*pos);
1373 auth_transaction = __le16_to_cpu(*pos);
1375 status_code = __le16_to_cpu(*pos);
1378 if (ether_addr_equal(dev->dev_addr, hdr->addr2) ||
1379 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1380 txt = "authentication denied";
1381 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1385 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1386 auth_alg == WLAN_AUTH_OPEN) ||
1387 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1388 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1390 txt = "unsupported algorithm";
1391 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1397 if (*u == WLAN_EID_CHALLENGE) {
1398 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1399 txt = "invalid challenge len";
1400 resp = WLAN_STATUS_CHALLENGE_FAIL;
1403 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1404 txt = "challenge underflow";
1405 resp = WLAN_STATUS_CHALLENGE_FAIL;
1408 challenge = (char *) (u + 2);
1412 if (sta && sta->ap) {
1413 if (time_after(jiffies, sta->u.ap.last_beacon +
1414 (10 * sta->listen_interval * HZ) / 1024)) {
1415 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1416 " assuming AP %pM is now STA\n",
1417 dev->name, sta->addr);
1420 sta->u.sta.challenge = NULL;
1422 txt = "AP trying to authenticate?";
1423 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1428 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1429 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1430 (auth_transaction == 1 ||
1431 (auth_transaction == 3 && sta != NULL &&
1432 sta->u.sta.challenge != NULL)))) {
1434 txt = "unknown authentication transaction number";
1435 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1442 if (local->ap->num_sta >= MAX_STA_COUNT) {
1443 /* FIX: might try to remove some old STAs first? */
1444 txt = "no more room for new STAs";
1445 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1449 sta = ap_add_sta(local->ap, hdr->addr2);
1451 txt = "ap_add_sta failed";
1452 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1458 case WLAN_AUTH_OPEN:
1460 /* IEEE 802.11 standard is not completely clear about
1461 * whether STA is considered authenticated after
1462 * authentication OK frame has been send or after it
1463 * has been ACKed. In order to reduce interoperability
1464 * issues, mark the STA authenticated before ACK. */
1465 sta->flags |= WLAN_STA_AUTH;
1468 case WLAN_AUTH_SHARED_KEY:
1469 if (auth_transaction == 1) {
1470 if (sta->u.sta.challenge == NULL) {
1471 sta->u.sta.challenge =
1472 ap_auth_make_challenge(local->ap);
1473 if (sta->u.sta.challenge == NULL) {
1474 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1479 if (sta->u.sta.challenge == NULL ||
1480 challenge == NULL ||
1481 memcmp(sta->u.sta.challenge, challenge,
1482 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
1483 !ieee80211_has_protected(hdr->frame_control)) {
1484 txt = "challenge response incorrect";
1485 resp = WLAN_STATUS_CHALLENGE_FAIL;
1489 txt = "challenge OK - authOK";
1490 /* IEEE 802.11 standard is not completely clear about
1491 * whether STA is considered authenticated after
1492 * authentication OK frame has been send or after it
1493 * has been ACKed. In order to reduce interoperability
1494 * issues, mark the STA authenticated before ACK. */
1495 sta->flags |= WLAN_STA_AUTH;
1496 kfree(sta->u.sta.challenge);
1497 sta->u.sta.challenge = NULL;
1503 pos = (__le16 *) body;
1504 *pos = cpu_to_le16(auth_alg);
1506 *pos = cpu_to_le16(auth_transaction + 1);
1508 *pos = cpu_to_le16(resp); /* status_code */
1512 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1513 sta->u.sta.challenge != NULL &&
1514 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1515 u8 *tmp = (u8 *) pos;
1516 *tmp++ = WLAN_EID_CHALLENGE;
1517 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1519 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1520 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1523 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
1524 body, olen, hdr->addr2, ap->tx_callback_auth);
1527 sta->last_rx = jiffies;
1528 atomic_dec(&sta->users);
1532 PDEBUG(DEBUG_AP, "%s: %pM auth (alg=%d "
1533 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1534 dev->name, hdr->addr2,
1535 auth_alg, auth_transaction, status_code, len,
1536 le16_to_cpu(hdr->frame_control), resp, txt);
1541 /* Called only as a scheduled task for pending AP frames. */
1542 static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1543 struct hostap_80211_rx_status *rx_stats, int reassoc)
1545 struct net_device *dev = local->dev;
1546 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1547 char body[12], *p, *lpos;
1550 u16 resp = WLAN_STATUS_SUCCESS;
1551 struct sta_info *sta = NULL;
1552 int send_deauth = 0;
1554 u8 prev_ap[ETH_ALEN];
1556 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1558 if (len < (reassoc ? 10 : 4)) {
1559 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1560 "(len=%d, reassoc=%d) from %pM\n",
1561 dev->name, len, reassoc, hdr->addr2);
1565 spin_lock_bh(&local->ap->sta_table_lock);
1566 sta = ap_get_sta(local->ap, hdr->addr2);
1567 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1568 spin_unlock_bh(&local->ap->sta_table_lock);
1569 txt = "trying to associate before authentication";
1571 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1572 sta = NULL; /* do not decrement sta->users */
1575 atomic_inc(&sta->users);
1576 spin_unlock_bh(&local->ap->sta_table_lock);
1578 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1579 sta->capability = __le16_to_cpu(*pos);
1581 sta->listen_interval = __le16_to_cpu(*pos);
1585 memcpy(prev_ap, pos, ETH_ALEN);
1586 pos++; pos++; pos++; left -= 6;
1588 eth_zero_addr(prev_ap);
1592 unsigned char *u = (unsigned char *) pos;
1594 if (*u == WLAN_EID_SSID) {
1599 if (ileft > left || ileft > MAX_SSID_LEN) {
1600 txt = "SSID overflow";
1601 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1605 if (ileft != strlen(local->essid) ||
1606 memcmp(local->essid, u, ileft) != 0) {
1607 txt = "not our SSID";
1608 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1616 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1621 if (ileft > left || ileft == 0 ||
1622 ileft > WLAN_SUPP_RATES_MAX) {
1623 txt = "SUPP_RATES len error";
1624 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1628 memset(sta->supported_rates, 0,
1629 sizeof(sta->supported_rates));
1630 memcpy(sta->supported_rates, u, ileft);
1631 prism2_check_tx_rates(sta);
1638 PDEBUG(DEBUG_AP, "%s: assoc from %pM"
1639 " with extra data (%d bytes) [",
1640 dev->name, hdr->addr2, left);
1642 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1645 PDEBUG2(DEBUG_AP, "]\n");
1648 txt = "frame underflow";
1649 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1653 /* get a unique AID */
1655 txt = "OK, old AID";
1657 spin_lock_bh(&local->ap->sta_table_lock);
1658 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1659 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1661 if (sta->aid > MAX_AID_TABLE_SIZE) {
1663 spin_unlock_bh(&local->ap->sta_table_lock);
1664 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1665 txt = "no room for more AIDs";
1667 local->ap->sta_aid[sta->aid - 1] = sta;
1668 spin_unlock_bh(&local->ap->sta_table_lock);
1669 txt = "OK, new AID";
1674 pos = (__le16 *) body;
1677 *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1680 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1681 * values in beacons/probe responses */
1682 /* FIX: how about privacy and WEP? */
1684 *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
1688 *pos = cpu_to_le16(resp);
1691 *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1692 BIT(14) | BIT(15)); /* AID */
1695 /* Supported rates (Information element) */
1697 *p++ = WLAN_EID_SUPP_RATES;
1700 if (local->tx_rate_control & WLAN_RATE_1M) {
1701 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1704 if (local->tx_rate_control & WLAN_RATE_2M) {
1705 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1708 if (local->tx_rate_control & WLAN_RATE_5M5) {
1709 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1713 if (local->tx_rate_control & WLAN_RATE_11M) {
1714 *p++ = local->basic_rates & WLAN_RATE_11M ?
1721 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1722 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1723 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1724 IEEE80211_STYPE_ASSOC_RESP)),
1725 body, (u8 *) pos - (u8 *) body,
1727 send_deauth ? 0 : local->ap->tx_callback_assoc);
1730 if (resp == WLAN_STATUS_SUCCESS) {
1731 sta->last_rx = jiffies;
1732 /* STA will be marked associated from TX callback, if
1733 * AssocResp is ACKed */
1735 atomic_dec(&sta->users);
1739 PDEBUG(DEBUG_AP, "%s: %pM %sassoc (len=%d "
1740 "prev_ap=%pM) => %d(%d) (%s)\n",
1743 reassoc ? "re" : "", len,
1745 resp, send_deauth, txt);
1750 /* Called only as a scheduled task for pending AP frames. */
1751 static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1752 struct hostap_80211_rx_status *rx_stats)
1754 struct net_device *dev = local->dev;
1755 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1756 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1760 struct sta_info *sta = NULL;
1762 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1765 printk("handle_deauth - too short payload (len=%d)\n", len);
1769 pos = (__le16 *) body;
1770 reason_code = le16_to_cpu(*pos);
1772 PDEBUG(DEBUG_AP, "%s: deauthentication: %pM len=%d, "
1773 "reason_code=%d\n", dev->name, hdr->addr2,
1776 spin_lock_bh(&local->ap->sta_table_lock);
1777 sta = ap_get_sta(local->ap, hdr->addr2);
1779 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1780 hostap_event_expired_sta(local->dev, sta);
1781 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1783 spin_unlock_bh(&local->ap->sta_table_lock);
1785 printk("%s: deauthentication from %pM, "
1786 "reason_code=%d, but STA not authenticated\n", dev->name,
1787 hdr->addr2, reason_code);
1792 /* Called only as a scheduled task for pending AP frames. */
1793 static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1794 struct hostap_80211_rx_status *rx_stats)
1796 struct net_device *dev = local->dev;
1797 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1798 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1802 struct sta_info *sta = NULL;
1804 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1807 printk("handle_disassoc - too short payload (len=%d)\n", len);
1811 pos = (__le16 *) body;
1812 reason_code = le16_to_cpu(*pos);
1814 PDEBUG(DEBUG_AP, "%s: disassociation: %pM len=%d, "
1815 "reason_code=%d\n", dev->name, hdr->addr2,
1818 spin_lock_bh(&local->ap->sta_table_lock);
1819 sta = ap_get_sta(local->ap, hdr->addr2);
1821 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1822 hostap_event_expired_sta(local->dev, sta);
1823 sta->flags &= ~WLAN_STA_ASSOC;
1825 spin_unlock_bh(&local->ap->sta_table_lock);
1827 printk("%s: disassociation from %pM, "
1828 "reason_code=%d, but STA not authenticated\n",
1829 dev->name, hdr->addr2, reason_code);
1834 /* Called only as a scheduled task for pending AP frames. */
1835 static void ap_handle_data_nullfunc(local_info_t *local,
1836 struct ieee80211_hdr *hdr)
1838 struct net_device *dev = local->dev;
1840 /* some STA f/w's seem to require control::ACK frame for
1841 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1843 * send control::ACK for the data::nullfunc */
1845 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1846 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
1847 NULL, 0, hdr->addr2, 0);
1851 /* Called only as a scheduled task for pending AP frames. */
1852 static void ap_handle_dropped_data(local_info_t *local,
1853 struct ieee80211_hdr *hdr)
1855 struct net_device *dev = local->dev;
1856 struct sta_info *sta;
1859 spin_lock_bh(&local->ap->sta_table_lock);
1860 sta = ap_get_sta(local->ap, hdr->addr2);
1862 atomic_inc(&sta->users);
1863 spin_unlock_bh(&local->ap->sta_table_lock);
1865 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1866 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1867 atomic_dec(&sta->users);
1871 reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1872 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1873 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1874 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
1875 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1878 atomic_dec(&sta->users);
1881 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1884 /* Called only as a scheduled task for pending AP frames. */
1885 static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1886 struct sk_buff *skb)
1888 struct hostap_skb_tx_data *meta;
1890 if (!(sta->flags & WLAN_STA_PS)) {
1891 /* Station has moved to non-PS mode, so send all buffered
1892 * frames using normal device queue. */
1893 dev_queue_xmit(skb);
1897 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1898 * be passed through even though STA is using PS */
1899 meta = (struct hostap_skb_tx_data *) skb->cb;
1900 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
1901 if (!skb_queue_empty(&sta->tx_buf)) {
1902 /* indicate to STA that more frames follow */
1903 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
1905 dev_queue_xmit(skb);
1909 /* Called only as a scheduled task for pending AP frames. */
1910 static void handle_pspoll(local_info_t *local,
1911 struct ieee80211_hdr *hdr,
1912 struct hostap_80211_rx_status *rx_stats)
1914 struct net_device *dev = local->dev;
1915 struct sta_info *sta;
1917 struct sk_buff *skb;
1919 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1920 hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
1922 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
1924 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1929 aid = le16_to_cpu(hdr->duration_id);
1930 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1931 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1934 aid &= ~(BIT(15) | BIT(14));
1935 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1936 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1939 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1941 spin_lock_bh(&local->ap->sta_table_lock);
1942 sta = ap_get_sta(local->ap, hdr->addr2);
1944 atomic_inc(&sta->users);
1945 spin_unlock_bh(&local->ap->sta_table_lock);
1948 PDEBUG(DEBUG_PS, " STA not found\n");
1951 if (sta->aid != aid) {
1952 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1953 "assoc.aid=%d\n", aid, sta->aid);
1958 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1959 * out (expiry time must be longer than ListenInterval for
1960 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1961 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1962 * sta; store buffer for later use and leave TIM aid bit set? use
1963 * TX event to check whether frame was ACKed?
1966 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1967 /* send buffered frame .. */
1968 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1969 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1971 pspoll_send_buffered(local, sta, skb);
1973 if (sta->flags & WLAN_STA_PS) {
1974 /* send only one buffered packet per PS Poll */
1975 /* FIX: should ignore further PS Polls until the
1976 * buffered packet that was just sent is acknowledged
1977 * (Tx or TxExc event) */
1982 if (skb_queue_empty(&sta->tx_buf)) {
1983 /* try to clear aid from TIM */
1984 if (!(sta->flags & WLAN_STA_TIM))
1985 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1987 hostap_set_tim(local, aid, 0);
1988 sta->flags &= ~WLAN_STA_TIM;
1991 atomic_dec(&sta->users);
1995 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1997 static void handle_wds_oper_queue(struct work_struct *work)
1999 struct ap_data *ap = container_of(work, struct ap_data,
2001 local_info_t *local = ap->local;
2002 struct wds_oper_data *entry, *prev;
2004 spin_lock_bh(&local->lock);
2005 entry = local->ap->wds_oper_entries;
2006 local->ap->wds_oper_entries = NULL;
2007 spin_unlock_bh(&local->lock);
2010 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
2013 entry->type == WDS_ADD ? "adding" : "removing",
2015 if (entry->type == WDS_ADD)
2016 prism2_wds_add(local, entry->addr, 0);
2017 else if (entry->type == WDS_DEL)
2018 prism2_wds_del(local, entry->addr, 0, 1);
2021 entry = entry->next;
2027 /* Called only as a scheduled task for pending AP frames. */
2028 static void handle_beacon(local_info_t *local, struct sk_buff *skb,
2029 struct hostap_80211_rx_status *rx_stats)
2031 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2032 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
2034 u16 beacon_int, capability;
2037 unsigned char *supp_rates = NULL;
2038 int ssid_len = 0, supp_rates_len = 0;
2039 struct sta_info *sta = NULL;
2040 int new_sta = 0, channel = -1;
2042 len = skb->len - IEEE80211_MGMT_HDR_LEN;
2044 if (len < 8 + 2 + 2) {
2045 printk(KERN_DEBUG "handle_beacon - too short payload "
2050 pos = (__le16 *) body;
2053 /* Timestamp (8 octets) */
2054 pos += 4; left -= 8;
2055 /* Beacon interval (2 octets) */
2056 beacon_int = le16_to_cpu(*pos);
2058 /* Capability information (2 octets) */
2059 capability = le16_to_cpu(*pos);
2062 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2063 capability & WLAN_CAPABILITY_IBSS)
2068 unsigned char *u = (unsigned char *) pos;
2070 if (*u == WLAN_EID_SSID) {
2075 if (ileft > left || ileft > MAX_SSID_LEN) {
2076 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2080 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2081 (ileft != strlen(local->essid) ||
2082 memcmp(local->essid, u, ileft) != 0)) {
2094 if (*u == WLAN_EID_SUPP_RATES) {
2099 if (ileft > left || ileft == 0 || ileft > 8) {
2100 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2105 supp_rates_len = ileft;
2111 if (*u == WLAN_EID_DS_PARAMS) {
2116 if (ileft > left || ileft != 1) {
2117 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2128 spin_lock_bh(&local->ap->sta_table_lock);
2129 sta = ap_get_sta(local->ap, hdr->addr2);
2131 atomic_inc(&sta->users);
2132 spin_unlock_bh(&local->ap->sta_table_lock);
2137 sta = ap_add_sta(local->ap, hdr->addr2);
2139 printk(KERN_INFO "prism2: kmalloc failed for AP "
2140 "data structure\n");
2143 hostap_event_new_sta(local->dev, sta);
2145 /* mark APs authentication and associated for pseudo ad-hoc
2146 * style communication */
2147 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2149 if (local->ap->autom_ap_wds) {
2150 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2156 sta->u.ap.ssid_len = ssid_len;
2157 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2158 sta->u.ap.ssid[ssid_len] = '\0';
2160 sta->u.ap.ssid_len = 0;
2161 sta->u.ap.ssid[0] = '\0';
2163 sta->u.ap.channel = channel;
2165 sta->rx_bytes += len;
2166 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2167 sta->capability = capability;
2168 sta->listen_interval = beacon_int;
2170 atomic_dec(&sta->users);
2173 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2174 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2175 prism2_check_tx_rates(sta);
2179 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2182 /* Called only as a tasklet. */
2183 static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2184 struct hostap_80211_rx_status *rx_stats)
2186 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2187 struct net_device *dev = local->dev;
2188 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2189 u16 fc, type, stype;
2190 struct ieee80211_hdr *hdr;
2192 /* FIX: should give skb->len to handler functions and check that the
2193 * buffer is long enough */
2194 hdr = (struct ieee80211_hdr *) skb->data;
2195 fc = le16_to_cpu(hdr->frame_control);
2196 type = fc & IEEE80211_FCTL_FTYPE;
2197 stype = fc & IEEE80211_FCTL_STYPE;
2199 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2200 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
2201 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2203 if (!(fc & IEEE80211_FCTL_TODS) ||
2204 (fc & IEEE80211_FCTL_FROMDS)) {
2205 if (stype == IEEE80211_STYPE_NULLFUNC) {
2206 /* no ToDS nullfunc seems to be used to check
2207 * AP association; so send reject message to
2208 * speed up re-association */
2209 ap_handle_dropped_data(local, hdr);
2212 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2217 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2218 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
2219 " not own MAC\n", hdr->addr1);
2223 if (local->ap->nullfunc_ack &&
2224 stype == IEEE80211_STYPE_NULLFUNC)
2225 ap_handle_data_nullfunc(local, hdr);
2227 ap_handle_dropped_data(local, hdr);
2231 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
2232 handle_beacon(local, skb, rx_stats);
2235 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2237 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
2238 handle_pspoll(local, hdr, rx_stats);
2242 if (local->hostapd) {
2243 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2244 "subtype=0x%02x\n", type, stype);
2248 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2249 if (type != IEEE80211_FTYPE_MGMT) {
2250 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2254 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2255 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
2256 " not own MAC\n", hdr->addr1);
2260 if (!ether_addr_equal(hdr->addr3, dev->dev_addr)) {
2261 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
2262 " not own MAC\n", hdr->addr3);
2267 case IEEE80211_STYPE_ASSOC_REQ:
2268 handle_assoc(local, skb, rx_stats, 0);
2270 case IEEE80211_STYPE_ASSOC_RESP:
2271 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2273 case IEEE80211_STYPE_REASSOC_REQ:
2274 handle_assoc(local, skb, rx_stats, 1);
2276 case IEEE80211_STYPE_REASSOC_RESP:
2277 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2279 case IEEE80211_STYPE_ATIM:
2280 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2282 case IEEE80211_STYPE_DISASSOC:
2283 handle_disassoc(local, skb, rx_stats);
2285 case IEEE80211_STYPE_AUTH:
2286 handle_authen(local, skb, rx_stats);
2288 case IEEE80211_STYPE_DEAUTH:
2289 handle_deauth(local, skb, rx_stats);
2292 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2296 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2303 /* Called only as a tasklet (software IRQ) */
2304 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2305 struct hostap_80211_rx_status *rx_stats)
2307 struct hostap_interface *iface;
2308 local_info_t *local;
2309 struct ieee80211_hdr *hdr;
2311 iface = netdev_priv(dev);
2312 local = iface->local;
2317 dev->stats.rx_packets++;
2319 hdr = (struct ieee80211_hdr *) skb->data;
2321 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2322 ieee80211_is_beacon(hdr->frame_control))
2325 skb->protocol = cpu_to_be16(ETH_P_HOSTAP);
2326 handle_ap_item(local, skb, rx_stats);
2334 /* Called only as a tasklet (software IRQ) */
2335 static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2337 struct sk_buff *skb;
2338 struct ieee80211_hdr *hdr;
2339 struct hostap_80211_rx_status rx_stats;
2341 if (skb_queue_empty(&sta->tx_buf))
2344 skb = dev_alloc_skb(16);
2346 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2347 "failed\n", local->dev->name);
2351 hdr = skb_put(skb, 16);
2353 /* Generate a fake pspoll frame to start packet delivery */
2354 hdr->frame_control = cpu_to_le16(
2355 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
2356 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2357 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2358 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2361 "%s: Scheduling buffered packet delivery for STA %pM\n",
2362 local->dev->name, sta->addr);
2364 skb->dev = local->dev;
2366 memset(&rx_stats, 0, sizeof(rx_stats));
2367 hostap_rx(local->dev, skb, &rx_stats);
2371 int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2372 struct iw_quality qual[], int buf_size,
2375 struct ap_data *ap = local->ap;
2376 struct list_head *ptr;
2379 spin_lock_bh(&ap->sta_table_lock);
2381 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2383 struct sta_info *sta = (struct sta_info *) ptr;
2385 if (aplist && !sta->ap)
2387 addr[count].sa_family = ARPHRD_ETHER;
2388 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2389 if (sta->last_rx_silence == 0)
2390 qual[count].qual = sta->last_rx_signal < 27 ?
2391 0 : (sta->last_rx_signal - 27) * 92 / 127;
2393 qual[count].qual = sta->last_rx_signal -
2394 sta->last_rx_silence - 35;
2395 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2396 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2397 qual[count].updated = sta->last_rx_updated;
2399 sta->last_rx_updated = IW_QUAL_DBM;
2402 if (count >= buf_size)
2405 spin_unlock_bh(&ap->sta_table_lock);
2411 /* Translate our list of Access Points & Stations to a card independent
2412 * format that the Wireless Tools will understand - Jean II */
2413 int prism2_ap_translate_scan(struct net_device *dev,
2414 struct iw_request_info *info, char *buffer)
2416 struct hostap_interface *iface;
2417 local_info_t *local;
2419 struct list_head *ptr;
2420 struct iw_event iwe;
2421 char *current_ev = buffer;
2422 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2423 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2427 iface = netdev_priv(dev);
2428 local = iface->local;
2431 spin_lock_bh(&ap->sta_table_lock);
2433 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2435 struct sta_info *sta = (struct sta_info *) ptr;
2437 /* First entry *MUST* be the AP MAC address */
2438 memset(&iwe, 0, sizeof(iwe));
2439 iwe.cmd = SIOCGIWAP;
2440 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2441 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2442 iwe.len = IW_EV_ADDR_LEN;
2443 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2444 &iwe, IW_EV_ADDR_LEN);
2446 /* Use the mode to indicate if it's a station or
2447 * an Access Point */
2448 memset(&iwe, 0, sizeof(iwe));
2449 iwe.cmd = SIOCGIWMODE;
2451 iwe.u.mode = IW_MODE_MASTER;
2453 iwe.u.mode = IW_MODE_INFRA;
2454 iwe.len = IW_EV_UINT_LEN;
2455 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2456 &iwe, IW_EV_UINT_LEN);
2459 memset(&iwe, 0, sizeof(iwe));
2461 if (sta->last_rx_silence == 0)
2462 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2463 0 : (sta->last_rx_signal - 27) * 92 / 127;
2465 iwe.u.qual.qual = sta->last_rx_signal -
2466 sta->last_rx_silence - 35;
2467 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2468 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2469 iwe.u.qual.updated = sta->last_rx_updated;
2470 iwe.len = IW_EV_QUAL_LEN;
2471 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2472 &iwe, IW_EV_QUAL_LEN);
2474 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2476 memset(&iwe, 0, sizeof(iwe));
2477 iwe.cmd = SIOCGIWESSID;
2478 iwe.u.data.length = sta->u.ap.ssid_len;
2479 iwe.u.data.flags = 1;
2480 current_ev = iwe_stream_add_point(info, current_ev,
2484 memset(&iwe, 0, sizeof(iwe));
2485 iwe.cmd = SIOCGIWENCODE;
2486 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2488 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2490 iwe.u.data.flags = IW_ENCODE_DISABLED;
2491 current_ev = iwe_stream_add_point(info, current_ev,
2495 if (sta->u.ap.channel > 0 &&
2496 sta->u.ap.channel <= FREQ_COUNT) {
2497 memset(&iwe, 0, sizeof(iwe));
2498 iwe.cmd = SIOCGIWFREQ;
2499 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2502 current_ev = iwe_stream_add_event(
2503 info, current_ev, end_buf, &iwe,
2507 memset(&iwe, 0, sizeof(iwe));
2508 iwe.cmd = IWEVCUSTOM;
2509 sprintf(buf, "beacon_interval=%d",
2510 sta->listen_interval);
2511 iwe.u.data.length = strlen(buf);
2512 current_ev = iwe_stream_add_point(info, current_ev,
2513 end_buf, &iwe, buf);
2515 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2517 sta->last_rx_updated = IW_QUAL_DBM;
2519 /* To be continued, we should make good use of IWEVCUSTOM */
2522 spin_unlock_bh(&ap->sta_table_lock);
2524 return current_ev - buffer;
2528 static int prism2_hostapd_add_sta(struct ap_data *ap,
2529 struct prism2_hostapd_param *param)
2531 struct sta_info *sta;
2533 spin_lock_bh(&ap->sta_table_lock);
2534 sta = ap_get_sta(ap, param->sta_addr);
2536 atomic_inc(&sta->users);
2537 spin_unlock_bh(&ap->sta_table_lock);
2540 sta = ap_add_sta(ap, param->sta_addr);
2545 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2546 hostap_event_new_sta(sta->local->dev, sta);
2548 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2549 sta->last_rx = jiffies;
2550 sta->aid = param->u.add_sta.aid;
2551 sta->capability = param->u.add_sta.capability;
2552 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2553 if (sta->tx_supp_rates & WLAN_RATE_1M)
2554 sta->supported_rates[0] = 2;
2555 if (sta->tx_supp_rates & WLAN_RATE_2M)
2556 sta->supported_rates[1] = 4;
2557 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2558 sta->supported_rates[2] = 11;
2559 if (sta->tx_supp_rates & WLAN_RATE_11M)
2560 sta->supported_rates[3] = 22;
2561 prism2_check_tx_rates(sta);
2562 atomic_dec(&sta->users);
2567 static int prism2_hostapd_remove_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);
2575 ap_sta_hash_del(ap, sta);
2576 list_del(&sta->list);
2578 spin_unlock_bh(&ap->sta_table_lock);
2583 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2584 hostap_event_expired_sta(sta->local->dev, sta);
2585 ap_free_sta(ap, sta);
2591 static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2592 struct prism2_hostapd_param *param)
2594 struct sta_info *sta;
2596 spin_lock_bh(&ap->sta_table_lock);
2597 sta = ap_get_sta(ap, param->sta_addr);
2599 atomic_inc(&sta->users);
2600 spin_unlock_bh(&ap->sta_table_lock);
2605 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2607 atomic_dec(&sta->users);
2613 static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2614 struct prism2_hostapd_param *param)
2616 struct sta_info *sta;
2618 spin_lock_bh(&ap->sta_table_lock);
2619 sta = ap_get_sta(ap, param->sta_addr);
2621 sta->flags |= param->u.set_flags_sta.flags_or;
2622 sta->flags &= param->u.set_flags_sta.flags_and;
2624 spin_unlock_bh(&ap->sta_table_lock);
2633 static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2634 struct prism2_hostapd_param *param)
2636 struct sta_info *sta;
2639 spin_lock_bh(&ap->sta_table_lock);
2640 sta = ap_get_sta(ap, param->sta_addr);
2642 sta->rx_packets = sta->tx_packets = 0;
2643 sta->rx_bytes = sta->tx_bytes = 0;
2644 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2645 sta->tx_count[rate] = 0;
2646 sta->rx_count[rate] = 0;
2649 spin_unlock_bh(&ap->sta_table_lock);
2658 int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
2660 switch (param->cmd) {
2661 case PRISM2_HOSTAPD_FLUSH:
2662 ap_control_kickall(ap);
2664 case PRISM2_HOSTAPD_ADD_STA:
2665 return prism2_hostapd_add_sta(ap, param);
2666 case PRISM2_HOSTAPD_REMOVE_STA:
2667 return prism2_hostapd_remove_sta(ap, param);
2668 case PRISM2_HOSTAPD_GET_INFO_STA:
2669 return prism2_hostapd_get_info_sta(ap, param);
2670 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2671 return prism2_hostapd_set_flags_sta(ap, param);
2672 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2673 return prism2_hostapd_sta_clear_stats(ap, param);
2675 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2682 /* Update station info for host-based TX rate control and return current
2684 static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2686 int ret = sta->tx_rate;
2687 struct hostap_interface *iface;
2688 local_info_t *local;
2690 iface = netdev_priv(dev);
2691 local = iface->local;
2693 sta->tx_count[sta->tx_rate_idx]++;
2694 sta->tx_since_last_failure++;
2695 sta->tx_consecutive_exc = 0;
2696 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2697 sta->tx_rate_idx < sta->tx_max_rate) {
2698 /* use next higher rate */
2699 int old_rate, new_rate;
2700 old_rate = new_rate = sta->tx_rate_idx;
2701 while (new_rate < sta->tx_max_rate) {
2703 if (ap_tx_rate_ok(new_rate, sta, local)) {
2704 sta->tx_rate_idx = new_rate;
2708 if (old_rate != sta->tx_rate_idx) {
2709 switch (sta->tx_rate_idx) {
2710 case 0: sta->tx_rate = 10; break;
2711 case 1: sta->tx_rate = 20; break;
2712 case 2: sta->tx_rate = 55; break;
2713 case 3: sta->tx_rate = 110; break;
2714 default: sta->tx_rate = 0; break;
2716 PDEBUG(DEBUG_AP, "%s: STA %pM TX rate raised to %d\n",
2717 dev->name, sta->addr, sta->tx_rate);
2719 sta->tx_since_last_failure = 0;
2726 /* Called only from software IRQ. Called for each TX frame prior possible
2727 * encryption and transmit. */
2728 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2730 struct sta_info *sta = NULL;
2731 struct sk_buff *skb = tx->skb;
2733 struct ieee80211_hdr *hdr;
2734 struct hostap_skb_tx_data *meta;
2736 meta = (struct hostap_skb_tx_data *) skb->cb;
2737 ret = AP_TX_CONTINUE;
2738 if (local->ap == NULL || skb->len < 10 ||
2739 meta->iface->type == HOSTAP_INTERFACE_STA)
2742 hdr = (struct ieee80211_hdr *) skb->data;
2744 if (hdr->addr1[0] & 0x01) {
2745 /* broadcast/multicast frame - no AP related processing */
2746 if (local->ap->num_sta <= 0)
2751 /* unicast packet - check whether destination STA is associated */
2752 spin_lock(&local->ap->sta_table_lock);
2753 sta = ap_get_sta(local->ap, hdr->addr1);
2755 atomic_inc(&sta->users);
2756 spin_unlock(&local->ap->sta_table_lock);
2758 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2759 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
2760 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2761 meta->iface->type != HOSTAP_INTERFACE_AP) {
2763 /* This can happen, e.g., when wlan0 is added to a bridge and
2764 * bridging code does not know which port is the correct target
2765 * for a unicast frame. In this case, the packet is send to all
2766 * ports of the bridge. Since this is a valid scenario, do not
2767 * print out any errors here. */
2768 if (net_ratelimit()) {
2769 printk(KERN_DEBUG "AP: drop packet to non-associated "
2770 "STA %pM\n", hdr->addr1);
2773 local->ap->tx_drop_nonassoc++;
2781 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2782 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2784 /* Set tx_rate if using host-based TX rate control */
2785 if (!local->fw_tx_rate_control)
2786 local->ap->last_tx_rate = meta->rate =
2787 ap_update_sta_tx_rate(sta, local->dev);
2789 if (local->iw_mode != IW_MODE_MASTER)
2792 if (!(sta->flags & WLAN_STA_PS))
2795 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2796 /* indicate to STA that more frames follow */
2797 hdr->frame_control |=
2798 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2801 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2802 /* packet was already buffered and now send due to
2803 * PS poll, so do not rebuffer it */
2807 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2808 PDEBUG(DEBUG_PS, "%s: No more space in STA (%pM)'s"
2810 local->dev->name, sta->addr);
2811 /* Make sure that TIM is set for the station (it might not be
2812 * after AP wlan hw reset). */
2813 /* FIX: should fix hw reset to restore bits based on STA
2815 hostap_set_tim(local, sta->aid, 1);
2816 sta->flags |= WLAN_STA_TIM;
2821 /* STA in PS mode, buffer frame for later delivery */
2822 set_tim = skb_queue_empty(&sta->tx_buf);
2823 skb_queue_tail(&sta->tx_buf, skb);
2824 /* FIX: could save RX time to skb and expire buffered frames after
2825 * some time if STA does not poll for them */
2828 if (sta->flags & WLAN_STA_TIM)
2829 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2831 hostap_set_tim(local, sta->aid, 1);
2832 sta->flags |= WLAN_STA_TIM;
2835 ret = AP_TX_BUFFERED;
2839 if (ret == AP_TX_CONTINUE ||
2840 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2842 sta->tx_bytes += skb->len;
2843 sta->last_tx = jiffies;
2846 if ((ret == AP_TX_CONTINUE ||
2847 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2848 sta->crypt && tx->host_encrypt) {
2849 tx->crypt = sta->crypt;
2850 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2851 * be called to release sta info
2854 atomic_dec(&sta->users);
2861 void hostap_handle_sta_release(void *ptr)
2863 struct sta_info *sta = ptr;
2864 atomic_dec(&sta->users);
2868 /* Called only as a tasklet (software IRQ) */
2869 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2871 struct sta_info *sta;
2872 struct ieee80211_hdr *hdr;
2873 struct hostap_skb_tx_data *meta;
2875 hdr = (struct ieee80211_hdr *) skb->data;
2876 meta = (struct hostap_skb_tx_data *) skb->cb;
2878 spin_lock(&local->ap->sta_table_lock);
2879 sta = ap_get_sta(local->ap, hdr->addr1);
2881 spin_unlock(&local->ap->sta_table_lock);
2882 PDEBUG(DEBUG_AP, "%s: Could not find STA %pM"
2883 " for this TX error (@%lu)\n",
2884 local->dev->name, hdr->addr1, jiffies);
2888 sta->tx_since_last_failure = 0;
2889 sta->tx_consecutive_exc++;
2891 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2892 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2893 /* use next lower rate */
2895 old = rate = sta->tx_rate_idx;
2898 if (ap_tx_rate_ok(rate, sta, local)) {
2899 sta->tx_rate_idx = rate;
2903 if (old != sta->tx_rate_idx) {
2904 switch (sta->tx_rate_idx) {
2905 case 0: sta->tx_rate = 10; break;
2906 case 1: sta->tx_rate = 20; break;
2907 case 2: sta->tx_rate = 55; break;
2908 case 3: sta->tx_rate = 110; break;
2909 default: sta->tx_rate = 0; break;
2912 "%s: STA %pM TX rate lowered to %d\n",
2913 local->dev->name, sta->addr, sta->tx_rate);
2915 sta->tx_consecutive_exc = 0;
2917 spin_unlock(&local->ap->sta_table_lock);
2921 static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2922 int pwrmgt, int type, int stype)
2924 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2925 sta->flags |= WLAN_STA_PS;
2926 PDEBUG(DEBUG_PS2, "STA %pM changed to use PS "
2927 "mode (type=0x%02X, stype=0x%02X)\n",
2928 sta->addr, type >> 2, stype >> 4);
2929 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2930 sta->flags &= ~WLAN_STA_PS;
2931 PDEBUG(DEBUG_PS2, "STA %pM changed to not use "
2932 "PS mode (type=0x%02X, stype=0x%02X)\n",
2933 sta->addr, type >> 2, stype >> 4);
2934 if (type != IEEE80211_FTYPE_CTL ||
2935 stype != IEEE80211_STYPE_PSPOLL)
2936 schedule_packet_send(local, sta);
2941 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2942 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2943 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr)
2945 struct sta_info *sta;
2948 spin_lock(&local->ap->sta_table_lock);
2949 sta = ap_get_sta(local->ap, hdr->addr2);
2951 atomic_inc(&sta->users);
2952 spin_unlock(&local->ap->sta_table_lock);
2957 fc = le16_to_cpu(hdr->frame_control);
2958 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
2959 fc & IEEE80211_FCTL_FTYPE,
2960 fc & IEEE80211_FCTL_STYPE);
2962 atomic_dec(&sta->users);
2967 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2968 * getting RX header and payload from hardware. */
2969 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2970 struct sk_buff *skb,
2971 struct hostap_80211_rx_status *rx_stats,
2975 struct sta_info *sta;
2976 u16 fc, type, stype;
2977 struct ieee80211_hdr *hdr;
2979 if (local->ap == NULL)
2980 return AP_RX_CONTINUE;
2982 hdr = (struct ieee80211_hdr *) skb->data;
2984 fc = le16_to_cpu(hdr->frame_control);
2985 type = fc & IEEE80211_FCTL_FTYPE;
2986 stype = fc & IEEE80211_FCTL_STYPE;
2988 spin_lock(&local->ap->sta_table_lock);
2989 sta = ap_get_sta(local->ap, hdr->addr2);
2991 atomic_inc(&sta->users);
2992 spin_unlock(&local->ap->sta_table_lock);
2994 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2995 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2997 ret = AP_RX_CONTINUE;
3000 if (fc & IEEE80211_FCTL_TODS) {
3001 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
3002 if (local->hostapd) {
3003 prism2_rx_80211(local->apdev, skb, rx_stats,
3004 PRISM2_RX_NON_ASSOC);
3005 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3007 printk(KERN_DEBUG "%s: dropped received packet"
3008 " from non-associated STA %pM"
3009 " (type=0x%02x, subtype=0x%02x)\n",
3010 dev->name, hdr->addr2,
3011 type >> 2, stype >> 4);
3012 hostap_rx(dev, skb, rx_stats);
3013 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3018 } else if (fc & IEEE80211_FCTL_FROMDS) {
3020 /* FromDS frame - not for us; probably
3021 * broadcast/multicast in another BSS - drop */
3022 if (ether_addr_equal(hdr->addr1, dev->dev_addr)) {
3023 printk(KERN_DEBUG "Odd.. FromDS packet "
3024 "received with own BSSID\n");
3025 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3030 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
3031 ether_addr_equal(hdr->addr1, dev->dev_addr)) {
3033 if (local->hostapd) {
3034 prism2_rx_80211(local->apdev, skb, rx_stats,
3035 PRISM2_RX_NON_ASSOC);
3036 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3038 /* At least Lucent f/w seems to send data::nullfunc
3039 * frames with no ToDS flag when the current AP returns
3040 * after being unavailable for some time. Speed up
3041 * re-association by informing the station about it not
3042 * being associated. */
3043 printk(KERN_DEBUG "%s: rejected received nullfunc frame"
3044 " without ToDS from not associated STA %pM\n",
3045 dev->name, hdr->addr2);
3046 hostap_rx(dev, skb, rx_stats);
3047 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3051 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
3052 /* At least Lucent cards seem to send periodic nullfunc
3053 * frames with ToDS. Let these through to update SQ
3054 * stats and PS state. Nullfunc frames do not contain
3055 * any data and they will be dropped below. */
3057 /* If BSSID (Addr3) is foreign, this frame is a normal
3058 * broadcast frame from an IBSS network. Drop it silently.
3059 * If BSSID is own, report the dropping of this frame. */
3060 if (ether_addr_equal(hdr->addr3, dev->dev_addr)) {
3061 printk(KERN_DEBUG "%s: dropped received packet from %pM"
3062 " with no ToDS flag "
3063 "(type=0x%02x, subtype=0x%02x)\n", dev->name,
3064 hdr->addr2, type >> 2, stype >> 4);
3065 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3072 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
3076 sta->rx_bytes += skb->len;
3077 sta->last_rx = jiffies;
3080 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
3081 fc & IEEE80211_FCTL_TODS) {
3082 if (local->hostapd) {
3083 prism2_rx_80211(local->apdev, skb, rx_stats,
3084 PRISM2_RX_NULLFUNC_ACK);
3085 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3087 /* some STA f/w's seem to require control::ACK frame
3088 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3089 * from Compaq) does not send this.. Try to generate
3090 * ACK for these frames from the host driver to make
3091 * power saving work with, e.g., Lucent WaveLAN f/w */
3092 hostap_rx(dev, skb, rx_stats);
3093 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3101 atomic_dec(&sta->users);
3107 /* Called only as a tasklet (software IRQ) */
3108 int hostap_handle_sta_crypto(local_info_t *local,
3109 struct ieee80211_hdr *hdr,
3110 struct lib80211_crypt_data **crypt,
3113 struct sta_info *sta;
3115 spin_lock(&local->ap->sta_table_lock);
3116 sta = ap_get_sta(local->ap, hdr->addr2);
3118 atomic_inc(&sta->users);
3119 spin_unlock(&local->ap->sta_table_lock);
3125 *crypt = sta->crypt;
3127 /* hostap_handle_sta_release() will be called to release STA
3130 atomic_dec(&sta->users);
3136 /* Called only as a tasklet (software IRQ) */
3137 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3139 struct sta_info *sta;
3142 spin_lock(&ap->sta_table_lock);
3143 sta = ap_get_sta(ap, sta_addr);
3144 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3146 spin_unlock(&ap->sta_table_lock);
3152 /* Called only as a tasklet (software IRQ) */
3153 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3155 struct sta_info *sta;
3158 spin_lock(&ap->sta_table_lock);
3159 sta = ap_get_sta(ap, sta_addr);
3160 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3161 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3162 ap->local->ieee_802_1x == 0))
3164 spin_unlock(&ap->sta_table_lock);
3170 /* Called only as a tasklet (software IRQ) */
3171 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3173 struct sta_info *sta;
3179 spin_lock(&ap->sta_table_lock);
3180 sta = ap_get_sta(ap, sta_addr);
3183 spin_unlock(&ap->sta_table_lock);
3186 sta = ap_add_sta(ap, sta_addr);
3189 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3191 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3192 /* No way of knowing which rates are supported since we did not
3193 * get supported rates element from beacon/assoc req. Assume
3194 * that remote end supports all 802.11b rates. */
3195 sta->supported_rates[0] = 0x82;
3196 sta->supported_rates[1] = 0x84;
3197 sta->supported_rates[2] = 0x0b;
3198 sta->supported_rates[3] = 0x16;
3199 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3200 WLAN_RATE_5M5 | WLAN_RATE_11M;
3202 sta->tx_max_rate = sta->tx_rate_idx = 3;
3209 /* Called only as a tasklet (software IRQ) */
3210 int hostap_update_rx_stats(struct ap_data *ap,
3211 struct ieee80211_hdr *hdr,
3212 struct hostap_80211_rx_status *rx_stats)
3214 struct sta_info *sta;
3219 spin_lock(&ap->sta_table_lock);
3220 sta = ap_get_sta(ap, hdr->addr2);
3222 sta->last_rx_silence = rx_stats->noise;
3223 sta->last_rx_signal = rx_stats->signal;
3224 sta->last_rx_rate = rx_stats->rate;
3225 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3226 if (rx_stats->rate == 10)
3228 else if (rx_stats->rate == 20)
3230 else if (rx_stats->rate == 55)
3232 else if (rx_stats->rate == 110)
3235 spin_unlock(&ap->sta_table_lock);
3237 return sta ? 0 : -1;
3241 void hostap_update_rates(local_info_t *local)
3243 struct sta_info *sta;
3244 struct ap_data *ap = local->ap;
3249 spin_lock_bh(&ap->sta_table_lock);
3250 list_for_each_entry(sta, &ap->sta_list, list) {
3251 prism2_check_tx_rates(sta);
3253 spin_unlock_bh(&ap->sta_table_lock);
3257 void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3258 struct lib80211_crypt_data ***crypt)
3260 struct sta_info *sta;
3262 spin_lock_bh(&ap->sta_table_lock);
3263 sta = ap_get_sta(ap, addr);
3265 atomic_inc(&sta->users);
3266 spin_unlock_bh(&ap->sta_table_lock);
3268 if (!sta && permanent)
3269 sta = ap_add_sta(ap, addr);
3275 sta->flags |= WLAN_STA_PERM;
3277 *crypt = &sta->crypt;
3283 void hostap_add_wds_links(local_info_t *local)
3285 struct ap_data *ap = local->ap;
3286 struct sta_info *sta;
3288 spin_lock_bh(&ap->sta_table_lock);
3289 list_for_each_entry(sta, &ap->sta_list, list) {
3291 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3293 spin_unlock_bh(&ap->sta_table_lock);
3295 schedule_work(&local->ap->wds_oper_queue);
3299 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3301 struct wds_oper_data *entry;
3303 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3306 memcpy(entry->addr, addr, ETH_ALEN);
3308 spin_lock_bh(&local->lock);
3309 entry->next = local->ap->wds_oper_entries;
3310 local->ap->wds_oper_entries = entry;
3311 spin_unlock_bh(&local->lock);
3313 schedule_work(&local->ap->wds_oper_queue);
3317 EXPORT_SYMBOL(hostap_init_data);
3318 EXPORT_SYMBOL(hostap_init_ap_proc);
3319 EXPORT_SYMBOL(hostap_free_data);
3320 EXPORT_SYMBOL(hostap_check_sta_fw_version);
3321 EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3322 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3323 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */