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 <jkmaline@cc.hut.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 static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
21 module_param_array(other_ap_policy, int, NULL, 0444);
22 MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
24 static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
26 module_param_array(ap_max_inactivity, int, NULL, 0444);
27 MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
30 static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
31 module_param_array(ap_bridge_packets, int, NULL, 0444);
32 MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
35 static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
36 module_param_array(autom_ap_wds, int, NULL, 0444);
37 MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
41 static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
42 static void hostap_event_expired_sta(struct net_device *dev,
43 struct sta_info *sta);
44 static void handle_add_proc_queue(void *data);
46 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
47 static void handle_wds_oper_queue(void *data);
48 static void prism2_send_mgmt(struct net_device *dev,
49 int type, int subtype, char *body,
50 int body_len, u8 *addr, u16 tx_cb_idx);
51 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
54 #ifndef PRISM2_NO_PROCFS_DEBUG
55 static int ap_debug_proc_read(char *page, char **start, off_t off,
56 int count, int *eof, void *data)
59 struct ap_data *ap = (struct ap_data *) data;
66 p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
67 p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
68 p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
69 p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
70 p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
71 p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
72 p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
73 p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
77 #endif /* PRISM2_NO_PROCFS_DEBUG */
80 static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
82 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
83 ap->sta_hash[STA_HASH(sta->addr)] = sta;
86 static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
90 s = ap->sta_hash[STA_HASH(sta->addr)];
91 if (s == NULL) return;
92 if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
93 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
97 while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
100 if (s->hnext != NULL)
101 s->hnext = s->hnext->hnext;
103 printk("AP: could not remove STA " MACSTR " from hash table\n",
107 static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
109 if (sta->ap && sta->local)
110 hostap_event_expired_sta(sta->local->dev, sta);
112 if (ap->proc != NULL) {
114 sprintf(name, MACSTR, MAC2STR(sta->addr));
115 remove_proc_entry(name, ap->proc);
119 sta->crypt->ops->deinit(sta->crypt->priv);
124 skb_queue_purge(&sta->tx_buf);
127 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
129 ap->sta_aid[sta->aid - 1] = NULL;
131 if (!sta->ap && sta->u.sta.challenge)
132 kfree(sta->u.sta.challenge);
133 del_timer(&sta->timer);
134 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
140 static void hostap_set_tim(local_info_t *local, int aid, int set)
142 if (local->func->set_tim)
143 local->func->set_tim(local->dev, aid, set);
147 static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
149 union iwreq_data wrqu;
150 memset(&wrqu, 0, sizeof(wrqu));
151 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
152 wrqu.addr.sa_family = ARPHRD_ETHER;
153 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
157 static void hostap_event_expired_sta(struct net_device *dev,
158 struct sta_info *sta)
160 union iwreq_data wrqu;
161 memset(&wrqu, 0, sizeof(wrqu));
162 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
163 wrqu.addr.sa_family = ARPHRD_ETHER;
164 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
168 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
170 static void ap_handle_timer(unsigned long data)
172 struct sta_info *sta = (struct sta_info *) data;
175 unsigned long next_time = 0;
178 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
179 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
185 was_assoc = sta->flags & WLAN_STA_ASSOC;
187 if (atomic_read(&sta->users) != 0)
188 next_time = jiffies + HZ;
189 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
190 next_time = jiffies + ap->max_inactivity;
192 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
193 /* station activity detected; reset timeout state */
194 sta->timeout_next = STA_NULLFUNC;
195 next_time = sta->last_rx + ap->max_inactivity;
196 } else if (sta->timeout_next == STA_DISASSOC &&
197 !(sta->flags & WLAN_STA_PENDING_POLL)) {
198 /* STA ACKed data nullfunc frame poll */
199 sta->timeout_next = STA_NULLFUNC;
200 next_time = jiffies + ap->max_inactivity;
204 sta->timer.expires = next_time;
205 add_timer(&sta->timer);
210 sta->timeout_next = STA_DEAUTH;
212 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
213 spin_lock(&ap->sta_table_lock);
214 ap_sta_hash_del(ap, sta);
215 list_del(&sta->list);
216 spin_unlock(&ap->sta_table_lock);
217 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
218 } else if (sta->timeout_next == STA_DISASSOC)
219 sta->flags &= ~WLAN_STA_ASSOC;
221 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
222 hostap_event_expired_sta(local->dev, sta);
224 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
225 !skb_queue_empty(&sta->tx_buf)) {
226 hostap_set_tim(local, sta->aid, 0);
227 sta->flags &= ~WLAN_STA_TIM;
231 if (ap->autom_ap_wds) {
232 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
233 "connection to AP " MACSTR "\n",
234 local->dev->name, MAC2STR(sta->addr));
235 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
237 } else if (sta->timeout_next == STA_NULLFUNC) {
238 /* send data frame to poll STA and check whether this frame
240 /* FIX: WLAN_FC_STYPE_NULLFUNC would be more appropriate, but
241 * it is apparently not retried so TX Exc events are not
243 sta->flags |= WLAN_STA_PENDING_POLL;
244 prism2_send_mgmt(local->dev, WLAN_FC_TYPE_DATA,
245 WLAN_FC_STYPE_DATA, NULL, 0,
246 sta->addr, ap->tx_callback_poll);
248 int deauth = sta->timeout_next == STA_DEAUTH;
250 PDEBUG(DEBUG_AP, "%s: sending %s info to STA " MACSTR
251 "(last=%lu, jiffies=%lu)\n",
253 deauth ? "deauthentication" : "disassociation",
254 MAC2STR(sta->addr), sta->last_rx, jiffies);
256 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
257 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
258 prism2_send_mgmt(local->dev, WLAN_FC_TYPE_MGMT,
259 (deauth ? WLAN_FC_STYPE_DEAUTH :
260 WLAN_FC_STYPE_DISASSOC),
261 (char *) &resp, 2, sta->addr, 0);
264 if (sta->timeout_next == STA_DEAUTH) {
265 if (sta->flags & WLAN_STA_PERM) {
266 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " would have been "
267 "removed, but it has 'perm' flag\n",
268 local->dev->name, MAC2STR(sta->addr));
270 ap_free_sta(ap, sta);
274 if (sta->timeout_next == STA_NULLFUNC) {
275 sta->timeout_next = STA_DISASSOC;
276 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
278 sta->timeout_next = STA_DEAUTH;
279 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
282 add_timer(&sta->timer);
286 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
293 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
294 memset(addr, 0xff, ETH_ALEN);
296 resp = __constant_cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
298 /* deauth message sent; try to resend it few times; the message is
299 * broadcast, so it may be delayed until next DTIM; there is not much
300 * else we can do at this point since the driver is going to be shut
302 for (i = 0; i < 5; i++) {
303 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH,
304 (char *) &resp, 2, addr, 0);
306 if (!resend || ap->num_sta <= 0)
314 static int ap_control_proc_read(char *page, char **start, off_t off,
315 int count, int *eof, void *data)
318 struct ap_data *ap = (struct ap_data *) data;
320 struct list_head *ptr;
321 struct mac_entry *entry;
328 switch (ap->mac_restrictions.policy) {
329 case MAC_POLICY_OPEN:
332 case MAC_POLICY_ALLOW:
333 policy_txt = "allow";
335 case MAC_POLICY_DENY:
339 policy_txt = "unknown";
342 p += sprintf(p, "MAC policy: %s\n", policy_txt);
343 p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
344 p += sprintf(p, "MAC list:\n");
345 spin_lock_bh(&ap->mac_restrictions.lock);
346 for (ptr = ap->mac_restrictions.mac_list.next;
347 ptr != &ap->mac_restrictions.mac_list; ptr = ptr->next) {
348 if (p - page > PAGE_SIZE - 80) {
349 p += sprintf(p, "All entries did not fit one page.\n");
353 entry = list_entry(ptr, struct mac_entry, list);
354 p += sprintf(p, MACSTR "\n", MAC2STR(entry->addr));
356 spin_unlock_bh(&ap->mac_restrictions.lock);
362 static int ap_control_add_mac(struct mac_restrictions *mac_restrictions,
365 struct mac_entry *entry;
367 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
371 memcpy(entry->addr, mac, ETH_ALEN);
373 spin_lock_bh(&mac_restrictions->lock);
374 list_add_tail(&entry->list, &mac_restrictions->mac_list);
375 mac_restrictions->entries++;
376 spin_unlock_bh(&mac_restrictions->lock);
382 static int ap_control_del_mac(struct mac_restrictions *mac_restrictions,
385 struct list_head *ptr;
386 struct mac_entry *entry;
388 spin_lock_bh(&mac_restrictions->lock);
389 for (ptr = mac_restrictions->mac_list.next;
390 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
391 entry = list_entry(ptr, struct mac_entry, list);
393 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
396 mac_restrictions->entries--;
397 spin_unlock_bh(&mac_restrictions->lock);
401 spin_unlock_bh(&mac_restrictions->lock);
406 static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
409 struct list_head *ptr;
410 struct mac_entry *entry;
413 if (mac_restrictions->policy == MAC_POLICY_OPEN)
416 spin_lock_bh(&mac_restrictions->lock);
417 for (ptr = mac_restrictions->mac_list.next;
418 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
419 entry = list_entry(ptr, struct mac_entry, list);
421 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
426 spin_unlock_bh(&mac_restrictions->lock);
428 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
435 static void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
437 struct list_head *ptr, *n;
438 struct mac_entry *entry;
440 if (mac_restrictions->entries == 0)
443 spin_lock_bh(&mac_restrictions->lock);
444 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
445 ptr != &mac_restrictions->mac_list;
446 ptr = n, n = ptr->next) {
447 entry = list_entry(ptr, struct mac_entry, list);
451 mac_restrictions->entries = 0;
452 spin_unlock_bh(&mac_restrictions->lock);
456 static int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev,
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, WLAN_FC_TYPE_MGMT, WLAN_FC_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 static 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 list_head *ptr;
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 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
527 struct sta_info *sta = (struct sta_info *) ptr;
532 p += sprintf(p, MACSTR " %d %d %d %d '", MAC2STR(sta->addr),
533 sta->u.ap.channel, sta->last_rx_signal,
534 sta->last_rx_silence, sta->last_rx_rate);
535 for (i = 0; i < sta->u.ap.ssid_len; i++)
536 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
537 sta->u.ap.ssid[i] < 127) ?
540 p += sprintf(p, "'");
541 if (sta->capability & WLAN_CAPABILITY_ESS)
542 p += sprintf(p, " [ESS]");
543 if (sta->capability & WLAN_CAPABILITY_IBSS)
544 p += sprintf(p, " [IBSS]");
545 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
546 p += sprintf(p, " [WEP]");
547 p += sprintf(p, "\n");
549 if ((p - page) > PROC_LIMIT) {
550 printk(KERN_DEBUG "hostap: ap proc did not fit\n");
554 spin_unlock_bh(&ap->sta_table_lock);
556 if ((p - page) <= off) {
563 return (p - page - off);
565 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
568 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
573 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
574 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
575 "firmware upgrade recommended\n");
576 ap->nullfunc_ack = 1;
578 ap->nullfunc_ack = 0;
580 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
581 printk(KERN_WARNING "%s: Warning: secondary station firmware "
582 "version 1.4.2 does not seem to work in Host AP mode\n",
583 ap->local->dev->name);
588 /* Called only as a tasklet (software IRQ) */
589 static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
591 struct ap_data *ap = data;
593 struct ieee80211_hdr *hdr;
595 if (!ap->local->hostapd || !ap->local->apdev) {
600 hdr = (struct ieee80211_hdr *) skb->data;
601 fc = le16_to_cpu(hdr->frame_ctl);
603 /* Pass the TX callback frame to the hostapd; use 802.11 header version
604 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
607 fc |= ok ? BIT(1) : BIT(0);
608 hdr->frame_ctl = cpu_to_le16(fc);
610 skb->dev = ap->local->apdev;
611 skb_pull(skb, hostap_80211_get_hdrlen(fc));
612 skb->pkt_type = PACKET_OTHERHOST;
613 skb->protocol = __constant_htons(ETH_P_802_2);
614 memset(skb->cb, 0, sizeof(skb->cb));
619 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
620 /* Called only as a tasklet (software IRQ) */
621 static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
623 struct ap_data *ap = data;
624 struct net_device *dev = ap->local->dev;
625 struct ieee80211_hdr *hdr;
626 u16 fc, *pos, auth_alg, auth_transaction, status;
627 struct sta_info *sta = NULL;
630 if (ap->local->hostapd) {
635 hdr = (struct ieee80211_hdr *) skb->data;
636 fc = le16_to_cpu(hdr->frame_ctl);
637 if (HOSTAP_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
638 HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_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 = (u16 *) (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: " MACSTR " auth_cb - alg=%d trans#=%d "
682 dev->name, MAC2STR(hdr->addr1), auth_alg,
683 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 *hdr;
695 u16 fc, *pos, status;
696 struct sta_info *sta = NULL;
699 if (ap->local->hostapd) {
704 hdr = (struct ieee80211_hdr *) skb->data;
705 fc = le16_to_cpu(hdr->frame_ctl);
706 if (HOSTAP_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
707 (HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ASSOC_RESP &&
708 HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_STYPE_REASSOC_RESP) ||
709 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
710 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
711 "frame\n", dev->name);
717 txt = "frame was not ACKed";
721 spin_lock(&ap->sta_table_lock);
722 sta = ap_get_sta(ap, hdr->addr1);
724 atomic_inc(&sta->users);
725 spin_unlock(&ap->sta_table_lock);
728 txt = "STA not found";
732 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
734 status = le16_to_cpu(*pos++);
735 if (status == WLAN_STATUS_SUCCESS) {
736 if (!(sta->flags & WLAN_STA_ASSOC))
737 hostap_event_new_sta(dev, sta);
738 txt = "STA associated";
739 sta->flags |= WLAN_STA_ASSOC;
740 sta->last_assoc = jiffies;
742 txt = "association failed";
746 atomic_dec(&sta->users);
748 PDEBUG(DEBUG_AP, "%s: " MACSTR " assoc_cb - %s\n",
749 dev->name, MAC2STR(hdr->addr1), txt);
754 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
755 * in verifying whether the STA is still present. */
756 static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
758 struct ap_data *ap = data;
759 struct ieee80211_hdr *hdr;
760 struct sta_info *sta;
764 hdr = (struct ieee80211_hdr *) skb->data;
766 spin_lock(&ap->sta_table_lock);
767 sta = ap_get_sta(ap, hdr->addr1);
769 sta->flags &= ~WLAN_STA_PENDING_POLL;
770 spin_unlock(&ap->sta_table_lock);
772 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " did not ACK activity "
773 "poll frame\n", ap->local->dev->name,
774 MAC2STR(hdr->addr1));
780 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
783 void hostap_init_data(local_info_t *local)
785 struct ap_data *ap = local->ap;
788 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
791 memset(ap, 0, sizeof(struct ap_data));
794 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
795 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
797 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
798 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
800 spin_lock_init(&ap->sta_table_lock);
801 INIT_LIST_HEAD(&ap->sta_list);
803 /* Initialize task queue structure for AP management */
804 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue, ap);
806 ap->tx_callback_idx =
807 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
808 if (ap->tx_callback_idx == 0)
809 printk(KERN_WARNING "%s: failed to register TX callback for "
810 "AP\n", local->dev->name);
811 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
812 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue, local);
814 ap->tx_callback_auth =
815 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
816 ap->tx_callback_assoc =
817 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
818 ap->tx_callback_poll =
819 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
820 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
821 ap->tx_callback_poll == 0)
822 printk(KERN_WARNING "%s: failed to register TX callback for "
823 "AP\n", local->dev->name);
825 spin_lock_init(&ap->mac_restrictions.lock);
826 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
827 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
833 void hostap_init_ap_proc(local_info_t *local)
835 struct ap_data *ap = local->ap;
837 ap->proc = local->proc;
838 if (ap->proc == NULL)
841 #ifndef PRISM2_NO_PROCFS_DEBUG
842 create_proc_read_entry("ap_debug", 0, ap->proc,
843 ap_debug_proc_read, ap);
844 #endif /* PRISM2_NO_PROCFS_DEBUG */
846 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
847 create_proc_read_entry("ap_control", 0, ap->proc,
848 ap_control_proc_read, ap);
849 create_proc_read_entry("ap", 0, ap->proc,
850 prism2_ap_proc_read, ap);
851 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
856 void hostap_free_data(struct ap_data *ap)
858 struct list_head *n, *ptr;
860 if (ap == NULL || !ap->initialized) {
861 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
862 "initialized - skip resource freeing\n");
866 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
868 ap->crypt->deinit(ap->crypt_priv);
869 ap->crypt = ap->crypt_priv = NULL;
870 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
872 list_for_each_safe(ptr, n, &ap->sta_list) {
873 struct sta_info *sta = list_entry(ptr, struct sta_info, 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 int type, int subtype, char *body,
916 int body_len, u8 *addr, u16 tx_cb_idx)
918 struct hostap_interface *iface;
920 struct ieee80211_hdr *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 "
944 fc = (type << 2) | (subtype << 4);
945 hdrlen = hostap_80211_get_hdrlen(fc);
946 hdr = (struct ieee80211_hdr *) 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 (type == WLAN_FC_TYPE_DATA) {
958 fc |= WLAN_FC_FROMDS;
959 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
960 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
961 } else if (type == WLAN_FC_TYPE_CTRL) {
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->mac.raw = skb->nh.raw = skb->data;
982 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
985 static int prism2_sta_proc_read(char *page, char **start, off_t off,
986 int count, int *eof, void *data)
989 struct sta_info *sta = (struct sta_info *) data;
992 /* FIX: possible race condition.. the STA data could have just expired,
993 * but proc entry was still here so that the read could have started;
994 * some locking should be done here.. */
1001 p += sprintf(p, "%s=" MACSTR "\nusers=%d\naid=%d\n"
1002 "flags=0x%04x%s%s%s%s%s%s%s\n"
1003 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1004 sta->ap ? "AP" : "STA",
1005 MAC2STR(sta->addr), atomic_read(&sta->users), sta->aid,
1007 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1008 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1009 sta->flags & WLAN_STA_PS ? " PS" : "",
1010 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1011 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1012 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1013 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1014 sta->capability, sta->listen_interval);
1015 /* supported_rates: 500 kbit/s units with msb ignored */
1016 for (i = 0; i < sizeof(sta->supported_rates); i++)
1017 if (sta->supported_rates[i] != 0)
1018 p += sprintf(p, "%d%sMbps ",
1019 (sta->supported_rates[i] & 0x7f) / 2,
1020 sta->supported_rates[i] & 1 ? ".5" : "");
1021 p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1022 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1024 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1025 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1026 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1028 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1029 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1031 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1032 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1033 sta->last_rx_silence,
1034 sta->last_rx_signal, sta->last_rx_rate / 10,
1035 sta->last_rx_rate % 10 ? ".5" : "",
1036 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1037 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1038 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1039 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1040 p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
1041 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1043 if (sta->u.ap.channel >= 0)
1044 p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
1045 p += sprintf(p, "ssid=");
1046 for (i = 0; i < sta->u.ap.ssid_len; i++)
1047 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
1048 sta->u.ap.ssid[i] < 127) ?
1051 p += sprintf(p, "\n");
1053 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1059 static void handle_add_proc_queue(void *data)
1061 struct ap_data *ap = (struct ap_data *) data;
1062 struct sta_info *sta;
1064 struct add_sta_proc_data *entry, *prev;
1066 entry = ap->add_sta_proc_entries;
1067 ap->add_sta_proc_entries = NULL;
1070 spin_lock_bh(&ap->sta_table_lock);
1071 sta = ap_get_sta(ap, entry->addr);
1073 atomic_inc(&sta->users);
1074 spin_unlock_bh(&ap->sta_table_lock);
1077 sprintf(name, MACSTR, MAC2STR(sta->addr));
1078 sta->proc = create_proc_read_entry(
1080 prism2_sta_proc_read, sta);
1082 atomic_dec(&sta->users);
1086 entry = entry->next;
1092 static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1094 struct sta_info *sta;
1096 sta = (struct sta_info *)
1097 kmalloc(sizeof(struct sta_info), GFP_ATOMIC);
1099 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1103 /* initialize STA info data */
1104 memset(sta, 0, sizeof(struct sta_info));
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 = ieee80211_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 "ieee80211_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 = (char *) 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_prefix_len +
1259 ap->crypt->extra_postfix_len);
1265 skb_reserve(skb, ap->crypt->extra_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 memcpy(tmpbuf, skb->data + ap->crypt->extra_prefix_len,
1275 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 *hdr = (struct ieee80211_hdr *) 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, *pos;
1293 u16 resp = WLAN_STATUS_SUCCESS, fc;
1294 struct sta_info *sta = NULL;
1295 struct ieee80211_crypt_data *crypt;
1298 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1300 fc = le16_to_cpu(hdr->frame_ctl);
1301 hdrlen = hostap_80211_get_hdrlen(fc);
1304 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1305 "(len=%d) from " MACSTR "\n", dev->name, len,
1306 MAC2STR(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[idx];
1325 pos = (u16 *) (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 " MACSTR " is now STA\n",
1372 dev->name, MAC2STR(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 & WLAN_FC_ISWEP)) {
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;
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, WLAN_FC_TYPE_MGMT, WLAN_FC_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: " MACSTR " auth (alg=%d trans#=%d "
1488 "stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1489 dev->name, MAC2STR(hdr->addr2), auth_alg,
1490 auth_transaction, status_code, len, fc, resp, txt);
1495 /* Called only as a scheduled task for pending AP frames. */
1496 static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1497 struct hostap_80211_rx_status *rx_stats, int reassoc)
1499 struct net_device *dev = local->dev;
1500 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1501 char body[12], *p, *lpos;
1504 u16 resp = WLAN_STATUS_SUCCESS;
1505 struct sta_info *sta = NULL;
1506 int send_deauth = 0;
1508 u8 prev_ap[ETH_ALEN];
1510 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1512 if (len < (reassoc ? 10 : 4)) {
1513 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1514 "(len=%d, reassoc=%d) from " MACSTR "\n",
1515 dev->name, len, reassoc, MAC2STR(hdr->addr2));
1519 spin_lock_bh(&local->ap->sta_table_lock);
1520 sta = ap_get_sta(local->ap, hdr->addr2);
1521 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1522 spin_unlock_bh(&local->ap->sta_table_lock);
1523 txt = "trying to associate before authentication";
1525 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1526 sta = NULL; /* do not decrement sta->users */
1529 atomic_inc(&sta->users);
1530 spin_unlock_bh(&local->ap->sta_table_lock);
1532 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1533 sta->capability = __le16_to_cpu(*pos);
1535 sta->listen_interval = __le16_to_cpu(*pos);
1539 memcpy(prev_ap, pos, ETH_ALEN);
1540 pos++; pos++; pos++; left -= 6;
1542 memset(prev_ap, 0, ETH_ALEN);
1546 unsigned char *u = (unsigned char *) pos;
1548 if (*u == WLAN_EID_SSID) {
1553 if (ileft > left || ileft > MAX_SSID_LEN) {
1554 txt = "SSID overflow";
1555 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1559 if (ileft != strlen(local->essid) ||
1560 memcmp(local->essid, u, ileft) != 0) {
1561 txt = "not our SSID";
1562 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1570 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1575 if (ileft > left || ileft == 0 ||
1576 ileft > WLAN_SUPP_RATES_MAX) {
1577 txt = "SUPP_RATES len error";
1578 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1582 memset(sta->supported_rates, 0,
1583 sizeof(sta->supported_rates));
1584 memcpy(sta->supported_rates, u, ileft);
1585 prism2_check_tx_rates(sta);
1592 PDEBUG(DEBUG_AP, "%s: assoc from " MACSTR " with extra"
1593 " data (%d bytes) [",
1594 dev->name, MAC2STR(hdr->addr2), left);
1596 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1599 PDEBUG2(DEBUG_AP, "]\n");
1602 txt = "frame underflow";
1603 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1607 /* get a unique AID */
1609 txt = "OK, old AID";
1611 spin_lock_bh(&local->ap->sta_table_lock);
1612 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1613 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1615 if (sta->aid > MAX_AID_TABLE_SIZE) {
1617 spin_unlock_bh(&local->ap->sta_table_lock);
1618 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1619 txt = "no room for more AIDs";
1621 local->ap->sta_aid[sta->aid - 1] = sta;
1622 spin_unlock_bh(&local->ap->sta_table_lock);
1623 txt = "OK, new AID";
1631 *pos = __constant_cpu_to_le16(
1632 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 = __constant_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, WLAN_FC_TYPE_MGMT,
1677 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1678 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1679 WLAN_FC_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: " MACSTR " %sassoc (len=%d prev_ap=" MACSTR
1695 ") => %d(%d) (%s)\n",
1696 dev->name, MAC2STR(hdr->addr2), reassoc ? "re" : "", len,
1697 MAC2STR(prev_ap), resp, send_deauth, txt);
1702 /* Called only as a scheduled task for pending AP frames. */
1703 static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1704 struct hostap_80211_rx_status *rx_stats)
1706 struct net_device *dev = local->dev;
1707 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1708 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1710 u16 reason_code, *pos;
1711 struct sta_info *sta = NULL;
1713 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1716 printk("handle_deauth - too short payload (len=%d)\n", len);
1721 reason_code = __le16_to_cpu(*pos);
1723 PDEBUG(DEBUG_AP, "%s: deauthentication: " MACSTR " len=%d, "
1724 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1727 spin_lock_bh(&local->ap->sta_table_lock);
1728 sta = ap_get_sta(local->ap, hdr->addr2);
1730 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1731 hostap_event_expired_sta(local->dev, sta);
1732 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1734 spin_unlock_bh(&local->ap->sta_table_lock);
1736 printk("%s: deauthentication from " MACSTR ", "
1737 "reason_code=%d, but STA not authenticated\n", dev->name,
1738 MAC2STR(hdr->addr2), reason_code);
1743 /* Called only as a scheduled task for pending AP frames. */
1744 static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1745 struct hostap_80211_rx_status *rx_stats)
1747 struct net_device *dev = local->dev;
1748 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1749 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1751 u16 reason_code, *pos;
1752 struct sta_info *sta = NULL;
1754 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1757 printk("handle_disassoc - too short payload (len=%d)\n", len);
1762 reason_code = __le16_to_cpu(*pos);
1764 PDEBUG(DEBUG_AP, "%s: disassociation: " MACSTR " len=%d, "
1765 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1768 spin_lock_bh(&local->ap->sta_table_lock);
1769 sta = ap_get_sta(local->ap, hdr->addr2);
1771 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1772 hostap_event_expired_sta(local->dev, sta);
1773 sta->flags &= ~WLAN_STA_ASSOC;
1775 spin_unlock_bh(&local->ap->sta_table_lock);
1777 printk("%s: disassociation from " MACSTR ", "
1778 "reason_code=%d, but STA not authenticated\n",
1779 dev->name, MAC2STR(hdr->addr2), reason_code);
1784 /* Called only as a scheduled task for pending AP frames. */
1785 static void ap_handle_data_nullfunc(local_info_t *local,
1786 struct ieee80211_hdr *hdr)
1788 struct net_device *dev = local->dev;
1790 /* some STA f/w's seem to require control::ACK frame for
1791 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1793 * send control::ACK for the data::nullfunc */
1795 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1796 prism2_send_mgmt(dev, WLAN_FC_TYPE_CTRL, WLAN_FC_STYPE_ACK,
1797 NULL, 0, hdr->addr2, 0);
1801 /* Called only as a scheduled task for pending AP frames. */
1802 static void ap_handle_dropped_data(local_info_t *local,
1803 struct ieee80211_hdr *hdr)
1805 struct net_device *dev = local->dev;
1806 struct sta_info *sta;
1809 spin_lock_bh(&local->ap->sta_table_lock);
1810 sta = ap_get_sta(local->ap, hdr->addr2);
1812 atomic_inc(&sta->users);
1813 spin_unlock_bh(&local->ap->sta_table_lock);
1815 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1816 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1817 atomic_dec(&sta->users);
1821 reason = __constant_cpu_to_le16(
1822 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1823 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT,
1824 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1825 WLAN_FC_STYPE_DEAUTH : WLAN_FC_STYPE_DISASSOC),
1826 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1829 atomic_dec(&sta->users);
1832 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1835 /* Called only as a scheduled task for pending AP frames. */
1836 static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1837 struct sk_buff *skb)
1839 struct hostap_skb_tx_data *meta;
1841 if (!(sta->flags & WLAN_STA_PS)) {
1842 /* Station has moved to non-PS mode, so send all buffered
1843 * frames using normal device queue. */
1844 dev_queue_xmit(skb);
1848 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1849 * be passed through even though STA is using PS */
1850 meta = (struct hostap_skb_tx_data *) skb->cb;
1851 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
1852 if (!skb_queue_empty(&sta->tx_buf)) {
1853 /* indicate to STA that more frames follow */
1854 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
1856 dev_queue_xmit(skb);
1860 /* Called only as a scheduled task for pending AP frames. */
1861 static void handle_pspoll(local_info_t *local,
1862 struct ieee80211_hdr *hdr,
1863 struct hostap_80211_rx_status *rx_stats)
1865 struct net_device *dev = local->dev;
1866 struct sta_info *sta;
1868 struct sk_buff *skb;
1870 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=" MACSTR ", TA=" MACSTR
1872 MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
1873 !!(le16_to_cpu(hdr->frame_ctl) & WLAN_FC_PWRMGT));
1875 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
1876 PDEBUG(DEBUG_AP, "handle_pspoll - addr1(BSSID)=" MACSTR
1877 " not own MAC\n", MAC2STR(hdr->addr1));
1881 aid = __le16_to_cpu(hdr->duration_id);
1882 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1883 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1886 aid &= ~BIT(15) & ~BIT(14);
1887 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1888 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1891 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1893 spin_lock_bh(&local->ap->sta_table_lock);
1894 sta = ap_get_sta(local->ap, hdr->addr2);
1896 atomic_inc(&sta->users);
1897 spin_unlock_bh(&local->ap->sta_table_lock);
1900 PDEBUG(DEBUG_PS, " STA not found\n");
1903 if (sta->aid != aid) {
1904 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1905 "assoc.aid=%d\n", aid, sta->aid);
1910 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1911 * out (expiry time must be longer than ListenInterval for
1912 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1913 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1914 * sta; store buffer for later use and leave TIM aid bit set? use
1915 * TX event to check whether frame was ACKed?
1918 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1919 /* send buffered frame .. */
1920 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1921 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1923 pspoll_send_buffered(local, sta, skb);
1925 if (sta->flags & WLAN_STA_PS) {
1926 /* send only one buffered packet per PS Poll */
1927 /* FIX: should ignore further PS Polls until the
1928 * buffered packet that was just sent is acknowledged
1929 * (Tx or TxExc event) */
1934 if (skb_queue_empty(&sta->tx_buf)) {
1935 /* try to clear aid from TIM */
1936 if (!(sta->flags & WLAN_STA_TIM))
1937 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1939 hostap_set_tim(local, aid, 0);
1940 sta->flags &= ~WLAN_STA_TIM;
1943 atomic_dec(&sta->users);
1947 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1949 static void handle_wds_oper_queue(void *data)
1951 local_info_t *local = data;
1952 struct wds_oper_data *entry, *prev;
1954 spin_lock_bh(&local->lock);
1955 entry = local->ap->wds_oper_entries;
1956 local->ap->wds_oper_entries = NULL;
1957 spin_unlock_bh(&local->lock);
1960 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
1961 "to AP " MACSTR "\n",
1963 entry->type == WDS_ADD ? "adding" : "removing",
1964 MAC2STR(entry->addr));
1965 if (entry->type == WDS_ADD)
1966 prism2_wds_add(local, entry->addr, 0);
1967 else if (entry->type == WDS_DEL)
1968 prism2_wds_del(local, entry->addr, 0, 1);
1971 entry = entry->next;
1977 /* Called only as a scheduled task for pending AP frames. */
1978 static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1979 struct hostap_80211_rx_status *rx_stats)
1981 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1982 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1984 u16 *pos, beacon_int, capability;
1986 unsigned char *supp_rates = NULL;
1987 int ssid_len = 0, supp_rates_len = 0;
1988 struct sta_info *sta = NULL;
1989 int new_sta = 0, channel = -1;
1991 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1993 if (len < 8 + 2 + 2) {
1994 printk(KERN_DEBUG "handle_beacon - too short payload "
2002 /* Timestamp (8 octets) */
2003 pos += 4; left -= 8;
2004 /* Beacon interval (2 octets) */
2005 beacon_int = __le16_to_cpu(*pos);
2007 /* Capability information (2 octets) */
2008 capability = __le16_to_cpu(*pos);
2011 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2012 capability & WLAN_CAPABILITY_IBSS)
2017 unsigned char *u = (unsigned char *) pos;
2019 if (*u == WLAN_EID_SSID) {
2024 if (ileft > left || ileft > MAX_SSID_LEN) {
2025 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2029 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2030 (ileft != strlen(local->essid) ||
2031 memcmp(local->essid, u, ileft) != 0)) {
2043 if (*u == WLAN_EID_SUPP_RATES) {
2048 if (ileft > left || ileft == 0 || ileft > 8) {
2049 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2054 supp_rates_len = ileft;
2060 if (*u == WLAN_EID_DS_PARAMS) {
2065 if (ileft > left || ileft != 1) {
2066 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2077 spin_lock_bh(&local->ap->sta_table_lock);
2078 sta = ap_get_sta(local->ap, hdr->addr2);
2080 atomic_inc(&sta->users);
2081 spin_unlock_bh(&local->ap->sta_table_lock);
2086 sta = ap_add_sta(local->ap, hdr->addr2);
2088 printk(KERN_INFO "prism2: kmalloc failed for AP "
2089 "data structure\n");
2092 hostap_event_new_sta(local->dev, sta);
2094 /* mark APs authentication and associated for pseudo ad-hoc
2095 * style communication */
2096 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2098 if (local->ap->autom_ap_wds) {
2099 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2105 sta->u.ap.ssid_len = ssid_len;
2106 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2107 sta->u.ap.ssid[ssid_len] = '\0';
2109 sta->u.ap.ssid_len = 0;
2110 sta->u.ap.ssid[0] = '\0';
2112 sta->u.ap.channel = channel;
2114 sta->rx_bytes += len;
2115 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2116 sta->capability = capability;
2117 sta->listen_interval = beacon_int;
2119 atomic_dec(&sta->users);
2122 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2123 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2124 prism2_check_tx_rates(sta);
2128 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2131 /* Called only as a tasklet. */
2132 static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2133 struct hostap_80211_rx_status *rx_stats)
2135 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2136 struct net_device *dev = local->dev;
2137 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2138 u16 fc, type, stype;
2139 struct ieee80211_hdr *hdr;
2141 /* FIX: should give skb->len to handler functions and check that the
2142 * buffer is long enough */
2143 hdr = (struct ieee80211_hdr *) skb->data;
2144 fc = le16_to_cpu(hdr->frame_ctl);
2145 type = HOSTAP_FC_GET_TYPE(fc);
2146 stype = HOSTAP_FC_GET_STYPE(fc);
2148 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2149 if (!local->hostapd && type == WLAN_FC_TYPE_DATA) {
2150 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2152 if (!(fc & WLAN_FC_TODS) || (fc & WLAN_FC_FROMDS)) {
2153 if (stype == WLAN_FC_STYPE_NULLFUNC) {
2154 /* no ToDS nullfunc seems to be used to check
2155 * AP association; so send reject message to
2156 * speed up re-association */
2157 ap_handle_dropped_data(local, hdr);
2160 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2165 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2166 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)="
2167 MACSTR " not own MAC\n",
2168 MAC2STR(hdr->addr1));
2172 if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC)
2173 ap_handle_data_nullfunc(local, hdr);
2175 ap_handle_dropped_data(local, hdr);
2179 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_BEACON) {
2180 handle_beacon(local, skb, rx_stats);
2183 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2185 if (type == WLAN_FC_TYPE_CTRL && stype == WLAN_FC_STYPE_PSPOLL) {
2186 handle_pspoll(local, hdr, rx_stats);
2190 if (local->hostapd) {
2191 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2192 "subtype=0x%02x\n", type, stype);
2196 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2197 if (type != WLAN_FC_TYPE_MGMT) {
2198 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2202 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2203 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=" MACSTR
2204 " not own MAC\n", MAC2STR(hdr->addr1));
2208 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
2209 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=" MACSTR
2210 " not own MAC\n", MAC2STR(hdr->addr3));
2215 case WLAN_FC_STYPE_ASSOC_REQ:
2216 handle_assoc(local, skb, rx_stats, 0);
2218 case WLAN_FC_STYPE_ASSOC_RESP:
2219 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2221 case WLAN_FC_STYPE_REASSOC_REQ:
2222 handle_assoc(local, skb, rx_stats, 1);
2224 case WLAN_FC_STYPE_REASSOC_RESP:
2225 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2227 case WLAN_FC_STYPE_ATIM:
2228 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2230 case WLAN_FC_STYPE_DISASSOC:
2231 handle_disassoc(local, skb, rx_stats);
2233 case WLAN_FC_STYPE_AUTH:
2234 handle_authen(local, skb, rx_stats);
2236 case WLAN_FC_STYPE_DEAUTH:
2237 handle_deauth(local, skb, rx_stats);
2240 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n", stype);
2243 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2250 /* Called only as a tasklet (software IRQ) */
2251 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2252 struct hostap_80211_rx_status *rx_stats)
2254 struct hostap_interface *iface;
2255 local_info_t *local;
2257 struct ieee80211_hdr *hdr;
2259 iface = netdev_priv(dev);
2260 local = iface->local;
2265 local->stats.rx_packets++;
2267 hdr = (struct ieee80211_hdr *) skb->data;
2268 fc = le16_to_cpu(hdr->frame_ctl);
2270 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2271 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2272 HOSTAP_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2275 skb->protocol = __constant_htons(ETH_P_HOSTAP);
2276 handle_ap_item(local, skb, rx_stats);
2284 /* Called only as a tasklet (software IRQ) */
2285 static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2287 struct sk_buff *skb;
2288 struct ieee80211_hdr *hdr;
2289 struct hostap_80211_rx_status rx_stats;
2291 if (skb_queue_empty(&sta->tx_buf))
2294 skb = dev_alloc_skb(16);
2296 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2297 "failed\n", local->dev->name);
2301 hdr = (struct ieee80211_hdr *) skb_put(skb, 16);
2303 /* Generate a fake pspoll frame to start packet delivery */
2304 hdr->frame_ctl = __constant_cpu_to_le16(
2305 (WLAN_FC_TYPE_CTRL << 2) | (WLAN_FC_STYPE_PSPOLL << 4));
2306 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2307 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2308 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2310 PDEBUG(DEBUG_PS2, "%s: Scheduling buffered packet delivery for "
2311 "STA " MACSTR "\n", local->dev->name, MAC2STR(sta->addr));
2313 skb->dev = local->dev;
2315 memset(&rx_stats, 0, sizeof(rx_stats));
2316 hostap_rx(local->dev, skb, &rx_stats);
2320 static int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2321 struct iw_quality qual[], int buf_size,
2324 struct ap_data *ap = local->ap;
2325 struct list_head *ptr;
2328 spin_lock_bh(&ap->sta_table_lock);
2330 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2332 struct sta_info *sta = (struct sta_info *) ptr;
2334 if (aplist && !sta->ap)
2336 addr[count].sa_family = ARPHRD_ETHER;
2337 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2338 if (sta->last_rx_silence == 0)
2339 qual[count].qual = sta->last_rx_signal < 27 ?
2340 0 : (sta->last_rx_signal - 27) * 92 / 127;
2342 qual[count].qual = sta->last_rx_signal -
2343 sta->last_rx_silence - 35;
2344 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2345 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2346 qual[count].updated = sta->last_rx_updated;
2348 sta->last_rx_updated = 0;
2351 if (count >= buf_size)
2354 spin_unlock_bh(&ap->sta_table_lock);
2360 /* Translate our list of Access Points & Stations to a card independant
2361 * format that the Wireless Tools will understand - Jean II */
2362 static int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
2364 struct hostap_interface *iface;
2365 local_info_t *local;
2367 struct list_head *ptr;
2368 struct iw_event iwe;
2369 char *current_ev = buffer;
2370 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2371 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2375 iface = netdev_priv(dev);
2376 local = iface->local;
2379 spin_lock_bh(&ap->sta_table_lock);
2381 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2383 struct sta_info *sta = (struct sta_info *) ptr;
2385 /* First entry *MUST* be the AP MAC address */
2386 memset(&iwe, 0, sizeof(iwe));
2387 iwe.cmd = SIOCGIWAP;
2388 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2389 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2390 iwe.len = IW_EV_ADDR_LEN;
2391 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2394 /* Use the mode to indicate if it's a station or
2395 * an Access Point */
2396 memset(&iwe, 0, sizeof(iwe));
2397 iwe.cmd = SIOCGIWMODE;
2399 iwe.u.mode = IW_MODE_MASTER;
2401 iwe.u.mode = IW_MODE_INFRA;
2402 iwe.len = IW_EV_UINT_LEN;
2403 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2407 memset(&iwe, 0, sizeof(iwe));
2409 if (sta->last_rx_silence == 0)
2410 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2411 0 : (sta->last_rx_signal - 27) * 92 / 127;
2413 iwe.u.qual.qual = sta->last_rx_signal -
2414 sta->last_rx_silence - 35;
2415 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2416 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2417 iwe.u.qual.updated = sta->last_rx_updated;
2418 iwe.len = IW_EV_QUAL_LEN;
2419 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2422 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2424 memset(&iwe, 0, sizeof(iwe));
2425 iwe.cmd = SIOCGIWESSID;
2426 iwe.u.data.length = sta->u.ap.ssid_len;
2427 iwe.u.data.flags = 1;
2428 current_ev = iwe_stream_add_point(current_ev, end_buf,
2432 memset(&iwe, 0, sizeof(iwe));
2433 iwe.cmd = SIOCGIWENCODE;
2434 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2436 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2438 iwe.u.data.flags = IW_ENCODE_DISABLED;
2439 current_ev = iwe_stream_add_point(current_ev, end_buf,
2442 /* 0 byte memcpy */);
2444 if (sta->u.ap.channel > 0 &&
2445 sta->u.ap.channel <= FREQ_COUNT) {
2446 memset(&iwe, 0, sizeof(iwe));
2447 iwe.cmd = SIOCGIWFREQ;
2448 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2451 current_ev = iwe_stream_add_event(
2452 current_ev, end_buf, &iwe,
2456 memset(&iwe, 0, sizeof(iwe));
2457 iwe.cmd = IWEVCUSTOM;
2458 sprintf(buf, "beacon_interval=%d",
2459 sta->listen_interval);
2460 iwe.u.data.length = strlen(buf);
2461 current_ev = iwe_stream_add_point(current_ev, end_buf,
2464 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2466 sta->last_rx_updated = 0;
2468 /* To be continued, we should make good use of IWEVCUSTOM */
2471 spin_unlock_bh(&ap->sta_table_lock);
2473 return current_ev - buffer;
2477 static int prism2_hostapd_add_sta(struct ap_data *ap,
2478 struct prism2_hostapd_param *param)
2480 struct sta_info *sta;
2482 spin_lock_bh(&ap->sta_table_lock);
2483 sta = ap_get_sta(ap, param->sta_addr);
2485 atomic_inc(&sta->users);
2486 spin_unlock_bh(&ap->sta_table_lock);
2489 sta = ap_add_sta(ap, param->sta_addr);
2494 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2495 hostap_event_new_sta(sta->local->dev, sta);
2497 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2498 sta->last_rx = jiffies;
2499 sta->aid = param->u.add_sta.aid;
2500 sta->capability = param->u.add_sta.capability;
2501 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2502 if (sta->tx_supp_rates & WLAN_RATE_1M)
2503 sta->supported_rates[0] = 2;
2504 if (sta->tx_supp_rates & WLAN_RATE_2M)
2505 sta->supported_rates[1] = 4;
2506 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2507 sta->supported_rates[2] = 11;
2508 if (sta->tx_supp_rates & WLAN_RATE_11M)
2509 sta->supported_rates[3] = 22;
2510 prism2_check_tx_rates(sta);
2511 atomic_dec(&sta->users);
2516 static int prism2_hostapd_remove_sta(struct ap_data *ap,
2517 struct prism2_hostapd_param *param)
2519 struct sta_info *sta;
2521 spin_lock_bh(&ap->sta_table_lock);
2522 sta = ap_get_sta(ap, param->sta_addr);
2524 ap_sta_hash_del(ap, sta);
2525 list_del(&sta->list);
2527 spin_unlock_bh(&ap->sta_table_lock);
2532 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2533 hostap_event_expired_sta(sta->local->dev, sta);
2534 ap_free_sta(ap, sta);
2540 static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2541 struct prism2_hostapd_param *param)
2543 struct sta_info *sta;
2545 spin_lock_bh(&ap->sta_table_lock);
2546 sta = ap_get_sta(ap, param->sta_addr);
2548 atomic_inc(&sta->users);
2549 spin_unlock_bh(&ap->sta_table_lock);
2554 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2556 atomic_dec(&sta->users);
2562 static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2563 struct prism2_hostapd_param *param)
2565 struct sta_info *sta;
2567 spin_lock_bh(&ap->sta_table_lock);
2568 sta = ap_get_sta(ap, param->sta_addr);
2570 sta->flags |= param->u.set_flags_sta.flags_or;
2571 sta->flags &= param->u.set_flags_sta.flags_and;
2573 spin_unlock_bh(&ap->sta_table_lock);
2582 static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2583 struct prism2_hostapd_param *param)
2585 struct sta_info *sta;
2588 spin_lock_bh(&ap->sta_table_lock);
2589 sta = ap_get_sta(ap, param->sta_addr);
2591 sta->rx_packets = sta->tx_packets = 0;
2592 sta->rx_bytes = sta->tx_bytes = 0;
2593 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2594 sta->tx_count[rate] = 0;
2595 sta->rx_count[rate] = 0;
2598 spin_unlock_bh(&ap->sta_table_lock);
2607 static int prism2_hostapd(struct ap_data *ap,
2608 struct prism2_hostapd_param *param)
2610 switch (param->cmd) {
2611 case PRISM2_HOSTAPD_FLUSH:
2612 ap_control_kickall(ap);
2614 case PRISM2_HOSTAPD_ADD_STA:
2615 return prism2_hostapd_add_sta(ap, param);
2616 case PRISM2_HOSTAPD_REMOVE_STA:
2617 return prism2_hostapd_remove_sta(ap, param);
2618 case PRISM2_HOSTAPD_GET_INFO_STA:
2619 return prism2_hostapd_get_info_sta(ap, param);
2620 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2621 return prism2_hostapd_set_flags_sta(ap, param);
2622 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2623 return prism2_hostapd_sta_clear_stats(ap, param);
2625 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2632 /* Update station info for host-based TX rate control and return current
2634 static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2636 int ret = sta->tx_rate;
2637 struct hostap_interface *iface;
2638 local_info_t *local;
2640 iface = netdev_priv(dev);
2641 local = iface->local;
2643 sta->tx_count[sta->tx_rate_idx]++;
2644 sta->tx_since_last_failure++;
2645 sta->tx_consecutive_exc = 0;
2646 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2647 sta->tx_rate_idx < sta->tx_max_rate) {
2648 /* use next higher rate */
2649 int old_rate, new_rate;
2650 old_rate = new_rate = sta->tx_rate_idx;
2651 while (new_rate < sta->tx_max_rate) {
2653 if (ap_tx_rate_ok(new_rate, sta, local)) {
2654 sta->tx_rate_idx = new_rate;
2658 if (old_rate != sta->tx_rate_idx) {
2659 switch (sta->tx_rate_idx) {
2660 case 0: sta->tx_rate = 10; break;
2661 case 1: sta->tx_rate = 20; break;
2662 case 2: sta->tx_rate = 55; break;
2663 case 3: sta->tx_rate = 110; break;
2664 default: sta->tx_rate = 0; break;
2666 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate raised to"
2667 " %d\n", dev->name, MAC2STR(sta->addr),
2670 sta->tx_since_last_failure = 0;
2677 /* Called only from software IRQ. Called for each TX frame prior possible
2678 * encryption and transmit. */
2679 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2681 struct sta_info *sta = NULL;
2682 struct sk_buff *skb = tx->skb;
2684 struct ieee80211_hdr *hdr;
2685 struct hostap_skb_tx_data *meta;
2687 meta = (struct hostap_skb_tx_data *) skb->cb;
2688 ret = AP_TX_CONTINUE;
2689 if (local->ap == NULL || skb->len < 10 ||
2690 meta->iface->type == HOSTAP_INTERFACE_STA)
2693 hdr = (struct ieee80211_hdr *) skb->data;
2695 if (hdr->addr1[0] & 0x01) {
2696 /* broadcast/multicast frame - no AP related processing */
2700 /* unicast packet - check whether destination STA is associated */
2701 spin_lock(&local->ap->sta_table_lock);
2702 sta = ap_get_sta(local->ap, hdr->addr1);
2704 atomic_inc(&sta->users);
2705 spin_unlock(&local->ap->sta_table_lock);
2707 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2708 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
2709 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2710 meta->iface->type != HOSTAP_INTERFACE_AP) {
2712 /* This can happen, e.g., when wlan0 is added to a bridge and
2713 * bridging code does not know which port is the correct target
2714 * for a unicast frame. In this case, the packet is send to all
2715 * ports of the bridge. Since this is a valid scenario, do not
2716 * print out any errors here. */
2717 if (net_ratelimit()) {
2718 printk(KERN_DEBUG "AP: drop packet to non-associated "
2719 "STA " MACSTR "\n", MAC2STR(hdr->addr1));
2722 local->ap->tx_drop_nonassoc++;
2730 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2731 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2733 /* Set tx_rate if using host-based TX rate control */
2734 if (!local->fw_tx_rate_control)
2735 local->ap->last_tx_rate = meta->rate =
2736 ap_update_sta_tx_rate(sta, local->dev);
2738 if (local->iw_mode != IW_MODE_MASTER)
2741 if (!(sta->flags & WLAN_STA_PS))
2744 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2745 /* indicate to STA that more frames follow */
2746 hdr->frame_ctl |= __constant_cpu_to_le16(WLAN_FC_MOREDATA);
2749 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2750 /* packet was already buffered and now send due to
2751 * PS poll, so do not rebuffer it */
2755 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2756 PDEBUG(DEBUG_PS, "%s: No more space in STA (" MACSTR ")'s PS "
2757 "mode buffer\n", local->dev->name, MAC2STR(sta->addr));
2758 /* Make sure that TIM is set for the station (it might not be
2759 * after AP wlan hw reset). */
2760 /* FIX: should fix hw reset to restore bits based on STA
2762 hostap_set_tim(local, sta->aid, 1);
2763 sta->flags |= WLAN_STA_TIM;
2768 /* STA in PS mode, buffer frame for later delivery */
2769 set_tim = skb_queue_empty(&sta->tx_buf);
2770 skb_queue_tail(&sta->tx_buf, skb);
2771 /* FIX: could save RX time to skb and expire buffered frames after
2772 * some time if STA does not poll for them */
2775 if (sta->flags & WLAN_STA_TIM)
2776 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2778 hostap_set_tim(local, sta->aid, 1);
2779 sta->flags |= WLAN_STA_TIM;
2782 ret = AP_TX_BUFFERED;
2786 if (ret == AP_TX_CONTINUE ||
2787 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2789 sta->tx_bytes += skb->len;
2790 sta->last_tx = jiffies;
2793 if ((ret == AP_TX_CONTINUE ||
2794 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2795 sta->crypt && tx->host_encrypt) {
2796 tx->crypt = sta->crypt;
2797 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2798 * be called to release sta info
2801 atomic_dec(&sta->users);
2808 void hostap_handle_sta_release(void *ptr)
2810 struct sta_info *sta = ptr;
2811 atomic_dec(&sta->users);
2815 /* Called only as a tasklet (software IRQ) */
2816 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2818 struct sta_info *sta;
2819 struct ieee80211_hdr *hdr;
2820 struct hostap_skb_tx_data *meta;
2822 hdr = (struct ieee80211_hdr *) skb->data;
2823 meta = (struct hostap_skb_tx_data *) skb->cb;
2825 spin_lock(&local->ap->sta_table_lock);
2826 sta = ap_get_sta(local->ap, hdr->addr1);
2828 spin_unlock(&local->ap->sta_table_lock);
2829 PDEBUG(DEBUG_AP, "%s: Could not find STA " MACSTR " for this "
2830 "TX error (@%lu)\n",
2831 local->dev->name, MAC2STR(hdr->addr1), jiffies);
2835 sta->tx_since_last_failure = 0;
2836 sta->tx_consecutive_exc++;
2838 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2839 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2840 /* use next lower rate */
2842 old = rate = sta->tx_rate_idx;
2845 if (ap_tx_rate_ok(rate, sta, local)) {
2846 sta->tx_rate_idx = rate;
2850 if (old != sta->tx_rate_idx) {
2851 switch (sta->tx_rate_idx) {
2852 case 0: sta->tx_rate = 10; break;
2853 case 1: sta->tx_rate = 20; break;
2854 case 2: sta->tx_rate = 55; break;
2855 case 3: sta->tx_rate = 110; break;
2856 default: sta->tx_rate = 0; break;
2858 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate lowered "
2859 "to %d\n", local->dev->name, MAC2STR(sta->addr),
2862 sta->tx_consecutive_exc = 0;
2864 spin_unlock(&local->ap->sta_table_lock);
2868 static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2869 int pwrmgt, int type, int stype)
2871 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2872 sta->flags |= WLAN_STA_PS;
2873 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to use PS "
2874 "mode (type=0x%02X, stype=0x%02X)\n",
2875 MAC2STR(sta->addr), type, stype);
2876 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2877 sta->flags &= ~WLAN_STA_PS;
2878 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to not use "
2879 "PS mode (type=0x%02X, stype=0x%02X)\n",
2880 MAC2STR(sta->addr), type, stype);
2881 if (type != WLAN_FC_TYPE_CTRL || stype != WLAN_FC_STYPE_PSPOLL)
2882 schedule_packet_send(local, sta);
2887 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2888 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
2889 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr)
2891 struct sta_info *sta;
2894 spin_lock(&local->ap->sta_table_lock);
2895 sta = ap_get_sta(local->ap, hdr->addr2);
2897 atomic_inc(&sta->users);
2898 spin_unlock(&local->ap->sta_table_lock);
2903 fc = le16_to_cpu(hdr->frame_ctl);
2904 hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
2905 HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc));
2907 atomic_dec(&sta->users);
2912 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2913 * getting RX header and payload from hardware. */
2914 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2915 struct sk_buff *skb,
2916 struct hostap_80211_rx_status *rx_stats,
2920 struct sta_info *sta;
2921 u16 fc, type, stype;
2922 struct ieee80211_hdr *hdr;
2924 if (local->ap == NULL)
2925 return AP_RX_CONTINUE;
2927 hdr = (struct ieee80211_hdr *) skb->data;
2929 fc = le16_to_cpu(hdr->frame_ctl);
2930 type = HOSTAP_FC_GET_TYPE(fc);
2931 stype = HOSTAP_FC_GET_STYPE(fc);
2933 spin_lock(&local->ap->sta_table_lock);
2934 sta = ap_get_sta(local->ap, hdr->addr2);
2936 atomic_inc(&sta->users);
2937 spin_unlock(&local->ap->sta_table_lock);
2939 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2940 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2942 ret = AP_RX_CONTINUE;
2945 if (fc & WLAN_FC_TODS) {
2946 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2947 if (local->hostapd) {
2948 prism2_rx_80211(local->apdev, skb, rx_stats,
2949 PRISM2_RX_NON_ASSOC);
2950 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2952 printk(KERN_DEBUG "%s: dropped received packet"
2953 " from non-associated STA " MACSTR
2954 " (type=0x%02x, subtype=0x%02x)\n",
2955 dev->name, MAC2STR(hdr->addr2), type,
2957 hostap_rx(dev, skb, rx_stats);
2958 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2963 } else if (fc & WLAN_FC_FROMDS) {
2965 /* FromDS frame - not for us; probably
2966 * broadcast/multicast in another BSS - drop */
2967 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2968 printk(KERN_DEBUG "Odd.. FromDS packet "
2969 "received with own BSSID\n");
2970 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2975 } else if (stype == WLAN_FC_STYPE_NULLFUNC && sta == NULL &&
2976 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2978 if (local->hostapd) {
2979 prism2_rx_80211(local->apdev, skb, rx_stats,
2980 PRISM2_RX_NON_ASSOC);
2981 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2983 /* At least Lucent f/w seems to send data::nullfunc
2984 * frames with no ToDS flag when the current AP returns
2985 * after being unavailable for some time. Speed up
2986 * re-association by informing the station about it not
2987 * being associated. */
2988 printk(KERN_DEBUG "%s: rejected received nullfunc "
2989 "frame without ToDS from not associated STA "
2991 dev->name, MAC2STR(hdr->addr2));
2992 hostap_rx(dev, skb, rx_stats);
2993 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2997 } else if (stype == WLAN_FC_STYPE_NULLFUNC) {
2998 /* At least Lucent cards seem to send periodic nullfunc
2999 * frames with ToDS. Let these through to update SQ
3000 * stats and PS state. Nullfunc frames do not contain
3001 * any data and they will be dropped below. */
3003 /* If BSSID (Addr3) is foreign, this frame is a normal
3004 * broadcast frame from an IBSS network. Drop it silently.
3005 * If BSSID is own, report the dropping of this frame. */
3006 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
3007 printk(KERN_DEBUG "%s: dropped received packet from "
3008 MACSTR " with no ToDS flag (type=0x%02x, "
3009 "subtype=0x%02x)\n", dev->name,
3010 MAC2STR(hdr->addr2), type, stype);
3011 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3018 hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
3022 sta->rx_bytes += skb->len;
3023 sta->last_rx = jiffies;
3026 if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC &&
3027 fc & WLAN_FC_TODS) {
3028 if (local->hostapd) {
3029 prism2_rx_80211(local->apdev, skb, rx_stats,
3030 PRISM2_RX_NULLFUNC_ACK);
3031 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3033 /* some STA f/w's seem to require control::ACK frame
3034 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3035 * from Compaq) does not send this.. Try to generate
3036 * ACK for these frames from the host driver to make
3037 * power saving work with, e.g., Lucent WaveLAN f/w */
3038 hostap_rx(dev, skb, rx_stats);
3039 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3047 atomic_dec(&sta->users);
3053 /* Called only as a tasklet (software IRQ) */
3054 int hostap_handle_sta_crypto(local_info_t *local,
3055 struct ieee80211_hdr *hdr,
3056 struct ieee80211_crypt_data **crypt,
3059 struct sta_info *sta;
3061 spin_lock(&local->ap->sta_table_lock);
3062 sta = ap_get_sta(local->ap, hdr->addr2);
3064 atomic_inc(&sta->users);
3065 spin_unlock(&local->ap->sta_table_lock);
3071 *crypt = sta->crypt;
3073 /* hostap_handle_sta_release() will be called to release STA
3076 atomic_dec(&sta->users);
3082 /* Called only as a tasklet (software IRQ) */
3083 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3085 struct sta_info *sta;
3088 spin_lock(&ap->sta_table_lock);
3089 sta = ap_get_sta(ap, sta_addr);
3090 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3092 spin_unlock(&ap->sta_table_lock);
3098 /* Called only as a tasklet (software IRQ) */
3099 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3101 struct sta_info *sta;
3104 spin_lock(&ap->sta_table_lock);
3105 sta = ap_get_sta(ap, sta_addr);
3106 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3107 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3108 ap->local->ieee_802_1x == 0))
3110 spin_unlock(&ap->sta_table_lock);
3116 /* Called only as a tasklet (software IRQ) */
3117 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3119 struct sta_info *sta;
3125 spin_lock(&ap->sta_table_lock);
3126 sta = ap_get_sta(ap, sta_addr);
3129 spin_unlock(&ap->sta_table_lock);
3132 sta = ap_add_sta(ap, sta_addr);
3135 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3137 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3138 /* No way of knowing which rates are supported since we did not
3139 * get supported rates element from beacon/assoc req. Assume
3140 * that remote end supports all 802.11b rates. */
3141 sta->supported_rates[0] = 0x82;
3142 sta->supported_rates[1] = 0x84;
3143 sta->supported_rates[2] = 0x0b;
3144 sta->supported_rates[3] = 0x16;
3145 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3146 WLAN_RATE_5M5 | WLAN_RATE_11M;
3148 sta->tx_max_rate = sta->tx_rate_idx = 3;
3155 /* Called only as a tasklet (software IRQ) */
3156 int hostap_update_rx_stats(struct ap_data *ap,
3157 struct ieee80211_hdr *hdr,
3158 struct hostap_80211_rx_status *rx_stats)
3160 struct sta_info *sta;
3165 spin_lock(&ap->sta_table_lock);
3166 sta = ap_get_sta(ap, hdr->addr2);
3168 sta->last_rx_silence = rx_stats->noise;
3169 sta->last_rx_signal = rx_stats->signal;
3170 sta->last_rx_rate = rx_stats->rate;
3171 sta->last_rx_updated = 7;
3172 if (rx_stats->rate == 10)
3174 else if (rx_stats->rate == 20)
3176 else if (rx_stats->rate == 55)
3178 else if (rx_stats->rate == 110)
3181 spin_unlock(&ap->sta_table_lock);
3183 return sta ? 0 : -1;
3187 void hostap_update_rates(local_info_t *local)
3189 struct list_head *ptr;
3190 struct ap_data *ap = local->ap;
3195 spin_lock_bh(&ap->sta_table_lock);
3196 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
3197 struct sta_info *sta = (struct sta_info *) ptr;
3198 prism2_check_tx_rates(sta);
3200 spin_unlock_bh(&ap->sta_table_lock);
3204 static void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3205 struct ieee80211_crypt_data ***crypt)
3207 struct sta_info *sta;
3209 spin_lock_bh(&ap->sta_table_lock);
3210 sta = ap_get_sta(ap, addr);
3212 atomic_inc(&sta->users);
3213 spin_unlock_bh(&ap->sta_table_lock);
3215 if (!sta && permanent)
3216 sta = ap_add_sta(ap, addr);
3222 sta->flags |= WLAN_STA_PERM;
3224 *crypt = &sta->crypt;
3230 void hostap_add_wds_links(local_info_t *local)
3232 struct ap_data *ap = local->ap;
3233 struct list_head *ptr;
3235 spin_lock_bh(&ap->sta_table_lock);
3236 list_for_each(ptr, &ap->sta_list) {
3237 struct sta_info *sta = list_entry(ptr, struct sta_info, list);
3239 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3241 spin_unlock_bh(&ap->sta_table_lock);
3243 schedule_work(&local->ap->wds_oper_queue);
3247 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3249 struct wds_oper_data *entry;
3251 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3254 memcpy(entry->addr, addr, ETH_ALEN);
3256 spin_lock_bh(&local->lock);
3257 entry->next = local->ap->wds_oper_entries;
3258 local->ap->wds_oper_entries = entry;
3259 spin_unlock_bh(&local->lock);
3261 schedule_work(&local->ap->wds_oper_queue);
3265 EXPORT_SYMBOL(hostap_init_data);
3266 EXPORT_SYMBOL(hostap_init_ap_proc);
3267 EXPORT_SYMBOL(hostap_free_data);
3268 EXPORT_SYMBOL(hostap_check_sta_fw_version);
3269 EXPORT_SYMBOL(hostap_handle_sta_tx);
3270 EXPORT_SYMBOL(hostap_handle_sta_release);
3271 EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3272 EXPORT_SYMBOL(hostap_update_sta_ps);
3273 EXPORT_SYMBOL(hostap_handle_sta_rx);
3274 EXPORT_SYMBOL(hostap_is_sta_assoc);
3275 EXPORT_SYMBOL(hostap_is_sta_authorized);
3276 EXPORT_SYMBOL(hostap_add_sta);
3277 EXPORT_SYMBOL(hostap_update_rates);
3278 EXPORT_SYMBOL(hostap_add_wds_links);
3279 EXPORT_SYMBOL(hostap_wds_link_oper);
3280 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3281 EXPORT_SYMBOL(hostap_deauth_all_stas);
3282 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */