2 * Intersil Prism2 driver with Host AP (software access point) support
3 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
5 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
7 * This file is to be included into hostap.c when S/W AP functionality is
11 * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
12 * unauthenticated STA, send deauth. frame (8802.11: 5.5)
13 * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
14 * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
15 * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
19 #include <linux/proc_fs.h>
20 #include <linux/seq_file.h>
21 #include <linux/delay.h>
22 #include <linux/random.h>
23 #include <linux/if_arp.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <linux/moduleparam.h>
28 #include "hostap_wlan.h"
30 #include "hostap_ap.h"
32 static int other_ap_policy
[MAX_PARM_DEVICES
] = { AP_OTHER_AP_SKIP_ALL
,
34 module_param_array(other_ap_policy
, int, NULL
, 0444);
35 MODULE_PARM_DESC(other_ap_policy
, "Other AP beacon monitoring policy (0-3)");
37 static int ap_max_inactivity
[MAX_PARM_DEVICES
] = { AP_MAX_INACTIVITY_SEC
,
39 module_param_array(ap_max_inactivity
, int, NULL
, 0444);
40 MODULE_PARM_DESC(ap_max_inactivity
, "AP timeout (in seconds) for station "
43 static int ap_bridge_packets
[MAX_PARM_DEVICES
] = { 1, DEF_INTS
};
44 module_param_array(ap_bridge_packets
, int, NULL
, 0444);
45 MODULE_PARM_DESC(ap_bridge_packets
, "Bridge packets directly between "
48 static int autom_ap_wds
[MAX_PARM_DEVICES
] = { 0, DEF_INTS
};
49 module_param_array(autom_ap_wds
, int, NULL
, 0444);
50 MODULE_PARM_DESC(autom_ap_wds
, "Add WDS connections to other APs "
54 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
);
55 static void hostap_event_expired_sta(struct net_device
*dev
,
56 struct sta_info
*sta
);
57 static void handle_add_proc_queue(struct work_struct
*work
);
59 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
60 static void handle_wds_oper_queue(struct work_struct
*work
);
61 static void prism2_send_mgmt(struct net_device
*dev
,
62 u16 type_subtype
, char *body
,
63 int body_len
, u8
*addr
, u16 tx_cb_idx
);
64 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
67 #ifndef PRISM2_NO_PROCFS_DEBUG
68 static int ap_debug_proc_show(struct seq_file
*m
, void *v
)
70 struct ap_data
*ap
= m
->private;
72 seq_printf(m
, "BridgedUnicastFrames=%u\n", ap
->bridged_unicast
);
73 seq_printf(m
, "BridgedMulticastFrames=%u\n", ap
->bridged_multicast
);
74 seq_printf(m
, "max_inactivity=%u\n", ap
->max_inactivity
/ HZ
);
75 seq_printf(m
, "bridge_packets=%u\n", ap
->bridge_packets
);
76 seq_printf(m
, "nullfunc_ack=%u\n", ap
->nullfunc_ack
);
77 seq_printf(m
, "autom_ap_wds=%u\n", ap
->autom_ap_wds
);
78 seq_printf(m
, "auth_algs=%u\n", ap
->local
->auth_algs
);
79 seq_printf(m
, "tx_drop_nonassoc=%u\n", ap
->tx_drop_nonassoc
);
83 static int ap_debug_proc_open(struct inode
*inode
, struct file
*file
)
85 return single_open(file
, ap_debug_proc_show
, PDE_DATA(inode
));
88 static const struct file_operations ap_debug_proc_fops
= {
89 .open
= ap_debug_proc_open
,
92 .release
= single_release
,
94 #endif /* PRISM2_NO_PROCFS_DEBUG */
97 static void ap_sta_hash_add(struct ap_data
*ap
, struct sta_info
*sta
)
99 sta
->hnext
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
100 ap
->sta_hash
[STA_HASH(sta
->addr
)] = sta
;
103 static void ap_sta_hash_del(struct ap_data
*ap
, struct sta_info
*sta
)
107 s
= ap
->sta_hash
[STA_HASH(sta
->addr
)];
108 if (s
== NULL
) return;
109 if (memcmp(s
->addr
, sta
->addr
, ETH_ALEN
) == 0) {
110 ap
->sta_hash
[STA_HASH(sta
->addr
)] = s
->hnext
;
114 while (s
->hnext
!= NULL
&& memcmp(s
->hnext
->addr
, sta
->addr
, ETH_ALEN
)
117 if (s
->hnext
!= NULL
)
118 s
->hnext
= s
->hnext
->hnext
;
120 printk("AP: could not remove STA %pM from hash table\n",
124 static void ap_free_sta(struct ap_data
*ap
, struct sta_info
*sta
)
126 if (sta
->ap
&& sta
->local
)
127 hostap_event_expired_sta(sta
->local
->dev
, sta
);
129 if (ap
->proc
!= NULL
) {
131 sprintf(name
, "%pM", sta
->addr
);
132 remove_proc_entry(name
, ap
->proc
);
136 sta
->crypt
->ops
->deinit(sta
->crypt
->priv
);
141 skb_queue_purge(&sta
->tx_buf
);
144 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
146 ap
->sta_aid
[sta
->aid
- 1] = NULL
;
148 if (!sta
->ap
&& sta
->u
.sta
.challenge
)
149 kfree(sta
->u
.sta
.challenge
);
150 del_timer(&sta
->timer
);
151 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
157 static void hostap_set_tim(local_info_t
*local
, int aid
, int set
)
159 if (local
->func
->set_tim
)
160 local
->func
->set_tim(local
->dev
, aid
, set
);
164 static void hostap_event_new_sta(struct net_device
*dev
, struct sta_info
*sta
)
166 union iwreq_data wrqu
;
167 memset(&wrqu
, 0, sizeof(wrqu
));
168 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
169 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
170 wireless_send_event(dev
, IWEVREGISTERED
, &wrqu
, NULL
);
174 static void hostap_event_expired_sta(struct net_device
*dev
,
175 struct sta_info
*sta
)
177 union iwreq_data wrqu
;
178 memset(&wrqu
, 0, sizeof(wrqu
));
179 memcpy(wrqu
.addr
.sa_data
, sta
->addr
, ETH_ALEN
);
180 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
181 wireless_send_event(dev
, IWEVEXPIRED
, &wrqu
, NULL
);
185 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
187 static void ap_handle_timer(unsigned long data
)
189 struct sta_info
*sta
= (struct sta_info
*) data
;
192 unsigned long next_time
= 0;
195 if (sta
== NULL
|| sta
->local
== NULL
|| sta
->local
->ap
== NULL
) {
196 PDEBUG(DEBUG_AP
, "ap_handle_timer() called with NULL data\n");
202 was_assoc
= sta
->flags
& WLAN_STA_ASSOC
;
204 if (atomic_read(&sta
->users
) != 0)
205 next_time
= jiffies
+ HZ
;
206 else if ((sta
->flags
& WLAN_STA_PERM
) && !(sta
->flags
& WLAN_STA_AUTH
))
207 next_time
= jiffies
+ ap
->max_inactivity
;
209 if (time_before(jiffies
, sta
->last_rx
+ ap
->max_inactivity
)) {
210 /* station activity detected; reset timeout state */
211 sta
->timeout_next
= STA_NULLFUNC
;
212 next_time
= sta
->last_rx
+ ap
->max_inactivity
;
213 } else if (sta
->timeout_next
== STA_DISASSOC
&&
214 !(sta
->flags
& WLAN_STA_PENDING_POLL
)) {
215 /* STA ACKed data nullfunc frame poll */
216 sta
->timeout_next
= STA_NULLFUNC
;
217 next_time
= jiffies
+ ap
->max_inactivity
;
221 sta
->timer
.expires
= next_time
;
222 add_timer(&sta
->timer
);
227 sta
->timeout_next
= STA_DEAUTH
;
229 if (sta
->timeout_next
== STA_DEAUTH
&& !(sta
->flags
& WLAN_STA_PERM
)) {
230 spin_lock(&ap
->sta_table_lock
);
231 ap_sta_hash_del(ap
, sta
);
232 list_del(&sta
->list
);
233 spin_unlock(&ap
->sta_table_lock
);
234 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
235 } else if (sta
->timeout_next
== STA_DISASSOC
)
236 sta
->flags
&= ~WLAN_STA_ASSOC
;
238 if (was_assoc
&& !(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
239 hostap_event_expired_sta(local
->dev
, sta
);
241 if (sta
->timeout_next
== STA_DEAUTH
&& sta
->aid
> 0 &&
242 !skb_queue_empty(&sta
->tx_buf
)) {
243 hostap_set_tim(local
, sta
->aid
, 0);
244 sta
->flags
&= ~WLAN_STA_TIM
;
248 if (ap
->autom_ap_wds
) {
249 PDEBUG(DEBUG_AP
, "%s: removing automatic WDS "
250 "connection to AP %pM\n",
251 local
->dev
->name
, sta
->addr
);
252 hostap_wds_link_oper(local
, sta
->addr
, WDS_DEL
);
254 } else if (sta
->timeout_next
== STA_NULLFUNC
) {
255 /* send data frame to poll STA and check whether this frame
257 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
258 * it is apparently not retried so TX Exc events are not
260 sta
->flags
|= WLAN_STA_PENDING_POLL
;
261 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_DATA
|
262 IEEE80211_STYPE_DATA
, NULL
, 0,
263 sta
->addr
, ap
->tx_callback_poll
);
265 int deauth
= sta
->timeout_next
== STA_DEAUTH
;
267 PDEBUG(DEBUG_AP
, "%s: sending %s info to STA %pM"
268 "(last=%lu, jiffies=%lu)\n",
270 deauth
? "deauthentication" : "disassociation",
271 sta
->addr
, sta
->last_rx
, jiffies
);
273 resp
= cpu_to_le16(deauth
? WLAN_REASON_PREV_AUTH_NOT_VALID
:
274 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
275 prism2_send_mgmt(local
->dev
, IEEE80211_FTYPE_MGMT
|
276 (deauth
? IEEE80211_STYPE_DEAUTH
:
277 IEEE80211_STYPE_DISASSOC
),
278 (char *) &resp
, 2, sta
->addr
, 0);
281 if (sta
->timeout_next
== STA_DEAUTH
) {
282 if (sta
->flags
& WLAN_STA_PERM
) {
283 PDEBUG(DEBUG_AP
, "%s: STA %pM"
284 " would have been removed, "
285 "but it has 'perm' flag\n",
286 local
->dev
->name
, sta
->addr
);
288 ap_free_sta(ap
, sta
);
292 if (sta
->timeout_next
== STA_NULLFUNC
) {
293 sta
->timeout_next
= STA_DISASSOC
;
294 sta
->timer
.expires
= jiffies
+ AP_DISASSOC_DELAY
;
296 sta
->timeout_next
= STA_DEAUTH
;
297 sta
->timer
.expires
= jiffies
+ AP_DEAUTH_DELAY
;
300 add_timer(&sta
->timer
);
304 void hostap_deauth_all_stas(struct net_device
*dev
, struct ap_data
*ap
,
311 PDEBUG(DEBUG_AP
, "%s: Deauthenticate all stations\n", dev
->name
);
312 memset(addr
, 0xff, ETH_ALEN
);
314 resp
= cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
316 /* deauth message sent; try to resend it few times; the message is
317 * broadcast, so it may be delayed until next DTIM; there is not much
318 * else we can do at this point since the driver is going to be shut
320 for (i
= 0; i
< 5; i
++) {
321 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
322 IEEE80211_STYPE_DEAUTH
,
323 (char *) &resp
, 2, addr
, 0);
325 if (!resend
|| ap
->num_sta
<= 0)
333 static int ap_control_proc_show(struct seq_file
*m
, void *v
)
335 struct ap_data
*ap
= m
->private;
337 struct mac_entry
*entry
;
339 if (v
== SEQ_START_TOKEN
) {
340 switch (ap
->mac_restrictions
.policy
) {
341 case MAC_POLICY_OPEN
:
344 case MAC_POLICY_ALLOW
:
345 policy_txt
= "allow";
347 case MAC_POLICY_DENY
:
351 policy_txt
= "unknown";
354 seq_printf(m
, "MAC policy: %s\n", policy_txt
);
355 seq_printf(m
, "MAC entries: %u\n", ap
->mac_restrictions
.entries
);
356 seq_puts(m
, "MAC list:\n");
361 seq_printf(m
, "%pM\n", entry
->addr
);
365 static void *ap_control_proc_start(struct seq_file
*m
, loff_t
*_pos
)
367 struct ap_data
*ap
= m
->private;
368 spin_lock_bh(&ap
->mac_restrictions
.lock
);
369 return seq_list_start_head(&ap
->mac_restrictions
.mac_list
, *_pos
);
372 static void *ap_control_proc_next(struct seq_file
*m
, void *v
, loff_t
*_pos
)
374 struct ap_data
*ap
= m
->private;
375 return seq_list_next(v
, &ap
->mac_restrictions
.mac_list
, _pos
);
378 static void ap_control_proc_stop(struct seq_file
*m
, void *v
)
380 struct ap_data
*ap
= m
->private;
381 spin_unlock_bh(&ap
->mac_restrictions
.lock
);
384 static const struct seq_operations ap_control_proc_seqops
= {
385 .start
= ap_control_proc_start
,
386 .next
= ap_control_proc_next
,
387 .stop
= ap_control_proc_stop
,
388 .show
= ap_control_proc_show
,
391 static int ap_control_proc_open(struct inode
*inode
, struct file
*file
)
393 int ret
= seq_open(file
, &ap_control_proc_seqops
);
395 struct seq_file
*m
= file
->private_data
;
396 m
->private = PDE_DATA(inode
);
401 static const struct file_operations ap_control_proc_fops
= {
402 .open
= ap_control_proc_open
,
405 .release
= seq_release
,
409 int ap_control_add_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
411 struct mac_entry
*entry
;
413 entry
= kmalloc(sizeof(struct mac_entry
), GFP_KERNEL
);
417 memcpy(entry
->addr
, mac
, ETH_ALEN
);
419 spin_lock_bh(&mac_restrictions
->lock
);
420 list_add_tail(&entry
->list
, &mac_restrictions
->mac_list
);
421 mac_restrictions
->entries
++;
422 spin_unlock_bh(&mac_restrictions
->lock
);
428 int ap_control_del_mac(struct mac_restrictions
*mac_restrictions
, u8
*mac
)
430 struct list_head
*ptr
;
431 struct mac_entry
*entry
;
433 spin_lock_bh(&mac_restrictions
->lock
);
434 for (ptr
= mac_restrictions
->mac_list
.next
;
435 ptr
!= &mac_restrictions
->mac_list
; ptr
= ptr
->next
) {
436 entry
= list_entry(ptr
, struct mac_entry
, list
);
438 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
441 mac_restrictions
->entries
--;
442 spin_unlock_bh(&mac_restrictions
->lock
);
446 spin_unlock_bh(&mac_restrictions
->lock
);
451 static int ap_control_mac_deny(struct mac_restrictions
*mac_restrictions
,
454 struct mac_entry
*entry
;
457 if (mac_restrictions
->policy
== MAC_POLICY_OPEN
)
460 spin_lock_bh(&mac_restrictions
->lock
);
461 list_for_each_entry(entry
, &mac_restrictions
->mac_list
, list
) {
462 if (memcmp(entry
->addr
, mac
, ETH_ALEN
) == 0) {
467 spin_unlock_bh(&mac_restrictions
->lock
);
469 if (mac_restrictions
->policy
== MAC_POLICY_ALLOW
)
476 void ap_control_flush_macs(struct mac_restrictions
*mac_restrictions
)
478 struct list_head
*ptr
, *n
;
479 struct mac_entry
*entry
;
481 if (mac_restrictions
->entries
== 0)
484 spin_lock_bh(&mac_restrictions
->lock
);
485 for (ptr
= mac_restrictions
->mac_list
.next
, n
= ptr
->next
;
486 ptr
!= &mac_restrictions
->mac_list
;
487 ptr
= n
, n
= ptr
->next
) {
488 entry
= list_entry(ptr
, struct mac_entry
, list
);
492 mac_restrictions
->entries
= 0;
493 spin_unlock_bh(&mac_restrictions
->lock
);
497 int ap_control_kick_mac(struct ap_data
*ap
, struct net_device
*dev
, u8
*mac
)
499 struct sta_info
*sta
;
502 spin_lock_bh(&ap
->sta_table_lock
);
503 sta
= ap_get_sta(ap
, mac
);
505 ap_sta_hash_del(ap
, sta
);
506 list_del(&sta
->list
);
508 spin_unlock_bh(&ap
->sta_table_lock
);
513 resp
= cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID
);
514 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_DEAUTH
,
515 (char *) &resp
, 2, sta
->addr
, 0);
517 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
518 hostap_event_expired_sta(dev
, sta
);
520 ap_free_sta(ap
, sta
);
525 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
528 void ap_control_kickall(struct ap_data
*ap
)
530 struct list_head
*ptr
, *n
;
531 struct sta_info
*sta
;
533 spin_lock_bh(&ap
->sta_table_lock
);
534 for (ptr
= ap
->sta_list
.next
, n
= ptr
->next
; ptr
!= &ap
->sta_list
;
535 ptr
= n
, n
= ptr
->next
) {
536 sta
= list_entry(ptr
, struct sta_info
, list
);
537 ap_sta_hash_del(ap
, sta
);
538 list_del(&sta
->list
);
539 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
540 hostap_event_expired_sta(sta
->local
->dev
, sta
);
541 ap_free_sta(ap
, sta
);
543 spin_unlock_bh(&ap
->sta_table_lock
);
547 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
549 static int prism2_ap_proc_show(struct seq_file
*m
, void *v
)
551 struct sta_info
*sta
= v
;
554 if (v
== SEQ_START_TOKEN
) {
555 seq_printf(m
, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
562 seq_printf(m
, "%pM %d %d %d %d '",
564 sta
->u
.ap
.channel
, sta
->last_rx_signal
,
565 sta
->last_rx_silence
, sta
->last_rx_rate
);
567 for (i
= 0; i
< sta
->u
.ap
.ssid_len
; i
++) {
568 if (sta
->u
.ap
.ssid
[i
] >= 32 && sta
->u
.ap
.ssid
[i
] < 127)
569 seq_putc(m
, sta
->u
.ap
.ssid
[i
]);
571 seq_printf(m
, "<%02x>", sta
->u
.ap
.ssid
[i
]);
575 if (sta
->capability
& WLAN_CAPABILITY_ESS
)
576 seq_puts(m
, " [ESS]");
577 if (sta
->capability
& WLAN_CAPABILITY_IBSS
)
578 seq_puts(m
, " [IBSS]");
579 if (sta
->capability
& WLAN_CAPABILITY_PRIVACY
)
580 seq_puts(m
, " [WEP]");
585 static void *prism2_ap_proc_start(struct seq_file
*m
, loff_t
*_pos
)
587 struct ap_data
*ap
= m
->private;
588 spin_lock_bh(&ap
->sta_table_lock
);
589 return seq_list_start_head(&ap
->sta_list
, *_pos
);
592 static void *prism2_ap_proc_next(struct seq_file
*m
, void *v
, loff_t
*_pos
)
594 struct ap_data
*ap
= m
->private;
595 return seq_list_next(v
, &ap
->sta_list
, _pos
);
598 static void prism2_ap_proc_stop(struct seq_file
*m
, void *v
)
600 struct ap_data
*ap
= m
->private;
601 spin_unlock_bh(&ap
->sta_table_lock
);
604 static const struct seq_operations prism2_ap_proc_seqops
= {
605 .start
= prism2_ap_proc_start
,
606 .next
= prism2_ap_proc_next
,
607 .stop
= prism2_ap_proc_stop
,
608 .show
= prism2_ap_proc_show
,
611 static int prism2_ap_proc_open(struct inode
*inode
, struct file
*file
)
613 int ret
= seq_open(file
, &prism2_ap_proc_seqops
);
615 struct seq_file
*m
= file
->private_data
;
616 m
->private = PDE_DATA(inode
);
621 static const struct file_operations prism2_ap_proc_fops
= {
622 .open
= prism2_ap_proc_open
,
625 .release
= seq_release
,
627 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
630 void hostap_check_sta_fw_version(struct ap_data
*ap
, int sta_fw_ver
)
635 if (sta_fw_ver
== PRISM2_FW_VER(0,8,0)) {
636 PDEBUG(DEBUG_AP
, "Using data::nullfunc ACK workaround - "
637 "firmware upgrade recommended\n");
638 ap
->nullfunc_ack
= 1;
640 ap
->nullfunc_ack
= 0;
642 if (sta_fw_ver
== PRISM2_FW_VER(1,4,2)) {
643 printk(KERN_WARNING
"%s: Warning: secondary station firmware "
644 "version 1.4.2 does not seem to work in Host AP mode\n",
645 ap
->local
->dev
->name
);
650 /* Called only as a tasklet (software IRQ) */
651 static void hostap_ap_tx_cb(struct sk_buff
*skb
, int ok
, void *data
)
653 struct ap_data
*ap
= data
;
654 struct ieee80211_hdr
*hdr
;
656 if (!ap
->local
->hostapd
|| !ap
->local
->apdev
) {
661 /* Pass the TX callback frame to the hostapd; use 802.11 header version
662 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
664 hdr
= (struct ieee80211_hdr
*) skb
->data
;
665 hdr
->frame_control
&= cpu_to_le16(~IEEE80211_FCTL_VERS
);
666 hdr
->frame_control
|= cpu_to_le16(ok
? BIT(1) : BIT(0));
668 skb
->dev
= ap
->local
->apdev
;
669 skb_pull(skb
, hostap_80211_get_hdrlen(hdr
->frame_control
));
670 skb
->pkt_type
= PACKET_OTHERHOST
;
671 skb
->protocol
= cpu_to_be16(ETH_P_802_2
);
672 memset(skb
->cb
, 0, sizeof(skb
->cb
));
677 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
678 /* Called only as a tasklet (software IRQ) */
679 static void hostap_ap_tx_cb_auth(struct sk_buff
*skb
, int ok
, void *data
)
681 struct ap_data
*ap
= data
;
682 struct net_device
*dev
= ap
->local
->dev
;
683 struct ieee80211_hdr
*hdr
;
684 u16 auth_alg
, auth_transaction
, status
;
686 struct sta_info
*sta
= NULL
;
689 if (ap
->local
->hostapd
) {
694 hdr
= (struct ieee80211_hdr
*) skb
->data
;
695 if (!ieee80211_is_auth(hdr
->frame_control
) ||
696 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 6) {
697 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_auth received invalid "
698 "frame\n", dev
->name
);
703 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
704 auth_alg
= le16_to_cpu(*pos
++);
705 auth_transaction
= le16_to_cpu(*pos
++);
706 status
= le16_to_cpu(*pos
++);
709 txt
= "frame was not ACKed";
713 spin_lock(&ap
->sta_table_lock
);
714 sta
= ap_get_sta(ap
, hdr
->addr1
);
716 atomic_inc(&sta
->users
);
717 spin_unlock(&ap
->sta_table_lock
);
720 txt
= "STA not found";
724 if (status
== WLAN_STATUS_SUCCESS
&&
725 ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 2) ||
726 (auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 4))) {
727 txt
= "STA authenticated";
728 sta
->flags
|= WLAN_STA_AUTH
;
729 sta
->last_auth
= jiffies
;
730 } else if (status
!= WLAN_STATUS_SUCCESS
)
731 txt
= "authentication failed";
735 atomic_dec(&sta
->users
);
737 PDEBUG(DEBUG_AP
, "%s: %pM auth_cb - alg=%d "
738 "trans#=%d status=%d - %s\n",
739 dev
->name
, hdr
->addr1
,
740 auth_alg
, auth_transaction
, status
, txt
);
746 /* Called only as a tasklet (software IRQ) */
747 static void hostap_ap_tx_cb_assoc(struct sk_buff
*skb
, int ok
, void *data
)
749 struct ap_data
*ap
= data
;
750 struct net_device
*dev
= ap
->local
->dev
;
751 struct ieee80211_hdr
*hdr
;
754 struct sta_info
*sta
= NULL
;
757 if (ap
->local
->hostapd
) {
762 hdr
= (struct ieee80211_hdr
*) skb
->data
;
763 if ((!ieee80211_is_assoc_resp(hdr
->frame_control
) &&
764 !ieee80211_is_reassoc_resp(hdr
->frame_control
)) ||
765 skb
->len
< IEEE80211_MGMT_HDR_LEN
+ 4) {
766 printk(KERN_DEBUG
"%s: hostap_ap_tx_cb_assoc received invalid "
767 "frame\n", dev
->name
);
773 txt
= "frame was not ACKed";
777 spin_lock(&ap
->sta_table_lock
);
778 sta
= ap_get_sta(ap
, hdr
->addr1
);
780 atomic_inc(&sta
->users
);
781 spin_unlock(&ap
->sta_table_lock
);
784 txt
= "STA not found";
788 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
790 status
= le16_to_cpu(*pos
++);
791 if (status
== WLAN_STATUS_SUCCESS
) {
792 if (!(sta
->flags
& WLAN_STA_ASSOC
))
793 hostap_event_new_sta(dev
, sta
);
794 txt
= "STA associated";
795 sta
->flags
|= WLAN_STA_ASSOC
;
796 sta
->last_assoc
= jiffies
;
798 txt
= "association failed";
802 atomic_dec(&sta
->users
);
804 PDEBUG(DEBUG_AP
, "%s: %pM assoc_cb - %s\n",
805 dev
->name
, hdr
->addr1
, txt
);
810 /* Called only as a tasklet (software IRQ); TX callback for poll frames used
811 * in verifying whether the STA is still present. */
812 static void hostap_ap_tx_cb_poll(struct sk_buff
*skb
, int ok
, void *data
)
814 struct ap_data
*ap
= data
;
815 struct ieee80211_hdr
*hdr
;
816 struct sta_info
*sta
;
820 hdr
= (struct ieee80211_hdr
*) skb
->data
;
822 spin_lock(&ap
->sta_table_lock
);
823 sta
= ap_get_sta(ap
, hdr
->addr1
);
825 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
826 spin_unlock(&ap
->sta_table_lock
);
829 "%s: STA %pM did not ACK activity poll frame\n",
830 ap
->local
->dev
->name
, hdr
->addr1
);
836 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
839 void hostap_init_data(local_info_t
*local
)
841 struct ap_data
*ap
= local
->ap
;
844 printk(KERN_WARNING
"hostap_init_data: ap == NULL\n");
847 memset(ap
, 0, sizeof(struct ap_data
));
850 ap
->ap_policy
= GET_INT_PARM(other_ap_policy
, local
->card_idx
);
851 ap
->bridge_packets
= GET_INT_PARM(ap_bridge_packets
, local
->card_idx
);
853 GET_INT_PARM(ap_max_inactivity
, local
->card_idx
) * HZ
;
854 ap
->autom_ap_wds
= GET_INT_PARM(autom_ap_wds
, local
->card_idx
);
856 spin_lock_init(&ap
->sta_table_lock
);
857 INIT_LIST_HEAD(&ap
->sta_list
);
859 /* Initialize task queue structure for AP management */
860 INIT_WORK(&local
->ap
->add_sta_proc_queue
, handle_add_proc_queue
);
862 ap
->tx_callback_idx
=
863 hostap_tx_callback_register(local
, hostap_ap_tx_cb
, ap
);
864 if (ap
->tx_callback_idx
== 0)
865 printk(KERN_WARNING
"%s: failed to register TX callback for "
866 "AP\n", local
->dev
->name
);
867 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
868 INIT_WORK(&local
->ap
->wds_oper_queue
, handle_wds_oper_queue
);
870 ap
->tx_callback_auth
=
871 hostap_tx_callback_register(local
, hostap_ap_tx_cb_auth
, ap
);
872 ap
->tx_callback_assoc
=
873 hostap_tx_callback_register(local
, hostap_ap_tx_cb_assoc
, ap
);
874 ap
->tx_callback_poll
=
875 hostap_tx_callback_register(local
, hostap_ap_tx_cb_poll
, ap
);
876 if (ap
->tx_callback_auth
== 0 || ap
->tx_callback_assoc
== 0 ||
877 ap
->tx_callback_poll
== 0)
878 printk(KERN_WARNING
"%s: failed to register TX callback for "
879 "AP\n", local
->dev
->name
);
881 spin_lock_init(&ap
->mac_restrictions
.lock
);
882 INIT_LIST_HEAD(&ap
->mac_restrictions
.mac_list
);
883 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
889 void hostap_init_ap_proc(local_info_t
*local
)
891 struct ap_data
*ap
= local
->ap
;
893 ap
->proc
= local
->proc
;
894 if (ap
->proc
== NULL
)
897 #ifndef PRISM2_NO_PROCFS_DEBUG
898 proc_create_data("ap_debug", 0, ap
->proc
, &ap_debug_proc_fops
, ap
);
899 #endif /* PRISM2_NO_PROCFS_DEBUG */
901 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
902 proc_create_data("ap_control", 0, ap
->proc
, &ap_control_proc_fops
, ap
);
903 proc_create_data("ap", 0, ap
->proc
, &prism2_ap_proc_fops
, ap
);
904 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
909 void hostap_free_data(struct ap_data
*ap
)
911 struct sta_info
*n
, *sta
;
913 if (ap
== NULL
|| !ap
->initialized
) {
914 printk(KERN_DEBUG
"hostap_free_data: ap has not yet been "
915 "initialized - skip resource freeing\n");
919 flush_work(&ap
->add_sta_proc_queue
);
921 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
922 flush_work(&ap
->wds_oper_queue
);
924 ap
->crypt
->deinit(ap
->crypt_priv
);
925 ap
->crypt
= ap
->crypt_priv
= NULL
;
926 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
928 list_for_each_entry_safe(sta
, n
, &ap
->sta_list
, list
) {
929 ap_sta_hash_del(ap
, sta
);
930 list_del(&sta
->list
);
931 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
932 hostap_event_expired_sta(sta
->local
->dev
, sta
);
933 ap_free_sta(ap
, sta
);
936 #ifndef PRISM2_NO_PROCFS_DEBUG
937 if (ap
->proc
!= NULL
) {
938 remove_proc_entry("ap_debug", ap
->proc
);
940 #endif /* PRISM2_NO_PROCFS_DEBUG */
942 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
943 if (ap
->proc
!= NULL
) {
944 remove_proc_entry("ap", ap
->proc
);
945 remove_proc_entry("ap_control", ap
->proc
);
947 ap_control_flush_macs(&ap
->mac_restrictions
);
948 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
954 /* caller should have mutex for AP STA list handling */
955 static struct sta_info
* ap_get_sta(struct ap_data
*ap
, u8
*sta
)
959 s
= ap
->sta_hash
[STA_HASH(sta
)];
960 while (s
!= NULL
&& memcmp(s
->addr
, sta
, ETH_ALEN
) != 0)
966 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
968 /* Called from timer handler and from scheduled AP queue handlers */
969 static void prism2_send_mgmt(struct net_device
*dev
,
970 u16 type_subtype
, char *body
,
971 int body_len
, u8
*addr
, u16 tx_cb_idx
)
973 struct hostap_interface
*iface
;
975 struct ieee80211_hdr
*hdr
;
978 struct hostap_skb_tx_data
*meta
;
981 iface
= netdev_priv(dev
);
982 local
= iface
->local
;
983 dev
= local
->dev
; /* always use master radio device */
984 iface
= netdev_priv(dev
);
986 if (!(dev
->flags
& IFF_UP
)) {
987 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt - device is not UP - "
988 "cannot send frame\n", dev
->name
);
992 skb
= dev_alloc_skb(sizeof(*hdr
) + body_len
);
994 PDEBUG(DEBUG_AP
, "%s: prism2_send_mgmt failed to allocate "
1000 hdrlen
= hostap_80211_get_hdrlen(cpu_to_le16(type_subtype
));
1001 hdr
= (struct ieee80211_hdr
*) skb_put(skb
, hdrlen
);
1003 memcpy(skb_put(skb
, body_len
), body
, body_len
);
1005 memset(hdr
, 0, hdrlen
);
1007 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
1008 * tx_control instead of using local->tx_control */
1011 memcpy(hdr
->addr1
, addr
, ETH_ALEN
); /* DA / RA */
1012 if (ieee80211_is_data(hdr
->frame_control
)) {
1013 fc
|= IEEE80211_FCTL_FROMDS
;
1014 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
1015 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* SA */
1016 } else if (ieee80211_is_ctl(hdr
->frame_control
)) {
1017 /* control:ACK does not have addr2 or addr3 */
1018 memset(hdr
->addr2
, 0, ETH_ALEN
);
1019 memset(hdr
->addr3
, 0, ETH_ALEN
);
1021 memcpy(hdr
->addr2
, dev
->dev_addr
, ETH_ALEN
); /* SA */
1022 memcpy(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
); /* BSSID */
1025 hdr
->frame_control
= cpu_to_le16(fc
);
1027 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1028 memset(meta
, 0, sizeof(*meta
));
1029 meta
->magic
= HOSTAP_SKB_TX_DATA_MAGIC
;
1030 meta
->iface
= iface
;
1031 meta
->tx_cb_idx
= tx_cb_idx
;
1034 skb_reset_mac_header(skb
);
1035 skb_reset_network_header(skb
);
1036 dev_queue_xmit(skb
);
1038 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1041 static int prism2_sta_proc_show(struct seq_file
*m
, void *v
)
1043 struct sta_info
*sta
= m
->private;
1046 /* FIX: possible race condition.. the STA data could have just expired,
1047 * but proc entry was still here so that the read could have started;
1048 * some locking should be done here.. */
1051 "%s=%pM\nusers=%d\naid=%d\n"
1052 "flags=0x%04x%s%s%s%s%s%s%s\n"
1053 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1054 sta
->ap
? "AP" : "STA",
1055 sta
->addr
, atomic_read(&sta
->users
), sta
->aid
,
1057 sta
->flags
& WLAN_STA_AUTH
? " AUTH" : "",
1058 sta
->flags
& WLAN_STA_ASSOC
? " ASSOC" : "",
1059 sta
->flags
& WLAN_STA_PS
? " PS" : "",
1060 sta
->flags
& WLAN_STA_TIM
? " TIM" : "",
1061 sta
->flags
& WLAN_STA_PERM
? " PERM" : "",
1062 sta
->flags
& WLAN_STA_AUTHORIZED
? " AUTHORIZED" : "",
1063 sta
->flags
& WLAN_STA_PENDING_POLL
? " POLL" : "",
1064 sta
->capability
, sta
->listen_interval
);
1065 /* supported_rates: 500 kbit/s units with msb ignored */
1066 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++)
1067 if (sta
->supported_rates
[i
] != 0)
1068 seq_printf(m
, "%d%sMbps ",
1069 (sta
->supported_rates
[i
] & 0x7f) / 2,
1070 sta
->supported_rates
[i
] & 1 ? ".5" : "");
1072 "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1073 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1075 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1076 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1077 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1079 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1080 jiffies
, sta
->last_auth
, sta
->last_assoc
, sta
->last_rx
,
1082 sta
->rx_packets
, sta
->tx_packets
, sta
->rx_bytes
,
1083 sta
->tx_bytes
, skb_queue_len(&sta
->tx_buf
),
1084 sta
->last_rx_silence
,
1085 sta
->last_rx_signal
, sta
->last_rx_rate
/ 10,
1086 sta
->last_rx_rate
% 10 ? ".5" : "",
1087 sta
->tx_rate
, sta
->tx_count
[0], sta
->tx_count
[1],
1088 sta
->tx_count
[2], sta
->tx_count
[3], sta
->rx_count
[0],
1089 sta
->rx_count
[1], sta
->rx_count
[2], sta
->rx_count
[3]);
1090 if (sta
->crypt
&& sta
->crypt
->ops
&& sta
->crypt
->ops
->print_stats
)
1091 sta
->crypt
->ops
->print_stats(m
, sta
->crypt
->priv
);
1092 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1094 if (sta
->u
.ap
.channel
>= 0)
1095 seq_printf(m
, "channel=%d\n", sta
->u
.ap
.channel
);
1096 seq_puts(m
, "ssid=");
1097 for (i
= 0; i
< sta
->u
.ap
.ssid_len
; i
++) {
1098 if (sta
->u
.ap
.ssid
[i
] >= 32 && sta
->u
.ap
.ssid
[i
] < 127)
1099 seq_putc(m
, sta
->u
.ap
.ssid
[i
]);
1101 seq_printf(m
, "<%02x>", sta
->u
.ap
.ssid
[i
]);
1105 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1110 static int prism2_sta_proc_open(struct inode
*inode
, struct file
*file
)
1112 return single_open(file
, prism2_sta_proc_show
, PDE_DATA(inode
));
1115 static const struct file_operations prism2_sta_proc_fops
= {
1116 .open
= prism2_sta_proc_open
,
1118 .llseek
= seq_lseek
,
1119 .release
= single_release
,
1122 static void handle_add_proc_queue(struct work_struct
*work
)
1124 struct ap_data
*ap
= container_of(work
, struct ap_data
,
1125 add_sta_proc_queue
);
1126 struct sta_info
*sta
;
1128 struct add_sta_proc_data
*entry
, *prev
;
1130 entry
= ap
->add_sta_proc_entries
;
1131 ap
->add_sta_proc_entries
= NULL
;
1134 spin_lock_bh(&ap
->sta_table_lock
);
1135 sta
= ap_get_sta(ap
, entry
->addr
);
1137 atomic_inc(&sta
->users
);
1138 spin_unlock_bh(&ap
->sta_table_lock
);
1141 sprintf(name
, "%pM", sta
->addr
);
1142 sta
->proc
= proc_create_data(
1144 &prism2_sta_proc_fops
, sta
);
1146 atomic_dec(&sta
->users
);
1150 entry
= entry
->next
;
1156 static struct sta_info
* ap_add_sta(struct ap_data
*ap
, u8
*addr
)
1158 struct sta_info
*sta
;
1160 sta
= kzalloc(sizeof(struct sta_info
), GFP_ATOMIC
);
1162 PDEBUG(DEBUG_AP
, "AP: kmalloc failed\n");
1166 /* initialize STA info data */
1167 sta
->local
= ap
->local
;
1168 skb_queue_head_init(&sta
->tx_buf
);
1169 memcpy(sta
->addr
, addr
, ETH_ALEN
);
1171 atomic_inc(&sta
->users
);
1172 spin_lock_bh(&ap
->sta_table_lock
);
1173 list_add(&sta
->list
, &ap
->sta_list
);
1175 ap_sta_hash_add(ap
, sta
);
1176 spin_unlock_bh(&ap
->sta_table_lock
);
1179 struct add_sta_proc_data
*entry
;
1180 /* schedule a non-interrupt context process to add a procfs
1181 * entry for the STA since procfs code use GFP_KERNEL */
1182 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1184 memcpy(entry
->addr
, sta
->addr
, ETH_ALEN
);
1185 entry
->next
= ap
->add_sta_proc_entries
;
1186 ap
->add_sta_proc_entries
= entry
;
1187 schedule_work(&ap
->add_sta_proc_queue
);
1189 printk(KERN_DEBUG
"Failed to add STA proc data\n");
1192 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1193 init_timer(&sta
->timer
);
1194 sta
->timer
.expires
= jiffies
+ ap
->max_inactivity
;
1195 sta
->timer
.data
= (unsigned long) sta
;
1196 sta
->timer
.function
= ap_handle_timer
;
1197 if (!ap
->local
->hostapd
)
1198 add_timer(&sta
->timer
);
1199 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1205 static int ap_tx_rate_ok(int rateidx
, struct sta_info
*sta
,
1206 local_info_t
*local
)
1208 if (rateidx
> sta
->tx_max_rate
||
1209 !(sta
->tx_supp_rates
& (1 << rateidx
)))
1212 if (local
->tx_rate_control
!= 0 &&
1213 !(local
->tx_rate_control
& (1 << rateidx
)))
1220 static void prism2_check_tx_rates(struct sta_info
*sta
)
1224 sta
->tx_supp_rates
= 0;
1225 for (i
= 0; i
< sizeof(sta
->supported_rates
); i
++) {
1226 if ((sta
->supported_rates
[i
] & 0x7f) == 2)
1227 sta
->tx_supp_rates
|= WLAN_RATE_1M
;
1228 if ((sta
->supported_rates
[i
] & 0x7f) == 4)
1229 sta
->tx_supp_rates
|= WLAN_RATE_2M
;
1230 if ((sta
->supported_rates
[i
] & 0x7f) == 11)
1231 sta
->tx_supp_rates
|= WLAN_RATE_5M5
;
1232 if ((sta
->supported_rates
[i
] & 0x7f) == 22)
1233 sta
->tx_supp_rates
|= WLAN_RATE_11M
;
1235 sta
->tx_max_rate
= sta
->tx_rate
= sta
->tx_rate_idx
= 0;
1236 if (sta
->tx_supp_rates
& WLAN_RATE_1M
) {
1237 sta
->tx_max_rate
= 0;
1238 if (ap_tx_rate_ok(0, sta
, sta
->local
)) {
1240 sta
->tx_rate_idx
= 0;
1243 if (sta
->tx_supp_rates
& WLAN_RATE_2M
) {
1244 sta
->tx_max_rate
= 1;
1245 if (ap_tx_rate_ok(1, sta
, sta
->local
)) {
1247 sta
->tx_rate_idx
= 1;
1250 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
) {
1251 sta
->tx_max_rate
= 2;
1252 if (ap_tx_rate_ok(2, sta
, sta
->local
)) {
1254 sta
->tx_rate_idx
= 2;
1257 if (sta
->tx_supp_rates
& WLAN_RATE_11M
) {
1258 sta
->tx_max_rate
= 3;
1259 if (ap_tx_rate_ok(3, sta
, sta
->local
)) {
1261 sta
->tx_rate_idx
= 3;
1267 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1269 static void ap_crypt_init(struct ap_data
*ap
)
1271 ap
->crypt
= lib80211_get_crypto_ops("WEP");
1274 if (ap
->crypt
->init
) {
1275 ap
->crypt_priv
= ap
->crypt
->init(0);
1276 if (ap
->crypt_priv
== NULL
)
1279 u8 key
[WEP_KEY_LEN
];
1280 get_random_bytes(key
, WEP_KEY_LEN
);
1281 ap
->crypt
->set_key(key
, WEP_KEY_LEN
, NULL
,
1287 if (ap
->crypt
== NULL
) {
1288 printk(KERN_WARNING
"AP could not initialize WEP: load module "
1289 "lib80211_crypt_wep.ko\n");
1294 /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1295 * that WEP algorithm is used for generating challenge. This should be unique,
1296 * but otherwise there is not really need for randomness etc. Initialize WEP
1297 * with pseudo random key and then use increasing IV to get unique challenge
1300 * Called only as a scheduled task for pending AP frames.
1302 static char * ap_auth_make_challenge(struct ap_data
*ap
)
1305 struct sk_buff
*skb
;
1307 if (ap
->crypt
== NULL
) {
1309 if (ap
->crypt
== NULL
)
1313 tmpbuf
= kmalloc(WLAN_AUTH_CHALLENGE_LEN
, GFP_ATOMIC
);
1314 if (tmpbuf
== NULL
) {
1315 PDEBUG(DEBUG_AP
, "AP: kmalloc failed for challenge\n");
1319 skb
= dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN
+
1320 ap
->crypt
->extra_mpdu_prefix_len
+
1321 ap
->crypt
->extra_mpdu_postfix_len
);
1327 skb_reserve(skb
, ap
->crypt
->extra_mpdu_prefix_len
);
1328 memset(skb_put(skb
, WLAN_AUTH_CHALLENGE_LEN
), 0,
1329 WLAN_AUTH_CHALLENGE_LEN
);
1330 if (ap
->crypt
->encrypt_mpdu(skb
, 0, ap
->crypt_priv
)) {
1336 skb_copy_from_linear_data_offset(skb
, ap
->crypt
->extra_mpdu_prefix_len
,
1337 tmpbuf
, WLAN_AUTH_CHALLENGE_LEN
);
1344 /* Called only as a scheduled task for pending AP frames. */
1345 static void handle_authen(local_info_t
*local
, struct sk_buff
*skb
,
1346 struct hostap_80211_rx_status
*rx_stats
)
1348 struct net_device
*dev
= local
->dev
;
1349 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1351 struct ap_data
*ap
= local
->ap
;
1352 char body
[8 + WLAN_AUTH_CHALLENGE_LEN
], *challenge
= NULL
;
1354 u16 auth_alg
, auth_transaction
, status_code
;
1356 u16 resp
= WLAN_STATUS_SUCCESS
;
1357 struct sta_info
*sta
= NULL
;
1358 struct lib80211_crypt_data
*crypt
;
1361 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1363 hdrlen
= hostap_80211_get_hdrlen(hdr
->frame_control
);
1366 PDEBUG(DEBUG_AP
, "%s: handle_authen - too short payload "
1367 "(len=%d) from %pM\n", dev
->name
, len
, hdr
->addr2
);
1371 spin_lock_bh(&local
->ap
->sta_table_lock
);
1372 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1374 atomic_inc(&sta
->users
);
1375 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1377 if (sta
&& sta
->crypt
)
1381 if (skb
->len
>= hdrlen
+ 3)
1382 idx
= skb
->data
[hdrlen
+ 3] >> 6;
1383 crypt
= local
->crypt_info
.crypt
[idx
];
1386 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1387 auth_alg
= __le16_to_cpu(*pos
);
1389 auth_transaction
= __le16_to_cpu(*pos
);
1391 status_code
= __le16_to_cpu(*pos
);
1394 if (memcmp(dev
->dev_addr
, hdr
->addr2
, ETH_ALEN
) == 0 ||
1395 ap_control_mac_deny(&ap
->mac_restrictions
, hdr
->addr2
)) {
1396 txt
= "authentication denied";
1397 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1401 if (((local
->auth_algs
& PRISM2_AUTH_OPEN
) &&
1402 auth_alg
== WLAN_AUTH_OPEN
) ||
1403 ((local
->auth_algs
& PRISM2_AUTH_SHARED_KEY
) &&
1404 crypt
&& auth_alg
== WLAN_AUTH_SHARED_KEY
)) {
1406 txt
= "unsupported algorithm";
1407 resp
= WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1413 if (*u
== WLAN_EID_CHALLENGE
) {
1414 if (*(u
+ 1) != WLAN_AUTH_CHALLENGE_LEN
) {
1415 txt
= "invalid challenge len";
1416 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1419 if (len
- 8 < WLAN_AUTH_CHALLENGE_LEN
) {
1420 txt
= "challenge underflow";
1421 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1424 challenge
= (char *) (u
+ 2);
1428 if (sta
&& sta
->ap
) {
1429 if (time_after(jiffies
, sta
->u
.ap
.last_beacon
+
1430 (10 * sta
->listen_interval
* HZ
) / 1024)) {
1431 PDEBUG(DEBUG_AP
, "%s: no beacons received for a while,"
1432 " assuming AP %pM is now STA\n",
1433 dev
->name
, sta
->addr
);
1436 sta
->u
.sta
.challenge
= NULL
;
1438 txt
= "AP trying to authenticate?";
1439 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1444 if ((auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 1) ||
1445 (auth_alg
== WLAN_AUTH_SHARED_KEY
&&
1446 (auth_transaction
== 1 ||
1447 (auth_transaction
== 3 && sta
!= NULL
&&
1448 sta
->u
.sta
.challenge
!= NULL
)))) {
1450 txt
= "unknown authentication transaction number";
1451 resp
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1458 if (local
->ap
->num_sta
>= MAX_STA_COUNT
) {
1459 /* FIX: might try to remove some old STAs first? */
1460 txt
= "no more room for new STAs";
1461 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1465 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
1467 txt
= "ap_add_sta failed";
1468 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1474 case WLAN_AUTH_OPEN
:
1476 /* IEEE 802.11 standard is not completely clear about
1477 * whether STA is considered authenticated after
1478 * authentication OK frame has been send or after it
1479 * has been ACKed. In order to reduce interoperability
1480 * issues, mark the STA authenticated before ACK. */
1481 sta
->flags
|= WLAN_STA_AUTH
;
1484 case WLAN_AUTH_SHARED_KEY
:
1485 if (auth_transaction
== 1) {
1486 if (sta
->u
.sta
.challenge
== NULL
) {
1487 sta
->u
.sta
.challenge
=
1488 ap_auth_make_challenge(local
->ap
);
1489 if (sta
->u
.sta
.challenge
== NULL
) {
1490 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1495 if (sta
->u
.sta
.challenge
== NULL
||
1496 challenge
== NULL
||
1497 memcmp(sta
->u
.sta
.challenge
, challenge
,
1498 WLAN_AUTH_CHALLENGE_LEN
) != 0 ||
1499 !ieee80211_has_protected(hdr
->frame_control
)) {
1500 txt
= "challenge response incorrect";
1501 resp
= WLAN_STATUS_CHALLENGE_FAIL
;
1505 txt
= "challenge OK - authOK";
1506 /* IEEE 802.11 standard is not completely clear about
1507 * whether STA is considered authenticated after
1508 * authentication OK frame has been send or after it
1509 * has been ACKed. In order to reduce interoperability
1510 * issues, mark the STA authenticated before ACK. */
1511 sta
->flags
|= WLAN_STA_AUTH
;
1512 kfree(sta
->u
.sta
.challenge
);
1513 sta
->u
.sta
.challenge
= NULL
;
1519 pos
= (__le16
*) body
;
1520 *pos
= cpu_to_le16(auth_alg
);
1522 *pos
= cpu_to_le16(auth_transaction
+ 1);
1524 *pos
= cpu_to_le16(resp
); /* status_code */
1528 if (resp
== WLAN_STATUS_SUCCESS
&& sta
!= NULL
&&
1529 sta
->u
.sta
.challenge
!= NULL
&&
1530 auth_alg
== WLAN_AUTH_SHARED_KEY
&& auth_transaction
== 1) {
1531 u8
*tmp
= (u8
*) pos
;
1532 *tmp
++ = WLAN_EID_CHALLENGE
;
1533 *tmp
++ = WLAN_AUTH_CHALLENGE_LEN
;
1535 memcpy(pos
, sta
->u
.sta
.challenge
, WLAN_AUTH_CHALLENGE_LEN
);
1536 olen
+= 2 + WLAN_AUTH_CHALLENGE_LEN
;
1539 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_AUTH
,
1540 body
, olen
, hdr
->addr2
, ap
->tx_callback_auth
);
1543 sta
->last_rx
= jiffies
;
1544 atomic_dec(&sta
->users
);
1548 PDEBUG(DEBUG_AP
, "%s: %pM auth (alg=%d "
1549 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1550 dev
->name
, hdr
->addr2
,
1551 auth_alg
, auth_transaction
, status_code
, len
,
1552 le16_to_cpu(hdr
->frame_control
), resp
, txt
);
1557 /* Called only as a scheduled task for pending AP frames. */
1558 static void handle_assoc(local_info_t
*local
, struct sk_buff
*skb
,
1559 struct hostap_80211_rx_status
*rx_stats
, int reassoc
)
1561 struct net_device
*dev
= local
->dev
;
1562 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1563 char body
[12], *p
, *lpos
;
1566 u16 resp
= WLAN_STATUS_SUCCESS
;
1567 struct sta_info
*sta
= NULL
;
1568 int send_deauth
= 0;
1570 u8 prev_ap
[ETH_ALEN
];
1572 left
= len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1574 if (len
< (reassoc
? 10 : 4)) {
1575 PDEBUG(DEBUG_AP
, "%s: handle_assoc - too short payload "
1576 "(len=%d, reassoc=%d) from %pM\n",
1577 dev
->name
, len
, reassoc
, hdr
->addr2
);
1581 spin_lock_bh(&local
->ap
->sta_table_lock
);
1582 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1583 if (sta
== NULL
|| (sta
->flags
& WLAN_STA_AUTH
) == 0) {
1584 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1585 txt
= "trying to associate before authentication";
1587 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1588 sta
= NULL
; /* do not decrement sta->users */
1591 atomic_inc(&sta
->users
);
1592 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1594 pos
= (__le16
*) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1595 sta
->capability
= __le16_to_cpu(*pos
);
1597 sta
->listen_interval
= __le16_to_cpu(*pos
);
1601 memcpy(prev_ap
, pos
, ETH_ALEN
);
1602 pos
++; pos
++; pos
++; left
-= 6;
1604 memset(prev_ap
, 0, ETH_ALEN
);
1608 unsigned char *u
= (unsigned char *) pos
;
1610 if (*u
== WLAN_EID_SSID
) {
1615 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
1616 txt
= "SSID overflow";
1617 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1621 if (ileft
!= strlen(local
->essid
) ||
1622 memcmp(local
->essid
, u
, ileft
) != 0) {
1623 txt
= "not our SSID";
1624 resp
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1632 if (left
>= 2 && *u
== WLAN_EID_SUPP_RATES
) {
1637 if (ileft
> left
|| ileft
== 0 ||
1638 ileft
> WLAN_SUPP_RATES_MAX
) {
1639 txt
= "SUPP_RATES len error";
1640 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1644 memset(sta
->supported_rates
, 0,
1645 sizeof(sta
->supported_rates
));
1646 memcpy(sta
->supported_rates
, u
, ileft
);
1647 prism2_check_tx_rates(sta
);
1654 PDEBUG(DEBUG_AP
, "%s: assoc from %pM"
1655 " with extra data (%d bytes) [",
1656 dev
->name
, hdr
->addr2
, left
);
1658 PDEBUG2(DEBUG_AP
, "<%02x>", *u
);
1661 PDEBUG2(DEBUG_AP
, "]\n");
1664 txt
= "frame underflow";
1665 resp
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1669 /* get a unique AID */
1671 txt
= "OK, old AID";
1673 spin_lock_bh(&local
->ap
->sta_table_lock
);
1674 for (sta
->aid
= 1; sta
->aid
<= MAX_AID_TABLE_SIZE
; sta
->aid
++)
1675 if (local
->ap
->sta_aid
[sta
->aid
- 1] == NULL
)
1677 if (sta
->aid
> MAX_AID_TABLE_SIZE
) {
1679 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1680 resp
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1681 txt
= "no room for more AIDs";
1683 local
->ap
->sta_aid
[sta
->aid
- 1] = sta
;
1684 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1685 txt
= "OK, new AID";
1690 pos
= (__le16
*) body
;
1693 *pos
= cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH
);
1696 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1697 * values in beacons/probe responses */
1698 /* FIX: how about privacy and WEP? */
1700 *pos
= cpu_to_le16(WLAN_CAPABILITY_ESS
);
1704 *pos
= cpu_to_le16(resp
);
1707 *pos
= cpu_to_le16((sta
&& sta
->aid
> 0 ? sta
->aid
: 0) |
1708 BIT(14) | BIT(15)); /* AID */
1711 /* Supported rates (Information element) */
1713 *p
++ = WLAN_EID_SUPP_RATES
;
1716 if (local
->tx_rate_control
& WLAN_RATE_1M
) {
1717 *p
++ = local
->basic_rates
& WLAN_RATE_1M
? 0x82 : 0x02;
1720 if (local
->tx_rate_control
& WLAN_RATE_2M
) {
1721 *p
++ = local
->basic_rates
& WLAN_RATE_2M
? 0x84 : 0x04;
1724 if (local
->tx_rate_control
& WLAN_RATE_5M5
) {
1725 *p
++ = local
->basic_rates
& WLAN_RATE_5M5
?
1729 if (local
->tx_rate_control
& WLAN_RATE_11M
) {
1730 *p
++ = local
->basic_rates
& WLAN_RATE_11M
?
1737 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1738 (send_deauth
? IEEE80211_STYPE_DEAUTH
:
1739 (reassoc
? IEEE80211_STYPE_REASSOC_RESP
:
1740 IEEE80211_STYPE_ASSOC_RESP
)),
1741 body
, (u8
*) pos
- (u8
*) body
,
1743 send_deauth
? 0 : local
->ap
->tx_callback_assoc
);
1746 if (resp
== WLAN_STATUS_SUCCESS
) {
1747 sta
->last_rx
= jiffies
;
1748 /* STA will be marked associated from TX callback, if
1749 * AssocResp is ACKed */
1751 atomic_dec(&sta
->users
);
1755 PDEBUG(DEBUG_AP
, "%s: %pM %sassoc (len=%d "
1756 "prev_ap=%pM) => %d(%d) (%s)\n",
1759 reassoc
? "re" : "", len
,
1761 resp
, send_deauth
, txt
);
1766 /* Called only as a scheduled task for pending AP frames. */
1767 static void handle_deauth(local_info_t
*local
, struct sk_buff
*skb
,
1768 struct hostap_80211_rx_status
*rx_stats
)
1770 struct net_device
*dev
= local
->dev
;
1771 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1772 char *body
= (char *) (skb
->data
+ IEEE80211_MGMT_HDR_LEN
);
1776 struct sta_info
*sta
= NULL
;
1778 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1781 printk("handle_deauth - too short payload (len=%d)\n", len
);
1785 pos
= (__le16
*) body
;
1786 reason_code
= le16_to_cpu(*pos
);
1788 PDEBUG(DEBUG_AP
, "%s: deauthentication: %pM len=%d, "
1789 "reason_code=%d\n", dev
->name
, hdr
->addr2
,
1792 spin_lock_bh(&local
->ap
->sta_table_lock
);
1793 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1795 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1796 hostap_event_expired_sta(local
->dev
, sta
);
1797 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
1799 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1801 printk("%s: deauthentication from %pM, "
1802 "reason_code=%d, but STA not authenticated\n", dev
->name
,
1803 hdr
->addr2
, reason_code
);
1808 /* Called only as a scheduled task for pending AP frames. */
1809 static void handle_disassoc(local_info_t
*local
, struct sk_buff
*skb
,
1810 struct hostap_80211_rx_status
*rx_stats
)
1812 struct net_device
*dev
= local
->dev
;
1813 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1814 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
1818 struct sta_info
*sta
= NULL
;
1820 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
1823 printk("handle_disassoc - too short payload (len=%d)\n", len
);
1827 pos
= (__le16
*) body
;
1828 reason_code
= le16_to_cpu(*pos
);
1830 PDEBUG(DEBUG_AP
, "%s: disassociation: %pM len=%d, "
1831 "reason_code=%d\n", dev
->name
, hdr
->addr2
,
1834 spin_lock_bh(&local
->ap
->sta_table_lock
);
1835 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1837 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
1838 hostap_event_expired_sta(local
->dev
, sta
);
1839 sta
->flags
&= ~WLAN_STA_ASSOC
;
1841 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1843 printk("%s: disassociation from %pM, "
1844 "reason_code=%d, but STA not authenticated\n",
1845 dev
->name
, hdr
->addr2
, reason_code
);
1850 /* Called only as a scheduled task for pending AP frames. */
1851 static void ap_handle_data_nullfunc(local_info_t
*local
,
1852 struct ieee80211_hdr
*hdr
)
1854 struct net_device
*dev
= local
->dev
;
1856 /* some STA f/w's seem to require control::ACK frame for
1857 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1859 * send control::ACK for the data::nullfunc */
1861 printk(KERN_DEBUG
"Sending control::ACK for data::nullfunc\n");
1862 prism2_send_mgmt(dev
, IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_ACK
,
1863 NULL
, 0, hdr
->addr2
, 0);
1867 /* Called only as a scheduled task for pending AP frames. */
1868 static void ap_handle_dropped_data(local_info_t
*local
,
1869 struct ieee80211_hdr
*hdr
)
1871 struct net_device
*dev
= local
->dev
;
1872 struct sta_info
*sta
;
1875 spin_lock_bh(&local
->ap
->sta_table_lock
);
1876 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1878 atomic_inc(&sta
->users
);
1879 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1881 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
)) {
1882 PDEBUG(DEBUG_AP
, "ap_handle_dropped_data: STA is now okay?\n");
1883 atomic_dec(&sta
->users
);
1887 reason
= cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
1888 prism2_send_mgmt(dev
, IEEE80211_FTYPE_MGMT
|
1889 ((sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) ?
1890 IEEE80211_STYPE_DEAUTH
: IEEE80211_STYPE_DISASSOC
),
1891 (char *) &reason
, sizeof(reason
), hdr
->addr2
, 0);
1894 atomic_dec(&sta
->users
);
1897 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1900 /* Called only as a scheduled task for pending AP frames. */
1901 static void pspoll_send_buffered(local_info_t
*local
, struct sta_info
*sta
,
1902 struct sk_buff
*skb
)
1904 struct hostap_skb_tx_data
*meta
;
1906 if (!(sta
->flags
& WLAN_STA_PS
)) {
1907 /* Station has moved to non-PS mode, so send all buffered
1908 * frames using normal device queue. */
1909 dev_queue_xmit(skb
);
1913 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1914 * be passed through even though STA is using PS */
1915 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1916 meta
->flags
|= HOSTAP_TX_FLAGS_BUFFERED_FRAME
;
1917 if (!skb_queue_empty(&sta
->tx_buf
)) {
1918 /* indicate to STA that more frames follow */
1919 meta
->flags
|= HOSTAP_TX_FLAGS_ADD_MOREDATA
;
1921 dev_queue_xmit(skb
);
1925 /* Called only as a scheduled task for pending AP frames. */
1926 static void handle_pspoll(local_info_t
*local
,
1927 struct ieee80211_hdr
*hdr
,
1928 struct hostap_80211_rx_status
*rx_stats
)
1930 struct net_device
*dev
= local
->dev
;
1931 struct sta_info
*sta
;
1933 struct sk_buff
*skb
;
1935 PDEBUG(DEBUG_PS2
, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
1936 hdr
->addr1
, hdr
->addr2
, !!ieee80211_has_pm(hdr
->frame_control
));
1938 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
1940 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1945 aid
= le16_to_cpu(hdr
->duration_id
);
1946 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1947 PDEBUG(DEBUG_PS
, " PSPOLL and AID[15:14] not set\n");
1950 aid
&= ~(BIT(15) | BIT(14));
1951 if (aid
== 0 || aid
> MAX_AID_TABLE_SIZE
) {
1952 PDEBUG(DEBUG_PS
, " invalid aid=%d\n", aid
);
1955 PDEBUG(DEBUG_PS2
, " aid=%d\n", aid
);
1957 spin_lock_bh(&local
->ap
->sta_table_lock
);
1958 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
1960 atomic_inc(&sta
->users
);
1961 spin_unlock_bh(&local
->ap
->sta_table_lock
);
1964 PDEBUG(DEBUG_PS
, " STA not found\n");
1967 if (sta
->aid
!= aid
) {
1968 PDEBUG(DEBUG_PS
, " received aid=%i does not match with "
1969 "assoc.aid=%d\n", aid
, sta
->aid
);
1974 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1975 * out (expiry time must be longer than ListenInterval for
1976 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1977 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1978 * sta; store buffer for later use and leave TIM aid bit set? use
1979 * TX event to check whether frame was ACKed?
1982 while ((skb
= skb_dequeue(&sta
->tx_buf
)) != NULL
) {
1983 /* send buffered frame .. */
1984 PDEBUG(DEBUG_PS2
, "Sending buffered frame to STA after PS POLL"
1985 " (buffer_count=%d)\n", skb_queue_len(&sta
->tx_buf
));
1987 pspoll_send_buffered(local
, sta
, skb
);
1989 if (sta
->flags
& WLAN_STA_PS
) {
1990 /* send only one buffered packet per PS Poll */
1991 /* FIX: should ignore further PS Polls until the
1992 * buffered packet that was just sent is acknowledged
1993 * (Tx or TxExc event) */
1998 if (skb_queue_empty(&sta
->tx_buf
)) {
1999 /* try to clear aid from TIM */
2000 if (!(sta
->flags
& WLAN_STA_TIM
))
2001 PDEBUG(DEBUG_PS2
, "Re-unsetting TIM for aid %d\n",
2003 hostap_set_tim(local
, aid
, 0);
2004 sta
->flags
&= ~WLAN_STA_TIM
;
2007 atomic_dec(&sta
->users
);
2011 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2013 static void handle_wds_oper_queue(struct work_struct
*work
)
2015 struct ap_data
*ap
= container_of(work
, struct ap_data
,
2017 local_info_t
*local
= ap
->local
;
2018 struct wds_oper_data
*entry
, *prev
;
2020 spin_lock_bh(&local
->lock
);
2021 entry
= local
->ap
->wds_oper_entries
;
2022 local
->ap
->wds_oper_entries
= NULL
;
2023 spin_unlock_bh(&local
->lock
);
2026 PDEBUG(DEBUG_AP
, "%s: %s automatic WDS connection "
2029 entry
->type
== WDS_ADD
? "adding" : "removing",
2031 if (entry
->type
== WDS_ADD
)
2032 prism2_wds_add(local
, entry
->addr
, 0);
2033 else if (entry
->type
== WDS_DEL
)
2034 prism2_wds_del(local
, entry
->addr
, 0, 1);
2037 entry
= entry
->next
;
2043 /* Called only as a scheduled task for pending AP frames. */
2044 static void handle_beacon(local_info_t
*local
, struct sk_buff
*skb
,
2045 struct hostap_80211_rx_status
*rx_stats
)
2047 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
2048 char *body
= skb
->data
+ IEEE80211_MGMT_HDR_LEN
;
2050 u16 beacon_int
, capability
;
2053 unsigned char *supp_rates
= NULL
;
2054 int ssid_len
= 0, supp_rates_len
= 0;
2055 struct sta_info
*sta
= NULL
;
2056 int new_sta
= 0, channel
= -1;
2058 len
= skb
->len
- IEEE80211_MGMT_HDR_LEN
;
2060 if (len
< 8 + 2 + 2) {
2061 printk(KERN_DEBUG
"handle_beacon - too short payload "
2066 pos
= (__le16
*) body
;
2069 /* Timestamp (8 octets) */
2070 pos
+= 4; left
-= 8;
2071 /* Beacon interval (2 octets) */
2072 beacon_int
= le16_to_cpu(*pos
);
2074 /* Capability information (2 octets) */
2075 capability
= le16_to_cpu(*pos
);
2078 if (local
->ap
->ap_policy
!= AP_OTHER_AP_EVEN_IBSS
&&
2079 capability
& WLAN_CAPABILITY_IBSS
)
2084 unsigned char *u
= (unsigned char *) pos
;
2086 if (*u
== WLAN_EID_SSID
) {
2091 if (ileft
> left
|| ileft
> MAX_SSID_LEN
) {
2092 PDEBUG(DEBUG_AP
, "SSID: overflow\n");
2096 if (local
->ap
->ap_policy
== AP_OTHER_AP_SAME_SSID
&&
2097 (ileft
!= strlen(local
->essid
) ||
2098 memcmp(local
->essid
, u
, ileft
) != 0)) {
2110 if (*u
== WLAN_EID_SUPP_RATES
) {
2115 if (ileft
> left
|| ileft
== 0 || ileft
> 8) {
2116 PDEBUG(DEBUG_AP
, " - SUPP_RATES len error\n");
2121 supp_rates_len
= ileft
;
2127 if (*u
== WLAN_EID_DS_PARAMS
) {
2132 if (ileft
> left
|| ileft
!= 1) {
2133 PDEBUG(DEBUG_AP
, " - DS_PARAMS len error\n");
2144 spin_lock_bh(&local
->ap
->sta_table_lock
);
2145 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2147 atomic_inc(&sta
->users
);
2148 spin_unlock_bh(&local
->ap
->sta_table_lock
);
2153 sta
= ap_add_sta(local
->ap
, hdr
->addr2
);
2155 printk(KERN_INFO
"prism2: kmalloc failed for AP "
2156 "data structure\n");
2159 hostap_event_new_sta(local
->dev
, sta
);
2161 /* mark APs authentication and associated for pseudo ad-hoc
2162 * style communication */
2163 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2165 if (local
->ap
->autom_ap_wds
) {
2166 hostap_wds_link_oper(local
, sta
->addr
, WDS_ADD
);
2172 sta
->u
.ap
.ssid_len
= ssid_len
;
2173 memcpy(sta
->u
.ap
.ssid
, ssid
, ssid_len
);
2174 sta
->u
.ap
.ssid
[ssid_len
] = '\0';
2176 sta
->u
.ap
.ssid_len
= 0;
2177 sta
->u
.ap
.ssid
[0] = '\0';
2179 sta
->u
.ap
.channel
= channel
;
2181 sta
->rx_bytes
+= len
;
2182 sta
->u
.ap
.last_beacon
= sta
->last_rx
= jiffies
;
2183 sta
->capability
= capability
;
2184 sta
->listen_interval
= beacon_int
;
2186 atomic_dec(&sta
->users
);
2189 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
2190 memcpy(sta
->supported_rates
, supp_rates
, supp_rates_len
);
2191 prism2_check_tx_rates(sta
);
2195 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2198 /* Called only as a tasklet. */
2199 static void handle_ap_item(local_info_t
*local
, struct sk_buff
*skb
,
2200 struct hostap_80211_rx_status
*rx_stats
)
2202 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2203 struct net_device
*dev
= local
->dev
;
2204 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2205 u16 fc
, type
, stype
;
2206 struct ieee80211_hdr
*hdr
;
2208 /* FIX: should give skb->len to handler functions and check that the
2209 * buffer is long enough */
2210 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2211 fc
= le16_to_cpu(hdr
->frame_control
);
2212 type
= fc
& IEEE80211_FCTL_FTYPE
;
2213 stype
= fc
& IEEE80211_FCTL_STYPE
;
2215 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2216 if (!local
->hostapd
&& type
== IEEE80211_FTYPE_DATA
) {
2217 PDEBUG(DEBUG_AP
, "handle_ap_item - data frame\n");
2219 if (!(fc
& IEEE80211_FCTL_TODS
) ||
2220 (fc
& IEEE80211_FCTL_FROMDS
)) {
2221 if (stype
== IEEE80211_STYPE_NULLFUNC
) {
2222 /* no ToDS nullfunc seems to be used to check
2223 * AP association; so send reject message to
2224 * speed up re-association */
2225 ap_handle_dropped_data(local
, hdr
);
2228 PDEBUG(DEBUG_AP
, " not ToDS frame (fc=0x%04x)\n",
2233 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
2234 PDEBUG(DEBUG_AP
, "handle_ap_item - addr1(BSSID)=%pM"
2235 " not own MAC\n", hdr
->addr1
);
2239 if (local
->ap
->nullfunc_ack
&&
2240 stype
== IEEE80211_STYPE_NULLFUNC
)
2241 ap_handle_data_nullfunc(local
, hdr
);
2243 ap_handle_dropped_data(local
, hdr
);
2247 if (type
== IEEE80211_FTYPE_MGMT
&& stype
== IEEE80211_STYPE_BEACON
) {
2248 handle_beacon(local
, skb
, rx_stats
);
2251 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2253 if (type
== IEEE80211_FTYPE_CTL
&& stype
== IEEE80211_STYPE_PSPOLL
) {
2254 handle_pspoll(local
, hdr
, rx_stats
);
2258 if (local
->hostapd
) {
2259 PDEBUG(DEBUG_AP
, "Unknown frame in AP queue: type=0x%02x "
2260 "subtype=0x%02x\n", type
, stype
);
2264 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2265 if (type
!= IEEE80211_FTYPE_MGMT
) {
2266 PDEBUG(DEBUG_AP
, "handle_ap_item - not a management frame?\n");
2270 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
)) {
2271 PDEBUG(DEBUG_AP
, "handle_ap_item - addr1(DA)=%pM"
2272 " not own MAC\n", hdr
->addr1
);
2276 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
)) {
2277 PDEBUG(DEBUG_AP
, "handle_ap_item - addr3(BSSID)=%pM"
2278 " not own MAC\n", hdr
->addr3
);
2283 case IEEE80211_STYPE_ASSOC_REQ
:
2284 handle_assoc(local
, skb
, rx_stats
, 0);
2286 case IEEE80211_STYPE_ASSOC_RESP
:
2287 PDEBUG(DEBUG_AP
, "==> ASSOC RESP (ignored)\n");
2289 case IEEE80211_STYPE_REASSOC_REQ
:
2290 handle_assoc(local
, skb
, rx_stats
, 1);
2292 case IEEE80211_STYPE_REASSOC_RESP
:
2293 PDEBUG(DEBUG_AP
, "==> REASSOC RESP (ignored)\n");
2295 case IEEE80211_STYPE_ATIM
:
2296 PDEBUG(DEBUG_AP
, "==> ATIM (ignored)\n");
2298 case IEEE80211_STYPE_DISASSOC
:
2299 handle_disassoc(local
, skb
, rx_stats
);
2301 case IEEE80211_STYPE_AUTH
:
2302 handle_authen(local
, skb
, rx_stats
);
2304 case IEEE80211_STYPE_DEAUTH
:
2305 handle_deauth(local
, skb
, rx_stats
);
2308 PDEBUG(DEBUG_AP
, "Unknown mgmt frame subtype 0x%02x\n",
2312 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2319 /* Called only as a tasklet (software IRQ) */
2320 void hostap_rx(struct net_device
*dev
, struct sk_buff
*skb
,
2321 struct hostap_80211_rx_status
*rx_stats
)
2323 struct hostap_interface
*iface
;
2324 local_info_t
*local
;
2325 struct ieee80211_hdr
*hdr
;
2327 iface
= netdev_priv(dev
);
2328 local
= iface
->local
;
2333 dev
->stats
.rx_packets
++;
2335 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2337 if (local
->ap
->ap_policy
== AP_OTHER_AP_SKIP_ALL
&&
2338 ieee80211_is_beacon(hdr
->frame_control
))
2341 skb
->protocol
= cpu_to_be16(ETH_P_HOSTAP
);
2342 handle_ap_item(local
, skb
, rx_stats
);
2350 /* Called only as a tasklet (software IRQ) */
2351 static void schedule_packet_send(local_info_t
*local
, struct sta_info
*sta
)
2353 struct sk_buff
*skb
;
2354 struct ieee80211_hdr
*hdr
;
2355 struct hostap_80211_rx_status rx_stats
;
2357 if (skb_queue_empty(&sta
->tx_buf
))
2360 skb
= dev_alloc_skb(16);
2362 printk(KERN_DEBUG
"%s: schedule_packet_send: skb alloc "
2363 "failed\n", local
->dev
->name
);
2367 hdr
= (struct ieee80211_hdr
*) skb_put(skb
, 16);
2369 /* Generate a fake pspoll frame to start packet delivery */
2370 hdr
->frame_control
= cpu_to_le16(
2371 IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_PSPOLL
);
2372 memcpy(hdr
->addr1
, local
->dev
->dev_addr
, ETH_ALEN
);
2373 memcpy(hdr
->addr2
, sta
->addr
, ETH_ALEN
);
2374 hdr
->duration_id
= cpu_to_le16(sta
->aid
| BIT(15) | BIT(14));
2377 "%s: Scheduling buffered packet delivery for STA %pM\n",
2378 local
->dev
->name
, sta
->addr
);
2380 skb
->dev
= local
->dev
;
2382 memset(&rx_stats
, 0, sizeof(rx_stats
));
2383 hostap_rx(local
->dev
, skb
, &rx_stats
);
2387 int prism2_ap_get_sta_qual(local_info_t
*local
, struct sockaddr addr
[],
2388 struct iw_quality qual
[], int buf_size
,
2391 struct ap_data
*ap
= local
->ap
;
2392 struct list_head
*ptr
;
2395 spin_lock_bh(&ap
->sta_table_lock
);
2397 for (ptr
= ap
->sta_list
.next
; ptr
!= NULL
&& ptr
!= &ap
->sta_list
;
2399 struct sta_info
*sta
= (struct sta_info
*) ptr
;
2401 if (aplist
&& !sta
->ap
)
2403 addr
[count
].sa_family
= ARPHRD_ETHER
;
2404 memcpy(addr
[count
].sa_data
, sta
->addr
, ETH_ALEN
);
2405 if (sta
->last_rx_silence
== 0)
2406 qual
[count
].qual
= sta
->last_rx_signal
< 27 ?
2407 0 : (sta
->last_rx_signal
- 27) * 92 / 127;
2409 qual
[count
].qual
= sta
->last_rx_signal
-
2410 sta
->last_rx_silence
- 35;
2411 qual
[count
].level
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_signal
);
2412 qual
[count
].noise
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_silence
);
2413 qual
[count
].updated
= sta
->last_rx_updated
;
2415 sta
->last_rx_updated
= IW_QUAL_DBM
;
2418 if (count
>= buf_size
)
2421 spin_unlock_bh(&ap
->sta_table_lock
);
2427 /* Translate our list of Access Points & Stations to a card independent
2428 * format that the Wireless Tools will understand - Jean II */
2429 int prism2_ap_translate_scan(struct net_device
*dev
,
2430 struct iw_request_info
*info
, char *buffer
)
2432 struct hostap_interface
*iface
;
2433 local_info_t
*local
;
2435 struct list_head
*ptr
;
2436 struct iw_event iwe
;
2437 char *current_ev
= buffer
;
2438 char *end_buf
= buffer
+ IW_SCAN_MAX_DATA
;
2439 #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2443 iface
= netdev_priv(dev
);
2444 local
= iface
->local
;
2447 spin_lock_bh(&ap
->sta_table_lock
);
2449 for (ptr
= ap
->sta_list
.next
; ptr
!= NULL
&& ptr
!= &ap
->sta_list
;
2451 struct sta_info
*sta
= (struct sta_info
*) ptr
;
2453 /* First entry *MUST* be the AP MAC address */
2454 memset(&iwe
, 0, sizeof(iwe
));
2455 iwe
.cmd
= SIOCGIWAP
;
2456 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2457 memcpy(iwe
.u
.ap_addr
.sa_data
, sta
->addr
, ETH_ALEN
);
2458 iwe
.len
= IW_EV_ADDR_LEN
;
2459 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
2460 &iwe
, IW_EV_ADDR_LEN
);
2462 /* Use the mode to indicate if it's a station or
2463 * an Access Point */
2464 memset(&iwe
, 0, sizeof(iwe
));
2465 iwe
.cmd
= SIOCGIWMODE
;
2467 iwe
.u
.mode
= IW_MODE_MASTER
;
2469 iwe
.u
.mode
= IW_MODE_INFRA
;
2470 iwe
.len
= IW_EV_UINT_LEN
;
2471 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
2472 &iwe
, IW_EV_UINT_LEN
);
2475 memset(&iwe
, 0, sizeof(iwe
));
2477 if (sta
->last_rx_silence
== 0)
2478 iwe
.u
.qual
.qual
= sta
->last_rx_signal
< 27 ?
2479 0 : (sta
->last_rx_signal
- 27) * 92 / 127;
2481 iwe
.u
.qual
.qual
= sta
->last_rx_signal
-
2482 sta
->last_rx_silence
- 35;
2483 iwe
.u
.qual
.level
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_signal
);
2484 iwe
.u
.qual
.noise
= HFA384X_LEVEL_TO_dBm(sta
->last_rx_silence
);
2485 iwe
.u
.qual
.updated
= sta
->last_rx_updated
;
2486 iwe
.len
= IW_EV_QUAL_LEN
;
2487 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
2488 &iwe
, IW_EV_QUAL_LEN
);
2490 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2492 memset(&iwe
, 0, sizeof(iwe
));
2493 iwe
.cmd
= SIOCGIWESSID
;
2494 iwe
.u
.data
.length
= sta
->u
.ap
.ssid_len
;
2495 iwe
.u
.data
.flags
= 1;
2496 current_ev
= iwe_stream_add_point(info
, current_ev
,
2500 memset(&iwe
, 0, sizeof(iwe
));
2501 iwe
.cmd
= SIOCGIWENCODE
;
2502 if (sta
->capability
& WLAN_CAPABILITY_PRIVACY
)
2504 IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2506 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2507 current_ev
= iwe_stream_add_point(info
, current_ev
,
2511 if (sta
->u
.ap
.channel
> 0 &&
2512 sta
->u
.ap
.channel
<= FREQ_COUNT
) {
2513 memset(&iwe
, 0, sizeof(iwe
));
2514 iwe
.cmd
= SIOCGIWFREQ
;
2515 iwe
.u
.freq
.m
= freq_list
[sta
->u
.ap
.channel
- 1]
2518 current_ev
= iwe_stream_add_event(
2519 info
, current_ev
, end_buf
, &iwe
,
2523 memset(&iwe
, 0, sizeof(iwe
));
2524 iwe
.cmd
= IWEVCUSTOM
;
2525 sprintf(buf
, "beacon_interval=%d",
2526 sta
->listen_interval
);
2527 iwe
.u
.data
.length
= strlen(buf
);
2528 current_ev
= iwe_stream_add_point(info
, current_ev
,
2529 end_buf
, &iwe
, buf
);
2531 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2533 sta
->last_rx_updated
= IW_QUAL_DBM
;
2535 /* To be continued, we should make good use of IWEVCUSTOM */
2538 spin_unlock_bh(&ap
->sta_table_lock
);
2540 return current_ev
- buffer
;
2544 static int prism2_hostapd_add_sta(struct ap_data
*ap
,
2545 struct prism2_hostapd_param
*param
)
2547 struct sta_info
*sta
;
2549 spin_lock_bh(&ap
->sta_table_lock
);
2550 sta
= ap_get_sta(ap
, param
->sta_addr
);
2552 atomic_inc(&sta
->users
);
2553 spin_unlock_bh(&ap
->sta_table_lock
);
2556 sta
= ap_add_sta(ap
, param
->sta_addr
);
2561 if (!(sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2562 hostap_event_new_sta(sta
->local
->dev
, sta
);
2564 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
2565 sta
->last_rx
= jiffies
;
2566 sta
->aid
= param
->u
.add_sta
.aid
;
2567 sta
->capability
= param
->u
.add_sta
.capability
;
2568 sta
->tx_supp_rates
= param
->u
.add_sta
.tx_supp_rates
;
2569 if (sta
->tx_supp_rates
& WLAN_RATE_1M
)
2570 sta
->supported_rates
[0] = 2;
2571 if (sta
->tx_supp_rates
& WLAN_RATE_2M
)
2572 sta
->supported_rates
[1] = 4;
2573 if (sta
->tx_supp_rates
& WLAN_RATE_5M5
)
2574 sta
->supported_rates
[2] = 11;
2575 if (sta
->tx_supp_rates
& WLAN_RATE_11M
)
2576 sta
->supported_rates
[3] = 22;
2577 prism2_check_tx_rates(sta
);
2578 atomic_dec(&sta
->users
);
2583 static int prism2_hostapd_remove_sta(struct ap_data
*ap
,
2584 struct prism2_hostapd_param
*param
)
2586 struct sta_info
*sta
;
2588 spin_lock_bh(&ap
->sta_table_lock
);
2589 sta
= ap_get_sta(ap
, param
->sta_addr
);
2591 ap_sta_hash_del(ap
, sta
);
2592 list_del(&sta
->list
);
2594 spin_unlock_bh(&ap
->sta_table_lock
);
2599 if ((sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&& sta
->local
)
2600 hostap_event_expired_sta(sta
->local
->dev
, sta
);
2601 ap_free_sta(ap
, sta
);
2607 static int prism2_hostapd_get_info_sta(struct ap_data
*ap
,
2608 struct prism2_hostapd_param
*param
)
2610 struct sta_info
*sta
;
2612 spin_lock_bh(&ap
->sta_table_lock
);
2613 sta
= ap_get_sta(ap
, param
->sta_addr
);
2615 atomic_inc(&sta
->users
);
2616 spin_unlock_bh(&ap
->sta_table_lock
);
2621 param
->u
.get_info_sta
.inactive_sec
= (jiffies
- sta
->last_rx
) / HZ
;
2623 atomic_dec(&sta
->users
);
2629 static int prism2_hostapd_set_flags_sta(struct ap_data
*ap
,
2630 struct prism2_hostapd_param
*param
)
2632 struct sta_info
*sta
;
2634 spin_lock_bh(&ap
->sta_table_lock
);
2635 sta
= ap_get_sta(ap
, param
->sta_addr
);
2637 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
2638 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
2640 spin_unlock_bh(&ap
->sta_table_lock
);
2649 static int prism2_hostapd_sta_clear_stats(struct ap_data
*ap
,
2650 struct prism2_hostapd_param
*param
)
2652 struct sta_info
*sta
;
2655 spin_lock_bh(&ap
->sta_table_lock
);
2656 sta
= ap_get_sta(ap
, param
->sta_addr
);
2658 sta
->rx_packets
= sta
->tx_packets
= 0;
2659 sta
->rx_bytes
= sta
->tx_bytes
= 0;
2660 for (rate
= 0; rate
< WLAN_RATE_COUNT
; rate
++) {
2661 sta
->tx_count
[rate
] = 0;
2662 sta
->rx_count
[rate
] = 0;
2665 spin_unlock_bh(&ap
->sta_table_lock
);
2674 int prism2_hostapd(struct ap_data
*ap
, struct prism2_hostapd_param
*param
)
2676 switch (param
->cmd
) {
2677 case PRISM2_HOSTAPD_FLUSH
:
2678 ap_control_kickall(ap
);
2680 case PRISM2_HOSTAPD_ADD_STA
:
2681 return prism2_hostapd_add_sta(ap
, param
);
2682 case PRISM2_HOSTAPD_REMOVE_STA
:
2683 return prism2_hostapd_remove_sta(ap
, param
);
2684 case PRISM2_HOSTAPD_GET_INFO_STA
:
2685 return prism2_hostapd_get_info_sta(ap
, param
);
2686 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
2687 return prism2_hostapd_set_flags_sta(ap
, param
);
2688 case PRISM2_HOSTAPD_STA_CLEAR_STATS
:
2689 return prism2_hostapd_sta_clear_stats(ap
, param
);
2691 printk(KERN_WARNING
"prism2_hostapd: unknown cmd=%d\n",
2698 /* Update station info for host-based TX rate control and return current
2700 static int ap_update_sta_tx_rate(struct sta_info
*sta
, struct net_device
*dev
)
2702 int ret
= sta
->tx_rate
;
2703 struct hostap_interface
*iface
;
2704 local_info_t
*local
;
2706 iface
= netdev_priv(dev
);
2707 local
= iface
->local
;
2709 sta
->tx_count
[sta
->tx_rate_idx
]++;
2710 sta
->tx_since_last_failure
++;
2711 sta
->tx_consecutive_exc
= 0;
2712 if (sta
->tx_since_last_failure
>= WLAN_RATE_UPDATE_COUNT
&&
2713 sta
->tx_rate_idx
< sta
->tx_max_rate
) {
2714 /* use next higher rate */
2715 int old_rate
, new_rate
;
2716 old_rate
= new_rate
= sta
->tx_rate_idx
;
2717 while (new_rate
< sta
->tx_max_rate
) {
2719 if (ap_tx_rate_ok(new_rate
, sta
, local
)) {
2720 sta
->tx_rate_idx
= new_rate
;
2724 if (old_rate
!= sta
->tx_rate_idx
) {
2725 switch (sta
->tx_rate_idx
) {
2726 case 0: sta
->tx_rate
= 10; break;
2727 case 1: sta
->tx_rate
= 20; break;
2728 case 2: sta
->tx_rate
= 55; break;
2729 case 3: sta
->tx_rate
= 110; break;
2730 default: sta
->tx_rate
= 0; break;
2732 PDEBUG(DEBUG_AP
, "%s: STA %pM TX rate raised to %d\n",
2733 dev
->name
, sta
->addr
, sta
->tx_rate
);
2735 sta
->tx_since_last_failure
= 0;
2742 /* Called only from software IRQ. Called for each TX frame prior possible
2743 * encryption and transmit. */
2744 ap_tx_ret
hostap_handle_sta_tx(local_info_t
*local
, struct hostap_tx_data
*tx
)
2746 struct sta_info
*sta
= NULL
;
2747 struct sk_buff
*skb
= tx
->skb
;
2749 struct ieee80211_hdr
*hdr
;
2750 struct hostap_skb_tx_data
*meta
;
2752 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2753 ret
= AP_TX_CONTINUE
;
2754 if (local
->ap
== NULL
|| skb
->len
< 10 ||
2755 meta
->iface
->type
== HOSTAP_INTERFACE_STA
)
2758 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2760 if (hdr
->addr1
[0] & 0x01) {
2761 /* broadcast/multicast frame - no AP related processing */
2762 if (local
->ap
->num_sta
<= 0)
2767 /* unicast packet - check whether destination STA is associated */
2768 spin_lock(&local
->ap
->sta_table_lock
);
2769 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2771 atomic_inc(&sta
->users
);
2772 spin_unlock(&local
->ap
->sta_table_lock
);
2774 if (local
->iw_mode
== IW_MODE_MASTER
&& sta
== NULL
&&
2775 !(meta
->flags
& HOSTAP_TX_FLAGS_WDS
) &&
2776 meta
->iface
->type
!= HOSTAP_INTERFACE_MASTER
&&
2777 meta
->iface
->type
!= HOSTAP_INTERFACE_AP
) {
2779 /* This can happen, e.g., when wlan0 is added to a bridge and
2780 * bridging code does not know which port is the correct target
2781 * for a unicast frame. In this case, the packet is send to all
2782 * ports of the bridge. Since this is a valid scenario, do not
2783 * print out any errors here. */
2784 if (net_ratelimit()) {
2785 printk(KERN_DEBUG
"AP: drop packet to non-associated "
2786 "STA %pM\n", hdr
->addr1
);
2789 local
->ap
->tx_drop_nonassoc
++;
2797 if (!(sta
->flags
& WLAN_STA_AUTHORIZED
))
2798 ret
= AP_TX_CONTINUE_NOT_AUTHORIZED
;
2800 /* Set tx_rate if using host-based TX rate control */
2801 if (!local
->fw_tx_rate_control
)
2802 local
->ap
->last_tx_rate
= meta
->rate
=
2803 ap_update_sta_tx_rate(sta
, local
->dev
);
2805 if (local
->iw_mode
!= IW_MODE_MASTER
)
2808 if (!(sta
->flags
& WLAN_STA_PS
))
2811 if (meta
->flags
& HOSTAP_TX_FLAGS_ADD_MOREDATA
) {
2812 /* indicate to STA that more frames follow */
2813 hdr
->frame_control
|=
2814 cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
2817 if (meta
->flags
& HOSTAP_TX_FLAGS_BUFFERED_FRAME
) {
2818 /* packet was already buffered and now send due to
2819 * PS poll, so do not rebuffer it */
2823 if (skb_queue_len(&sta
->tx_buf
) >= STA_MAX_TX_BUFFER
) {
2824 PDEBUG(DEBUG_PS
, "%s: No more space in STA (%pM)'s"
2826 local
->dev
->name
, sta
->addr
);
2827 /* Make sure that TIM is set for the station (it might not be
2828 * after AP wlan hw reset). */
2829 /* FIX: should fix hw reset to restore bits based on STA
2831 hostap_set_tim(local
, sta
->aid
, 1);
2832 sta
->flags
|= WLAN_STA_TIM
;
2837 /* STA in PS mode, buffer frame for later delivery */
2838 set_tim
= skb_queue_empty(&sta
->tx_buf
);
2839 skb_queue_tail(&sta
->tx_buf
, skb
);
2840 /* FIX: could save RX time to skb and expire buffered frames after
2841 * some time if STA does not poll for them */
2844 if (sta
->flags
& WLAN_STA_TIM
)
2845 PDEBUG(DEBUG_PS2
, "Re-setting TIM for aid %d\n",
2847 hostap_set_tim(local
, sta
->aid
, 1);
2848 sta
->flags
|= WLAN_STA_TIM
;
2851 ret
= AP_TX_BUFFERED
;
2855 if (ret
== AP_TX_CONTINUE
||
2856 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) {
2858 sta
->tx_bytes
+= skb
->len
;
2859 sta
->last_tx
= jiffies
;
2862 if ((ret
== AP_TX_CONTINUE
||
2863 ret
== AP_TX_CONTINUE_NOT_AUTHORIZED
) &&
2864 sta
->crypt
&& tx
->host_encrypt
) {
2865 tx
->crypt
= sta
->crypt
;
2866 tx
->sta_ptr
= sta
; /* hostap_handle_sta_release() will
2867 * be called to release sta info
2870 atomic_dec(&sta
->users
);
2877 void hostap_handle_sta_release(void *ptr
)
2879 struct sta_info
*sta
= ptr
;
2880 atomic_dec(&sta
->users
);
2884 /* Called only as a tasklet (software IRQ) */
2885 void hostap_handle_sta_tx_exc(local_info_t
*local
, struct sk_buff
*skb
)
2887 struct sta_info
*sta
;
2888 struct ieee80211_hdr
*hdr
;
2889 struct hostap_skb_tx_data
*meta
;
2891 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2892 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
2894 spin_lock(&local
->ap
->sta_table_lock
);
2895 sta
= ap_get_sta(local
->ap
, hdr
->addr1
);
2897 spin_unlock(&local
->ap
->sta_table_lock
);
2898 PDEBUG(DEBUG_AP
, "%s: Could not find STA %pM"
2899 " for this TX error (@%lu)\n",
2900 local
->dev
->name
, hdr
->addr1
, jiffies
);
2904 sta
->tx_since_last_failure
= 0;
2905 sta
->tx_consecutive_exc
++;
2907 if (sta
->tx_consecutive_exc
>= WLAN_RATE_DECREASE_THRESHOLD
&&
2908 sta
->tx_rate_idx
> 0 && meta
->rate
<= sta
->tx_rate
) {
2909 /* use next lower rate */
2911 old
= rate
= sta
->tx_rate_idx
;
2914 if (ap_tx_rate_ok(rate
, sta
, local
)) {
2915 sta
->tx_rate_idx
= rate
;
2919 if (old
!= sta
->tx_rate_idx
) {
2920 switch (sta
->tx_rate_idx
) {
2921 case 0: sta
->tx_rate
= 10; break;
2922 case 1: sta
->tx_rate
= 20; break;
2923 case 2: sta
->tx_rate
= 55; break;
2924 case 3: sta
->tx_rate
= 110; break;
2925 default: sta
->tx_rate
= 0; break;
2928 "%s: STA %pM TX rate lowered to %d\n",
2929 local
->dev
->name
, sta
->addr
, sta
->tx_rate
);
2931 sta
->tx_consecutive_exc
= 0;
2933 spin_unlock(&local
->ap
->sta_table_lock
);
2937 static void hostap_update_sta_ps2(local_info_t
*local
, struct sta_info
*sta
,
2938 int pwrmgt
, int type
, int stype
)
2940 if (pwrmgt
&& !(sta
->flags
& WLAN_STA_PS
)) {
2941 sta
->flags
|= WLAN_STA_PS
;
2942 PDEBUG(DEBUG_PS2
, "STA %pM changed to use PS "
2943 "mode (type=0x%02X, stype=0x%02X)\n",
2944 sta
->addr
, type
>> 2, stype
>> 4);
2945 } else if (!pwrmgt
&& (sta
->flags
& WLAN_STA_PS
)) {
2946 sta
->flags
&= ~WLAN_STA_PS
;
2947 PDEBUG(DEBUG_PS2
, "STA %pM changed to not use "
2948 "PS mode (type=0x%02X, stype=0x%02X)\n",
2949 sta
->addr
, type
>> 2, stype
>> 4);
2950 if (type
!= IEEE80211_FTYPE_CTL
||
2951 stype
!= IEEE80211_STYPE_PSPOLL
)
2952 schedule_packet_send(local
, sta
);
2957 /* Called only as a tasklet (software IRQ). Called for each RX frame to update
2958 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2959 int hostap_update_sta_ps(local_info_t
*local
, struct ieee80211_hdr
*hdr
)
2961 struct sta_info
*sta
;
2964 spin_lock(&local
->ap
->sta_table_lock
);
2965 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
2967 atomic_inc(&sta
->users
);
2968 spin_unlock(&local
->ap
->sta_table_lock
);
2973 fc
= le16_to_cpu(hdr
->frame_control
);
2974 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
2975 fc
& IEEE80211_FCTL_FTYPE
,
2976 fc
& IEEE80211_FCTL_STYPE
);
2978 atomic_dec(&sta
->users
);
2983 /* Called only as a tasklet (software IRQ). Called for each RX frame after
2984 * getting RX header and payload from hardware. */
2985 ap_rx_ret
hostap_handle_sta_rx(local_info_t
*local
, struct net_device
*dev
,
2986 struct sk_buff
*skb
,
2987 struct hostap_80211_rx_status
*rx_stats
,
2991 struct sta_info
*sta
;
2992 u16 fc
, type
, stype
;
2993 struct ieee80211_hdr
*hdr
;
2995 if (local
->ap
== NULL
)
2996 return AP_RX_CONTINUE
;
2998 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3000 fc
= le16_to_cpu(hdr
->frame_control
);
3001 type
= fc
& IEEE80211_FCTL_FTYPE
;
3002 stype
= fc
& IEEE80211_FCTL_STYPE
;
3004 spin_lock(&local
->ap
->sta_table_lock
);
3005 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
3007 atomic_inc(&sta
->users
);
3008 spin_unlock(&local
->ap
->sta_table_lock
);
3010 if (sta
&& !(sta
->flags
& WLAN_STA_AUTHORIZED
))
3011 ret
= AP_RX_CONTINUE_NOT_AUTHORIZED
;
3013 ret
= AP_RX_CONTINUE
;
3016 if (fc
& IEEE80211_FCTL_TODS
) {
3017 if (!wds
&& (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
))) {
3018 if (local
->hostapd
) {
3019 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
3020 PRISM2_RX_NON_ASSOC
);
3021 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3023 printk(KERN_DEBUG
"%s: dropped received packet"
3024 " from non-associated STA %pM"
3025 " (type=0x%02x, subtype=0x%02x)\n",
3026 dev
->name
, hdr
->addr2
,
3027 type
>> 2, stype
>> 4);
3028 hostap_rx(dev
, skb
, rx_stats
);
3029 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3034 } else if (fc
& IEEE80211_FCTL_FROMDS
) {
3036 /* FromDS frame - not for us; probably
3037 * broadcast/multicast in another BSS - drop */
3038 if (memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
3039 printk(KERN_DEBUG
"Odd.. FromDS packet "
3040 "received with own BSSID\n");
3041 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
3046 } else if (stype
== IEEE80211_STYPE_NULLFUNC
&& sta
== NULL
&&
3047 memcmp(hdr
->addr1
, dev
->dev_addr
, ETH_ALEN
) == 0) {
3049 if (local
->hostapd
) {
3050 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
3051 PRISM2_RX_NON_ASSOC
);
3052 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3054 /* At least Lucent f/w seems to send data::nullfunc
3055 * frames with no ToDS flag when the current AP returns
3056 * after being unavailable for some time. Speed up
3057 * re-association by informing the station about it not
3058 * being associated. */
3059 printk(KERN_DEBUG
"%s: rejected received nullfunc frame"
3060 " without ToDS from not associated STA %pM\n",
3061 dev
->name
, hdr
->addr2
);
3062 hostap_rx(dev
, skb
, rx_stats
);
3063 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3067 } else if (stype
== IEEE80211_STYPE_NULLFUNC
) {
3068 /* At least Lucent cards seem to send periodic nullfunc
3069 * frames with ToDS. Let these through to update SQ
3070 * stats and PS state. Nullfunc frames do not contain
3071 * any data and they will be dropped below. */
3073 /* If BSSID (Addr3) is foreign, this frame is a normal
3074 * broadcast frame from an IBSS network. Drop it silently.
3075 * If BSSID is own, report the dropping of this frame. */
3076 if (memcmp(hdr
->addr3
, dev
->dev_addr
, ETH_ALEN
) == 0) {
3077 printk(KERN_DEBUG
"%s: dropped received packet from %pM"
3078 " with no ToDS flag "
3079 "(type=0x%02x, subtype=0x%02x)\n", dev
->name
,
3080 hdr
->addr2
, type
>> 2, stype
>> 4);
3081 hostap_dump_rx_80211(dev
->name
, skb
, rx_stats
);
3088 hostap_update_sta_ps2(local
, sta
, fc
& IEEE80211_FCTL_PM
,
3092 sta
->rx_bytes
+= skb
->len
;
3093 sta
->last_rx
= jiffies
;
3096 if (local
->ap
->nullfunc_ack
&& stype
== IEEE80211_STYPE_NULLFUNC
&&
3097 fc
& IEEE80211_FCTL_TODS
) {
3098 if (local
->hostapd
) {
3099 prism2_rx_80211(local
->apdev
, skb
, rx_stats
,
3100 PRISM2_RX_NULLFUNC_ACK
);
3101 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3103 /* some STA f/w's seem to require control::ACK frame
3104 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3105 * from Compaq) does not send this.. Try to generate
3106 * ACK for these frames from the host driver to make
3107 * power saving work with, e.g., Lucent WaveLAN f/w */
3108 hostap_rx(dev
, skb
, rx_stats
);
3109 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3117 atomic_dec(&sta
->users
);
3123 /* Called only as a tasklet (software IRQ) */
3124 int hostap_handle_sta_crypto(local_info_t
*local
,
3125 struct ieee80211_hdr
*hdr
,
3126 struct lib80211_crypt_data
**crypt
,
3129 struct sta_info
*sta
;
3131 spin_lock(&local
->ap
->sta_table_lock
);
3132 sta
= ap_get_sta(local
->ap
, hdr
->addr2
);
3134 atomic_inc(&sta
->users
);
3135 spin_unlock(&local
->ap
->sta_table_lock
);
3141 *crypt
= sta
->crypt
;
3143 /* hostap_handle_sta_release() will be called to release STA
3146 atomic_dec(&sta
->users
);
3152 /* Called only as a tasklet (software IRQ) */
3153 int hostap_is_sta_assoc(struct ap_data
*ap
, u8
*sta_addr
)
3155 struct sta_info
*sta
;
3158 spin_lock(&ap
->sta_table_lock
);
3159 sta
= ap_get_sta(ap
, sta_addr
);
3160 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
)
3162 spin_unlock(&ap
->sta_table_lock
);
3168 /* Called only as a tasklet (software IRQ) */
3169 int hostap_is_sta_authorized(struct ap_data
*ap
, u8
*sta_addr
)
3171 struct sta_info
*sta
;
3174 spin_lock(&ap
->sta_table_lock
);
3175 sta
= ap_get_sta(ap
, sta_addr
);
3176 if (sta
!= NULL
&& (sta
->flags
& WLAN_STA_ASSOC
) && !sta
->ap
&&
3177 ((sta
->flags
& WLAN_STA_AUTHORIZED
) ||
3178 ap
->local
->ieee_802_1x
== 0))
3180 spin_unlock(&ap
->sta_table_lock
);
3186 /* Called only as a tasklet (software IRQ) */
3187 int hostap_add_sta(struct ap_data
*ap
, u8
*sta_addr
)
3189 struct sta_info
*sta
;
3195 spin_lock(&ap
->sta_table_lock
);
3196 sta
= ap_get_sta(ap
, sta_addr
);
3199 spin_unlock(&ap
->sta_table_lock
);
3202 sta
= ap_add_sta(ap
, sta_addr
);
3205 sta
->flags
= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
3207 memset(sta
->supported_rates
, 0, sizeof(sta
->supported_rates
));
3208 /* No way of knowing which rates are supported since we did not
3209 * get supported rates element from beacon/assoc req. Assume
3210 * that remote end supports all 802.11b rates. */
3211 sta
->supported_rates
[0] = 0x82;
3212 sta
->supported_rates
[1] = 0x84;
3213 sta
->supported_rates
[2] = 0x0b;
3214 sta
->supported_rates
[3] = 0x16;
3215 sta
->tx_supp_rates
= WLAN_RATE_1M
| WLAN_RATE_2M
|
3216 WLAN_RATE_5M5
| WLAN_RATE_11M
;
3218 sta
->tx_max_rate
= sta
->tx_rate_idx
= 3;
3225 /* Called only as a tasklet (software IRQ) */
3226 int hostap_update_rx_stats(struct ap_data
*ap
,
3227 struct ieee80211_hdr
*hdr
,
3228 struct hostap_80211_rx_status
*rx_stats
)
3230 struct sta_info
*sta
;
3235 spin_lock(&ap
->sta_table_lock
);
3236 sta
= ap_get_sta(ap
, hdr
->addr2
);
3238 sta
->last_rx_silence
= rx_stats
->noise
;
3239 sta
->last_rx_signal
= rx_stats
->signal
;
3240 sta
->last_rx_rate
= rx_stats
->rate
;
3241 sta
->last_rx_updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
3242 if (rx_stats
->rate
== 10)
3244 else if (rx_stats
->rate
== 20)
3246 else if (rx_stats
->rate
== 55)
3248 else if (rx_stats
->rate
== 110)
3251 spin_unlock(&ap
->sta_table_lock
);
3253 return sta
? 0 : -1;
3257 void hostap_update_rates(local_info_t
*local
)
3259 struct sta_info
*sta
;
3260 struct ap_data
*ap
= local
->ap
;
3265 spin_lock_bh(&ap
->sta_table_lock
);
3266 list_for_each_entry(sta
, &ap
->sta_list
, list
) {
3267 prism2_check_tx_rates(sta
);
3269 spin_unlock_bh(&ap
->sta_table_lock
);
3273 void * ap_crypt_get_ptrs(struct ap_data
*ap
, u8
*addr
, int permanent
,
3274 struct lib80211_crypt_data
***crypt
)
3276 struct sta_info
*sta
;
3278 spin_lock_bh(&ap
->sta_table_lock
);
3279 sta
= ap_get_sta(ap
, addr
);
3281 atomic_inc(&sta
->users
);
3282 spin_unlock_bh(&ap
->sta_table_lock
);
3284 if (!sta
&& permanent
)
3285 sta
= ap_add_sta(ap
, addr
);
3291 sta
->flags
|= WLAN_STA_PERM
;
3293 *crypt
= &sta
->crypt
;
3299 void hostap_add_wds_links(local_info_t
*local
)
3301 struct ap_data
*ap
= local
->ap
;
3302 struct sta_info
*sta
;
3304 spin_lock_bh(&ap
->sta_table_lock
);
3305 list_for_each_entry(sta
, &ap
->sta_list
, list
) {
3307 hostap_wds_link_oper(local
, sta
->addr
, WDS_ADD
);
3309 spin_unlock_bh(&ap
->sta_table_lock
);
3311 schedule_work(&local
->ap
->wds_oper_queue
);
3315 void hostap_wds_link_oper(local_info_t
*local
, u8
*addr
, wds_oper_type type
)
3317 struct wds_oper_data
*entry
;
3319 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
3322 memcpy(entry
->addr
, addr
, ETH_ALEN
);
3324 spin_lock_bh(&local
->lock
);
3325 entry
->next
= local
->ap
->wds_oper_entries
;
3326 local
->ap
->wds_oper_entries
= entry
;
3327 spin_unlock_bh(&local
->lock
);
3329 schedule_work(&local
->ap
->wds_oper_queue
);
3333 EXPORT_SYMBOL(hostap_init_data
);
3334 EXPORT_SYMBOL(hostap_init_ap_proc
);
3335 EXPORT_SYMBOL(hostap_free_data
);
3336 EXPORT_SYMBOL(hostap_check_sta_fw_version
);
3337 EXPORT_SYMBOL(hostap_handle_sta_tx_exc
);
3338 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3339 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */