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/delay.h>
21 #include <linux/random.h>
23 #include "hostap_wlan.h"
25 #include "hostap_ap.h"
27 static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
29 module_param_array(other_ap_policy, int, NULL, 0444);
30 MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
32 static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
34 module_param_array(ap_max_inactivity, int, NULL, 0444);
35 MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
38 static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
39 module_param_array(ap_bridge_packets, int, NULL, 0444);
40 MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
43 static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
44 module_param_array(autom_ap_wds, int, NULL, 0444);
45 MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
49 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
50 static void hostap_event_expired_sta(struct net_device *dev,
51 struct sta_info *sta);
52 static void handle_add_proc_queue(struct work_struct *work);
54 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
55 static void handle_wds_oper_queue(struct work_struct *work);
56 static void prism2_send_mgmt(struct net_device *dev,
57 u16 type_subtype, char *body,
58 int body_len, u8 *addr, u16 tx_cb_idx);
59 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
62 #ifndef PRISM2_NO_PROCFS_DEBUG
63 static int ap_debug_proc_read(char *page, char **start, off_t off,
64 int count, int *eof, void *data)
67 struct ap_data *ap = (struct ap_data *) data;
74 p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
75 p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
76 p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
77 p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
78 p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
79 p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
80 p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
81 p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
85 #endif /* PRISM2_NO_PROCFS_DEBUG */
88 static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
90 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
91 ap->sta_hash[STA_HASH(sta->addr)] = sta;
94 static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
98 s = ap->sta_hash[STA_HASH(sta->addr)];
99 if (s == NULL) return;
100 if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
101 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
105 while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
108 if (s->hnext != NULL)
109 s->hnext = s->hnext->hnext;
111 printk("AP: could not remove STA %pM from hash table\n",
115 static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
117 if (sta->ap && sta->local)
118 hostap_event_expired_sta(sta->local->dev, sta);
120 if (ap->proc != NULL) {
122 sprintf(name, "%pM", sta->addr);
123 remove_proc_entry(name, ap->proc);
127 sta->crypt->ops->deinit(sta->crypt->priv);
132 skb_queue_purge(&sta->tx_buf);
135 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
137 ap->sta_aid[sta->aid - 1] = NULL;
139 if (!sta->ap && sta->u.sta.challenge)
140 kfree(sta->u.sta.challenge);
141 del_timer(&sta->timer);
142 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
148 static void hostap_set_tim(local_info_t *local, int aid, int set)
150 if (local->func->set_tim)
151 local->func->set_tim(local->dev, aid, set);
155 static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
157 union iwreq_data wrqu;
158 memset(&wrqu, 0, sizeof(wrqu));
159 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
160 wrqu.addr.sa_family = ARPHRD_ETHER;
161 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
165 static void hostap_event_expired_sta(struct net_device *dev,
166 struct sta_info *sta)
168 union iwreq_data wrqu;
169 memset(&wrqu, 0, sizeof(wrqu));
170 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
171 wrqu.addr.sa_family = ARPHRD_ETHER;
172 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
176 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
178 static void ap_handle_timer(unsigned long data)
180 struct sta_info *sta = (struct sta_info *) data;
183 unsigned long next_time = 0;
186 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
187 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
193 was_assoc = sta->flags & WLAN_STA_ASSOC;
195 if (atomic_read(&sta->users) != 0)
196 next_time = jiffies + HZ;
197 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
198 next_time = jiffies + ap->max_inactivity;
200 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
201 /* station activity detected; reset timeout state */
202 sta->timeout_next = STA_NULLFUNC;
203 next_time = sta->last_rx + ap->max_inactivity;
204 } else if (sta->timeout_next == STA_DISASSOC &&
205 !(sta->flags & WLAN_STA_PENDING_POLL)) {
206 /* STA ACKed data nullfunc frame poll */
207 sta->timeout_next = STA_NULLFUNC;
208 next_time = jiffies + ap->max_inactivity;
212 sta->timer.expires = next_time;
213 add_timer(&sta->timer);
218 sta->timeout_next = STA_DEAUTH;
220 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
221 spin_lock(&ap->sta_table_lock);
222 ap_sta_hash_del(ap, sta);
223 list_del(&sta->list);
224 spin_unlock(&ap->sta_table_lock);
225 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
226 } else if (sta->timeout_next == STA_DISASSOC)
227 sta->flags &= ~WLAN_STA_ASSOC;
229 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
230 hostap_event_expired_sta(local->dev, sta);
232 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
233 !skb_queue_empty(&sta->tx_buf)) {
234 hostap_set_tim(local, sta->aid, 0);
235 sta->flags &= ~WLAN_STA_TIM;
239 if (ap->autom_ap_wds) {
240 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
241 "connection to AP %pM\n",
242 local->dev->name, sta->addr);
243 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
245 } else if (sta->timeout_next == STA_NULLFUNC) {
246 /* send data frame to poll STA and check whether this frame
248 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
249 * it is apparently not retried so TX Exc events are not
251 sta->flags |= WLAN_STA_PENDING_POLL;
252 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
253 IEEE80211_STYPE_DATA, NULL, 0,
254 sta->addr, ap->tx_callback_poll);
256 int deauth = sta->timeout_next == STA_DEAUTH;
258 PDEBUG(DEBUG_AP, "%s: sending %s info to STA %pM"
259 "(last=%lu, jiffies=%lu)\n",
261 deauth ? "deauthentication" : "disassociation",
262 sta->addr, sta->last_rx, jiffies);
264 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
265 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
266 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
267 (deauth ? IEEE80211_STYPE_DEAUTH :
268 IEEE80211_STYPE_DISASSOC),
269 (char *) &resp, 2, sta->addr, 0);
272 if (sta->timeout_next == STA_DEAUTH) {
273 if (sta->flags & WLAN_STA_PERM) {
274 PDEBUG(DEBUG_AP, "%s: STA %pM"
275 " would have been removed, "
276 "but it has 'perm' flag\n",
277 local->dev->name, sta->addr);
279 ap_free_sta(ap, sta);
283 if (sta->timeout_next == STA_NULLFUNC) {
284 sta->timeout_next = STA_DISASSOC;
285 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
287 sta->timeout_next = STA_DEAUTH;
288 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
291 add_timer(&sta->timer);
295 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
302 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
303 memset(addr, 0xff, ETH_ALEN);
305 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
307 /* deauth message sent; try to resend it few times; the message is
308 * broadcast, so it may be delayed until next DTIM; there is not much
309 * else we can do at this point since the driver is going to be shut
311 for (i = 0; i < 5; i++) {
312 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
313 IEEE80211_STYPE_DEAUTH,
314 (char *) &resp, 2, addr, 0);
316 if (!resend || ap->num_sta <= 0)
324 static int ap_control_proc_read(char *page, char **start, off_t off,
325 int count, int *eof, void *data)
328 struct ap_data *ap = (struct ap_data *) data;
330 struct mac_entry *entry;
337 switch (ap->mac_restrictions.policy) {
338 case MAC_POLICY_OPEN:
341 case MAC_POLICY_ALLOW:
342 policy_txt = "allow";
344 case MAC_POLICY_DENY:
348 policy_txt = "unknown";
351 p += sprintf(p, "MAC policy: %s\n", policy_txt);
352 p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
353 p += sprintf(p, "MAC list:\n");
354 spin_lock_bh(&ap->mac_restrictions.lock);
355 list_for_each_entry(entry, &ap->mac_restrictions.mac_list, list) {
356 if (p - page > PAGE_SIZE - 80) {
357 p += sprintf(p, "All entries did not fit one page.\n");
361 p += sprintf(p, "%pM\n", entry->addr);
363 spin_unlock_bh(&ap->mac_restrictions.lock);
369 int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
371 struct mac_entry *entry;
373 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
377 memcpy(entry->addr, mac, ETH_ALEN);
379 spin_lock_bh(&mac_restrictions->lock);
380 list_add_tail(&entry->list, &mac_restrictions->mac_list);
381 mac_restrictions->entries++;
382 spin_unlock_bh(&mac_restrictions->lock);
388 int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
390 struct list_head *ptr;
391 struct mac_entry *entry;
393 spin_lock_bh(&mac_restrictions->lock);
394 for (ptr = mac_restrictions->mac_list.next;
395 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
396 entry = list_entry(ptr, struct mac_entry, list);
398 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
401 mac_restrictions->entries--;
402 spin_unlock_bh(&mac_restrictions->lock);
406 spin_unlock_bh(&mac_restrictions->lock);
411 static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
414 struct mac_entry *entry;
417 if (mac_restrictions->policy == MAC_POLICY_OPEN)
420 spin_lock_bh(&mac_restrictions->lock);
421 list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
422 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
427 spin_unlock_bh(&mac_restrictions->lock);
429 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
436 void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
438 struct list_head *ptr, *n;
439 struct mac_entry *entry;
441 if (mac_restrictions->entries == 0)
444 spin_lock_bh(&mac_restrictions->lock);
445 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
446 ptr != &mac_restrictions->mac_list;
447 ptr = n, n = ptr->next) {
448 entry = list_entry(ptr, struct mac_entry, list);
452 mac_restrictions->entries = 0;
453 spin_unlock_bh(&mac_restrictions->lock);
457 int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
459 struct sta_info *sta;
462 spin_lock_bh(&ap->sta_table_lock);
463 sta = ap_get_sta(ap, mac);
465 ap_sta_hash_del(ap, sta);
466 list_del(&sta->list);
468 spin_unlock_bh(&ap->sta_table_lock);
473 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
474 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
475 (char *) &resp, 2, sta->addr, 0);
477 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
478 hostap_event_expired_sta(dev, sta);
480 ap_free_sta(ap, sta);
485 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
488 void ap_control_kickall(struct ap_data *ap)
490 struct list_head *ptr, *n;
491 struct sta_info *sta;
493 spin_lock_bh(&ap->sta_table_lock);
494 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
495 ptr = n, n = ptr->next) {
496 sta = list_entry(ptr, struct sta_info, list);
497 ap_sta_hash_del(ap, sta);
498 list_del(&sta->list);
499 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
500 hostap_event_expired_sta(sta->local->dev, sta);
501 ap_free_sta(ap, sta);
503 spin_unlock_bh(&ap->sta_table_lock);
507 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
509 #define PROC_LIMIT (PAGE_SIZE - 80)
511 static int prism2_ap_proc_read(char *page, char **start, off_t off,
512 int count, int *eof, void *data)
515 struct ap_data *ap = (struct ap_data *) data;
516 struct sta_info *sta;
519 if (off > PROC_LIMIT) {
524 p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
525 spin_lock_bh(&ap->sta_table_lock);
526 list_for_each_entry(sta, &ap->sta_list, list) {
530 p += sprintf(p, "%pM %d %d %d %d '",
532 sta->u.ap.channel, sta->last_rx_signal,
533 sta->last_rx_silence, sta->last_rx_rate);
534 for (i = 0; i < sta->u.ap.ssid_len; i++)
535 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
536 sta->u.ap.ssid[i] < 127) ?
539 p += sprintf(p, "'");
540 if (sta->capability & WLAN_CAPABILITY_ESS)
541 p += sprintf(p, " [ESS]");
542 if (sta->capability & WLAN_CAPABILITY_IBSS)
543 p += sprintf(p, " [IBSS]");
544 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
545 p += sprintf(p, " [WEP]");
546 p += sprintf(p, "\n");
548 if ((p - page) > PROC_LIMIT) {
549 printk(KERN_DEBUG "hostap: ap proc did not fit\n");
553 spin_unlock_bh(&ap->sta_table_lock);
555 if ((p - page) <= off) {
562 return (p - page - off);
564 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
567 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
572 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
573 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
574 "firmware upgrade recommended\n");
575 ap->nullfunc_ack = 1;
577 ap->nullfunc_ack = 0;
579 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
580 printk(KERN_WARNING "%s: Warning: secondary station firmware "
581 "version 1.4.2 does not seem to work in Host AP mode\n",
582 ap->local->dev->name);
587 /* Called only as a tasklet (software IRQ) */
588 static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
590 struct ap_data *ap = data;
592 struct ieee80211_hdr_4addr *hdr;
594 if (!ap->local->hostapd || !ap->local->apdev) {
599 hdr = (struct ieee80211_hdr_4addr *) skb->data;
600 fc = le16_to_cpu(hdr->frame_ctl);
602 /* Pass the TX callback frame to the hostapd; use 802.11 header version
603 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
605 fc &= ~IEEE80211_FCTL_VERS;
606 fc |= ok ? BIT(1) : BIT(0);
607 hdr->frame_ctl = cpu_to_le16(fc);
609 skb->dev = ap->local->apdev;
610 skb_pull(skb, hostap_80211_get_hdrlen(fc));
611 skb->pkt_type = PACKET_OTHERHOST;
612 skb->protocol = __constant_htons(ETH_P_802_2);
613 memset(skb->cb, 0, sizeof(skb->cb));
618 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
619 /* Called only as a tasklet (software IRQ) */
620 static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
622 struct ap_data *ap = data;
623 struct net_device *dev = ap->local->dev;
624 struct ieee80211_hdr_4addr *hdr;
625 u16 fc, auth_alg, auth_transaction, status;
627 struct sta_info *sta = NULL;
630 if (ap->local->hostapd) {
635 hdr = (struct ieee80211_hdr_4addr *) skb->data;
636 fc = le16_to_cpu(hdr->frame_ctl);
637 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
638 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_AUTH ||
639 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
640 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
641 "frame\n", dev->name);
646 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
647 auth_alg = le16_to_cpu(*pos++);
648 auth_transaction = le16_to_cpu(*pos++);
649 status = le16_to_cpu(*pos++);
652 txt = "frame was not ACKed";
656 spin_lock(&ap->sta_table_lock);
657 sta = ap_get_sta(ap, hdr->addr1);
659 atomic_inc(&sta->users);
660 spin_unlock(&ap->sta_table_lock);
663 txt = "STA not found";
667 if (status == WLAN_STATUS_SUCCESS &&
668 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
669 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
670 txt = "STA authenticated";
671 sta->flags |= WLAN_STA_AUTH;
672 sta->last_auth = jiffies;
673 } else if (status != WLAN_STATUS_SUCCESS)
674 txt = "authentication failed";
678 atomic_dec(&sta->users);
680 PDEBUG(DEBUG_AP, "%s: %pM auth_cb - alg=%d "
681 "trans#=%d status=%d - %s\n",
682 dev->name, hdr->addr1,
683 auth_alg, auth_transaction, status, txt);
689 /* Called only as a tasklet (software IRQ) */
690 static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
692 struct ap_data *ap = data;
693 struct net_device *dev = ap->local->dev;
694 struct ieee80211_hdr_4addr *hdr;
697 struct sta_info *sta = NULL;
700 if (ap->local->hostapd) {
705 hdr = (struct ieee80211_hdr_4addr *) skb->data;
706 fc = le16_to_cpu(hdr->frame_ctl);
707 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
708 (WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_ASSOC_RESP &&
709 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_REASSOC_RESP) ||
710 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
711 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
712 "frame\n", dev->name);
718 txt = "frame was not ACKed";
722 spin_lock(&ap->sta_table_lock);
723 sta = ap_get_sta(ap, hdr->addr1);
725 atomic_inc(&sta->users);
726 spin_unlock(&ap->sta_table_lock);
729 txt = "STA not found";
733 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
735 status = le16_to_cpu(*pos++);
736 if (status == WLAN_STATUS_SUCCESS) {
737 if (!(sta->flags & WLAN_STA_ASSOC))
738 hostap_event_new_sta(dev, sta);
739 txt = "STA associated";
740 sta->flags |= WLAN_STA_ASSOC;
741 sta->last_assoc = jiffies;
743 txt = "association failed";
747 atomic_dec(&sta->users);
749 PDEBUG(DEBUG_AP, "%s: %pM assoc_cb - %s\n",
750 dev->name, hdr->addr1, txt);
755 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
756 * in verifying whether the STA is still present. */
757 static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
759 struct ap_data *ap = data;
760 struct ieee80211_hdr_4addr *hdr;
761 struct sta_info *sta;
765 hdr = (struct ieee80211_hdr_4addr *) skb->data;
767 spin_lock(&ap->sta_table_lock);
768 sta = ap_get_sta(ap, hdr->addr1);
770 sta->flags &= ~WLAN_STA_PENDING_POLL;
771 spin_unlock(&ap->sta_table_lock);
774 "%s: STA %pM did not ACK activity poll frame\n",
775 ap->local->dev->name, hdr->addr1);
781 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
784 void hostap_init_data(local_info_t *local)
786 struct ap_data *ap = local->ap;
789 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
792 memset(ap, 0, sizeof(struct ap_data));
795 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
796 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
798 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
799 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
801 spin_lock_init(&ap->sta_table_lock);
802 INIT_LIST_HEAD(&ap->sta_list);
804 /* Initialize task queue structure for AP management */
805 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
807 ap->tx_callback_idx =
808 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
809 if (ap->tx_callback_idx == 0)
810 printk(KERN_WARNING "%s: failed to register TX callback for "
811 "AP\n", local->dev->name);
812 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
813 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
815 ap->tx_callback_auth =
816 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
817 ap->tx_callback_assoc =
818 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
819 ap->tx_callback_poll =
820 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
821 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
822 ap->tx_callback_poll == 0)
823 printk(KERN_WARNING "%s: failed to register TX callback for "
824 "AP\n", local->dev->name);
826 spin_lock_init(&ap->mac_restrictions.lock);
827 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
828 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
834 void hostap_init_ap_proc(local_info_t *local)
836 struct ap_data *ap = local->ap;
838 ap->proc = local->proc;
839 if (ap->proc == NULL)
842 #ifndef PRISM2_NO_PROCFS_DEBUG
843 create_proc_read_entry("ap_debug", 0, ap->proc,
844 ap_debug_proc_read, ap);
845 #endif /* PRISM2_NO_PROCFS_DEBUG */
847 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
848 create_proc_read_entry("ap_control", 0, ap->proc,
849 ap_control_proc_read, ap);
850 create_proc_read_entry("ap", 0, ap->proc,
851 prism2_ap_proc_read, ap);
852 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
857 void hostap_free_data(struct ap_data *ap)
859 struct sta_info *n, *sta;
861 if (ap == NULL || !ap->initialized) {
862 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
863 "initialized - skip resource freeing\n");
867 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
869 ap->crypt->deinit(ap->crypt_priv);
870 ap->crypt = ap->crypt_priv = NULL;
871 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
873 list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
874 ap_sta_hash_del(ap, sta);
875 list_del(&sta->list);
876 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
877 hostap_event_expired_sta(sta->local->dev, sta);
878 ap_free_sta(ap, sta);
881 #ifndef PRISM2_NO_PROCFS_DEBUG
882 if (ap->proc != NULL) {
883 remove_proc_entry("ap_debug", ap->proc);
885 #endif /* PRISM2_NO_PROCFS_DEBUG */
887 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
888 if (ap->proc != NULL) {
889 remove_proc_entry("ap", ap->proc);
890 remove_proc_entry("ap_control", ap->proc);
892 ap_control_flush_macs(&ap->mac_restrictions);
893 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
899 /* caller should have mutex for AP STA list handling */
900 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
904 s = ap->sta_hash[STA_HASH(sta)];
905 while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
911 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
913 /* Called from timer handler and from scheduled AP queue handlers */
914 static void prism2_send_mgmt(struct net_device *dev,
915 u16 type_subtype, char *body,
916 int body_len, u8 *addr, u16 tx_cb_idx)
918 struct hostap_interface *iface;
920 struct ieee80211_hdr_4addr *hdr;
923 struct hostap_skb_tx_data *meta;
926 iface = netdev_priv(dev);
927 local = iface->local;
928 dev = local->dev; /* always use master radio device */
929 iface = netdev_priv(dev);
931 if (!(dev->flags & IFF_UP)) {
932 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
933 "cannot send frame\n", dev->name);
937 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
939 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
945 hdrlen = hostap_80211_get_hdrlen(fc);
946 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, hdrlen);
948 memcpy(skb_put(skb, body_len), body, body_len);
950 memset(hdr, 0, hdrlen);
952 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
953 * tx_control instead of using local->tx_control */
956 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
957 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) {
958 fc |= IEEE80211_FCTL_FROMDS;
959 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
960 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
961 } else if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_CTL) {
962 /* control:ACK does not have addr2 or addr3 */
963 memset(hdr->addr2, 0, ETH_ALEN);
964 memset(hdr->addr3, 0, ETH_ALEN);
966 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
967 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
970 hdr->frame_ctl = cpu_to_le16(fc);
972 meta = (struct hostap_skb_tx_data *) skb->cb;
973 memset(meta, 0, sizeof(*meta));
974 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
976 meta->tx_cb_idx = tx_cb_idx;
979 skb_reset_mac_header(skb);
980 skb_reset_network_header(skb);
983 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
986 static int prism2_sta_proc_read(char *page, char **start, off_t off,
987 int count, int *eof, void *data)
990 struct sta_info *sta = (struct sta_info *) data;
993 /* FIX: possible race condition.. the STA data could have just expired,
994 * but proc entry was still here so that the read could have started;
995 * some locking should be done here.. */
1002 p += sprintf(p, "%s=%pM\nusers=%d\naid=%d\n"
1003 "flags=0x%04x%s%s%s%s%s%s%s\n"
1004 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1005 sta->ap ? "AP" : "STA",
1006 sta->addr, atomic_read(&sta->users), sta->aid,
1008 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1009 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1010 sta->flags & WLAN_STA_PS ? " PS" : "",
1011 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1012 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1013 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1014 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1015 sta->capability, sta->listen_interval);
1016 /* supported_rates: 500 kbit/s units with msb ignored */
1017 for (i = 0; i < sizeof(sta->supported_rates); i++)
1018 if (sta->supported_rates[i] != 0)
1019 p += sprintf(p, "%d%sMbps ",
1020 (sta->supported_rates[i] & 0x7f) / 2,
1021 sta->supported_rates[i] & 1 ? ".5" : "");
1022 p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1023 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1025 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1026 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1027 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1029 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1030 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1032 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1033 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1034 sta->last_rx_silence,
1035 sta->last_rx_signal, sta->last_rx_rate / 10,
1036 sta->last_rx_rate % 10 ? ".5" : "",
1037 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1038 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1039 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1040 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1041 p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
1042 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1044 if (sta->u.ap.channel >= 0)
1045 p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
1046 p += sprintf(p, "ssid=");
1047 for (i = 0; i < sta->u.ap.ssid_len; i++)
1048 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
1049 sta->u.ap.ssid[i] < 127) ?
1052 p += sprintf(p, "\n");
1054 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1060 static void handle_add_proc_queue(struct work_struct *work)
1062 struct ap_data *ap = container_of(work, struct ap_data,
1063 add_sta_proc_queue);
1064 struct sta_info *sta;
1066 struct add_sta_proc_data *entry, *prev;
1068 entry = ap->add_sta_proc_entries;
1069 ap->add_sta_proc_entries = NULL;
1072 spin_lock_bh(&ap->sta_table_lock);
1073 sta = ap_get_sta(ap, entry->addr);
1075 atomic_inc(&sta->users);
1076 spin_unlock_bh(&ap->sta_table_lock);
1079 sprintf(name, "%pM", sta->addr);
1080 sta->proc = create_proc_read_entry(
1082 prism2_sta_proc_read, sta);
1084 atomic_dec(&sta->users);
1088 entry = entry->next;
1094 static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1096 struct sta_info *sta;
1098 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
1100 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1104 /* initialize STA info data */
1105 sta->local = ap->local;
1106 skb_queue_head_init(&sta->tx_buf);
1107 memcpy(sta->addr, addr, ETH_ALEN);
1109 atomic_inc(&sta->users);
1110 spin_lock_bh(&ap->sta_table_lock);
1111 list_add(&sta->list, &ap->sta_list);
1113 ap_sta_hash_add(ap, sta);
1114 spin_unlock_bh(&ap->sta_table_lock);
1117 struct add_sta_proc_data *entry;
1118 /* schedule a non-interrupt context process to add a procfs
1119 * entry for the STA since procfs code use GFP_KERNEL */
1120 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1122 memcpy(entry->addr, sta->addr, ETH_ALEN);
1123 entry->next = ap->add_sta_proc_entries;
1124 ap->add_sta_proc_entries = entry;
1125 schedule_work(&ap->add_sta_proc_queue);
1127 printk(KERN_DEBUG "Failed to add STA proc data\n");
1130 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1131 init_timer(&sta->timer);
1132 sta->timer.expires = jiffies + ap->max_inactivity;
1133 sta->timer.data = (unsigned long) sta;
1134 sta->timer.function = ap_handle_timer;
1135 if (!ap->local->hostapd)
1136 add_timer(&sta->timer);
1137 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1143 static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1144 local_info_t *local)
1146 if (rateidx > sta->tx_max_rate ||
1147 !(sta->tx_supp_rates & (1 << rateidx)))
1150 if (local->tx_rate_control != 0 &&
1151 !(local->tx_rate_control & (1 << rateidx)))
1158 static void prism2_check_tx_rates(struct sta_info *sta)
1162 sta->tx_supp_rates = 0;
1163 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1164 if ((sta->supported_rates[i] & 0x7f) == 2)
1165 sta->tx_supp_rates |= WLAN_RATE_1M;
1166 if ((sta->supported_rates[i] & 0x7f) == 4)
1167 sta->tx_supp_rates |= WLAN_RATE_2M;
1168 if ((sta->supported_rates[i] & 0x7f) == 11)
1169 sta->tx_supp_rates |= WLAN_RATE_5M5;
1170 if ((sta->supported_rates[i] & 0x7f) == 22)
1171 sta->tx_supp_rates |= WLAN_RATE_11M;
1173 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1174 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1175 sta->tx_max_rate = 0;
1176 if (ap_tx_rate_ok(0, sta, sta->local)) {
1178 sta->tx_rate_idx = 0;
1181 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1182 sta->tx_max_rate = 1;
1183 if (ap_tx_rate_ok(1, sta, sta->local)) {
1185 sta->tx_rate_idx = 1;
1188 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1189 sta->tx_max_rate = 2;
1190 if (ap_tx_rate_ok(2, sta, sta->local)) {
1192 sta->tx_rate_idx = 2;
1195 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1196 sta->tx_max_rate = 3;
1197 if (ap_tx_rate_ok(3, sta, sta->local)) {
1199 sta->tx_rate_idx = 3;
1205 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1207 static void ap_crypt_init(struct ap_data *ap)
1209 ap->crypt = lib80211_get_crypto_ops("WEP");
1212 if (ap->crypt->init) {
1213 ap->crypt_priv = ap->crypt->init(0);
1214 if (ap->crypt_priv == NULL)
1217 u8 key[WEP_KEY_LEN];
1218 get_random_bytes(key, WEP_KEY_LEN);
1219 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1225 if (ap->crypt == NULL) {
1226 printk(KERN_WARNING "AP could not initialize WEP: load module "
1227 "lib80211_crypt_wep.ko\n");
1232 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1233 * that WEP algorithm is used for generating challange. This should be unique,
1234 * but otherwise there is not really need for randomness etc. Initialize WEP
1235 * with pseudo random key and then use increasing IV to get unique challenge
1238 * Called only as a scheduled task for pending AP frames.
1240 static char * ap_auth_make_challenge(struct ap_data *ap)
1243 struct sk_buff *skb;
1245 if (ap->crypt == NULL) {
1247 if (ap->crypt == NULL)
1251 tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1252 if (tmpbuf == NULL) {
1253 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1257 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1258 ap->crypt->extra_mpdu_prefix_len +
1259 ap->crypt->extra_mpdu_postfix_len);
1265 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
1266 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
1267 WLAN_AUTH_CHALLENGE_LEN);
1268 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1274 skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
1275 tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
1282 /* Called only as a scheduled task for pending AP frames. */
1283 static void handle_authen(local_info_t *local, struct sk_buff *skb,
1284 struct hostap_80211_rx_status *rx_stats)
1286 struct net_device *dev = local->dev;
1287 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1289 struct ap_data *ap = local->ap;
1290 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1292 u16 auth_alg, auth_transaction, status_code;
1294 u16 resp = WLAN_STATUS_SUCCESS, fc;
1295 struct sta_info *sta = NULL;
1296 struct lib80211_crypt_data *crypt;
1299 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1301 fc = le16_to_cpu(hdr->frame_ctl);
1302 hdrlen = hostap_80211_get_hdrlen(fc);
1305 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1306 "(len=%d) from %pM\n", dev->name, len, hdr->addr2);
1310 spin_lock_bh(&local->ap->sta_table_lock);
1311 sta = ap_get_sta(local->ap, hdr->addr2);
1313 atomic_inc(&sta->users);
1314 spin_unlock_bh(&local->ap->sta_table_lock);
1316 if (sta && sta->crypt)
1320 if (skb->len >= hdrlen + 3)
1321 idx = skb->data[hdrlen + 3] >> 6;
1322 crypt = local->crypt_info.crypt[idx];
1325 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1326 auth_alg = __le16_to_cpu(*pos);
1328 auth_transaction = __le16_to_cpu(*pos);
1330 status_code = __le16_to_cpu(*pos);
1333 if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
1334 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1335 txt = "authentication denied";
1336 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1340 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1341 auth_alg == WLAN_AUTH_OPEN) ||
1342 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1343 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1345 txt = "unsupported algorithm";
1346 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1352 if (*u == WLAN_EID_CHALLENGE) {
1353 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1354 txt = "invalid challenge len";
1355 resp = WLAN_STATUS_CHALLENGE_FAIL;
1358 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1359 txt = "challenge underflow";
1360 resp = WLAN_STATUS_CHALLENGE_FAIL;
1363 challenge = (char *) (u + 2);
1367 if (sta && sta->ap) {
1368 if (time_after(jiffies, sta->u.ap.last_beacon +
1369 (10 * sta->listen_interval * HZ) / 1024)) {
1370 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1371 " assuming AP %pM is now STA\n",
1372 dev->name, sta->addr);
1375 sta->u.sta.challenge = NULL;
1377 txt = "AP trying to authenticate?";
1378 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1383 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1384 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1385 (auth_transaction == 1 ||
1386 (auth_transaction == 3 && sta != NULL &&
1387 sta->u.sta.challenge != NULL)))) {
1389 txt = "unknown authentication transaction number";
1390 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1397 if (local->ap->num_sta >= MAX_STA_COUNT) {
1398 /* FIX: might try to remove some old STAs first? */
1399 txt = "no more room for new STAs";
1400 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1404 sta = ap_add_sta(local->ap, hdr->addr2);
1406 txt = "ap_add_sta failed";
1407 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1413 case WLAN_AUTH_OPEN:
1415 /* IEEE 802.11 standard is not completely clear about
1416 * whether STA is considered authenticated after
1417 * authentication OK frame has been send or after it
1418 * has been ACKed. In order to reduce interoperability
1419 * issues, mark the STA authenticated before ACK. */
1420 sta->flags |= WLAN_STA_AUTH;
1423 case WLAN_AUTH_SHARED_KEY:
1424 if (auth_transaction == 1) {
1425 if (sta->u.sta.challenge == NULL) {
1426 sta->u.sta.challenge =
1427 ap_auth_make_challenge(local->ap);
1428 if (sta->u.sta.challenge == NULL) {
1429 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1434 if (sta->u.sta.challenge == NULL ||
1435 challenge == NULL ||
1436 memcmp(sta->u.sta.challenge, challenge,
1437 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
1438 !(fc & IEEE80211_FCTL_PROTECTED)) {
1439 txt = "challenge response incorrect";
1440 resp = WLAN_STATUS_CHALLENGE_FAIL;
1444 txt = "challenge OK - authOK";
1445 /* IEEE 802.11 standard is not completely clear about
1446 * whether STA is considered authenticated after
1447 * authentication OK frame has been send or after it
1448 * has been ACKed. In order to reduce interoperability
1449 * issues, mark the STA authenticated before ACK. */
1450 sta->flags |= WLAN_STA_AUTH;
1451 kfree(sta->u.sta.challenge);
1452 sta->u.sta.challenge = NULL;
1458 pos = (__le16 *) body;
1459 *pos = cpu_to_le16(auth_alg);
1461 *pos = cpu_to_le16(auth_transaction + 1);
1463 *pos = cpu_to_le16(resp); /* status_code */
1467 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1468 sta->u.sta.challenge != NULL &&
1469 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1470 u8 *tmp = (u8 *) pos;
1471 *tmp++ = WLAN_EID_CHALLENGE;
1472 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1474 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1475 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1478 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
1479 body, olen, hdr->addr2, ap->tx_callback_auth);
1482 sta->last_rx = jiffies;
1483 atomic_dec(&sta->users);
1487 PDEBUG(DEBUG_AP, "%s: %pM auth (alg=%d "
1488 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1489 dev->name, hdr->addr2,
1490 auth_alg, auth_transaction, status_code, len,
1496 /* Called only as a scheduled task for pending AP frames. */
1497 static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1498 struct hostap_80211_rx_status *rx_stats, int reassoc)
1500 struct net_device *dev = local->dev;
1501 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1502 char body[12], *p, *lpos;
1505 u16 resp = WLAN_STATUS_SUCCESS;
1506 struct sta_info *sta = NULL;
1507 int send_deauth = 0;
1509 u8 prev_ap[ETH_ALEN];
1511 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1513 if (len < (reassoc ? 10 : 4)) {
1514 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1515 "(len=%d, reassoc=%d) from %pM\n",
1516 dev->name, len, reassoc, hdr->addr2);
1520 spin_lock_bh(&local->ap->sta_table_lock);
1521 sta = ap_get_sta(local->ap, hdr->addr2);
1522 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1523 spin_unlock_bh(&local->ap->sta_table_lock);
1524 txt = "trying to associate before authentication";
1526 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1527 sta = NULL; /* do not decrement sta->users */
1530 atomic_inc(&sta->users);
1531 spin_unlock_bh(&local->ap->sta_table_lock);
1533 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1534 sta->capability = __le16_to_cpu(*pos);
1536 sta->listen_interval = __le16_to_cpu(*pos);
1540 memcpy(prev_ap, pos, ETH_ALEN);
1541 pos++; pos++; pos++; left -= 6;
1543 memset(prev_ap, 0, ETH_ALEN);
1547 unsigned char *u = (unsigned char *) pos;
1549 if (*u == WLAN_EID_SSID) {
1554 if (ileft > left || ileft > MAX_SSID_LEN) {
1555 txt = "SSID overflow";
1556 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1560 if (ileft != strlen(local->essid) ||
1561 memcmp(local->essid, u, ileft) != 0) {
1562 txt = "not our SSID";
1563 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1571 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1576 if (ileft > left || ileft == 0 ||
1577 ileft > WLAN_SUPP_RATES_MAX) {
1578 txt = "SUPP_RATES len error";
1579 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1583 memset(sta->supported_rates, 0,
1584 sizeof(sta->supported_rates));
1585 memcpy(sta->supported_rates, u, ileft);
1586 prism2_check_tx_rates(sta);
1593 PDEBUG(DEBUG_AP, "%s: assoc from %pM"
1594 " with extra data (%d bytes) [",
1595 dev->name, hdr->addr2, left);
1597 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1600 PDEBUG2(DEBUG_AP, "]\n");
1603 txt = "frame underflow";
1604 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1608 /* get a unique AID */
1610 txt = "OK, old AID";
1612 spin_lock_bh(&local->ap->sta_table_lock);
1613 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1614 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1616 if (sta->aid > MAX_AID_TABLE_SIZE) {
1618 spin_unlock_bh(&local->ap->sta_table_lock);
1619 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1620 txt = "no room for more AIDs";
1622 local->ap->sta_aid[sta->aid - 1] = sta;
1623 spin_unlock_bh(&local->ap->sta_table_lock);
1624 txt = "OK, new AID";
1629 pos = (__le16 *) body;
1632 *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1635 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1636 * values in beacons/probe responses */
1637 /* FIX: how about privacy and WEP? */
1639 *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
1643 *pos = cpu_to_le16(resp);
1646 *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1647 BIT(14) | BIT(15)); /* AID */
1650 /* Supported rates (Information element) */
1652 *p++ = WLAN_EID_SUPP_RATES;
1655 if (local->tx_rate_control & WLAN_RATE_1M) {
1656 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1659 if (local->tx_rate_control & WLAN_RATE_2M) {
1660 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1663 if (local->tx_rate_control & WLAN_RATE_5M5) {
1664 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1668 if (local->tx_rate_control & WLAN_RATE_11M) {
1669 *p++ = local->basic_rates & WLAN_RATE_11M ?
1676 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1677 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1678 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1679 IEEE80211_STYPE_ASSOC_RESP)),
1680 body, (u8 *) pos - (u8 *) body,
1682 send_deauth ? 0 : local->ap->tx_callback_assoc);
1685 if (resp == WLAN_STATUS_SUCCESS) {
1686 sta->last_rx = jiffies;
1687 /* STA will be marked associated from TX callback, if
1688 * AssocResp is ACKed */
1690 atomic_dec(&sta->users);
1694 PDEBUG(DEBUG_AP, "%s: %pM %sassoc (len=%d "
1695 "prev_ap=%pM) => %d(%d) (%s)\n",
1698 reassoc ? "re" : "", len,
1700 resp, send_deauth, txt);
1705 /* Called only as a scheduled task for pending AP frames. */
1706 static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1707 struct hostap_80211_rx_status *rx_stats)
1709 struct net_device *dev = local->dev;
1710 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1711 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1715 struct sta_info *sta = NULL;
1717 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1720 printk("handle_deauth - too short payload (len=%d)\n", len);
1724 pos = (__le16 *) body;
1725 reason_code = le16_to_cpu(*pos);
1727 PDEBUG(DEBUG_AP, "%s: deauthentication: %pM len=%d, "
1728 "reason_code=%d\n", dev->name, hdr->addr2,
1731 spin_lock_bh(&local->ap->sta_table_lock);
1732 sta = ap_get_sta(local->ap, hdr->addr2);
1734 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1735 hostap_event_expired_sta(local->dev, sta);
1736 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1738 spin_unlock_bh(&local->ap->sta_table_lock);
1740 printk("%s: deauthentication from %pM, "
1741 "reason_code=%d, but STA not authenticated\n", dev->name,
1742 hdr->addr2, reason_code);
1747 /* Called only as a scheduled task for pending AP frames. */
1748 static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1749 struct hostap_80211_rx_status *rx_stats)
1751 struct net_device *dev = local->dev;
1752 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1753 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1757 struct sta_info *sta = NULL;
1759 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1762 printk("handle_disassoc - too short payload (len=%d)\n", len);
1766 pos = (__le16 *) body;
1767 reason_code = le16_to_cpu(*pos);
1769 PDEBUG(DEBUG_AP, "%s: disassociation: %pM len=%d, "
1770 "reason_code=%d\n", dev->name, hdr->addr2,
1773 spin_lock_bh(&local->ap->sta_table_lock);
1774 sta = ap_get_sta(local->ap, hdr->addr2);
1776 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1777 hostap_event_expired_sta(local->dev, sta);
1778 sta->flags &= ~WLAN_STA_ASSOC;
1780 spin_unlock_bh(&local->ap->sta_table_lock);
1782 printk("%s: disassociation from %pM, "
1783 "reason_code=%d, but STA not authenticated\n",
1784 dev->name, hdr->addr2, reason_code);
1789 /* Called only as a scheduled task for pending AP frames. */
1790 static void ap_handle_data_nullfunc(local_info_t *local,
1791 struct ieee80211_hdr_4addr *hdr)
1793 struct net_device *dev = local->dev;
1795 /* some STA f/w's seem to require control::ACK frame for
1796 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1798 * send control::ACK for the data::nullfunc */
1800 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1801 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
1802 NULL, 0, hdr->addr2, 0);
1806 /* Called only as a scheduled task for pending AP frames. */
1807 static void ap_handle_dropped_data(local_info_t *local,
1808 struct ieee80211_hdr_4addr *hdr)
1810 struct net_device *dev = local->dev;
1811 struct sta_info *sta;
1814 spin_lock_bh(&local->ap->sta_table_lock);
1815 sta = ap_get_sta(local->ap, hdr->addr2);
1817 atomic_inc(&sta->users);
1818 spin_unlock_bh(&local->ap->sta_table_lock);
1820 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1821 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1822 atomic_dec(&sta->users);
1826 reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1827 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1828 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1829 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
1830 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1833 atomic_dec(&sta->users);
1836 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1839 /* Called only as a scheduled task for pending AP frames. */
1840 static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1841 struct sk_buff *skb)
1843 struct hostap_skb_tx_data *meta;
1845 if (!(sta->flags & WLAN_STA_PS)) {
1846 /* Station has moved to non-PS mode, so send all buffered
1847 * frames using normal device queue. */
1848 dev_queue_xmit(skb);
1852 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1853 * be passed through even though STA is using PS */
1854 meta = (struct hostap_skb_tx_data *) skb->cb;
1855 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
1856 if (!skb_queue_empty(&sta->tx_buf)) {
1857 /* indicate to STA that more frames follow */
1858 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
1860 dev_queue_xmit(skb);
1864 /* Called only as a scheduled task for pending AP frames. */
1865 static void handle_pspoll(local_info_t *local,
1866 struct ieee80211_hdr_4addr *hdr,
1867 struct hostap_80211_rx_status *rx_stats)
1869 struct net_device *dev = local->dev;
1870 struct sta_info *sta;
1872 struct sk_buff *skb;
1874 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1875 hdr->addr1, hdr->addr2,
1876 !!(le16_to_cpu(hdr->frame_ctl) & IEEE80211_FCTL_PM));
1878 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
1880 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1885 aid = le16_to_cpu(hdr->duration_id);
1886 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1887 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1890 aid &= ~(BIT(15) | BIT(14));
1891 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1892 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1895 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1897 spin_lock_bh(&local->ap->sta_table_lock);
1898 sta = ap_get_sta(local->ap, hdr->addr2);
1900 atomic_inc(&sta->users);
1901 spin_unlock_bh(&local->ap->sta_table_lock);
1904 PDEBUG(DEBUG_PS, " STA not found\n");
1907 if (sta->aid != aid) {
1908 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1909 "assoc.aid=%d\n", aid, sta->aid);
1914 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1915 * out (expiry time must be longer than ListenInterval for
1916 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1917 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1918 * sta; store buffer for later use and leave TIM aid bit set? use
1919 * TX event to check whether frame was ACKed?
1922 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1923 /* send buffered frame .. */
1924 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1925 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1927 pspoll_send_buffered(local, sta, skb);
1929 if (sta->flags & WLAN_STA_PS) {
1930 /* send only one buffered packet per PS Poll */
1931 /* FIX: should ignore further PS Polls until the
1932 * buffered packet that was just sent is acknowledged
1933 * (Tx or TxExc event) */
1938 if (skb_queue_empty(&sta->tx_buf)) {
1939 /* try to clear aid from TIM */
1940 if (!(sta->flags & WLAN_STA_TIM))
1941 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1943 hostap_set_tim(local, aid, 0);
1944 sta->flags &= ~WLAN_STA_TIM;
1947 atomic_dec(&sta->users);
1951 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1953 static void handle_wds_oper_queue(struct work_struct *work)
1955 struct ap_data *ap = container_of(work, struct ap_data,
1957 local_info_t *local = ap->local;
1958 struct wds_oper_data *entry, *prev;
1960 spin_lock_bh(&local->lock);
1961 entry = local->ap->wds_oper_entries;
1962 local->ap->wds_oper_entries = NULL;
1963 spin_unlock_bh(&local->lock);
1966 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
1969 entry->type == WDS_ADD ? "adding" : "removing",
1971 if (entry->type == WDS_ADD)
1972 prism2_wds_add(local, entry->addr, 0);
1973 else if (entry->type == WDS_DEL)
1974 prism2_wds_del(local, entry->addr, 0, 1);
1977 entry = entry->next;
1983 /* Called only as a scheduled task for pending AP frames. */
1984 static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1985 struct hostap_80211_rx_status *rx_stats)
1987 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1988 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1990 u16 beacon_int, capability;
1993 unsigned char *supp_rates = NULL;
1994 int ssid_len = 0, supp_rates_len = 0;
1995 struct sta_info *sta = NULL;
1996 int new_sta = 0, channel = -1;
1998 len = skb->len - IEEE80211_MGMT_HDR_LEN;
2000 if (len < 8 + 2 + 2) {
2001 printk(KERN_DEBUG "handle_beacon - too short payload "
2006 pos = (__le16 *) body;
2009 /* Timestamp (8 octets) */
2010 pos += 4; left -= 8;
2011 /* Beacon interval (2 octets) */
2012 beacon_int = le16_to_cpu(*pos);
2014 /* Capability information (2 octets) */
2015 capability = le16_to_cpu(*pos);
2018 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2019 capability & WLAN_CAPABILITY_IBSS)
2024 unsigned char *u = (unsigned char *) pos;
2026 if (*u == WLAN_EID_SSID) {
2031 if (ileft > left || ileft > MAX_SSID_LEN) {
2032 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2036 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2037 (ileft != strlen(local->essid) ||
2038 memcmp(local->essid, u, ileft) != 0)) {
2050 if (*u == WLAN_EID_SUPP_RATES) {
2055 if (ileft > left || ileft == 0 || ileft > 8) {
2056 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2061 supp_rates_len = ileft;
2067 if (*u == WLAN_EID_DS_PARAMS) {
2072 if (ileft > left || ileft != 1) {
2073 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2084 spin_lock_bh(&local->ap->sta_table_lock);
2085 sta = ap_get_sta(local->ap, hdr->addr2);
2087 atomic_inc(&sta->users);
2088 spin_unlock_bh(&local->ap->sta_table_lock);
2093 sta = ap_add_sta(local->ap, hdr->addr2);
2095 printk(KERN_INFO "prism2: kmalloc failed for AP "
2096 "data structure\n");
2099 hostap_event_new_sta(local->dev, sta);
2101 /* mark APs authentication and associated for pseudo ad-hoc
2102 * style communication */
2103 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2105 if (local->ap->autom_ap_wds) {
2106 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2112 sta->u.ap.ssid_len = ssid_len;
2113 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2114 sta->u.ap.ssid[ssid_len] = '\0';
2116 sta->u.ap.ssid_len = 0;
2117 sta->u.ap.ssid[0] = '\0';
2119 sta->u.ap.channel = channel;
2121 sta->rx_bytes += len;
2122 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2123 sta->capability = capability;
2124 sta->listen_interval = beacon_int;
2126 atomic_dec(&sta->users);
2129 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2130 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2131 prism2_check_tx_rates(sta);
2135 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2138 /* Called only as a tasklet. */
2139 static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2140 struct hostap_80211_rx_status *rx_stats)
2142 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2143 struct net_device *dev = local->dev;
2144 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2145 u16 fc, type, stype;
2146 struct ieee80211_hdr_4addr *hdr;
2148 /* FIX: should give skb->len to handler functions and check that the
2149 * buffer is long enough */
2150 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2151 fc = le16_to_cpu(hdr->frame_ctl);
2152 type = WLAN_FC_GET_TYPE(fc);
2153 stype = WLAN_FC_GET_STYPE(fc);
2155 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2156 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
2157 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2159 if (!(fc & IEEE80211_FCTL_TODS) ||
2160 (fc & IEEE80211_FCTL_FROMDS)) {
2161 if (stype == IEEE80211_STYPE_NULLFUNC) {
2162 /* no ToDS nullfunc seems to be used to check
2163 * AP association; so send reject message to
2164 * speed up re-association */
2165 ap_handle_dropped_data(local, hdr);
2168 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2173 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2174 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
2175 " not own MAC\n", hdr->addr1);
2179 if (local->ap->nullfunc_ack &&
2180 stype == IEEE80211_STYPE_NULLFUNC)
2181 ap_handle_data_nullfunc(local, hdr);
2183 ap_handle_dropped_data(local, hdr);
2187 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
2188 handle_beacon(local, skb, rx_stats);
2191 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2193 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
2194 handle_pspoll(local, hdr, rx_stats);
2198 if (local->hostapd) {
2199 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2200 "subtype=0x%02x\n", type, stype);
2204 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2205 if (type != IEEE80211_FTYPE_MGMT) {
2206 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2210 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2211 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
2212 " not own MAC\n", hdr->addr1);
2216 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
2217 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
2218 " not own MAC\n", hdr->addr3);
2223 case IEEE80211_STYPE_ASSOC_REQ:
2224 handle_assoc(local, skb, rx_stats, 0);
2226 case IEEE80211_STYPE_ASSOC_RESP:
2227 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2229 case IEEE80211_STYPE_REASSOC_REQ:
2230 handle_assoc(local, skb, rx_stats, 1);
2232 case IEEE80211_STYPE_REASSOC_RESP:
2233 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2235 case IEEE80211_STYPE_ATIM:
2236 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2238 case IEEE80211_STYPE_DISASSOC:
2239 handle_disassoc(local, skb, rx_stats);
2241 case IEEE80211_STYPE_AUTH:
2242 handle_authen(local, skb, rx_stats);
2244 case IEEE80211_STYPE_DEAUTH:
2245 handle_deauth(local, skb, rx_stats);
2248 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2252 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2259 /* Called only as a tasklet (software IRQ) */
2260 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2261 struct hostap_80211_rx_status *rx_stats)
2263 struct hostap_interface *iface;
2264 local_info_t *local;
2266 struct ieee80211_hdr_4addr *hdr;
2268 iface = netdev_priv(dev);
2269 local = iface->local;
2274 local->stats.rx_packets++;
2276 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2277 fc = le16_to_cpu(hdr->frame_ctl);
2279 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2280 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_MGMT &&
2281 WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_BEACON)
2284 skb->protocol = __constant_htons(ETH_P_HOSTAP);
2285 handle_ap_item(local, skb, rx_stats);
2293 /* Called only as a tasklet (software IRQ) */
2294 static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2296 struct sk_buff *skb;
2297 struct ieee80211_hdr_4addr *hdr;
2298 struct hostap_80211_rx_status rx_stats;
2300 if (skb_queue_empty(&sta->tx_buf))
2303 skb = dev_alloc_skb(16);
2305 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2306 "failed\n", local->dev->name);
2310 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, 16);
2312 /* Generate a fake pspoll frame to start packet delivery */
2313 hdr->frame_ctl = __constant_cpu_to_le16(
2314 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
2315 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2316 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2317 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2320 "%s: Scheduling buffered packet delivery for STA %pM\n",
2321 local->dev->name, sta->addr);
2323 skb->dev = local->dev;
2325 memset(&rx_stats, 0, sizeof(rx_stats));
2326 hostap_rx(local->dev, skb, &rx_stats);
2330 int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2331 struct iw_quality qual[], int buf_size,
2334 struct ap_data *ap = local->ap;
2335 struct list_head *ptr;
2338 spin_lock_bh(&ap->sta_table_lock);
2340 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2342 struct sta_info *sta = (struct sta_info *) ptr;
2344 if (aplist && !sta->ap)
2346 addr[count].sa_family = ARPHRD_ETHER;
2347 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2348 if (sta->last_rx_silence == 0)
2349 qual[count].qual = sta->last_rx_signal < 27 ?
2350 0 : (sta->last_rx_signal - 27) * 92 / 127;
2352 qual[count].qual = sta->last_rx_signal -
2353 sta->last_rx_silence - 35;
2354 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2355 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2356 qual[count].updated = sta->last_rx_updated;
2358 sta->last_rx_updated = IW_QUAL_DBM;
2361 if (count >= buf_size)
2364 spin_unlock_bh(&ap->sta_table_lock);
2370 /* Translate our list of Access Points & Stations to a card independant
2371 * format that the Wireless Tools will understand - Jean II */
2372 int prism2_ap_translate_scan(struct net_device *dev,
2373 struct iw_request_info *info, char *buffer)
2375 struct hostap_interface *iface;
2376 local_info_t *local;
2378 struct list_head *ptr;
2379 struct iw_event iwe;
2380 char *current_ev = buffer;
2381 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2382 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2386 iface = netdev_priv(dev);
2387 local = iface->local;
2390 spin_lock_bh(&ap->sta_table_lock);
2392 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2394 struct sta_info *sta = (struct sta_info *) ptr;
2396 /* First entry *MUST* be the AP MAC address */
2397 memset(&iwe, 0, sizeof(iwe));
2398 iwe.cmd = SIOCGIWAP;
2399 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2400 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2401 iwe.len = IW_EV_ADDR_LEN;
2402 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2403 &iwe, IW_EV_ADDR_LEN);
2405 /* Use the mode to indicate if it's a station or
2406 * an Access Point */
2407 memset(&iwe, 0, sizeof(iwe));
2408 iwe.cmd = SIOCGIWMODE;
2410 iwe.u.mode = IW_MODE_MASTER;
2412 iwe.u.mode = IW_MODE_INFRA;
2413 iwe.len = IW_EV_UINT_LEN;
2414 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2415 &iwe, IW_EV_UINT_LEN);
2418 memset(&iwe, 0, sizeof(iwe));
2420 if (sta->last_rx_silence == 0)
2421 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2422 0 : (sta->last_rx_signal - 27) * 92 / 127;
2424 iwe.u.qual.qual = sta->last_rx_signal -
2425 sta->last_rx_silence - 35;
2426 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2427 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2428 iwe.u.qual.updated = sta->last_rx_updated;
2429 iwe.len = IW_EV_QUAL_LEN;
2430 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2431 &iwe, IW_EV_QUAL_LEN);
2433 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2435 memset(&iwe, 0, sizeof(iwe));
2436 iwe.cmd = SIOCGIWESSID;
2437 iwe.u.data.length = sta->u.ap.ssid_len;
2438 iwe.u.data.flags = 1;
2439 current_ev = iwe_stream_add_point(info, current_ev,
2443 memset(&iwe, 0, sizeof(iwe));
2444 iwe.cmd = SIOCGIWENCODE;
2445 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2447 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2449 iwe.u.data.flags = IW_ENCODE_DISABLED;
2450 current_ev = iwe_stream_add_point(info, current_ev,
2454 if (sta->u.ap.channel > 0 &&
2455 sta->u.ap.channel <= FREQ_COUNT) {
2456 memset(&iwe, 0, sizeof(iwe));
2457 iwe.cmd = SIOCGIWFREQ;
2458 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2461 current_ev = iwe_stream_add_event(
2462 info, current_ev, end_buf, &iwe,
2466 memset(&iwe, 0, sizeof(iwe));
2467 iwe.cmd = IWEVCUSTOM;
2468 sprintf(buf, "beacon_interval=%d",
2469 sta->listen_interval);
2470 iwe.u.data.length = strlen(buf);
2471 current_ev = iwe_stream_add_point(info, current_ev,
2472 end_buf, &iwe, buf);
2474 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2476 sta->last_rx_updated = IW_QUAL_DBM;
2478 /* To be continued, we should make good use of IWEVCUSTOM */
2481 spin_unlock_bh(&ap->sta_table_lock);
2483 return current_ev - buffer;
2487 static int prism2_hostapd_add_sta(struct ap_data *ap,
2488 struct prism2_hostapd_param *param)
2490 struct sta_info *sta;
2492 spin_lock_bh(&ap->sta_table_lock);
2493 sta = ap_get_sta(ap, param->sta_addr);
2495 atomic_inc(&sta->users);
2496 spin_unlock_bh(&ap->sta_table_lock);
2499 sta = ap_add_sta(ap, param->sta_addr);
2504 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2505 hostap_event_new_sta(sta->local->dev, sta);
2507 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2508 sta->last_rx = jiffies;
2509 sta->aid = param->u.add_sta.aid;
2510 sta->capability = param->u.add_sta.capability;
2511 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2512 if (sta->tx_supp_rates & WLAN_RATE_1M)
2513 sta->supported_rates[0] = 2;
2514 if (sta->tx_supp_rates & WLAN_RATE_2M)
2515 sta->supported_rates[1] = 4;
2516 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2517 sta->supported_rates[2] = 11;
2518 if (sta->tx_supp_rates & WLAN_RATE_11M)
2519 sta->supported_rates[3] = 22;
2520 prism2_check_tx_rates(sta);
2521 atomic_dec(&sta->users);
2526 static int prism2_hostapd_remove_sta(struct ap_data *ap,
2527 struct prism2_hostapd_param *param)
2529 struct sta_info *sta;
2531 spin_lock_bh(&ap->sta_table_lock);
2532 sta = ap_get_sta(ap, param->sta_addr);
2534 ap_sta_hash_del(ap, sta);
2535 list_del(&sta->list);
2537 spin_unlock_bh(&ap->sta_table_lock);
2542 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2543 hostap_event_expired_sta(sta->local->dev, sta);
2544 ap_free_sta(ap, sta);
2550 static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2551 struct prism2_hostapd_param *param)
2553 struct sta_info *sta;
2555 spin_lock_bh(&ap->sta_table_lock);
2556 sta = ap_get_sta(ap, param->sta_addr);
2558 atomic_inc(&sta->users);
2559 spin_unlock_bh(&ap->sta_table_lock);
2564 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2566 atomic_dec(&sta->users);
2572 static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2573 struct prism2_hostapd_param *param)
2575 struct sta_info *sta;
2577 spin_lock_bh(&ap->sta_table_lock);
2578 sta = ap_get_sta(ap, param->sta_addr);
2580 sta->flags |= param->u.set_flags_sta.flags_or;
2581 sta->flags &= param->u.set_flags_sta.flags_and;
2583 spin_unlock_bh(&ap->sta_table_lock);
2592 static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2593 struct prism2_hostapd_param *param)
2595 struct sta_info *sta;
2598 spin_lock_bh(&ap->sta_table_lock);
2599 sta = ap_get_sta(ap, param->sta_addr);
2601 sta->rx_packets = sta->tx_packets = 0;
2602 sta->rx_bytes = sta->tx_bytes = 0;
2603 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2604 sta->tx_count[rate] = 0;
2605 sta->rx_count[rate] = 0;
2608 spin_unlock_bh(&ap->sta_table_lock);
2617 int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
2619 switch (param->cmd) {
2620 case PRISM2_HOSTAPD_FLUSH:
2621 ap_control_kickall(ap);
2623 case PRISM2_HOSTAPD_ADD_STA:
2624 return prism2_hostapd_add_sta(ap, param);
2625 case PRISM2_HOSTAPD_REMOVE_STA:
2626 return prism2_hostapd_remove_sta(ap, param);
2627 case PRISM2_HOSTAPD_GET_INFO_STA:
2628 return prism2_hostapd_get_info_sta(ap, param);
2629 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2630 return prism2_hostapd_set_flags_sta(ap, param);
2631 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2632 return prism2_hostapd_sta_clear_stats(ap, param);
2634 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2641 /* Update station info for host-based TX rate control and return current
2643 static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2645 int ret = sta->tx_rate;
2646 struct hostap_interface *iface;
2647 local_info_t *local;
2649 iface = netdev_priv(dev);
2650 local = iface->local;
2652 sta->tx_count[sta->tx_rate_idx]++;
2653 sta->tx_since_last_failure++;
2654 sta->tx_consecutive_exc = 0;
2655 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2656 sta->tx_rate_idx < sta->tx_max_rate) {
2657 /* use next higher rate */
2658 int old_rate, new_rate;
2659 old_rate = new_rate = sta->tx_rate_idx;
2660 while (new_rate < sta->tx_max_rate) {
2662 if (ap_tx_rate_ok(new_rate, sta, local)) {
2663 sta->tx_rate_idx = new_rate;
2667 if (old_rate != sta->tx_rate_idx) {
2668 switch (sta->tx_rate_idx) {
2669 case 0: sta->tx_rate = 10; break;
2670 case 1: sta->tx_rate = 20; break;
2671 case 2: sta->tx_rate = 55; break;
2672 case 3: sta->tx_rate = 110; break;
2673 default: sta->tx_rate = 0; break;
2675 PDEBUG(DEBUG_AP, "%s: STA %pM TX rate raised to %d\n",
2676 dev->name, sta->addr, sta->tx_rate);
2678 sta->tx_since_last_failure = 0;
2685 /* Called only from software IRQ. Called for each TX frame prior possible
2686 * encryption and transmit. */
2687 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2689 struct sta_info *sta = NULL;
2690 struct sk_buff *skb = tx->skb;
2692 struct ieee80211_hdr_4addr *hdr;
2693 struct hostap_skb_tx_data *meta;
2695 meta = (struct hostap_skb_tx_data *) skb->cb;
2696 ret = AP_TX_CONTINUE;
2697 if (local->ap == NULL || skb->len < 10 ||
2698 meta->iface->type == HOSTAP_INTERFACE_STA)
2701 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2703 if (hdr->addr1[0] & 0x01) {
2704 /* broadcast/multicast frame - no AP related processing */
2705 if (local->ap->num_sta <= 0)
2710 /* unicast packet - check whether destination STA is associated */
2711 spin_lock(&local->ap->sta_table_lock);
2712 sta = ap_get_sta(local->ap, hdr->addr1);
2714 atomic_inc(&sta->users);
2715 spin_unlock(&local->ap->sta_table_lock);
2717 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2718 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
2719 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2720 meta->iface->type != HOSTAP_INTERFACE_AP) {
2722 /* This can happen, e.g., when wlan0 is added to a bridge and
2723 * bridging code does not know which port is the correct target
2724 * for a unicast frame. In this case, the packet is send to all
2725 * ports of the bridge. Since this is a valid scenario, do not
2726 * print out any errors here. */
2727 if (net_ratelimit()) {
2728 printk(KERN_DEBUG "AP: drop packet to non-associated "
2729 "STA %pM\n", hdr->addr1);
2732 local->ap->tx_drop_nonassoc++;
2740 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2741 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2743 /* Set tx_rate if using host-based TX rate control */
2744 if (!local->fw_tx_rate_control)
2745 local->ap->last_tx_rate = meta->rate =
2746 ap_update_sta_tx_rate(sta, local->dev);
2748 if (local->iw_mode != IW_MODE_MASTER)
2751 if (!(sta->flags & WLAN_STA_PS))
2754 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2755 /* indicate to STA that more frames follow */
2757 __constant_cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2760 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2761 /* packet was already buffered and now send due to
2762 * PS poll, so do not rebuffer it */
2766 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2767 PDEBUG(DEBUG_PS, "%s: No more space in STA (%pM)'s"
2769 local->dev->name, sta->addr);
2770 /* Make sure that TIM is set for the station (it might not be
2771 * after AP wlan hw reset). */
2772 /* FIX: should fix hw reset to restore bits based on STA
2774 hostap_set_tim(local, sta->aid, 1);
2775 sta->flags |= WLAN_STA_TIM;
2780 /* STA in PS mode, buffer frame for later delivery */
2781 set_tim = skb_queue_empty(&sta->tx_buf);
2782 skb_queue_tail(&sta->tx_buf, skb);
2783 /* FIX: could save RX time to skb and expire buffered frames after
2784 * some time if STA does not poll for them */
2787 if (sta->flags & WLAN_STA_TIM)
2788 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2790 hostap_set_tim(local, sta->aid, 1);
2791 sta->flags |= WLAN_STA_TIM;
2794 ret = AP_TX_BUFFERED;
2798 if (ret == AP_TX_CONTINUE ||
2799 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2801 sta->tx_bytes += skb->len;
2802 sta->last_tx = jiffies;
2805 if ((ret == AP_TX_CONTINUE ||
2806 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2807 sta->crypt && tx->host_encrypt) {
2808 tx->crypt = sta->crypt;
2809 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2810 * be called to release sta info
2813 atomic_dec(&sta->users);
2820 void hostap_handle_sta_release(void *ptr)
2822 struct sta_info *sta = ptr;
2823 atomic_dec(&sta->users);
2827 /* Called only as a tasklet (software IRQ) */
2828 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2830 struct sta_info *sta;
2831 struct ieee80211_hdr_4addr *hdr;
2832 struct hostap_skb_tx_data *meta;
2834 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2835 meta = (struct hostap_skb_tx_data *) skb->cb;
2837 spin_lock(&local->ap->sta_table_lock);
2838 sta = ap_get_sta(local->ap, hdr->addr1);
2840 spin_unlock(&local->ap->sta_table_lock);
2841 PDEBUG(DEBUG_AP, "%s: Could not find STA %pM"
2842 " for this TX error (@%lu)\n",
2843 local->dev->name, hdr->addr1, jiffies);
2847 sta->tx_since_last_failure = 0;
2848 sta->tx_consecutive_exc++;
2850 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2851 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2852 /* use next lower rate */
2854 old = rate = sta->tx_rate_idx;
2857 if (ap_tx_rate_ok(rate, sta, local)) {
2858 sta->tx_rate_idx = rate;
2862 if (old != sta->tx_rate_idx) {
2863 switch (sta->tx_rate_idx) {
2864 case 0: sta->tx_rate = 10; break;
2865 case 1: sta->tx_rate = 20; break;
2866 case 2: sta->tx_rate = 55; break;
2867 case 3: sta->tx_rate = 110; break;
2868 default: sta->tx_rate = 0; break;
2871 "%s: STA %pM TX rate lowered to %d\n",
2872 local->dev->name, sta->addr, sta->tx_rate);
2874 sta->tx_consecutive_exc = 0;
2876 spin_unlock(&local->ap->sta_table_lock);
2880 static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2881 int pwrmgt, int type, int stype)
2883 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2884 sta->flags |= WLAN_STA_PS;
2885 PDEBUG(DEBUG_PS2, "STA %pM changed to use PS "
2886 "mode (type=0x%02X, stype=0x%02X)\n",
2887 sta->addr, type >> 2, stype >> 4);
2888 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2889 sta->flags &= ~WLAN_STA_PS;
2890 PDEBUG(DEBUG_PS2, "STA %pM changed to not use "
2891 "PS mode (type=0x%02X, stype=0x%02X)\n",
2892 sta->addr, type >> 2, stype >> 4);
2893 if (type != IEEE80211_FTYPE_CTL ||
2894 stype != IEEE80211_STYPE_PSPOLL)
2895 schedule_packet_send(local, sta);
2900 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2901 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
2902 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
2904 struct sta_info *sta;
2907 spin_lock(&local->ap->sta_table_lock);
2908 sta = ap_get_sta(local->ap, hdr->addr2);
2910 atomic_inc(&sta->users);
2911 spin_unlock(&local->ap->sta_table_lock);
2916 fc = le16_to_cpu(hdr->frame_ctl);
2917 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
2918 WLAN_FC_GET_TYPE(fc), WLAN_FC_GET_STYPE(fc));
2920 atomic_dec(&sta->users);
2925 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2926 * getting RX header and payload from hardware. */
2927 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2928 struct sk_buff *skb,
2929 struct hostap_80211_rx_status *rx_stats,
2933 struct sta_info *sta;
2934 u16 fc, type, stype;
2935 struct ieee80211_hdr_4addr *hdr;
2937 if (local->ap == NULL)
2938 return AP_RX_CONTINUE;
2940 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2942 fc = le16_to_cpu(hdr->frame_ctl);
2943 type = WLAN_FC_GET_TYPE(fc);
2944 stype = WLAN_FC_GET_STYPE(fc);
2946 spin_lock(&local->ap->sta_table_lock);
2947 sta = ap_get_sta(local->ap, hdr->addr2);
2949 atomic_inc(&sta->users);
2950 spin_unlock(&local->ap->sta_table_lock);
2952 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2953 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2955 ret = AP_RX_CONTINUE;
2958 if (fc & IEEE80211_FCTL_TODS) {
2959 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2960 if (local->hostapd) {
2961 prism2_rx_80211(local->apdev, skb, rx_stats,
2962 PRISM2_RX_NON_ASSOC);
2963 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2965 printk(KERN_DEBUG "%s: dropped received packet"
2966 " from non-associated STA %pM"
2967 " (type=0x%02x, subtype=0x%02x)\n",
2968 dev->name, hdr->addr2,
2969 type >> 2, stype >> 4);
2970 hostap_rx(dev, skb, rx_stats);
2971 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2976 } else if (fc & IEEE80211_FCTL_FROMDS) {
2978 /* FromDS frame - not for us; probably
2979 * broadcast/multicast in another BSS - drop */
2980 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2981 printk(KERN_DEBUG "Odd.. FromDS packet "
2982 "received with own BSSID\n");
2983 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2988 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
2989 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2991 if (local->hostapd) {
2992 prism2_rx_80211(local->apdev, skb, rx_stats,
2993 PRISM2_RX_NON_ASSOC);
2994 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2996 /* At least Lucent f/w seems to send data::nullfunc
2997 * frames with no ToDS flag when the current AP returns
2998 * after being unavailable for some time. Speed up
2999 * re-association by informing the station about it not
3000 * being associated. */
3001 printk(KERN_DEBUG "%s: rejected received nullfunc frame"
3002 " without ToDS from not associated STA %pM\n",
3003 dev->name, hdr->addr2);
3004 hostap_rx(dev, skb, rx_stats);
3005 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3009 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
3010 /* At least Lucent cards seem to send periodic nullfunc
3011 * frames with ToDS. Let these through to update SQ
3012 * stats and PS state. Nullfunc frames do not contain
3013 * any data and they will be dropped below. */
3015 /* If BSSID (Addr3) is foreign, this frame is a normal
3016 * broadcast frame from an IBSS network. Drop it silently.
3017 * If BSSID is own, report the dropping of this frame. */
3018 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
3019 printk(KERN_DEBUG "%s: dropped received packet from %pM"
3020 " with no ToDS flag "
3021 "(type=0x%02x, subtype=0x%02x)\n", dev->name,
3022 hdr->addr2, type >> 2, stype >> 4);
3023 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3030 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
3034 sta->rx_bytes += skb->len;
3035 sta->last_rx = jiffies;
3038 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
3039 fc & IEEE80211_FCTL_TODS) {
3040 if (local->hostapd) {
3041 prism2_rx_80211(local->apdev, skb, rx_stats,
3042 PRISM2_RX_NULLFUNC_ACK);
3043 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3045 /* some STA f/w's seem to require control::ACK frame
3046 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3047 * from Compaq) does not send this.. Try to generate
3048 * ACK for these frames from the host driver to make
3049 * power saving work with, e.g., Lucent WaveLAN f/w */
3050 hostap_rx(dev, skb, rx_stats);
3051 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3059 atomic_dec(&sta->users);
3065 /* Called only as a tasklet (software IRQ) */
3066 int hostap_handle_sta_crypto(local_info_t *local,
3067 struct ieee80211_hdr_4addr *hdr,
3068 struct lib80211_crypt_data **crypt,
3071 struct sta_info *sta;
3073 spin_lock(&local->ap->sta_table_lock);
3074 sta = ap_get_sta(local->ap, hdr->addr2);
3076 atomic_inc(&sta->users);
3077 spin_unlock(&local->ap->sta_table_lock);
3083 *crypt = sta->crypt;
3085 /* hostap_handle_sta_release() will be called to release STA
3088 atomic_dec(&sta->users);
3094 /* Called only as a tasklet (software IRQ) */
3095 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3097 struct sta_info *sta;
3100 spin_lock(&ap->sta_table_lock);
3101 sta = ap_get_sta(ap, sta_addr);
3102 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3104 spin_unlock(&ap->sta_table_lock);
3110 /* Called only as a tasklet (software IRQ) */
3111 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3113 struct sta_info *sta;
3116 spin_lock(&ap->sta_table_lock);
3117 sta = ap_get_sta(ap, sta_addr);
3118 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3119 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3120 ap->local->ieee_802_1x == 0))
3122 spin_unlock(&ap->sta_table_lock);
3128 /* Called only as a tasklet (software IRQ) */
3129 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3131 struct sta_info *sta;
3137 spin_lock(&ap->sta_table_lock);
3138 sta = ap_get_sta(ap, sta_addr);
3141 spin_unlock(&ap->sta_table_lock);
3144 sta = ap_add_sta(ap, sta_addr);
3147 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3149 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3150 /* No way of knowing which rates are supported since we did not
3151 * get supported rates element from beacon/assoc req. Assume
3152 * that remote end supports all 802.11b rates. */
3153 sta->supported_rates[0] = 0x82;
3154 sta->supported_rates[1] = 0x84;
3155 sta->supported_rates[2] = 0x0b;
3156 sta->supported_rates[3] = 0x16;
3157 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3158 WLAN_RATE_5M5 | WLAN_RATE_11M;
3160 sta->tx_max_rate = sta->tx_rate_idx = 3;
3167 /* Called only as a tasklet (software IRQ) */
3168 int hostap_update_rx_stats(struct ap_data *ap,
3169 struct ieee80211_hdr_4addr *hdr,
3170 struct hostap_80211_rx_status *rx_stats)
3172 struct sta_info *sta;
3177 spin_lock(&ap->sta_table_lock);
3178 sta = ap_get_sta(ap, hdr->addr2);
3180 sta->last_rx_silence = rx_stats->noise;
3181 sta->last_rx_signal = rx_stats->signal;
3182 sta->last_rx_rate = rx_stats->rate;
3183 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3184 if (rx_stats->rate == 10)
3186 else if (rx_stats->rate == 20)
3188 else if (rx_stats->rate == 55)
3190 else if (rx_stats->rate == 110)
3193 spin_unlock(&ap->sta_table_lock);
3195 return sta ? 0 : -1;
3199 void hostap_update_rates(local_info_t *local)
3201 struct sta_info *sta;
3202 struct ap_data *ap = local->ap;
3207 spin_lock_bh(&ap->sta_table_lock);
3208 list_for_each_entry(sta, &ap->sta_list, list) {
3209 prism2_check_tx_rates(sta);
3211 spin_unlock_bh(&ap->sta_table_lock);
3215 void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3216 struct lib80211_crypt_data ***crypt)
3218 struct sta_info *sta;
3220 spin_lock_bh(&ap->sta_table_lock);
3221 sta = ap_get_sta(ap, addr);
3223 atomic_inc(&sta->users);
3224 spin_unlock_bh(&ap->sta_table_lock);
3226 if (!sta && permanent)
3227 sta = ap_add_sta(ap, addr);
3233 sta->flags |= WLAN_STA_PERM;
3235 *crypt = &sta->crypt;
3241 void hostap_add_wds_links(local_info_t *local)
3243 struct ap_data *ap = local->ap;
3244 struct sta_info *sta;
3246 spin_lock_bh(&ap->sta_table_lock);
3247 list_for_each_entry(sta, &ap->sta_list, list) {
3249 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3251 spin_unlock_bh(&ap->sta_table_lock);
3253 schedule_work(&local->ap->wds_oper_queue);
3257 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3259 struct wds_oper_data *entry;
3261 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3264 memcpy(entry->addr, addr, ETH_ALEN);
3266 spin_lock_bh(&local->lock);
3267 entry->next = local->ap->wds_oper_entries;
3268 local->ap->wds_oper_entries = entry;
3269 spin_unlock_bh(&local->lock);
3271 schedule_work(&local->ap->wds_oper_queue);
3275 EXPORT_SYMBOL(hostap_init_data);
3276 EXPORT_SYMBOL(hostap_init_ap_proc);
3277 EXPORT_SYMBOL(hostap_free_data);
3278 EXPORT_SYMBOL(hostap_check_sta_fw_version);
3279 EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3280 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3281 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */