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>
22 #include <linux/if_arp.h>
24 #include "hostap_wlan.h"
26 #include "hostap_ap.h"
28 static int other_ap_policy
[MAX_PARM_DEVICES
] = { AP_OTHER_AP_SKIP_ALL
,
30 module_param_array(other_ap_policy
, int, NULL
, 0444);
31 MODULE_PARM_DESC(other_ap_policy
, "Other AP beacon monitoring policy (0-3)");
33 static int ap_max_inactivity
[MAX_PARM_DEVICES
] = { AP_MAX_INACTIVITY_SEC
,
35 module_param_array(ap_max_inactivity
, int, NULL
, 0444);
36 MODULE_PARM_DESC(ap_max_inactivity
, "AP timeout (in seconds) for station "
39 static int ap_bridge_packets
[MAX_PARM_DEVICES
] = { 1, DEF_INTS
};
40 module_param_array(ap_bridge_packets
, int, NULL
, 0444);
41 MODULE_PARM_DESC(ap_bridge_packets
, "Bridge packets directly between "
44 static int autom_ap_wds
[MAX_PARM_DEVICES
] = { 0, DEF_INTS
};
45 module_param_array(autom_ap_wds
, int, NULL
, 0444);
46 MODULE_PARM_DESC(autom_ap_wds
, "Add WDS connections to other APs "
50 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
);
51 static void hostap_event_expired_sta(struct net_device
*dev
,
52 struct sta_info
*sta
);
53 static void handle_add_proc_queue(struct work_struct
*work
);
55 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
56 static void handle_wds_oper_queue(struct work_struct
*work
);
57 static void prism2_send_mgmt(struct net_device
*dev
,
58 u16 type_subtype
, char *body
,
59 int body_len
, u8
*addr
, u16 tx_cb_idx
);
60 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
63 #ifndef PRISM2_NO_PROCFS_DEBUG
64 static int ap_debug_proc_read(char *page
, char **start
, off_t off
,
65 int count
, int *eof
, void *data
)
68 struct ap_data
*ap
= (struct ap_data
*) data
;
75 p
+= sprintf(p
, "BridgedUnicastFrames=%u\n", ap
->bridged_unicast
);
76 p
+= sprintf(p
, "BridgedMulticastFrames=%u\n", ap
->bridged_multicast
);
77 p
+= sprintf(p
, "max_inactivity=%u\n", ap
->max_inactivity
/ HZ
);
78 p
+= sprintf(p
, "bridge_packets=%u\n", ap
->bridge_packets
);
79 p
+= sprintf(p
, "nullfunc_ack=%u\n", ap
->nullfunc_ack
);
80 p
+= sprintf(p
, "autom_ap_wds=%u\n", ap
->autom_ap_wds
);
81 p
+= sprintf(p
, "auth_algs=%u\n", ap
->local
->auth_algs
);
82 p
+= sprintf(p
, "tx_drop_nonassoc=%u\n", ap
->tx_drop_nonassoc
);
86 #endif /* PRISM2_NO_PROCFS_DEBUG */
89 static void ap_sta_hash_add(struct ap_data
*ap
, struct sta_info
*sta
)
91 sta
->hnext
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
92 ap
->sta_hash
[STA_HASH(sta
->addr
)] = sta
;
95 static void ap_sta_hash_del(struct ap_data
*ap
, struct sta_info
*sta
)
99 s
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
100 if (s
== NULL
) return;
101 if (memcmp(s
->addr
, sta
->addr
, ETH_ALEN
) == 0) {
102 ap
->sta_hash
[STA_HASH(sta
->addr
)] = s
->hnext
;
106 while (s
->hnext
!= NULL
&& memcmp(s
->hnext
->addr
, sta
->addr
, ETH_ALEN
)
109 if (s
->hnext
!= NULL
)
110 s
->hnext
= s
->hnext
->hnext
;
112 printk("AP: could not remove STA %pM from hash table\n",
116 static void ap_free_sta(struct ap_data
*ap
, struct sta_info
*sta
)
118 if (sta
->ap
&& sta
->local
)
119 hostap_event_expired_sta(sta
->local
->dev
, sta
);
121 if (ap
->proc
!= NULL
) {
123 sprintf(name
, "%pM", sta
->addr
);
124 remove_proc_entry(name
, ap
->proc
);
128 sta
->crypt
->ops
->deinit(sta
->crypt
->priv
);
133 skb_queue_purge(&sta
->tx_buf
);
136 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
138 ap
->sta_aid
[sta
->aid
- 1] = NULL
;
140 if (!sta
->ap
&& sta
->u
.sta
.challenge
)
141 kfree(sta
->u
.sta
.challenge
);
142 del_timer(&sta
->timer
);
143 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
149 static void hostap_set_tim(local_info_t
*local
, int aid
, int set
)
151 if (local
->func
->set_tim
)
152 local
->func
->set_tim(local
->dev
, aid
, set
);
156 static void hostap_event_new_sta(struct net_device
*dev
, struct sta_info
*sta
)
158 union iwreq_data wrqu
;
159 memset(&wrqu
, 0, sizeof(wrqu
));
160 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
161 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
162 wireless_send_event(dev
, IWEVREGISTERED
, &wrqu
, NULL
);
166 static void hostap_event_expired_sta(struct net_device
*dev
,
167 struct sta_info
*sta
)
169 union iwreq_data wrqu
;
170 memset(&wrqu
, 0, sizeof(wrqu
));
171 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
172 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
173 wireless_send_event(dev
, IWEVEXPIRED
, &wrqu
, NULL
);
177 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
179 static void ap_handle_timer(unsigned long data
)
181 struct sta_info
*sta
= (struct sta_info
*) data
;
184 unsigned long next_time
= 0;
187 if (sta
== NULL
|| sta
->local
== NULL
|| sta
->local
->ap
== NULL
) {
188 PDEBUG(DEBUG_AP
, "ap_handle_timer() called with NULL data\n");
194 was_assoc
= sta
->flags
& WLAN_STA_ASSOC
;
196 if (atomic_read(&sta
->users
) != 0)
197 next_time
= jiffies
+ HZ
;
198 else if ((sta
->flags
& WLAN_STA_PERM
) && !(sta
->flags
& WLAN_STA_AUTH
))
199 next_time
= jiffies
+ ap
->max_inactivity
;
201 if (time_before(jiffies
, sta
->last_rx
+ ap
->max_inactivity
)) {
202 /* station activity detected; reset timeout state */
203 sta
->timeout_next
= STA_NULLFUNC
;
204 next_time
= sta
->last_rx
+ ap
->max_inactivity
;
205 } else if (sta
->timeout_next
== STA_DISASSOC
&&
206 !(sta
->flags
& WLAN_STA_PENDING_POLL
)) {
207 /* STA ACKed data nullfunc frame poll */
208 sta
->timeout_next
= STA_NULLFUNC
;
209 next_time
= jiffies
+ ap
->max_inactivity
;
213 sta
->timer
.expires
= next_time
;
214 add_timer(&sta
->timer
);
219 sta
->timeout_next
= STA_DEAUTH
;
221 if (sta
->timeout_next
== STA_DEAUTH
&& !(sta
->flags
& WLAN_STA_PERM
)) {
222 spin_lock(&ap
->sta_table_lock
);
223 ap_sta_hash_del(ap
, sta
);
224 list_del(&sta
->list
);
225 spin_unlock(&ap
->sta_table_lock
);
226 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
227 } else if (sta
->timeout_next
== STA_DISASSOC
)
228 sta
->flags
&= ~WLAN_STA_ASSOC
;
230 if (was_assoc
&& !(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
231 hostap_event_expired_sta(local
->dev
, sta
);
233 if (sta
->timeout_next
== STA_DEAUTH
&& sta
->aid
> 0 &&
234 !skb_queue_empty(&sta
->tx_buf
)) {
235 hostap_set_tim(local
, sta
->aid
, 0);
236 sta
->flags
&= ~WLAN_STA_TIM
;
240 if (ap
->autom_ap_wds
) {
241 PDEBUG(DEBUG_AP
, "%s: removing automatic WDS "
242 "connection to AP %pM\n",
243 local
->dev
->name
, sta
->addr
);
244 hostap_wds_link_oper(local
, sta
->addr
, WDS_DEL
);
246 } else if (sta
->timeout_next
== STA_NULLFUNC
) {
247 /* send data frame to poll STA and check whether this frame
249 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
250 * it is apparently not retried so TX Exc events are not
252 sta
->flags
|= WLAN_STA_PENDING_POLL
;
253 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_DATA
|
254 IEEE80211_STYPE_DATA
, NULL
, 0,
255 sta
->addr
, ap
->tx_callback_poll
);
257 int deauth
= sta
->timeout_next
== STA_DEAUTH
;
259 PDEBUG(DEBUG_AP
, "%s: sending %s info to STA %pM"
260 "(last=%lu, jiffies=%lu)\n",
262 deauth
? "deauthentication" : "disassociation",
263 sta
->addr
, sta
->last_rx
, jiffies
);
265 resp
= cpu_to_le16(deauth
? WLAN_REASON_PREV_AUTH_NOT_VALID
:
266 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
267 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_MGMT
|
268 (deauth
? IEEE80211_STYPE_DEAUTH
:
269 IEEE80211_STYPE_DISASSOC
),
270 (char *) &resp
, 2, sta
->addr
, 0);
273 if (sta
->timeout_next
== STA_DEAUTH
) {
274 if (sta
->flags
& WLAN_STA_PERM
) {
275 PDEBUG(DEBUG_AP
, "%s: STA %pM"
276 " would have been removed, "
277 "but it has 'perm' flag\n",
278 local
->dev
->name
, sta
->addr
);
280 ap_free_sta(ap
, sta
);
284 if (sta
->timeout_next
== STA_NULLFUNC
) {
285 sta
->timeout_next
= STA_DISASSOC
;
286 sta
->timer
.expires
= jiffies
+ AP_DISASSOC_DELAY
;
288 sta
->timeout_next
= STA_DEAUTH
;
289 sta
->timer
.expires
= jiffies
+ AP_DEAUTH_DELAY
;
292 add_timer(&sta
->timer
);
296 void hostap_deauth_all_stas(struct net_device
*dev
, struct ap_data
*ap
,
303 PDEBUG(DEBUG_AP
, "%s: Deauthenticate all stations\n", dev
->name
);
304 memset(addr
, 0xff, ETH_ALEN
);
306 resp
= cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
308 /* deauth message sent; try to resend it few times; the message is
309 * broadcast, so it may be delayed until next DTIM; there is not much
310 * else we can do at this point since the driver is going to be shut
312 for (i
= 0; i
< 5; i
++) {
313 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
314 IEEE80211_STYPE_DEAUTH
,
315 (char *) &resp
, 2, addr
, 0);
317 if (!resend
|| ap
->num_sta
<= 0)
325 static int ap_control_proc_read(char *page
, char **start
, off_t off
,
326 int count
, int *eof
, void *data
)
329 struct ap_data
*ap
= (struct ap_data
*) data
;
331 struct mac_entry
*entry
;
338 switch (ap
->mac_restrictions
.policy
) {
339 case MAC_POLICY_OPEN
:
342 case MAC_POLICY_ALLOW
:
343 policy_txt
= "allow";
345 case MAC_POLICY_DENY
:
349 policy_txt
= "unknown";
352 p
+= sprintf(p
, "MAC policy: %s\n", policy_txt
);
353 p
+= sprintf(p
, "MAC entries: %u\n", ap
->mac_restrictions
.entries
);
354 p
+= sprintf(p
, "MAC list:\n");
355 spin_lock_bh(&ap
->mac_restrictions
.lock
);
356 list_for_each_entry(entry
, &ap
->mac_restrictions
.mac_list
, list
) {
357 if (p
- page
> PAGE_SIZE
- 80) {
358 p
+= sprintf(p
, "All entries did not fit one page.\n");
362 p
+= sprintf(p
, "%pM\n", entry
->addr
);
364 spin_unlock_bh(&ap
->mac_restrictions
.lock
);
370 int ap_control_add_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
372 struct mac_entry
*entry
;
374 entry
= kmalloc(sizeof(struct mac_entry
), GFP_KERNEL
);
378 memcpy(entry
->addr
, mac
, ETH_ALEN
);
380 spin_lock_bh(&mac_restrictions
->lock
);
381 list_add_tail(&entry
->list
, &mac_restrictions
->mac_list
);
382 mac_restrictions
->entries
++;
383 spin_unlock_bh(&mac_restrictions
->lock
);
389 int ap_control_del_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
391 struct list_head
*ptr
;
392 struct mac_entry
*entry
;
394 spin_lock_bh(&mac_restrictions
->lock
);
395 for (ptr
= mac_restrictions
->mac_list
.next
;
396 ptr
!= &mac_restrictions
->mac_list
; ptr
= ptr
->next
) {
397 entry
= list_entry(ptr
, struct mac_entry
, list
);
399 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
402 mac_restrictions
->entries
--;
403 spin_unlock_bh(&mac_restrictions
->lock
);
407 spin_unlock_bh(&mac_restrictions
->lock
);
412 static int ap_control_mac_deny(struct mac_restrictions
*mac_restrictions
,
415 struct mac_entry
*entry
;
418 if (mac_restrictions
->policy
== MAC_POLICY_OPEN
)
421 spin_lock_bh(&mac_restrictions
->lock
);
422 list_for_each_entry(entry
, &mac_restrictions
->mac_list
, list
) {
423 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
428 spin_unlock_bh(&mac_restrictions
->lock
);
430 if (mac_restrictions
->policy
== MAC_POLICY_ALLOW
)
437 void ap_control_flush_macs(struct mac_restrictions
*mac_restrictions
)
439 struct list_head
*ptr
, *n
;
440 struct mac_entry
*entry
;
442 if (mac_restrictions
->entries
== 0)
445 spin_lock_bh(&mac_restrictions
->lock
);
446 for (ptr
= mac_restrictions
->mac_list
.next
, n
= ptr
->next
;
447 ptr
!= &mac_restrictions
->mac_list
;
448 ptr
= n
, n
= ptr
->next
) {
449 entry
= list_entry(ptr
, struct mac_entry
, list
);
453 mac_restrictions
->entries
= 0;
454 spin_unlock_bh(&mac_restrictions
->lock
);
458 int ap_control_kick_mac(struct ap_data
*ap
, struct net_device
*dev
, u8
*mac
)
460 struct sta_info
*sta
;
463 spin_lock_bh(&ap
->sta_table_lock
);
464 sta
= ap_get_sta(ap
, mac
);
466 ap_sta_hash_del(ap
, sta
);
467 list_del(&sta
->list
);
469 spin_unlock_bh(&ap
->sta_table_lock
);
474 resp
= cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
475 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_DEAUTH
,
476 (char *) &resp
, 2, sta
->addr
, 0);
478 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
479 hostap_event_expired_sta(dev
, sta
);
481 ap_free_sta(ap
, sta
);
486 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
489 void ap_control_kickall(struct ap_data
*ap
)
491 struct list_head
*ptr
, *n
;
492 struct sta_info
*sta
;
494 spin_lock_bh(&ap
->sta_table_lock
);
495 for (ptr
= ap
->sta_list
.next
, n
= ptr
->next
; ptr
!= &ap
->sta_list
;
496 ptr
= n
, n
= ptr
->next
) {
497 sta
= list_entry(ptr
, struct sta_info
, list
);
498 ap_sta_hash_del(ap
, sta
);
499 list_del(&sta
->list
);
500 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
501 hostap_event_expired_sta(sta
->local
->dev
, sta
);
502 ap_free_sta(ap
, sta
);
504 spin_unlock_bh(&ap
->sta_table_lock
);
508 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
510 #define PROC_LIMIT (PAGE_SIZE - 80)
512 static int prism2_ap_proc_read(char *page
, char **start
, off_t off
,
513 int count
, int *eof
, void *data
)
516 struct ap_data
*ap
= (struct ap_data
*) data
;
517 struct sta_info
*sta
;
520 if (off
> PROC_LIMIT
) {
525 p
+= sprintf(p
, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
526 spin_lock_bh(&ap
->sta_table_lock
);
527 list_for_each_entry(sta
, &ap
->sta_list
, list
) {
531 p
+= sprintf(p
, "%pM %d %d %d %d '",
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
;
592 struct ieee80211_hdr
*hdr
;
594 if (!ap
->local
->hostapd
|| !ap
->local
->apdev
) {
599 /* Pass the TX callback frame to the hostapd; use 802.11 header version
600 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
602 hdr
= (struct ieee80211_hdr
*) skb
->data
;
603 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_VERS
);
604 hdr
->frame_control
|= cpu_to_le16(ok
? BIT(1) : BIT(0));
606 skb
->dev
= ap
->local
->apdev
;
607 skb_pull(skb
, hostap_80211_get_hdrlen(hdr
->frame_control
));
608 skb
->pkt_type
= PACKET_OTHERHOST
;
609 skb
->protocol
= cpu_to_be16(ETH_P_802_2
);
610 memset(skb
->cb
, 0, sizeof(skb
->cb
));
615 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
616 /* Called only as a tasklet (software IRQ) */
617 static void hostap_ap_tx_cb_auth(struct sk_buff
*skb
, int ok
, void *data
)
619 struct ap_data
*ap
= data
;
620 struct net_device
*dev
= ap
->local
->dev
;
621 struct ieee80211_hdr
*hdr
;
622 u16 auth_alg
, auth_transaction
, status
;
624 struct sta_info
*sta
= NULL
;
627 if (ap
->local
->hostapd
) {
632 hdr
= (struct ieee80211_hdr
*) skb
->data
;
633 if (!ieee80211_is_auth(hdr
->frame_control
) ||
634 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 6) {
635 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_auth received invalid "
636 "frame\n", dev
->name
);
641 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
642 auth_alg
= le16_to_cpu(*pos
++);
643 auth_transaction
= le16_to_cpu(*pos
++);
644 status
= le16_to_cpu(*pos
++);
647 txt
= "frame was not ACKed";
651 spin_lock(&ap
->sta_table_lock
);
652 sta
= ap_get_sta(ap
, hdr
->addr1
);
654 atomic_inc(&sta
->users
);
655 spin_unlock(&ap
->sta_table_lock
);
658 txt
= "STA not found";
662 if (status
== WLAN_STATUS_SUCCESS
&&
663 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
664 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
665 txt
= "STA authenticated";
666 sta
->flags
|= WLAN_STA_AUTH
;
667 sta
->last_auth
= jiffies
;
668 } else if (status
!= WLAN_STATUS_SUCCESS
)
669 txt
= "authentication failed";
673 atomic_dec(&sta
->users
);
675 PDEBUG(DEBUG_AP
, "%s: %pM auth_cb - alg=%d "
676 "trans#=%d status=%d - %s\n",
677 dev
->name
, hdr
->addr1
,
678 auth_alg
, auth_transaction
, status
, txt
);
684 /* Called only as a tasklet (software IRQ) */
685 static void hostap_ap_tx_cb_assoc(struct sk_buff
*skb
, int ok
, void *data
)
687 struct ap_data
*ap
= data
;
688 struct net_device
*dev
= ap
->local
->dev
;
689 struct ieee80211_hdr
*hdr
;
692 struct sta_info
*sta
= NULL
;
695 if (ap
->local
->hostapd
) {
700 hdr
= (struct ieee80211_hdr
*) skb
->data
;
701 fc
= le16_to_cpu(hdr
->frame_control
);
702 if ((!ieee80211_is_assoc_resp(hdr
->frame_control
) &&
703 !ieee80211_is_reassoc_resp(hdr
->frame_control
)) ||
704 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 4) {
705 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_assoc received invalid "
706 "frame\n", dev
->name
);
712 txt
= "frame was not ACKed";
716 spin_lock(&ap
->sta_table_lock
);
717 sta
= ap_get_sta(ap
, hdr
->addr1
);
719 atomic_inc(&sta
->users
);
720 spin_unlock(&ap
->sta_table_lock
);
723 txt
= "STA not found";
727 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
729 status
= le16_to_cpu(*pos
++);
730 if (status
== WLAN_STATUS_SUCCESS
) {
731 if (!(sta
->flags
& WLAN_STA_ASSOC
))
732 hostap_event_new_sta(dev
, sta
);
733 txt
= "STA associated";
734 sta
->flags
|= WLAN_STA_ASSOC
;
735 sta
->last_assoc
= jiffies
;
737 txt
= "association failed";
741 atomic_dec(&sta
->users
);
743 PDEBUG(DEBUG_AP
, "%s: %pM assoc_cb - %s\n",
744 dev
->name
, hdr
->addr1
, txt
);
749 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
750 * in verifying whether the STA is still present. */
751 static void hostap_ap_tx_cb_poll(struct sk_buff
*skb
, int ok
, void *data
)
753 struct ap_data
*ap
= data
;
754 struct ieee80211_hdr
*hdr
;
755 struct sta_info
*sta
;
759 hdr
= (struct ieee80211_hdr
*) skb
->data
;
761 spin_lock(&ap
->sta_table_lock
);
762 sta
= ap_get_sta(ap
, hdr
->addr1
);
764 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
765 spin_unlock(&ap
->sta_table_lock
);
768 "%s: STA %pM did not ACK activity poll frame\n",
769 ap
->local
->dev
->name
, hdr
->addr1
);
775 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
778 void hostap_init_data(local_info_t
*local
)
780 struct ap_data
*ap
= local
->ap
;
783 printk(KERN_WARNING
"hostap_init_data: ap == NULL\n");
786 memset(ap
, 0, sizeof(struct ap_data
));
789 ap
->ap_policy
= GET_INT_PARM(other_ap_policy
, local
->card_idx
);
790 ap
->bridge_packets
= GET_INT_PARM(ap_bridge_packets
, local
->card_idx
);
792 GET_INT_PARM(ap_max_inactivity
, local
->card_idx
) * HZ
;
793 ap
->autom_ap_wds
= GET_INT_PARM(autom_ap_wds
, local
->card_idx
);
795 spin_lock_init(&ap
->sta_table_lock
);
796 INIT_LIST_HEAD(&ap
->sta_list
);
798 /* Initialize task queue structure for AP management */
799 INIT_WORK(&local
->ap
->add_sta_proc_queue
, handle_add_proc_queue
);
801 ap
->tx_callback_idx
=
802 hostap_tx_callback_register(local
, hostap_ap_tx_cb
, ap
);
803 if (ap
->tx_callback_idx
== 0)
804 printk(KERN_WARNING
"%s: failed to register TX callback for "
805 "AP\n", local
->dev
->name
);
806 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
807 INIT_WORK(&local
->ap
->wds_oper_queue
, handle_wds_oper_queue
);
809 ap
->tx_callback_auth
=
810 hostap_tx_callback_register(local
, hostap_ap_tx_cb_auth
, ap
);
811 ap
->tx_callback_assoc
=
812 hostap_tx_callback_register(local
, hostap_ap_tx_cb_assoc
, ap
);
813 ap
->tx_callback_poll
=
814 hostap_tx_callback_register(local
, hostap_ap_tx_cb_poll
, ap
);
815 if (ap
->tx_callback_auth
== 0 || ap
->tx_callback_assoc
== 0 ||
816 ap
->tx_callback_poll
== 0)
817 printk(KERN_WARNING
"%s: failed to register TX callback for "
818 "AP\n", local
->dev
->name
);
820 spin_lock_init(&ap
->mac_restrictions
.lock
);
821 INIT_LIST_HEAD(&ap
->mac_restrictions
.mac_list
);
822 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
828 void hostap_init_ap_proc(local_info_t
*local
)
830 struct ap_data
*ap
= local
->ap
;
832 ap
->proc
= local
->proc
;
833 if (ap
->proc
== NULL
)
836 #ifndef PRISM2_NO_PROCFS_DEBUG
837 create_proc_read_entry("ap_debug", 0, ap
->proc
,
838 ap_debug_proc_read
, ap
);
839 #endif /* PRISM2_NO_PROCFS_DEBUG */
841 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
842 create_proc_read_entry("ap_control", 0, ap
->proc
,
843 ap_control_proc_read
, ap
);
844 create_proc_read_entry("ap", 0, ap
->proc
,
845 prism2_ap_proc_read
, ap
);
846 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
851 void hostap_free_data(struct ap_data
*ap
)
853 struct sta_info
*n
, *sta
;
855 if (ap
== NULL
|| !ap
->initialized
) {
856 printk(KERN_DEBUG
"hostap_free_data: ap has not yet been "
857 "initialized - skip resource freeing\n");
861 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
863 ap
->crypt
->deinit(ap
->crypt_priv
);
864 ap
->crypt
= ap
->crypt_priv
= NULL
;
865 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
867 list_for_each_entry_safe(sta
, n
, &ap
->sta_list
, list
) {
868 ap_sta_hash_del(ap
, sta
);
869 list_del(&sta
->list
);
870 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
871 hostap_event_expired_sta(sta
->local
->dev
, sta
);
872 ap_free_sta(ap
, sta
);
875 #ifndef PRISM2_NO_PROCFS_DEBUG
876 if (ap
->proc
!= NULL
) {
877 remove_proc_entry("ap_debug", ap
->proc
);
879 #endif /* PRISM2_NO_PROCFS_DEBUG */
881 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
882 if (ap
->proc
!= NULL
) {
883 remove_proc_entry("ap", ap
->proc
);
884 remove_proc_entry("ap_control", ap
->proc
);
886 ap_control_flush_macs(&ap
->mac_restrictions
);
887 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
893 /* caller should have mutex for AP STA list handling */
894 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
)
898 s
= ap
->sta_hash
[STA_HASH(sta
)];
899 while (s
!= NULL
&& memcmp(s
->addr
, sta
, ETH_ALEN
) != 0)
905 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
907 /* Called from timer handler and from scheduled AP queue handlers */
908 static void prism2_send_mgmt(struct net_device
*dev
,
909 u16 type_subtype
, char *body
,
910 int body_len
, u8
*addr
, u16 tx_cb_idx
)
912 struct hostap_interface
*iface
;
914 struct ieee80211_hdr
*hdr
;
917 struct hostap_skb_tx_data
*meta
;
920 iface
= netdev_priv(dev
);
921 local
= iface
->local
;
922 dev
= local
->dev
; /* always use master radio device */
923 iface
= netdev_priv(dev
);
925 if (!(dev
->flags
& IFF_UP
)) {
926 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt - device is not UP - "
927 "cannot send frame\n", dev
->name
);
931 skb
= dev_alloc_skb(sizeof(*hdr
) + body_len
);
933 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt failed to allocate "
939 hdrlen
= hostap_80211_get_hdrlen(cpu_to_le16(type_subtype
));
940 hdr
= (struct ieee80211_hdr
*) skb_put(skb
, hdrlen
);
942 memcpy(skb_put(skb
, body_len
), body
, body_len
);
944 memset(hdr
, 0, hdrlen
);
946 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
947 * tx_control instead of using local->tx_control */
950 memcpy(hdr
->addr1
, addr
, ETH_ALEN
); /* DA / RA */
951 if (ieee80211_is_data(hdr
->frame_control
)) {
952 fc
|= IEEE80211_FCTL_FROMDS
;
953 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
954 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* SA */
955 } else if (ieee80211_is_ctl(hdr
->frame_control
)) {
956 /* control:ACK does not have addr2 or addr3 */
957 memset(hdr
->addr2
, 0, ETH_ALEN
);
958 memset(hdr
->addr3
, 0, ETH_ALEN
);
960 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* SA */
961 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
964 hdr
->frame_control
= cpu_to_le16(fc
);
966 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
967 memset(meta
, 0, sizeof(*meta
));
968 meta
->magic
= HOSTAP_SKB_TX_DATA_MAGIC
;
970 meta
->tx_cb_idx
= tx_cb_idx
;
973 skb_reset_mac_header(skb
);
974 skb_reset_network_header(skb
);
977 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
980 static int prism2_sta_proc_read(char *page
, char **start
, off_t off
,
981 int count
, int *eof
, void *data
)
984 struct sta_info
*sta
= (struct sta_info
*) data
;
987 /* FIX: possible race condition.. the STA data could have just expired,
988 * but proc entry was still here so that the read could have started;
989 * some locking should be done here.. */
996 p
+= sprintf(p
, "%s=%pM\nusers=%d\naid=%d\n"
997 "flags=0x%04x%s%s%s%s%s%s%s\n"
998 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
999 sta
->ap
? "AP" : "STA",
1000 sta
->addr
, atomic_read(&sta
->users
), sta
->aid
,
1002 sta
->flags
& WLAN_STA_AUTH
? " AUTH" : "",
1003 sta
->flags
& WLAN_STA_ASSOC
? " ASSOC" : "",
1004 sta
->flags
& WLAN_STA_PS
? " PS" : "",
1005 sta
->flags
& WLAN_STA_TIM
? " TIM" : "",
1006 sta
->flags
& WLAN_STA_PERM
? " PERM" : "",
1007 sta
->flags
& WLAN_STA_AUTHORIZED
? " AUTHORIZED" : "",
1008 sta
->flags
& WLAN_STA_PENDING_POLL
? " POLL" : "",
1009 sta
->capability
, sta
->listen_interval
);
1010 /* supported_rates: 500 kbit/s units with msb ignored */
1011 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++)
1012 if (sta
->supported_rates
[i
] != 0)
1013 p
+= sprintf(p
, "%d%sMbps ",
1014 (sta
->supported_rates
[i
] & 0x7f) / 2,
1015 sta
->supported_rates
[i
] & 1 ? ".5" : "");
1016 p
+= sprintf(p
, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1017 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1019 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1020 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1021 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1023 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1024 jiffies
, sta
->last_auth
, sta
->last_assoc
, sta
->last_rx
,
1026 sta
->rx_packets
, sta
->tx_packets
, sta
->rx_bytes
,
1027 sta
->tx_bytes
, skb_queue_len(&sta
->tx_buf
),
1028 sta
->last_rx_silence
,
1029 sta
->last_rx_signal
, sta
->last_rx_rate
/ 10,
1030 sta
->last_rx_rate
% 10 ? ".5" : "",
1031 sta
->tx_rate
, sta
->tx_count
[0], sta
->tx_count
[1],
1032 sta
->tx_count
[2], sta
->tx_count
[3], sta
->rx_count
[0],
1033 sta
->rx_count
[1], sta
->rx_count
[2], sta
->rx_count
[3]);
1034 if (sta
->crypt
&& sta
->crypt
->ops
&& sta
->crypt
->ops
->print_stats
)
1035 p
= sta
->crypt
->ops
->print_stats(p
, sta
->crypt
->priv
);
1036 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1038 if (sta
->u
.ap
.channel
>= 0)
1039 p
+= sprintf(p
, "channel=%d\n", sta
->u
.ap
.channel
);
1040 p
+= sprintf(p
, "ssid=");
1041 for (i
= 0; i
< sta
->u
.ap
.ssid_len
; i
++)
1042 p
+= sprintf(p
, ((sta
->u
.ap
.ssid
[i
] >= 32 &&
1043 sta
->u
.ap
.ssid
[i
] < 127) ?
1046 p
+= sprintf(p
, "\n");
1048 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1054 static void handle_add_proc_queue(struct work_struct
*work
)
1056 struct ap_data
*ap
= container_of(work
, struct ap_data
,
1057 add_sta_proc_queue
);
1058 struct sta_info
*sta
;
1060 struct add_sta_proc_data
*entry
, *prev
;
1062 entry
= ap
->add_sta_proc_entries
;
1063 ap
->add_sta_proc_entries
= NULL
;
1066 spin_lock_bh(&ap
->sta_table_lock
);
1067 sta
= ap_get_sta(ap
, entry
->addr
);
1069 atomic_inc(&sta
->users
);
1070 spin_unlock_bh(&ap
->sta_table_lock
);
1073 sprintf(name
, "%pM", sta
->addr
);
1074 sta
->proc
= create_proc_read_entry(
1076 prism2_sta_proc_read
, sta
);
1078 atomic_dec(&sta
->users
);
1082 entry
= entry
->next
;
1088 static struct sta_info
* ap_add_sta(struct ap_data
*ap
, u8
*addr
)
1090 struct sta_info
*sta
;
1092 sta
= kzalloc(sizeof(struct sta_info
), GFP_ATOMIC
);
1094 PDEBUG(DEBUG_AP
, "AP: kmalloc failed\n");
1098 /* initialize STA info data */
1099 sta
->local
= ap
->local
;
1100 skb_queue_head_init(&sta
->tx_buf
);
1101 memcpy(sta
->addr
, addr
, ETH_ALEN
);
1103 atomic_inc(&sta
->users
);
1104 spin_lock_bh(&ap
->sta_table_lock
);
1105 list_add(&sta
->list
, &ap
->sta_list
);
1107 ap_sta_hash_add(ap
, sta
);
1108 spin_unlock_bh(&ap
->sta_table_lock
);
1111 struct add_sta_proc_data
*entry
;
1112 /* schedule a non-interrupt context process to add a procfs
1113 * entry for the STA since procfs code use GFP_KERNEL */
1114 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1116 memcpy(entry
->addr
, sta
->addr
, ETH_ALEN
);
1117 entry
->next
= ap
->add_sta_proc_entries
;
1118 ap
->add_sta_proc_entries
= entry
;
1119 schedule_work(&ap
->add_sta_proc_queue
);
1121 printk(KERN_DEBUG
"Failed to add STA proc data\n");
1124 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1125 init_timer(&sta
->timer
);
1126 sta
->timer
.expires
= jiffies
+ ap
->max_inactivity
;
1127 sta
->timer
.data
= (unsigned long) sta
;
1128 sta
->timer
.function
= ap_handle_timer
;
1129 if (!ap
->local
->hostapd
)
1130 add_timer(&sta
->timer
);
1131 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1137 static int ap_tx_rate_ok(int rateidx
, struct sta_info
*sta
,
1138 local_info_t
*local
)
1140 if (rateidx
> sta
->tx_max_rate
||
1141 !(sta
->tx_supp_rates
& (1 << rateidx
)))
1144 if (local
->tx_rate_control
!= 0 &&
1145 !(local
->tx_rate_control
& (1 << rateidx
)))
1152 static void prism2_check_tx_rates(struct sta_info
*sta
)
1156 sta
->tx_supp_rates
= 0;
1157 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++) {
1158 if ((sta
->supported_rates
[i
] & 0x7f) == 2)
1159 sta
->tx_supp_rates
|= WLAN_RATE_1M
;
1160 if ((sta
->supported_rates
[i
] & 0x7f) == 4)
1161 sta
->tx_supp_rates
|= WLAN_RATE_2M
;
1162 if ((sta
->supported_rates
[i
] & 0x7f) == 11)
1163 sta
->tx_supp_rates
|= WLAN_RATE_5M5
;
1164 if ((sta
->supported_rates
[i
] & 0x7f) == 22)
1165 sta
->tx_supp_rates
|= WLAN_RATE_11M
;
1167 sta
->tx_max_rate
= sta
->tx_rate
= sta
->tx_rate_idx
= 0;
1168 if (sta
->tx_supp_rates
& WLAN_RATE_1M
) {
1169 sta
->tx_max_rate
= 0;
1170 if (ap_tx_rate_ok(0, sta
, sta
->local
)) {
1172 sta
->tx_rate_idx
= 0;
1175 if (sta
->tx_supp_rates
& WLAN_RATE_2M
) {
1176 sta
->tx_max_rate
= 1;
1177 if (ap_tx_rate_ok(1, sta
, sta
->local
)) {
1179 sta
->tx_rate_idx
= 1;
1182 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
) {
1183 sta
->tx_max_rate
= 2;
1184 if (ap_tx_rate_ok(2, sta
, sta
->local
)) {
1186 sta
->tx_rate_idx
= 2;
1189 if (sta
->tx_supp_rates
& WLAN_RATE_11M
) {
1190 sta
->tx_max_rate
= 3;
1191 if (ap_tx_rate_ok(3, sta
, sta
->local
)) {
1193 sta
->tx_rate_idx
= 3;
1199 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1201 static void ap_crypt_init(struct ap_data
*ap
)
1203 ap
->crypt
= lib80211_get_crypto_ops("WEP");
1206 if (ap
->crypt
->init
) {
1207 ap
->crypt_priv
= ap
->crypt
->init(0);
1208 if (ap
->crypt_priv
== NULL
)
1211 u8 key
[WEP_KEY_LEN
];
1212 get_random_bytes(key
, WEP_KEY_LEN
);
1213 ap
->crypt
->set_key(key
, WEP_KEY_LEN
, NULL
,
1219 if (ap
->crypt
== NULL
) {
1220 printk(KERN_WARNING
"AP could not initialize WEP: load module "
1221 "lib80211_crypt_wep.ko\n");
1226 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1227 * that WEP algorithm is used for generating challange. This should be unique,
1228 * but otherwise there is not really need for randomness etc. Initialize WEP
1229 * with pseudo random key and then use increasing IV to get unique challenge
1232 * Called only as a scheduled task for pending AP frames.
1234 static char * ap_auth_make_challenge(struct ap_data
*ap
)
1237 struct sk_buff
*skb
;
1239 if (ap
->crypt
== NULL
) {
1241 if (ap
->crypt
== NULL
)
1245 tmpbuf
= kmalloc(WLAN_AUTH_CHALLENGE_LEN
, GFP_ATOMIC
);
1246 if (tmpbuf
== NULL
) {
1247 PDEBUG(DEBUG_AP
, "AP: kmalloc failed for challenge\n");
1251 skb
= dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN
+
1252 ap
->crypt
->extra_mpdu_prefix_len
+
1253 ap
->crypt
->extra_mpdu_postfix_len
);
1259 skb_reserve(skb
, ap
->crypt
->extra_mpdu_prefix_len
);
1260 memset(skb_put(skb
, WLAN_AUTH_CHALLENGE_LEN
), 0,
1261 WLAN_AUTH_CHALLENGE_LEN
);
1262 if (ap
->crypt
->encrypt_mpdu(skb
, 0, ap
->crypt_priv
)) {
1268 skb_copy_from_linear_data_offset(skb
, ap
->crypt
->extra_mpdu_prefix_len
,
1269 tmpbuf
, WLAN_AUTH_CHALLENGE_LEN
);
1276 /* Called only as a scheduled task for pending AP frames. */
1277 static void handle_authen(local_info_t
*local
, struct sk_buff
*skb
,
1278 struct hostap_80211_rx_status
*rx_stats
)
1280 struct net_device
*dev
= local
->dev
;
1281 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1283 struct ap_data
*ap
= local
->ap
;
1284 char body
[8 + WLAN_AUTH_CHALLENGE_LEN
], *challenge
= NULL
;
1286 u16 auth_alg
, auth_transaction
, status_code
;
1288 u16 resp
= WLAN_STATUS_SUCCESS
;
1289 struct sta_info
*sta
= NULL
;
1290 struct lib80211_crypt_data
*crypt
;
1293 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1295 hdrlen
= hostap_80211_get_hdrlen(hdr
->frame_control
);
1298 PDEBUG(DEBUG_AP
, "%s: handle_authen - too short payload "
1299 "(len=%d) from %pM\n", dev
->name
, len
, hdr
->addr2
);
1303 spin_lock_bh(&local
->ap
->sta_table_lock
);
1304 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1306 atomic_inc(&sta
->users
);
1307 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1309 if (sta
&& sta
->crypt
)
1313 if (skb
->len
>= hdrlen
+ 3)
1314 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1315 crypt
= local
->crypt_info
.crypt
[idx
];
1318 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1319 auth_alg
= __le16_to_cpu(*pos
);
1321 auth_transaction
= __le16_to_cpu(*pos
);
1323 status_code
= __le16_to_cpu(*pos
);
1326 if (memcmp(dev
->dev_addr
, hdr
->addr2
, ETH_ALEN
) == 0 ||
1327 ap_control_mac_deny(&ap
->mac_restrictions
, hdr
->addr2
)) {
1328 txt
= "authentication denied";
1329 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1333 if (((local
->auth_algs
& PRISM2_AUTH_OPEN
) &&
1334 auth_alg
== WLAN_AUTH_OPEN
) ||
1335 ((local
->auth_algs
& PRISM2_AUTH_SHARED_KEY
) &&
1336 crypt
&& auth_alg
== WLAN_AUTH_SHARED_KEY
)) {
1338 txt
= "unsupported algorithm";
1339 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1345 if (*u
== WLAN_EID_CHALLENGE
) {
1346 if (*(u
+ 1) != WLAN_AUTH_CHALLENGE_LEN
) {
1347 txt
= "invalid challenge len";
1348 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1351 if (len
- 8 < WLAN_AUTH_CHALLENGE_LEN
) {
1352 txt
= "challenge underflow";
1353 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1356 challenge
= (char *) (u
+ 2);
1360 if (sta
&& sta
->ap
) {
1361 if (time_after(jiffies
, sta
->u
.ap
.last_beacon
+
1362 (10 * sta
->listen_interval
* HZ
) / 1024)) {
1363 PDEBUG(DEBUG_AP
, "%s: no beacons received for a while,"
1364 " assuming AP %pM is now STA\n",
1365 dev
->name
, sta
->addr
);
1368 sta
->u
.sta
.challenge
= NULL
;
1370 txt
= "AP trying to authenticate?";
1371 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1376 if ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 1) ||
1377 (auth_alg
== WLAN_AUTH_SHARED_KEY
&&
1378 (auth_transaction
== 1 ||
1379 (auth_transaction
== 3 && sta
!= NULL
&&
1380 sta
->u
.sta
.challenge
!= NULL
)))) {
1382 txt
= "unknown authentication transaction number";
1383 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1390 if (local
->ap
->num_sta
>= MAX_STA_COUNT
) {
1391 /* FIX: might try to remove some old STAs first? */
1392 txt
= "no more room for new STAs";
1393 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1397 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
1399 txt
= "ap_add_sta failed";
1400 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1406 case WLAN_AUTH_OPEN
:
1408 /* IEEE 802.11 standard is not completely clear about
1409 * whether STA is considered authenticated after
1410 * authentication OK frame has been send or after it
1411 * has been ACKed. In order to reduce interoperability
1412 * issues, mark the STA authenticated before ACK. */
1413 sta
->flags
|= WLAN_STA_AUTH
;
1416 case WLAN_AUTH_SHARED_KEY
:
1417 if (auth_transaction
== 1) {
1418 if (sta
->u
.sta
.challenge
== NULL
) {
1419 sta
->u
.sta
.challenge
=
1420 ap_auth_make_challenge(local
->ap
);
1421 if (sta
->u
.sta
.challenge
== NULL
) {
1422 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1427 if (sta
->u
.sta
.challenge
== NULL
||
1428 challenge
== NULL
||
1429 memcmp(sta
->u
.sta
.challenge
, challenge
,
1430 WLAN_AUTH_CHALLENGE_LEN
) != 0 ||
1431 !ieee80211_has_protected(hdr
->frame_control
)) {
1432 txt
= "challenge response incorrect";
1433 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1437 txt
= "challenge OK - authOK";
1438 /* IEEE 802.11 standard is not completely clear about
1439 * whether STA is considered authenticated after
1440 * authentication OK frame has been send or after it
1441 * has been ACKed. In order to reduce interoperability
1442 * issues, mark the STA authenticated before ACK. */
1443 sta
->flags
|= WLAN_STA_AUTH
;
1444 kfree(sta
->u
.sta
.challenge
);
1445 sta
->u
.sta
.challenge
= NULL
;
1451 pos
= (__le16
*) body
;
1452 *pos
= cpu_to_le16(auth_alg
);
1454 *pos
= cpu_to_le16(auth_transaction
+ 1);
1456 *pos
= cpu_to_le16(resp
); /* status_code */
1460 if (resp
== WLAN_STATUS_SUCCESS
&& sta
!= NULL
&&
1461 sta
->u
.sta
.challenge
!= NULL
&&
1462 auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 1) {
1463 u8
*tmp
= (u8
*) pos
;
1464 *tmp
++ = WLAN_EID_CHALLENGE
;
1465 *tmp
++ = WLAN_AUTH_CHALLENGE_LEN
;
1467 memcpy(pos
, sta
->u
.sta
.challenge
, WLAN_AUTH_CHALLENGE_LEN
);
1468 olen
+= 2 + WLAN_AUTH_CHALLENGE_LEN
;
1471 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_AUTH
,
1472 body
, olen
, hdr
->addr2
, ap
->tx_callback_auth
);
1475 sta
->last_rx
= jiffies
;
1476 atomic_dec(&sta
->users
);
1480 PDEBUG(DEBUG_AP
, "%s: %pM auth (alg=%d "
1481 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1482 dev
->name
, hdr
->addr2
,
1483 auth_alg
, auth_transaction
, status_code
, len
,
1484 le16_to_cpu(hdr
->frame_control
), resp
, txt
);
1489 /* Called only as a scheduled task for pending AP frames. */
1490 static void handle_assoc(local_info_t
*local
, struct sk_buff
*skb
,
1491 struct hostap_80211_rx_status
*rx_stats
, int reassoc
)
1493 struct net_device
*dev
= local
->dev
;
1494 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1495 char body
[12], *p
, *lpos
;
1498 u16 resp
= WLAN_STATUS_SUCCESS
;
1499 struct sta_info
*sta
= NULL
;
1500 int send_deauth
= 0;
1502 u8 prev_ap
[ETH_ALEN
];
1504 left
= len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1506 if (len
< (reassoc
? 10 : 4)) {
1507 PDEBUG(DEBUG_AP
, "%s: handle_assoc - too short payload "
1508 "(len=%d, reassoc=%d) from %pM\n",
1509 dev
->name
, len
, reassoc
, hdr
->addr2
);
1513 spin_lock_bh(&local
->ap
->sta_table_lock
);
1514 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1515 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
1516 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1517 txt
= "trying to associate before authentication";
1519 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1520 sta
= NULL
; /* do not decrement sta->users */
1523 atomic_inc(&sta
->users
);
1524 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1526 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1527 sta
->capability
= __le16_to_cpu(*pos
);
1529 sta
->listen_interval
= __le16_to_cpu(*pos
);
1533 memcpy(prev_ap
, pos
, ETH_ALEN
);
1534 pos
++; pos
++; pos
++; left
-= 6;
1536 memset(prev_ap
, 0, ETH_ALEN
);
1540 unsigned char *u
= (unsigned char *) pos
;
1542 if (*u
== WLAN_EID_SSID
) {
1547 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
1548 txt
= "SSID overflow";
1549 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1553 if (ileft
!= strlen(local
->essid
) ||
1554 memcmp(local
->essid
, u
, ileft
) != 0) {
1555 txt
= "not our SSID";
1556 resp
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1564 if (left
>= 2 && *u
== WLAN_EID_SUPP_RATES
) {
1569 if (ileft
> left
|| ileft
== 0 ||
1570 ileft
> WLAN_SUPP_RATES_MAX
) {
1571 txt
= "SUPP_RATES len error";
1572 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1576 memset(sta
->supported_rates
, 0,
1577 sizeof(sta
->supported_rates
));
1578 memcpy(sta
->supported_rates
, u
, ileft
);
1579 prism2_check_tx_rates(sta
);
1586 PDEBUG(DEBUG_AP
, "%s: assoc from %pM"
1587 " with extra data (%d bytes) [",
1588 dev
->name
, hdr
->addr2
, left
);
1590 PDEBUG2(DEBUG_AP
, "<%02x>", *u
);
1593 PDEBUG2(DEBUG_AP
, "]\n");
1596 txt
= "frame underflow";
1597 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1601 /* get a unique AID */
1603 txt
= "OK, old AID";
1605 spin_lock_bh(&local
->ap
->sta_table_lock
);
1606 for (sta
->aid
= 1; sta
->aid
<= MAX_AID_TABLE_SIZE
; sta
->aid
++)
1607 if (local
->ap
->sta_aid
[sta
->aid
- 1] == NULL
)
1609 if (sta
->aid
> MAX_AID_TABLE_SIZE
) {
1611 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1612 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1613 txt
= "no room for more AIDs";
1615 local
->ap
->sta_aid
[sta
->aid
- 1] = sta
;
1616 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1617 txt
= "OK, new AID";
1622 pos
= (__le16
*) body
;
1625 *pos
= cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH
);
1628 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1629 * values in beacons/probe responses */
1630 /* FIX: how about privacy and WEP? */
1632 *pos
= cpu_to_le16(WLAN_CAPABILITY_ESS
);
1636 *pos
= cpu_to_le16(resp
);
1639 *pos
= cpu_to_le16((sta
&& sta
->aid
> 0 ? sta
->aid
: 0) |
1640 BIT(14) | BIT(15)); /* AID */
1643 /* Supported rates (Information element) */
1645 *p
++ = WLAN_EID_SUPP_RATES
;
1648 if (local
->tx_rate_control
& WLAN_RATE_1M
) {
1649 *p
++ = local
->basic_rates
& WLAN_RATE_1M
? 0x82 : 0x02;
1652 if (local
->tx_rate_control
& WLAN_RATE_2M
) {
1653 *p
++ = local
->basic_rates
& WLAN_RATE_2M
? 0x84 : 0x04;
1656 if (local
->tx_rate_control
& WLAN_RATE_5M5
) {
1657 *p
++ = local
->basic_rates
& WLAN_RATE_5M5
?
1661 if (local
->tx_rate_control
& WLAN_RATE_11M
) {
1662 *p
++ = local
->basic_rates
& WLAN_RATE_11M
?
1669 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1670 (send_deauth
? IEEE80211_STYPE_DEAUTH
:
1671 (reassoc
? IEEE80211_STYPE_REASSOC_RESP
:
1672 IEEE80211_STYPE_ASSOC_RESP
)),
1673 body
, (u8
*) pos
- (u8
*) body
,
1675 send_deauth
? 0 : local
->ap
->tx_callback_assoc
);
1678 if (resp
== WLAN_STATUS_SUCCESS
) {
1679 sta
->last_rx
= jiffies
;
1680 /* STA will be marked associated from TX callback, if
1681 * AssocResp is ACKed */
1683 atomic_dec(&sta
->users
);
1687 PDEBUG(DEBUG_AP
, "%s: %pM %sassoc (len=%d "
1688 "prev_ap=%pM) => %d(%d) (%s)\n",
1691 reassoc
? "re" : "", len
,
1693 resp
, send_deauth
, txt
);
1698 /* Called only as a scheduled task for pending AP frames. */
1699 static void handle_deauth(local_info_t
*local
, struct sk_buff
*skb
,
1700 struct hostap_80211_rx_status
*rx_stats
)
1702 struct net_device
*dev
= local
->dev
;
1703 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1704 char *body
= (char *) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1708 struct sta_info
*sta
= NULL
;
1710 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1713 printk("handle_deauth - too short payload (len=%d)\n", len
);
1717 pos
= (__le16
*) body
;
1718 reason_code
= le16_to_cpu(*pos
);
1720 PDEBUG(DEBUG_AP
, "%s: deauthentication: %pM len=%d, "
1721 "reason_code=%d\n", dev
->name
, hdr
->addr2
,
1724 spin_lock_bh(&local
->ap
->sta_table_lock
);
1725 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1727 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1728 hostap_event_expired_sta(local
->dev
, sta
);
1729 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
1731 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1733 printk("%s: deauthentication from %pM, "
1734 "reason_code=%d, but STA not authenticated\n", dev
->name
,
1735 hdr
->addr2
, reason_code
);
1740 /* Called only as a scheduled task for pending AP frames. */
1741 static void handle_disassoc(local_info_t
*local
, struct sk_buff
*skb
,
1742 struct hostap_80211_rx_status
*rx_stats
)
1744 struct net_device
*dev
= local
->dev
;
1745 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1746 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
1750 struct sta_info
*sta
= NULL
;
1752 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1755 printk("handle_disassoc - too short payload (len=%d)\n", len
);
1759 pos
= (__le16
*) body
;
1760 reason_code
= le16_to_cpu(*pos
);
1762 PDEBUG(DEBUG_AP
, "%s: disassociation: %pM len=%d, "
1763 "reason_code=%d\n", dev
->name
, hdr
->addr2
,
1766 spin_lock_bh(&local
->ap
->sta_table_lock
);
1767 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1769 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1770 hostap_event_expired_sta(local
->dev
, sta
);
1771 sta
->flags
&= ~WLAN_STA_ASSOC
;
1773 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1775 printk("%s: disassociation from %pM, "
1776 "reason_code=%d, but STA not authenticated\n",
1777 dev
->name
, hdr
->addr2
, reason_code
);
1782 /* Called only as a scheduled task for pending AP frames. */
1783 static void ap_handle_data_nullfunc(local_info_t
*local
,
1784 struct ieee80211_hdr
*hdr
)
1786 struct net_device
*dev
= local
->dev
;
1788 /* some STA f/w's seem to require control::ACK frame for
1789 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1791 * send control::ACK for the data::nullfunc */
1793 printk(KERN_DEBUG
"Sending control::ACK for data::nullfunc\n");
1794 prism2_send_mgmt(dev
, IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_ACK
,
1795 NULL
, 0, hdr
->addr2
, 0);
1799 /* Called only as a scheduled task for pending AP frames. */
1800 static void ap_handle_dropped_data(local_info_t
*local
,
1801 struct ieee80211_hdr
*hdr
)
1803 struct net_device
*dev
= local
->dev
;
1804 struct sta_info
*sta
;
1807 spin_lock_bh(&local
->ap
->sta_table_lock
);
1808 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1810 atomic_inc(&sta
->users
);
1811 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1813 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
)) {
1814 PDEBUG(DEBUG_AP
, "ap_handle_dropped_data: STA is now okay?\n");
1815 atomic_dec(&sta
->users
);
1819 reason
= cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
1820 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1821 ((sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) ?
1822 IEEE80211_STYPE_DEAUTH
: IEEE80211_STYPE_DISASSOC
),
1823 (char *) &reason
, sizeof(reason
), hdr
->addr2
, 0);
1826 atomic_dec(&sta
->users
);
1829 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1832 /* Called only as a scheduled task for pending AP frames. */
1833 static void pspoll_send_buffered(local_info_t
*local
, struct sta_info
*sta
,
1834 struct sk_buff
*skb
)
1836 struct hostap_skb_tx_data
*meta
;
1838 if (!(sta
->flags
& WLAN_STA_PS
)) {
1839 /* Station has moved to non-PS mode, so send all buffered
1840 * frames using normal device queue. */
1841 dev_queue_xmit(skb
);
1845 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1846 * be passed through even though STA is using PS */
1847 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1848 meta
->flags
|= HOSTAP_TX_FLAGS_BUFFERED_FRAME
;
1849 if (!skb_queue_empty(&sta
->tx_buf
)) {
1850 /* indicate to STA that more frames follow */
1851 meta
->flags
|= HOSTAP_TX_FLAGS_ADD_MOREDATA
;
1853 dev_queue_xmit(skb
);
1857 /* Called only as a scheduled task for pending AP frames. */
1858 static void handle_pspoll(local_info_t
*local
,
1859 struct ieee80211_hdr
*hdr
,
1860 struct hostap_80211_rx_status
*rx_stats
)
1862 struct net_device
*dev
= local
->dev
;
1863 struct sta_info
*sta
;
1865 struct sk_buff
*skb
;
1867 PDEBUG(DEBUG_PS2
, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1868 hdr
->addr1
, hdr
->addr2
, !!ieee80211_has_pm(hdr
->frame_control
));
1870 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
1872 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1877 aid
= le16_to_cpu(hdr
->duration_id
);
1878 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1879 PDEBUG(DEBUG_PS
, " PSPOLL and AID[15:14] not set\n");
1882 aid
&= ~(BIT(15) | BIT(14));
1883 if (aid
== 0 || aid
> MAX_AID_TABLE_SIZE
) {
1884 PDEBUG(DEBUG_PS
, " invalid aid=%d\n", aid
);
1887 PDEBUG(DEBUG_PS2
, " aid=%d\n", aid
);
1889 spin_lock_bh(&local
->ap
->sta_table_lock
);
1890 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1892 atomic_inc(&sta
->users
);
1893 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1896 PDEBUG(DEBUG_PS
, " STA not found\n");
1899 if (sta
->aid
!= aid
) {
1900 PDEBUG(DEBUG_PS
, " received aid=%i does not match with "
1901 "assoc.aid=%d\n", aid
, sta
->aid
);
1906 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1907 * out (expiry time must be longer than ListenInterval for
1908 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1909 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1910 * sta; store buffer for later use and leave TIM aid bit set? use
1911 * TX event to check whether frame was ACKed?
1914 while ((skb
= skb_dequeue(&sta
->tx_buf
)) != NULL
) {
1915 /* send buffered frame .. */
1916 PDEBUG(DEBUG_PS2
, "Sending buffered frame to STA after PS POLL"
1917 " (buffer_count=%d)\n", skb_queue_len(&sta
->tx_buf
));
1919 pspoll_send_buffered(local
, sta
, skb
);
1921 if (sta
->flags
& WLAN_STA_PS
) {
1922 /* send only one buffered packet per PS Poll */
1923 /* FIX: should ignore further PS Polls until the
1924 * buffered packet that was just sent is acknowledged
1925 * (Tx or TxExc event) */
1930 if (skb_queue_empty(&sta
->tx_buf
)) {
1931 /* try to clear aid from TIM */
1932 if (!(sta
->flags
& WLAN_STA_TIM
))
1933 PDEBUG(DEBUG_PS2
, "Re-unsetting TIM for aid %d\n",
1935 hostap_set_tim(local
, aid
, 0);
1936 sta
->flags
&= ~WLAN_STA_TIM
;
1939 atomic_dec(&sta
->users
);
1943 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1945 static void handle_wds_oper_queue(struct work_struct
*work
)
1947 struct ap_data
*ap
= container_of(work
, struct ap_data
,
1949 local_info_t
*local
= ap
->local
;
1950 struct wds_oper_data
*entry
, *prev
;
1952 spin_lock_bh(&local
->lock
);
1953 entry
= local
->ap
->wds_oper_entries
;
1954 local
->ap
->wds_oper_entries
= NULL
;
1955 spin_unlock_bh(&local
->lock
);
1958 PDEBUG(DEBUG_AP
, "%s: %s automatic WDS connection "
1961 entry
->type
== WDS_ADD
? "adding" : "removing",
1963 if (entry
->type
== WDS_ADD
)
1964 prism2_wds_add(local
, entry
->addr
, 0);
1965 else if (entry
->type
== WDS_DEL
)
1966 prism2_wds_del(local
, entry
->addr
, 0, 1);
1969 entry
= entry
->next
;
1975 /* Called only as a scheduled task for pending AP frames. */
1976 static void handle_beacon(local_info_t
*local
, struct sk_buff
*skb
,
1977 struct hostap_80211_rx_status
*rx_stats
)
1979 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1980 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
1982 u16 beacon_int
, capability
;
1985 unsigned char *supp_rates
= NULL
;
1986 int ssid_len
= 0, supp_rates_len
= 0;
1987 struct sta_info
*sta
= NULL
;
1988 int new_sta
= 0, channel
= -1;
1990 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1992 if (len
< 8 + 2 + 2) {
1993 printk(KERN_DEBUG
"handle_beacon - too short payload "
1998 pos
= (__le16
*) body
;
2001 /* Timestamp (8 octets) */
2002 pos
+= 4; left
-= 8;
2003 /* Beacon interval (2 octets) */
2004 beacon_int
= le16_to_cpu(*pos
);
2006 /* Capability information (2 octets) */
2007 capability
= le16_to_cpu(*pos
);
2010 if (local
->ap
->ap_policy
!= AP_OTHER_AP_EVEN_IBSS
&&
2011 capability
& WLAN_CAPABILITY_IBSS
)
2016 unsigned char *u
= (unsigned char *) pos
;
2018 if (*u
== WLAN_EID_SSID
) {
2023 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
2024 PDEBUG(DEBUG_AP
, "SSID: overflow\n");
2028 if (local
->ap
->ap_policy
== AP_OTHER_AP_SAME_SSID
&&
2029 (ileft
!= strlen(local
->essid
) ||
2030 memcmp(local
->essid
, u
, ileft
) != 0)) {
2042 if (*u
== WLAN_EID_SUPP_RATES
) {
2047 if (ileft
> left
|| ileft
== 0 || ileft
> 8) {
2048 PDEBUG(DEBUG_AP
, " - SUPP_RATES len error\n");
2053 supp_rates_len
= ileft
;
2059 if (*u
== WLAN_EID_DS_PARAMS
) {
2064 if (ileft
> left
|| ileft
!= 1) {
2065 PDEBUG(DEBUG_AP
, " - DS_PARAMS len error\n");
2076 spin_lock_bh(&local
->ap
->sta_table_lock
);
2077 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2079 atomic_inc(&sta
->users
);
2080 spin_unlock_bh(&local
->ap
->sta_table_lock
);
2085 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
2087 printk(KERN_INFO
"prism2: kmalloc failed for AP "
2088 "data structure\n");
2091 hostap_event_new_sta(local
->dev
, sta
);
2093 /* mark APs authentication and associated for pseudo ad-hoc
2094 * style communication */
2095 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2097 if (local
->ap
->autom_ap_wds
) {
2098 hostap_wds_link_oper(local
, sta
->addr
, WDS_ADD
);
2104 sta
->u
.ap
.ssid_len
= ssid_len
;
2105 memcpy(sta
->u
.ap
.ssid
, ssid
, ssid_len
);
2106 sta
->u
.ap
.ssid
[ssid_len
] = '\0';
2108 sta
->u
.ap
.ssid_len
= 0;
2109 sta
->u
.ap
.ssid
[0] = '\0';
2111 sta
->u
.ap
.channel
= channel
;
2113 sta
->rx_bytes
+= len
;
2114 sta
->u
.ap
.last_beacon
= sta
->last_rx
= jiffies
;
2115 sta
->capability
= capability
;
2116 sta
->listen_interval
= beacon_int
;
2118 atomic_dec(&sta
->users
);
2121 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
2122 memcpy(sta
->supported_rates
, supp_rates
, supp_rates_len
);
2123 prism2_check_tx_rates(sta
);
2127 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2130 /* Called only as a tasklet. */
2131 static void handle_ap_item(local_info_t
*local
, struct sk_buff
*skb
,
2132 struct hostap_80211_rx_status
*rx_stats
)
2134 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2135 struct net_device
*dev
= local
->dev
;
2136 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2137 u16 fc
, type
, stype
;
2138 struct ieee80211_hdr
*hdr
;
2140 /* FIX: should give skb->len to handler functions and check that the
2141 * buffer is long enough */
2142 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2143 fc
= le16_to_cpu(hdr
->frame_control
);
2144 type
= fc
& IEEE80211_FCTL_FTYPE
;
2145 stype
= fc
& IEEE80211_FCTL_STYPE
;
2147 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2148 if (!local
->hostapd
&& type
== IEEE80211_FTYPE_DATA
) {
2149 PDEBUG(DEBUG_AP
, "handle_ap_item - data frame\n");
2151 if (!(fc
& IEEE80211_FCTL_TODS
) ||
2152 (fc
& IEEE80211_FCTL_FROMDS
)) {
2153 if (stype
== IEEE80211_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)=%pM"
2167 " not own MAC\n", hdr
->addr1
);
2171 if (local
->ap
->nullfunc_ack
&&
2172 stype
== IEEE80211_STYPE_NULLFUNC
)
2173 ap_handle_data_nullfunc(local
, hdr
);
2175 ap_handle_dropped_data(local
, hdr
);
2179 if (type
== IEEE80211_FTYPE_MGMT
&& stype
== IEEE80211_STYPE_BEACON
) {
2180 handle_beacon(local
, skb
, rx_stats
);
2183 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2185 if (type
== IEEE80211_FTYPE_CTL
&& stype
== IEEE80211_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
!= IEEE80211_FTYPE_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)=%pM"
2204 " not own MAC\n", hdr
->addr1
);
2208 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
)) {
2209 PDEBUG(DEBUG_AP
, "handle_ap_item - addr3(BSSID)=%pM"
2210 " not own MAC\n", hdr
->addr3
);
2215 case IEEE80211_STYPE_ASSOC_REQ
:
2216 handle_assoc(local
, skb
, rx_stats
, 0);
2218 case IEEE80211_STYPE_ASSOC_RESP
:
2219 PDEBUG(DEBUG_AP
, "==> ASSOC RESP (ignored)\n");
2221 case IEEE80211_STYPE_REASSOC_REQ
:
2222 handle_assoc(local
, skb
, rx_stats
, 1);
2224 case IEEE80211_STYPE_REASSOC_RESP
:
2225 PDEBUG(DEBUG_AP
, "==> REASSOC RESP (ignored)\n");
2227 case IEEE80211_STYPE_ATIM
:
2228 PDEBUG(DEBUG_AP
, "==> ATIM (ignored)\n");
2230 case IEEE80211_STYPE_DISASSOC
:
2231 handle_disassoc(local
, skb
, rx_stats
);
2233 case IEEE80211_STYPE_AUTH
:
2234 handle_authen(local
, skb
, rx_stats
);
2236 case IEEE80211_STYPE_DEAUTH
:
2237 handle_deauth(local
, skb
, rx_stats
);
2240 PDEBUG(DEBUG_AP
, "Unknown mgmt frame subtype 0x%02x\n",
2244 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2251 /* Called only as a tasklet (software IRQ) */
2252 void hostap_rx(struct net_device
*dev
, struct sk_buff
*skb
,
2253 struct hostap_80211_rx_status
*rx_stats
)
2255 struct hostap_interface
*iface
;
2256 local_info_t
*local
;
2257 struct ieee80211_hdr
*hdr
;
2259 iface
= netdev_priv(dev
);
2260 local
= iface
->local
;
2265 dev
->stats
.rx_packets
++;
2267 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2269 if (local
->ap
->ap_policy
== AP_OTHER_AP_SKIP_ALL
&&
2270 ieee80211_is_beacon(hdr
->frame_control
))
2273 skb
->protocol
= cpu_to_be16(ETH_P_HOSTAP
);
2274 handle_ap_item(local
, skb
, rx_stats
);
2282 /* Called only as a tasklet (software IRQ) */
2283 static void schedule_packet_send(local_info_t
*local
, struct sta_info
*sta
)
2285 struct sk_buff
*skb
;
2286 struct ieee80211_hdr
*hdr
;
2287 struct hostap_80211_rx_status rx_stats
;
2289 if (skb_queue_empty(&sta
->tx_buf
))
2292 skb
= dev_alloc_skb(16);
2294 printk(KERN_DEBUG
"%s: schedule_packet_send: skb alloc "
2295 "failed\n", local
->dev
->name
);
2299 hdr
= (struct ieee80211_hdr
*) skb_put(skb
, 16);
2301 /* Generate a fake pspoll frame to start packet delivery */
2302 hdr
->frame_control
= cpu_to_le16(
2303 IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_PSPOLL
);
2304 memcpy(hdr
->addr1
, local
->dev
->dev_addr
, ETH_ALEN
);
2305 memcpy(hdr
->addr2
, sta
->addr
, ETH_ALEN
);
2306 hdr
->duration_id
= cpu_to_le16(sta
->aid
| BIT(15) | BIT(14));
2309 "%s: Scheduling buffered packet delivery for STA %pM\n",
2310 local
->dev
->name
, sta
->addr
);
2312 skb
->dev
= local
->dev
;
2314 memset(&rx_stats
, 0, sizeof(rx_stats
));
2315 hostap_rx(local
->dev
, skb
, &rx_stats
);
2319 int prism2_ap_get_sta_qual(local_info_t
*local
, struct sockaddr addr
[],
2320 struct iw_quality qual
[], int buf_size
,
2323 struct ap_data
*ap
= local
->ap
;
2324 struct list_head
*ptr
;
2327 spin_lock_bh(&ap
->sta_table_lock
);
2329 for (ptr
= ap
->sta_list
.next
; ptr
!= NULL
&& ptr
!= &ap
->sta_list
;
2331 struct sta_info
*sta
= (struct sta_info
*) ptr
;
2333 if (aplist
&& !sta
->ap
)
2335 addr
[count
].sa_family
= ARPHRD_ETHER
;
2336 memcpy(addr
[count
].sa_data
, sta
->addr
, ETH_ALEN
);
2337 if (sta
->last_rx_silence
== 0)
2338 qual
[count
].qual
= sta
->last_rx_signal
< 27 ?
2339 0 : (sta
->last_rx_signal
- 27) * 92 / 127;
2341 qual
[count
].qual
= sta
->last_rx_signal
-
2342 sta
->last_rx_silence
- 35;
2343 qual
[count
].level
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_signal
);
2344 qual
[count
].noise
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_silence
);
2345 qual
[count
].updated
= sta
->last_rx_updated
;
2347 sta
->last_rx_updated
= IW_QUAL_DBM
;
2350 if (count
>= buf_size
)
2353 spin_unlock_bh(&ap
->sta_table_lock
);
2359 /* Translate our list of Access Points & Stations to a card independant
2360 * format that the Wireless Tools will understand - Jean II */
2361 int prism2_ap_translate_scan(struct net_device
*dev
,
2362 struct iw_request_info
*info
, 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(info
, current_ev
, end_buf
,
2392 &iwe
, IW_EV_ADDR_LEN
);
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(info
, current_ev
, end_buf
,
2404 &iwe
, IW_EV_UINT_LEN
);
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(info
, current_ev
, end_buf
,
2420 &iwe
, IW_EV_QUAL_LEN
);
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(info
, current_ev
,
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(info
, current_ev
,
2443 if (sta
->u
.ap
.channel
> 0 &&
2444 sta
->u
.ap
.channel
<= FREQ_COUNT
) {
2445 memset(&iwe
, 0, sizeof(iwe
));
2446 iwe
.cmd
= SIOCGIWFREQ
;
2447 iwe
.u
.freq
.m
= freq_list
[sta
->u
.ap
.channel
- 1]
2450 current_ev
= iwe_stream_add_event(
2451 info
, current_ev
, end_buf
, &iwe
,
2455 memset(&iwe
, 0, sizeof(iwe
));
2456 iwe
.cmd
= IWEVCUSTOM
;
2457 sprintf(buf
, "beacon_interval=%d",
2458 sta
->listen_interval
);
2459 iwe
.u
.data
.length
= strlen(buf
);
2460 current_ev
= iwe_stream_add_point(info
, current_ev
,
2461 end_buf
, &iwe
, buf
);
2463 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2465 sta
->last_rx_updated
= IW_QUAL_DBM
;
2467 /* To be continued, we should make good use of IWEVCUSTOM */
2470 spin_unlock_bh(&ap
->sta_table_lock
);
2472 return current_ev
- buffer
;
2476 static int prism2_hostapd_add_sta(struct ap_data
*ap
,
2477 struct prism2_hostapd_param
*param
)
2479 struct sta_info
*sta
;
2481 spin_lock_bh(&ap
->sta_table_lock
);
2482 sta
= ap_get_sta(ap
, param
->sta_addr
);
2484 atomic_inc(&sta
->users
);
2485 spin_unlock_bh(&ap
->sta_table_lock
);
2488 sta
= ap_add_sta(ap
, param
->sta_addr
);
2493 if (!(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2494 hostap_event_new_sta(sta
->local
->dev
, sta
);
2496 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2497 sta
->last_rx
= jiffies
;
2498 sta
->aid
= param
->u
.add_sta
.aid
;
2499 sta
->capability
= param
->u
.add_sta
.capability
;
2500 sta
->tx_supp_rates
= param
->u
.add_sta
.tx_supp_rates
;
2501 if (sta
->tx_supp_rates
& WLAN_RATE_1M
)
2502 sta
->supported_rates
[0] = 2;
2503 if (sta
->tx_supp_rates
& WLAN_RATE_2M
)
2504 sta
->supported_rates
[1] = 4;
2505 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
)
2506 sta
->supported_rates
[2] = 11;
2507 if (sta
->tx_supp_rates
& WLAN_RATE_11M
)
2508 sta
->supported_rates
[3] = 22;
2509 prism2_check_tx_rates(sta
);
2510 atomic_dec(&sta
->users
);
2515 static int prism2_hostapd_remove_sta(struct ap_data
*ap
,
2516 struct prism2_hostapd_param
*param
)
2518 struct sta_info
*sta
;
2520 spin_lock_bh(&ap
->sta_table_lock
);
2521 sta
= ap_get_sta(ap
, param
->sta_addr
);
2523 ap_sta_hash_del(ap
, sta
);
2524 list_del(&sta
->list
);
2526 spin_unlock_bh(&ap
->sta_table_lock
);
2531 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2532 hostap_event_expired_sta(sta
->local
->dev
, sta
);
2533 ap_free_sta(ap
, sta
);
2539 static int prism2_hostapd_get_info_sta(struct ap_data
*ap
,
2540 struct prism2_hostapd_param
*param
)
2542 struct sta_info
*sta
;
2544 spin_lock_bh(&ap
->sta_table_lock
);
2545 sta
= ap_get_sta(ap
, param
->sta_addr
);
2547 atomic_inc(&sta
->users
);
2548 spin_unlock_bh(&ap
->sta_table_lock
);
2553 param
->u
.get_info_sta
.inactive_sec
= (jiffies
- sta
->last_rx
) / HZ
;
2555 atomic_dec(&sta
->users
);
2561 static int prism2_hostapd_set_flags_sta(struct ap_data
*ap
,
2562 struct prism2_hostapd_param
*param
)
2564 struct sta_info
*sta
;
2566 spin_lock_bh(&ap
->sta_table_lock
);
2567 sta
= ap_get_sta(ap
, param
->sta_addr
);
2569 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
2570 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
2572 spin_unlock_bh(&ap
->sta_table_lock
);
2581 static int prism2_hostapd_sta_clear_stats(struct ap_data
*ap
,
2582 struct prism2_hostapd_param
*param
)
2584 struct sta_info
*sta
;
2587 spin_lock_bh(&ap
->sta_table_lock
);
2588 sta
= ap_get_sta(ap
, param
->sta_addr
);
2590 sta
->rx_packets
= sta
->tx_packets
= 0;
2591 sta
->rx_bytes
= sta
->tx_bytes
= 0;
2592 for (rate
= 0; rate
< WLAN_RATE_COUNT
; rate
++) {
2593 sta
->tx_count
[rate
] = 0;
2594 sta
->rx_count
[rate
] = 0;
2597 spin_unlock_bh(&ap
->sta_table_lock
);
2606 int prism2_hostapd(struct ap_data
*ap
, struct prism2_hostapd_param
*param
)
2608 switch (param
->cmd
) {
2609 case PRISM2_HOSTAPD_FLUSH
:
2610 ap_control_kickall(ap
);
2612 case PRISM2_HOSTAPD_ADD_STA
:
2613 return prism2_hostapd_add_sta(ap
, param
);
2614 case PRISM2_HOSTAPD_REMOVE_STA
:
2615 return prism2_hostapd_remove_sta(ap
, param
);
2616 case PRISM2_HOSTAPD_GET_INFO_STA
:
2617 return prism2_hostapd_get_info_sta(ap
, param
);
2618 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
2619 return prism2_hostapd_set_flags_sta(ap
, param
);
2620 case PRISM2_HOSTAPD_STA_CLEAR_STATS
:
2621 return prism2_hostapd_sta_clear_stats(ap
, param
);
2623 printk(KERN_WARNING
"prism2_hostapd: unknown cmd=%d\n",
2630 /* Update station info for host-based TX rate control and return current
2632 static int ap_update_sta_tx_rate(struct sta_info
*sta
, struct net_device
*dev
)
2634 int ret
= sta
->tx_rate
;
2635 struct hostap_interface
*iface
;
2636 local_info_t
*local
;
2638 iface
= netdev_priv(dev
);
2639 local
= iface
->local
;
2641 sta
->tx_count
[sta
->tx_rate_idx
]++;
2642 sta
->tx_since_last_failure
++;
2643 sta
->tx_consecutive_exc
= 0;
2644 if (sta
->tx_since_last_failure
>= WLAN_RATE_UPDATE_COUNT
&&
2645 sta
->tx_rate_idx
< sta
->tx_max_rate
) {
2646 /* use next higher rate */
2647 int old_rate
, new_rate
;
2648 old_rate
= new_rate
= sta
->tx_rate_idx
;
2649 while (new_rate
< sta
->tx_max_rate
) {
2651 if (ap_tx_rate_ok(new_rate
, sta
, local
)) {
2652 sta
->tx_rate_idx
= new_rate
;
2656 if (old_rate
!= sta
->tx_rate_idx
) {
2657 switch (sta
->tx_rate_idx
) {
2658 case 0: sta
->tx_rate
= 10; break;
2659 case 1: sta
->tx_rate
= 20; break;
2660 case 2: sta
->tx_rate
= 55; break;
2661 case 3: sta
->tx_rate
= 110; break;
2662 default: sta
->tx_rate
= 0; break;
2664 PDEBUG(DEBUG_AP
, "%s: STA %pM TX rate raised to %d\n",
2665 dev
->name
, sta
->addr
, sta
->tx_rate
);
2667 sta
->tx_since_last_failure
= 0;
2674 /* Called only from software IRQ. Called for each TX frame prior possible
2675 * encryption and transmit. */
2676 ap_tx_ret
hostap_handle_sta_tx(local_info_t
*local
, struct hostap_tx_data
*tx
)
2678 struct sta_info
*sta
= NULL
;
2679 struct sk_buff
*skb
= tx
->skb
;
2681 struct ieee80211_hdr
*hdr
;
2682 struct hostap_skb_tx_data
*meta
;
2684 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2685 ret
= AP_TX_CONTINUE
;
2686 if (local
->ap
== NULL
|| skb
->len
< 10 ||
2687 meta
->iface
->type
== HOSTAP_INTERFACE_STA
)
2690 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2692 if (hdr
->addr1
[0] & 0x01) {
2693 /* broadcast/multicast frame - no AP related processing */
2694 if (local
->ap
->num_sta
<= 0)
2699 /* unicast packet - check whether destination STA is associated */
2700 spin_lock(&local
->ap
->sta_table_lock
);
2701 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2703 atomic_inc(&sta
->users
);
2704 spin_unlock(&local
->ap
->sta_table_lock
);
2706 if (local
->iw_mode
== IW_MODE_MASTER
&& sta
== NULL
&&
2707 !(meta
->flags
& HOSTAP_TX_FLAGS_WDS
) &&
2708 meta
->iface
->type
!= HOSTAP_INTERFACE_MASTER
&&
2709 meta
->iface
->type
!= HOSTAP_INTERFACE_AP
) {
2711 /* This can happen, e.g., when wlan0 is added to a bridge and
2712 * bridging code does not know which port is the correct target
2713 * for a unicast frame. In this case, the packet is send to all
2714 * ports of the bridge. Since this is a valid scenario, do not
2715 * print out any errors here. */
2716 if (net_ratelimit()) {
2717 printk(KERN_DEBUG
"AP: drop packet to non-associated "
2718 "STA %pM\n", hdr
->addr1
);
2721 local
->ap
->tx_drop_nonassoc
++;
2729 if (!(sta
->flags
& WLAN_STA_AUTHORIZED
))
2730 ret
= AP_TX_CONTINUE_NOT_AUTHORIZED
;
2732 /* Set tx_rate if using host-based TX rate control */
2733 if (!local
->fw_tx_rate_control
)
2734 local
->ap
->last_tx_rate
= meta
->rate
=
2735 ap_update_sta_tx_rate(sta
, local
->dev
);
2737 if (local
->iw_mode
!= IW_MODE_MASTER
)
2740 if (!(sta
->flags
& WLAN_STA_PS
))
2743 if (meta
->flags
& HOSTAP_TX_FLAGS_ADD_MOREDATA
) {
2744 /* indicate to STA that more frames follow */
2745 hdr
->frame_control
|=
2746 cpu_to_le16(IEEE80211_FCTL_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 (%pM)'s"
2758 local
->dev
->name
, sta
->addr
);
2759 /* Make sure that TIM is set for the station (it might not be
2760 * after AP wlan hw reset). */
2761 /* FIX: should fix hw reset to restore bits based on STA
2763 hostap_set_tim(local
, sta
->aid
, 1);
2764 sta
->flags
|= WLAN_STA_TIM
;
2769 /* STA in PS mode, buffer frame for later delivery */
2770 set_tim
= skb_queue_empty(&sta
->tx_buf
);
2771 skb_queue_tail(&sta
->tx_buf
, skb
);
2772 /* FIX: could save RX time to skb and expire buffered frames after
2773 * some time if STA does not poll for them */
2776 if (sta
->flags
& WLAN_STA_TIM
)
2777 PDEBUG(DEBUG_PS2
, "Re-setting TIM for aid %d\n",
2779 hostap_set_tim(local
, sta
->aid
, 1);
2780 sta
->flags
|= WLAN_STA_TIM
;
2783 ret
= AP_TX_BUFFERED
;
2787 if (ret
== AP_TX_CONTINUE
||
2788 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) {
2790 sta
->tx_bytes
+= skb
->len
;
2791 sta
->last_tx
= jiffies
;
2794 if ((ret
== AP_TX_CONTINUE
||
2795 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) &&
2796 sta
->crypt
&& tx
->host_encrypt
) {
2797 tx
->crypt
= sta
->crypt
;
2798 tx
->sta_ptr
= sta
; /* hostap_handle_sta_release() will
2799 * be called to release sta info
2802 atomic_dec(&sta
->users
);
2809 void hostap_handle_sta_release(void *ptr
)
2811 struct sta_info
*sta
= ptr
;
2812 atomic_dec(&sta
->users
);
2816 /* Called only as a tasklet (software IRQ) */
2817 void hostap_handle_sta_tx_exc(local_info_t
*local
, struct sk_buff
*skb
)
2819 struct sta_info
*sta
;
2820 struct ieee80211_hdr
*hdr
;
2821 struct hostap_skb_tx_data
*meta
;
2823 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2824 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2826 spin_lock(&local
->ap
->sta_table_lock
);
2827 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2829 spin_unlock(&local
->ap
->sta_table_lock
);
2830 PDEBUG(DEBUG_AP
, "%s: Could not find STA %pM"
2831 " for this TX error (@%lu)\n",
2832 local
->dev
->name
, hdr
->addr1
, jiffies
);
2836 sta
->tx_since_last_failure
= 0;
2837 sta
->tx_consecutive_exc
++;
2839 if (sta
->tx_consecutive_exc
>= WLAN_RATE_DECREASE_THRESHOLD
&&
2840 sta
->tx_rate_idx
> 0 && meta
->rate
<= sta
->tx_rate
) {
2841 /* use next lower rate */
2843 old
= rate
= sta
->tx_rate_idx
;
2846 if (ap_tx_rate_ok(rate
, sta
, local
)) {
2847 sta
->tx_rate_idx
= rate
;
2851 if (old
!= sta
->tx_rate_idx
) {
2852 switch (sta
->tx_rate_idx
) {
2853 case 0: sta
->tx_rate
= 10; break;
2854 case 1: sta
->tx_rate
= 20; break;
2855 case 2: sta
->tx_rate
= 55; break;
2856 case 3: sta
->tx_rate
= 110; break;
2857 default: sta
->tx_rate
= 0; break;
2860 "%s: STA %pM TX rate lowered to %d\n",
2861 local
->dev
->name
, sta
->addr
, sta
->tx_rate
);
2863 sta
->tx_consecutive_exc
= 0;
2865 spin_unlock(&local
->ap
->sta_table_lock
);
2869 static void hostap_update_sta_ps2(local_info_t
*local
, struct sta_info
*sta
,
2870 int pwrmgt
, int type
, int stype
)
2872 if (pwrmgt
&& !(sta
->flags
& WLAN_STA_PS
)) {
2873 sta
->flags
|= WLAN_STA_PS
;
2874 PDEBUG(DEBUG_PS2
, "STA %pM changed to use PS "
2875 "mode (type=0x%02X, stype=0x%02X)\n",
2876 sta
->addr
, type
>> 2, stype
>> 4);
2877 } else if (!pwrmgt
&& (sta
->flags
& WLAN_STA_PS
)) {
2878 sta
->flags
&= ~WLAN_STA_PS
;
2879 PDEBUG(DEBUG_PS2
, "STA %pM changed to not use "
2880 "PS mode (type=0x%02X, stype=0x%02X)\n",
2881 sta
->addr
, type
>> 2, stype
>> 4);
2882 if (type
!= IEEE80211_FTYPE_CTL
||
2883 stype
!= IEEE80211_STYPE_PSPOLL
)
2884 schedule_packet_send(local
, sta
);
2889 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2890 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2891 int hostap_update_sta_ps(local_info_t
*local
, struct ieee80211_hdr
*hdr
)
2893 struct sta_info
*sta
;
2896 spin_lock(&local
->ap
->sta_table_lock
);
2897 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2899 atomic_inc(&sta
->users
);
2900 spin_unlock(&local
->ap
->sta_table_lock
);
2905 fc
= le16_to_cpu(hdr
->frame_control
);
2906 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
2907 fc
& IEEE80211_FCTL_FTYPE
,
2908 fc
& IEEE80211_FCTL_STYPE
);
2910 atomic_dec(&sta
->users
);
2915 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2916 * getting RX header and payload from hardware. */
2917 ap_rx_ret
hostap_handle_sta_rx(local_info_t
*local
, struct net_device
*dev
,
2918 struct sk_buff
*skb
,
2919 struct hostap_80211_rx_status
*rx_stats
,
2923 struct sta_info
*sta
;
2924 u16 fc
, type
, stype
;
2925 struct ieee80211_hdr
*hdr
;
2927 if (local
->ap
== NULL
)
2928 return AP_RX_CONTINUE
;
2930 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2932 fc
= le16_to_cpu(hdr
->frame_control
);
2933 type
= fc
& IEEE80211_FCTL_FTYPE
;
2934 stype
= fc
& IEEE80211_FCTL_STYPE
;
2936 spin_lock(&local
->ap
->sta_table_lock
);
2937 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2939 atomic_inc(&sta
->users
);
2940 spin_unlock(&local
->ap
->sta_table_lock
);
2942 if (sta
&& !(sta
->flags
& WLAN_STA_AUTHORIZED
))
2943 ret
= AP_RX_CONTINUE_NOT_AUTHORIZED
;
2945 ret
= AP_RX_CONTINUE
;
2948 if (fc
& IEEE80211_FCTL_TODS
) {
2949 if (!wds
&& (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
2950 if (local
->hostapd
) {
2951 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
2952 PRISM2_RX_NON_ASSOC
);
2953 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2955 printk(KERN_DEBUG
"%s: dropped received packet"
2956 " from non-associated STA %pM"
2957 " (type=0x%02x, subtype=0x%02x)\n",
2958 dev
->name
, hdr
->addr2
,
2959 type
>> 2, stype
>> 4);
2960 hostap_rx(dev
, skb
, rx_stats
);
2961 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2966 } else if (fc
& IEEE80211_FCTL_FROMDS
) {
2968 /* FromDS frame - not for us; probably
2969 * broadcast/multicast in another BSS - drop */
2970 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
2971 printk(KERN_DEBUG
"Odd.. FromDS packet "
2972 "received with own BSSID\n");
2973 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
2978 } else if (stype
== IEEE80211_STYPE_NULLFUNC
&& sta
== NULL
&&
2979 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
2981 if (local
->hostapd
) {
2982 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
2983 PRISM2_RX_NON_ASSOC
);
2984 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2986 /* At least Lucent f/w seems to send data::nullfunc
2987 * frames with no ToDS flag when the current AP returns
2988 * after being unavailable for some time. Speed up
2989 * re-association by informing the station about it not
2990 * being associated. */
2991 printk(KERN_DEBUG
"%s: rejected received nullfunc frame"
2992 " without ToDS from not associated STA %pM\n",
2993 dev
->name
, hdr
->addr2
);
2994 hostap_rx(dev
, skb
, rx_stats
);
2995 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2999 } else if (stype
== IEEE80211_STYPE_NULLFUNC
) {
3000 /* At least Lucent cards seem to send periodic nullfunc
3001 * frames with ToDS. Let these through to update SQ
3002 * stats and PS state. Nullfunc frames do not contain
3003 * any data and they will be dropped below. */
3005 /* If BSSID (Addr3) is foreign, this frame is a normal
3006 * broadcast frame from an IBSS network. Drop it silently.
3007 * If BSSID is own, report the dropping of this frame. */
3008 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
3009 printk(KERN_DEBUG
"%s: dropped received packet from %pM"
3010 " with no ToDS flag "
3011 "(type=0x%02x, subtype=0x%02x)\n", dev
->name
,
3012 hdr
->addr2
, type
>> 2, stype
>> 4);
3013 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
3020 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
3024 sta
->rx_bytes
+= skb
->len
;
3025 sta
->last_rx
= jiffies
;
3028 if (local
->ap
->nullfunc_ack
&& stype
== IEEE80211_STYPE_NULLFUNC
&&
3029 fc
& IEEE80211_FCTL_TODS
) {
3030 if (local
->hostapd
) {
3031 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
3032 PRISM2_RX_NULLFUNC_ACK
);
3033 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3035 /* some STA f/w's seem to require control::ACK frame
3036 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3037 * from Compaq) does not send this.. Try to generate
3038 * ACK for these frames from the host driver to make
3039 * power saving work with, e.g., Lucent WaveLAN f/w */
3040 hostap_rx(dev
, skb
, rx_stats
);
3041 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3049 atomic_dec(&sta
->users
);
3055 /* Called only as a tasklet (software IRQ) */
3056 int hostap_handle_sta_crypto(local_info_t
*local
,
3057 struct ieee80211_hdr
*hdr
,
3058 struct lib80211_crypt_data
**crypt
,
3061 struct sta_info
*sta
;
3063 spin_lock(&local
->ap
->sta_table_lock
);
3064 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
3066 atomic_inc(&sta
->users
);
3067 spin_unlock(&local
->ap
->sta_table_lock
);
3073 *crypt
= sta
->crypt
;
3075 /* hostap_handle_sta_release() will be called to release STA
3078 atomic_dec(&sta
->users
);
3084 /* Called only as a tasklet (software IRQ) */
3085 int hostap_is_sta_assoc(struct ap_data
*ap
, u8
*sta_addr
)
3087 struct sta_info
*sta
;
3090 spin_lock(&ap
->sta_table_lock
);
3091 sta
= ap_get_sta(ap
, sta_addr
);
3092 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
3094 spin_unlock(&ap
->sta_table_lock
);
3100 /* Called only as a tasklet (software IRQ) */
3101 int hostap_is_sta_authorized(struct ap_data
*ap
, u8
*sta_addr
)
3103 struct sta_info
*sta
;
3106 spin_lock(&ap
->sta_table_lock
);
3107 sta
= ap_get_sta(ap
, sta_addr
);
3108 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&&
3109 ((sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3110 ap
->local
->ieee_802_1x
== 0))
3112 spin_unlock(&ap
->sta_table_lock
);
3118 /* Called only as a tasklet (software IRQ) */
3119 int hostap_add_sta(struct ap_data
*ap
, u8
*sta_addr
)
3121 struct sta_info
*sta
;
3127 spin_lock(&ap
->sta_table_lock
);
3128 sta
= ap_get_sta(ap
, sta_addr
);
3131 spin_unlock(&ap
->sta_table_lock
);
3134 sta
= ap_add_sta(ap
, sta_addr
);
3137 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
3139 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
3140 /* No way of knowing which rates are supported since we did not
3141 * get supported rates element from beacon/assoc req. Assume
3142 * that remote end supports all 802.11b rates. */
3143 sta
->supported_rates
[0] = 0x82;
3144 sta
->supported_rates
[1] = 0x84;
3145 sta
->supported_rates
[2] = 0x0b;
3146 sta
->supported_rates
[3] = 0x16;
3147 sta
->tx_supp_rates
= WLAN_RATE_1M
| WLAN_RATE_2M
|
3148 WLAN_RATE_5M5
| WLAN_RATE_11M
;
3150 sta
->tx_max_rate
= sta
->tx_rate_idx
= 3;
3157 /* Called only as a tasklet (software IRQ) */
3158 int hostap_update_rx_stats(struct ap_data
*ap
,
3159 struct ieee80211_hdr
*hdr
,
3160 struct hostap_80211_rx_status
*rx_stats
)
3162 struct sta_info
*sta
;
3167 spin_lock(&ap
->sta_table_lock
);
3168 sta
= ap_get_sta(ap
, hdr
->addr2
);
3170 sta
->last_rx_silence
= rx_stats
->noise
;
3171 sta
->last_rx_signal
= rx_stats
->signal
;
3172 sta
->last_rx_rate
= rx_stats
->rate
;
3173 sta
->last_rx_updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
3174 if (rx_stats
->rate
== 10)
3176 else if (rx_stats
->rate
== 20)
3178 else if (rx_stats
->rate
== 55)
3180 else if (rx_stats
->rate
== 110)
3183 spin_unlock(&ap
->sta_table_lock
);
3185 return sta
? 0 : -1;
3189 void hostap_update_rates(local_info_t
*local
)
3191 struct sta_info
*sta
;
3192 struct ap_data
*ap
= local
->ap
;
3197 spin_lock_bh(&ap
->sta_table_lock
);
3198 list_for_each_entry(sta
, &ap
->sta_list
, list
) {
3199 prism2_check_tx_rates(sta
);
3201 spin_unlock_bh(&ap
->sta_table_lock
);
3205 void * ap_crypt_get_ptrs(struct ap_data
*ap
, u8
*addr
, int permanent
,
3206 struct lib80211_crypt_data
***crypt
)
3208 struct sta_info
*sta
;
3210 spin_lock_bh(&ap
->sta_table_lock
);
3211 sta
= ap_get_sta(ap
, addr
);
3213 atomic_inc(&sta
->users
);
3214 spin_unlock_bh(&ap
->sta_table_lock
);
3216 if (!sta
&& permanent
)
3217 sta
= ap_add_sta(ap
, addr
);
3223 sta
->flags
|= WLAN_STA_PERM
;
3225 *crypt
= &sta
->crypt
;
3231 void hostap_add_wds_links(local_info_t
*local
)
3233 struct ap_data
*ap
= local
->ap
;
3234 struct sta_info
*sta
;
3236 spin_lock_bh(&ap
->sta_table_lock
);
3237 list_for_each_entry(sta
, &ap
->sta_list
, 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_exc
);
3270 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3271 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */