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 #include <linux/proc_fs.h>
20 #include <linux/delay.h>
21 #include <linux/random.h>
23 #include "hostap_wlan.h"
25 #include "hostap_ap.h"
27 static int other_ap_policy
[MAX_PARM_DEVICES
] = { AP_OTHER_AP_SKIP_ALL
,
29 module_param_array(other_ap_policy
, int, NULL
, 0444);
30 MODULE_PARM_DESC(other_ap_policy
, "Other AP beacon monitoring policy (0-3)");
32 static int ap_max_inactivity
[MAX_PARM_DEVICES
] = { AP_MAX_INACTIVITY_SEC
,
34 module_param_array(ap_max_inactivity
, int, NULL
, 0444);
35 MODULE_PARM_DESC(ap_max_inactivity
, "AP timeout (in seconds) for station "
38 static int ap_bridge_packets
[MAX_PARM_DEVICES
] = { 1, DEF_INTS
};
39 module_param_array(ap_bridge_packets
, int, NULL
, 0444);
40 MODULE_PARM_DESC(ap_bridge_packets
, "Bridge packets directly between "
43 static int autom_ap_wds
[MAX_PARM_DEVICES
] = { 0, DEF_INTS
};
44 module_param_array(autom_ap_wds
, int, NULL
, 0444);
45 MODULE_PARM_DESC(autom_ap_wds
, "Add WDS connections to other APs "
49 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
);
50 static void hostap_event_expired_sta(struct net_device
*dev
,
51 struct sta_info
*sta
);
52 static void handle_add_proc_queue(struct work_struct
*work
);
54 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
55 static void handle_wds_oper_queue(struct work_struct
*work
);
56 static void prism2_send_mgmt(struct net_device
*dev
,
57 u16 type_subtype
, char *body
,
58 int body_len
, u8
*addr
, u16 tx_cb_idx
);
59 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
62 #ifndef PRISM2_NO_PROCFS_DEBUG
63 static int ap_debug_proc_read(char *page
, char **start
, off_t off
,
64 int count
, int *eof
, void *data
)
67 struct ap_data
*ap
= (struct ap_data
*) data
;
74 p
+= sprintf(p
, "BridgedUnicastFrames=%u\n", ap
->bridged_unicast
);
75 p
+= sprintf(p
, "BridgedMulticastFrames=%u\n", ap
->bridged_multicast
);
76 p
+= sprintf(p
, "max_inactivity=%u\n", ap
->max_inactivity
/ HZ
);
77 p
+= sprintf(p
, "bridge_packets=%u\n", ap
->bridge_packets
);
78 p
+= sprintf(p
, "nullfunc_ack=%u\n", ap
->nullfunc_ack
);
79 p
+= sprintf(p
, "autom_ap_wds=%u\n", ap
->autom_ap_wds
);
80 p
+= sprintf(p
, "auth_algs=%u\n", ap
->local
->auth_algs
);
81 p
+= sprintf(p
, "tx_drop_nonassoc=%u\n", ap
->tx_drop_nonassoc
);
85 #endif /* PRISM2_NO_PROCFS_DEBUG */
88 static void ap_sta_hash_add(struct ap_data
*ap
, struct sta_info
*sta
)
90 sta
->hnext
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
91 ap
->sta_hash
[STA_HASH(sta
->addr
)] = sta
;
94 static void ap_sta_hash_del(struct ap_data
*ap
, struct sta_info
*sta
)
98 s
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
99 if (s
== NULL
) return;
100 if (memcmp(s
->addr
, sta
->addr
, ETH_ALEN
) == 0) {
101 ap
->sta_hash
[STA_HASH(sta
->addr
)] = s
->hnext
;
105 while (s
->hnext
!= NULL
&& memcmp(s
->hnext
->addr
, sta
->addr
, ETH_ALEN
)
108 if (s
->hnext
!= NULL
)
109 s
->hnext
= s
->hnext
->hnext
;
111 printk("AP: could not remove STA " MACSTR
" from hash table\n",
115 static void ap_free_sta(struct ap_data
*ap
, struct sta_info
*sta
)
117 if (sta
->ap
&& sta
->local
)
118 hostap_event_expired_sta(sta
->local
->dev
, sta
);
120 if (ap
->proc
!= NULL
) {
122 sprintf(name
, MACSTR
, MAC2STR(sta
->addr
));
123 remove_proc_entry(name
, ap
->proc
);
127 sta
->crypt
->ops
->deinit(sta
->crypt
->priv
);
132 skb_queue_purge(&sta
->tx_buf
);
135 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
137 ap
->sta_aid
[sta
->aid
- 1] = NULL
;
139 if (!sta
->ap
&& sta
->u
.sta
.challenge
)
140 kfree(sta
->u
.sta
.challenge
);
141 del_timer(&sta
->timer
);
142 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
148 static void hostap_set_tim(local_info_t
*local
, int aid
, int set
)
150 if (local
->func
->set_tim
)
151 local
->func
->set_tim(local
->dev
, aid
, set
);
155 static void hostap_event_new_sta(struct net_device
*dev
, struct sta_info
*sta
)
157 union iwreq_data wrqu
;
158 memset(&wrqu
, 0, sizeof(wrqu
));
159 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
160 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
161 wireless_send_event(dev
, IWEVREGISTERED
, &wrqu
, NULL
);
165 static void hostap_event_expired_sta(struct net_device
*dev
,
166 struct sta_info
*sta
)
168 union iwreq_data wrqu
;
169 memset(&wrqu
, 0, sizeof(wrqu
));
170 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
171 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
172 wireless_send_event(dev
, IWEVEXPIRED
, &wrqu
, NULL
);
176 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
178 static void ap_handle_timer(unsigned long data
)
180 struct sta_info
*sta
= (struct sta_info
*) data
;
183 unsigned long next_time
= 0;
186 if (sta
== NULL
|| sta
->local
== NULL
|| sta
->local
->ap
== NULL
) {
187 PDEBUG(DEBUG_AP
, "ap_handle_timer() called with NULL data\n");
193 was_assoc
= sta
->flags
& WLAN_STA_ASSOC
;
195 if (atomic_read(&sta
->users
) != 0)
196 next_time
= jiffies
+ HZ
;
197 else if ((sta
->flags
& WLAN_STA_PERM
) && !(sta
->flags
& WLAN_STA_AUTH
))
198 next_time
= jiffies
+ ap
->max_inactivity
;
200 if (time_before(jiffies
, sta
->last_rx
+ ap
->max_inactivity
)) {
201 /* station activity detected; reset timeout state */
202 sta
->timeout_next
= STA_NULLFUNC
;
203 next_time
= sta
->last_rx
+ ap
->max_inactivity
;
204 } else if (sta
->timeout_next
== STA_DISASSOC
&&
205 !(sta
->flags
& WLAN_STA_PENDING_POLL
)) {
206 /* STA ACKed data nullfunc frame poll */
207 sta
->timeout_next
= STA_NULLFUNC
;
208 next_time
= jiffies
+ ap
->max_inactivity
;
212 sta
->timer
.expires
= next_time
;
213 add_timer(&sta
->timer
);
218 sta
->timeout_next
= STA_DEAUTH
;
220 if (sta
->timeout_next
== STA_DEAUTH
&& !(sta
->flags
& WLAN_STA_PERM
)) {
221 spin_lock(&ap
->sta_table_lock
);
222 ap_sta_hash_del(ap
, sta
);
223 list_del(&sta
->list
);
224 spin_unlock(&ap
->sta_table_lock
);
225 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
226 } else if (sta
->timeout_next
== STA_DISASSOC
)
227 sta
->flags
&= ~WLAN_STA_ASSOC
;
229 if (was_assoc
&& !(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
230 hostap_event_expired_sta(local
->dev
, sta
);
232 if (sta
->timeout_next
== STA_DEAUTH
&& sta
->aid
> 0 &&
233 !skb_queue_empty(&sta
->tx_buf
)) {
234 hostap_set_tim(local
, sta
->aid
, 0);
235 sta
->flags
&= ~WLAN_STA_TIM
;
239 if (ap
->autom_ap_wds
) {
240 PDEBUG(DEBUG_AP
, "%s: removing automatic WDS "
241 "connection to AP " MACSTR
"\n",
242 local
->dev
->name
, MAC2STR(sta
->addr
));
243 hostap_wds_link_oper(local
, sta
->addr
, WDS_DEL
);
245 } else if (sta
->timeout_next
== STA_NULLFUNC
) {
246 /* send data frame to poll STA and check whether this frame
248 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
249 * it is apparently not retried so TX Exc events are not
251 sta
->flags
|= WLAN_STA_PENDING_POLL
;
252 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_DATA
|
253 IEEE80211_STYPE_DATA
, NULL
, 0,
254 sta
->addr
, ap
->tx_callback_poll
);
256 int deauth
= sta
->timeout_next
== STA_DEAUTH
;
258 PDEBUG(DEBUG_AP
, "%s: sending %s info to STA " MACSTR
259 "(last=%lu, jiffies=%lu)\n",
261 deauth
? "deauthentication" : "disassociation",
262 MAC2STR(sta
->addr
), sta
->last_rx
, jiffies
);
264 resp
= cpu_to_le16(deauth
? WLAN_REASON_PREV_AUTH_NOT_VALID
:
265 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
266 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_MGMT
|
267 (deauth
? IEEE80211_STYPE_DEAUTH
:
268 IEEE80211_STYPE_DISASSOC
),
269 (char *) &resp
, 2, sta
->addr
, 0);
272 if (sta
->timeout_next
== STA_DEAUTH
) {
273 if (sta
->flags
& WLAN_STA_PERM
) {
274 PDEBUG(DEBUG_AP
, "%s: STA " MACSTR
" would have been "
275 "removed, but it has 'perm' flag\n",
276 local
->dev
->name
, MAC2STR(sta
->addr
));
278 ap_free_sta(ap
, sta
);
282 if (sta
->timeout_next
== STA_NULLFUNC
) {
283 sta
->timeout_next
= STA_DISASSOC
;
284 sta
->timer
.expires
= jiffies
+ AP_DISASSOC_DELAY
;
286 sta
->timeout_next
= STA_DEAUTH
;
287 sta
->timer
.expires
= jiffies
+ AP_DEAUTH_DELAY
;
290 add_timer(&sta
->timer
);
294 void hostap_deauth_all_stas(struct net_device
*dev
, struct ap_data
*ap
,
301 PDEBUG(DEBUG_AP
, "%s: Deauthenticate all stations\n", dev
->name
);
302 memset(addr
, 0xff, ETH_ALEN
);
304 resp
= __constant_cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
306 /* deauth message sent; try to resend it few times; the message is
307 * broadcast, so it may be delayed until next DTIM; there is not much
308 * else we can do at this point since the driver is going to be shut
310 for (i
= 0; i
< 5; i
++) {
311 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
312 IEEE80211_STYPE_DEAUTH
,
313 (char *) &resp
, 2, addr
, 0);
315 if (!resend
|| ap
->num_sta
<= 0)
323 static int ap_control_proc_read(char *page
, char **start
, off_t off
,
324 int count
, int *eof
, void *data
)
327 struct ap_data
*ap
= (struct ap_data
*) data
;
329 struct list_head
*ptr
;
330 struct mac_entry
*entry
;
337 switch (ap
->mac_restrictions
.policy
) {
338 case MAC_POLICY_OPEN
:
341 case MAC_POLICY_ALLOW
:
342 policy_txt
= "allow";
344 case MAC_POLICY_DENY
:
348 policy_txt
= "unknown";
351 p
+= sprintf(p
, "MAC policy: %s\n", policy_txt
);
352 p
+= sprintf(p
, "MAC entries: %u\n", ap
->mac_restrictions
.entries
);
353 p
+= sprintf(p
, "MAC list:\n");
354 spin_lock_bh(&ap
->mac_restrictions
.lock
);
355 for (ptr
= ap
->mac_restrictions
.mac_list
.next
;
356 ptr
!= &ap
->mac_restrictions
.mac_list
; ptr
= ptr
->next
) {
357 if (p
- page
> PAGE_SIZE
- 80) {
358 p
+= sprintf(p
, "All entries did not fit one page.\n");
362 entry
= list_entry(ptr
, struct mac_entry
, list
);
363 p
+= sprintf(p
, MACSTR
"\n", MAC2STR(entry
->addr
));
365 spin_unlock_bh(&ap
->mac_restrictions
.lock
);
371 int ap_control_add_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
373 struct mac_entry
*entry
;
375 entry
= kmalloc(sizeof(struct mac_entry
), GFP_KERNEL
);
379 memcpy(entry
->addr
, mac
, ETH_ALEN
);
381 spin_lock_bh(&mac_restrictions
->lock
);
382 list_add_tail(&entry
->list
, &mac_restrictions
->mac_list
);
383 mac_restrictions
->entries
++;
384 spin_unlock_bh(&mac_restrictions
->lock
);
390 int ap_control_del_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
392 struct list_head
*ptr
;
393 struct mac_entry
*entry
;
395 spin_lock_bh(&mac_restrictions
->lock
);
396 for (ptr
= mac_restrictions
->mac_list
.next
;
397 ptr
!= &mac_restrictions
->mac_list
; ptr
= ptr
->next
) {
398 entry
= list_entry(ptr
, struct mac_entry
, list
);
400 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
403 mac_restrictions
->entries
--;
404 spin_unlock_bh(&mac_restrictions
->lock
);
408 spin_unlock_bh(&mac_restrictions
->lock
);
413 static int ap_control_mac_deny(struct mac_restrictions
*mac_restrictions
,
416 struct list_head
*ptr
;
417 struct mac_entry
*entry
;
420 if (mac_restrictions
->policy
== MAC_POLICY_OPEN
)
423 spin_lock_bh(&mac_restrictions
->lock
);
424 for (ptr
= mac_restrictions
->mac_list
.next
;
425 ptr
!= &mac_restrictions
->mac_list
; ptr
= ptr
->next
) {
426 entry
= list_entry(ptr
, struct mac_entry
, list
);
428 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
433 spin_unlock_bh(&mac_restrictions
->lock
);
435 if (mac_restrictions
->policy
== MAC_POLICY_ALLOW
)
442 void ap_control_flush_macs(struct mac_restrictions
*mac_restrictions
)
444 struct list_head
*ptr
, *n
;
445 struct mac_entry
*entry
;
447 if (mac_restrictions
->entries
== 0)
450 spin_lock_bh(&mac_restrictions
->lock
);
451 for (ptr
= mac_restrictions
->mac_list
.next
, n
= ptr
->next
;
452 ptr
!= &mac_restrictions
->mac_list
;
453 ptr
= n
, n
= ptr
->next
) {
454 entry
= list_entry(ptr
, struct mac_entry
, list
);
458 mac_restrictions
->entries
= 0;
459 spin_unlock_bh(&mac_restrictions
->lock
);
463 int ap_control_kick_mac(struct ap_data
*ap
, struct net_device
*dev
, u8
*mac
)
465 struct sta_info
*sta
;
468 spin_lock_bh(&ap
->sta_table_lock
);
469 sta
= ap_get_sta(ap
, mac
);
471 ap_sta_hash_del(ap
, sta
);
472 list_del(&sta
->list
);
474 spin_unlock_bh(&ap
->sta_table_lock
);
479 resp
= cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
480 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_DEAUTH
,
481 (char *) &resp
, 2, sta
->addr
, 0);
483 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
484 hostap_event_expired_sta(dev
, sta
);
486 ap_free_sta(ap
, sta
);
491 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
494 void ap_control_kickall(struct ap_data
*ap
)
496 struct list_head
*ptr
, *n
;
497 struct sta_info
*sta
;
499 spin_lock_bh(&ap
->sta_table_lock
);
500 for (ptr
= ap
->sta_list
.next
, n
= ptr
->next
; ptr
!= &ap
->sta_list
;
501 ptr
= n
, n
= ptr
->next
) {
502 sta
= list_entry(ptr
, struct sta_info
, list
);
503 ap_sta_hash_del(ap
, sta
);
504 list_del(&sta
->list
);
505 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
506 hostap_event_expired_sta(sta
->local
->dev
, sta
);
507 ap_free_sta(ap
, sta
);
509 spin_unlock_bh(&ap
->sta_table_lock
);
513 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
515 #define PROC_LIMIT (PAGE_SIZE - 80)
517 static int prism2_ap_proc_read(char *page
, char **start
, off_t off
,
518 int count
, int *eof
, void *data
)
521 struct ap_data
*ap
= (struct ap_data
*) data
;
522 struct list_head
*ptr
;
525 if (off
> PROC_LIMIT
) {
530 p
+= sprintf(p
, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
531 spin_lock_bh(&ap
->sta_table_lock
);
532 for (ptr
= ap
->sta_list
.next
; ptr
!= &ap
->sta_list
; ptr
= ptr
->next
) {
533 struct sta_info
*sta
= (struct sta_info
*) ptr
;
538 p
+= sprintf(p
, MACSTR
" %d %d %d %d '", MAC2STR(sta
->addr
),
539 sta
->u
.ap
.channel
, sta
->last_rx_signal
,
540 sta
->last_rx_silence
, sta
->last_rx_rate
);
541 for (i
= 0; i
< sta
->u
.ap
.ssid_len
; i
++)
542 p
+= sprintf(p
, ((sta
->u
.ap
.ssid
[i
] >= 32 &&
543 sta
->u
.ap
.ssid
[i
] < 127) ?
546 p
+= sprintf(p
, "'");
547 if (sta
->capability
& WLAN_CAPABILITY_ESS
)
548 p
+= sprintf(p
, " [ESS]");
549 if (sta
->capability
& WLAN_CAPABILITY_IBSS
)
550 p
+= sprintf(p
, " [IBSS]");
551 if (sta
->capability
& WLAN_CAPABILITY_PRIVACY
)
552 p
+= sprintf(p
, " [WEP]");
553 p
+= sprintf(p
, "\n");
555 if ((p
- page
) > PROC_LIMIT
) {
556 printk(KERN_DEBUG
"hostap: ap proc did not fit\n");
560 spin_unlock_bh(&ap
->sta_table_lock
);
562 if ((p
- page
) <= off
) {
569 return (p
- page
- off
);
571 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
574 void hostap_check_sta_fw_version(struct ap_data
*ap
, int sta_fw_ver
)
579 if (sta_fw_ver
== PRISM2_FW_VER(0,8,0)) {
580 PDEBUG(DEBUG_AP
, "Using data::nullfunc ACK workaround - "
581 "firmware upgrade recommended\n");
582 ap
->nullfunc_ack
= 1;
584 ap
->nullfunc_ack
= 0;
586 if (sta_fw_ver
== PRISM2_FW_VER(1,4,2)) {
587 printk(KERN_WARNING
"%s: Warning: secondary station firmware "
588 "version 1.4.2 does not seem to work in Host AP mode\n",
589 ap
->local
->dev
->name
);
594 /* Called only as a tasklet (software IRQ) */
595 static void hostap_ap_tx_cb(struct sk_buff
*skb
, int ok
, void *data
)
597 struct ap_data
*ap
= data
;
599 struct ieee80211_hdr_4addr
*hdr
;
601 if (!ap
->local
->hostapd
|| !ap
->local
->apdev
) {
606 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
607 fc
= le16_to_cpu(hdr
->frame_ctl
);
609 /* Pass the TX callback frame to the hostapd; use 802.11 header version
610 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
612 fc
&= ~IEEE80211_FCTL_VERS
;
613 fc
|= ok
? BIT(1) : BIT(0);
614 hdr
->frame_ctl
= cpu_to_le16(fc
);
616 skb
->dev
= ap
->local
->apdev
;
617 skb_pull(skb
, hostap_80211_get_hdrlen(fc
));
618 skb
->pkt_type
= PACKET_OTHERHOST
;
619 skb
->protocol
= __constant_htons(ETH_P_802_2
);
620 memset(skb
->cb
, 0, sizeof(skb
->cb
));
625 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
626 /* Called only as a tasklet (software IRQ) */
627 static void hostap_ap_tx_cb_auth(struct sk_buff
*skb
, int ok
, void *data
)
629 struct ap_data
*ap
= data
;
630 struct net_device
*dev
= ap
->local
->dev
;
631 struct ieee80211_hdr_4addr
*hdr
;
632 u16 fc
, *pos
, auth_alg
, auth_transaction
, status
;
633 struct sta_info
*sta
= NULL
;
636 if (ap
->local
->hostapd
) {
641 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
642 fc
= le16_to_cpu(hdr
->frame_ctl
);
643 if (WLAN_FC_GET_TYPE(fc
) != IEEE80211_FTYPE_MGMT
||
644 WLAN_FC_GET_STYPE(fc
) != IEEE80211_STYPE_AUTH
||
645 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 6) {
646 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_auth received invalid "
647 "frame\n", dev
->name
);
652 pos
= (u16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
653 auth_alg
= le16_to_cpu(*pos
++);
654 auth_transaction
= le16_to_cpu(*pos
++);
655 status
= le16_to_cpu(*pos
++);
658 txt
= "frame was not ACKed";
662 spin_lock(&ap
->sta_table_lock
);
663 sta
= ap_get_sta(ap
, hdr
->addr1
);
665 atomic_inc(&sta
->users
);
666 spin_unlock(&ap
->sta_table_lock
);
669 txt
= "STA not found";
673 if (status
== WLAN_STATUS_SUCCESS
&&
674 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
675 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
676 txt
= "STA authenticated";
677 sta
->flags
|= WLAN_STA_AUTH
;
678 sta
->last_auth
= jiffies
;
679 } else if (status
!= WLAN_STATUS_SUCCESS
)
680 txt
= "authentication failed";
684 atomic_dec(&sta
->users
);
686 PDEBUG(DEBUG_AP
, "%s: " MACSTR
" auth_cb - alg=%d trans#=%d "
688 dev
->name
, MAC2STR(hdr
->addr1
), auth_alg
,
689 auth_transaction
, status
, txt
);
695 /* Called only as a tasklet (software IRQ) */
696 static void hostap_ap_tx_cb_assoc(struct sk_buff
*skb
, int ok
, void *data
)
698 struct ap_data
*ap
= data
;
699 struct net_device
*dev
= ap
->local
->dev
;
700 struct ieee80211_hdr_4addr
*hdr
;
701 u16 fc
, *pos
, status
;
702 struct sta_info
*sta
= NULL
;
705 if (ap
->local
->hostapd
) {
710 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
711 fc
= le16_to_cpu(hdr
->frame_ctl
);
712 if (WLAN_FC_GET_TYPE(fc
) != IEEE80211_FTYPE_MGMT
||
713 (WLAN_FC_GET_STYPE(fc
) != IEEE80211_STYPE_ASSOC_RESP
&&
714 WLAN_FC_GET_STYPE(fc
) != IEEE80211_STYPE_REASSOC_RESP
) ||
715 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 4) {
716 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_assoc received invalid "
717 "frame\n", dev
->name
);
723 txt
= "frame was not ACKed";
727 spin_lock(&ap
->sta_table_lock
);
728 sta
= ap_get_sta(ap
, hdr
->addr1
);
730 atomic_inc(&sta
->users
);
731 spin_unlock(&ap
->sta_table_lock
);
734 txt
= "STA not found";
738 pos
= (u16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
740 status
= le16_to_cpu(*pos
++);
741 if (status
== WLAN_STATUS_SUCCESS
) {
742 if (!(sta
->flags
& WLAN_STA_ASSOC
))
743 hostap_event_new_sta(dev
, sta
);
744 txt
= "STA associated";
745 sta
->flags
|= WLAN_STA_ASSOC
;
746 sta
->last_assoc
= jiffies
;
748 txt
= "association failed";
752 atomic_dec(&sta
->users
);
754 PDEBUG(DEBUG_AP
, "%s: " MACSTR
" assoc_cb - %s\n",
755 dev
->name
, MAC2STR(hdr
->addr1
), txt
);
760 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
761 * in verifying whether the STA is still present. */
762 static void hostap_ap_tx_cb_poll(struct sk_buff
*skb
, int ok
, void *data
)
764 struct ap_data
*ap
= data
;
765 struct ieee80211_hdr_4addr
*hdr
;
766 struct sta_info
*sta
;
770 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
772 spin_lock(&ap
->sta_table_lock
);
773 sta
= ap_get_sta(ap
, hdr
->addr1
);
775 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
776 spin_unlock(&ap
->sta_table_lock
);
778 PDEBUG(DEBUG_AP
, "%s: STA " MACSTR
" did not ACK activity "
779 "poll frame\n", ap
->local
->dev
->name
,
780 MAC2STR(hdr
->addr1
));
786 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
789 void hostap_init_data(local_info_t
*local
)
791 struct ap_data
*ap
= local
->ap
;
794 printk(KERN_WARNING
"hostap_init_data: ap == NULL\n");
797 memset(ap
, 0, sizeof(struct ap_data
));
800 ap
->ap_policy
= GET_INT_PARM(other_ap_policy
, local
->card_idx
);
801 ap
->bridge_packets
= GET_INT_PARM(ap_bridge_packets
, local
->card_idx
);
803 GET_INT_PARM(ap_max_inactivity
, local
->card_idx
) * HZ
;
804 ap
->autom_ap_wds
= GET_INT_PARM(autom_ap_wds
, local
->card_idx
);
806 spin_lock_init(&ap
->sta_table_lock
);
807 INIT_LIST_HEAD(&ap
->sta_list
);
809 /* Initialize task queue structure for AP management */
810 INIT_WORK(&local
->ap
->add_sta_proc_queue
, handle_add_proc_queue
);
812 ap
->tx_callback_idx
=
813 hostap_tx_callback_register(local
, hostap_ap_tx_cb
, ap
);
814 if (ap
->tx_callback_idx
== 0)
815 printk(KERN_WARNING
"%s: failed to register TX callback for "
816 "AP\n", local
->dev
->name
);
817 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
818 INIT_WORK(&local
->ap
->wds_oper_queue
, handle_wds_oper_queue
);
820 ap
->tx_callback_auth
=
821 hostap_tx_callback_register(local
, hostap_ap_tx_cb_auth
, ap
);
822 ap
->tx_callback_assoc
=
823 hostap_tx_callback_register(local
, hostap_ap_tx_cb_assoc
, ap
);
824 ap
->tx_callback_poll
=
825 hostap_tx_callback_register(local
, hostap_ap_tx_cb_poll
, ap
);
826 if (ap
->tx_callback_auth
== 0 || ap
->tx_callback_assoc
== 0 ||
827 ap
->tx_callback_poll
== 0)
828 printk(KERN_WARNING
"%s: failed to register TX callback for "
829 "AP\n", local
->dev
->name
);
831 spin_lock_init(&ap
->mac_restrictions
.lock
);
832 INIT_LIST_HEAD(&ap
->mac_restrictions
.mac_list
);
833 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
839 void hostap_init_ap_proc(local_info_t
*local
)
841 struct ap_data
*ap
= local
->ap
;
843 ap
->proc
= local
->proc
;
844 if (ap
->proc
== NULL
)
847 #ifndef PRISM2_NO_PROCFS_DEBUG
848 create_proc_read_entry("ap_debug", 0, ap
->proc
,
849 ap_debug_proc_read
, ap
);
850 #endif /* PRISM2_NO_PROCFS_DEBUG */
852 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
853 create_proc_read_entry("ap_control", 0, ap
->proc
,
854 ap_control_proc_read
, ap
);
855 create_proc_read_entry("ap", 0, ap
->proc
,
856 prism2_ap_proc_read
, ap
);
857 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
862 void hostap_free_data(struct ap_data
*ap
)
864 struct list_head
*n
, *ptr
;
866 if (ap
== NULL
|| !ap
->initialized
) {
867 printk(KERN_DEBUG
"hostap_free_data: ap has not yet been "
868 "initialized - skip resource freeing\n");
872 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
874 ap
->crypt
->deinit(ap
->crypt_priv
);
875 ap
->crypt
= ap
->crypt_priv
= NULL
;
876 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
878 list_for_each_safe(ptr
, n
, &ap
->sta_list
) {
879 struct sta_info
*sta
= list_entry(ptr
, struct sta_info
, list
);
880 ap_sta_hash_del(ap
, sta
);
881 list_del(&sta
->list
);
882 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
883 hostap_event_expired_sta(sta
->local
->dev
, sta
);
884 ap_free_sta(ap
, sta
);
887 #ifndef PRISM2_NO_PROCFS_DEBUG
888 if (ap
->proc
!= NULL
) {
889 remove_proc_entry("ap_debug", ap
->proc
);
891 #endif /* PRISM2_NO_PROCFS_DEBUG */
893 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
894 if (ap
->proc
!= NULL
) {
895 remove_proc_entry("ap", ap
->proc
);
896 remove_proc_entry("ap_control", ap
->proc
);
898 ap_control_flush_macs(&ap
->mac_restrictions
);
899 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
905 /* caller should have mutex for AP STA list handling */
906 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
)
910 s
= ap
->sta_hash
[STA_HASH(sta
)];
911 while (s
!= NULL
&& memcmp(s
->addr
, sta
, ETH_ALEN
) != 0)
917 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
919 /* Called from timer handler and from scheduled AP queue handlers */
920 static void prism2_send_mgmt(struct net_device
*dev
,
921 u16 type_subtype
, char *body
,
922 int body_len
, u8
*addr
, u16 tx_cb_idx
)
924 struct hostap_interface
*iface
;
926 struct ieee80211_hdr_4addr
*hdr
;
929 struct hostap_skb_tx_data
*meta
;
932 iface
= netdev_priv(dev
);
933 local
= iface
->local
;
934 dev
= local
->dev
; /* always use master radio device */
935 iface
= netdev_priv(dev
);
937 if (!(dev
->flags
& IFF_UP
)) {
938 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt - device is not UP - "
939 "cannot send frame\n", dev
->name
);
943 skb
= dev_alloc_skb(sizeof(*hdr
) + body_len
);
945 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt failed to allocate "
951 hdrlen
= hostap_80211_get_hdrlen(fc
);
952 hdr
= (struct ieee80211_hdr_4addr
*) skb_put(skb
, hdrlen
);
954 memcpy(skb_put(skb
, body_len
), body
, body_len
);
956 memset(hdr
, 0, hdrlen
);
958 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
959 * tx_control instead of using local->tx_control */
962 memcpy(hdr
->addr1
, addr
, ETH_ALEN
); /* DA / RA */
963 if (WLAN_FC_GET_TYPE(fc
) == IEEE80211_FTYPE_DATA
) {
964 fc
|= IEEE80211_FCTL_FROMDS
;
965 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
966 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* SA */
967 } else if (WLAN_FC_GET_TYPE(fc
) == IEEE80211_FTYPE_CTL
) {
968 /* control:ACK does not have addr2 or addr3 */
969 memset(hdr
->addr2
, 0, ETH_ALEN
);
970 memset(hdr
->addr3
, 0, ETH_ALEN
);
972 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* SA */
973 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
976 hdr
->frame_ctl
= cpu_to_le16(fc
);
978 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
979 memset(meta
, 0, sizeof(*meta
));
980 meta
->magic
= HOSTAP_SKB_TX_DATA_MAGIC
;
982 meta
->tx_cb_idx
= tx_cb_idx
;
985 skb
->mac
.raw
= skb
->nh
.raw
= skb
->data
;
988 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
991 static int prism2_sta_proc_read(char *page
, char **start
, off_t off
,
992 int count
, int *eof
, void *data
)
995 struct sta_info
*sta
= (struct sta_info
*) data
;
998 /* FIX: possible race condition.. the STA data could have just expired,
999 * but proc entry was still here so that the read could have started;
1000 * some locking should be done here.. */
1007 p
+= sprintf(p
, "%s=" MACSTR
"\nusers=%d\naid=%d\n"
1008 "flags=0x%04x%s%s%s%s%s%s%s\n"
1009 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1010 sta
->ap
? "AP" : "STA",
1011 MAC2STR(sta
->addr
), atomic_read(&sta
->users
), sta
->aid
,
1013 sta
->flags
& WLAN_STA_AUTH
? " AUTH" : "",
1014 sta
->flags
& WLAN_STA_ASSOC
? " ASSOC" : "",
1015 sta
->flags
& WLAN_STA_PS
? " PS" : "",
1016 sta
->flags
& WLAN_STA_TIM
? " TIM" : "",
1017 sta
->flags
& WLAN_STA_PERM
? " PERM" : "",
1018 sta
->flags
& WLAN_STA_AUTHORIZED
? " AUTHORIZED" : "",
1019 sta
->flags
& WLAN_STA_PENDING_POLL
? " POLL" : "",
1020 sta
->capability
, sta
->listen_interval
);
1021 /* supported_rates: 500 kbit/s units with msb ignored */
1022 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++)
1023 if (sta
->supported_rates
[i
] != 0)
1024 p
+= sprintf(p
, "%d%sMbps ",
1025 (sta
->supported_rates
[i
] & 0x7f) / 2,
1026 sta
->supported_rates
[i
] & 1 ? ".5" : "");
1027 p
+= sprintf(p
, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1028 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1030 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1031 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1032 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1034 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1035 jiffies
, sta
->last_auth
, sta
->last_assoc
, sta
->last_rx
,
1037 sta
->rx_packets
, sta
->tx_packets
, sta
->rx_bytes
,
1038 sta
->tx_bytes
, skb_queue_len(&sta
->tx_buf
),
1039 sta
->last_rx_silence
,
1040 sta
->last_rx_signal
, sta
->last_rx_rate
/ 10,
1041 sta
->last_rx_rate
% 10 ? ".5" : "",
1042 sta
->tx_rate
, sta
->tx_count
[0], sta
->tx_count
[1],
1043 sta
->tx_count
[2], sta
->tx_count
[3], sta
->rx_count
[0],
1044 sta
->rx_count
[1], sta
->rx_count
[2], sta
->rx_count
[3]);
1045 if (sta
->crypt
&& sta
->crypt
->ops
&& sta
->crypt
->ops
->print_stats
)
1046 p
= sta
->crypt
->ops
->print_stats(p
, sta
->crypt
->priv
);
1047 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1049 if (sta
->u
.ap
.channel
>= 0)
1050 p
+= sprintf(p
, "channel=%d\n", sta
->u
.ap
.channel
);
1051 p
+= sprintf(p
, "ssid=");
1052 for (i
= 0; i
< sta
->u
.ap
.ssid_len
; i
++)
1053 p
+= sprintf(p
, ((sta
->u
.ap
.ssid
[i
] >= 32 &&
1054 sta
->u
.ap
.ssid
[i
] < 127) ?
1057 p
+= sprintf(p
, "\n");
1059 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1065 static void handle_add_proc_queue(struct work_struct
*work
)
1067 struct ap_data
*ap
= container_of(work
, struct ap_data
,
1068 add_sta_proc_queue
);
1069 struct sta_info
*sta
;
1071 struct add_sta_proc_data
*entry
, *prev
;
1073 entry
= ap
->add_sta_proc_entries
;
1074 ap
->add_sta_proc_entries
= NULL
;
1077 spin_lock_bh(&ap
->sta_table_lock
);
1078 sta
= ap_get_sta(ap
, entry
->addr
);
1080 atomic_inc(&sta
->users
);
1081 spin_unlock_bh(&ap
->sta_table_lock
);
1084 sprintf(name
, MACSTR
, MAC2STR(sta
->addr
));
1085 sta
->proc
= create_proc_read_entry(
1087 prism2_sta_proc_read
, sta
);
1089 atomic_dec(&sta
->users
);
1093 entry
= entry
->next
;
1099 static struct sta_info
* ap_add_sta(struct ap_data
*ap
, u8
*addr
)
1101 struct sta_info
*sta
;
1103 sta
= kzalloc(sizeof(struct sta_info
), GFP_ATOMIC
);
1105 PDEBUG(DEBUG_AP
, "AP: kmalloc failed\n");
1109 /* initialize STA info data */
1110 sta
->local
= ap
->local
;
1111 skb_queue_head_init(&sta
->tx_buf
);
1112 memcpy(sta
->addr
, addr
, ETH_ALEN
);
1114 atomic_inc(&sta
->users
);
1115 spin_lock_bh(&ap
->sta_table_lock
);
1116 list_add(&sta
->list
, &ap
->sta_list
);
1118 ap_sta_hash_add(ap
, sta
);
1119 spin_unlock_bh(&ap
->sta_table_lock
);
1122 struct add_sta_proc_data
*entry
;
1123 /* schedule a non-interrupt context process to add a procfs
1124 * entry for the STA since procfs code use GFP_KERNEL */
1125 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1127 memcpy(entry
->addr
, sta
->addr
, ETH_ALEN
);
1128 entry
->next
= ap
->add_sta_proc_entries
;
1129 ap
->add_sta_proc_entries
= entry
;
1130 schedule_work(&ap
->add_sta_proc_queue
);
1132 printk(KERN_DEBUG
"Failed to add STA proc data\n");
1135 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1136 init_timer(&sta
->timer
);
1137 sta
->timer
.expires
= jiffies
+ ap
->max_inactivity
;
1138 sta
->timer
.data
= (unsigned long) sta
;
1139 sta
->timer
.function
= ap_handle_timer
;
1140 if (!ap
->local
->hostapd
)
1141 add_timer(&sta
->timer
);
1142 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1148 static int ap_tx_rate_ok(int rateidx
, struct sta_info
*sta
,
1149 local_info_t
*local
)
1151 if (rateidx
> sta
->tx_max_rate
||
1152 !(sta
->tx_supp_rates
& (1 << rateidx
)))
1155 if (local
->tx_rate_control
!= 0 &&
1156 !(local
->tx_rate_control
& (1 << rateidx
)))
1163 static void prism2_check_tx_rates(struct sta_info
*sta
)
1167 sta
->tx_supp_rates
= 0;
1168 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++) {
1169 if ((sta
->supported_rates
[i
] & 0x7f) == 2)
1170 sta
->tx_supp_rates
|= WLAN_RATE_1M
;
1171 if ((sta
->supported_rates
[i
] & 0x7f) == 4)
1172 sta
->tx_supp_rates
|= WLAN_RATE_2M
;
1173 if ((sta
->supported_rates
[i
] & 0x7f) == 11)
1174 sta
->tx_supp_rates
|= WLAN_RATE_5M5
;
1175 if ((sta
->supported_rates
[i
] & 0x7f) == 22)
1176 sta
->tx_supp_rates
|= WLAN_RATE_11M
;
1178 sta
->tx_max_rate
= sta
->tx_rate
= sta
->tx_rate_idx
= 0;
1179 if (sta
->tx_supp_rates
& WLAN_RATE_1M
) {
1180 sta
->tx_max_rate
= 0;
1181 if (ap_tx_rate_ok(0, sta
, sta
->local
)) {
1183 sta
->tx_rate_idx
= 0;
1186 if (sta
->tx_supp_rates
& WLAN_RATE_2M
) {
1187 sta
->tx_max_rate
= 1;
1188 if (ap_tx_rate_ok(1, sta
, sta
->local
)) {
1190 sta
->tx_rate_idx
= 1;
1193 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
) {
1194 sta
->tx_max_rate
= 2;
1195 if (ap_tx_rate_ok(2, sta
, sta
->local
)) {
1197 sta
->tx_rate_idx
= 2;
1200 if (sta
->tx_supp_rates
& WLAN_RATE_11M
) {
1201 sta
->tx_max_rate
= 3;
1202 if (ap_tx_rate_ok(3, sta
, sta
->local
)) {
1204 sta
->tx_rate_idx
= 3;
1210 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1212 static void ap_crypt_init(struct ap_data
*ap
)
1214 ap
->crypt
= ieee80211_get_crypto_ops("WEP");
1217 if (ap
->crypt
->init
) {
1218 ap
->crypt_priv
= ap
->crypt
->init(0);
1219 if (ap
->crypt_priv
== NULL
)
1222 u8 key
[WEP_KEY_LEN
];
1223 get_random_bytes(key
, WEP_KEY_LEN
);
1224 ap
->crypt
->set_key(key
, WEP_KEY_LEN
, NULL
,
1230 if (ap
->crypt
== NULL
) {
1231 printk(KERN_WARNING
"AP could not initialize WEP: load module "
1232 "ieee80211_crypt_wep.ko\n");
1237 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1238 * that WEP algorithm is used for generating challange. This should be unique,
1239 * but otherwise there is not really need for randomness etc. Initialize WEP
1240 * with pseudo random key and then use increasing IV to get unique challenge
1243 * Called only as a scheduled task for pending AP frames.
1245 static char * ap_auth_make_challenge(struct ap_data
*ap
)
1248 struct sk_buff
*skb
;
1250 if (ap
->crypt
== NULL
) {
1252 if (ap
->crypt
== NULL
)
1256 tmpbuf
= kmalloc(WLAN_AUTH_CHALLENGE_LEN
, GFP_ATOMIC
);
1257 if (tmpbuf
== NULL
) {
1258 PDEBUG(DEBUG_AP
, "AP: kmalloc failed for challenge\n");
1262 skb
= dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN
+
1263 ap
->crypt
->extra_mpdu_prefix_len
+
1264 ap
->crypt
->extra_mpdu_postfix_len
);
1270 skb_reserve(skb
, ap
->crypt
->extra_mpdu_prefix_len
);
1271 memset(skb_put(skb
, WLAN_AUTH_CHALLENGE_LEN
), 0,
1272 WLAN_AUTH_CHALLENGE_LEN
);
1273 if (ap
->crypt
->encrypt_mpdu(skb
, 0, ap
->crypt_priv
)) {
1279 memcpy(tmpbuf
, skb
->data
+ ap
->crypt
->extra_mpdu_prefix_len
,
1280 WLAN_AUTH_CHALLENGE_LEN
);
1287 /* Called only as a scheduled task for pending AP frames. */
1288 static void handle_authen(local_info_t
*local
, struct sk_buff
*skb
,
1289 struct hostap_80211_rx_status
*rx_stats
)
1291 struct net_device
*dev
= local
->dev
;
1292 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1294 struct ap_data
*ap
= local
->ap
;
1295 char body
[8 + WLAN_AUTH_CHALLENGE_LEN
], *challenge
= NULL
;
1297 u16 auth_alg
, auth_transaction
, status_code
, *pos
;
1298 u16 resp
= WLAN_STATUS_SUCCESS
, fc
;
1299 struct sta_info
*sta
= NULL
;
1300 struct ieee80211_crypt_data
*crypt
;
1303 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1305 fc
= le16_to_cpu(hdr
->frame_ctl
);
1306 hdrlen
= hostap_80211_get_hdrlen(fc
);
1309 PDEBUG(DEBUG_AP
, "%s: handle_authen - too short payload "
1310 "(len=%d) from " MACSTR
"\n", dev
->name
, len
,
1311 MAC2STR(hdr
->addr2
));
1315 spin_lock_bh(&local
->ap
->sta_table_lock
);
1316 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1318 atomic_inc(&sta
->users
);
1319 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1321 if (sta
&& sta
->crypt
)
1325 if (skb
->len
>= hdrlen
+ 3)
1326 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1327 crypt
= local
->crypt
[idx
];
1330 pos
= (u16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1331 auth_alg
= __le16_to_cpu(*pos
);
1333 auth_transaction
= __le16_to_cpu(*pos
);
1335 status_code
= __le16_to_cpu(*pos
);
1338 if (memcmp(dev
->dev_addr
, hdr
->addr2
, ETH_ALEN
) == 0 ||
1339 ap_control_mac_deny(&ap
->mac_restrictions
, hdr
->addr2
)) {
1340 txt
= "authentication denied";
1341 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1345 if (((local
->auth_algs
& PRISM2_AUTH_OPEN
) &&
1346 auth_alg
== WLAN_AUTH_OPEN
) ||
1347 ((local
->auth_algs
& PRISM2_AUTH_SHARED_KEY
) &&
1348 crypt
&& auth_alg
== WLAN_AUTH_SHARED_KEY
)) {
1350 txt
= "unsupported algorithm";
1351 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1357 if (*u
== WLAN_EID_CHALLENGE
) {
1358 if (*(u
+ 1) != WLAN_AUTH_CHALLENGE_LEN
) {
1359 txt
= "invalid challenge len";
1360 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1363 if (len
- 8 < WLAN_AUTH_CHALLENGE_LEN
) {
1364 txt
= "challenge underflow";
1365 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1368 challenge
= (char *) (u
+ 2);
1372 if (sta
&& sta
->ap
) {
1373 if (time_after(jiffies
, sta
->u
.ap
.last_beacon
+
1374 (10 * sta
->listen_interval
* HZ
) / 1024)) {
1375 PDEBUG(DEBUG_AP
, "%s: no beacons received for a while,"
1376 " assuming AP " MACSTR
" is now STA\n",
1377 dev
->name
, MAC2STR(sta
->addr
));
1380 sta
->u
.sta
.challenge
= NULL
;
1382 txt
= "AP trying to authenticate?";
1383 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1388 if ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 1) ||
1389 (auth_alg
== WLAN_AUTH_SHARED_KEY
&&
1390 (auth_transaction
== 1 ||
1391 (auth_transaction
== 3 && sta
!= NULL
&&
1392 sta
->u
.sta
.challenge
!= NULL
)))) {
1394 txt
= "unknown authentication transaction number";
1395 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1402 if (local
->ap
->num_sta
>= MAX_STA_COUNT
) {
1403 /* FIX: might try to remove some old STAs first? */
1404 txt
= "no more room for new STAs";
1405 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1409 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
1411 txt
= "ap_add_sta failed";
1412 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1418 case WLAN_AUTH_OPEN
:
1420 /* IEEE 802.11 standard is not completely clear about
1421 * whether STA is considered authenticated after
1422 * authentication OK frame has been send or after it
1423 * has been ACKed. In order to reduce interoperability
1424 * issues, mark the STA authenticated before ACK. */
1425 sta
->flags
|= WLAN_STA_AUTH
;
1428 case WLAN_AUTH_SHARED_KEY
:
1429 if (auth_transaction
== 1) {
1430 if (sta
->u
.sta
.challenge
== NULL
) {
1431 sta
->u
.sta
.challenge
=
1432 ap_auth_make_challenge(local
->ap
);
1433 if (sta
->u
.sta
.challenge
== NULL
) {
1434 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1439 if (sta
->u
.sta
.challenge
== NULL
||
1440 challenge
== NULL
||
1441 memcmp(sta
->u
.sta
.challenge
, challenge
,
1442 WLAN_AUTH_CHALLENGE_LEN
) != 0 ||
1443 !(fc
& IEEE80211_FCTL_PROTECTED
)) {
1444 txt
= "challenge response incorrect";
1445 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1449 txt
= "challenge OK - authOK";
1450 /* IEEE 802.11 standard is not completely clear about
1451 * whether STA is considered authenticated after
1452 * authentication OK frame has been send or after it
1453 * has been ACKed. In order to reduce interoperability
1454 * issues, mark the STA authenticated before ACK. */
1455 sta
->flags
|= WLAN_STA_AUTH
;
1456 kfree(sta
->u
.sta
.challenge
);
1457 sta
->u
.sta
.challenge
= NULL
;
1464 *pos
= cpu_to_le16(auth_alg
);
1466 *pos
= cpu_to_le16(auth_transaction
+ 1);
1468 *pos
= cpu_to_le16(resp
); /* status_code */
1472 if (resp
== WLAN_STATUS_SUCCESS
&& sta
!= NULL
&&
1473 sta
->u
.sta
.challenge
!= NULL
&&
1474 auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 1) {
1475 u8
*tmp
= (u8
*) pos
;
1476 *tmp
++ = WLAN_EID_CHALLENGE
;
1477 *tmp
++ = WLAN_AUTH_CHALLENGE_LEN
;
1479 memcpy(pos
, sta
->u
.sta
.challenge
, WLAN_AUTH_CHALLENGE_LEN
);
1480 olen
+= 2 + WLAN_AUTH_CHALLENGE_LEN
;
1483 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_AUTH
,
1484 body
, olen
, hdr
->addr2
, ap
->tx_callback_auth
);
1487 sta
->last_rx
= jiffies
;
1488 atomic_dec(&sta
->users
);
1492 PDEBUG(DEBUG_AP
, "%s: " MACSTR
" auth (alg=%d trans#=%d "
1493 "stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1494 dev
->name
, MAC2STR(hdr
->addr2
), auth_alg
,
1495 auth_transaction
, status_code
, len
, fc
, resp
, txt
);
1500 /* Called only as a scheduled task for pending AP frames. */
1501 static void handle_assoc(local_info_t
*local
, struct sk_buff
*skb
,
1502 struct hostap_80211_rx_status
*rx_stats
, int reassoc
)
1504 struct net_device
*dev
= local
->dev
;
1505 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1506 char body
[12], *p
, *lpos
;
1509 u16 resp
= WLAN_STATUS_SUCCESS
;
1510 struct sta_info
*sta
= NULL
;
1511 int send_deauth
= 0;
1513 u8 prev_ap
[ETH_ALEN
];
1515 left
= len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1517 if (len
< (reassoc
? 10 : 4)) {
1518 PDEBUG(DEBUG_AP
, "%s: handle_assoc - too short payload "
1519 "(len=%d, reassoc=%d) from " MACSTR
"\n",
1520 dev
->name
, len
, reassoc
, MAC2STR(hdr
->addr2
));
1524 spin_lock_bh(&local
->ap
->sta_table_lock
);
1525 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1526 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
1527 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1528 txt
= "trying to associate before authentication";
1530 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1531 sta
= NULL
; /* do not decrement sta->users */
1534 atomic_inc(&sta
->users
);
1535 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1537 pos
= (u16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1538 sta
->capability
= __le16_to_cpu(*pos
);
1540 sta
->listen_interval
= __le16_to_cpu(*pos
);
1544 memcpy(prev_ap
, pos
, ETH_ALEN
);
1545 pos
++; pos
++; pos
++; left
-= 6;
1547 memset(prev_ap
, 0, ETH_ALEN
);
1551 unsigned char *u
= (unsigned char *) pos
;
1553 if (*u
== WLAN_EID_SSID
) {
1558 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
1559 txt
= "SSID overflow";
1560 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1564 if (ileft
!= strlen(local
->essid
) ||
1565 memcmp(local
->essid
, u
, ileft
) != 0) {
1566 txt
= "not our SSID";
1567 resp
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1575 if (left
>= 2 && *u
== WLAN_EID_SUPP_RATES
) {
1580 if (ileft
> left
|| ileft
== 0 ||
1581 ileft
> WLAN_SUPP_RATES_MAX
) {
1582 txt
= "SUPP_RATES len error";
1583 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1587 memset(sta
->supported_rates
, 0,
1588 sizeof(sta
->supported_rates
));
1589 memcpy(sta
->supported_rates
, u
, ileft
);
1590 prism2_check_tx_rates(sta
);
1597 PDEBUG(DEBUG_AP
, "%s: assoc from " MACSTR
" with extra"
1598 " data (%d bytes) [",
1599 dev
->name
, MAC2STR(hdr
->addr2
), left
);
1601 PDEBUG2(DEBUG_AP
, "<%02x>", *u
);
1604 PDEBUG2(DEBUG_AP
, "]\n");
1607 txt
= "frame underflow";
1608 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1612 /* get a unique AID */
1614 txt
= "OK, old AID";
1616 spin_lock_bh(&local
->ap
->sta_table_lock
);
1617 for (sta
->aid
= 1; sta
->aid
<= MAX_AID_TABLE_SIZE
; sta
->aid
++)
1618 if (local
->ap
->sta_aid
[sta
->aid
- 1] == NULL
)
1620 if (sta
->aid
> MAX_AID_TABLE_SIZE
) {
1622 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1623 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1624 txt
= "no room for more AIDs";
1626 local
->ap
->sta_aid
[sta
->aid
- 1] = sta
;
1627 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1628 txt
= "OK, new AID";
1636 *pos
= __constant_cpu_to_le16(
1637 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH
);
1640 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1641 * values in beacons/probe responses */
1642 /* FIX: how about privacy and WEP? */
1644 *pos
= __constant_cpu_to_le16(WLAN_CAPABILITY_ESS
);
1648 *pos
= __cpu_to_le16(resp
);
1651 *pos
= __cpu_to_le16((sta
&& sta
->aid
> 0 ? sta
->aid
: 0) |
1652 BIT(14) | BIT(15)); /* AID */
1655 /* Supported rates (Information element) */
1657 *p
++ = WLAN_EID_SUPP_RATES
;
1660 if (local
->tx_rate_control
& WLAN_RATE_1M
) {
1661 *p
++ = local
->basic_rates
& WLAN_RATE_1M
? 0x82 : 0x02;
1664 if (local
->tx_rate_control
& WLAN_RATE_2M
) {
1665 *p
++ = local
->basic_rates
& WLAN_RATE_2M
? 0x84 : 0x04;
1668 if (local
->tx_rate_control
& WLAN_RATE_5M5
) {
1669 *p
++ = local
->basic_rates
& WLAN_RATE_5M5
?
1673 if (local
->tx_rate_control
& WLAN_RATE_11M
) {
1674 *p
++ = local
->basic_rates
& WLAN_RATE_11M
?
1681 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1682 (send_deauth
? IEEE80211_STYPE_DEAUTH
:
1683 (reassoc
? IEEE80211_STYPE_REASSOC_RESP
:
1684 IEEE80211_STYPE_ASSOC_RESP
)),
1685 body
, (u8
*) pos
- (u8
*) body
,
1687 send_deauth
? 0 : local
->ap
->tx_callback_assoc
);
1690 if (resp
== WLAN_STATUS_SUCCESS
) {
1691 sta
->last_rx
= jiffies
;
1692 /* STA will be marked associated from TX callback, if
1693 * AssocResp is ACKed */
1695 atomic_dec(&sta
->users
);
1699 PDEBUG(DEBUG_AP
, "%s: " MACSTR
" %sassoc (len=%d prev_ap=" MACSTR
1700 ") => %d(%d) (%s)\n",
1701 dev
->name
, MAC2STR(hdr
->addr2
), reassoc
? "re" : "", len
,
1702 MAC2STR(prev_ap
), resp
, send_deauth
, txt
);
1707 /* Called only as a scheduled task for pending AP frames. */
1708 static void handle_deauth(local_info_t
*local
, struct sk_buff
*skb
,
1709 struct hostap_80211_rx_status
*rx_stats
)
1711 struct net_device
*dev
= local
->dev
;
1712 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1713 char *body
= (char *) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1715 u16 reason_code
, *pos
;
1716 struct sta_info
*sta
= NULL
;
1718 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1721 printk("handle_deauth - too short payload (len=%d)\n", len
);
1726 reason_code
= __le16_to_cpu(*pos
);
1728 PDEBUG(DEBUG_AP
, "%s: deauthentication: " MACSTR
" len=%d, "
1729 "reason_code=%d\n", dev
->name
, MAC2STR(hdr
->addr2
), len
,
1732 spin_lock_bh(&local
->ap
->sta_table_lock
);
1733 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1735 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1736 hostap_event_expired_sta(local
->dev
, sta
);
1737 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
1739 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1741 printk("%s: deauthentication from " MACSTR
", "
1742 "reason_code=%d, but STA not authenticated\n", dev
->name
,
1743 MAC2STR(hdr
->addr2
), reason_code
);
1748 /* Called only as a scheduled task for pending AP frames. */
1749 static void handle_disassoc(local_info_t
*local
, struct sk_buff
*skb
,
1750 struct hostap_80211_rx_status
*rx_stats
)
1752 struct net_device
*dev
= local
->dev
;
1753 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1754 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
1756 u16 reason_code
, *pos
;
1757 struct sta_info
*sta
= NULL
;
1759 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1762 printk("handle_disassoc - too short payload (len=%d)\n", len
);
1767 reason_code
= __le16_to_cpu(*pos
);
1769 PDEBUG(DEBUG_AP
, "%s: disassociation: " MACSTR
" len=%d, "
1770 "reason_code=%d\n", dev
->name
, MAC2STR(hdr
->addr2
), len
,
1773 spin_lock_bh(&local
->ap
->sta_table_lock
);
1774 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1776 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1777 hostap_event_expired_sta(local
->dev
, sta
);
1778 sta
->flags
&= ~WLAN_STA_ASSOC
;
1780 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1782 printk("%s: disassociation from " MACSTR
", "
1783 "reason_code=%d, but STA not authenticated\n",
1784 dev
->name
, MAC2STR(hdr
->addr2
), reason_code
);
1789 /* Called only as a scheduled task for pending AP frames. */
1790 static void ap_handle_data_nullfunc(local_info_t
*local
,
1791 struct ieee80211_hdr_4addr
*hdr
)
1793 struct net_device
*dev
= local
->dev
;
1795 /* some STA f/w's seem to require control::ACK frame for
1796 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1798 * send control::ACK for the data::nullfunc */
1800 printk(KERN_DEBUG
"Sending control::ACK for data::nullfunc\n");
1801 prism2_send_mgmt(dev
, IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_ACK
,
1802 NULL
, 0, hdr
->addr2
, 0);
1806 /* Called only as a scheduled task for pending AP frames. */
1807 static void ap_handle_dropped_data(local_info_t
*local
,
1808 struct ieee80211_hdr_4addr
*hdr
)
1810 struct net_device
*dev
= local
->dev
;
1811 struct sta_info
*sta
;
1814 spin_lock_bh(&local
->ap
->sta_table_lock
);
1815 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1817 atomic_inc(&sta
->users
);
1818 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1820 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
)) {
1821 PDEBUG(DEBUG_AP
, "ap_handle_dropped_data: STA is now okay?\n");
1822 atomic_dec(&sta
->users
);
1826 reason
= __constant_cpu_to_le16(
1827 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
1828 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1829 ((sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) ?
1830 IEEE80211_STYPE_DEAUTH
: IEEE80211_STYPE_DISASSOC
),
1831 (char *) &reason
, sizeof(reason
), hdr
->addr2
, 0);
1834 atomic_dec(&sta
->users
);
1837 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1840 /* Called only as a scheduled task for pending AP frames. */
1841 static void pspoll_send_buffered(local_info_t
*local
, struct sta_info
*sta
,
1842 struct sk_buff
*skb
)
1844 struct hostap_skb_tx_data
*meta
;
1846 if (!(sta
->flags
& WLAN_STA_PS
)) {
1847 /* Station has moved to non-PS mode, so send all buffered
1848 * frames using normal device queue. */
1849 dev_queue_xmit(skb
);
1853 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1854 * be passed through even though STA is using PS */
1855 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1856 meta
->flags
|= HOSTAP_TX_FLAGS_BUFFERED_FRAME
;
1857 if (!skb_queue_empty(&sta
->tx_buf
)) {
1858 /* indicate to STA that more frames follow */
1859 meta
->flags
|= HOSTAP_TX_FLAGS_ADD_MOREDATA
;
1861 dev_queue_xmit(skb
);
1865 /* Called only as a scheduled task for pending AP frames. */
1866 static void handle_pspoll(local_info_t
*local
,
1867 struct ieee80211_hdr_4addr
*hdr
,
1868 struct hostap_80211_rx_status
*rx_stats
)
1870 struct net_device
*dev
= local
->dev
;
1871 struct sta_info
*sta
;
1873 struct sk_buff
*skb
;
1875 PDEBUG(DEBUG_PS2
, "handle_pspoll: BSSID=" MACSTR
", TA=" MACSTR
1877 MAC2STR(hdr
->addr1
), MAC2STR(hdr
->addr2
),
1878 !!(le16_to_cpu(hdr
->frame_ctl
) & IEEE80211_FCTL_PM
));
1880 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
1881 PDEBUG(DEBUG_AP
, "handle_pspoll - addr1(BSSID)=" MACSTR
1882 " not own MAC\n", MAC2STR(hdr
->addr1
));
1886 aid
= __le16_to_cpu(hdr
->duration_id
);
1887 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1888 PDEBUG(DEBUG_PS
, " PSPOLL and AID[15:14] not set\n");
1891 aid
&= ~BIT(15) & ~BIT(14);
1892 if (aid
== 0 || aid
> MAX_AID_TABLE_SIZE
) {
1893 PDEBUG(DEBUG_PS
, " invalid aid=%d\n", aid
);
1896 PDEBUG(DEBUG_PS2
, " aid=%d\n", aid
);
1898 spin_lock_bh(&local
->ap
->sta_table_lock
);
1899 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1901 atomic_inc(&sta
->users
);
1902 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1905 PDEBUG(DEBUG_PS
, " STA not found\n");
1908 if (sta
->aid
!= aid
) {
1909 PDEBUG(DEBUG_PS
, " received aid=%i does not match with "
1910 "assoc.aid=%d\n", aid
, sta
->aid
);
1915 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1916 * out (expiry time must be longer than ListenInterval for
1917 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1918 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1919 * sta; store buffer for later use and leave TIM aid bit set? use
1920 * TX event to check whether frame was ACKed?
1923 while ((skb
= skb_dequeue(&sta
->tx_buf
)) != NULL
) {
1924 /* send buffered frame .. */
1925 PDEBUG(DEBUG_PS2
, "Sending buffered frame to STA after PS POLL"
1926 " (buffer_count=%d)\n", skb_queue_len(&sta
->tx_buf
));
1928 pspoll_send_buffered(local
, sta
, skb
);
1930 if (sta
->flags
& WLAN_STA_PS
) {
1931 /* send only one buffered packet per PS Poll */
1932 /* FIX: should ignore further PS Polls until the
1933 * buffered packet that was just sent is acknowledged
1934 * (Tx or TxExc event) */
1939 if (skb_queue_empty(&sta
->tx_buf
)) {
1940 /* try to clear aid from TIM */
1941 if (!(sta
->flags
& WLAN_STA_TIM
))
1942 PDEBUG(DEBUG_PS2
, "Re-unsetting TIM for aid %d\n",
1944 hostap_set_tim(local
, aid
, 0);
1945 sta
->flags
&= ~WLAN_STA_TIM
;
1948 atomic_dec(&sta
->users
);
1952 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1954 static void handle_wds_oper_queue(struct work_struct
*work
)
1956 struct ap_data
*ap
= container_of(work
, struct ap_data
,
1958 local_info_t
*local
= ap
->local
;
1959 struct wds_oper_data
*entry
, *prev
;
1961 spin_lock_bh(&local
->lock
);
1962 entry
= local
->ap
->wds_oper_entries
;
1963 local
->ap
->wds_oper_entries
= NULL
;
1964 spin_unlock_bh(&local
->lock
);
1967 PDEBUG(DEBUG_AP
, "%s: %s automatic WDS connection "
1968 "to AP " MACSTR
"\n",
1970 entry
->type
== WDS_ADD
? "adding" : "removing",
1971 MAC2STR(entry
->addr
));
1972 if (entry
->type
== WDS_ADD
)
1973 prism2_wds_add(local
, entry
->addr
, 0);
1974 else if (entry
->type
== WDS_DEL
)
1975 prism2_wds_del(local
, entry
->addr
, 0, 1);
1978 entry
= entry
->next
;
1984 /* Called only as a scheduled task for pending AP frames. */
1985 static void handle_beacon(local_info_t
*local
, struct sk_buff
*skb
,
1986 struct hostap_80211_rx_status
*rx_stats
)
1988 struct ieee80211_hdr_4addr
*hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
1989 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
1991 u16
*pos
, beacon_int
, capability
;
1993 unsigned char *supp_rates
= NULL
;
1994 int ssid_len
= 0, supp_rates_len
= 0;
1995 struct sta_info
*sta
= NULL
;
1996 int new_sta
= 0, channel
= -1;
1998 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
2000 if (len
< 8 + 2 + 2) {
2001 printk(KERN_DEBUG
"handle_beacon - too short payload "
2009 /* Timestamp (8 octets) */
2010 pos
+= 4; left
-= 8;
2011 /* Beacon interval (2 octets) */
2012 beacon_int
= __le16_to_cpu(*pos
);
2014 /* Capability information (2 octets) */
2015 capability
= __le16_to_cpu(*pos
);
2018 if (local
->ap
->ap_policy
!= AP_OTHER_AP_EVEN_IBSS
&&
2019 capability
& WLAN_CAPABILITY_IBSS
)
2024 unsigned char *u
= (unsigned char *) pos
;
2026 if (*u
== WLAN_EID_SSID
) {
2031 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
2032 PDEBUG(DEBUG_AP
, "SSID: overflow\n");
2036 if (local
->ap
->ap_policy
== AP_OTHER_AP_SAME_SSID
&&
2037 (ileft
!= strlen(local
->essid
) ||
2038 memcmp(local
->essid
, u
, ileft
) != 0)) {
2050 if (*u
== WLAN_EID_SUPP_RATES
) {
2055 if (ileft
> left
|| ileft
== 0 || ileft
> 8) {
2056 PDEBUG(DEBUG_AP
, " - SUPP_RATES len error\n");
2061 supp_rates_len
= ileft
;
2067 if (*u
== WLAN_EID_DS_PARAMS
) {
2072 if (ileft
> left
|| ileft
!= 1) {
2073 PDEBUG(DEBUG_AP
, " - DS_PARAMS len error\n");
2084 spin_lock_bh(&local
->ap
->sta_table_lock
);
2085 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2087 atomic_inc(&sta
->users
);
2088 spin_unlock_bh(&local
->ap
->sta_table_lock
);
2093 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
2095 printk(KERN_INFO
"prism2: kmalloc failed for AP "
2096 "data structure\n");
2099 hostap_event_new_sta(local
->dev
, sta
);
2101 /* mark APs authentication and associated for pseudo ad-hoc
2102 * style communication */
2103 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2105 if (local
->ap
->autom_ap_wds
) {
2106 hostap_wds_link_oper(local
, sta
->addr
, WDS_ADD
);
2112 sta
->u
.ap
.ssid_len
= ssid_len
;
2113 memcpy(sta
->u
.ap
.ssid
, ssid
, ssid_len
);
2114 sta
->u
.ap
.ssid
[ssid_len
] = '\0';
2116 sta
->u
.ap
.ssid_len
= 0;
2117 sta
->u
.ap
.ssid
[0] = '\0';
2119 sta
->u
.ap
.channel
= channel
;
2121 sta
->rx_bytes
+= len
;
2122 sta
->u
.ap
.last_beacon
= sta
->last_rx
= jiffies
;
2123 sta
->capability
= capability
;
2124 sta
->listen_interval
= beacon_int
;
2126 atomic_dec(&sta
->users
);
2129 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
2130 memcpy(sta
->supported_rates
, supp_rates
, supp_rates_len
);
2131 prism2_check_tx_rates(sta
);
2135 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2138 /* Called only as a tasklet. */
2139 static void handle_ap_item(local_info_t
*local
, struct sk_buff
*skb
,
2140 struct hostap_80211_rx_status
*rx_stats
)
2142 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2143 struct net_device
*dev
= local
->dev
;
2144 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2145 u16 fc
, type
, stype
;
2146 struct ieee80211_hdr_4addr
*hdr
;
2148 /* FIX: should give skb->len to handler functions and check that the
2149 * buffer is long enough */
2150 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
2151 fc
= le16_to_cpu(hdr
->frame_ctl
);
2152 type
= WLAN_FC_GET_TYPE(fc
);
2153 stype
= WLAN_FC_GET_STYPE(fc
);
2155 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2156 if (!local
->hostapd
&& type
== IEEE80211_FTYPE_DATA
) {
2157 PDEBUG(DEBUG_AP
, "handle_ap_item - data frame\n");
2159 if (!(fc
& IEEE80211_FCTL_TODS
) ||
2160 (fc
& IEEE80211_FCTL_FROMDS
)) {
2161 if (stype
== IEEE80211_STYPE_NULLFUNC
) {
2162 /* no ToDS nullfunc seems to be used to check
2163 * AP association; so send reject message to
2164 * speed up re-association */
2165 ap_handle_dropped_data(local
, hdr
);
2168 PDEBUG(DEBUG_AP
, " not ToDS frame (fc=0x%04x)\n",
2173 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
2174 PDEBUG(DEBUG_AP
, "handle_ap_item - addr1(BSSID)="
2175 MACSTR
" not own MAC\n",
2176 MAC2STR(hdr
->addr1
));
2180 if (local
->ap
->nullfunc_ack
&&
2181 stype
== IEEE80211_STYPE_NULLFUNC
)
2182 ap_handle_data_nullfunc(local
, hdr
);
2184 ap_handle_dropped_data(local
, hdr
);
2188 if (type
== IEEE80211_FTYPE_MGMT
&& stype
== IEEE80211_STYPE_BEACON
) {
2189 handle_beacon(local
, skb
, rx_stats
);
2192 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2194 if (type
== IEEE80211_FTYPE_CTL
&& stype
== IEEE80211_STYPE_PSPOLL
) {
2195 handle_pspoll(local
, hdr
, rx_stats
);
2199 if (local
->hostapd
) {
2200 PDEBUG(DEBUG_AP
, "Unknown frame in AP queue: type=0x%02x "
2201 "subtype=0x%02x\n", type
, stype
);
2205 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2206 if (type
!= IEEE80211_FTYPE_MGMT
) {
2207 PDEBUG(DEBUG_AP
, "handle_ap_item - not a management frame?\n");
2211 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
2212 PDEBUG(DEBUG_AP
, "handle_ap_item - addr1(DA)=" MACSTR
2213 " not own MAC\n", MAC2STR(hdr
->addr1
));
2217 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
)) {
2218 PDEBUG(DEBUG_AP
, "handle_ap_item - addr3(BSSID)=" MACSTR
2219 " not own MAC\n", MAC2STR(hdr
->addr3
));
2224 case IEEE80211_STYPE_ASSOC_REQ
:
2225 handle_assoc(local
, skb
, rx_stats
, 0);
2227 case IEEE80211_STYPE_ASSOC_RESP
:
2228 PDEBUG(DEBUG_AP
, "==> ASSOC RESP (ignored)\n");
2230 case IEEE80211_STYPE_REASSOC_REQ
:
2231 handle_assoc(local
, skb
, rx_stats
, 1);
2233 case IEEE80211_STYPE_REASSOC_RESP
:
2234 PDEBUG(DEBUG_AP
, "==> REASSOC RESP (ignored)\n");
2236 case IEEE80211_STYPE_ATIM
:
2237 PDEBUG(DEBUG_AP
, "==> ATIM (ignored)\n");
2239 case IEEE80211_STYPE_DISASSOC
:
2240 handle_disassoc(local
, skb
, rx_stats
);
2242 case IEEE80211_STYPE_AUTH
:
2243 handle_authen(local
, skb
, rx_stats
);
2245 case IEEE80211_STYPE_DEAUTH
:
2246 handle_deauth(local
, skb
, rx_stats
);
2249 PDEBUG(DEBUG_AP
, "Unknown mgmt frame subtype 0x%02x\n",
2253 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2260 /* Called only as a tasklet (software IRQ) */
2261 void hostap_rx(struct net_device
*dev
, struct sk_buff
*skb
,
2262 struct hostap_80211_rx_status
*rx_stats
)
2264 struct hostap_interface
*iface
;
2265 local_info_t
*local
;
2267 struct ieee80211_hdr_4addr
*hdr
;
2269 iface
= netdev_priv(dev
);
2270 local
= iface
->local
;
2275 local
->stats
.rx_packets
++;
2277 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
2278 fc
= le16_to_cpu(hdr
->frame_ctl
);
2280 if (local
->ap
->ap_policy
== AP_OTHER_AP_SKIP_ALL
&&
2281 WLAN_FC_GET_TYPE(fc
) == IEEE80211_FTYPE_MGMT
&&
2282 WLAN_FC_GET_STYPE(fc
) == IEEE80211_STYPE_BEACON
)
2285 skb
->protocol
= __constant_htons(ETH_P_HOSTAP
);
2286 handle_ap_item(local
, skb
, rx_stats
);
2294 /* Called only as a tasklet (software IRQ) */
2295 static void schedule_packet_send(local_info_t
*local
, struct sta_info
*sta
)
2297 struct sk_buff
*skb
;
2298 struct ieee80211_hdr_4addr
*hdr
;
2299 struct hostap_80211_rx_status rx_stats
;
2301 if (skb_queue_empty(&sta
->tx_buf
))
2304 skb
= dev_alloc_skb(16);
2306 printk(KERN_DEBUG
"%s: schedule_packet_send: skb alloc "
2307 "failed\n", local
->dev
->name
);
2311 hdr
= (struct ieee80211_hdr_4addr
*) skb_put(skb
, 16);
2313 /* Generate a fake pspoll frame to start packet delivery */
2314 hdr
->frame_ctl
= __constant_cpu_to_le16(
2315 IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_PSPOLL
);
2316 memcpy(hdr
->addr1
, local
->dev
->dev_addr
, ETH_ALEN
);
2317 memcpy(hdr
->addr2
, sta
->addr
, ETH_ALEN
);
2318 hdr
->duration_id
= cpu_to_le16(sta
->aid
| BIT(15) | BIT(14));
2320 PDEBUG(DEBUG_PS2
, "%s: Scheduling buffered packet delivery for "
2321 "STA " MACSTR
"\n", local
->dev
->name
, MAC2STR(sta
->addr
));
2323 skb
->dev
= local
->dev
;
2325 memset(&rx_stats
, 0, sizeof(rx_stats
));
2326 hostap_rx(local
->dev
, skb
, &rx_stats
);
2330 int prism2_ap_get_sta_qual(local_info_t
*local
, struct sockaddr addr
[],
2331 struct iw_quality qual
[], int buf_size
,
2334 struct ap_data
*ap
= local
->ap
;
2335 struct list_head
*ptr
;
2338 spin_lock_bh(&ap
->sta_table_lock
);
2340 for (ptr
= ap
->sta_list
.next
; ptr
!= NULL
&& ptr
!= &ap
->sta_list
;
2342 struct sta_info
*sta
= (struct sta_info
*) ptr
;
2344 if (aplist
&& !sta
->ap
)
2346 addr
[count
].sa_family
= ARPHRD_ETHER
;
2347 memcpy(addr
[count
].sa_data
, sta
->addr
, ETH_ALEN
);
2348 if (sta
->last_rx_silence
== 0)
2349 qual
[count
].qual
= sta
->last_rx_signal
< 27 ?
2350 0 : (sta
->last_rx_signal
- 27) * 92 / 127;
2352 qual
[count
].qual
= sta
->last_rx_signal
-
2353 sta
->last_rx_silence
- 35;
2354 qual
[count
].level
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_signal
);
2355 qual
[count
].noise
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_silence
);
2356 qual
[count
].updated
= sta
->last_rx_updated
;
2358 sta
->last_rx_updated
= IW_QUAL_DBM
;
2361 if (count
>= buf_size
)
2364 spin_unlock_bh(&ap
->sta_table_lock
);
2370 /* Translate our list of Access Points & Stations to a card independant
2371 * format that the Wireless Tools will understand - Jean II */
2372 int prism2_ap_translate_scan(struct net_device
*dev
, char *buffer
)
2374 struct hostap_interface
*iface
;
2375 local_info_t
*local
;
2377 struct list_head
*ptr
;
2378 struct iw_event iwe
;
2379 char *current_ev
= buffer
;
2380 char *end_buf
= buffer
+ IW_SCAN_MAX_DATA
;
2381 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2385 iface
= netdev_priv(dev
);
2386 local
= iface
->local
;
2389 spin_lock_bh(&ap
->sta_table_lock
);
2391 for (ptr
= ap
->sta_list
.next
; ptr
!= NULL
&& ptr
!= &ap
->sta_list
;
2393 struct sta_info
*sta
= (struct sta_info
*) ptr
;
2395 /* First entry *MUST* be the AP MAC address */
2396 memset(&iwe
, 0, sizeof(iwe
));
2397 iwe
.cmd
= SIOCGIWAP
;
2398 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2399 memcpy(iwe
.u
.ap_addr
.sa_data
, sta
->addr
, ETH_ALEN
);
2400 iwe
.len
= IW_EV_ADDR_LEN
;
2401 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2404 /* Use the mode to indicate if it's a station or
2405 * an Access Point */
2406 memset(&iwe
, 0, sizeof(iwe
));
2407 iwe
.cmd
= SIOCGIWMODE
;
2409 iwe
.u
.mode
= IW_MODE_MASTER
;
2411 iwe
.u
.mode
= IW_MODE_INFRA
;
2412 iwe
.len
= IW_EV_UINT_LEN
;
2413 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2417 memset(&iwe
, 0, sizeof(iwe
));
2419 if (sta
->last_rx_silence
== 0)
2420 iwe
.u
.qual
.qual
= sta
->last_rx_signal
< 27 ?
2421 0 : (sta
->last_rx_signal
- 27) * 92 / 127;
2423 iwe
.u
.qual
.qual
= sta
->last_rx_signal
-
2424 sta
->last_rx_silence
- 35;
2425 iwe
.u
.qual
.level
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_signal
);
2426 iwe
.u
.qual
.noise
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_silence
);
2427 iwe
.u
.qual
.updated
= sta
->last_rx_updated
;
2428 iwe
.len
= IW_EV_QUAL_LEN
;
2429 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2432 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2434 memset(&iwe
, 0, sizeof(iwe
));
2435 iwe
.cmd
= SIOCGIWESSID
;
2436 iwe
.u
.data
.length
= sta
->u
.ap
.ssid_len
;
2437 iwe
.u
.data
.flags
= 1;
2438 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2442 memset(&iwe
, 0, sizeof(iwe
));
2443 iwe
.cmd
= SIOCGIWENCODE
;
2444 if (sta
->capability
& WLAN_CAPABILITY_PRIVACY
)
2446 IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2448 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2449 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2452 /* 0 byte memcpy */);
2454 if (sta
->u
.ap
.channel
> 0 &&
2455 sta
->u
.ap
.channel
<= FREQ_COUNT
) {
2456 memset(&iwe
, 0, sizeof(iwe
));
2457 iwe
.cmd
= SIOCGIWFREQ
;
2458 iwe
.u
.freq
.m
= freq_list
[sta
->u
.ap
.channel
- 1]
2461 current_ev
= iwe_stream_add_event(
2462 current_ev
, end_buf
, &iwe
,
2466 memset(&iwe
, 0, sizeof(iwe
));
2467 iwe
.cmd
= IWEVCUSTOM
;
2468 sprintf(buf
, "beacon_interval=%d",
2469 sta
->listen_interval
);
2470 iwe
.u
.data
.length
= strlen(buf
);
2471 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2474 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2476 sta
->last_rx_updated
= IW_QUAL_DBM
;
2478 /* To be continued, we should make good use of IWEVCUSTOM */
2481 spin_unlock_bh(&ap
->sta_table_lock
);
2483 return current_ev
- buffer
;
2487 static int prism2_hostapd_add_sta(struct ap_data
*ap
,
2488 struct prism2_hostapd_param
*param
)
2490 struct sta_info
*sta
;
2492 spin_lock_bh(&ap
->sta_table_lock
);
2493 sta
= ap_get_sta(ap
, param
->sta_addr
);
2495 atomic_inc(&sta
->users
);
2496 spin_unlock_bh(&ap
->sta_table_lock
);
2499 sta
= ap_add_sta(ap
, param
->sta_addr
);
2504 if (!(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2505 hostap_event_new_sta(sta
->local
->dev
, sta
);
2507 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2508 sta
->last_rx
= jiffies
;
2509 sta
->aid
= param
->u
.add_sta
.aid
;
2510 sta
->capability
= param
->u
.add_sta
.capability
;
2511 sta
->tx_supp_rates
= param
->u
.add_sta
.tx_supp_rates
;
2512 if (sta
->tx_supp_rates
& WLAN_RATE_1M
)
2513 sta
->supported_rates
[0] = 2;
2514 if (sta
->tx_supp_rates
& WLAN_RATE_2M
)
2515 sta
->supported_rates
[1] = 4;
2516 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
)
2517 sta
->supported_rates
[2] = 11;
2518 if (sta
->tx_supp_rates
& WLAN_RATE_11M
)
2519 sta
->supported_rates
[3] = 22;
2520 prism2_check_tx_rates(sta
);
2521 atomic_dec(&sta
->users
);
2526 static int prism2_hostapd_remove_sta(struct ap_data
*ap
,
2527 struct prism2_hostapd_param
*param
)
2529 struct sta_info
*sta
;
2531 spin_lock_bh(&ap
->sta_table_lock
);
2532 sta
= ap_get_sta(ap
, param
->sta_addr
);
2534 ap_sta_hash_del(ap
, sta
);
2535 list_del(&sta
->list
);
2537 spin_unlock_bh(&ap
->sta_table_lock
);
2542 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2543 hostap_event_expired_sta(sta
->local
->dev
, sta
);
2544 ap_free_sta(ap
, sta
);
2550 static int prism2_hostapd_get_info_sta(struct ap_data
*ap
,
2551 struct prism2_hostapd_param
*param
)
2553 struct sta_info
*sta
;
2555 spin_lock_bh(&ap
->sta_table_lock
);
2556 sta
= ap_get_sta(ap
, param
->sta_addr
);
2558 atomic_inc(&sta
->users
);
2559 spin_unlock_bh(&ap
->sta_table_lock
);
2564 param
->u
.get_info_sta
.inactive_sec
= (jiffies
- sta
->last_rx
) / HZ
;
2566 atomic_dec(&sta
->users
);
2572 static int prism2_hostapd_set_flags_sta(struct ap_data
*ap
,
2573 struct prism2_hostapd_param
*param
)
2575 struct sta_info
*sta
;
2577 spin_lock_bh(&ap
->sta_table_lock
);
2578 sta
= ap_get_sta(ap
, param
->sta_addr
);
2580 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
2581 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
2583 spin_unlock_bh(&ap
->sta_table_lock
);
2592 static int prism2_hostapd_sta_clear_stats(struct ap_data
*ap
,
2593 struct prism2_hostapd_param
*param
)
2595 struct sta_info
*sta
;
2598 spin_lock_bh(&ap
->sta_table_lock
);
2599 sta
= ap_get_sta(ap
, param
->sta_addr
);
2601 sta
->rx_packets
= sta
->tx_packets
= 0;
2602 sta
->rx_bytes
= sta
->tx_bytes
= 0;
2603 for (rate
= 0; rate
< WLAN_RATE_COUNT
; rate
++) {
2604 sta
->tx_count
[rate
] = 0;
2605 sta
->rx_count
[rate
] = 0;
2608 spin_unlock_bh(&ap
->sta_table_lock
);
2617 int prism2_hostapd(struct ap_data
*ap
, struct prism2_hostapd_param
*param
)
2619 switch (param
->cmd
) {
2620 case PRISM2_HOSTAPD_FLUSH
:
2621 ap_control_kickall(ap
);
2623 case PRISM2_HOSTAPD_ADD_STA
:
2624 return prism2_hostapd_add_sta(ap
, param
);
2625 case PRISM2_HOSTAPD_REMOVE_STA
:
2626 return prism2_hostapd_remove_sta(ap
, param
);
2627 case PRISM2_HOSTAPD_GET_INFO_STA
:
2628 return prism2_hostapd_get_info_sta(ap
, param
);
2629 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
2630 return prism2_hostapd_set_flags_sta(ap
, param
);
2631 case PRISM2_HOSTAPD_STA_CLEAR_STATS
:
2632 return prism2_hostapd_sta_clear_stats(ap
, param
);
2634 printk(KERN_WARNING
"prism2_hostapd: unknown cmd=%d\n",
2641 /* Update station info for host-based TX rate control and return current
2643 static int ap_update_sta_tx_rate(struct sta_info
*sta
, struct net_device
*dev
)
2645 int ret
= sta
->tx_rate
;
2646 struct hostap_interface
*iface
;
2647 local_info_t
*local
;
2649 iface
= netdev_priv(dev
);
2650 local
= iface
->local
;
2652 sta
->tx_count
[sta
->tx_rate_idx
]++;
2653 sta
->tx_since_last_failure
++;
2654 sta
->tx_consecutive_exc
= 0;
2655 if (sta
->tx_since_last_failure
>= WLAN_RATE_UPDATE_COUNT
&&
2656 sta
->tx_rate_idx
< sta
->tx_max_rate
) {
2657 /* use next higher rate */
2658 int old_rate
, new_rate
;
2659 old_rate
= new_rate
= sta
->tx_rate_idx
;
2660 while (new_rate
< sta
->tx_max_rate
) {
2662 if (ap_tx_rate_ok(new_rate
, sta
, local
)) {
2663 sta
->tx_rate_idx
= new_rate
;
2667 if (old_rate
!= sta
->tx_rate_idx
) {
2668 switch (sta
->tx_rate_idx
) {
2669 case 0: sta
->tx_rate
= 10; break;
2670 case 1: sta
->tx_rate
= 20; break;
2671 case 2: sta
->tx_rate
= 55; break;
2672 case 3: sta
->tx_rate
= 110; break;
2673 default: sta
->tx_rate
= 0; break;
2675 PDEBUG(DEBUG_AP
, "%s: STA " MACSTR
" TX rate raised to"
2676 " %d\n", dev
->name
, MAC2STR(sta
->addr
),
2679 sta
->tx_since_last_failure
= 0;
2686 /* Called only from software IRQ. Called for each TX frame prior possible
2687 * encryption and transmit. */
2688 ap_tx_ret
hostap_handle_sta_tx(local_info_t
*local
, struct hostap_tx_data
*tx
)
2690 struct sta_info
*sta
= NULL
;
2691 struct sk_buff
*skb
= tx
->skb
;
2693 struct ieee80211_hdr_4addr
*hdr
;
2694 struct hostap_skb_tx_data
*meta
;
2696 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2697 ret
= AP_TX_CONTINUE
;
2698 if (local
->ap
== NULL
|| skb
->len
< 10 ||
2699 meta
->iface
->type
== HOSTAP_INTERFACE_STA
)
2702 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
2704 if (hdr
->addr1
[0] & 0x01) {
2705 /* broadcast/multicast frame - no AP related processing */
2709 /* unicast packet - check whether destination STA is associated */
2710 spin_lock(&local
->ap
->sta_table_lock
);
2711 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2713 atomic_inc(&sta
->users
);
2714 spin_unlock(&local
->ap
->sta_table_lock
);
2716 if (local
->iw_mode
== IW_MODE_MASTER
&& sta
== NULL
&&
2717 !(meta
->flags
& HOSTAP_TX_FLAGS_WDS
) &&
2718 meta
->iface
->type
!= HOSTAP_INTERFACE_MASTER
&&
2719 meta
->iface
->type
!= HOSTAP_INTERFACE_AP
) {
2721 /* This can happen, e.g., when wlan0 is added to a bridge and
2722 * bridging code does not know which port is the correct target
2723 * for a unicast frame. In this case, the packet is send to all
2724 * ports of the bridge. Since this is a valid scenario, do not
2725 * print out any errors here. */
2726 if (net_ratelimit()) {
2727 printk(KERN_DEBUG
"AP: drop packet to non-associated "
2728 "STA " MACSTR
"\n", MAC2STR(hdr
->addr1
));
2731 local
->ap
->tx_drop_nonassoc
++;
2739 if (!(sta
->flags
& WLAN_STA_AUTHORIZED
))
2740 ret
= AP_TX_CONTINUE_NOT_AUTHORIZED
;
2742 /* Set tx_rate if using host-based TX rate control */
2743 if (!local
->fw_tx_rate_control
)
2744 local
->ap
->last_tx_rate
= meta
->rate
=
2745 ap_update_sta_tx_rate(sta
, local
->dev
);
2747 if (local
->iw_mode
!= IW_MODE_MASTER
)
2750 if (!(sta
->flags
& WLAN_STA_PS
))
2753 if (meta
->flags
& HOSTAP_TX_FLAGS_ADD_MOREDATA
) {
2754 /* indicate to STA that more frames follow */
2756 __constant_cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
2759 if (meta
->flags
& HOSTAP_TX_FLAGS_BUFFERED_FRAME
) {
2760 /* packet was already buffered and now send due to
2761 * PS poll, so do not rebuffer it */
2765 if (skb_queue_len(&sta
->tx_buf
) >= STA_MAX_TX_BUFFER
) {
2766 PDEBUG(DEBUG_PS
, "%s: No more space in STA (" MACSTR
")'s PS "
2767 "mode buffer\n", local
->dev
->name
, MAC2STR(sta
->addr
));
2768 /* Make sure that TIM is set for the station (it might not be
2769 * after AP wlan hw reset). */
2770 /* FIX: should fix hw reset to restore bits based on STA
2772 hostap_set_tim(local
, sta
->aid
, 1);
2773 sta
->flags
|= WLAN_STA_TIM
;
2778 /* STA in PS mode, buffer frame for later delivery */
2779 set_tim
= skb_queue_empty(&sta
->tx_buf
);
2780 skb_queue_tail(&sta
->tx_buf
, skb
);
2781 /* FIX: could save RX time to skb and expire buffered frames after
2782 * some time if STA does not poll for them */
2785 if (sta
->flags
& WLAN_STA_TIM
)
2786 PDEBUG(DEBUG_PS2
, "Re-setting TIM for aid %d\n",
2788 hostap_set_tim(local
, sta
->aid
, 1);
2789 sta
->flags
|= WLAN_STA_TIM
;
2792 ret
= AP_TX_BUFFERED
;
2796 if (ret
== AP_TX_CONTINUE
||
2797 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) {
2799 sta
->tx_bytes
+= skb
->len
;
2800 sta
->last_tx
= jiffies
;
2803 if ((ret
== AP_TX_CONTINUE
||
2804 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) &&
2805 sta
->crypt
&& tx
->host_encrypt
) {
2806 tx
->crypt
= sta
->crypt
;
2807 tx
->sta_ptr
= sta
; /* hostap_handle_sta_release() will
2808 * be called to release sta info
2811 atomic_dec(&sta
->users
);
2818 void hostap_handle_sta_release(void *ptr
)
2820 struct sta_info
*sta
= ptr
;
2821 atomic_dec(&sta
->users
);
2825 /* Called only as a tasklet (software IRQ) */
2826 void hostap_handle_sta_tx_exc(local_info_t
*local
, struct sk_buff
*skb
)
2828 struct sta_info
*sta
;
2829 struct ieee80211_hdr_4addr
*hdr
;
2830 struct hostap_skb_tx_data
*meta
;
2832 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
2833 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2835 spin_lock(&local
->ap
->sta_table_lock
);
2836 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2838 spin_unlock(&local
->ap
->sta_table_lock
);
2839 PDEBUG(DEBUG_AP
, "%s: Could not find STA " MACSTR
" for this "
2840 "TX error (@%lu)\n",
2841 local
->dev
->name
, MAC2STR(hdr
->addr1
), jiffies
);
2845 sta
->tx_since_last_failure
= 0;
2846 sta
->tx_consecutive_exc
++;
2848 if (sta
->tx_consecutive_exc
>= WLAN_RATE_DECREASE_THRESHOLD
&&
2849 sta
->tx_rate_idx
> 0 && meta
->rate
<= sta
->tx_rate
) {
2850 /* use next lower rate */
2852 old
= rate
= sta
->tx_rate_idx
;
2855 if (ap_tx_rate_ok(rate
, sta
, local
)) {
2856 sta
->tx_rate_idx
= rate
;
2860 if (old
!= sta
->tx_rate_idx
) {
2861 switch (sta
->tx_rate_idx
) {
2862 case 0: sta
->tx_rate
= 10; break;
2863 case 1: sta
->tx_rate
= 20; break;
2864 case 2: sta
->tx_rate
= 55; break;
2865 case 3: sta
->tx_rate
= 110; break;
2866 default: sta
->tx_rate
= 0; break;
2868 PDEBUG(DEBUG_AP
, "%s: STA " MACSTR
" TX rate lowered "
2869 "to %d\n", local
->dev
->name
, MAC2STR(sta
->addr
),
2872 sta
->tx_consecutive_exc
= 0;
2874 spin_unlock(&local
->ap
->sta_table_lock
);
2878 static void hostap_update_sta_ps2(local_info_t
*local
, struct sta_info
*sta
,
2879 int pwrmgt
, int type
, int stype
)
2881 if (pwrmgt
&& !(sta
->flags
& WLAN_STA_PS
)) {
2882 sta
->flags
|= WLAN_STA_PS
;
2883 PDEBUG(DEBUG_PS2
, "STA " MACSTR
" changed to use PS "
2884 "mode (type=0x%02X, stype=0x%02X)\n",
2885 MAC2STR(sta
->addr
), type
>> 2, stype
>> 4);
2886 } else if (!pwrmgt
&& (sta
->flags
& WLAN_STA_PS
)) {
2887 sta
->flags
&= ~WLAN_STA_PS
;
2888 PDEBUG(DEBUG_PS2
, "STA " MACSTR
" changed to not use "
2889 "PS mode (type=0x%02X, stype=0x%02X)\n",
2890 MAC2STR(sta
->addr
), type
>> 2, stype
>> 4);
2891 if (type
!= IEEE80211_FTYPE_CTL
||
2892 stype
!= IEEE80211_STYPE_PSPOLL
)
2893 schedule_packet_send(local
, sta
);
2898 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2899 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
2900 int hostap_update_sta_ps(local_info_t
*local
, struct ieee80211_hdr_4addr
*hdr
)
2902 struct sta_info
*sta
;
2905 spin_lock(&local
->ap
->sta_table_lock
);
2906 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2908 atomic_inc(&sta
->users
);
2909 spin_unlock(&local
->ap
->sta_table_lock
);
2914 fc
= le16_to_cpu(hdr
->frame_ctl
);
2915 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
2916 WLAN_FC_GET_TYPE(fc
), WLAN_FC_GET_STYPE(fc
));
2918 atomic_dec(&sta
->users
);
2923 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2924 * getting RX header and payload from hardware. */
2925 ap_rx_ret
hostap_handle_sta_rx(local_info_t
*local
, struct net_device
*dev
,
2926 struct sk_buff
*skb
,
2927 struct hostap_80211_rx_status
*rx_stats
,
2931 struct sta_info
*sta
;
2932 u16 fc
, type
, stype
;
2933 struct ieee80211_hdr_4addr
*hdr
;
2935 if (local
->ap
== NULL
)
2936 return AP_RX_CONTINUE
;
2938 hdr
= (struct ieee80211_hdr_4addr
*) skb
->data
;
2940 fc
= le16_to_cpu(hdr
->frame_ctl
);
2941 type
= WLAN_FC_GET_TYPE(fc
);
2942 stype
= WLAN_FC_GET_STYPE(fc
);
2944 spin_lock(&local
->ap
->sta_table_lock
);
2945 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2947 atomic_inc(&sta
->users
);
2948 spin_unlock(&local
->ap
->sta_table_lock
);
2950 if (sta
&& !(sta
->flags
& WLAN_STA_AUTHORIZED
))
2951 ret
= AP_RX_CONTINUE_NOT_AUTHORIZED
;
2953 ret
= AP_RX_CONTINUE
;
2956 if (fc
& IEEE80211_FCTL_TODS
) {
2957 if (!wds
&& (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
2958 if (local
->hostapd
) {
2959 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
2960 PRISM2_RX_NON_ASSOC
);
2961 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2963 printk(KERN_DEBUG
"%s: dropped received packet"
2964 " from non-associated STA " MACSTR
2965 " (type=0x%02x, subtype=0x%02x)\n",
2966 dev
->name
, MAC2STR(hdr
->addr2
),
2967 type
>> 2, stype
>> 4);
2968 hostap_rx(dev
, skb
, rx_stats
);
2969 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2974 } else if (fc
& IEEE80211_FCTL_FROMDS
) {
2976 /* FromDS frame - not for us; probably
2977 * broadcast/multicast in another BSS - drop */
2978 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
2979 printk(KERN_DEBUG
"Odd.. FromDS packet "
2980 "received with own BSSID\n");
2981 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
2986 } else if (stype
== IEEE80211_STYPE_NULLFUNC
&& sta
== NULL
&&
2987 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
2989 if (local
->hostapd
) {
2990 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
2991 PRISM2_RX_NON_ASSOC
);
2992 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2994 /* At least Lucent f/w seems to send data::nullfunc
2995 * frames with no ToDS flag when the current AP returns
2996 * after being unavailable for some time. Speed up
2997 * re-association by informing the station about it not
2998 * being associated. */
2999 printk(KERN_DEBUG
"%s: rejected received nullfunc "
3000 "frame without ToDS from not associated STA "
3002 dev
->name
, MAC2STR(hdr
->addr2
));
3003 hostap_rx(dev
, skb
, rx_stats
);
3004 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3008 } else if (stype
== IEEE80211_STYPE_NULLFUNC
) {
3009 /* At least Lucent cards seem to send periodic nullfunc
3010 * frames with ToDS. Let these through to update SQ
3011 * stats and PS state. Nullfunc frames do not contain
3012 * any data and they will be dropped below. */
3014 /* If BSSID (Addr3) is foreign, this frame is a normal
3015 * broadcast frame from an IBSS network. Drop it silently.
3016 * If BSSID is own, report the dropping of this frame. */
3017 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
3018 printk(KERN_DEBUG
"%s: dropped received packet from "
3019 MACSTR
" with no ToDS flag (type=0x%02x, "
3020 "subtype=0x%02x)\n", dev
->name
,
3021 MAC2STR(hdr
->addr2
), type
>> 2, stype
>> 4);
3022 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
3029 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
3033 sta
->rx_bytes
+= skb
->len
;
3034 sta
->last_rx
= jiffies
;
3037 if (local
->ap
->nullfunc_ack
&& stype
== IEEE80211_STYPE_NULLFUNC
&&
3038 fc
& IEEE80211_FCTL_TODS
) {
3039 if (local
->hostapd
) {
3040 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
3041 PRISM2_RX_NULLFUNC_ACK
);
3042 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3044 /* some STA f/w's seem to require control::ACK frame
3045 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3046 * from Compaq) does not send this.. Try to generate
3047 * ACK for these frames from the host driver to make
3048 * power saving work with, e.g., Lucent WaveLAN f/w */
3049 hostap_rx(dev
, skb
, rx_stats
);
3050 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3058 atomic_dec(&sta
->users
);
3064 /* Called only as a tasklet (software IRQ) */
3065 int hostap_handle_sta_crypto(local_info_t
*local
,
3066 struct ieee80211_hdr_4addr
*hdr
,
3067 struct ieee80211_crypt_data
**crypt
,
3070 struct sta_info
*sta
;
3072 spin_lock(&local
->ap
->sta_table_lock
);
3073 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
3075 atomic_inc(&sta
->users
);
3076 spin_unlock(&local
->ap
->sta_table_lock
);
3082 *crypt
= sta
->crypt
;
3084 /* hostap_handle_sta_release() will be called to release STA
3087 atomic_dec(&sta
->users
);
3093 /* Called only as a tasklet (software IRQ) */
3094 int hostap_is_sta_assoc(struct ap_data
*ap
, u8
*sta_addr
)
3096 struct sta_info
*sta
;
3099 spin_lock(&ap
->sta_table_lock
);
3100 sta
= ap_get_sta(ap
, sta_addr
);
3101 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
3103 spin_unlock(&ap
->sta_table_lock
);
3109 /* Called only as a tasklet (software IRQ) */
3110 int hostap_is_sta_authorized(struct ap_data
*ap
, u8
*sta_addr
)
3112 struct sta_info
*sta
;
3115 spin_lock(&ap
->sta_table_lock
);
3116 sta
= ap_get_sta(ap
, sta_addr
);
3117 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&&
3118 ((sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3119 ap
->local
->ieee_802_1x
== 0))
3121 spin_unlock(&ap
->sta_table_lock
);
3127 /* Called only as a tasklet (software IRQ) */
3128 int hostap_add_sta(struct ap_data
*ap
, u8
*sta_addr
)
3130 struct sta_info
*sta
;
3136 spin_lock(&ap
->sta_table_lock
);
3137 sta
= ap_get_sta(ap
, sta_addr
);
3140 spin_unlock(&ap
->sta_table_lock
);
3143 sta
= ap_add_sta(ap
, sta_addr
);
3146 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
3148 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
3149 /* No way of knowing which rates are supported since we did not
3150 * get supported rates element from beacon/assoc req. Assume
3151 * that remote end supports all 802.11b rates. */
3152 sta
->supported_rates
[0] = 0x82;
3153 sta
->supported_rates
[1] = 0x84;
3154 sta
->supported_rates
[2] = 0x0b;
3155 sta
->supported_rates
[3] = 0x16;
3156 sta
->tx_supp_rates
= WLAN_RATE_1M
| WLAN_RATE_2M
|
3157 WLAN_RATE_5M5
| WLAN_RATE_11M
;
3159 sta
->tx_max_rate
= sta
->tx_rate_idx
= 3;
3166 /* Called only as a tasklet (software IRQ) */
3167 int hostap_update_rx_stats(struct ap_data
*ap
,
3168 struct ieee80211_hdr_4addr
*hdr
,
3169 struct hostap_80211_rx_status
*rx_stats
)
3171 struct sta_info
*sta
;
3176 spin_lock(&ap
->sta_table_lock
);
3177 sta
= ap_get_sta(ap
, hdr
->addr2
);
3179 sta
->last_rx_silence
= rx_stats
->noise
;
3180 sta
->last_rx_signal
= rx_stats
->signal
;
3181 sta
->last_rx_rate
= rx_stats
->rate
;
3182 sta
->last_rx_updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
3183 if (rx_stats
->rate
== 10)
3185 else if (rx_stats
->rate
== 20)
3187 else if (rx_stats
->rate
== 55)
3189 else if (rx_stats
->rate
== 110)
3192 spin_unlock(&ap
->sta_table_lock
);
3194 return sta
? 0 : -1;
3198 void hostap_update_rates(local_info_t
*local
)
3200 struct list_head
*ptr
;
3201 struct ap_data
*ap
= local
->ap
;
3206 spin_lock_bh(&ap
->sta_table_lock
);
3207 for (ptr
= ap
->sta_list
.next
; ptr
!= &ap
->sta_list
; ptr
= ptr
->next
) {
3208 struct sta_info
*sta
= (struct sta_info
*) ptr
;
3209 prism2_check_tx_rates(sta
);
3211 spin_unlock_bh(&ap
->sta_table_lock
);
3215 void * ap_crypt_get_ptrs(struct ap_data
*ap
, u8
*addr
, int permanent
,
3216 struct ieee80211_crypt_data
***crypt
)
3218 struct sta_info
*sta
;
3220 spin_lock_bh(&ap
->sta_table_lock
);
3221 sta
= ap_get_sta(ap
, addr
);
3223 atomic_inc(&sta
->users
);
3224 spin_unlock_bh(&ap
->sta_table_lock
);
3226 if (!sta
&& permanent
)
3227 sta
= ap_add_sta(ap
, addr
);
3233 sta
->flags
|= WLAN_STA_PERM
;
3235 *crypt
= &sta
->crypt
;
3241 void hostap_add_wds_links(local_info_t
*local
)
3243 struct ap_data
*ap
= local
->ap
;
3244 struct list_head
*ptr
;
3246 spin_lock_bh(&ap
->sta_table_lock
);
3247 list_for_each(ptr
, &ap
->sta_list
) {
3248 struct sta_info
*sta
= list_entry(ptr
, struct sta_info
, list
);
3250 hostap_wds_link_oper(local
, sta
->addr
, WDS_ADD
);
3252 spin_unlock_bh(&ap
->sta_table_lock
);
3254 schedule_work(&local
->ap
->wds_oper_queue
);
3258 void hostap_wds_link_oper(local_info_t
*local
, u8
*addr
, wds_oper_type type
)
3260 struct wds_oper_data
*entry
;
3262 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
3265 memcpy(entry
->addr
, addr
, ETH_ALEN
);
3267 spin_lock_bh(&local
->lock
);
3268 entry
->next
= local
->ap
->wds_oper_entries
;
3269 local
->ap
->wds_oper_entries
= entry
;
3270 spin_unlock_bh(&local
->lock
);
3272 schedule_work(&local
->ap
->wds_oper_queue
);
3276 EXPORT_SYMBOL(hostap_init_data
);
3277 EXPORT_SYMBOL(hostap_init_ap_proc
);
3278 EXPORT_SYMBOL(hostap_free_data
);
3279 EXPORT_SYMBOL(hostap_check_sta_fw_version
);
3280 EXPORT_SYMBOL(hostap_handle_sta_tx_exc
);
3281 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3282 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */