2 * Intersil Prism2 driver with Host AP (software access point) support
3 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
5 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
7 * This file is to be included into hostap.c when S/W AP functionality is
11 * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
12 * unauthenticated STA, send deauth. frame (8802.11: 5.5)
13 * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
14 * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
15 * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
19 #include <linux/proc_fs.h>
20 #include <linux/seq_file.h>
21 #include <linux/delay.h>
22 #include <linux/random.h>
23 #include <linux/if_arp.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <linux/moduleparam.h>
27 #include <linux/etherdevice.h>
29 #include "hostap_wlan.h"
31 #include "hostap_ap.h"
33 static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
35 module_param_array(other_ap_policy, int, NULL, 0444);
36 MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
38 static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
40 module_param_array(ap_max_inactivity, int, NULL, 0444);
41 MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
44 static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
45 module_param_array(ap_bridge_packets, int, NULL, 0444);
46 MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
49 static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
50 module_param_array(autom_ap_wds, int, NULL, 0444);
51 MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
55 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
56 static void hostap_event_expired_sta(struct net_device *dev,
57 struct sta_info *sta);
58 static void handle_add_proc_queue(struct work_struct *work);
60 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
61 static void handle_wds_oper_queue(struct work_struct *work);
62 static void prism2_send_mgmt(struct net_device *dev,
63 u16 type_subtype, char *body,
64 int body_len, u8 *addr, u16 tx_cb_idx);
65 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
68 #ifndef PRISM2_NO_PROCFS_DEBUG
69 static int ap_debug_proc_show(struct seq_file *m, void *v)
71 struct ap_data *ap = m->private;
73 seq_printf(m, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
74 seq_printf(m, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
75 seq_printf(m, "max_inactivity=%u\n", ap->max_inactivity / HZ);
76 seq_printf(m, "bridge_packets=%u\n", ap->bridge_packets);
77 seq_printf(m, "nullfunc_ack=%u\n", ap->nullfunc_ack);
78 seq_printf(m, "autom_ap_wds=%u\n", ap->autom_ap_wds);
79 seq_printf(m, "auth_algs=%u\n", ap->local->auth_algs);
80 seq_printf(m, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
84 static int ap_debug_proc_open(struct inode *inode, struct file *file)
86 return single_open(file, ap_debug_proc_show, PDE_DATA(inode));
89 static const struct file_operations ap_debug_proc_fops = {
90 .open = ap_debug_proc_open,
93 .release = single_release,
95 #endif /* PRISM2_NO_PROCFS_DEBUG */
98 static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
100 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
101 ap->sta_hash[STA_HASH(sta->addr)] = sta;
104 static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
108 s = ap->sta_hash[STA_HASH(sta->addr)];
109 if (s == NULL) return;
110 if (ether_addr_equal(s->addr, sta->addr)) {
111 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
115 while (s->hnext != NULL && !ether_addr_equal(s->hnext->addr, sta->addr))
117 if (s->hnext != NULL)
118 s->hnext = s->hnext->hnext;
120 printk("AP: could not remove STA %pM from hash table\n",
124 static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
126 if (sta->ap && sta->local)
127 hostap_event_expired_sta(sta->local->dev, sta);
129 if (ap->proc != NULL) {
131 sprintf(name, "%pM", sta->addr);
132 remove_proc_entry(name, ap->proc);
136 sta->crypt->ops->deinit(sta->crypt->priv);
141 skb_queue_purge(&sta->tx_buf);
144 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
146 ap->sta_aid[sta->aid - 1] = NULL;
149 kfree(sta->u.sta.challenge);
150 del_timer_sync(&sta->timer);
151 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
157 static void hostap_set_tim(local_info_t *local, int aid, int set)
159 if (local->func->set_tim)
160 local->func->set_tim(local->dev, aid, set);
164 static void hostap_event_new_sta(struct net_device *dev, 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, IWEVREGISTERED, &wrqu, NULL);
174 static void hostap_event_expired_sta(struct net_device *dev,
175 struct sta_info *sta)
177 union iwreq_data wrqu;
178 memset(&wrqu, 0, sizeof(wrqu));
179 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
180 wrqu.addr.sa_family = ARPHRD_ETHER;
181 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
185 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
187 static void ap_handle_timer(unsigned long data)
189 struct sta_info *sta = (struct sta_info *) data;
192 unsigned long next_time = 0;
195 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
196 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
202 was_assoc = sta->flags & WLAN_STA_ASSOC;
204 if (atomic_read(&sta->users) != 0)
205 next_time = jiffies + HZ;
206 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
207 next_time = jiffies + ap->max_inactivity;
209 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
210 /* station activity detected; reset timeout state */
211 sta->timeout_next = STA_NULLFUNC;
212 next_time = sta->last_rx + ap->max_inactivity;
213 } else if (sta->timeout_next == STA_DISASSOC &&
214 !(sta->flags & WLAN_STA_PENDING_POLL)) {
215 /* STA ACKed data nullfunc frame poll */
216 sta->timeout_next = STA_NULLFUNC;
217 next_time = jiffies + ap->max_inactivity;
221 sta->timer.expires = next_time;
222 add_timer(&sta->timer);
227 sta->timeout_next = STA_DEAUTH;
229 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
230 spin_lock(&ap->sta_table_lock);
231 ap_sta_hash_del(ap, sta);
232 list_del(&sta->list);
233 spin_unlock(&ap->sta_table_lock);
234 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
235 } else if (sta->timeout_next == STA_DISASSOC)
236 sta->flags &= ~WLAN_STA_ASSOC;
238 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
239 hostap_event_expired_sta(local->dev, sta);
241 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
242 !skb_queue_empty(&sta->tx_buf)) {
243 hostap_set_tim(local, sta->aid, 0);
244 sta->flags &= ~WLAN_STA_TIM;
248 if (ap->autom_ap_wds) {
249 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
250 "connection to AP %pM\n",
251 local->dev->name, sta->addr);
252 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
254 } else if (sta->timeout_next == STA_NULLFUNC) {
255 /* send data frame to poll STA and check whether this frame
257 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
258 * it is apparently not retried so TX Exc events are not
260 sta->flags |= WLAN_STA_PENDING_POLL;
261 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
262 IEEE80211_STYPE_DATA, NULL, 0,
263 sta->addr, ap->tx_callback_poll);
265 int deauth = sta->timeout_next == STA_DEAUTH;
267 PDEBUG(DEBUG_AP, "%s: sending %s info to STA %pM"
268 "(last=%lu, jiffies=%lu)\n",
270 deauth ? "deauthentication" : "disassociation",
271 sta->addr, sta->last_rx, jiffies);
273 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
274 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
275 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
276 (deauth ? IEEE80211_STYPE_DEAUTH :
277 IEEE80211_STYPE_DISASSOC),
278 (char *) &resp, 2, sta->addr, 0);
281 if (sta->timeout_next == STA_DEAUTH) {
282 if (sta->flags & WLAN_STA_PERM) {
283 PDEBUG(DEBUG_AP, "%s: STA %pM"
284 " would have been removed, "
285 "but it has 'perm' flag\n",
286 local->dev->name, sta->addr);
288 ap_free_sta(ap, sta);
292 if (sta->timeout_next == STA_NULLFUNC) {
293 sta->timeout_next = STA_DISASSOC;
294 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
296 sta->timeout_next = STA_DEAUTH;
297 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
300 add_timer(&sta->timer);
304 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
311 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
312 eth_broadcast_addr(addr);
314 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
316 /* deauth message sent; try to resend it few times; the message is
317 * broadcast, so it may be delayed until next DTIM; there is not much
318 * else we can do at this point since the driver is going to be shut
320 for (i = 0; i < 5; i++) {
321 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
322 IEEE80211_STYPE_DEAUTH,
323 (char *) &resp, 2, addr, 0);
325 if (!resend || ap->num_sta <= 0)
333 static int ap_control_proc_show(struct seq_file *m, void *v)
335 struct ap_data *ap = m->private;
337 struct mac_entry *entry;
339 if (v == SEQ_START_TOKEN) {
340 switch (ap->mac_restrictions.policy) {
341 case MAC_POLICY_OPEN:
344 case MAC_POLICY_ALLOW:
345 policy_txt = "allow";
347 case MAC_POLICY_DENY:
351 policy_txt = "unknown";
354 seq_printf(m, "MAC policy: %s\n", policy_txt);
355 seq_printf(m, "MAC entries: %u\n", ap->mac_restrictions.entries);
356 seq_puts(m, "MAC list:\n");
361 seq_printf(m, "%pM\n", entry->addr);
365 static void *ap_control_proc_start(struct seq_file *m, loff_t *_pos)
367 struct ap_data *ap = m->private;
368 spin_lock_bh(&ap->mac_restrictions.lock);
369 return seq_list_start_head(&ap->mac_restrictions.mac_list, *_pos);
372 static void *ap_control_proc_next(struct seq_file *m, void *v, loff_t *_pos)
374 struct ap_data *ap = m->private;
375 return seq_list_next(v, &ap->mac_restrictions.mac_list, _pos);
378 static void ap_control_proc_stop(struct seq_file *m, void *v)
380 struct ap_data *ap = m->private;
381 spin_unlock_bh(&ap->mac_restrictions.lock);
384 static const struct seq_operations ap_control_proc_seqops = {
385 .start = ap_control_proc_start,
386 .next = ap_control_proc_next,
387 .stop = ap_control_proc_stop,
388 .show = ap_control_proc_show,
391 static int ap_control_proc_open(struct inode *inode, struct file *file)
393 int ret = seq_open(file, &ap_control_proc_seqops);
395 struct seq_file *m = file->private_data;
396 m->private = PDE_DATA(inode);
401 static const struct file_operations ap_control_proc_fops = {
402 .open = ap_control_proc_open,
405 .release = seq_release,
409 int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
411 struct mac_entry *entry;
413 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
417 memcpy(entry->addr, mac, ETH_ALEN);
419 spin_lock_bh(&mac_restrictions->lock);
420 list_add_tail(&entry->list, &mac_restrictions->mac_list);
421 mac_restrictions->entries++;
422 spin_unlock_bh(&mac_restrictions->lock);
428 int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
430 struct list_head *ptr;
431 struct mac_entry *entry;
433 spin_lock_bh(&mac_restrictions->lock);
434 for (ptr = mac_restrictions->mac_list.next;
435 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
436 entry = list_entry(ptr, struct mac_entry, list);
438 if (ether_addr_equal(entry->addr, mac)) {
441 mac_restrictions->entries--;
442 spin_unlock_bh(&mac_restrictions->lock);
446 spin_unlock_bh(&mac_restrictions->lock);
451 static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
454 struct mac_entry *entry;
457 if (mac_restrictions->policy == MAC_POLICY_OPEN)
460 spin_lock_bh(&mac_restrictions->lock);
461 list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
462 if (ether_addr_equal(entry->addr, mac)) {
467 spin_unlock_bh(&mac_restrictions->lock);
469 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
476 void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
478 struct list_head *ptr, *n;
479 struct mac_entry *entry;
481 if (mac_restrictions->entries == 0)
484 spin_lock_bh(&mac_restrictions->lock);
485 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
486 ptr != &mac_restrictions->mac_list;
487 ptr = n, n = ptr->next) {
488 entry = list_entry(ptr, struct mac_entry, list);
492 mac_restrictions->entries = 0;
493 spin_unlock_bh(&mac_restrictions->lock);
497 int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
499 struct sta_info *sta;
502 spin_lock_bh(&ap->sta_table_lock);
503 sta = ap_get_sta(ap, mac);
505 ap_sta_hash_del(ap, sta);
506 list_del(&sta->list);
508 spin_unlock_bh(&ap->sta_table_lock);
513 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
514 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
515 (char *) &resp, 2, sta->addr, 0);
517 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
518 hostap_event_expired_sta(dev, sta);
520 ap_free_sta(ap, sta);
525 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
528 void ap_control_kickall(struct ap_data *ap)
530 struct list_head *ptr, *n;
531 struct sta_info *sta;
533 spin_lock_bh(&ap->sta_table_lock);
534 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
535 ptr = n, n = ptr->next) {
536 sta = list_entry(ptr, struct sta_info, list);
537 ap_sta_hash_del(ap, sta);
538 list_del(&sta->list);
539 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
540 hostap_event_expired_sta(sta->local->dev, sta);
541 ap_free_sta(ap, sta);
543 spin_unlock_bh(&ap->sta_table_lock);
547 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
549 static int prism2_ap_proc_show(struct seq_file *m, void *v)
551 struct sta_info *sta = v;
554 if (v == SEQ_START_TOKEN) {
555 seq_printf(m, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
562 seq_printf(m, "%pM %d %d %d %d '",
564 sta->u.ap.channel, sta->last_rx_signal,
565 sta->last_rx_silence, sta->last_rx_rate);
567 for (i = 0; i < sta->u.ap.ssid_len; i++) {
568 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
569 seq_putc(m, sta->u.ap.ssid[i]);
571 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
575 if (sta->capability & WLAN_CAPABILITY_ESS)
576 seq_puts(m, " [ESS]");
577 if (sta->capability & WLAN_CAPABILITY_IBSS)
578 seq_puts(m, " [IBSS]");
579 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
580 seq_puts(m, " [WEP]");
585 static void *prism2_ap_proc_start(struct seq_file *m, loff_t *_pos)
587 struct ap_data *ap = m->private;
588 spin_lock_bh(&ap->sta_table_lock);
589 return seq_list_start_head(&ap->sta_list, *_pos);
592 static void *prism2_ap_proc_next(struct seq_file *m, void *v, loff_t *_pos)
594 struct ap_data *ap = m->private;
595 return seq_list_next(v, &ap->sta_list, _pos);
598 static void prism2_ap_proc_stop(struct seq_file *m, void *v)
600 struct ap_data *ap = m->private;
601 spin_unlock_bh(&ap->sta_table_lock);
604 static const struct seq_operations prism2_ap_proc_seqops = {
605 .start = prism2_ap_proc_start,
606 .next = prism2_ap_proc_next,
607 .stop = prism2_ap_proc_stop,
608 .show = prism2_ap_proc_show,
611 static int prism2_ap_proc_open(struct inode *inode, struct file *file)
613 int ret = seq_open(file, &prism2_ap_proc_seqops);
615 struct seq_file *m = file->private_data;
616 m->private = PDE_DATA(inode);
621 static const struct file_operations prism2_ap_proc_fops = {
622 .open = prism2_ap_proc_open,
625 .release = seq_release,
627 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
630 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
635 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
636 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
637 "firmware upgrade recommended\n");
638 ap->nullfunc_ack = 1;
640 ap->nullfunc_ack = 0;
642 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
643 printk(KERN_WARNING "%s: Warning: secondary station firmware "
644 "version 1.4.2 does not seem to work in Host AP mode\n",
645 ap->local->dev->name);
650 /* Called only as a tasklet (software IRQ) */
651 static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
653 struct ap_data *ap = data;
654 struct ieee80211_hdr *hdr;
656 if (!ap->local->hostapd || !ap->local->apdev) {
661 /* Pass the TX callback frame to the hostapd; use 802.11 header version
662 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
664 hdr = (struct ieee80211_hdr *) skb->data;
665 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_VERS);
666 hdr->frame_control |= cpu_to_le16(ok ? BIT(1) : BIT(0));
668 skb->dev = ap->local->apdev;
669 skb_pull(skb, hostap_80211_get_hdrlen(hdr->frame_control));
670 skb->pkt_type = PACKET_OTHERHOST;
671 skb->protocol = cpu_to_be16(ETH_P_802_2);
672 memset(skb->cb, 0, sizeof(skb->cb));
677 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
678 /* Called only as a tasklet (software IRQ) */
679 static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
681 struct ap_data *ap = data;
682 struct net_device *dev = ap->local->dev;
683 struct ieee80211_hdr *hdr;
684 u16 auth_alg, auth_transaction, status;
686 struct sta_info *sta = NULL;
689 if (ap->local->hostapd) {
694 hdr = (struct ieee80211_hdr *) skb->data;
695 if (!ieee80211_is_auth(hdr->frame_control) ||
696 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
697 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
698 "frame\n", dev->name);
703 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
704 auth_alg = le16_to_cpu(*pos++);
705 auth_transaction = le16_to_cpu(*pos++);
706 status = le16_to_cpu(*pos++);
709 txt = "frame was not ACKed";
713 spin_lock(&ap->sta_table_lock);
714 sta = ap_get_sta(ap, hdr->addr1);
716 atomic_inc(&sta->users);
717 spin_unlock(&ap->sta_table_lock);
720 txt = "STA not found";
724 if (status == WLAN_STATUS_SUCCESS &&
725 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
726 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
727 txt = "STA authenticated";
728 sta->flags |= WLAN_STA_AUTH;
729 sta->last_auth = jiffies;
730 } else if (status != WLAN_STATUS_SUCCESS)
731 txt = "authentication failed";
735 atomic_dec(&sta->users);
737 PDEBUG(DEBUG_AP, "%s: %pM auth_cb - alg=%d "
738 "trans#=%d status=%d - %s\n",
739 dev->name, hdr->addr1,
740 auth_alg, auth_transaction, status, txt);
746 /* Called only as a tasklet (software IRQ) */
747 static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
749 struct ap_data *ap = data;
750 struct net_device *dev = ap->local->dev;
751 struct ieee80211_hdr *hdr;
754 struct sta_info *sta = NULL;
757 if (ap->local->hostapd) {
762 hdr = (struct ieee80211_hdr *) skb->data;
763 if ((!ieee80211_is_assoc_resp(hdr->frame_control) &&
764 !ieee80211_is_reassoc_resp(hdr->frame_control)) ||
765 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
766 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
767 "frame\n", dev->name);
773 txt = "frame was not ACKed";
777 spin_lock(&ap->sta_table_lock);
778 sta = ap_get_sta(ap, hdr->addr1);
780 atomic_inc(&sta->users);
781 spin_unlock(&ap->sta_table_lock);
784 txt = "STA not found";
788 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
790 status = le16_to_cpu(*pos++);
791 if (status == WLAN_STATUS_SUCCESS) {
792 if (!(sta->flags & WLAN_STA_ASSOC))
793 hostap_event_new_sta(dev, sta);
794 txt = "STA associated";
795 sta->flags |= WLAN_STA_ASSOC;
796 sta->last_assoc = jiffies;
798 txt = "association failed";
802 atomic_dec(&sta->users);
804 PDEBUG(DEBUG_AP, "%s: %pM assoc_cb - %s\n",
805 dev->name, hdr->addr1, txt);
810 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
811 * in verifying whether the STA is still present. */
812 static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
814 struct ap_data *ap = data;
815 struct ieee80211_hdr *hdr;
816 struct sta_info *sta;
820 hdr = (struct ieee80211_hdr *) skb->data;
822 spin_lock(&ap->sta_table_lock);
823 sta = ap_get_sta(ap, hdr->addr1);
825 sta->flags &= ~WLAN_STA_PENDING_POLL;
826 spin_unlock(&ap->sta_table_lock);
829 "%s: STA %pM did not ACK activity poll frame\n",
830 ap->local->dev->name, hdr->addr1);
836 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
839 void hostap_init_data(local_info_t *local)
841 struct ap_data *ap = local->ap;
844 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
847 memset(ap, 0, sizeof(struct ap_data));
850 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
851 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
853 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
854 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
856 spin_lock_init(&ap->sta_table_lock);
857 INIT_LIST_HEAD(&ap->sta_list);
859 /* Initialize task queue structure for AP management */
860 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
862 ap->tx_callback_idx =
863 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
864 if (ap->tx_callback_idx == 0)
865 printk(KERN_WARNING "%s: failed to register TX callback for "
866 "AP\n", local->dev->name);
867 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
868 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
870 ap->tx_callback_auth =
871 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
872 ap->tx_callback_assoc =
873 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
874 ap->tx_callback_poll =
875 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
876 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
877 ap->tx_callback_poll == 0)
878 printk(KERN_WARNING "%s: failed to register TX callback for "
879 "AP\n", local->dev->name);
881 spin_lock_init(&ap->mac_restrictions.lock);
882 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
883 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
889 void hostap_init_ap_proc(local_info_t *local)
891 struct ap_data *ap = local->ap;
893 ap->proc = local->proc;
894 if (ap->proc == NULL)
897 #ifndef PRISM2_NO_PROCFS_DEBUG
898 proc_create_data("ap_debug", 0, ap->proc, &ap_debug_proc_fops, ap);
899 #endif /* PRISM2_NO_PROCFS_DEBUG */
901 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
902 proc_create_data("ap_control", 0, ap->proc, &ap_control_proc_fops, ap);
903 proc_create_data("ap", 0, ap->proc, &prism2_ap_proc_fops, ap);
904 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
909 void hostap_free_data(struct ap_data *ap)
911 struct sta_info *n, *sta;
913 if (ap == NULL || !ap->initialized) {
914 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
915 "initialized - skip resource freeing\n");
919 flush_work(&ap->add_sta_proc_queue);
921 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
922 flush_work(&ap->wds_oper_queue);
924 ap->crypt->deinit(ap->crypt_priv);
925 ap->crypt = ap->crypt_priv = NULL;
926 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
928 list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
929 ap_sta_hash_del(ap, sta);
930 list_del(&sta->list);
931 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
932 hostap_event_expired_sta(sta->local->dev, sta);
933 ap_free_sta(ap, sta);
936 #ifndef PRISM2_NO_PROCFS_DEBUG
937 if (ap->proc != NULL) {
938 remove_proc_entry("ap_debug", ap->proc);
940 #endif /* PRISM2_NO_PROCFS_DEBUG */
942 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
943 if (ap->proc != NULL) {
944 remove_proc_entry("ap", ap->proc);
945 remove_proc_entry("ap_control", ap->proc);
947 ap_control_flush_macs(&ap->mac_restrictions);
948 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
954 /* caller should have mutex for AP STA list handling */
955 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
959 s = ap->sta_hash[STA_HASH(sta)];
960 while (s != NULL && !ether_addr_equal(s->addr, sta))
966 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
968 /* Called from timer handler and from scheduled AP queue handlers */
969 static void prism2_send_mgmt(struct net_device *dev,
970 u16 type_subtype, char *body,
971 int body_len, u8 *addr, u16 tx_cb_idx)
973 struct hostap_interface *iface;
975 struct ieee80211_hdr *hdr;
978 struct hostap_skb_tx_data *meta;
981 iface = netdev_priv(dev);
982 local = iface->local;
983 dev = local->dev; /* always use master radio device */
984 iface = netdev_priv(dev);
986 if (!(dev->flags & IFF_UP)) {
987 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
988 "cannot send frame\n", dev->name);
992 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
994 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
1000 hdrlen = hostap_80211_get_hdrlen(cpu_to_le16(type_subtype));
1001 hdr = skb_put_zero(skb, hdrlen);
1003 memcpy(skb_put(skb, body_len), body, body_len);
1005 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
1006 * tx_control instead of using local->tx_control */
1009 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
1010 if (ieee80211_is_data(hdr->frame_control)) {
1011 fc |= IEEE80211_FCTL_FROMDS;
1012 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
1013 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
1014 } else if (ieee80211_is_ctl(hdr->frame_control)) {
1015 /* control:ACK does not have addr2 or addr3 */
1016 eth_zero_addr(hdr->addr2);
1017 eth_zero_addr(hdr->addr3);
1019 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
1020 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
1023 hdr->frame_control = cpu_to_le16(fc);
1025 meta = (struct hostap_skb_tx_data *) skb->cb;
1026 memset(meta, 0, sizeof(*meta));
1027 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1028 meta->iface = iface;
1029 meta->tx_cb_idx = tx_cb_idx;
1032 skb_reset_mac_header(skb);
1033 skb_reset_network_header(skb);
1034 dev_queue_xmit(skb);
1036 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1039 static int prism2_sta_proc_show(struct seq_file *m, void *v)
1041 struct sta_info *sta = m->private;
1044 /* FIX: possible race condition.. the STA data could have just expired,
1045 * but proc entry was still here so that the read could have started;
1046 * some locking should be done here.. */
1049 "%s=%pM\nusers=%d\naid=%d\n"
1050 "flags=0x%04x%s%s%s%s%s%s%s\n"
1051 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1052 sta->ap ? "AP" : "STA",
1053 sta->addr, atomic_read(&sta->users), sta->aid,
1055 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1056 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1057 sta->flags & WLAN_STA_PS ? " PS" : "",
1058 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1059 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1060 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1061 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1062 sta->capability, sta->listen_interval);
1063 /* supported_rates: 500 kbit/s units with msb ignored */
1064 for (i = 0; i < sizeof(sta->supported_rates); i++)
1065 if (sta->supported_rates[i] != 0)
1066 seq_printf(m, "%d%sMbps ",
1067 (sta->supported_rates[i] & 0x7f) / 2,
1068 sta->supported_rates[i] & 1 ? ".5" : "");
1070 "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1071 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1073 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1074 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1075 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1077 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1078 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1080 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1081 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1082 sta->last_rx_silence,
1083 sta->last_rx_signal, sta->last_rx_rate / 10,
1084 sta->last_rx_rate % 10 ? ".5" : "",
1085 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1086 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1087 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1088 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1089 sta->crypt->ops->print_stats(m, sta->crypt->priv);
1090 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1092 if (sta->u.ap.channel >= 0)
1093 seq_printf(m, "channel=%d\n", sta->u.ap.channel);
1094 seq_puts(m, "ssid=");
1095 for (i = 0; i < sta->u.ap.ssid_len; i++) {
1096 if (sta->u.ap.ssid[i] >= 32 && sta->u.ap.ssid[i] < 127)
1097 seq_putc(m, sta->u.ap.ssid[i]);
1099 seq_printf(m, "<%02x>", sta->u.ap.ssid[i]);
1103 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1108 static int prism2_sta_proc_open(struct inode *inode, struct file *file)
1110 return single_open(file, prism2_sta_proc_show, PDE_DATA(inode));
1113 static const struct file_operations prism2_sta_proc_fops = {
1114 .open = prism2_sta_proc_open,
1116 .llseek = seq_lseek,
1117 .release = single_release,
1120 static void handle_add_proc_queue(struct work_struct *work)
1122 struct ap_data *ap = container_of(work, struct ap_data,
1123 add_sta_proc_queue);
1124 struct sta_info *sta;
1126 struct add_sta_proc_data *entry, *prev;
1128 entry = ap->add_sta_proc_entries;
1129 ap->add_sta_proc_entries = NULL;
1132 spin_lock_bh(&ap->sta_table_lock);
1133 sta = ap_get_sta(ap, entry->addr);
1135 atomic_inc(&sta->users);
1136 spin_unlock_bh(&ap->sta_table_lock);
1139 sprintf(name, "%pM", sta->addr);
1140 sta->proc = proc_create_data(
1142 &prism2_sta_proc_fops, sta);
1144 atomic_dec(&sta->users);
1148 entry = entry->next;
1154 static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1156 struct sta_info *sta;
1158 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
1160 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1164 /* initialize STA info data */
1165 sta->local = ap->local;
1166 skb_queue_head_init(&sta->tx_buf);
1167 memcpy(sta->addr, addr, ETH_ALEN);
1169 atomic_inc(&sta->users);
1170 spin_lock_bh(&ap->sta_table_lock);
1171 list_add(&sta->list, &ap->sta_list);
1173 ap_sta_hash_add(ap, sta);
1174 spin_unlock_bh(&ap->sta_table_lock);
1177 struct add_sta_proc_data *entry;
1178 /* schedule a non-interrupt context process to add a procfs
1179 * entry for the STA since procfs code use GFP_KERNEL */
1180 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1182 memcpy(entry->addr, sta->addr, ETH_ALEN);
1183 entry->next = ap->add_sta_proc_entries;
1184 ap->add_sta_proc_entries = entry;
1185 schedule_work(&ap->add_sta_proc_queue);
1187 printk(KERN_DEBUG "Failed to add STA proc data\n");
1190 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1191 init_timer(&sta->timer);
1192 sta->timer.expires = jiffies + ap->max_inactivity;
1193 sta->timer.data = (unsigned long) sta;
1194 sta->timer.function = ap_handle_timer;
1195 if (!ap->local->hostapd)
1196 add_timer(&sta->timer);
1197 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1203 static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1204 local_info_t *local)
1206 if (rateidx > sta->tx_max_rate ||
1207 !(sta->tx_supp_rates & (1 << rateidx)))
1210 if (local->tx_rate_control != 0 &&
1211 !(local->tx_rate_control & (1 << rateidx)))
1218 static void prism2_check_tx_rates(struct sta_info *sta)
1222 sta->tx_supp_rates = 0;
1223 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1224 if ((sta->supported_rates[i] & 0x7f) == 2)
1225 sta->tx_supp_rates |= WLAN_RATE_1M;
1226 if ((sta->supported_rates[i] & 0x7f) == 4)
1227 sta->tx_supp_rates |= WLAN_RATE_2M;
1228 if ((sta->supported_rates[i] & 0x7f) == 11)
1229 sta->tx_supp_rates |= WLAN_RATE_5M5;
1230 if ((sta->supported_rates[i] & 0x7f) == 22)
1231 sta->tx_supp_rates |= WLAN_RATE_11M;
1233 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1234 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1235 sta->tx_max_rate = 0;
1236 if (ap_tx_rate_ok(0, sta, sta->local)) {
1238 sta->tx_rate_idx = 0;
1241 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1242 sta->tx_max_rate = 1;
1243 if (ap_tx_rate_ok(1, sta, sta->local)) {
1245 sta->tx_rate_idx = 1;
1248 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1249 sta->tx_max_rate = 2;
1250 if (ap_tx_rate_ok(2, sta, sta->local)) {
1252 sta->tx_rate_idx = 2;
1255 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1256 sta->tx_max_rate = 3;
1257 if (ap_tx_rate_ok(3, sta, sta->local)) {
1259 sta->tx_rate_idx = 3;
1265 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1267 static void ap_crypt_init(struct ap_data *ap)
1269 ap->crypt = lib80211_get_crypto_ops("WEP");
1272 if (ap->crypt->init) {
1273 ap->crypt_priv = ap->crypt->init(0);
1274 if (ap->crypt_priv == NULL)
1277 u8 key[WEP_KEY_LEN];
1278 get_random_bytes(key, WEP_KEY_LEN);
1279 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1285 if (ap->crypt == NULL) {
1286 printk(KERN_WARNING "AP could not initialize WEP: load module "
1287 "lib80211_crypt_wep.ko\n");
1292 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1293 * that WEP algorithm is used for generating challenge. This should be unique,
1294 * but otherwise there is not really need for randomness etc. Initialize WEP
1295 * with pseudo random key and then use increasing IV to get unique challenge
1298 * Called only as a scheduled task for pending AP frames.
1300 static char * ap_auth_make_challenge(struct ap_data *ap)
1303 struct sk_buff *skb;
1305 if (ap->crypt == NULL) {
1307 if (ap->crypt == NULL)
1311 tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1312 if (tmpbuf == NULL) {
1313 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1317 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1318 ap->crypt->extra_mpdu_prefix_len +
1319 ap->crypt->extra_mpdu_postfix_len);
1325 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
1326 skb_put_zero(skb, WLAN_AUTH_CHALLENGE_LEN);
1327 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1333 skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
1334 tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
1341 /* Called only as a scheduled task for pending AP frames. */
1342 static void handle_authen(local_info_t *local, struct sk_buff *skb,
1343 struct hostap_80211_rx_status *rx_stats)
1345 struct net_device *dev = local->dev;
1346 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1348 struct ap_data *ap = local->ap;
1349 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1351 u16 auth_alg, auth_transaction, status_code;
1353 u16 resp = WLAN_STATUS_SUCCESS;
1354 struct sta_info *sta = NULL;
1355 struct lib80211_crypt_data *crypt;
1358 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1360 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
1363 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1364 "(len=%d) from %pM\n", dev->name, len, hdr->addr2);
1368 spin_lock_bh(&local->ap->sta_table_lock);
1369 sta = ap_get_sta(local->ap, hdr->addr2);
1371 atomic_inc(&sta->users);
1372 spin_unlock_bh(&local->ap->sta_table_lock);
1374 if (sta && sta->crypt)
1378 if (skb->len >= hdrlen + 3)
1379 idx = skb->data[hdrlen + 3] >> 6;
1380 crypt = local->crypt_info.crypt[idx];
1383 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1384 auth_alg = __le16_to_cpu(*pos);
1386 auth_transaction = __le16_to_cpu(*pos);
1388 status_code = __le16_to_cpu(*pos);
1391 if (ether_addr_equal(dev->dev_addr, hdr->addr2) ||
1392 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1393 txt = "authentication denied";
1394 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1398 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1399 auth_alg == WLAN_AUTH_OPEN) ||
1400 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1401 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1403 txt = "unsupported algorithm";
1404 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1410 if (*u == WLAN_EID_CHALLENGE) {
1411 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1412 txt = "invalid challenge len";
1413 resp = WLAN_STATUS_CHALLENGE_FAIL;
1416 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1417 txt = "challenge underflow";
1418 resp = WLAN_STATUS_CHALLENGE_FAIL;
1421 challenge = (char *) (u + 2);
1425 if (sta && sta->ap) {
1426 if (time_after(jiffies, sta->u.ap.last_beacon +
1427 (10 * sta->listen_interval * HZ) / 1024)) {
1428 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1429 " assuming AP %pM is now STA\n",
1430 dev->name, sta->addr);
1433 sta->u.sta.challenge = NULL;
1435 txt = "AP trying to authenticate?";
1436 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1441 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1442 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1443 (auth_transaction == 1 ||
1444 (auth_transaction == 3 && sta != NULL &&
1445 sta->u.sta.challenge != NULL)))) {
1447 txt = "unknown authentication transaction number";
1448 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1455 if (local->ap->num_sta >= MAX_STA_COUNT) {
1456 /* FIX: might try to remove some old STAs first? */
1457 txt = "no more room for new STAs";
1458 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1462 sta = ap_add_sta(local->ap, hdr->addr2);
1464 txt = "ap_add_sta failed";
1465 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1471 case WLAN_AUTH_OPEN:
1473 /* IEEE 802.11 standard is not completely clear about
1474 * whether STA is considered authenticated after
1475 * authentication OK frame has been send or after it
1476 * has been ACKed. In order to reduce interoperability
1477 * issues, mark the STA authenticated before ACK. */
1478 sta->flags |= WLAN_STA_AUTH;
1481 case WLAN_AUTH_SHARED_KEY:
1482 if (auth_transaction == 1) {
1483 if (sta->u.sta.challenge == NULL) {
1484 sta->u.sta.challenge =
1485 ap_auth_make_challenge(local->ap);
1486 if (sta->u.sta.challenge == NULL) {
1487 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1492 if (sta->u.sta.challenge == NULL ||
1493 challenge == NULL ||
1494 memcmp(sta->u.sta.challenge, challenge,
1495 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
1496 !ieee80211_has_protected(hdr->frame_control)) {
1497 txt = "challenge response incorrect";
1498 resp = WLAN_STATUS_CHALLENGE_FAIL;
1502 txt = "challenge OK - authOK";
1503 /* IEEE 802.11 standard is not completely clear about
1504 * whether STA is considered authenticated after
1505 * authentication OK frame has been send or after it
1506 * has been ACKed. In order to reduce interoperability
1507 * issues, mark the STA authenticated before ACK. */
1508 sta->flags |= WLAN_STA_AUTH;
1509 kfree(sta->u.sta.challenge);
1510 sta->u.sta.challenge = NULL;
1516 pos = (__le16 *) body;
1517 *pos = cpu_to_le16(auth_alg);
1519 *pos = cpu_to_le16(auth_transaction + 1);
1521 *pos = cpu_to_le16(resp); /* status_code */
1525 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1526 sta->u.sta.challenge != NULL &&
1527 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1528 u8 *tmp = (u8 *) pos;
1529 *tmp++ = WLAN_EID_CHALLENGE;
1530 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1532 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1533 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1536 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
1537 body, olen, hdr->addr2, ap->tx_callback_auth);
1540 sta->last_rx = jiffies;
1541 atomic_dec(&sta->users);
1545 PDEBUG(DEBUG_AP, "%s: %pM auth (alg=%d "
1546 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1547 dev->name, hdr->addr2,
1548 auth_alg, auth_transaction, status_code, len,
1549 le16_to_cpu(hdr->frame_control), resp, txt);
1554 /* Called only as a scheduled task for pending AP frames. */
1555 static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1556 struct hostap_80211_rx_status *rx_stats, int reassoc)
1558 struct net_device *dev = local->dev;
1559 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1560 char body[12], *p, *lpos;
1563 u16 resp = WLAN_STATUS_SUCCESS;
1564 struct sta_info *sta = NULL;
1565 int send_deauth = 0;
1567 u8 prev_ap[ETH_ALEN];
1569 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1571 if (len < (reassoc ? 10 : 4)) {
1572 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1573 "(len=%d, reassoc=%d) from %pM\n",
1574 dev->name, len, reassoc, hdr->addr2);
1578 spin_lock_bh(&local->ap->sta_table_lock);
1579 sta = ap_get_sta(local->ap, hdr->addr2);
1580 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1581 spin_unlock_bh(&local->ap->sta_table_lock);
1582 txt = "trying to associate before authentication";
1584 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1585 sta = NULL; /* do not decrement sta->users */
1588 atomic_inc(&sta->users);
1589 spin_unlock_bh(&local->ap->sta_table_lock);
1591 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1592 sta->capability = __le16_to_cpu(*pos);
1594 sta->listen_interval = __le16_to_cpu(*pos);
1598 memcpy(prev_ap, pos, ETH_ALEN);
1599 pos++; pos++; pos++; left -= 6;
1601 eth_zero_addr(prev_ap);
1605 unsigned char *u = (unsigned char *) pos;
1607 if (*u == WLAN_EID_SSID) {
1612 if (ileft > left || ileft > MAX_SSID_LEN) {
1613 txt = "SSID overflow";
1614 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1618 if (ileft != strlen(local->essid) ||
1619 memcmp(local->essid, u, ileft) != 0) {
1620 txt = "not our SSID";
1621 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1629 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1634 if (ileft > left || ileft == 0 ||
1635 ileft > WLAN_SUPP_RATES_MAX) {
1636 txt = "SUPP_RATES len error";
1637 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1641 memset(sta->supported_rates, 0,
1642 sizeof(sta->supported_rates));
1643 memcpy(sta->supported_rates, u, ileft);
1644 prism2_check_tx_rates(sta);
1651 PDEBUG(DEBUG_AP, "%s: assoc from %pM"
1652 " with extra data (%d bytes) [",
1653 dev->name, hdr->addr2, left);
1655 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1658 PDEBUG2(DEBUG_AP, "]\n");
1661 txt = "frame underflow";
1662 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1666 /* get a unique AID */
1668 txt = "OK, old AID";
1670 spin_lock_bh(&local->ap->sta_table_lock);
1671 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1672 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1674 if (sta->aid > MAX_AID_TABLE_SIZE) {
1676 spin_unlock_bh(&local->ap->sta_table_lock);
1677 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1678 txt = "no room for more AIDs";
1680 local->ap->sta_aid[sta->aid - 1] = sta;
1681 spin_unlock_bh(&local->ap->sta_table_lock);
1682 txt = "OK, new AID";
1687 pos = (__le16 *) body;
1690 *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1693 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1694 * values in beacons/probe responses */
1695 /* FIX: how about privacy and WEP? */
1697 *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
1701 *pos = cpu_to_le16(resp);
1704 *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1705 BIT(14) | BIT(15)); /* AID */
1708 /* Supported rates (Information element) */
1710 *p++ = WLAN_EID_SUPP_RATES;
1713 if (local->tx_rate_control & WLAN_RATE_1M) {
1714 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1717 if (local->tx_rate_control & WLAN_RATE_2M) {
1718 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1721 if (local->tx_rate_control & WLAN_RATE_5M5) {
1722 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1726 if (local->tx_rate_control & WLAN_RATE_11M) {
1727 *p++ = local->basic_rates & WLAN_RATE_11M ?
1734 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1735 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1736 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1737 IEEE80211_STYPE_ASSOC_RESP)),
1738 body, (u8 *) pos - (u8 *) body,
1740 send_deauth ? 0 : local->ap->tx_callback_assoc);
1743 if (resp == WLAN_STATUS_SUCCESS) {
1744 sta->last_rx = jiffies;
1745 /* STA will be marked associated from TX callback, if
1746 * AssocResp is ACKed */
1748 atomic_dec(&sta->users);
1752 PDEBUG(DEBUG_AP, "%s: %pM %sassoc (len=%d "
1753 "prev_ap=%pM) => %d(%d) (%s)\n",
1756 reassoc ? "re" : "", len,
1758 resp, send_deauth, txt);
1763 /* Called only as a scheduled task for pending AP frames. */
1764 static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1765 struct hostap_80211_rx_status *rx_stats)
1767 struct net_device *dev = local->dev;
1768 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1769 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1773 struct sta_info *sta = NULL;
1775 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1778 printk("handle_deauth - too short payload (len=%d)\n", len);
1782 pos = (__le16 *) body;
1783 reason_code = le16_to_cpu(*pos);
1785 PDEBUG(DEBUG_AP, "%s: deauthentication: %pM len=%d, "
1786 "reason_code=%d\n", dev->name, hdr->addr2,
1789 spin_lock_bh(&local->ap->sta_table_lock);
1790 sta = ap_get_sta(local->ap, hdr->addr2);
1792 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1793 hostap_event_expired_sta(local->dev, sta);
1794 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1796 spin_unlock_bh(&local->ap->sta_table_lock);
1798 printk("%s: deauthentication from %pM, "
1799 "reason_code=%d, but STA not authenticated\n", dev->name,
1800 hdr->addr2, reason_code);
1805 /* Called only as a scheduled task for pending AP frames. */
1806 static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1807 struct hostap_80211_rx_status *rx_stats)
1809 struct net_device *dev = local->dev;
1810 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1811 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1815 struct sta_info *sta = NULL;
1817 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1820 printk("handle_disassoc - too short payload (len=%d)\n", len);
1824 pos = (__le16 *) body;
1825 reason_code = le16_to_cpu(*pos);
1827 PDEBUG(DEBUG_AP, "%s: disassociation: %pM len=%d, "
1828 "reason_code=%d\n", dev->name, hdr->addr2,
1831 spin_lock_bh(&local->ap->sta_table_lock);
1832 sta = ap_get_sta(local->ap, hdr->addr2);
1834 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1835 hostap_event_expired_sta(local->dev, sta);
1836 sta->flags &= ~WLAN_STA_ASSOC;
1838 spin_unlock_bh(&local->ap->sta_table_lock);
1840 printk("%s: disassociation from %pM, "
1841 "reason_code=%d, but STA not authenticated\n",
1842 dev->name, hdr->addr2, reason_code);
1847 /* Called only as a scheduled task for pending AP frames. */
1848 static void ap_handle_data_nullfunc(local_info_t *local,
1849 struct ieee80211_hdr *hdr)
1851 struct net_device *dev = local->dev;
1853 /* some STA f/w's seem to require control::ACK frame for
1854 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1856 * send control::ACK for the data::nullfunc */
1858 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1859 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
1860 NULL, 0, hdr->addr2, 0);
1864 /* Called only as a scheduled task for pending AP frames. */
1865 static void ap_handle_dropped_data(local_info_t *local,
1866 struct ieee80211_hdr *hdr)
1868 struct net_device *dev = local->dev;
1869 struct sta_info *sta;
1872 spin_lock_bh(&local->ap->sta_table_lock);
1873 sta = ap_get_sta(local->ap, hdr->addr2);
1875 atomic_inc(&sta->users);
1876 spin_unlock_bh(&local->ap->sta_table_lock);
1878 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1879 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1880 atomic_dec(&sta->users);
1884 reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1885 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1886 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1887 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
1888 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1891 atomic_dec(&sta->users);
1894 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1897 /* Called only as a scheduled task for pending AP frames. */
1898 static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1899 struct sk_buff *skb)
1901 struct hostap_skb_tx_data *meta;
1903 if (!(sta->flags & WLAN_STA_PS)) {
1904 /* Station has moved to non-PS mode, so send all buffered
1905 * frames using normal device queue. */
1906 dev_queue_xmit(skb);
1910 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1911 * be passed through even though STA is using PS */
1912 meta = (struct hostap_skb_tx_data *) skb->cb;
1913 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
1914 if (!skb_queue_empty(&sta->tx_buf)) {
1915 /* indicate to STA that more frames follow */
1916 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
1918 dev_queue_xmit(skb);
1922 /* Called only as a scheduled task for pending AP frames. */
1923 static void handle_pspoll(local_info_t *local,
1924 struct ieee80211_hdr *hdr,
1925 struct hostap_80211_rx_status *rx_stats)
1927 struct net_device *dev = local->dev;
1928 struct sta_info *sta;
1930 struct sk_buff *skb;
1932 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1933 hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
1935 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
1937 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1942 aid = le16_to_cpu(hdr->duration_id);
1943 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1944 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1947 aid &= ~(BIT(15) | BIT(14));
1948 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1949 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1952 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1954 spin_lock_bh(&local->ap->sta_table_lock);
1955 sta = ap_get_sta(local->ap, hdr->addr2);
1957 atomic_inc(&sta->users);
1958 spin_unlock_bh(&local->ap->sta_table_lock);
1961 PDEBUG(DEBUG_PS, " STA not found\n");
1964 if (sta->aid != aid) {
1965 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1966 "assoc.aid=%d\n", aid, sta->aid);
1971 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1972 * out (expiry time must be longer than ListenInterval for
1973 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1974 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1975 * sta; store buffer for later use and leave TIM aid bit set? use
1976 * TX event to check whether frame was ACKed?
1979 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1980 /* send buffered frame .. */
1981 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1982 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1984 pspoll_send_buffered(local, sta, skb);
1986 if (sta->flags & WLAN_STA_PS) {
1987 /* send only one buffered packet per PS Poll */
1988 /* FIX: should ignore further PS Polls until the
1989 * buffered packet that was just sent is acknowledged
1990 * (Tx or TxExc event) */
1995 if (skb_queue_empty(&sta->tx_buf)) {
1996 /* try to clear aid from TIM */
1997 if (!(sta->flags & WLAN_STA_TIM))
1998 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
2000 hostap_set_tim(local, aid, 0);
2001 sta->flags &= ~WLAN_STA_TIM;
2004 atomic_dec(&sta->users);
2008 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2010 static void handle_wds_oper_queue(struct work_struct *work)
2012 struct ap_data *ap = container_of(work, struct ap_data,
2014 local_info_t *local = ap->local;
2015 struct wds_oper_data *entry, *prev;
2017 spin_lock_bh(&local->lock);
2018 entry = local->ap->wds_oper_entries;
2019 local->ap->wds_oper_entries = NULL;
2020 spin_unlock_bh(&local->lock);
2023 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
2026 entry->type == WDS_ADD ? "adding" : "removing",
2028 if (entry->type == WDS_ADD)
2029 prism2_wds_add(local, entry->addr, 0);
2030 else if (entry->type == WDS_DEL)
2031 prism2_wds_del(local, entry->addr, 0, 1);
2034 entry = entry->next;
2040 /* Called only as a scheduled task for pending AP frames. */
2041 static void handle_beacon(local_info_t *local, struct sk_buff *skb,
2042 struct hostap_80211_rx_status *rx_stats)
2044 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2045 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
2047 u16 beacon_int, capability;
2050 unsigned char *supp_rates = NULL;
2051 int ssid_len = 0, supp_rates_len = 0;
2052 struct sta_info *sta = NULL;
2053 int new_sta = 0, channel = -1;
2055 len = skb->len - IEEE80211_MGMT_HDR_LEN;
2057 if (len < 8 + 2 + 2) {
2058 printk(KERN_DEBUG "handle_beacon - too short payload "
2063 pos = (__le16 *) body;
2066 /* Timestamp (8 octets) */
2067 pos += 4; left -= 8;
2068 /* Beacon interval (2 octets) */
2069 beacon_int = le16_to_cpu(*pos);
2071 /* Capability information (2 octets) */
2072 capability = le16_to_cpu(*pos);
2075 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2076 capability & WLAN_CAPABILITY_IBSS)
2081 unsigned char *u = (unsigned char *) pos;
2083 if (*u == WLAN_EID_SSID) {
2088 if (ileft > left || ileft > MAX_SSID_LEN) {
2089 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2093 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2094 (ileft != strlen(local->essid) ||
2095 memcmp(local->essid, u, ileft) != 0)) {
2107 if (*u == WLAN_EID_SUPP_RATES) {
2112 if (ileft > left || ileft == 0 || ileft > 8) {
2113 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2118 supp_rates_len = ileft;
2124 if (*u == WLAN_EID_DS_PARAMS) {
2129 if (ileft > left || ileft != 1) {
2130 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2141 spin_lock_bh(&local->ap->sta_table_lock);
2142 sta = ap_get_sta(local->ap, hdr->addr2);
2144 atomic_inc(&sta->users);
2145 spin_unlock_bh(&local->ap->sta_table_lock);
2150 sta = ap_add_sta(local->ap, hdr->addr2);
2152 printk(KERN_INFO "prism2: kmalloc failed for AP "
2153 "data structure\n");
2156 hostap_event_new_sta(local->dev, sta);
2158 /* mark APs authentication and associated for pseudo ad-hoc
2159 * style communication */
2160 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2162 if (local->ap->autom_ap_wds) {
2163 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2169 sta->u.ap.ssid_len = ssid_len;
2170 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2171 sta->u.ap.ssid[ssid_len] = '\0';
2173 sta->u.ap.ssid_len = 0;
2174 sta->u.ap.ssid[0] = '\0';
2176 sta->u.ap.channel = channel;
2178 sta->rx_bytes += len;
2179 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2180 sta->capability = capability;
2181 sta->listen_interval = beacon_int;
2183 atomic_dec(&sta->users);
2186 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2187 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2188 prism2_check_tx_rates(sta);
2192 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2195 /* Called only as a tasklet. */
2196 static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2197 struct hostap_80211_rx_status *rx_stats)
2199 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2200 struct net_device *dev = local->dev;
2201 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2202 u16 fc, type, stype;
2203 struct ieee80211_hdr *hdr;
2205 /* FIX: should give skb->len to handler functions and check that the
2206 * buffer is long enough */
2207 hdr = (struct ieee80211_hdr *) skb->data;
2208 fc = le16_to_cpu(hdr->frame_control);
2209 type = fc & IEEE80211_FCTL_FTYPE;
2210 stype = fc & IEEE80211_FCTL_STYPE;
2212 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2213 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
2214 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2216 if (!(fc & IEEE80211_FCTL_TODS) ||
2217 (fc & IEEE80211_FCTL_FROMDS)) {
2218 if (stype == IEEE80211_STYPE_NULLFUNC) {
2219 /* no ToDS nullfunc seems to be used to check
2220 * AP association; so send reject message to
2221 * speed up re-association */
2222 ap_handle_dropped_data(local, hdr);
2225 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2230 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2231 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
2232 " not own MAC\n", hdr->addr1);
2236 if (local->ap->nullfunc_ack &&
2237 stype == IEEE80211_STYPE_NULLFUNC)
2238 ap_handle_data_nullfunc(local, hdr);
2240 ap_handle_dropped_data(local, hdr);
2244 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
2245 handle_beacon(local, skb, rx_stats);
2248 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2250 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
2251 handle_pspoll(local, hdr, rx_stats);
2255 if (local->hostapd) {
2256 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2257 "subtype=0x%02x\n", type, stype);
2261 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2262 if (type != IEEE80211_FTYPE_MGMT) {
2263 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2267 if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
2268 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
2269 " not own MAC\n", hdr->addr1);
2273 if (!ether_addr_equal(hdr->addr3, dev->dev_addr)) {
2274 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
2275 " not own MAC\n", hdr->addr3);
2280 case IEEE80211_STYPE_ASSOC_REQ:
2281 handle_assoc(local, skb, rx_stats, 0);
2283 case IEEE80211_STYPE_ASSOC_RESP:
2284 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2286 case IEEE80211_STYPE_REASSOC_REQ:
2287 handle_assoc(local, skb, rx_stats, 1);
2289 case IEEE80211_STYPE_REASSOC_RESP:
2290 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2292 case IEEE80211_STYPE_ATIM:
2293 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2295 case IEEE80211_STYPE_DISASSOC:
2296 handle_disassoc(local, skb, rx_stats);
2298 case IEEE80211_STYPE_AUTH:
2299 handle_authen(local, skb, rx_stats);
2301 case IEEE80211_STYPE_DEAUTH:
2302 handle_deauth(local, skb, rx_stats);
2305 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2309 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2316 /* Called only as a tasklet (software IRQ) */
2317 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2318 struct hostap_80211_rx_status *rx_stats)
2320 struct hostap_interface *iface;
2321 local_info_t *local;
2322 struct ieee80211_hdr *hdr;
2324 iface = netdev_priv(dev);
2325 local = iface->local;
2330 dev->stats.rx_packets++;
2332 hdr = (struct ieee80211_hdr *) skb->data;
2334 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2335 ieee80211_is_beacon(hdr->frame_control))
2338 skb->protocol = cpu_to_be16(ETH_P_HOSTAP);
2339 handle_ap_item(local, skb, rx_stats);
2347 /* Called only as a tasklet (software IRQ) */
2348 static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2350 struct sk_buff *skb;
2351 struct ieee80211_hdr *hdr;
2352 struct hostap_80211_rx_status rx_stats;
2354 if (skb_queue_empty(&sta->tx_buf))
2357 skb = dev_alloc_skb(16);
2359 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2360 "failed\n", local->dev->name);
2364 hdr = (struct ieee80211_hdr *) skb_put(skb, 16);
2366 /* Generate a fake pspoll frame to start packet delivery */
2367 hdr->frame_control = cpu_to_le16(
2368 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
2369 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2370 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2371 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2374 "%s: Scheduling buffered packet delivery for STA %pM\n",
2375 local->dev->name, sta->addr);
2377 skb->dev = local->dev;
2379 memset(&rx_stats, 0, sizeof(rx_stats));
2380 hostap_rx(local->dev, skb, &rx_stats);
2384 int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2385 struct iw_quality qual[], int buf_size,
2388 struct ap_data *ap = local->ap;
2389 struct list_head *ptr;
2392 spin_lock_bh(&ap->sta_table_lock);
2394 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2396 struct sta_info *sta = (struct sta_info *) ptr;
2398 if (aplist && !sta->ap)
2400 addr[count].sa_family = ARPHRD_ETHER;
2401 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2402 if (sta->last_rx_silence == 0)
2403 qual[count].qual = sta->last_rx_signal < 27 ?
2404 0 : (sta->last_rx_signal - 27) * 92 / 127;
2406 qual[count].qual = sta->last_rx_signal -
2407 sta->last_rx_silence - 35;
2408 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2409 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2410 qual[count].updated = sta->last_rx_updated;
2412 sta->last_rx_updated = IW_QUAL_DBM;
2415 if (count >= buf_size)
2418 spin_unlock_bh(&ap->sta_table_lock);
2424 /* Translate our list of Access Points & Stations to a card independent
2425 * format that the Wireless Tools will understand - Jean II */
2426 int prism2_ap_translate_scan(struct net_device *dev,
2427 struct iw_request_info *info, char *buffer)
2429 struct hostap_interface *iface;
2430 local_info_t *local;
2432 struct list_head *ptr;
2433 struct iw_event iwe;
2434 char *current_ev = buffer;
2435 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2436 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2440 iface = netdev_priv(dev);
2441 local = iface->local;
2444 spin_lock_bh(&ap->sta_table_lock);
2446 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2448 struct sta_info *sta = (struct sta_info *) ptr;
2450 /* First entry *MUST* be the AP MAC address */
2451 memset(&iwe, 0, sizeof(iwe));
2452 iwe.cmd = SIOCGIWAP;
2453 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2454 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2455 iwe.len = IW_EV_ADDR_LEN;
2456 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2457 &iwe, IW_EV_ADDR_LEN);
2459 /* Use the mode to indicate if it's a station or
2460 * an Access Point */
2461 memset(&iwe, 0, sizeof(iwe));
2462 iwe.cmd = SIOCGIWMODE;
2464 iwe.u.mode = IW_MODE_MASTER;
2466 iwe.u.mode = IW_MODE_INFRA;
2467 iwe.len = IW_EV_UINT_LEN;
2468 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2469 &iwe, IW_EV_UINT_LEN);
2472 memset(&iwe, 0, sizeof(iwe));
2474 if (sta->last_rx_silence == 0)
2475 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2476 0 : (sta->last_rx_signal - 27) * 92 / 127;
2478 iwe.u.qual.qual = sta->last_rx_signal -
2479 sta->last_rx_silence - 35;
2480 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2481 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2482 iwe.u.qual.updated = sta->last_rx_updated;
2483 iwe.len = IW_EV_QUAL_LEN;
2484 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2485 &iwe, IW_EV_QUAL_LEN);
2487 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2489 memset(&iwe, 0, sizeof(iwe));
2490 iwe.cmd = SIOCGIWESSID;
2491 iwe.u.data.length = sta->u.ap.ssid_len;
2492 iwe.u.data.flags = 1;
2493 current_ev = iwe_stream_add_point(info, current_ev,
2497 memset(&iwe, 0, sizeof(iwe));
2498 iwe.cmd = SIOCGIWENCODE;
2499 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2501 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2503 iwe.u.data.flags = IW_ENCODE_DISABLED;
2504 current_ev = iwe_stream_add_point(info, current_ev,
2508 if (sta->u.ap.channel > 0 &&
2509 sta->u.ap.channel <= FREQ_COUNT) {
2510 memset(&iwe, 0, sizeof(iwe));
2511 iwe.cmd = SIOCGIWFREQ;
2512 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2515 current_ev = iwe_stream_add_event(
2516 info, current_ev, end_buf, &iwe,
2520 memset(&iwe, 0, sizeof(iwe));
2521 iwe.cmd = IWEVCUSTOM;
2522 sprintf(buf, "beacon_interval=%d",
2523 sta->listen_interval);
2524 iwe.u.data.length = strlen(buf);
2525 current_ev = iwe_stream_add_point(info, current_ev,
2526 end_buf, &iwe, buf);
2528 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2530 sta->last_rx_updated = IW_QUAL_DBM;
2532 /* To be continued, we should make good use of IWEVCUSTOM */
2535 spin_unlock_bh(&ap->sta_table_lock);
2537 return current_ev - buffer;
2541 static int prism2_hostapd_add_sta(struct ap_data *ap,
2542 struct prism2_hostapd_param *param)
2544 struct sta_info *sta;
2546 spin_lock_bh(&ap->sta_table_lock);
2547 sta = ap_get_sta(ap, param->sta_addr);
2549 atomic_inc(&sta->users);
2550 spin_unlock_bh(&ap->sta_table_lock);
2553 sta = ap_add_sta(ap, param->sta_addr);
2558 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2559 hostap_event_new_sta(sta->local->dev, sta);
2561 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2562 sta->last_rx = jiffies;
2563 sta->aid = param->u.add_sta.aid;
2564 sta->capability = param->u.add_sta.capability;
2565 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2566 if (sta->tx_supp_rates & WLAN_RATE_1M)
2567 sta->supported_rates[0] = 2;
2568 if (sta->tx_supp_rates & WLAN_RATE_2M)
2569 sta->supported_rates[1] = 4;
2570 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2571 sta->supported_rates[2] = 11;
2572 if (sta->tx_supp_rates & WLAN_RATE_11M)
2573 sta->supported_rates[3] = 22;
2574 prism2_check_tx_rates(sta);
2575 atomic_dec(&sta->users);
2580 static int prism2_hostapd_remove_sta(struct ap_data *ap,
2581 struct prism2_hostapd_param *param)
2583 struct sta_info *sta;
2585 spin_lock_bh(&ap->sta_table_lock);
2586 sta = ap_get_sta(ap, param->sta_addr);
2588 ap_sta_hash_del(ap, sta);
2589 list_del(&sta->list);
2591 spin_unlock_bh(&ap->sta_table_lock);
2596 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2597 hostap_event_expired_sta(sta->local->dev, sta);
2598 ap_free_sta(ap, sta);
2604 static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2605 struct prism2_hostapd_param *param)
2607 struct sta_info *sta;
2609 spin_lock_bh(&ap->sta_table_lock);
2610 sta = ap_get_sta(ap, param->sta_addr);
2612 atomic_inc(&sta->users);
2613 spin_unlock_bh(&ap->sta_table_lock);
2618 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2620 atomic_dec(&sta->users);
2626 static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2627 struct prism2_hostapd_param *param)
2629 struct sta_info *sta;
2631 spin_lock_bh(&ap->sta_table_lock);
2632 sta = ap_get_sta(ap, param->sta_addr);
2634 sta->flags |= param->u.set_flags_sta.flags_or;
2635 sta->flags &= param->u.set_flags_sta.flags_and;
2637 spin_unlock_bh(&ap->sta_table_lock);
2646 static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2647 struct prism2_hostapd_param *param)
2649 struct sta_info *sta;
2652 spin_lock_bh(&ap->sta_table_lock);
2653 sta = ap_get_sta(ap, param->sta_addr);
2655 sta->rx_packets = sta->tx_packets = 0;
2656 sta->rx_bytes = sta->tx_bytes = 0;
2657 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2658 sta->tx_count[rate] = 0;
2659 sta->rx_count[rate] = 0;
2662 spin_unlock_bh(&ap->sta_table_lock);
2671 int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
2673 switch (param->cmd) {
2674 case PRISM2_HOSTAPD_FLUSH:
2675 ap_control_kickall(ap);
2677 case PRISM2_HOSTAPD_ADD_STA:
2678 return prism2_hostapd_add_sta(ap, param);
2679 case PRISM2_HOSTAPD_REMOVE_STA:
2680 return prism2_hostapd_remove_sta(ap, param);
2681 case PRISM2_HOSTAPD_GET_INFO_STA:
2682 return prism2_hostapd_get_info_sta(ap, param);
2683 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2684 return prism2_hostapd_set_flags_sta(ap, param);
2685 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2686 return prism2_hostapd_sta_clear_stats(ap, param);
2688 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2695 /* Update station info for host-based TX rate control and return current
2697 static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2699 int ret = sta->tx_rate;
2700 struct hostap_interface *iface;
2701 local_info_t *local;
2703 iface = netdev_priv(dev);
2704 local = iface->local;
2706 sta->tx_count[sta->tx_rate_idx]++;
2707 sta->tx_since_last_failure++;
2708 sta->tx_consecutive_exc = 0;
2709 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2710 sta->tx_rate_idx < sta->tx_max_rate) {
2711 /* use next higher rate */
2712 int old_rate, new_rate;
2713 old_rate = new_rate = sta->tx_rate_idx;
2714 while (new_rate < sta->tx_max_rate) {
2716 if (ap_tx_rate_ok(new_rate, sta, local)) {
2717 sta->tx_rate_idx = new_rate;
2721 if (old_rate != sta->tx_rate_idx) {
2722 switch (sta->tx_rate_idx) {
2723 case 0: sta->tx_rate = 10; break;
2724 case 1: sta->tx_rate = 20; break;
2725 case 2: sta->tx_rate = 55; break;
2726 case 3: sta->tx_rate = 110; break;
2727 default: sta->tx_rate = 0; break;
2729 PDEBUG(DEBUG_AP, "%s: STA %pM TX rate raised to %d\n",
2730 dev->name, sta->addr, sta->tx_rate);
2732 sta->tx_since_last_failure = 0;
2739 /* Called only from software IRQ. Called for each TX frame prior possible
2740 * encryption and transmit. */
2741 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2743 struct sta_info *sta = NULL;
2744 struct sk_buff *skb = tx->skb;
2746 struct ieee80211_hdr *hdr;
2747 struct hostap_skb_tx_data *meta;
2749 meta = (struct hostap_skb_tx_data *) skb->cb;
2750 ret = AP_TX_CONTINUE;
2751 if (local->ap == NULL || skb->len < 10 ||
2752 meta->iface->type == HOSTAP_INTERFACE_STA)
2755 hdr = (struct ieee80211_hdr *) skb->data;
2757 if (hdr->addr1[0] & 0x01) {
2758 /* broadcast/multicast frame - no AP related processing */
2759 if (local->ap->num_sta <= 0)
2764 /* unicast packet - check whether destination STA is associated */
2765 spin_lock(&local->ap->sta_table_lock);
2766 sta = ap_get_sta(local->ap, hdr->addr1);
2768 atomic_inc(&sta->users);
2769 spin_unlock(&local->ap->sta_table_lock);
2771 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2772 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
2773 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2774 meta->iface->type != HOSTAP_INTERFACE_AP) {
2776 /* This can happen, e.g., when wlan0 is added to a bridge and
2777 * bridging code does not know which port is the correct target
2778 * for a unicast frame. In this case, the packet is send to all
2779 * ports of the bridge. Since this is a valid scenario, do not
2780 * print out any errors here. */
2781 if (net_ratelimit()) {
2782 printk(KERN_DEBUG "AP: drop packet to non-associated "
2783 "STA %pM\n", hdr->addr1);
2786 local->ap->tx_drop_nonassoc++;
2794 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2795 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2797 /* Set tx_rate if using host-based TX rate control */
2798 if (!local->fw_tx_rate_control)
2799 local->ap->last_tx_rate = meta->rate =
2800 ap_update_sta_tx_rate(sta, local->dev);
2802 if (local->iw_mode != IW_MODE_MASTER)
2805 if (!(sta->flags & WLAN_STA_PS))
2808 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2809 /* indicate to STA that more frames follow */
2810 hdr->frame_control |=
2811 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2814 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2815 /* packet was already buffered and now send due to
2816 * PS poll, so do not rebuffer it */
2820 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2821 PDEBUG(DEBUG_PS, "%s: No more space in STA (%pM)'s"
2823 local->dev->name, sta->addr);
2824 /* Make sure that TIM is set for the station (it might not be
2825 * after AP wlan hw reset). */
2826 /* FIX: should fix hw reset to restore bits based on STA
2828 hostap_set_tim(local, sta->aid, 1);
2829 sta->flags |= WLAN_STA_TIM;
2834 /* STA in PS mode, buffer frame for later delivery */
2835 set_tim = skb_queue_empty(&sta->tx_buf);
2836 skb_queue_tail(&sta->tx_buf, skb);
2837 /* FIX: could save RX time to skb and expire buffered frames after
2838 * some time if STA does not poll for them */
2841 if (sta->flags & WLAN_STA_TIM)
2842 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2844 hostap_set_tim(local, sta->aid, 1);
2845 sta->flags |= WLAN_STA_TIM;
2848 ret = AP_TX_BUFFERED;
2852 if (ret == AP_TX_CONTINUE ||
2853 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2855 sta->tx_bytes += skb->len;
2856 sta->last_tx = jiffies;
2859 if ((ret == AP_TX_CONTINUE ||
2860 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2861 sta->crypt && tx->host_encrypt) {
2862 tx->crypt = sta->crypt;
2863 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2864 * be called to release sta info
2867 atomic_dec(&sta->users);
2874 void hostap_handle_sta_release(void *ptr)
2876 struct sta_info *sta = ptr;
2877 atomic_dec(&sta->users);
2881 /* Called only as a tasklet (software IRQ) */
2882 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2884 struct sta_info *sta;
2885 struct ieee80211_hdr *hdr;
2886 struct hostap_skb_tx_data *meta;
2888 hdr = (struct ieee80211_hdr *) skb->data;
2889 meta = (struct hostap_skb_tx_data *) skb->cb;
2891 spin_lock(&local->ap->sta_table_lock);
2892 sta = ap_get_sta(local->ap, hdr->addr1);
2894 spin_unlock(&local->ap->sta_table_lock);
2895 PDEBUG(DEBUG_AP, "%s: Could not find STA %pM"
2896 " for this TX error (@%lu)\n",
2897 local->dev->name, hdr->addr1, jiffies);
2901 sta->tx_since_last_failure = 0;
2902 sta->tx_consecutive_exc++;
2904 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2905 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2906 /* use next lower rate */
2908 old = rate = sta->tx_rate_idx;
2911 if (ap_tx_rate_ok(rate, sta, local)) {
2912 sta->tx_rate_idx = rate;
2916 if (old != sta->tx_rate_idx) {
2917 switch (sta->tx_rate_idx) {
2918 case 0: sta->tx_rate = 10; break;
2919 case 1: sta->tx_rate = 20; break;
2920 case 2: sta->tx_rate = 55; break;
2921 case 3: sta->tx_rate = 110; break;
2922 default: sta->tx_rate = 0; break;
2925 "%s: STA %pM TX rate lowered to %d\n",
2926 local->dev->name, sta->addr, sta->tx_rate);
2928 sta->tx_consecutive_exc = 0;
2930 spin_unlock(&local->ap->sta_table_lock);
2934 static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2935 int pwrmgt, int type, int stype)
2937 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2938 sta->flags |= WLAN_STA_PS;
2939 PDEBUG(DEBUG_PS2, "STA %pM changed to use PS "
2940 "mode (type=0x%02X, stype=0x%02X)\n",
2941 sta->addr, type >> 2, stype >> 4);
2942 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2943 sta->flags &= ~WLAN_STA_PS;
2944 PDEBUG(DEBUG_PS2, "STA %pM changed to not use "
2945 "PS mode (type=0x%02X, stype=0x%02X)\n",
2946 sta->addr, type >> 2, stype >> 4);
2947 if (type != IEEE80211_FTYPE_CTL ||
2948 stype != IEEE80211_STYPE_PSPOLL)
2949 schedule_packet_send(local, sta);
2954 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2955 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2956 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr)
2958 struct sta_info *sta;
2961 spin_lock(&local->ap->sta_table_lock);
2962 sta = ap_get_sta(local->ap, hdr->addr2);
2964 atomic_inc(&sta->users);
2965 spin_unlock(&local->ap->sta_table_lock);
2970 fc = le16_to_cpu(hdr->frame_control);
2971 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
2972 fc & IEEE80211_FCTL_FTYPE,
2973 fc & IEEE80211_FCTL_STYPE);
2975 atomic_dec(&sta->users);
2980 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2981 * getting RX header and payload from hardware. */
2982 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2983 struct sk_buff *skb,
2984 struct hostap_80211_rx_status *rx_stats,
2988 struct sta_info *sta;
2989 u16 fc, type, stype;
2990 struct ieee80211_hdr *hdr;
2992 if (local->ap == NULL)
2993 return AP_RX_CONTINUE;
2995 hdr = (struct ieee80211_hdr *) skb->data;
2997 fc = le16_to_cpu(hdr->frame_control);
2998 type = fc & IEEE80211_FCTL_FTYPE;
2999 stype = fc & IEEE80211_FCTL_STYPE;
3001 spin_lock(&local->ap->sta_table_lock);
3002 sta = ap_get_sta(local->ap, hdr->addr2);
3004 atomic_inc(&sta->users);
3005 spin_unlock(&local->ap->sta_table_lock);
3007 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
3008 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
3010 ret = AP_RX_CONTINUE;
3013 if (fc & IEEE80211_FCTL_TODS) {
3014 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
3015 if (local->hostapd) {
3016 prism2_rx_80211(local->apdev, skb, rx_stats,
3017 PRISM2_RX_NON_ASSOC);
3018 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3020 printk(KERN_DEBUG "%s: dropped received packet"
3021 " from non-associated STA %pM"
3022 " (type=0x%02x, subtype=0x%02x)\n",
3023 dev->name, hdr->addr2,
3024 type >> 2, stype >> 4);
3025 hostap_rx(dev, skb, rx_stats);
3026 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3031 } else if (fc & IEEE80211_FCTL_FROMDS) {
3033 /* FromDS frame - not for us; probably
3034 * broadcast/multicast in another BSS - drop */
3035 if (ether_addr_equal(hdr->addr1, dev->dev_addr)) {
3036 printk(KERN_DEBUG "Odd.. FromDS packet "
3037 "received with own BSSID\n");
3038 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3043 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
3044 ether_addr_equal(hdr->addr1, dev->dev_addr)) {
3046 if (local->hostapd) {
3047 prism2_rx_80211(local->apdev, skb, rx_stats,
3048 PRISM2_RX_NON_ASSOC);
3049 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3051 /* At least Lucent f/w seems to send data::nullfunc
3052 * frames with no ToDS flag when the current AP returns
3053 * after being unavailable for some time. Speed up
3054 * re-association by informing the station about it not
3055 * being associated. */
3056 printk(KERN_DEBUG "%s: rejected received nullfunc frame"
3057 " without ToDS from not associated STA %pM\n",
3058 dev->name, hdr->addr2);
3059 hostap_rx(dev, skb, rx_stats);
3060 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3064 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
3065 /* At least Lucent cards seem to send periodic nullfunc
3066 * frames with ToDS. Let these through to update SQ
3067 * stats and PS state. Nullfunc frames do not contain
3068 * any data and they will be dropped below. */
3070 /* If BSSID (Addr3) is foreign, this frame is a normal
3071 * broadcast frame from an IBSS network. Drop it silently.
3072 * If BSSID is own, report the dropping of this frame. */
3073 if (ether_addr_equal(hdr->addr3, dev->dev_addr)) {
3074 printk(KERN_DEBUG "%s: dropped received packet from %pM"
3075 " with no ToDS flag "
3076 "(type=0x%02x, subtype=0x%02x)\n", dev->name,
3077 hdr->addr2, type >> 2, stype >> 4);
3078 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3085 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
3089 sta->rx_bytes += skb->len;
3090 sta->last_rx = jiffies;
3093 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
3094 fc & IEEE80211_FCTL_TODS) {
3095 if (local->hostapd) {
3096 prism2_rx_80211(local->apdev, skb, rx_stats,
3097 PRISM2_RX_NULLFUNC_ACK);
3098 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3100 /* some STA f/w's seem to require control::ACK frame
3101 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3102 * from Compaq) does not send this.. Try to generate
3103 * ACK for these frames from the host driver to make
3104 * power saving work with, e.g., Lucent WaveLAN f/w */
3105 hostap_rx(dev, skb, rx_stats);
3106 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3114 atomic_dec(&sta->users);
3120 /* Called only as a tasklet (software IRQ) */
3121 int hostap_handle_sta_crypto(local_info_t *local,
3122 struct ieee80211_hdr *hdr,
3123 struct lib80211_crypt_data **crypt,
3126 struct sta_info *sta;
3128 spin_lock(&local->ap->sta_table_lock);
3129 sta = ap_get_sta(local->ap, hdr->addr2);
3131 atomic_inc(&sta->users);
3132 spin_unlock(&local->ap->sta_table_lock);
3138 *crypt = sta->crypt;
3140 /* hostap_handle_sta_release() will be called to release STA
3143 atomic_dec(&sta->users);
3149 /* Called only as a tasklet (software IRQ) */
3150 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3152 struct sta_info *sta;
3155 spin_lock(&ap->sta_table_lock);
3156 sta = ap_get_sta(ap, sta_addr);
3157 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3159 spin_unlock(&ap->sta_table_lock);
3165 /* Called only as a tasklet (software IRQ) */
3166 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3168 struct sta_info *sta;
3171 spin_lock(&ap->sta_table_lock);
3172 sta = ap_get_sta(ap, sta_addr);
3173 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3174 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3175 ap->local->ieee_802_1x == 0))
3177 spin_unlock(&ap->sta_table_lock);
3183 /* Called only as a tasklet (software IRQ) */
3184 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3186 struct sta_info *sta;
3192 spin_lock(&ap->sta_table_lock);
3193 sta = ap_get_sta(ap, sta_addr);
3196 spin_unlock(&ap->sta_table_lock);
3199 sta = ap_add_sta(ap, sta_addr);
3202 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3204 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3205 /* No way of knowing which rates are supported since we did not
3206 * get supported rates element from beacon/assoc req. Assume
3207 * that remote end supports all 802.11b rates. */
3208 sta->supported_rates[0] = 0x82;
3209 sta->supported_rates[1] = 0x84;
3210 sta->supported_rates[2] = 0x0b;
3211 sta->supported_rates[3] = 0x16;
3212 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3213 WLAN_RATE_5M5 | WLAN_RATE_11M;
3215 sta->tx_max_rate = sta->tx_rate_idx = 3;
3222 /* Called only as a tasklet (software IRQ) */
3223 int hostap_update_rx_stats(struct ap_data *ap,
3224 struct ieee80211_hdr *hdr,
3225 struct hostap_80211_rx_status *rx_stats)
3227 struct sta_info *sta;
3232 spin_lock(&ap->sta_table_lock);
3233 sta = ap_get_sta(ap, hdr->addr2);
3235 sta->last_rx_silence = rx_stats->noise;
3236 sta->last_rx_signal = rx_stats->signal;
3237 sta->last_rx_rate = rx_stats->rate;
3238 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3239 if (rx_stats->rate == 10)
3241 else if (rx_stats->rate == 20)
3243 else if (rx_stats->rate == 55)
3245 else if (rx_stats->rate == 110)
3248 spin_unlock(&ap->sta_table_lock);
3250 return sta ? 0 : -1;
3254 void hostap_update_rates(local_info_t *local)
3256 struct sta_info *sta;
3257 struct ap_data *ap = local->ap;
3262 spin_lock_bh(&ap->sta_table_lock);
3263 list_for_each_entry(sta, &ap->sta_list, list) {
3264 prism2_check_tx_rates(sta);
3266 spin_unlock_bh(&ap->sta_table_lock);
3270 void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3271 struct lib80211_crypt_data ***crypt)
3273 struct sta_info *sta;
3275 spin_lock_bh(&ap->sta_table_lock);
3276 sta = ap_get_sta(ap, addr);
3278 atomic_inc(&sta->users);
3279 spin_unlock_bh(&ap->sta_table_lock);
3281 if (!sta && permanent)
3282 sta = ap_add_sta(ap, addr);
3288 sta->flags |= WLAN_STA_PERM;
3290 *crypt = &sta->crypt;
3296 void hostap_add_wds_links(local_info_t *local)
3298 struct ap_data *ap = local->ap;
3299 struct sta_info *sta;
3301 spin_lock_bh(&ap->sta_table_lock);
3302 list_for_each_entry(sta, &ap->sta_list, list) {
3304 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3306 spin_unlock_bh(&ap->sta_table_lock);
3308 schedule_work(&local->ap->wds_oper_queue);
3312 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3314 struct wds_oper_data *entry;
3316 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3319 memcpy(entry->addr, addr, ETH_ALEN);
3321 spin_lock_bh(&local->lock);
3322 entry->next = local->ap->wds_oper_entries;
3323 local->ap->wds_oper_entries = entry;
3324 spin_unlock_bh(&local->lock);
3326 schedule_work(&local->ap->wds_oper_queue);
3330 EXPORT_SYMBOL(hostap_init_data);
3331 EXPORT_SYMBOL(hostap_init_ap_proc);
3332 EXPORT_SYMBOL(hostap_free_data);
3333 EXPORT_SYMBOL(hostap_check_sta_fw_version);
3334 EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3335 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3336 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */