blob: cb3c25f0c190a4b168eb65f9ee0d8ec52d4e692e [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001/*
2 * Intersil Prism2 driver with Host AP (software access point) support
3 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
Jouni Malinen85d32e72007-03-24 17:15:30 -07004 * <j@w1.fi>
5 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
Jouni Malinenff1d2762005-05-12 22:54:16 -04006 *
7 * This file is to be included into hostap.c when S/W AP functionality is
8 * compiled.
9 *
10 * AP: FIX:
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
16 * (8802.11: 5.5)
17 */
18
Adrian Bunk5fad5a22006-01-14 03:09:34 +010019#include <linux/proc_fs.h>
20#include <linux/delay.h>
21#include <linux/random.h>
Dan Williams1ea893f2009-02-11 17:17:10 -050022#include <linux/if_arp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Adrian Bunk5fad5a22006-01-14 03:09:34 +010024
25#include "hostap_wlan.h"
26#include "hostap.h"
27#include "hostap_ap.h"
28
Jouni Malinenff1d2762005-05-12 22:54:16 -040029static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
30 DEF_INTS };
31module_param_array(other_ap_policy, int, NULL, 0444);
32MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
33
34static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
35 DEF_INTS };
36module_param_array(ap_max_inactivity, int, NULL, 0444);
37MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
38 "inactivity");
39
40static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
41module_param_array(ap_bridge_packets, int, NULL, 0444);
42MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
43 "stations");
44
45static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
46module_param_array(autom_ap_wds, int, NULL, 0444);
47MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
48 "automatically");
49
50
51static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
52static void hostap_event_expired_sta(struct net_device *dev,
53 struct sta_info *sta);
David Howellsc4028952006-11-22 14:57:56 +000054static void handle_add_proc_queue(struct work_struct *work);
Jouni Malinenff1d2762005-05-12 22:54:16 -040055
56#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
David Howellsc4028952006-11-22 14:57:56 +000057static void handle_wds_oper_queue(struct work_struct *work);
Jouni Malinenff1d2762005-05-12 22:54:16 -040058static void prism2_send_mgmt(struct net_device *dev,
Jouni Malinen4339d322005-08-14 19:08:44 -070059 u16 type_subtype, char *body,
Jouni Malinenff1d2762005-05-12 22:54:16 -040060 int body_len, u8 *addr, u16 tx_cb_idx);
61#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
62
63
64#ifndef PRISM2_NO_PROCFS_DEBUG
65static int ap_debug_proc_read(char *page, char **start, off_t off,
66 int count, int *eof, void *data)
67{
68 char *p = page;
69 struct ap_data *ap = (struct ap_data *) data;
70
71 if (off != 0) {
72 *eof = 1;
73 return 0;
74 }
75
76 p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
77 p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
78 p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
79 p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
80 p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
81 p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
82 p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
83 p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
84
85 return (p - page);
86}
87#endif /* PRISM2_NO_PROCFS_DEBUG */
88
89
90static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
91{
92 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
93 ap->sta_hash[STA_HASH(sta->addr)] = sta;
94}
95
96static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
97{
98 struct sta_info *s;
99
100 s = ap->sta_hash[STA_HASH(sta->addr)];
101 if (s == NULL) return;
102 if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
103 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
104 return;
105 }
106
107 while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
108 != 0)
109 s = s->hnext;
110 if (s->hnext != NULL)
111 s->hnext = s->hnext->hnext;
112 else
Johannes Berge1749612008-10-27 15:59:26 -0700113 printk("AP: could not remove STA %pM from hash table\n",
114 sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400115}
116
117static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
118{
119 if (sta->ap && sta->local)
120 hostap_event_expired_sta(sta->local->dev, sta);
121
122 if (ap->proc != NULL) {
123 char name[20];
Johannes Berge1749612008-10-27 15:59:26 -0700124 sprintf(name, "%pM", sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400125 remove_proc_entry(name, ap->proc);
126 }
127
128 if (sta->crypt) {
129 sta->crypt->ops->deinit(sta->crypt->priv);
130 kfree(sta->crypt);
131 sta->crypt = NULL;
132 }
133
134 skb_queue_purge(&sta->tx_buf);
135
136 ap->num_sta--;
137#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
138 if (sta->aid > 0)
139 ap->sta_aid[sta->aid - 1] = NULL;
140
141 if (!sta->ap && sta->u.sta.challenge)
142 kfree(sta->u.sta.challenge);
143 del_timer(&sta->timer);
144#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
145
146 kfree(sta);
147}
148
149
150static void hostap_set_tim(local_info_t *local, int aid, int set)
151{
152 if (local->func->set_tim)
153 local->func->set_tim(local->dev, aid, set);
154}
155
156
157static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
158{
159 union iwreq_data wrqu;
160 memset(&wrqu, 0, sizeof(wrqu));
161 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
162 wrqu.addr.sa_family = ARPHRD_ETHER;
163 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
164}
165
166
167static void hostap_event_expired_sta(struct net_device *dev,
168 struct sta_info *sta)
169{
170 union iwreq_data wrqu;
171 memset(&wrqu, 0, sizeof(wrqu));
172 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
173 wrqu.addr.sa_family = ARPHRD_ETHER;
174 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
175}
176
177
178#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
179
180static void ap_handle_timer(unsigned long data)
181{
182 struct sta_info *sta = (struct sta_info *) data;
183 local_info_t *local;
184 struct ap_data *ap;
185 unsigned long next_time = 0;
186 int was_assoc;
187
188 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
189 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
190 return;
191 }
192
193 local = sta->local;
194 ap = local->ap;
195 was_assoc = sta->flags & WLAN_STA_ASSOC;
196
197 if (atomic_read(&sta->users) != 0)
198 next_time = jiffies + HZ;
199 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
200 next_time = jiffies + ap->max_inactivity;
201
202 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
203 /* station activity detected; reset timeout state */
204 sta->timeout_next = STA_NULLFUNC;
205 next_time = sta->last_rx + ap->max_inactivity;
206 } else if (sta->timeout_next == STA_DISASSOC &&
207 !(sta->flags & WLAN_STA_PENDING_POLL)) {
208 /* STA ACKed data nullfunc frame poll */
209 sta->timeout_next = STA_NULLFUNC;
210 next_time = jiffies + ap->max_inactivity;
211 }
212
213 if (next_time) {
214 sta->timer.expires = next_time;
215 add_timer(&sta->timer);
216 return;
217 }
218
219 if (sta->ap)
220 sta->timeout_next = STA_DEAUTH;
221
222 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
223 spin_lock(&ap->sta_table_lock);
224 ap_sta_hash_del(ap, sta);
225 list_del(&sta->list);
226 spin_unlock(&ap->sta_table_lock);
227 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
228 } else if (sta->timeout_next == STA_DISASSOC)
229 sta->flags &= ~WLAN_STA_ASSOC;
230
231 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
232 hostap_event_expired_sta(local->dev, sta);
233
234 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
235 !skb_queue_empty(&sta->tx_buf)) {
236 hostap_set_tim(local, sta->aid, 0);
237 sta->flags &= ~WLAN_STA_TIM;
238 }
239
240 if (sta->ap) {
241 if (ap->autom_ap_wds) {
242 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
Johannes Berge1749612008-10-27 15:59:26 -0700243 "connection to AP %pM\n",
244 local->dev->name, sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400245 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
246 }
247 } else if (sta->timeout_next == STA_NULLFUNC) {
248 /* send data frame to poll STA and check whether this frame
249 * is ACKed */
Jouni Malinen4339d322005-08-14 19:08:44 -0700250 /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
Jouni Malinenff1d2762005-05-12 22:54:16 -0400251 * it is apparently not retried so TX Exc events are not
252 * received for it */
253 sta->flags |= WLAN_STA_PENDING_POLL;
Jouni Malinen4339d322005-08-14 19:08:44 -0700254 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
255 IEEE80211_STYPE_DATA, NULL, 0,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400256 sta->addr, ap->tx_callback_poll);
257 } else {
258 int deauth = sta->timeout_next == STA_DEAUTH;
Al Viro8a9faf32007-12-21 03:30:16 -0500259 __le16 resp;
Johannes Berge1749612008-10-27 15:59:26 -0700260 PDEBUG(DEBUG_AP, "%s: sending %s info to STA %pM"
Jouni Malinenff1d2762005-05-12 22:54:16 -0400261 "(last=%lu, jiffies=%lu)\n",
262 local->dev->name,
263 deauth ? "deauthentication" : "disassociation",
Johannes Berge1749612008-10-27 15:59:26 -0700264 sta->addr, sta->last_rx, jiffies);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400265
266 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
267 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Jouni Malinen4339d322005-08-14 19:08:44 -0700268 prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
269 (deauth ? IEEE80211_STYPE_DEAUTH :
270 IEEE80211_STYPE_DISASSOC),
Jouni Malinenff1d2762005-05-12 22:54:16 -0400271 (char *) &resp, 2, sta->addr, 0);
272 }
273
274 if (sta->timeout_next == STA_DEAUTH) {
275 if (sta->flags & WLAN_STA_PERM) {
Johannes Berge1749612008-10-27 15:59:26 -0700276 PDEBUG(DEBUG_AP, "%s: STA %pM"
Joe Perches0795af52007-10-03 17:59:30 -0700277 " would have been removed, "
278 "but it has 'perm' flag\n",
Johannes Berge1749612008-10-27 15:59:26 -0700279 local->dev->name, sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400280 } else
281 ap_free_sta(ap, sta);
282 return;
283 }
284
285 if (sta->timeout_next == STA_NULLFUNC) {
286 sta->timeout_next = STA_DISASSOC;
287 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
288 } else {
289 sta->timeout_next = STA_DEAUTH;
290 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
291 }
292
293 add_timer(&sta->timer);
294}
295
296
297void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
298 int resend)
299{
300 u8 addr[ETH_ALEN];
Al Viro8a9faf32007-12-21 03:30:16 -0500301 __le16 resp;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400302 int i;
303
304 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
305 memset(addr, 0xff, ETH_ALEN);
306
Al Viro8a9faf32007-12-21 03:30:16 -0500307 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400308
309 /* deauth message sent; try to resend it few times; the message is
310 * broadcast, so it may be delayed until next DTIM; there is not much
311 * else we can do at this point since the driver is going to be shut
312 * down */
313 for (i = 0; i < 5; i++) {
Jouni Malinen4339d322005-08-14 19:08:44 -0700314 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
315 IEEE80211_STYPE_DEAUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400316 (char *) &resp, 2, addr, 0);
317
318 if (!resend || ap->num_sta <= 0)
319 return;
320
321 mdelay(50);
322 }
323}
324
325
326static int ap_control_proc_read(char *page, char **start, off_t off,
327 int count, int *eof, void *data)
328{
329 char *p = page;
330 struct ap_data *ap = (struct ap_data *) data;
331 char *policy_txt;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400332 struct mac_entry *entry;
333
334 if (off != 0) {
335 *eof = 1;
336 return 0;
337 }
338
339 switch (ap->mac_restrictions.policy) {
340 case MAC_POLICY_OPEN:
341 policy_txt = "open";
342 break;
343 case MAC_POLICY_ALLOW:
344 policy_txt = "allow";
345 break;
346 case MAC_POLICY_DENY:
347 policy_txt = "deny";
348 break;
349 default:
350 policy_txt = "unknown";
351 break;
Joe Perchesee289b62010-05-17 22:47:34 -0700352 }
Jouni Malinenff1d2762005-05-12 22:54:16 -0400353 p += sprintf(p, "MAC policy: %s\n", policy_txt);
354 p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
355 p += sprintf(p, "MAC list:\n");
356 spin_lock_bh(&ap->mac_restrictions.lock);
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700357 list_for_each_entry(entry, &ap->mac_restrictions.mac_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400358 if (p - page > PAGE_SIZE - 80) {
359 p += sprintf(p, "All entries did not fit one page.\n");
360 break;
361 }
362
Johannes Berge1749612008-10-27 15:59:26 -0700363 p += sprintf(p, "%pM\n", entry->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400364 }
365 spin_unlock_bh(&ap->mac_restrictions.lock);
366
367 return (p - page);
368}
369
370
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100371int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400372{
373 struct mac_entry *entry;
374
375 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
376 if (entry == NULL)
377 return -1;
378
379 memcpy(entry->addr, mac, ETH_ALEN);
380
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);
385
386 return 0;
387}
388
389
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100390int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400391{
392 struct list_head *ptr;
393 struct mac_entry *entry;
394
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);
399
400 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
401 list_del(ptr);
402 kfree(entry);
403 mac_restrictions->entries--;
404 spin_unlock_bh(&mac_restrictions->lock);
405 return 0;
406 }
407 }
408 spin_unlock_bh(&mac_restrictions->lock);
409 return -1;
410}
411
412
413static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
414 u8 *mac)
415{
Jouni Malinenff1d2762005-05-12 22:54:16 -0400416 struct mac_entry *entry;
417 int found = 0;
418
419 if (mac_restrictions->policy == MAC_POLICY_OPEN)
420 return 0;
421
422 spin_lock_bh(&mac_restrictions->lock);
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700423 list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400424 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
425 found = 1;
426 break;
427 }
428 }
429 spin_unlock_bh(&mac_restrictions->lock);
430
431 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
432 return !found;
433 else
434 return found;
435}
436
437
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100438void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400439{
440 struct list_head *ptr, *n;
441 struct mac_entry *entry;
442
443 if (mac_restrictions->entries == 0)
444 return;
445
446 spin_lock_bh(&mac_restrictions->lock);
447 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
448 ptr != &mac_restrictions->mac_list;
449 ptr = n, n = ptr->next) {
450 entry = list_entry(ptr, struct mac_entry, list);
451 list_del(ptr);
452 kfree(entry);
453 }
454 mac_restrictions->entries = 0;
455 spin_unlock_bh(&mac_restrictions->lock);
456}
457
458
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100459int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400460{
461 struct sta_info *sta;
Al Viro8a9faf32007-12-21 03:30:16 -0500462 __le16 resp;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400463
464 spin_lock_bh(&ap->sta_table_lock);
465 sta = ap_get_sta(ap, mac);
466 if (sta) {
467 ap_sta_hash_del(ap, sta);
468 list_del(&sta->list);
469 }
470 spin_unlock_bh(&ap->sta_table_lock);
471
472 if (!sta)
473 return -EINVAL;
474
475 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
Jouni Malinen4339d322005-08-14 19:08:44 -0700476 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400477 (char *) &resp, 2, sta->addr, 0);
478
479 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
480 hostap_event_expired_sta(dev, sta);
481
482 ap_free_sta(ap, sta);
483
484 return 0;
485}
486
487#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
488
489
Adrian Bunk5fad5a22006-01-14 03:09:34 +0100490void ap_control_kickall(struct ap_data *ap)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400491{
492 struct list_head *ptr, *n;
493 struct sta_info *sta;
Jeff Garzik74fae822005-07-31 13:08:32 -0400494
Jouni Malinenff1d2762005-05-12 22:54:16 -0400495 spin_lock_bh(&ap->sta_table_lock);
496 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
497 ptr = n, n = ptr->next) {
498 sta = list_entry(ptr, struct sta_info, list);
499 ap_sta_hash_del(ap, sta);
500 list_del(&sta->list);
501 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
502 hostap_event_expired_sta(sta->local->dev, sta);
503 ap_free_sta(ap, sta);
504 }
505 spin_unlock_bh(&ap->sta_table_lock);
506}
507
508
509#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
510
511#define PROC_LIMIT (PAGE_SIZE - 80)
512
513static int prism2_ap_proc_read(char *page, char **start, off_t off,
514 int count, int *eof, void *data)
515{
516 char *p = page;
517 struct ap_data *ap = (struct ap_data *) data;
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700518 struct sta_info *sta;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400519 int i;
520
521 if (off > PROC_LIMIT) {
522 *eof = 1;
523 return 0;
524 }
525
526 p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
527 spin_lock_bh(&ap->sta_table_lock);
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700528 list_for_each_entry(sta, &ap->sta_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400529 if (!sta->ap)
530 continue;
531
Johannes Berge1749612008-10-27 15:59:26 -0700532 p += sprintf(p, "%pM %d %d %d %d '",
533 sta->addr,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400534 sta->u.ap.channel, sta->last_rx_signal,
535 sta->last_rx_silence, sta->last_rx_rate);
536 for (i = 0; i < sta->u.ap.ssid_len; i++)
537 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
538 sta->u.ap.ssid[i] < 127) ?
539 "%c" : "<%02x>"),
540 sta->u.ap.ssid[i]);
541 p += sprintf(p, "'");
542 if (sta->capability & WLAN_CAPABILITY_ESS)
543 p += sprintf(p, " [ESS]");
544 if (sta->capability & WLAN_CAPABILITY_IBSS)
545 p += sprintf(p, " [IBSS]");
546 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
547 p += sprintf(p, " [WEP]");
548 p += sprintf(p, "\n");
549
550 if ((p - page) > PROC_LIMIT) {
551 printk(KERN_DEBUG "hostap: ap proc did not fit\n");
552 break;
553 }
554 }
555 spin_unlock_bh(&ap->sta_table_lock);
556
557 if ((p - page) <= off) {
558 *eof = 1;
559 return 0;
560 }
561
562 *start = page + off;
563
564 return (p - page - off);
565}
566#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
567
568
569void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
570{
571 if (!ap)
572 return;
573
574 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
575 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
576 "firmware upgrade recommended\n");
577 ap->nullfunc_ack = 1;
578 } else
579 ap->nullfunc_ack = 0;
580
581 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
582 printk(KERN_WARNING "%s: Warning: secondary station firmware "
583 "version 1.4.2 does not seem to work in Host AP mode\n",
584 ap->local->dev->name);
585 }
586}
587
588
589/* Called only as a tasklet (software IRQ) */
590static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
591{
592 struct ap_data *ap = data;
Dan Williams1ea893f2009-02-11 17:17:10 -0500593 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400594
595 if (!ap->local->hostapd || !ap->local->apdev) {
596 dev_kfree_skb(skb);
597 return;
598 }
599
Jouni Malinenff1d2762005-05-12 22:54:16 -0400600 /* Pass the TX callback frame to the hostapd; use 802.11 header version
601 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
602
Dan Williams1ea893f2009-02-11 17:17:10 -0500603 hdr = (struct ieee80211_hdr *) skb->data;
604 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_VERS);
605 hdr->frame_control |= cpu_to_le16(ok ? BIT(1) : BIT(0));
Jouni Malinenff1d2762005-05-12 22:54:16 -0400606
607 skb->dev = ap->local->apdev;
Dan Williams1ea893f2009-02-11 17:17:10 -0500608 skb_pull(skb, hostap_80211_get_hdrlen(hdr->frame_control));
Jouni Malinenff1d2762005-05-12 22:54:16 -0400609 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800610 skb->protocol = cpu_to_be16(ETH_P_802_2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400611 memset(skb->cb, 0, sizeof(skb->cb));
612 netif_rx(skb);
613}
614
615
616#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
617/* Called only as a tasklet (software IRQ) */
618static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
619{
620 struct ap_data *ap = data;
621 struct net_device *dev = ap->local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -0500622 struct ieee80211_hdr *hdr;
623 u16 auth_alg, auth_transaction, status;
Al Viro8a9faf32007-12-21 03:30:16 -0500624 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400625 struct sta_info *sta = NULL;
626 char *txt = NULL;
627
628 if (ap->local->hostapd) {
629 dev_kfree_skb(skb);
630 return;
631 }
632
Dan Williams1ea893f2009-02-11 17:17:10 -0500633 hdr = (struct ieee80211_hdr *) skb->data;
634 if (!ieee80211_is_auth(hdr->frame_control) ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400635 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
636 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
637 "frame\n", dev->name);
638 dev_kfree_skb(skb);
639 return;
640 }
641
Al Viro8a9faf32007-12-21 03:30:16 -0500642 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400643 auth_alg = le16_to_cpu(*pos++);
644 auth_transaction = le16_to_cpu(*pos++);
645 status = le16_to_cpu(*pos++);
646
647 if (!ok) {
648 txt = "frame was not ACKed";
649 goto done;
650 }
651
652 spin_lock(&ap->sta_table_lock);
653 sta = ap_get_sta(ap, hdr->addr1);
654 if (sta)
655 atomic_inc(&sta->users);
656 spin_unlock(&ap->sta_table_lock);
657
658 if (!sta) {
659 txt = "STA not found";
660 goto done;
661 }
662
663 if (status == WLAN_STATUS_SUCCESS &&
664 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
665 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
666 txt = "STA authenticated";
667 sta->flags |= WLAN_STA_AUTH;
668 sta->last_auth = jiffies;
669 } else if (status != WLAN_STATUS_SUCCESS)
670 txt = "authentication failed";
671
672 done:
673 if (sta)
674 atomic_dec(&sta->users);
675 if (txt) {
Johannes Berge1749612008-10-27 15:59:26 -0700676 PDEBUG(DEBUG_AP, "%s: %pM auth_cb - alg=%d "
Joe Perches0795af52007-10-03 17:59:30 -0700677 "trans#=%d status=%d - %s\n",
Johannes Berge1749612008-10-27 15:59:26 -0700678 dev->name, hdr->addr1,
David S. Miller21f644f2008-04-08 16:50:44 -0700679 auth_alg, auth_transaction, status, txt);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400680 }
681 dev_kfree_skb(skb);
682}
683
684
685/* Called only as a tasklet (software IRQ) */
686static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
687{
688 struct ap_data *ap = data;
689 struct net_device *dev = ap->local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -0500690 struct ieee80211_hdr *hdr;
Al Viro8a9faf32007-12-21 03:30:16 -0500691 u16 fc, status;
692 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400693 struct sta_info *sta = NULL;
694 char *txt = NULL;
695
696 if (ap->local->hostapd) {
697 dev_kfree_skb(skb);
698 return;
699 }
700
Dan Williams1ea893f2009-02-11 17:17:10 -0500701 hdr = (struct ieee80211_hdr *) skb->data;
702 fc = le16_to_cpu(hdr->frame_control);
703 if ((!ieee80211_is_assoc_resp(hdr->frame_control) &&
704 !ieee80211_is_reassoc_resp(hdr->frame_control)) ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400705 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
706 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
707 "frame\n", dev->name);
708 dev_kfree_skb(skb);
709 return;
710 }
711
712 if (!ok) {
713 txt = "frame was not ACKed";
714 goto done;
715 }
716
717 spin_lock(&ap->sta_table_lock);
718 sta = ap_get_sta(ap, hdr->addr1);
719 if (sta)
720 atomic_inc(&sta->users);
721 spin_unlock(&ap->sta_table_lock);
722
723 if (!sta) {
724 txt = "STA not found";
725 goto done;
726 }
727
Al Viro8a9faf32007-12-21 03:30:16 -0500728 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400729 pos++;
730 status = le16_to_cpu(*pos++);
731 if (status == WLAN_STATUS_SUCCESS) {
732 if (!(sta->flags & WLAN_STA_ASSOC))
733 hostap_event_new_sta(dev, sta);
734 txt = "STA associated";
735 sta->flags |= WLAN_STA_ASSOC;
736 sta->last_assoc = jiffies;
737 } else
738 txt = "association failed";
739
740 done:
741 if (sta)
742 atomic_dec(&sta->users);
743 if (txt) {
Johannes Berge1749612008-10-27 15:59:26 -0700744 PDEBUG(DEBUG_AP, "%s: %pM assoc_cb - %s\n",
745 dev->name, hdr->addr1, txt);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400746 }
747 dev_kfree_skb(skb);
748}
749
750/* Called only as a tasklet (software IRQ); TX callback for poll frames used
751 * in verifying whether the STA is still present. */
752static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
753{
754 struct ap_data *ap = data;
Dan Williams1ea893f2009-02-11 17:17:10 -0500755 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400756 struct sta_info *sta;
757
758 if (skb->len < 24)
759 goto fail;
Dan Williams1ea893f2009-02-11 17:17:10 -0500760 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400761 if (ok) {
762 spin_lock(&ap->sta_table_lock);
763 sta = ap_get_sta(ap, hdr->addr1);
764 if (sta)
765 sta->flags &= ~WLAN_STA_PENDING_POLL;
766 spin_unlock(&ap->sta_table_lock);
767 } else {
Johannes Berge1749612008-10-27 15:59:26 -0700768 PDEBUG(DEBUG_AP,
769 "%s: STA %pM did not ACK activity poll frame\n",
770 ap->local->dev->name, hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400771 }
772
773 fail:
774 dev_kfree_skb(skb);
775}
776#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
777
778
779void hostap_init_data(local_info_t *local)
780{
781 struct ap_data *ap = local->ap;
782
783 if (ap == NULL) {
784 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
785 return;
786 }
787 memset(ap, 0, sizeof(struct ap_data));
788 ap->local = local;
789
790 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
791 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
792 ap->max_inactivity =
793 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
794 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
795
796 spin_lock_init(&ap->sta_table_lock);
797 INIT_LIST_HEAD(&ap->sta_list);
798
799 /* Initialize task queue structure for AP management */
David Howellsc4028952006-11-22 14:57:56 +0000800 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400801
802 ap->tx_callback_idx =
803 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
804 if (ap->tx_callback_idx == 0)
805 printk(KERN_WARNING "%s: failed to register TX callback for "
806 "AP\n", local->dev->name);
807#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
David Howellsc4028952006-11-22 14:57:56 +0000808 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400809
810 ap->tx_callback_auth =
811 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
812 ap->tx_callback_assoc =
813 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
814 ap->tx_callback_poll =
815 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
816 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
817 ap->tx_callback_poll == 0)
818 printk(KERN_WARNING "%s: failed to register TX callback for "
819 "AP\n", local->dev->name);
820
821 spin_lock_init(&ap->mac_restrictions.lock);
822 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
823#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
824
825 ap->initialized = 1;
826}
827
828
829void hostap_init_ap_proc(local_info_t *local)
830{
831 struct ap_data *ap = local->ap;
832
833 ap->proc = local->proc;
834 if (ap->proc == NULL)
835 return;
836
837#ifndef PRISM2_NO_PROCFS_DEBUG
838 create_proc_read_entry("ap_debug", 0, ap->proc,
839 ap_debug_proc_read, ap);
840#endif /* PRISM2_NO_PROCFS_DEBUG */
841
842#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
843 create_proc_read_entry("ap_control", 0, ap->proc,
844 ap_control_proc_read, ap);
845 create_proc_read_entry("ap", 0, ap->proc,
846 prism2_ap_proc_read, ap);
847#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
848
849}
850
851
852void hostap_free_data(struct ap_data *ap)
853{
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700854 struct sta_info *n, *sta;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400855
856 if (ap == NULL || !ap->initialized) {
857 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
858 "initialized - skip resource freeing\n");
859 return;
860 }
861
862#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
863 if (ap->crypt)
864 ap->crypt->deinit(ap->crypt_priv);
865 ap->crypt = ap->crypt_priv = NULL;
866#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
867
Matthias Kaehlckec1505732007-05-28 09:38:48 -0700868 list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400869 ap_sta_hash_del(ap, sta);
870 list_del(&sta->list);
871 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
872 hostap_event_expired_sta(sta->local->dev, sta);
873 ap_free_sta(ap, sta);
874 }
875
876#ifndef PRISM2_NO_PROCFS_DEBUG
877 if (ap->proc != NULL) {
878 remove_proc_entry("ap_debug", ap->proc);
879 }
880#endif /* PRISM2_NO_PROCFS_DEBUG */
881
882#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
883 if (ap->proc != NULL) {
884 remove_proc_entry("ap", ap->proc);
885 remove_proc_entry("ap_control", ap->proc);
886 }
887 ap_control_flush_macs(&ap->mac_restrictions);
888#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
889
890 ap->initialized = 0;
891}
892
893
894/* caller should have mutex for AP STA list handling */
895static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
896{
897 struct sta_info *s;
898
899 s = ap->sta_hash[STA_HASH(sta)];
900 while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
901 s = s->hnext;
902 return s;
903}
904
905
906#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
907
908/* Called from timer handler and from scheduled AP queue handlers */
909static void prism2_send_mgmt(struct net_device *dev,
Jouni Malinen4339d322005-08-14 19:08:44 -0700910 u16 type_subtype, char *body,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400911 int body_len, u8 *addr, u16 tx_cb_idx)
912{
913 struct hostap_interface *iface;
914 local_info_t *local;
Dan Williams1ea893f2009-02-11 17:17:10 -0500915 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400916 u16 fc;
917 struct sk_buff *skb;
918 struct hostap_skb_tx_data *meta;
919 int hdrlen;
920
921 iface = netdev_priv(dev);
922 local = iface->local;
923 dev = local->dev; /* always use master radio device */
924 iface = netdev_priv(dev);
925
926 if (!(dev->flags & IFF_UP)) {
927 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
928 "cannot send frame\n", dev->name);
929 return;
930 }
931
932 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
933 if (skb == NULL) {
934 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
935 "skb\n", dev->name);
936 return;
937 }
938
Jouni Malinen4339d322005-08-14 19:08:44 -0700939 fc = type_subtype;
Dan Williams1ea893f2009-02-11 17:17:10 -0500940 hdrlen = hostap_80211_get_hdrlen(cpu_to_le16(type_subtype));
941 hdr = (struct ieee80211_hdr *) skb_put(skb, hdrlen);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400942 if (body)
943 memcpy(skb_put(skb, body_len), body, body_len);
944
945 memset(hdr, 0, hdrlen);
946
947 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
948 * tx_control instead of using local->tx_control */
949
950
951 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
Dan Williams1ea893f2009-02-11 17:17:10 -0500952 if (ieee80211_is_data(hdr->frame_control)) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700953 fc |= IEEE80211_FCTL_FROMDS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400954 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
955 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
Dan Williams1ea893f2009-02-11 17:17:10 -0500956 } else if (ieee80211_is_ctl(hdr->frame_control)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400957 /* control:ACK does not have addr2 or addr3 */
958 memset(hdr->addr2, 0, ETH_ALEN);
959 memset(hdr->addr3, 0, ETH_ALEN);
960 } else {
961 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
962 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
963 }
964
Dan Williams1ea893f2009-02-11 17:17:10 -0500965 hdr->frame_control = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400966
967 meta = (struct hostap_skb_tx_data *) skb->cb;
968 memset(meta, 0, sizeof(*meta));
969 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
970 meta->iface = iface;
971 meta->tx_cb_idx = tx_cb_idx;
972
973 skb->dev = dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700974 skb_reset_mac_header(skb);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700975 skb_reset_network_header(skb);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400976 dev_queue_xmit(skb);
977}
978#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
979
980
981static int prism2_sta_proc_read(char *page, char **start, off_t off,
982 int count, int *eof, void *data)
983{
984 char *p = page;
985 struct sta_info *sta = (struct sta_info *) data;
986 int i;
987
988 /* FIX: possible race condition.. the STA data could have just expired,
989 * but proc entry was still here so that the read could have started;
990 * some locking should be done here.. */
991
992 if (off != 0) {
993 *eof = 1;
994 return 0;
995 }
996
Johannes Berge1749612008-10-27 15:59:26 -0700997 p += sprintf(p, "%s=%pM\nusers=%d\naid=%d\n"
Jouni Malinenff1d2762005-05-12 22:54:16 -0400998 "flags=0x%04x%s%s%s%s%s%s%s\n"
999 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1000 sta->ap ? "AP" : "STA",
Johannes Berge1749612008-10-27 15:59:26 -07001001 sta->addr, atomic_read(&sta->users), sta->aid,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001002 sta->flags,
1003 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1004 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1005 sta->flags & WLAN_STA_PS ? " PS" : "",
1006 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1007 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1008 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1009 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1010 sta->capability, sta->listen_interval);
1011 /* supported_rates: 500 kbit/s units with msb ignored */
1012 for (i = 0; i < sizeof(sta->supported_rates); i++)
1013 if (sta->supported_rates[i] != 0)
1014 p += sprintf(p, "%d%sMbps ",
1015 (sta->supported_rates[i] & 0x7f) / 2,
1016 sta->supported_rates[i] & 1 ? ".5" : "");
1017 p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1018 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1019 "tx_packets=%lu\n"
1020 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1021 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1022 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1023 "tx[11M]=%d\n"
1024 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1025 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1026 sta->last_tx,
1027 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1028 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1029 sta->last_rx_silence,
1030 sta->last_rx_signal, sta->last_rx_rate / 10,
1031 sta->last_rx_rate % 10 ? ".5" : "",
1032 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1033 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1034 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1035 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1036 p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
1037#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1038 if (sta->ap) {
1039 if (sta->u.ap.channel >= 0)
1040 p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
1041 p += sprintf(p, "ssid=");
1042 for (i = 0; i < sta->u.ap.ssid_len; i++)
1043 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
1044 sta->u.ap.ssid[i] < 127) ?
1045 "%c" : "<%02x>"),
1046 sta->u.ap.ssid[i]);
1047 p += sprintf(p, "\n");
1048 }
1049#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1050
1051 return (p - page);
1052}
1053
1054
David Howellsc4028952006-11-22 14:57:56 +00001055static void handle_add_proc_queue(struct work_struct *work)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001056{
David Howellsc4028952006-11-22 14:57:56 +00001057 struct ap_data *ap = container_of(work, struct ap_data,
1058 add_sta_proc_queue);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001059 struct sta_info *sta;
1060 char name[20];
1061 struct add_sta_proc_data *entry, *prev;
1062
1063 entry = ap->add_sta_proc_entries;
1064 ap->add_sta_proc_entries = NULL;
1065
1066 while (entry) {
1067 spin_lock_bh(&ap->sta_table_lock);
1068 sta = ap_get_sta(ap, entry->addr);
1069 if (sta)
1070 atomic_inc(&sta->users);
1071 spin_unlock_bh(&ap->sta_table_lock);
1072
1073 if (sta) {
Johannes Berge1749612008-10-27 15:59:26 -07001074 sprintf(name, "%pM", sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001075 sta->proc = create_proc_read_entry(
1076 name, 0, ap->proc,
1077 prism2_sta_proc_read, sta);
1078
1079 atomic_dec(&sta->users);
1080 }
1081
1082 prev = entry;
1083 entry = entry->next;
1084 kfree(prev);
1085 }
1086}
1087
1088
1089static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1090{
1091 struct sta_info *sta;
1092
Yan Burmanb0471bb72006-12-02 13:33:40 +02001093 sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001094 if (sta == NULL) {
1095 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1096 return NULL;
1097 }
1098
1099 /* initialize STA info data */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001100 sta->local = ap->local;
1101 skb_queue_head_init(&sta->tx_buf);
1102 memcpy(sta->addr, addr, ETH_ALEN);
1103
1104 atomic_inc(&sta->users);
1105 spin_lock_bh(&ap->sta_table_lock);
1106 list_add(&sta->list, &ap->sta_list);
1107 ap->num_sta++;
1108 ap_sta_hash_add(ap, sta);
1109 spin_unlock_bh(&ap->sta_table_lock);
1110
1111 if (ap->proc) {
1112 struct add_sta_proc_data *entry;
1113 /* schedule a non-interrupt context process to add a procfs
1114 * entry for the STA since procfs code use GFP_KERNEL */
1115 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1116 if (entry) {
1117 memcpy(entry->addr, sta->addr, ETH_ALEN);
1118 entry->next = ap->add_sta_proc_entries;
1119 ap->add_sta_proc_entries = entry;
1120 schedule_work(&ap->add_sta_proc_queue);
1121 } else
1122 printk(KERN_DEBUG "Failed to add STA proc data\n");
1123 }
1124
1125#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1126 init_timer(&sta->timer);
1127 sta->timer.expires = jiffies + ap->max_inactivity;
1128 sta->timer.data = (unsigned long) sta;
1129 sta->timer.function = ap_handle_timer;
1130 if (!ap->local->hostapd)
1131 add_timer(&sta->timer);
1132#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1133
1134 return sta;
1135}
1136
1137
1138static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1139 local_info_t *local)
1140{
1141 if (rateidx > sta->tx_max_rate ||
1142 !(sta->tx_supp_rates & (1 << rateidx)))
1143 return 0;
1144
1145 if (local->tx_rate_control != 0 &&
1146 !(local->tx_rate_control & (1 << rateidx)))
1147 return 0;
1148
1149 return 1;
1150}
1151
1152
1153static void prism2_check_tx_rates(struct sta_info *sta)
1154{
1155 int i;
1156
1157 sta->tx_supp_rates = 0;
1158 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1159 if ((sta->supported_rates[i] & 0x7f) == 2)
1160 sta->tx_supp_rates |= WLAN_RATE_1M;
1161 if ((sta->supported_rates[i] & 0x7f) == 4)
1162 sta->tx_supp_rates |= WLAN_RATE_2M;
1163 if ((sta->supported_rates[i] & 0x7f) == 11)
1164 sta->tx_supp_rates |= WLAN_RATE_5M5;
1165 if ((sta->supported_rates[i] & 0x7f) == 22)
1166 sta->tx_supp_rates |= WLAN_RATE_11M;
1167 }
1168 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1169 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1170 sta->tx_max_rate = 0;
1171 if (ap_tx_rate_ok(0, sta, sta->local)) {
1172 sta->tx_rate = 10;
1173 sta->tx_rate_idx = 0;
1174 }
1175 }
1176 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1177 sta->tx_max_rate = 1;
1178 if (ap_tx_rate_ok(1, sta, sta->local)) {
1179 sta->tx_rate = 20;
1180 sta->tx_rate_idx = 1;
1181 }
1182 }
1183 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1184 sta->tx_max_rate = 2;
1185 if (ap_tx_rate_ok(2, sta, sta->local)) {
1186 sta->tx_rate = 55;
1187 sta->tx_rate_idx = 2;
1188 }
1189 }
1190 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1191 sta->tx_max_rate = 3;
1192 if (ap_tx_rate_ok(3, sta, sta->local)) {
1193 sta->tx_rate = 110;
1194 sta->tx_rate_idx = 3;
1195 }
1196 }
1197}
1198
1199
1200#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1201
1202static void ap_crypt_init(struct ap_data *ap)
1203{
John W. Linville274bfb82008-10-29 11:35:05 -04001204 ap->crypt = lib80211_get_crypto_ops("WEP");
Jouni Malinenff1d2762005-05-12 22:54:16 -04001205
1206 if (ap->crypt) {
1207 if (ap->crypt->init) {
1208 ap->crypt_priv = ap->crypt->init(0);
1209 if (ap->crypt_priv == NULL)
1210 ap->crypt = NULL;
1211 else {
1212 u8 key[WEP_KEY_LEN];
1213 get_random_bytes(key, WEP_KEY_LEN);
1214 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1215 ap->crypt_priv);
1216 }
1217 }
1218 }
1219
1220 if (ap->crypt == NULL) {
1221 printk(KERN_WARNING "AP could not initialize WEP: load module "
John W. Linville274bfb82008-10-29 11:35:05 -04001222 "lib80211_crypt_wep.ko\n");
Jouni Malinenff1d2762005-05-12 22:54:16 -04001223 }
1224}
1225
1226
1227/* Generate challenge data for shared key authentication. IEEE 802.11 specifies
Uwe Kleine-König25d1fbf2010-07-13 11:27:58 +02001228 * that WEP algorithm is used for generating challenge. This should be unique,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001229 * but otherwise there is not really need for randomness etc. Initialize WEP
1230 * with pseudo random key and then use increasing IV to get unique challenge
1231 * streams.
1232 *
1233 * Called only as a scheduled task for pending AP frames.
1234 */
1235static char * ap_auth_make_challenge(struct ap_data *ap)
1236{
1237 char *tmpbuf;
1238 struct sk_buff *skb;
1239
1240 if (ap->crypt == NULL) {
1241 ap_crypt_init(ap);
1242 if (ap->crypt == NULL)
1243 return NULL;
1244 }
1245
Robert P. J. Day5cbded52006-12-13 00:35:56 -08001246 tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001247 if (tmpbuf == NULL) {
1248 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1249 return NULL;
1250 }
1251
1252 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
James Ketrenos5bfc8192005-09-21 12:23:51 -05001253 ap->crypt->extra_mpdu_prefix_len +
1254 ap->crypt->extra_mpdu_postfix_len);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001255 if (skb == NULL) {
1256 kfree(tmpbuf);
1257 return NULL;
1258 }
1259
James Ketrenos5bfc8192005-09-21 12:23:51 -05001260 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001261 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
1262 WLAN_AUTH_CHALLENGE_LEN);
1263 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1264 dev_kfree_skb(skb);
1265 kfree(tmpbuf);
1266 return NULL;
1267 }
1268
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001269 skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
1270 tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001271 dev_kfree_skb(skb);
1272
1273 return tmpbuf;
1274}
1275
1276
1277/* Called only as a scheduled task for pending AP frames. */
1278static void handle_authen(local_info_t *local, struct sk_buff *skb,
1279 struct hostap_80211_rx_status *rx_stats)
1280{
1281 struct net_device *dev = local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -05001282 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001283 size_t hdrlen;
1284 struct ap_data *ap = local->ap;
1285 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1286 int len, olen;
Al Viro8a9faf32007-12-21 03:30:16 -05001287 u16 auth_alg, auth_transaction, status_code;
1288 __le16 *pos;
Dan Williams1ea893f2009-02-11 17:17:10 -05001289 u16 resp = WLAN_STATUS_SUCCESS;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001290 struct sta_info *sta = NULL;
John W. Linville274bfb82008-10-29 11:35:05 -04001291 struct lib80211_crypt_data *crypt;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001292 char *txt = "";
1293
1294 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1295
Dan Williams1ea893f2009-02-11 17:17:10 -05001296 hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001297
1298 if (len < 6) {
1299 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
Johannes Berge1749612008-10-27 15:59:26 -07001300 "(len=%d) from %pM\n", dev->name, len, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001301 return;
1302 }
1303
1304 spin_lock_bh(&local->ap->sta_table_lock);
1305 sta = ap_get_sta(local->ap, hdr->addr2);
1306 if (sta)
1307 atomic_inc(&sta->users);
1308 spin_unlock_bh(&local->ap->sta_table_lock);
1309
1310 if (sta && sta->crypt)
1311 crypt = sta->crypt;
1312 else {
1313 int idx = 0;
1314 if (skb->len >= hdrlen + 3)
1315 idx = skb->data[hdrlen + 3] >> 6;
John W. Linville274bfb82008-10-29 11:35:05 -04001316 crypt = local->crypt_info.crypt[idx];
Jouni Malinenff1d2762005-05-12 22:54:16 -04001317 }
1318
Al Viro8a9faf32007-12-21 03:30:16 -05001319 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001320 auth_alg = __le16_to_cpu(*pos);
1321 pos++;
1322 auth_transaction = __le16_to_cpu(*pos);
1323 pos++;
1324 status_code = __le16_to_cpu(*pos);
1325 pos++;
1326
1327 if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
1328 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1329 txt = "authentication denied";
1330 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1331 goto fail;
1332 }
1333
1334 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1335 auth_alg == WLAN_AUTH_OPEN) ||
1336 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1337 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1338 } else {
1339 txt = "unsupported algorithm";
1340 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1341 goto fail;
1342 }
1343
1344 if (len >= 8) {
1345 u8 *u = (u8 *) pos;
1346 if (*u == WLAN_EID_CHALLENGE) {
1347 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1348 txt = "invalid challenge len";
1349 resp = WLAN_STATUS_CHALLENGE_FAIL;
1350 goto fail;
1351 }
1352 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1353 txt = "challenge underflow";
1354 resp = WLAN_STATUS_CHALLENGE_FAIL;
1355 goto fail;
1356 }
1357 challenge = (char *) (u + 2);
1358 }
1359 }
1360
1361 if (sta && sta->ap) {
1362 if (time_after(jiffies, sta->u.ap.last_beacon +
1363 (10 * sta->listen_interval * HZ) / 1024)) {
1364 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
Johannes Berge1749612008-10-27 15:59:26 -07001365 " assuming AP %pM is now STA\n",
1366 dev->name, sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001367 sta->ap = 0;
1368 sta->flags = 0;
1369 sta->u.sta.challenge = NULL;
1370 } else {
1371 txt = "AP trying to authenticate?";
1372 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1373 goto fail;
1374 }
1375 }
1376
1377 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1378 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1379 (auth_transaction == 1 ||
1380 (auth_transaction == 3 && sta != NULL &&
1381 sta->u.sta.challenge != NULL)))) {
1382 } else {
1383 txt = "unknown authentication transaction number";
1384 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1385 goto fail;
1386 }
1387
1388 if (sta == NULL) {
1389 txt = "new STA";
1390
1391 if (local->ap->num_sta >= MAX_STA_COUNT) {
1392 /* FIX: might try to remove some old STAs first? */
1393 txt = "no more room for new STAs";
1394 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1395 goto fail;
1396 }
1397
1398 sta = ap_add_sta(local->ap, hdr->addr2);
1399 if (sta == NULL) {
1400 txt = "ap_add_sta failed";
1401 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1402 goto fail;
1403 }
1404 }
1405
1406 switch (auth_alg) {
1407 case WLAN_AUTH_OPEN:
1408 txt = "authOK";
1409 /* IEEE 802.11 standard is not completely clear about
1410 * whether STA is considered authenticated after
1411 * authentication OK frame has been send or after it
1412 * has been ACKed. In order to reduce interoperability
1413 * issues, mark the STA authenticated before ACK. */
1414 sta->flags |= WLAN_STA_AUTH;
1415 break;
1416
1417 case WLAN_AUTH_SHARED_KEY:
1418 if (auth_transaction == 1) {
1419 if (sta->u.sta.challenge == NULL) {
1420 sta->u.sta.challenge =
1421 ap_auth_make_challenge(local->ap);
1422 if (sta->u.sta.challenge == NULL) {
1423 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1424 goto fail;
1425 }
1426 }
1427 } else {
1428 if (sta->u.sta.challenge == NULL ||
1429 challenge == NULL ||
1430 memcmp(sta->u.sta.challenge, challenge,
1431 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
Dan Williams1ea893f2009-02-11 17:17:10 -05001432 !ieee80211_has_protected(hdr->frame_control)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04001433 txt = "challenge response incorrect";
1434 resp = WLAN_STATUS_CHALLENGE_FAIL;
1435 goto fail;
1436 }
1437
1438 txt = "challenge OK - authOK";
1439 /* IEEE 802.11 standard is not completely clear about
1440 * whether STA is considered authenticated after
1441 * authentication OK frame has been send or after it
1442 * has been ACKed. In order to reduce interoperability
1443 * issues, mark the STA authenticated before ACK. */
1444 sta->flags |= WLAN_STA_AUTH;
1445 kfree(sta->u.sta.challenge);
1446 sta->u.sta.challenge = NULL;
1447 }
1448 break;
1449 }
1450
1451 fail:
Al Viro8a9faf32007-12-21 03:30:16 -05001452 pos = (__le16 *) body;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001453 *pos = cpu_to_le16(auth_alg);
1454 pos++;
1455 *pos = cpu_to_le16(auth_transaction + 1);
1456 pos++;
1457 *pos = cpu_to_le16(resp); /* status_code */
1458 pos++;
1459 olen = 6;
1460
1461 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1462 sta->u.sta.challenge != NULL &&
1463 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1464 u8 *tmp = (u8 *) pos;
1465 *tmp++ = WLAN_EID_CHALLENGE;
1466 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1467 pos++;
1468 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1469 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1470 }
1471
Jouni Malinen4339d322005-08-14 19:08:44 -07001472 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001473 body, olen, hdr->addr2, ap->tx_callback_auth);
1474
1475 if (sta) {
1476 sta->last_rx = jiffies;
1477 atomic_dec(&sta->users);
1478 }
1479
1480 if (resp) {
Johannes Berge1749612008-10-27 15:59:26 -07001481 PDEBUG(DEBUG_AP, "%s: %pM auth (alg=%d "
Joe Perches0795af52007-10-03 17:59:30 -07001482 "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
Johannes Berge1749612008-10-27 15:59:26 -07001483 dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -07001484 auth_alg, auth_transaction, status_code, len,
Dan Williams1ea893f2009-02-11 17:17:10 -05001485 le16_to_cpu(hdr->frame_control), resp, txt);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001486 }
1487}
1488
1489
1490/* Called only as a scheduled task for pending AP frames. */
1491static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1492 struct hostap_80211_rx_status *rx_stats, int reassoc)
1493{
1494 struct net_device *dev = local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -05001495 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001496 char body[12], *p, *lpos;
1497 int len, left;
Al Viro8a9faf32007-12-21 03:30:16 -05001498 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001499 u16 resp = WLAN_STATUS_SUCCESS;
1500 struct sta_info *sta = NULL;
1501 int send_deauth = 0;
1502 char *txt = "";
1503 u8 prev_ap[ETH_ALEN];
1504
1505 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1506
1507 if (len < (reassoc ? 10 : 4)) {
1508 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
Johannes Berge1749612008-10-27 15:59:26 -07001509 "(len=%d, reassoc=%d) from %pM\n",
1510 dev->name, len, reassoc, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001511 return;
1512 }
1513
1514 spin_lock_bh(&local->ap->sta_table_lock);
1515 sta = ap_get_sta(local->ap, hdr->addr2);
1516 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1517 spin_unlock_bh(&local->ap->sta_table_lock);
1518 txt = "trying to associate before authentication";
1519 send_deauth = 1;
1520 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1521 sta = NULL; /* do not decrement sta->users */
1522 goto fail;
1523 }
1524 atomic_inc(&sta->users);
1525 spin_unlock_bh(&local->ap->sta_table_lock);
1526
Al Viro8a9faf32007-12-21 03:30:16 -05001527 pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001528 sta->capability = __le16_to_cpu(*pos);
1529 pos++; left -= 2;
1530 sta->listen_interval = __le16_to_cpu(*pos);
1531 pos++; left -= 2;
1532
1533 if (reassoc) {
1534 memcpy(prev_ap, pos, ETH_ALEN);
1535 pos++; pos++; pos++; left -= 6;
1536 } else
1537 memset(prev_ap, 0, ETH_ALEN);
1538
1539 if (left >= 2) {
1540 unsigned int ileft;
1541 unsigned char *u = (unsigned char *) pos;
1542
1543 if (*u == WLAN_EID_SSID) {
1544 u++; left--;
1545 ileft = *u;
1546 u++; left--;
1547
1548 if (ileft > left || ileft > MAX_SSID_LEN) {
1549 txt = "SSID overflow";
1550 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1551 goto fail;
1552 }
1553
1554 if (ileft != strlen(local->essid) ||
1555 memcmp(local->essid, u, ileft) != 0) {
1556 txt = "not our SSID";
1557 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1558 goto fail;
1559 }
1560
1561 u += ileft;
1562 left -= ileft;
1563 }
1564
1565 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1566 u++; left--;
1567 ileft = *u;
1568 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04001569
Jouni Malinenff1d2762005-05-12 22:54:16 -04001570 if (ileft > left || ileft == 0 ||
1571 ileft > WLAN_SUPP_RATES_MAX) {
1572 txt = "SUPP_RATES len error";
1573 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1574 goto fail;
1575 }
1576
1577 memset(sta->supported_rates, 0,
1578 sizeof(sta->supported_rates));
1579 memcpy(sta->supported_rates, u, ileft);
1580 prism2_check_tx_rates(sta);
1581
1582 u += ileft;
1583 left -= ileft;
1584 }
1585
1586 if (left > 0) {
Johannes Berge1749612008-10-27 15:59:26 -07001587 PDEBUG(DEBUG_AP, "%s: assoc from %pM"
Joe Perches0795af52007-10-03 17:59:30 -07001588 " with extra data (%d bytes) [",
Johannes Berge1749612008-10-27 15:59:26 -07001589 dev->name, hdr->addr2, left);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001590 while (left > 0) {
1591 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1592 u++; left--;
1593 }
1594 PDEBUG2(DEBUG_AP, "]\n");
1595 }
1596 } else {
1597 txt = "frame underflow";
1598 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1599 goto fail;
1600 }
1601
1602 /* get a unique AID */
1603 if (sta->aid > 0)
1604 txt = "OK, old AID";
1605 else {
1606 spin_lock_bh(&local->ap->sta_table_lock);
1607 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1608 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1609 break;
1610 if (sta->aid > MAX_AID_TABLE_SIZE) {
1611 sta->aid = 0;
1612 spin_unlock_bh(&local->ap->sta_table_lock);
1613 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1614 txt = "no room for more AIDs";
1615 } else {
1616 local->ap->sta_aid[sta->aid - 1] = sta;
1617 spin_unlock_bh(&local->ap->sta_table_lock);
1618 txt = "OK, new AID";
1619 }
1620 }
1621
1622 fail:
Al Viro8a9faf32007-12-21 03:30:16 -05001623 pos = (__le16 *) body;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001624
1625 if (send_deauth) {
Al Viro8a9faf32007-12-21 03:30:16 -05001626 *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001627 pos++;
1628 } else {
1629 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1630 * values in beacons/probe responses */
1631 /* FIX: how about privacy and WEP? */
1632 /* capability */
Al Viro8a9faf32007-12-21 03:30:16 -05001633 *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001634 pos++;
1635
1636 /* status_code */
Al Viro8a9faf32007-12-21 03:30:16 -05001637 *pos = cpu_to_le16(resp);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001638 pos++;
1639
Al Viro8a9faf32007-12-21 03:30:16 -05001640 *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
Jouni Malinenff1d2762005-05-12 22:54:16 -04001641 BIT(14) | BIT(15)); /* AID */
1642 pos++;
1643
1644 /* Supported rates (Information element) */
1645 p = (char *) pos;
1646 *p++ = WLAN_EID_SUPP_RATES;
1647 lpos = p;
1648 *p++ = 0; /* len */
1649 if (local->tx_rate_control & WLAN_RATE_1M) {
1650 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1651 (*lpos)++;
1652 }
1653 if (local->tx_rate_control & WLAN_RATE_2M) {
1654 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1655 (*lpos)++;
1656 }
1657 if (local->tx_rate_control & WLAN_RATE_5M5) {
1658 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1659 0x8b : 0x0b;
1660 (*lpos)++;
1661 }
1662 if (local->tx_rate_control & WLAN_RATE_11M) {
1663 *p++ = local->basic_rates & WLAN_RATE_11M ?
1664 0x96 : 0x16;
1665 (*lpos)++;
1666 }
Al Viro8a9faf32007-12-21 03:30:16 -05001667 pos = (__le16 *) p;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001668 }
1669
Jouni Malinen4339d322005-08-14 19:08:44 -07001670 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
1671 (send_deauth ? IEEE80211_STYPE_DEAUTH :
1672 (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
1673 IEEE80211_STYPE_ASSOC_RESP)),
Jouni Malinenff1d2762005-05-12 22:54:16 -04001674 body, (u8 *) pos - (u8 *) body,
1675 hdr->addr2,
1676 send_deauth ? 0 : local->ap->tx_callback_assoc);
1677
1678 if (sta) {
1679 if (resp == WLAN_STATUS_SUCCESS) {
1680 sta->last_rx = jiffies;
1681 /* STA will be marked associated from TX callback, if
1682 * AssocResp is ACKed */
1683 }
1684 atomic_dec(&sta->users);
1685 }
1686
1687#if 0
Johannes Berge1749612008-10-27 15:59:26 -07001688 PDEBUG(DEBUG_AP, "%s: %pM %sassoc (len=%d "
1689 "prev_ap=%pM) => %d(%d) (%s)\n",
David S. Miller21f644f2008-04-08 16:50:44 -07001690 dev->name,
Johannes Berge1749612008-10-27 15:59:26 -07001691 hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -07001692 reassoc ? "re" : "", len,
Johannes Berge1749612008-10-27 15:59:26 -07001693 prev_ap,
David S. Miller21f644f2008-04-08 16:50:44 -07001694 resp, send_deauth, txt);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001695#endif
1696}
1697
1698
1699/* Called only as a scheduled task for pending AP frames. */
1700static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1701 struct hostap_80211_rx_status *rx_stats)
1702{
1703 struct net_device *dev = local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -05001704 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001705 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1706 int len;
Al Viro8a9faf32007-12-21 03:30:16 -05001707 u16 reason_code;
1708 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001709 struct sta_info *sta = NULL;
1710
1711 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1712
1713 if (len < 2) {
1714 printk("handle_deauth - too short payload (len=%d)\n", len);
1715 return;
1716 }
1717
Al Viro8a9faf32007-12-21 03:30:16 -05001718 pos = (__le16 *) body;
1719 reason_code = le16_to_cpu(*pos);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001720
Johannes Berge1749612008-10-27 15:59:26 -07001721 PDEBUG(DEBUG_AP, "%s: deauthentication: %pM len=%d, "
1722 "reason_code=%d\n", dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -07001723 len, reason_code);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001724
1725 spin_lock_bh(&local->ap->sta_table_lock);
1726 sta = ap_get_sta(local->ap, hdr->addr2);
1727 if (sta != NULL) {
1728 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1729 hostap_event_expired_sta(local->dev, sta);
1730 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1731 }
1732 spin_unlock_bh(&local->ap->sta_table_lock);
1733 if (sta == NULL) {
Johannes Berge1749612008-10-27 15:59:26 -07001734 printk("%s: deauthentication from %pM, "
Jouni Malinenff1d2762005-05-12 22:54:16 -04001735 "reason_code=%d, but STA not authenticated\n", dev->name,
Johannes Berge1749612008-10-27 15:59:26 -07001736 hdr->addr2, reason_code);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001737 }
1738}
1739
1740
1741/* Called only as a scheduled task for pending AP frames. */
1742static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1743 struct hostap_80211_rx_status *rx_stats)
1744{
1745 struct net_device *dev = local->dev;
Dan Williams1ea893f2009-02-11 17:17:10 -05001746 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001747 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1748 int len;
Al Viro8a9faf32007-12-21 03:30:16 -05001749 u16 reason_code;
1750 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001751 struct sta_info *sta = NULL;
1752
1753 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1754
1755 if (len < 2) {
1756 printk("handle_disassoc - too short payload (len=%d)\n", len);
1757 return;
1758 }
1759
Al Viro8a9faf32007-12-21 03:30:16 -05001760 pos = (__le16 *) body;
1761 reason_code = le16_to_cpu(*pos);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001762
Johannes Berge1749612008-10-27 15:59:26 -07001763 PDEBUG(DEBUG_AP, "%s: disassociation: %pM len=%d, "
1764 "reason_code=%d\n", dev->name, hdr->addr2,
David S. Miller21f644f2008-04-08 16:50:44 -07001765 len, reason_code);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001766
1767 spin_lock_bh(&local->ap->sta_table_lock);
1768 sta = ap_get_sta(local->ap, hdr->addr2);
1769 if (sta != NULL) {
1770 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1771 hostap_event_expired_sta(local->dev, sta);
1772 sta->flags &= ~WLAN_STA_ASSOC;
1773 }
1774 spin_unlock_bh(&local->ap->sta_table_lock);
1775 if (sta == NULL) {
Johannes Berge1749612008-10-27 15:59:26 -07001776 printk("%s: disassociation from %pM, "
Jouni Malinenff1d2762005-05-12 22:54:16 -04001777 "reason_code=%d, but STA not authenticated\n",
Johannes Berge1749612008-10-27 15:59:26 -07001778 dev->name, hdr->addr2, reason_code);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001779 }
1780}
1781
1782
1783/* Called only as a scheduled task for pending AP frames. */
1784static void ap_handle_data_nullfunc(local_info_t *local,
Dan Williams1ea893f2009-02-11 17:17:10 -05001785 struct ieee80211_hdr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001786{
1787 struct net_device *dev = local->dev;
1788
1789 /* some STA f/w's seem to require control::ACK frame for
1790 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1791 * not send this..
1792 * send control::ACK for the data::nullfunc */
1793
1794 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
Jouni Malinen4339d322005-08-14 19:08:44 -07001795 prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001796 NULL, 0, hdr->addr2, 0);
1797}
1798
1799
1800/* Called only as a scheduled task for pending AP frames. */
1801static void ap_handle_dropped_data(local_info_t *local,
Dan Williams1ea893f2009-02-11 17:17:10 -05001802 struct ieee80211_hdr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001803{
1804 struct net_device *dev = local->dev;
1805 struct sta_info *sta;
Al Viro8a9faf32007-12-21 03:30:16 -05001806 __le16 reason;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001807
1808 spin_lock_bh(&local->ap->sta_table_lock);
1809 sta = ap_get_sta(local->ap, hdr->addr2);
1810 if (sta)
1811 atomic_inc(&sta->users);
1812 spin_unlock_bh(&local->ap->sta_table_lock);
1813
1814 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1815 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1816 atomic_dec(&sta->users);
1817 return;
1818 }
1819
Al Viro8a9faf32007-12-21 03:30:16 -05001820 reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
Jouni Malinen4339d322005-08-14 19:08:44 -07001821 prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
Jouni Malinenff1d2762005-05-12 22:54:16 -04001822 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
Jouni Malinen4339d322005-08-14 19:08:44 -07001823 IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
Jouni Malinenff1d2762005-05-12 22:54:16 -04001824 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1825
1826 if (sta)
1827 atomic_dec(&sta->users);
1828}
1829
1830#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1831
1832
1833/* Called only as a scheduled task for pending AP frames. */
1834static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1835 struct sk_buff *skb)
1836{
Jouni Malinen5bee7202005-08-14 19:08:39 -07001837 struct hostap_skb_tx_data *meta;
1838
Jouni Malinenff1d2762005-05-12 22:54:16 -04001839 if (!(sta->flags & WLAN_STA_PS)) {
1840 /* Station has moved to non-PS mode, so send all buffered
1841 * frames using normal device queue. */
1842 dev_queue_xmit(skb);
1843 return;
1844 }
1845
1846 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1847 * be passed through even though STA is using PS */
Jouni Malinen5bee7202005-08-14 19:08:39 -07001848 meta = (struct hostap_skb_tx_data *) skb->cb;
1849 meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001850 if (!skb_queue_empty(&sta->tx_buf)) {
1851 /* indicate to STA that more frames follow */
Jouni Malinen5bee7202005-08-14 19:08:39 -07001852 meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001853 }
1854 dev_queue_xmit(skb);
1855}
1856
1857
1858/* Called only as a scheduled task for pending AP frames. */
1859static void handle_pspoll(local_info_t *local,
Dan Williams1ea893f2009-02-11 17:17:10 -05001860 struct ieee80211_hdr *hdr,
Jouni Malinenff1d2762005-05-12 22:54:16 -04001861 struct hostap_80211_rx_status *rx_stats)
1862{
1863 struct net_device *dev = local->dev;
1864 struct sta_info *sta;
1865 u16 aid;
1866 struct sk_buff *skb;
1867
Johannes Berge1749612008-10-27 15:59:26 -07001868 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
Dan Williams1ea893f2009-02-11 17:17:10 -05001869 hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
Jouni Malinenff1d2762005-05-12 22:54:16 -04001870
1871 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07001872 PDEBUG(DEBUG_AP,
1873 "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
1874 hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001875 return;
1876 }
1877
Al Viro8a9faf32007-12-21 03:30:16 -05001878 aid = le16_to_cpu(hdr->duration_id);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001879 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1880 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1881 return;
1882 }
Pavel Roskin1bcca3c2008-06-27 16:19:58 -04001883 aid &= ~(BIT(15) | BIT(14));
Jouni Malinenff1d2762005-05-12 22:54:16 -04001884 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1885 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1886 return;
1887 }
1888 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1889
1890 spin_lock_bh(&local->ap->sta_table_lock);
1891 sta = ap_get_sta(local->ap, hdr->addr2);
1892 if (sta)
1893 atomic_inc(&sta->users);
1894 spin_unlock_bh(&local->ap->sta_table_lock);
1895
1896 if (sta == NULL) {
1897 PDEBUG(DEBUG_PS, " STA not found\n");
1898 return;
1899 }
1900 if (sta->aid != aid) {
1901 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1902 "assoc.aid=%d\n", aid, sta->aid);
1903 return;
1904 }
1905
1906 /* FIX: todo:
1907 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1908 * out (expiry time must be longer than ListenInterval for
1909 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1910 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1911 * sta; store buffer for later use and leave TIM aid bit set? use
1912 * TX event to check whether frame was ACKed?
1913 */
1914
1915 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1916 /* send buffered frame .. */
1917 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1918 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1919
1920 pspoll_send_buffered(local, sta, skb);
1921
1922 if (sta->flags & WLAN_STA_PS) {
1923 /* send only one buffered packet per PS Poll */
1924 /* FIX: should ignore further PS Polls until the
1925 * buffered packet that was just sent is acknowledged
1926 * (Tx or TxExc event) */
1927 break;
1928 }
1929 }
1930
1931 if (skb_queue_empty(&sta->tx_buf)) {
1932 /* try to clear aid from TIM */
1933 if (!(sta->flags & WLAN_STA_TIM))
1934 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1935 aid);
1936 hostap_set_tim(local, aid, 0);
1937 sta->flags &= ~WLAN_STA_TIM;
1938 }
1939
1940 atomic_dec(&sta->users);
1941}
1942
1943
1944#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1945
David Howellsc4028952006-11-22 14:57:56 +00001946static void handle_wds_oper_queue(struct work_struct *work)
Jouni Malinenff1d2762005-05-12 22:54:16 -04001947{
David Howellsc4028952006-11-22 14:57:56 +00001948 struct ap_data *ap = container_of(work, struct ap_data,
1949 wds_oper_queue);
1950 local_info_t *local = ap->local;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001951 struct wds_oper_data *entry, *prev;
1952
1953 spin_lock_bh(&local->lock);
1954 entry = local->ap->wds_oper_entries;
1955 local->ap->wds_oper_entries = NULL;
1956 spin_unlock_bh(&local->lock);
1957
1958 while (entry) {
1959 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
Johannes Berge1749612008-10-27 15:59:26 -07001960 "to AP %pM\n",
Jouni Malinenff1d2762005-05-12 22:54:16 -04001961 local->dev->name,
1962 entry->type == WDS_ADD ? "adding" : "removing",
Johannes Berge1749612008-10-27 15:59:26 -07001963 entry->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001964 if (entry->type == WDS_ADD)
1965 prism2_wds_add(local, entry->addr, 0);
1966 else if (entry->type == WDS_DEL)
1967 prism2_wds_del(local, entry->addr, 0, 1);
1968
1969 prev = entry;
1970 entry = entry->next;
1971 kfree(prev);
1972 }
1973}
1974
1975
1976/* Called only as a scheduled task for pending AP frames. */
1977static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1978 struct hostap_80211_rx_status *rx_stats)
1979{
Dan Williams1ea893f2009-02-11 17:17:10 -05001980 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001981 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1982 int len, left;
Al Viro8a9faf32007-12-21 03:30:16 -05001983 u16 beacon_int, capability;
1984 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -04001985 char *ssid = NULL;
1986 unsigned char *supp_rates = NULL;
1987 int ssid_len = 0, supp_rates_len = 0;
1988 struct sta_info *sta = NULL;
1989 int new_sta = 0, channel = -1;
1990
1991 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1992
1993 if (len < 8 + 2 + 2) {
1994 printk(KERN_DEBUG "handle_beacon - too short payload "
1995 "(len=%d)\n", len);
1996 return;
1997 }
1998
Al Viro8a9faf32007-12-21 03:30:16 -05001999 pos = (__le16 *) body;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002000 left = len;
2001
2002 /* Timestamp (8 octets) */
2003 pos += 4; left -= 8;
2004 /* Beacon interval (2 octets) */
Al Viro8a9faf32007-12-21 03:30:16 -05002005 beacon_int = le16_to_cpu(*pos);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002006 pos++; left -= 2;
2007 /* Capability information (2 octets) */
Al Viro8a9faf32007-12-21 03:30:16 -05002008 capability = le16_to_cpu(*pos);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002009 pos++; left -= 2;
2010
2011 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2012 capability & WLAN_CAPABILITY_IBSS)
2013 return;
2014
2015 if (left >= 2) {
2016 unsigned int ileft;
2017 unsigned char *u = (unsigned char *) pos;
2018
2019 if (*u == WLAN_EID_SSID) {
2020 u++; left--;
2021 ileft = *u;
2022 u++; left--;
2023
2024 if (ileft > left || ileft > MAX_SSID_LEN) {
2025 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2026 return;
2027 }
2028
2029 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2030 (ileft != strlen(local->essid) ||
2031 memcmp(local->essid, u, ileft) != 0)) {
2032 /* not our SSID */
2033 return;
2034 }
2035
2036 ssid = u;
2037 ssid_len = ileft;
2038
2039 u += ileft;
2040 left -= ileft;
2041 }
2042
2043 if (*u == WLAN_EID_SUPP_RATES) {
2044 u++; left--;
2045 ileft = *u;
2046 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04002047
Jouni Malinenff1d2762005-05-12 22:54:16 -04002048 if (ileft > left || ileft == 0 || ileft > 8) {
2049 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2050 return;
2051 }
2052
2053 supp_rates = u;
2054 supp_rates_len = ileft;
2055
2056 u += ileft;
2057 left -= ileft;
2058 }
2059
2060 if (*u == WLAN_EID_DS_PARAMS) {
2061 u++; left--;
2062 ileft = *u;
2063 u++; left--;
Jeff Garzik74fae822005-07-31 13:08:32 -04002064
Jouni Malinenff1d2762005-05-12 22:54:16 -04002065 if (ileft > left || ileft != 1) {
2066 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2067 return;
2068 }
2069
2070 channel = *u;
2071
2072 u += ileft;
2073 left -= ileft;
2074 }
2075 }
2076
2077 spin_lock_bh(&local->ap->sta_table_lock);
2078 sta = ap_get_sta(local->ap, hdr->addr2);
2079 if (sta != NULL)
2080 atomic_inc(&sta->users);
2081 spin_unlock_bh(&local->ap->sta_table_lock);
2082
2083 if (sta == NULL) {
2084 /* add new AP */
2085 new_sta = 1;
2086 sta = ap_add_sta(local->ap, hdr->addr2);
2087 if (sta == NULL) {
2088 printk(KERN_INFO "prism2: kmalloc failed for AP "
2089 "data structure\n");
2090 return;
2091 }
2092 hostap_event_new_sta(local->dev, sta);
2093
2094 /* mark APs authentication and associated for pseudo ad-hoc
2095 * style communication */
2096 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2097
2098 if (local->ap->autom_ap_wds) {
2099 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2100 }
2101 }
2102
2103 sta->ap = 1;
2104 if (ssid) {
2105 sta->u.ap.ssid_len = ssid_len;
2106 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2107 sta->u.ap.ssid[ssid_len] = '\0';
2108 } else {
2109 sta->u.ap.ssid_len = 0;
2110 sta->u.ap.ssid[0] = '\0';
2111 }
2112 sta->u.ap.channel = channel;
2113 sta->rx_packets++;
2114 sta->rx_bytes += len;
2115 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2116 sta->capability = capability;
2117 sta->listen_interval = beacon_int;
2118
2119 atomic_dec(&sta->users);
2120
2121 if (new_sta) {
2122 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2123 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2124 prism2_check_tx_rates(sta);
2125 }
2126}
2127
2128#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2129
2130
2131/* Called only as a tasklet. */
2132static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2133 struct hostap_80211_rx_status *rx_stats)
2134{
2135#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2136 struct net_device *dev = local->dev;
2137#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2138 u16 fc, type, stype;
Dan Williams1ea893f2009-02-11 17:17:10 -05002139 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002140
2141 /* FIX: should give skb->len to handler functions and check that the
2142 * buffer is long enough */
Dan Williams1ea893f2009-02-11 17:17:10 -05002143 hdr = (struct ieee80211_hdr *) skb->data;
2144 fc = le16_to_cpu(hdr->frame_control);
2145 type = fc & IEEE80211_FCTL_FTYPE;
2146 stype = fc & IEEE80211_FCTL_STYPE;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002147
2148#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinen4339d322005-08-14 19:08:44 -07002149 if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002150 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2151
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002152 if (!(fc & IEEE80211_FCTL_TODS) ||
2153 (fc & IEEE80211_FCTL_FROMDS)) {
Jouni Malinen4339d322005-08-14 19:08:44 -07002154 if (stype == IEEE80211_STYPE_NULLFUNC) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002155 /* no ToDS nullfunc seems to be used to check
2156 * AP association; so send reject message to
2157 * speed up re-association */
2158 ap_handle_dropped_data(local, hdr);
2159 goto done;
2160 }
2161 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2162 fc);
2163 goto done;
2164 }
2165
2166 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07002167 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
2168 " not own MAC\n", hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002169 goto done;
2170 }
2171
Jouni Malinen4339d322005-08-14 19:08:44 -07002172 if (local->ap->nullfunc_ack &&
2173 stype == IEEE80211_STYPE_NULLFUNC)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002174 ap_handle_data_nullfunc(local, hdr);
2175 else
2176 ap_handle_dropped_data(local, hdr);
2177 goto done;
2178 }
2179
Jouni Malinen4339d322005-08-14 19:08:44 -07002180 if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002181 handle_beacon(local, skb, rx_stats);
2182 goto done;
2183 }
2184#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2185
Jouni Malinen4339d322005-08-14 19:08:44 -07002186 if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002187 handle_pspoll(local, hdr, rx_stats);
2188 goto done;
2189 }
2190
2191 if (local->hostapd) {
2192 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2193 "subtype=0x%02x\n", type, stype);
2194 goto done;
2195 }
2196
2197#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinen4339d322005-08-14 19:08:44 -07002198 if (type != IEEE80211_FTYPE_MGMT) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002199 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2200 goto done;
2201 }
2202
2203 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07002204 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
2205 " not own MAC\n", hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002206 goto done;
2207 }
2208
2209 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
Johannes Berge1749612008-10-27 15:59:26 -07002210 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
2211 " not own MAC\n", hdr->addr3);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002212 goto done;
2213 }
2214
2215 switch (stype) {
Jouni Malinen4339d322005-08-14 19:08:44 -07002216 case IEEE80211_STYPE_ASSOC_REQ:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002217 handle_assoc(local, skb, rx_stats, 0);
2218 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002219 case IEEE80211_STYPE_ASSOC_RESP:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002220 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2221 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002222 case IEEE80211_STYPE_REASSOC_REQ:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002223 handle_assoc(local, skb, rx_stats, 1);
2224 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002225 case IEEE80211_STYPE_REASSOC_RESP:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002226 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2227 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002228 case IEEE80211_STYPE_ATIM:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002229 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2230 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002231 case IEEE80211_STYPE_DISASSOC:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002232 handle_disassoc(local, skb, rx_stats);
2233 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002234 case IEEE80211_STYPE_AUTH:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002235 handle_authen(local, skb, rx_stats);
2236 break;
Jouni Malinen4339d322005-08-14 19:08:44 -07002237 case IEEE80211_STYPE_DEAUTH:
Jouni Malinenff1d2762005-05-12 22:54:16 -04002238 handle_deauth(local, skb, rx_stats);
2239 break;
2240 default:
Jouni Malinen4339d322005-08-14 19:08:44 -07002241 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
2242 stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002243 break;
2244 }
2245#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2246
2247 done:
2248 dev_kfree_skb(skb);
2249}
2250
2251
2252/* Called only as a tasklet (software IRQ) */
2253void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2254 struct hostap_80211_rx_status *rx_stats)
2255{
2256 struct hostap_interface *iface;
2257 local_info_t *local;
Dan Williams1ea893f2009-02-11 17:17:10 -05002258 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002259
2260 iface = netdev_priv(dev);
2261 local = iface->local;
2262
2263 if (skb->len < 16)
2264 goto drop;
2265
Stephen Hemminger4cfa8e42009-03-20 19:36:42 +00002266 dev->stats.rx_packets++;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002267
Dan Williams1ea893f2009-02-11 17:17:10 -05002268 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002269
2270 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
Dan Williams1ea893f2009-02-11 17:17:10 -05002271 ieee80211_is_beacon(hdr->frame_control))
Jouni Malinenff1d2762005-05-12 22:54:16 -04002272 goto drop;
2273
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08002274 skb->protocol = cpu_to_be16(ETH_P_HOSTAP);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002275 handle_ap_item(local, skb, rx_stats);
2276 return;
2277
2278 drop:
2279 dev_kfree_skb(skb);
2280}
2281
2282
2283/* Called only as a tasklet (software IRQ) */
2284static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2285{
2286 struct sk_buff *skb;
Dan Williams1ea893f2009-02-11 17:17:10 -05002287 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002288 struct hostap_80211_rx_status rx_stats;
2289
2290 if (skb_queue_empty(&sta->tx_buf))
2291 return;
2292
2293 skb = dev_alloc_skb(16);
2294 if (skb == NULL) {
2295 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2296 "failed\n", local->dev->name);
2297 return;
2298 }
2299
Dan Williams1ea893f2009-02-11 17:17:10 -05002300 hdr = (struct ieee80211_hdr *) skb_put(skb, 16);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002301
2302 /* Generate a fake pspoll frame to start packet delivery */
Dan Williams1ea893f2009-02-11 17:17:10 -05002303 hdr->frame_control = cpu_to_le16(
Jouni Malinen4339d322005-08-14 19:08:44 -07002304 IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002305 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2306 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2307 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2308
Johannes Berge1749612008-10-27 15:59:26 -07002309 PDEBUG(DEBUG_PS2,
2310 "%s: Scheduling buffered packet delivery for STA %pM\n",
2311 local->dev->name, sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002312
2313 skb->dev = local->dev;
2314
2315 memset(&rx_stats, 0, sizeof(rx_stats));
2316 hostap_rx(local->dev, skb, &rx_stats);
2317}
2318
2319
Adrian Bunk5fad5a22006-01-14 03:09:34 +01002320int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2321 struct iw_quality qual[], int buf_size,
2322 int aplist)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002323{
2324 struct ap_data *ap = local->ap;
2325 struct list_head *ptr;
2326 int count = 0;
2327
2328 spin_lock_bh(&ap->sta_table_lock);
2329
2330 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2331 ptr = ptr->next) {
2332 struct sta_info *sta = (struct sta_info *) ptr;
2333
2334 if (aplist && !sta->ap)
2335 continue;
2336 addr[count].sa_family = ARPHRD_ETHER;
2337 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2338 if (sta->last_rx_silence == 0)
2339 qual[count].qual = sta->last_rx_signal < 27 ?
2340 0 : (sta->last_rx_signal - 27) * 92 / 127;
2341 else
2342 qual[count].qual = sta->last_rx_signal -
2343 sta->last_rx_silence - 35;
2344 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2345 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2346 qual[count].updated = sta->last_rx_updated;
2347
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07002348 sta->last_rx_updated = IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002349
2350 count++;
2351 if (count >= buf_size)
2352 break;
2353 }
2354 spin_unlock_bh(&ap->sta_table_lock);
2355
2356 return count;
2357}
2358
2359
2360/* Translate our list of Access Points & Stations to a card independant
2361 * format that the Wireless Tools will understand - Jean II */
David S. Millerccc58052008-06-16 18:50:49 -07002362int prism2_ap_translate_scan(struct net_device *dev,
2363 struct iw_request_info *info, char *buffer)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002364{
2365 struct hostap_interface *iface;
2366 local_info_t *local;
2367 struct ap_data *ap;
2368 struct list_head *ptr;
2369 struct iw_event iwe;
2370 char *current_ev = buffer;
2371 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2372#if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2373 char buf[64];
2374#endif
2375
2376 iface = netdev_priv(dev);
2377 local = iface->local;
2378 ap = local->ap;
2379
2380 spin_lock_bh(&ap->sta_table_lock);
2381
2382 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2383 ptr = ptr->next) {
2384 struct sta_info *sta = (struct sta_info *) ptr;
2385
2386 /* First entry *MUST* be the AP MAC address */
2387 memset(&iwe, 0, sizeof(iwe));
2388 iwe.cmd = SIOCGIWAP;
2389 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2390 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2391 iwe.len = IW_EV_ADDR_LEN;
David S. Millerccc58052008-06-16 18:50:49 -07002392 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2393 &iwe, IW_EV_ADDR_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002394
2395 /* Use the mode to indicate if it's a station or
2396 * an Access Point */
2397 memset(&iwe, 0, sizeof(iwe));
2398 iwe.cmd = SIOCGIWMODE;
2399 if (sta->ap)
2400 iwe.u.mode = IW_MODE_MASTER;
2401 else
2402 iwe.u.mode = IW_MODE_INFRA;
2403 iwe.len = IW_EV_UINT_LEN;
David S. Millerccc58052008-06-16 18:50:49 -07002404 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2405 &iwe, IW_EV_UINT_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002406
2407 /* Some quality */
2408 memset(&iwe, 0, sizeof(iwe));
2409 iwe.cmd = IWEVQUAL;
2410 if (sta->last_rx_silence == 0)
2411 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2412 0 : (sta->last_rx_signal - 27) * 92 / 127;
2413 else
2414 iwe.u.qual.qual = sta->last_rx_signal -
2415 sta->last_rx_silence - 35;
2416 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2417 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2418 iwe.u.qual.updated = sta->last_rx_updated;
2419 iwe.len = IW_EV_QUAL_LEN;
David S. Millerccc58052008-06-16 18:50:49 -07002420 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2421 &iwe, IW_EV_QUAL_LEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002422
2423#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2424 if (sta->ap) {
2425 memset(&iwe, 0, sizeof(iwe));
2426 iwe.cmd = SIOCGIWESSID;
2427 iwe.u.data.length = sta->u.ap.ssid_len;
2428 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07002429 current_ev = iwe_stream_add_point(info, current_ev,
2430 end_buf, &iwe,
Jouni Malinenff1d2762005-05-12 22:54:16 -04002431 sta->u.ap.ssid);
2432
2433 memset(&iwe, 0, sizeof(iwe));
2434 iwe.cmd = SIOCGIWENCODE;
2435 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2436 iwe.u.data.flags =
2437 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2438 else
2439 iwe.u.data.flags = IW_ENCODE_DISABLED;
David S. Millerccc58052008-06-16 18:50:49 -07002440 current_ev = iwe_stream_add_point(info, current_ev,
2441 end_buf, &iwe,
2442 sta->u.ap.ssid);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002443
2444 if (sta->u.ap.channel > 0 &&
2445 sta->u.ap.channel <= FREQ_COUNT) {
2446 memset(&iwe, 0, sizeof(iwe));
2447 iwe.cmd = SIOCGIWFREQ;
2448 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2449 * 100000;
2450 iwe.u.freq.e = 1;
2451 current_ev = iwe_stream_add_event(
David S. Millerccc58052008-06-16 18:50:49 -07002452 info, current_ev, end_buf, &iwe,
Jouni Malinenff1d2762005-05-12 22:54:16 -04002453 IW_EV_FREQ_LEN);
2454 }
2455
2456 memset(&iwe, 0, sizeof(iwe));
2457 iwe.cmd = IWEVCUSTOM;
2458 sprintf(buf, "beacon_interval=%d",
2459 sta->listen_interval);
2460 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07002461 current_ev = iwe_stream_add_point(info, current_ev,
2462 end_buf, &iwe, buf);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002463 }
2464#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2465
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07002466 sta->last_rx_updated = IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002467
2468 /* To be continued, we should make good use of IWEVCUSTOM */
2469 }
2470
2471 spin_unlock_bh(&ap->sta_table_lock);
2472
2473 return current_ev - buffer;
2474}
2475
2476
2477static int prism2_hostapd_add_sta(struct ap_data *ap,
2478 struct prism2_hostapd_param *param)
2479{
2480 struct sta_info *sta;
2481
2482 spin_lock_bh(&ap->sta_table_lock);
2483 sta = ap_get_sta(ap, param->sta_addr);
2484 if (sta)
2485 atomic_inc(&sta->users);
2486 spin_unlock_bh(&ap->sta_table_lock);
2487
2488 if (sta == NULL) {
2489 sta = ap_add_sta(ap, param->sta_addr);
2490 if (sta == NULL)
2491 return -1;
2492 }
2493
2494 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2495 hostap_event_new_sta(sta->local->dev, sta);
2496
2497 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2498 sta->last_rx = jiffies;
2499 sta->aid = param->u.add_sta.aid;
2500 sta->capability = param->u.add_sta.capability;
2501 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2502 if (sta->tx_supp_rates & WLAN_RATE_1M)
2503 sta->supported_rates[0] = 2;
2504 if (sta->tx_supp_rates & WLAN_RATE_2M)
2505 sta->supported_rates[1] = 4;
2506 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2507 sta->supported_rates[2] = 11;
2508 if (sta->tx_supp_rates & WLAN_RATE_11M)
2509 sta->supported_rates[3] = 22;
2510 prism2_check_tx_rates(sta);
2511 atomic_dec(&sta->users);
2512 return 0;
2513}
2514
2515
2516static int prism2_hostapd_remove_sta(struct ap_data *ap,
2517 struct prism2_hostapd_param *param)
2518{
2519 struct sta_info *sta;
2520
2521 spin_lock_bh(&ap->sta_table_lock);
2522 sta = ap_get_sta(ap, param->sta_addr);
2523 if (sta) {
2524 ap_sta_hash_del(ap, sta);
2525 list_del(&sta->list);
2526 }
2527 spin_unlock_bh(&ap->sta_table_lock);
2528
2529 if (!sta)
2530 return -ENOENT;
2531
2532 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2533 hostap_event_expired_sta(sta->local->dev, sta);
2534 ap_free_sta(ap, sta);
2535
2536 return 0;
2537}
2538
2539
2540static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2541 struct prism2_hostapd_param *param)
2542{
2543 struct sta_info *sta;
2544
2545 spin_lock_bh(&ap->sta_table_lock);
2546 sta = ap_get_sta(ap, param->sta_addr);
2547 if (sta)
2548 atomic_inc(&sta->users);
2549 spin_unlock_bh(&ap->sta_table_lock);
2550
2551 if (!sta)
2552 return -ENOENT;
2553
2554 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2555
2556 atomic_dec(&sta->users);
2557
2558 return 1;
2559}
2560
2561
2562static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2563 struct prism2_hostapd_param *param)
2564{
2565 struct sta_info *sta;
2566
2567 spin_lock_bh(&ap->sta_table_lock);
2568 sta = ap_get_sta(ap, param->sta_addr);
2569 if (sta) {
2570 sta->flags |= param->u.set_flags_sta.flags_or;
2571 sta->flags &= param->u.set_flags_sta.flags_and;
2572 }
2573 spin_unlock_bh(&ap->sta_table_lock);
2574
2575 if (!sta)
2576 return -ENOENT;
2577
2578 return 0;
2579}
2580
2581
2582static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2583 struct prism2_hostapd_param *param)
2584{
2585 struct sta_info *sta;
2586 int rate;
2587
2588 spin_lock_bh(&ap->sta_table_lock);
2589 sta = ap_get_sta(ap, param->sta_addr);
2590 if (sta) {
2591 sta->rx_packets = sta->tx_packets = 0;
2592 sta->rx_bytes = sta->tx_bytes = 0;
2593 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2594 sta->tx_count[rate] = 0;
2595 sta->rx_count[rate] = 0;
2596 }
2597 }
2598 spin_unlock_bh(&ap->sta_table_lock);
2599
2600 if (!sta)
2601 return -ENOENT;
2602
2603 return 0;
2604}
2605
2606
Adrian Bunk5fad5a22006-01-14 03:09:34 +01002607int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002608{
2609 switch (param->cmd) {
2610 case PRISM2_HOSTAPD_FLUSH:
2611 ap_control_kickall(ap);
2612 return 0;
2613 case PRISM2_HOSTAPD_ADD_STA:
2614 return prism2_hostapd_add_sta(ap, param);
2615 case PRISM2_HOSTAPD_REMOVE_STA:
2616 return prism2_hostapd_remove_sta(ap, param);
2617 case PRISM2_HOSTAPD_GET_INFO_STA:
2618 return prism2_hostapd_get_info_sta(ap, param);
2619 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2620 return prism2_hostapd_set_flags_sta(ap, param);
2621 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2622 return prism2_hostapd_sta_clear_stats(ap, param);
2623 default:
2624 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2625 param->cmd);
2626 return -EOPNOTSUPP;
2627 }
2628}
2629
2630
2631/* Update station info for host-based TX rate control and return current
2632 * TX rate */
2633static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2634{
2635 int ret = sta->tx_rate;
2636 struct hostap_interface *iface;
2637 local_info_t *local;
2638
2639 iface = netdev_priv(dev);
2640 local = iface->local;
2641
2642 sta->tx_count[sta->tx_rate_idx]++;
2643 sta->tx_since_last_failure++;
2644 sta->tx_consecutive_exc = 0;
2645 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2646 sta->tx_rate_idx < sta->tx_max_rate) {
2647 /* use next higher rate */
2648 int old_rate, new_rate;
2649 old_rate = new_rate = sta->tx_rate_idx;
2650 while (new_rate < sta->tx_max_rate) {
2651 new_rate++;
2652 if (ap_tx_rate_ok(new_rate, sta, local)) {
2653 sta->tx_rate_idx = new_rate;
2654 break;
2655 }
2656 }
2657 if (old_rate != sta->tx_rate_idx) {
2658 switch (sta->tx_rate_idx) {
2659 case 0: sta->tx_rate = 10; break;
2660 case 1: sta->tx_rate = 20; break;
2661 case 2: sta->tx_rate = 55; break;
2662 case 3: sta->tx_rate = 110; break;
2663 default: sta->tx_rate = 0; break;
2664 }
Johannes Berge1749612008-10-27 15:59:26 -07002665 PDEBUG(DEBUG_AP, "%s: STA %pM TX rate raised to %d\n",
2666 dev->name, sta->addr, sta->tx_rate);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002667 }
2668 sta->tx_since_last_failure = 0;
2669 }
2670
2671 return ret;
2672}
2673
2674
2675/* Called only from software IRQ. Called for each TX frame prior possible
2676 * encryption and transmit. */
2677ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2678{
2679 struct sta_info *sta = NULL;
2680 struct sk_buff *skb = tx->skb;
2681 int set_tim, ret;
Dan Williams1ea893f2009-02-11 17:17:10 -05002682 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002683 struct hostap_skb_tx_data *meta;
2684
2685 meta = (struct hostap_skb_tx_data *) skb->cb;
2686 ret = AP_TX_CONTINUE;
2687 if (local->ap == NULL || skb->len < 10 ||
2688 meta->iface->type == HOSTAP_INTERFACE_STA)
2689 goto out;
2690
Dan Williams1ea893f2009-02-11 17:17:10 -05002691 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002692
2693 if (hdr->addr1[0] & 0x01) {
2694 /* broadcast/multicast frame - no AP related processing */
Pavel Roskinb9180992007-05-28 09:38:47 -07002695 if (local->ap->num_sta <= 0)
2696 ret = AP_TX_DROP;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002697 goto out;
2698 }
2699
2700 /* unicast packet - check whether destination STA is associated */
2701 spin_lock(&local->ap->sta_table_lock);
2702 sta = ap_get_sta(local->ap, hdr->addr1);
2703 if (sta)
2704 atomic_inc(&sta->users);
2705 spin_unlock(&local->ap->sta_table_lock);
2706
Jouni Malinen5bee7202005-08-14 19:08:39 -07002707 if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
2708 !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -04002709 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2710 meta->iface->type != HOSTAP_INTERFACE_AP) {
2711#if 0
2712 /* This can happen, e.g., when wlan0 is added to a bridge and
2713 * bridging code does not know which port is the correct target
2714 * for a unicast frame. In this case, the packet is send to all
2715 * ports of the bridge. Since this is a valid scenario, do not
2716 * print out any errors here. */
2717 if (net_ratelimit()) {
2718 printk(KERN_DEBUG "AP: drop packet to non-associated "
Johannes Berge1749612008-10-27 15:59:26 -07002719 "STA %pM\n", hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002720 }
2721#endif
2722 local->ap->tx_drop_nonassoc++;
2723 ret = AP_TX_DROP;
2724 goto out;
2725 }
2726
2727 if (sta == NULL)
2728 goto out;
2729
2730 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2731 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2732
2733 /* Set tx_rate if using host-based TX rate control */
2734 if (!local->fw_tx_rate_control)
2735 local->ap->last_tx_rate = meta->rate =
2736 ap_update_sta_tx_rate(sta, local->dev);
2737
2738 if (local->iw_mode != IW_MODE_MASTER)
2739 goto out;
2740
2741 if (!(sta->flags & WLAN_STA_PS))
2742 goto out;
2743
Jouni Malinen5bee7202005-08-14 19:08:39 -07002744 if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
2745 /* indicate to STA that more frames follow */
Dan Williams1ea893f2009-02-11 17:17:10 -05002746 hdr->frame_control |=
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08002747 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Jouni Malinen5bee7202005-08-14 19:08:39 -07002748 }
Jouni Malinenff1d2762005-05-12 22:54:16 -04002749
Jouni Malinen5bee7202005-08-14 19:08:39 -07002750 if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
2751 /* packet was already buffered and now send due to
2752 * PS poll, so do not rebuffer it */
2753 goto out;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002754 }
2755
2756 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
Johannes Berge1749612008-10-27 15:59:26 -07002757 PDEBUG(DEBUG_PS, "%s: No more space in STA (%pM)'s"
2758 "PS mode buffer\n",
2759 local->dev->name, sta->addr);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002760 /* Make sure that TIM is set for the station (it might not be
2761 * after AP wlan hw reset). */
2762 /* FIX: should fix hw reset to restore bits based on STA
2763 * buffer state.. */
2764 hostap_set_tim(local, sta->aid, 1);
2765 sta->flags |= WLAN_STA_TIM;
2766 ret = AP_TX_DROP;
2767 goto out;
2768 }
2769
2770 /* STA in PS mode, buffer frame for later delivery */
2771 set_tim = skb_queue_empty(&sta->tx_buf);
2772 skb_queue_tail(&sta->tx_buf, skb);
2773 /* FIX: could save RX time to skb and expire buffered frames after
2774 * some time if STA does not poll for them */
2775
2776 if (set_tim) {
2777 if (sta->flags & WLAN_STA_TIM)
2778 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2779 sta->aid);
2780 hostap_set_tim(local, sta->aid, 1);
2781 sta->flags |= WLAN_STA_TIM;
2782 }
2783
2784 ret = AP_TX_BUFFERED;
2785
2786 out:
2787 if (sta != NULL) {
2788 if (ret == AP_TX_CONTINUE ||
2789 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2790 sta->tx_packets++;
2791 sta->tx_bytes += skb->len;
2792 sta->last_tx = jiffies;
2793 }
2794
2795 if ((ret == AP_TX_CONTINUE ||
2796 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2797 sta->crypt && tx->host_encrypt) {
2798 tx->crypt = sta->crypt;
2799 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2800 * be called to release sta info
2801 * later */
2802 } else
2803 atomic_dec(&sta->users);
2804 }
2805
2806 return ret;
2807}
2808
2809
2810void hostap_handle_sta_release(void *ptr)
2811{
2812 struct sta_info *sta = ptr;
2813 atomic_dec(&sta->users);
2814}
2815
2816
2817/* Called only as a tasklet (software IRQ) */
2818void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2819{
2820 struct sta_info *sta;
Dan Williams1ea893f2009-02-11 17:17:10 -05002821 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002822 struct hostap_skb_tx_data *meta;
2823
Dan Williams1ea893f2009-02-11 17:17:10 -05002824 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002825 meta = (struct hostap_skb_tx_data *) skb->cb;
2826
2827 spin_lock(&local->ap->sta_table_lock);
2828 sta = ap_get_sta(local->ap, hdr->addr1);
2829 if (!sta) {
2830 spin_unlock(&local->ap->sta_table_lock);
Johannes Berge1749612008-10-27 15:59:26 -07002831 PDEBUG(DEBUG_AP, "%s: Could not find STA %pM"
Joe Perches0795af52007-10-03 17:59:30 -07002832 " for this TX error (@%lu)\n",
Johannes Berge1749612008-10-27 15:59:26 -07002833 local->dev->name, hdr->addr1, jiffies);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002834 return;
2835 }
2836
2837 sta->tx_since_last_failure = 0;
2838 sta->tx_consecutive_exc++;
Jeff Garzik74fae822005-07-31 13:08:32 -04002839
Jouni Malinenff1d2762005-05-12 22:54:16 -04002840 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2841 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2842 /* use next lower rate */
2843 int old, rate;
2844 old = rate = sta->tx_rate_idx;
2845 while (rate > 0) {
2846 rate--;
2847 if (ap_tx_rate_ok(rate, sta, local)) {
2848 sta->tx_rate_idx = rate;
2849 break;
2850 }
2851 }
2852 if (old != sta->tx_rate_idx) {
2853 switch (sta->tx_rate_idx) {
2854 case 0: sta->tx_rate = 10; break;
2855 case 1: sta->tx_rate = 20; break;
2856 case 2: sta->tx_rate = 55; break;
2857 case 3: sta->tx_rate = 110; break;
2858 default: sta->tx_rate = 0; break;
2859 }
Johannes Berge1749612008-10-27 15:59:26 -07002860 PDEBUG(DEBUG_AP,
2861 "%s: STA %pM TX rate lowered to %d\n",
2862 local->dev->name, sta->addr, sta->tx_rate);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002863 }
2864 sta->tx_consecutive_exc = 0;
2865 }
2866 spin_unlock(&local->ap->sta_table_lock);
2867}
2868
2869
2870static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2871 int pwrmgt, int type, int stype)
2872{
2873 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2874 sta->flags |= WLAN_STA_PS;
Johannes Berge1749612008-10-27 15:59:26 -07002875 PDEBUG(DEBUG_PS2, "STA %pM changed to use PS "
Jouni Malinenff1d2762005-05-12 22:54:16 -04002876 "mode (type=0x%02X, stype=0x%02X)\n",
Johannes Berge1749612008-10-27 15:59:26 -07002877 sta->addr, type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002878 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2879 sta->flags &= ~WLAN_STA_PS;
Johannes Berge1749612008-10-27 15:59:26 -07002880 PDEBUG(DEBUG_PS2, "STA %pM changed to not use "
Jouni Malinenff1d2762005-05-12 22:54:16 -04002881 "PS mode (type=0x%02X, stype=0x%02X)\n",
Johannes Berge1749612008-10-27 15:59:26 -07002882 sta->addr, type >> 2, stype >> 4);
Jouni Malinen4339d322005-08-14 19:08:44 -07002883 if (type != IEEE80211_FTYPE_CTL ||
2884 stype != IEEE80211_STYPE_PSPOLL)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002885 schedule_packet_send(local, sta);
2886 }
2887}
2888
2889
2890/* Called only as a tasklet (software IRQ). Called for each RX frame to update
Dan Williams1ea893f2009-02-11 17:17:10 -05002891 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2892int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04002893{
2894 struct sta_info *sta;
2895 u16 fc;
2896
2897 spin_lock(&local->ap->sta_table_lock);
2898 sta = ap_get_sta(local->ap, hdr->addr2);
2899 if (sta)
2900 atomic_inc(&sta->users);
2901 spin_unlock(&local->ap->sta_table_lock);
2902
2903 if (!sta)
2904 return -1;
2905
Dan Williams1ea893f2009-02-11 17:17:10 -05002906 fc = le16_to_cpu(hdr->frame_control);
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002907 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
Dan Williams1ea893f2009-02-11 17:17:10 -05002908 fc & IEEE80211_FCTL_FTYPE,
2909 fc & IEEE80211_FCTL_STYPE);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002910
2911 atomic_dec(&sta->users);
2912 return 0;
2913}
2914
2915
2916/* Called only as a tasklet (software IRQ). Called for each RX frame after
2917 * getting RX header and payload from hardware. */
2918ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2919 struct sk_buff *skb,
2920 struct hostap_80211_rx_status *rx_stats,
2921 int wds)
2922{
2923 int ret;
2924 struct sta_info *sta;
2925 u16 fc, type, stype;
Dan Williams1ea893f2009-02-11 17:17:10 -05002926 struct ieee80211_hdr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002927
2928 if (local->ap == NULL)
2929 return AP_RX_CONTINUE;
2930
Dan Williams1ea893f2009-02-11 17:17:10 -05002931 hdr = (struct ieee80211_hdr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002932
Dan Williams1ea893f2009-02-11 17:17:10 -05002933 fc = le16_to_cpu(hdr->frame_control);
2934 type = fc & IEEE80211_FCTL_FTYPE;
2935 stype = fc & IEEE80211_FCTL_STYPE;
Jouni Malinenff1d2762005-05-12 22:54:16 -04002936
2937 spin_lock(&local->ap->sta_table_lock);
2938 sta = ap_get_sta(local->ap, hdr->addr2);
2939 if (sta)
2940 atomic_inc(&sta->users);
2941 spin_unlock(&local->ap->sta_table_lock);
2942
2943 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2944 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2945 else
2946 ret = AP_RX_CONTINUE;
2947
2948
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002949 if (fc & IEEE80211_FCTL_TODS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002950 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2951 if (local->hostapd) {
2952 prism2_rx_80211(local->apdev, skb, rx_stats,
2953 PRISM2_RX_NON_ASSOC);
2954#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2955 } else {
2956 printk(KERN_DEBUG "%s: dropped received packet"
Johannes Berge1749612008-10-27 15:59:26 -07002957 " from non-associated STA %pM"
Jouni Malinenff1d2762005-05-12 22:54:16 -04002958 " (type=0x%02x, subtype=0x%02x)\n",
Johannes Berge1749612008-10-27 15:59:26 -07002959 dev->name, hdr->addr2,
Jouni Malinen4339d322005-08-14 19:08:44 -07002960 type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002961 hostap_rx(dev, skb, rx_stats);
2962#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2963 }
2964 ret = AP_RX_EXIT;
2965 goto out;
2966 }
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07002967 } else if (fc & IEEE80211_FCTL_FROMDS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04002968 if (!wds) {
2969 /* FromDS frame - not for us; probably
2970 * broadcast/multicast in another BSS - drop */
2971 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2972 printk(KERN_DEBUG "Odd.. FromDS packet "
2973 "received with own BSSID\n");
2974 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2975 }
2976 ret = AP_RX_DROP;
2977 goto out;
2978 }
Jouni Malinen4339d322005-08-14 19:08:44 -07002979 } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
Jouni Malinenff1d2762005-05-12 22:54:16 -04002980 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2981
2982 if (local->hostapd) {
2983 prism2_rx_80211(local->apdev, skb, rx_stats,
2984 PRISM2_RX_NON_ASSOC);
2985#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2986 } else {
2987 /* At least Lucent f/w seems to send data::nullfunc
2988 * frames with no ToDS flag when the current AP returns
2989 * after being unavailable for some time. Speed up
2990 * re-association by informing the station about it not
2991 * being associated. */
Johannes Berge1749612008-10-27 15:59:26 -07002992 printk(KERN_DEBUG "%s: rejected received nullfunc frame"
2993 " without ToDS from not associated STA %pM\n",
2994 dev->name, hdr->addr2);
Jouni Malinenff1d2762005-05-12 22:54:16 -04002995 hostap_rx(dev, skb, rx_stats);
2996#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2997 }
2998 ret = AP_RX_EXIT;
2999 goto out;
Jouni Malinen4339d322005-08-14 19:08:44 -07003000 } else if (stype == IEEE80211_STYPE_NULLFUNC) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003001 /* At least Lucent cards seem to send periodic nullfunc
3002 * frames with ToDS. Let these through to update SQ
3003 * stats and PS state. Nullfunc frames do not contain
3004 * any data and they will be dropped below. */
3005 } else {
3006 /* If BSSID (Addr3) is foreign, this frame is a normal
3007 * broadcast frame from an IBSS network. Drop it silently.
3008 * If BSSID is own, report the dropping of this frame. */
3009 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
Johannes Berge1749612008-10-27 15:59:26 -07003010 printk(KERN_DEBUG "%s: dropped received packet from %pM"
3011 " with no ToDS flag "
Joe Perches0795af52007-10-03 17:59:30 -07003012 "(type=0x%02x, subtype=0x%02x)\n", dev->name,
Johannes Berge1749612008-10-27 15:59:26 -07003013 hdr->addr2, type >> 2, stype >> 4);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003014 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3015 }
3016 ret = AP_RX_DROP;
3017 goto out;
3018 }
3019
3020 if (sta) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07003021 hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
Jouni Malinenff1d2762005-05-12 22:54:16 -04003022 type, stype);
3023
3024 sta->rx_packets++;
3025 sta->rx_bytes += skb->len;
3026 sta->last_rx = jiffies;
3027 }
3028
Jouni Malinen4339d322005-08-14 19:08:44 -07003029 if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -07003030 fc & IEEE80211_FCTL_TODS) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003031 if (local->hostapd) {
3032 prism2_rx_80211(local->apdev, skb, rx_stats,
3033 PRISM2_RX_NULLFUNC_ACK);
3034#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3035 } else {
3036 /* some STA f/w's seem to require control::ACK frame
3037 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3038 * from Compaq) does not send this.. Try to generate
3039 * ACK for these frames from the host driver to make
3040 * power saving work with, e.g., Lucent WaveLAN f/w */
3041 hostap_rx(dev, skb, rx_stats);
3042#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3043 }
3044 ret = AP_RX_EXIT;
3045 goto out;
3046 }
3047
3048 out:
3049 if (sta)
3050 atomic_dec(&sta->users);
3051
3052 return ret;
3053}
3054
3055
3056/* Called only as a tasklet (software IRQ) */
3057int hostap_handle_sta_crypto(local_info_t *local,
Dan Williams1ea893f2009-02-11 17:17:10 -05003058 struct ieee80211_hdr *hdr,
John W. Linville274bfb82008-10-29 11:35:05 -04003059 struct lib80211_crypt_data **crypt,
Jouni Malinen62fe7e32005-07-30 20:43:20 -07003060 void **sta_ptr)
Jouni Malinenff1d2762005-05-12 22:54:16 -04003061{
3062 struct sta_info *sta;
3063
3064 spin_lock(&local->ap->sta_table_lock);
3065 sta = ap_get_sta(local->ap, hdr->addr2);
3066 if (sta)
3067 atomic_inc(&sta->users);
3068 spin_unlock(&local->ap->sta_table_lock);
3069
3070 if (!sta)
3071 return -1;
3072
3073 if (sta->crypt) {
3074 *crypt = sta->crypt;
3075 *sta_ptr = sta;
3076 /* hostap_handle_sta_release() will be called to release STA
3077 * info */
3078 } else
3079 atomic_dec(&sta->users);
3080
3081 return 0;
3082}
3083
3084
3085/* Called only as a tasklet (software IRQ) */
3086int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3087{
3088 struct sta_info *sta;
3089 int ret = 0;
3090
3091 spin_lock(&ap->sta_table_lock);
3092 sta = ap_get_sta(ap, sta_addr);
3093 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3094 ret = 1;
3095 spin_unlock(&ap->sta_table_lock);
3096
3097 return ret;
3098}
3099
3100
3101/* Called only as a tasklet (software IRQ) */
3102int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3103{
3104 struct sta_info *sta;
3105 int ret = 0;
3106
3107 spin_lock(&ap->sta_table_lock);
3108 sta = ap_get_sta(ap, sta_addr);
3109 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3110 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3111 ap->local->ieee_802_1x == 0))
3112 ret = 1;
3113 spin_unlock(&ap->sta_table_lock);
3114
3115 return ret;
3116}
3117
3118
3119/* Called only as a tasklet (software IRQ) */
3120int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3121{
3122 struct sta_info *sta;
3123 int ret = 1;
3124
3125 if (!ap)
3126 return -1;
3127
3128 spin_lock(&ap->sta_table_lock);
3129 sta = ap_get_sta(ap, sta_addr);
3130 if (sta)
3131 ret = 0;
3132 spin_unlock(&ap->sta_table_lock);
3133
3134 if (ret == 1) {
3135 sta = ap_add_sta(ap, sta_addr);
3136 if (!sta)
Adrian Bunk54b85f42006-03-19 19:21:45 -08003137 return -1;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003138 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3139 sta->ap = 1;
3140 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3141 /* No way of knowing which rates are supported since we did not
3142 * get supported rates element from beacon/assoc req. Assume
3143 * that remote end supports all 802.11b rates. */
3144 sta->supported_rates[0] = 0x82;
3145 sta->supported_rates[1] = 0x84;
3146 sta->supported_rates[2] = 0x0b;
3147 sta->supported_rates[3] = 0x16;
3148 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3149 WLAN_RATE_5M5 | WLAN_RATE_11M;
3150 sta->tx_rate = 110;
3151 sta->tx_max_rate = sta->tx_rate_idx = 3;
3152 }
3153
3154 return ret;
3155}
3156
3157
3158/* Called only as a tasklet (software IRQ) */
3159int hostap_update_rx_stats(struct ap_data *ap,
Dan Williams1ea893f2009-02-11 17:17:10 -05003160 struct ieee80211_hdr *hdr,
Jouni Malinenff1d2762005-05-12 22:54:16 -04003161 struct hostap_80211_rx_status *rx_stats)
3162{
3163 struct sta_info *sta;
3164
3165 if (!ap)
3166 return -1;
3167
3168 spin_lock(&ap->sta_table_lock);
3169 sta = ap_get_sta(ap, hdr->addr2);
3170 if (sta) {
3171 sta->last_rx_silence = rx_stats->noise;
3172 sta->last_rx_signal = rx_stats->signal;
3173 sta->last_rx_rate = rx_stats->rate;
Jean Tourrilhesc28df16e2005-09-23 21:58:59 -07003174 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003175 if (rx_stats->rate == 10)
3176 sta->rx_count[0]++;
3177 else if (rx_stats->rate == 20)
3178 sta->rx_count[1]++;
3179 else if (rx_stats->rate == 55)
3180 sta->rx_count[2]++;
3181 else if (rx_stats->rate == 110)
3182 sta->rx_count[3]++;
3183 }
3184 spin_unlock(&ap->sta_table_lock);
3185
3186 return sta ? 0 : -1;
3187}
3188
3189
3190void hostap_update_rates(local_info_t *local)
3191{
Matthias Kaehlckec1505732007-05-28 09:38:48 -07003192 struct sta_info *sta;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003193 struct ap_data *ap = local->ap;
3194
3195 if (!ap)
3196 return;
3197
3198 spin_lock_bh(&ap->sta_table_lock);
Matthias Kaehlckec1505732007-05-28 09:38:48 -07003199 list_for_each_entry(sta, &ap->sta_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003200 prism2_check_tx_rates(sta);
3201 }
3202 spin_unlock_bh(&ap->sta_table_lock);
3203}
3204
3205
Adrian Bunk5fad5a22006-01-14 03:09:34 +01003206void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
John W. Linville274bfb82008-10-29 11:35:05 -04003207 struct lib80211_crypt_data ***crypt)
Jouni Malinenff1d2762005-05-12 22:54:16 -04003208{
3209 struct sta_info *sta;
3210
3211 spin_lock_bh(&ap->sta_table_lock);
3212 sta = ap_get_sta(ap, addr);
3213 if (sta)
3214 atomic_inc(&sta->users);
3215 spin_unlock_bh(&ap->sta_table_lock);
3216
3217 if (!sta && permanent)
3218 sta = ap_add_sta(ap, addr);
3219
3220 if (!sta)
3221 return NULL;
3222
3223 if (permanent)
3224 sta->flags |= WLAN_STA_PERM;
3225
3226 *crypt = &sta->crypt;
3227
3228 return sta;
3229}
3230
3231
3232void hostap_add_wds_links(local_info_t *local)
3233{
3234 struct ap_data *ap = local->ap;
Matthias Kaehlckec1505732007-05-28 09:38:48 -07003235 struct sta_info *sta;
Jouni Malinenff1d2762005-05-12 22:54:16 -04003236
3237 spin_lock_bh(&ap->sta_table_lock);
Matthias Kaehlckec1505732007-05-28 09:38:48 -07003238 list_for_each_entry(sta, &ap->sta_list, list) {
Jouni Malinenff1d2762005-05-12 22:54:16 -04003239 if (sta->ap)
3240 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3241 }
3242 spin_unlock_bh(&ap->sta_table_lock);
3243
3244 schedule_work(&local->ap->wds_oper_queue);
3245}
3246
3247
3248void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3249{
3250 struct wds_oper_data *entry;
3251
3252 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3253 if (!entry)
3254 return;
3255 memcpy(entry->addr, addr, ETH_ALEN);
3256 entry->type = type;
3257 spin_lock_bh(&local->lock);
3258 entry->next = local->ap->wds_oper_entries;
3259 local->ap->wds_oper_entries = entry;
3260 spin_unlock_bh(&local->lock);
3261
3262 schedule_work(&local->ap->wds_oper_queue);
3263}
3264
3265
3266EXPORT_SYMBOL(hostap_init_data);
3267EXPORT_SYMBOL(hostap_init_ap_proc);
3268EXPORT_SYMBOL(hostap_free_data);
3269EXPORT_SYMBOL(hostap_check_sta_fw_version);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003270EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
Jouni Malinenff1d2762005-05-12 22:54:16 -04003271#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
Jouni Malinenff1d2762005-05-12 22:54:16 -04003272#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */