add free bcm43xx driver as patch for brcm-2.6, needs more testing and Makefile change...
[openwrt/staging/mkresin.git] / openwrt / target / linux / brcm-2.6 / patches / 005-bcm43xx-dscape-060328.patch
1 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c
2 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c 2006-03-28 22:16:14.000000000 +0200
4 @@ -0,0 +1,499 @@
5 +/*
6 +
7 + Broadcom BCM43xx wireless driver
8 +
9 + debugfs driver debugging code
10 +
11 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
12 +
13 + This program is free software; you can redistribute it and/or modify
14 + it under the terms of the GNU General Public License as published by
15 + the Free Software Foundation; either version 2 of the License, or
16 + (at your option) any later version.
17 +
18 + This program is distributed in the hope that it will be useful,
19 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 + GNU General Public License for more details.
22 +
23 + You should have received a copy of the GNU General Public License
24 + along with this program; see the file COPYING. If not, write to
25 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
26 + Boston, MA 02110-1301, USA.
27 +
28 +*/
29 +
30 +
31 +
32 +#include <linux/fs.h>
33 +#include <linux/debugfs.h>
34 +#include <linux/slab.h>
35 +#include <linux/netdevice.h>
36 +#include <linux/pci.h>
37 +#include <asm/io.h>
38 +
39 +#include "bcm43xx.h"
40 +#include "bcm43xx_main.h"
41 +#include "bcm43xx_debugfs.h"
42 +#include "bcm43xx_dma.h"
43 +#include "bcm43xx_pio.h"
44 +#include "bcm43xx_xmit.h"
45 +
46 +#define REALLY_BIG_BUFFER_SIZE (1024*256)
47 +
48 +static struct bcm43xx_debugfs fs;
49 +static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
50 +static DECLARE_MUTEX(big_buffer_sem);
51 +
52 +
53 +static ssize_t write_file_dummy(struct file *file, const char __user *buf,
54 + size_t count, loff_t *ppos)
55 +{
56 + return count;
57 +}
58 +
59 +static int open_file_generic(struct inode *inode, struct file *file)
60 +{
61 + file->private_data = inode->u.generic_ip;
62 + return 0;
63 +}
64 +
65 +#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
66 +
67 +static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
68 + size_t count, loff_t *ppos)
69 +{
70 + const size_t len = REALLY_BIG_BUFFER_SIZE;
71 +
72 + struct bcm43xx_private *bcm = file->private_data;
73 + char *buf = really_big_buffer;
74 + size_t pos = 0;
75 + ssize_t res;
76 + struct net_device *net_dev;
77 + struct pci_dev *pci_dev;
78 + unsigned long flags;
79 + u16 tmp16;
80 + int i;
81 +
82 + down(&big_buffer_sem);
83 +
84 + bcm43xx_lock_mmio(bcm, flags);
85 + if (!bcm->initialized) {
86 + fappend("Board not initialized.\n");
87 + goto out;
88 + }
89 + net_dev = bcm->net_dev;
90 + pci_dev = bcm->pci_dev;
91 +
92 + /* This is where the information is written to the "devinfo" file */
93 + fappend("*** %s devinfo ***\n", net_dev->name);
94 + fappend("vendor: 0x%04x device: 0x%04x\n",
95 + pci_dev->vendor, pci_dev->device);
96 + fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
97 + pci_dev->subsystem_vendor, pci_dev->subsystem_device);
98 + fappend("IRQ: %d\n", bcm->irq);
99 + fappend("mmio_addr: 0x%p mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
100 + fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
101 + if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
102 + fappend("Radio disabled by hardware!\n");
103 + if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
104 + fappend("Radio disabled by hardware!\n");
105 + fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm->board_vendor,
106 + bcm->board_type);
107 +
108 + fappend("\nCores:\n");
109 +#define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
110 + "rev: 0x%02x, index: 0x%02x\n", \
111 + (info).available \
112 + ? "available" : "nonavailable", \
113 + (info).enabled \
114 + ? "enabled" : "disabled", \
115 + (info).id, (info).rev, (info).index)
116 + fappend_core("CHIPCOMMON", bcm->core_chipcommon);
117 + fappend_core("PCI", bcm->core_pci);
118 + fappend_core("first 80211", bcm->core_80211[0]);
119 + fappend_core("second 80211", bcm->core_80211[1]);
120 +#undef fappend_core
121 + tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
122 + fappend("LEDs: ");
123 + for (i = 0; i < BCM43xx_NR_LEDS; i++)
124 + fappend("%d ", !!(tmp16 & (1 << i)));
125 + fappend("\n");
126 +
127 +out:
128 + bcm43xx_unlock_mmio(bcm, flags);
129 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
130 + up(&big_buffer_sem);
131 + return res;
132 +}
133 +
134 +static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
135 + size_t count, loff_t *ppos)
136 +{
137 + const size_t len = REALLY_BIG_BUFFER_SIZE;
138 +
139 + char *buf = really_big_buffer;
140 + size_t pos = 0;
141 + ssize_t res;
142 +
143 + down(&big_buffer_sem);
144 +
145 + /* This is where the information is written to the "driver" file */
146 + fappend(KBUILD_MODNAME " driver\n");
147 + fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
148 +
149 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
150 + up(&big_buffer_sem);
151 + return res;
152 +}
153 +
154 +static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
155 + size_t count, loff_t *ppos)
156 +{
157 + const size_t len = REALLY_BIG_BUFFER_SIZE;
158 +
159 + struct bcm43xx_private *bcm = file->private_data;
160 + char *buf = really_big_buffer;
161 + size_t pos = 0;
162 + ssize_t res;
163 + unsigned long flags;
164 +
165 + down(&big_buffer_sem);
166 + bcm43xx_lock_mmio(bcm, flags);
167 + if (!bcm->initialized) {
168 + fappend("Board not initialized.\n");
169 + goto out;
170 + }
171 +
172 + /* This is where the information is written to the "sprom_dump" file */
173 + fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
174 +
175 +out:
176 + bcm43xx_unlock_mmio(bcm, flags);
177 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
178 + up(&big_buffer_sem);
179 + return res;
180 +}
181 +
182 +static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
183 + size_t count, loff_t *ppos)
184 +{
185 + const size_t len = REALLY_BIG_BUFFER_SIZE;
186 +
187 + struct bcm43xx_private *bcm = file->private_data;
188 + char *buf = really_big_buffer;
189 + size_t pos = 0;
190 + ssize_t res;
191 + unsigned long flags;
192 + u64 tsf;
193 +
194 + down(&big_buffer_sem);
195 + bcm43xx_lock_mmio(bcm, flags);
196 + if (!bcm->initialized) {
197 + fappend("Board not initialized.\n");
198 + goto out;
199 + }
200 + bcm43xx_tsf_read(bcm, &tsf);
201 + fappend("0x%08x%08x\n",
202 + (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
203 + (unsigned int)(tsf & 0xFFFFFFFFULL));
204 +
205 +out:
206 + bcm43xx_unlock_mmio(bcm, flags);
207 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
208 + up(&big_buffer_sem);
209 + return res;
210 +}
211 +
212 +static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
213 + size_t count, loff_t *ppos)
214 +{
215 + struct bcm43xx_private *bcm = file->private_data;
216 + char *buf = really_big_buffer;
217 + ssize_t buf_size;
218 + ssize_t res;
219 + unsigned long flags;
220 + u64 tsf;
221 +
222 + buf_size = min(count, sizeof (really_big_buffer) - 1);
223 + down(&big_buffer_sem);
224 + if (copy_from_user(buf, user_buf, buf_size)) {
225 + res = -EFAULT;
226 + goto out_up;
227 + }
228 + bcm43xx_lock_mmio(bcm, flags);
229 + if (!bcm->initialized) {
230 + printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
231 + res = -EFAULT;
232 + goto out_unlock;
233 + }
234 + if (sscanf(buf, "%lli", &tsf) != 1) {
235 + printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
236 + res = -EINVAL;
237 + goto out_unlock;
238 + }
239 + bcm43xx_tsf_write(bcm, tsf);
240 + res = buf_size;
241 +
242 +out_unlock:
243 + bcm43xx_unlock_mmio(bcm, flags);
244 +out_up:
245 + up(&big_buffer_sem);
246 + return res;
247 +}
248 +
249 +static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
250 + size_t count, loff_t *ppos)
251 +{
252 + const size_t len = REALLY_BIG_BUFFER_SIZE;
253 +
254 + struct bcm43xx_private *bcm = file->private_data;
255 + char *buf = really_big_buffer;
256 + size_t pos = 0;
257 + ssize_t res;
258 + unsigned long flags;
259 + struct bcm43xx_dfsentry *e;
260 + struct bcm43xx_xmitstatus *status;
261 + int i, cnt, j = 0;
262 +
263 + down(&big_buffer_sem);
264 + bcm43xx_lock(bcm, flags);
265 +
266 + fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
267 + BCM43xx_NR_LOGGED_XMITSTATUS);
268 + e = bcm->dfsentry;
269 + if (e->xmitstatus_printing == 0) {
270 + /* At the beginning, make a copy of all data to avoid
271 + * concurrency, as this function is called multiple
272 + * times for big logs. Without copying, the data might
273 + * change between reads. This would result in total trash.
274 + */
275 + e->xmitstatus_printing = 1;
276 + e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
277 + e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
278 + memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
279 + BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
280 + }
281 + i = e->saved_xmitstatus_ptr - 1;
282 + if (i < 0)
283 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
284 + cnt = e->saved_xmitstatus_cnt;
285 + while (cnt) {
286 + status = e->xmitstatus_print_buffer + i;
287 + fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
288 + "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
289 + "unk: 0x%04x\n", j,
290 + status->cookie, status->flags,
291 + status->cnt1, status->cnt2, status->seq,
292 + status->unknown);
293 + j++;
294 + cnt--;
295 + i--;
296 + if (i < 0)
297 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
298 + }
299 +
300 + bcm43xx_unlock(bcm, flags);
301 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
302 + bcm43xx_lock(bcm, flags);
303 + if (*ppos == pos) {
304 + /* Done. Drop the copied data. */
305 + e->xmitstatus_printing = 0;
306 + }
307 + bcm43xx_unlock(bcm, flags);
308 + up(&big_buffer_sem);
309 + return res;
310 +}
311 +
312 +#undef fappend
313 +
314 +
315 +static struct file_operations devinfo_fops = {
316 + .read = devinfo_read_file,
317 + .write = write_file_dummy,
318 + .open = open_file_generic,
319 +};
320 +
321 +static struct file_operations spromdump_fops = {
322 + .read = spromdump_read_file,
323 + .write = write_file_dummy,
324 + .open = open_file_generic,
325 +};
326 +
327 +static struct file_operations drvinfo_fops = {
328 + .read = drvinfo_read_file,
329 + .write = write_file_dummy,
330 + .open = open_file_generic,
331 +};
332 +
333 +static struct file_operations tsf_fops = {
334 + .read = tsf_read_file,
335 + .write = tsf_write_file,
336 + .open = open_file_generic,
337 +};
338 +
339 +static struct file_operations txstat_fops = {
340 + .read = txstat_read_file,
341 + .write = write_file_dummy,
342 + .open = open_file_generic,
343 +};
344 +
345 +
346 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
347 +{
348 + struct bcm43xx_dfsentry *e;
349 + char devdir[IFNAMSIZ];
350 +
351 + assert(bcm);
352 + e = kzalloc(sizeof(*e), GFP_KERNEL);
353 + if (!e) {
354 + printk(KERN_ERR PFX "out of memory\n");
355 + return;
356 + }
357 + e->bcm = bcm;
358 + e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
359 + * sizeof(*(e->xmitstatus_buffer)),
360 + GFP_KERNEL);
361 + if (!e->xmitstatus_buffer) {
362 + printk(KERN_ERR PFX "out of memory\n");
363 + kfree(e);
364 + return;
365 + }
366 + e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
367 + * sizeof(*(e->xmitstatus_buffer)),
368 + GFP_KERNEL);
369 + if (!e->xmitstatus_print_buffer) {
370 + printk(KERN_ERR PFX "out of memory\n");
371 + kfree(e);
372 + return;
373 + }
374 +
375 +
376 + bcm->dfsentry = e;
377 +
378 + strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
379 + e->subdir = debugfs_create_dir(devdir, fs.root);
380 + e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
381 + bcm, &devinfo_fops);
382 + if (!e->dentry_devinfo)
383 + printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
384 + e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
385 + bcm, &spromdump_fops);
386 + if (!e->dentry_spromdump)
387 + printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
388 + e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
389 + bcm, &tsf_fops);
390 + if (!e->dentry_tsf)
391 + printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
392 + e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
393 + bcm, &txstat_fops);
394 + if (!e->dentry_txstat)
395 + printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
396 +}
397 +
398 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
399 +{
400 + struct bcm43xx_dfsentry *e;
401 +
402 + if (!bcm)
403 + return;
404 +
405 + e = bcm->dfsentry;
406 + assert(e);
407 + debugfs_remove(e->dentry_spromdump);
408 + debugfs_remove(e->dentry_devinfo);
409 + debugfs_remove(e->dentry_tsf);
410 + debugfs_remove(e->dentry_txstat);
411 + debugfs_remove(e->subdir);
412 + kfree(e->xmitstatus_buffer);
413 + kfree(e->xmitstatus_print_buffer);
414 + kfree(e);
415 +}
416 +
417 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
418 + struct bcm43xx_xmitstatus *status)
419 +{
420 + struct bcm43xx_dfsentry *e;
421 + struct bcm43xx_xmitstatus *savedstatus;
422 +
423 + /* This is protected by bcm->_lock */
424 + e = bcm->dfsentry;
425 + assert(e);
426 + savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
427 + memcpy(savedstatus, status, sizeof(*status));
428 + e->xmitstatus_ptr++;
429 + if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
430 + e->xmitstatus_ptr = 0;
431 + if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
432 + e->xmitstatus_cnt++;
433 +}
434 +
435 +void bcm43xx_debugfs_init(void)
436 +{
437 + memset(&fs, 0, sizeof(fs));
438 + fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
439 + if (!fs.root)
440 + printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
441 + fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
442 + if (!fs.dentry_driverinfo)
443 + printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
444 +}
445 +
446 +void bcm43xx_debugfs_exit(void)
447 +{
448 + debugfs_remove(fs.dentry_driverinfo);
449 + debugfs_remove(fs.root);
450 +}
451 +
452 +void bcm43xx_printk_dump(const char *data,
453 + size_t size,
454 + const char *description)
455 +{
456 + size_t i;
457 + char c;
458 +
459 + printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
460 + description, size);
461 + for (i = 0; i < size; i++) {
462 + c = data[i];
463 + if (i % 8 == 0)
464 + printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
465 + else
466 + printk("0x%02x, ", c & 0xff);
467 + }
468 + printk("\n");
469 +}
470 +
471 +void bcm43xx_printk_bitdump(const unsigned char *data,
472 + size_t bytes, int msb_to_lsb,
473 + const char *description)
474 +{
475 + size_t i;
476 + int j;
477 + const unsigned char *d;
478 +
479 + printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
480 + description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
481 + for (i = 0; i < bytes; i++) {
482 + d = data + i;
483 + if (i % 8 == 0)
484 + printk("\n" KERN_INFO PFX "0x%08x: ", i);
485 + if (msb_to_lsb) {
486 + for (j = 7; j >= 0; j--) {
487 + if (*d & (1 << j))
488 + printk("1");
489 + else
490 + printk("0");
491 + }
492 + } else {
493 + for (j = 0; j < 8; j++) {
494 + if (*d & (1 << j))
495 + printk("1");
496 + else
497 + printk("0");
498 + }
499 + }
500 + printk(" ");
501 + }
502 + printk("\n");
503 +}
504 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h
505 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h 1970-01-01 01:00:00.000000000 +0100
506 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h 2006-03-28 22:16:14.000000000 +0200
507 @@ -0,0 +1,117 @@
508 +#ifndef BCM43xx_DEBUGFS_H_
509 +#define BCM43xx_DEBUGFS_H_
510 +
511 +struct bcm43xx_private;
512 +struct bcm43xx_xmitstatus;
513 +
514 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
515 +
516 +#include <linux/list.h>
517 +#include <asm/semaphore.h>
518 +
519 +struct dentry;
520 +
521 +/* limited by the size of the "really_big_buffer" */
522 +#define BCM43xx_NR_LOGGED_XMITSTATUS 100
523 +
524 +struct bcm43xx_dfsentry {
525 + struct dentry *subdir;
526 + struct dentry *dentry_devinfo;
527 + struct dentry *dentry_spromdump;
528 + struct dentry *dentry_tsf;
529 + struct dentry *dentry_txstat;
530 +
531 + struct bcm43xx_private *bcm;
532 +
533 + /* saved xmitstatus. */
534 + struct bcm43xx_xmitstatus *xmitstatus_buffer;
535 + int xmitstatus_ptr;
536 + int xmitstatus_cnt;
537 + /* We need a seperate buffer while printing to avoid
538 + * concurrency issues. (New xmitstatus can arrive
539 + * while we are printing).
540 + */
541 + struct bcm43xx_xmitstatus *xmitstatus_print_buffer;
542 + int saved_xmitstatus_ptr;
543 + int saved_xmitstatus_cnt;
544 + int xmitstatus_printing;
545 +};
546 +
547 +struct bcm43xx_debugfs {
548 + struct dentry *root;
549 + struct dentry *dentry_driverinfo;
550 +};
551 +
552 +void bcm43xx_debugfs_init(void);
553 +void bcm43xx_debugfs_exit(void);
554 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm);
555 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm);
556 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
557 + struct bcm43xx_xmitstatus *status);
558 +
559 +/* Debug helper: Dump binary data through printk. */
560 +void bcm43xx_printk_dump(const char *data,
561 + size_t size,
562 + const char *description);
563 +/* Debug helper: Dump bitwise binary data through printk. */
564 +void bcm43xx_printk_bitdump(const unsigned char *data,
565 + size_t bytes, int msb_to_lsb,
566 + const char *description);
567 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) \
568 + do { \
569 + bcm43xx_printk_bitdump((const unsigned char *)(pointer), \
570 + sizeof(*(pointer)), \
571 + (msb_to_lsb), \
572 + (description)); \
573 + } while (0)
574 +
575 +#else /* CONFIG_BCM43XX_D80211_DEBUG*/
576 +
577 +static inline
578 +void bcm43xx_debugfs_init(void) { }
579 +static inline
580 +void bcm43xx_debugfs_exit(void) { }
581 +static inline
582 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm) { }
583 +static inline
584 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm) { }
585 +static inline
586 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
587 + struct bcm43xx_xmitstatus *status) { }
588 +
589 +static inline
590 +void bcm43xx_printk_dump(const char *data,
591 + size_t size,
592 + const char *description)
593 +{
594 +}
595 +static inline
596 +void bcm43xx_printk_bitdump(const unsigned char *data,
597 + size_t bytes, int msb_to_lsb,
598 + const char *description)
599 +{
600 +}
601 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) do { /* nothing */ } while (0)
602 +
603 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
604 +
605 +/* Ugly helper macros to make incomplete code more verbose on runtime */
606 +#ifdef TODO
607 +# undef TODO
608 +#endif
609 +#define TODO() \
610 + do { \
611 + printk(KERN_INFO PFX "TODO: Incomplete code in %s() at %s:%d\n", \
612 + __FUNCTION__, __FILE__, __LINE__); \
613 + } while (0)
614 +
615 +#ifdef FIXME
616 +# undef FIXME
617 +#endif
618 +#define FIXME() \
619 + do { \
620 + printk(KERN_INFO PFX "FIXME: Possibly broken code in %s() at %s:%d\n", \
621 + __FUNCTION__, __FILE__, __LINE__); \
622 + } while (0)
623 +
624 +#endif /* BCM43xx_DEBUGFS_H_ */
625 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c
626 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c 1970-01-01 01:00:00.000000000 +0100
627 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c 2006-03-28 22:16:14.000000000 +0200
628 @@ -0,0 +1,991 @@
629 +/*
630 +
631 + Broadcom BCM43xx wireless driver
632 +
633 + DMA ringbuffer and descriptor allocation/management
634 +
635 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
636 +
637 + Some code in this file is derived from the b44.c driver
638 + Copyright (C) 2002 David S. Miller
639 + Copyright (C) Pekka Pietikainen
640 +
641 + This program is free software; you can redistribute it and/or modify
642 + it under the terms of the GNU General Public License as published by
643 + the Free Software Foundation; either version 2 of the License, or
644 + (at your option) any later version.
645 +
646 + This program is distributed in the hope that it will be useful,
647 + but WITHOUT ANY WARRANTY; without even the implied warranty of
648 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
649 + GNU General Public License for more details.
650 +
651 + You should have received a copy of the GNU General Public License
652 + along with this program; see the file COPYING. If not, write to
653 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
654 + Boston, MA 02110-1301, USA.
655 +
656 +*/
657 +
658 +#include "bcm43xx.h"
659 +#include "bcm43xx_dma.h"
660 +#include "bcm43xx_main.h"
661 +#include "bcm43xx_debugfs.h"
662 +#include "bcm43xx_power.h"
663 +#include "bcm43xx_xmit.h"
664 +
665 +#include <linux/dma-mapping.h>
666 +#include <linux/pci.h>
667 +#include <linux/delay.h>
668 +#include <linux/skbuff.h>
669 +
670 +
671 +static inline int free_slots(struct bcm43xx_dmaring *ring)
672 +{
673 + return (ring->nr_slots - ring->used_slots);
674 +}
675 +
676 +static inline int next_slot(struct bcm43xx_dmaring *ring, int slot)
677 +{
678 + assert(slot >= -1 && slot <= ring->nr_slots - 1);
679 + if (slot == ring->nr_slots - 1)
680 + return 0;
681 + return slot + 1;
682 +}
683 +
684 +static inline int prev_slot(struct bcm43xx_dmaring *ring, int slot)
685 +{
686 + assert(slot >= 0 && slot <= ring->nr_slots - 1);
687 + if (slot == 0)
688 + return ring->nr_slots - 1;
689 + return slot - 1;
690 +}
691 +
692 +/* Request a slot for usage. */
693 +static inline
694 +int request_slot(struct bcm43xx_dmaring *ring)
695 +{
696 + int slot;
697 +
698 + assert(ring->tx);
699 + assert(!ring->suspended);
700 + assert(free_slots(ring) != 0);
701 +
702 + slot = next_slot(ring, ring->current_slot);
703 + ring->current_slot = slot;
704 + ring->used_slots++;
705 +
706 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
707 + if (ring->used_slots > ring->max_used_slots)
708 + ring->max_used_slots = ring->used_slots;
709 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
710 +
711 + return slot;
712 +}
713 +
714 +/* Return a slot to the free slots. */
715 +static inline
716 +void return_slot(struct bcm43xx_dmaring *ring, int slot)
717 +{
718 + assert(ring->tx);
719 +
720 + ring->used_slots--;
721 +}
722 +
723 +static inline
724 +dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
725 + unsigned char *buf,
726 + size_t len,
727 + int tx)
728 +{
729 + dma_addr_t dmaaddr;
730 +
731 + if (tx) {
732 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
733 + buf, len,
734 + DMA_TO_DEVICE);
735 + } else {
736 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
737 + buf, len,
738 + DMA_FROM_DEVICE);
739 + }
740 +
741 + return dmaaddr;
742 +}
743 +
744 +static inline
745 +void unmap_descbuffer(struct bcm43xx_dmaring *ring,
746 + dma_addr_t addr,
747 + size_t len,
748 + int tx)
749 +{
750 + if (tx) {
751 + dma_unmap_single(&ring->bcm->pci_dev->dev,
752 + addr, len,
753 + DMA_TO_DEVICE);
754 + } else {
755 + dma_unmap_single(&ring->bcm->pci_dev->dev,
756 + addr, len,
757 + DMA_FROM_DEVICE);
758 + }
759 +}
760 +
761 +static inline
762 +void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
763 + dma_addr_t addr,
764 + size_t len)
765 +{
766 + assert(!ring->tx);
767 +
768 + dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev,
769 + addr, len, DMA_FROM_DEVICE);
770 +}
771 +
772 +static inline
773 +void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
774 + dma_addr_t addr,
775 + size_t len)
776 +{
777 + assert(!ring->tx);
778 +
779 + dma_sync_single_for_device(&ring->bcm->pci_dev->dev,
780 + addr, len, DMA_FROM_DEVICE);
781 +}
782 +
783 +/* Unmap and free a descriptor buffer. */
784 +static inline
785 +void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
786 + struct bcm43xx_dmadesc *desc,
787 + struct bcm43xx_dmadesc_meta *meta,
788 + int irq_context)
789 +{
790 + assert(meta->skb);
791 + if (irq_context)
792 + dev_kfree_skb_irq(meta->skb);
793 + else
794 + dev_kfree_skb(meta->skb);
795 + meta->skb = NULL;
796 +}
797 +
798 +static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
799 +{
800 + struct device *dev = &(ring->bcm->pci_dev->dev);
801 +
802 + ring->vbase = dma_alloc_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
803 + &(ring->dmabase), GFP_KERNEL);
804 + if (!ring->vbase) {
805 + printk(KERN_ERR PFX "DMA ringmemory allocation failed\n");
806 + return -ENOMEM;
807 + }
808 + if (ring->dmabase + BCM43xx_DMA_RINGMEMSIZE > BCM43xx_DMA_BUSADDRMAX) {
809 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RINGMEMORY >1G "
810 + "(0x%08x, len: %lu)\n",
811 + ring->dmabase, BCM43xx_DMA_RINGMEMSIZE);
812 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
813 + ring->vbase, ring->dmabase);
814 + return -ENOMEM;
815 + }
816 + assert(!(ring->dmabase & 0x000003FF));
817 + memset(ring->vbase, 0, BCM43xx_DMA_RINGMEMSIZE);
818 +
819 + return 0;
820 +}
821 +
822 +static void free_ringmemory(struct bcm43xx_dmaring *ring)
823 +{
824 + struct device *dev = &(ring->bcm->pci_dev->dev);
825 +
826 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
827 + ring->vbase, ring->dmabase);
828 +}
829 +
830 +/* Reset the RX DMA channel */
831 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
832 + u16 mmio_base)
833 +{
834 + int i;
835 + u32 value;
836 +
837 + bcm43xx_write32(bcm,
838 + mmio_base + BCM43xx_DMA_RX_CONTROL,
839 + 0x00000000);
840 + for (i = 0; i < 1000; i++) {
841 + value = bcm43xx_read32(bcm,
842 + mmio_base + BCM43xx_DMA_RX_STATUS);
843 + value &= BCM43xx_DMA_RXSTAT_STAT_MASK;
844 + if (value == BCM43xx_DMA_RXSTAT_STAT_DISABLED) {
845 + i = -1;
846 + break;
847 + }
848 + udelay(10);
849 + }
850 + if (i != -1) {
851 + printk(KERN_ERR PFX "Error: Wait on DMA RX status timed out.\n");
852 + return -ENODEV;
853 + }
854 +
855 + return 0;
856 +}
857 +
858 +/* Reset the RX DMA channel */
859 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
860 + u16 mmio_base)
861 +{
862 + int i;
863 + u32 value;
864 +
865 + for (i = 0; i < 1000; i++) {
866 + value = bcm43xx_read32(bcm,
867 + mmio_base + BCM43xx_DMA_TX_STATUS);
868 + value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
869 + if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED ||
870 + value == BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT ||
871 + value == BCM43xx_DMA_TXSTAT_STAT_STOPPED)
872 + break;
873 + udelay(10);
874 + }
875 + bcm43xx_write32(bcm,
876 + mmio_base + BCM43xx_DMA_TX_CONTROL,
877 + 0x00000000);
878 + for (i = 0; i < 1000; i++) {
879 + value = bcm43xx_read32(bcm,
880 + mmio_base + BCM43xx_DMA_TX_STATUS);
881 + value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
882 + if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED) {
883 + i = -1;
884 + break;
885 + }
886 + udelay(10);
887 + }
888 + if (i != -1) {
889 + printk(KERN_ERR PFX "Error: Wait on DMA TX status timed out.\n");
890 + return -ENODEV;
891 + }
892 + /* ensure the reset is completed. */
893 + udelay(300);
894 +
895 + return 0;
896 +}
897 +
898 +static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
899 + struct bcm43xx_dmadesc *desc,
900 + struct bcm43xx_dmadesc_meta *meta,
901 + gfp_t gfp_flags)
902 +{
903 + struct bcm43xx_rxhdr *rxhdr;
904 + dma_addr_t dmaaddr;
905 + u32 desc_addr;
906 + u32 desc_ctl;
907 + const int slot = (int)(desc - ring->vbase);
908 + struct sk_buff *skb;
909 +
910 + assert(slot >= 0 && slot < ring->nr_slots);
911 + assert(!ring->tx);
912 +
913 + skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
914 + if (unlikely(!skb))
915 + return -ENOMEM;
916 + dmaaddr = map_descbuffer(ring, skb->data,
917 + ring->rx_buffersize, 0);
918 + if (unlikely(dmaaddr + ring->rx_buffersize > BCM43xx_DMA_BUSADDRMAX)) {
919 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
920 + dev_kfree_skb_any(skb);
921 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RX SKB >1G "
922 + "(0x%08x, len: %u)\n",
923 + dmaaddr, ring->rx_buffersize);
924 + return -ENOMEM;
925 + }
926 + meta->skb = skb;
927 + meta->dmaaddr = dmaaddr;
928 + skb->dev = ring->bcm->net_dev;
929 + desc_addr = (u32)(dmaaddr + ring->memoffset);
930 + desc_ctl = (BCM43xx_DMADTOR_BYTECNT_MASK &
931 + (u32)(ring->rx_buffersize - ring->frameoffset));
932 + if (slot == ring->nr_slots - 1)
933 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
934 + set_desc_addr(desc, desc_addr);
935 + set_desc_ctl(desc, desc_ctl);
936 +
937 + rxhdr = (struct bcm43xx_rxhdr *)(skb->data);
938 + rxhdr->frame_length = 0;
939 + rxhdr->flags1 = 0;
940 +
941 + return 0;
942 +}
943 +
944 +/* Allocate the initial descbuffers.
945 + * This is used for an RX ring only.
946 + */
947 +static int alloc_initial_descbuffers(struct bcm43xx_dmaring *ring)
948 +{
949 + int i, err = -ENOMEM;
950 + struct bcm43xx_dmadesc *desc;
951 + struct bcm43xx_dmadesc_meta *meta;
952 +
953 + for (i = 0; i < ring->nr_slots; i++) {
954 + desc = ring->vbase + i;
955 + meta = ring->meta + i;
956 +
957 + err = setup_rx_descbuffer(ring, desc, meta, GFP_KERNEL);
958 + if (err)
959 + goto err_unwind;
960 + }
961 + ring->used_slots = ring->nr_slots;
962 + err = 0;
963 +out:
964 + return err;
965 +
966 +err_unwind:
967 + for (i--; i >= 0; i--) {
968 + desc = ring->vbase + i;
969 + meta = ring->meta + i;
970 +
971 + unmap_descbuffer(ring, meta->dmaaddr, ring->rx_buffersize, 0);
972 + dev_kfree_skb(meta->skb);
973 + }
974 + goto out;
975 +}
976 +
977 +/* Do initial setup of the DMA controller.
978 + * Reset the controller, write the ring busaddress
979 + * and switch the "enable" bit on.
980 + */
981 +static int dmacontroller_setup(struct bcm43xx_dmaring *ring)
982 +{
983 + int err = 0;
984 + u32 value;
985 +
986 + if (ring->tx) {
987 + /* Set Transmit Control register to "transmit enable" */
988 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
989 + BCM43xx_DMA_TXCTRL_ENABLE);
990 + /* Set Transmit Descriptor ring address. */
991 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING,
992 + ring->dmabase + ring->memoffset);
993 + } else {
994 + err = alloc_initial_descbuffers(ring);
995 + if (err)
996 + goto out;
997 + /* Set Receive Control "receive enable" and frame offset */
998 + value = (ring->frameoffset << BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT);
999 + value |= BCM43xx_DMA_RXCTRL_ENABLE;
1000 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_CONTROL, value);
1001 + /* Set Receive Descriptor ring address. */
1002 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING,
1003 + ring->dmabase + ring->memoffset);
1004 + /* Init the descriptor pointer. */
1005 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX, 200);
1006 + }
1007 +
1008 +out:
1009 + return err;
1010 +}
1011 +
1012 +/* Shutdown the DMA controller. */
1013 +static void dmacontroller_cleanup(struct bcm43xx_dmaring *ring)
1014 +{
1015 + if (ring->tx) {
1016 + bcm43xx_dmacontroller_tx_reset(ring->bcm, ring->mmio_base);
1017 + /* Zero out Transmit Descriptor ring address. */
1018 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING, 0);
1019 + } else {
1020 + bcm43xx_dmacontroller_rx_reset(ring->bcm, ring->mmio_base);
1021 + /* Zero out Receive Descriptor ring address. */
1022 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING, 0);
1023 + }
1024 +}
1025 +
1026 +static void free_all_descbuffers(struct bcm43xx_dmaring *ring)
1027 +{
1028 + struct bcm43xx_dmadesc *desc;
1029 + struct bcm43xx_dmadesc_meta *meta;
1030 + int i;
1031 +
1032 + if (!ring->used_slots)
1033 + return;
1034 + for (i = 0; i < ring->nr_slots; i++) {
1035 + desc = ring->vbase + i;
1036 + meta = ring->meta + i;
1037 +
1038 + if (!meta->skb) {
1039 + assert(ring->tx);
1040 + continue;
1041 + }
1042 + if (ring->tx) {
1043 + unmap_descbuffer(ring, meta->dmaaddr,
1044 + meta->skb->len, 1);
1045 + } else {
1046 + unmap_descbuffer(ring, meta->dmaaddr,
1047 + ring->rx_buffersize, 0);
1048 + }
1049 + free_descriptor_buffer(ring, desc, meta, 0);
1050 + }
1051 +}
1052 +
1053 +/* Main initialization function. */
1054 +static
1055 +struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
1056 + u16 dma_controller_base,
1057 + int nr_descriptor_slots,
1058 + int tx)
1059 +{
1060 + struct bcm43xx_dmaring *ring;
1061 + int err;
1062 +
1063 + ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1064 + if (!ring)
1065 + goto out;
1066 +
1067 + ring->meta = kzalloc(sizeof(*ring->meta) * nr_descriptor_slots,
1068 + GFP_KERNEL);
1069 + if (!ring->meta)
1070 + goto err_kfree_ring;
1071 +
1072 + ring->memoffset = BCM43xx_DMA_DMABUSADDROFFSET;
1073 +#ifdef CONFIG_BCM947XX
1074 + if (bcm->pci_dev->bus->number == 0)
1075 + ring->memoffset = 0;
1076 +#endif
1077 +
1078 + ring->bcm = bcm;
1079 + ring->nr_slots = nr_descriptor_slots;
1080 + ring->mmio_base = dma_controller_base;
1081 + if (tx) {
1082 + ring->tx = 1;
1083 + ring->current_slot = -1;
1084 + } else {
1085 + switch (dma_controller_base) {
1086 + case BCM43xx_MMIO_DMA1_BASE:
1087 + ring->rx_buffersize = BCM43xx_DMA1_RXBUFFERSIZE;
1088 + ring->frameoffset = BCM43xx_DMA1_RX_FRAMEOFFSET;
1089 + break;
1090 + case BCM43xx_MMIO_DMA4_BASE:
1091 + ring->rx_buffersize = BCM43xx_DMA4_RXBUFFERSIZE;
1092 + ring->frameoffset = BCM43xx_DMA4_RX_FRAMEOFFSET;
1093 + break;
1094 + default:
1095 + assert(0);
1096 + }
1097 + }
1098 +
1099 + err = alloc_ringmemory(ring);
1100 + if (err)
1101 + goto err_kfree_meta;
1102 + err = dmacontroller_setup(ring);
1103 + if (err)
1104 + goto err_free_ringmemory;
1105 +
1106 +out:
1107 + return ring;
1108 +
1109 +err_free_ringmemory:
1110 + free_ringmemory(ring);
1111 +err_kfree_meta:
1112 + kfree(ring->meta);
1113 +err_kfree_ring:
1114 + kfree(ring);
1115 + ring = NULL;
1116 + goto out;
1117 +}
1118 +
1119 +/* Main cleanup function. */
1120 +static void bcm43xx_destroy_dmaring(struct bcm43xx_dmaring *ring)
1121 +{
1122 + if (!ring)
1123 + return;
1124 +
1125 + dprintk(KERN_INFO PFX "DMA 0x%04x (%s) max used slots: %d/%d\n",
1126 + ring->mmio_base,
1127 + (ring->tx) ? "TX" : "RX",
1128 + ring->max_used_slots, ring->nr_slots);
1129 + /* Device IRQs are disabled prior entering this function,
1130 + * so no need to take care of concurrency with rx handler stuff.
1131 + */
1132 + dmacontroller_cleanup(ring);
1133 + free_all_descbuffers(ring);
1134 + free_ringmemory(ring);
1135 +
1136 + kfree(ring->meta);
1137 + kfree(ring);
1138 +}
1139 +
1140 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1141 +{
1142 + struct bcm43xx_dma *dma;
1143 +
1144 + if (bcm43xx_using_pio(bcm))
1145 + return;
1146 + dma = bcm43xx_current_dma(bcm);
1147 +
1148 + bcm43xx_destroy_dmaring(dma->rx_ring1);
1149 + dma->rx_ring1 = NULL;
1150 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1151 + dma->rx_ring0 = NULL;
1152 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1153 + dma->tx_ring3 = NULL;
1154 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1155 + dma->tx_ring2 = NULL;
1156 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1157 + dma->tx_ring1 = NULL;
1158 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1159 + dma->tx_ring0 = NULL;
1160 +}
1161 +
1162 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1163 +{
1164 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1165 + struct bcm43xx_dmaring *ring;
1166 + int err = -ENOMEM;
1167 +
1168 + /* setup TX DMA channels. */
1169 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1170 + BCM43xx_TXRING_SLOTS, 1);
1171 + if (!ring)
1172 + goto out;
1173 + dma->tx_ring0 = ring;
1174 +
1175 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA2_BASE,
1176 + BCM43xx_TXRING_SLOTS, 1);
1177 + if (!ring)
1178 + goto err_destroy_tx0;
1179 + dma->tx_ring1 = ring;
1180 +
1181 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA3_BASE,
1182 + BCM43xx_TXRING_SLOTS, 1);
1183 + if (!ring)
1184 + goto err_destroy_tx1;
1185 + dma->tx_ring2 = ring;
1186 +
1187 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1188 + BCM43xx_TXRING_SLOTS, 1);
1189 + if (!ring)
1190 + goto err_destroy_tx2;
1191 + dma->tx_ring3 = ring;
1192 +
1193 + /* setup RX DMA channels. */
1194 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1195 + BCM43xx_RXRING_SLOTS, 0);
1196 + if (!ring)
1197 + goto err_destroy_tx3;
1198 + dma->rx_ring0 = ring;
1199 +
1200 + if (bcm->current_core->rev < 5) {
1201 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1202 + BCM43xx_RXRING_SLOTS, 0);
1203 + if (!ring)
1204 + goto err_destroy_rx0;
1205 + dma->rx_ring1 = ring;
1206 + }
1207 +
1208 + dprintk(KERN_INFO PFX "DMA initialized\n");
1209 + err = 0;
1210 +out:
1211 + return err;
1212 +
1213 +err_destroy_rx0:
1214 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1215 + dma->rx_ring0 = NULL;
1216 +err_destroy_tx3:
1217 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1218 + dma->tx_ring3 = NULL;
1219 +err_destroy_tx2:
1220 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1221 + dma->tx_ring2 = NULL;
1222 +err_destroy_tx1:
1223 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1224 + dma->tx_ring1 = NULL;
1225 +err_destroy_tx0:
1226 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1227 + dma->tx_ring0 = NULL;
1228 + goto out;
1229 +}
1230 +
1231 +/* Generate a cookie for the TX header. */
1232 +static u16 generate_cookie(struct bcm43xx_dmaring *ring,
1233 + int slot)
1234 +{
1235 + u16 cookie = 0x0000;
1236 +
1237 + /* Use the upper 4 bits of the cookie as
1238 + * DMA controller ID and store the slot number
1239 + * in the lower 12 bits
1240 + */
1241 + switch (ring->mmio_base) {
1242 + default:
1243 + assert(0);
1244 + case BCM43xx_MMIO_DMA1_BASE:
1245 + break;
1246 + case BCM43xx_MMIO_DMA2_BASE:
1247 + cookie = 0x1000;
1248 + break;
1249 + case BCM43xx_MMIO_DMA3_BASE:
1250 + cookie = 0x2000;
1251 + break;
1252 + case BCM43xx_MMIO_DMA4_BASE:
1253 + cookie = 0x3000;
1254 + break;
1255 + }
1256 + assert(((u16)slot & 0xF000) == 0x0000);
1257 + cookie |= (u16)slot;
1258 +
1259 + return cookie;
1260 +}
1261 +
1262 +/* Inspect a cookie and find out to which controller/slot it belongs. */
1263 +static
1264 +struct bcm43xx_dmaring * parse_cookie(struct bcm43xx_private *bcm,
1265 + u16 cookie, int *slot)
1266 +{
1267 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1268 + struct bcm43xx_dmaring *ring = NULL;
1269 +
1270 + switch (cookie & 0xF000) {
1271 + case 0x0000:
1272 + ring = dma->tx_ring0;
1273 + break;
1274 + case 0x1000:
1275 + ring = dma->tx_ring1;
1276 + break;
1277 + case 0x2000:
1278 + ring = dma->tx_ring2;
1279 + break;
1280 + case 0x3000:
1281 + ring = dma->tx_ring3;
1282 + break;
1283 + default:
1284 + assert(0);
1285 + }
1286 + *slot = (cookie & 0x0FFF);
1287 + assert(*slot >= 0 && *slot < ring->nr_slots);
1288 +
1289 + return ring;
1290 +}
1291 +
1292 +static void dmacontroller_poke_tx(struct bcm43xx_dmaring *ring,
1293 + int slot)
1294 +{
1295 + /* Everything is ready to start. Buffers are DMA mapped and
1296 + * associated with slots.
1297 + * "slot" is the last slot of the new frame we want to transmit.
1298 + * Close your seat belts now, please.
1299 + */
1300 + wmb();
1301 + slot = next_slot(ring, slot);
1302 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_INDEX,
1303 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1304 +}
1305 +
1306 +static int dma_tx_fragment(struct bcm43xx_dmaring *ring,
1307 + struct sk_buff *skb,
1308 + struct ieee80211_tx_control *ctl)
1309 +{
1310 + struct sk_buff *hdr_skb;
1311 + int slot;
1312 + struct bcm43xx_dmadesc *desc;
1313 + struct bcm43xx_dmadesc_meta *meta;
1314 + u32 desc_ctl;
1315 + u32 desc_addr;
1316 +
1317 + assert(skb_shinfo(skb)->nr_frags == 0);
1318 +
1319 + hdr_skb = dev_alloc_skb(sizeof(struct bcm43xx_txhdr));
1320 + if (unlikely(!hdr_skb))
1321 + return -ENOMEM;
1322 + skb_put(hdr_skb, sizeof(struct bcm43xx_txhdr));
1323 +
1324 + slot = request_slot(ring);
1325 + desc = ring->vbase + slot;
1326 + meta = ring->meta + slot;
1327 +
1328 + bcm43xx_generate_txhdr(ring->bcm,
1329 + (struct bcm43xx_txhdr *)hdr_skb->data,
1330 + skb->data, skb->len,
1331 + 1,//FIXME
1332 + generate_cookie(ring, slot),
1333 + ctl);
1334 +
1335 + meta->skb = hdr_skb;
1336 + meta->dmaaddr = map_descbuffer(ring, hdr_skb->data, hdr_skb->len, 1);
1337 + if (unlikely(meta->dmaaddr + hdr_skb->len > BCM43xx_DMA_BUSADDRMAX)) {
1338 + return_slot(ring, slot);
1339 + dev_kfree_skb_irq(hdr_skb);
1340 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA TX SKB >1G "
1341 + "(0x%08x, len: %u)\n",
1342 + meta->dmaaddr, hdr_skb->len);
1343 + return -ENOMEM;
1344 + }
1345 +
1346 + desc_addr = (u32)(meta->dmaaddr + ring->memoffset);
1347 + desc_ctl = BCM43xx_DMADTOR_FRAMESTART |
1348 + (BCM43xx_DMADTOR_BYTECNT_MASK & (u32)(hdr_skb->len));
1349 + if (slot == ring->nr_slots - 1)
1350 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
1351 + set_desc_ctl(desc, desc_ctl);
1352 + set_desc_addr(desc, desc_addr);
1353 +
1354 + slot = request_slot(ring);
1355 + desc = ring->vbase + slot;
1356 + meta = ring->meta + slot;
1357 +
1358 + /* We inspect the txstatus on the FRAMESTART descriptor later
1359 + * on xmit-status IRQ.
1360 + */
1361 + meta->must_xmit_txstat = 1;
1362 + memset(&meta->txstat, 0, sizeof(meta->txstat));
1363 + memcpy(&meta->txstat.control, ctl, sizeof(*ctl));
1364 +
1365 + meta->skb = skb;
1366 + meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
1367 + if (unlikely(meta->dmaaddr + skb->len > BCM43xx_DMA_BUSADDRMAX)) {
1368 + return_slot(ring, prev_slot(ring, slot));
1369 + return_slot(ring, slot);
1370 + dev_kfree_skb_irq(hdr_skb);
1371 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA TX SKB >1G "
1372 + "(0x%08x, len: %u)\n",
1373 + meta->dmaaddr, skb->len);
1374 + return -ENOMEM;
1375 + }
1376 +
1377 + desc_addr = (u32)(meta->dmaaddr + ring->memoffset);
1378 + desc_ctl = (BCM43xx_DMADTOR_BYTECNT_MASK & (u32)(skb->len));
1379 + if (slot == ring->nr_slots - 1)
1380 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
1381 +
1382 + desc_ctl |= BCM43xx_DMADTOR_FRAMEEND | BCM43xx_DMADTOR_COMPIRQ;
1383 + set_desc_ctl(desc, desc_ctl);
1384 + set_desc_addr(desc, desc_addr);
1385 + /* Now transfer the whole frame. */
1386 + dmacontroller_poke_tx(ring, slot);
1387 +
1388 + return 0;
1389 +}
1390 +
1391 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1392 + struct sk_buff *skb,
1393 + struct ieee80211_tx_control *ctl)
1394 +{
1395 + struct bcm43xx_dmaring *ring = bcm43xx_current_dma(bcm)->tx_ring1;
1396 + int err;
1397 +
1398 + assert(ring->tx);
1399 +
1400 +#define SLOTS_PER_PACKET 2
1401 + if (unlikely(free_slots(ring) < SLOTS_PER_PACKET)) {
1402 + /* This should never trigger, as the ieee80211 stack
1403 + * recognizes if the device queue is full and does
1404 + * not send data anymore.
1405 + */
1406 + printk(KERN_ERR PFX "DMA queue overflow\n");
1407 + return -ENOMEM;
1408 + }
1409 +
1410 + err = dma_tx_fragment(ring, skb, ctl);
1411 + if (likely(!err))
1412 + ring->nr_tx_packets++;
1413 +
1414 + return err;
1415 +}
1416 +
1417 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1418 + struct bcm43xx_xmitstatus *status)
1419 +{
1420 + struct bcm43xx_dmaring *ring;
1421 + struct bcm43xx_dmadesc *desc;
1422 + struct bcm43xx_dmadesc_meta *meta;
1423 + int is_last_fragment;
1424 + int slot;
1425 +
1426 + ring = parse_cookie(bcm, status->cookie, &slot);
1427 + assert(ring);
1428 + assert(ring->tx);
1429 + assert(get_desc_ctl(ring->vbase + slot) & BCM43xx_DMADTOR_FRAMESTART);
1430 + while (1) {
1431 + assert(slot >= 0 && slot < ring->nr_slots);
1432 + desc = ring->vbase + slot;
1433 + meta = ring->meta + slot;
1434 +
1435 + is_last_fragment = !!(get_desc_ctl(desc) & BCM43xx_DMADTOR_FRAMEEND);
1436 + unmap_descbuffer(ring, meta->dmaaddr, meta->skb->len, 1);
1437 +
1438 + if (meta->must_xmit_txstat) {
1439 + meta->must_xmit_txstat = 0;
1440 + /* Call back to inform the ieee80211 subsystem about the
1441 + * status of the transmission.
1442 + * Some fields of txstat are already filled in dma_tx().
1443 + */
1444 + meta->txstat.ack = !!(status->flags & BCM43xx_TXSTAT_FLAG_ACK);
1445 + meta->txstat.retry_count = status->cnt2 - 1;
1446 + //FIXME: Fill in more information?
1447 + ieee80211_tx_status_irqsafe(bcm->net_dev, meta->skb, &(meta->txstat));
1448 + meta->skb = NULL;
1449 + } else
1450 + free_descriptor_buffer(ring, desc, meta, 1);
1451 + /* Everything belonging to the slot is unmapped
1452 + * and freed, so we can return it.
1453 + */
1454 + return_slot(ring, slot);
1455 +
1456 + if (is_last_fragment)
1457 + break;
1458 + slot = next_slot(ring, slot);
1459 + }
1460 + bcm->stats.last_tx = jiffies;
1461 +}
1462 +
1463 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1464 + struct ieee80211_tx_queue_stats *stats)
1465 +{
1466 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1467 + struct bcm43xx_dmaring *ring;
1468 + struct ieee80211_tx_queue_stats_data *data;
1469 +
1470 + ring = dma->tx_ring1;
1471 + data = &(stats->data[0]);
1472 + data->len = ring->used_slots / SLOTS_PER_PACKET;
1473 + data->limit = ring->nr_slots / SLOTS_PER_PACKET;
1474 + data->count = ring->nr_tx_packets;
1475 +}
1476 +
1477 +static void dma_rx(struct bcm43xx_dmaring *ring,
1478 + int *slot)
1479 +{
1480 + struct bcm43xx_dmadesc *desc;
1481 + struct bcm43xx_dmadesc_meta *meta;
1482 + struct bcm43xx_rxhdr *rxhdr;
1483 + struct sk_buff *skb;
1484 + u16 len;
1485 + int err;
1486 + dma_addr_t dmaaddr;
1487 +
1488 + desc = ring->vbase + *slot;
1489 + meta = ring->meta + *slot;
1490 +
1491 + sync_descbuffer_for_cpu(ring, meta->dmaaddr, ring->rx_buffersize);
1492 + skb = meta->skb;
1493 +
1494 + if (ring->mmio_base == BCM43xx_MMIO_DMA4_BASE) {
1495 + /* We received an xmit status. */
1496 + struct bcm43xx_hwxmitstatus *hw = (struct bcm43xx_hwxmitstatus *)skb->data;
1497 + struct bcm43xx_xmitstatus stat;
1498 +
1499 + stat.cookie = le16_to_cpu(hw->cookie);
1500 + stat.flags = hw->flags;
1501 + stat.cnt1 = hw->cnt1;
1502 + stat.cnt2 = hw->cnt2;
1503 + stat.seq = le16_to_cpu(hw->seq);
1504 + stat.unknown = le16_to_cpu(hw->unknown);
1505 +
1506 + bcm43xx_debugfs_log_txstat(ring->bcm, &stat);
1507 + bcm43xx_dma_handle_xmitstatus(ring->bcm, &stat);
1508 + /* recycle the descriptor buffer. */
1509 + sync_descbuffer_for_device(ring, meta->dmaaddr, ring->rx_buffersize);
1510 +
1511 + return;
1512 + }
1513 + rxhdr = (struct bcm43xx_rxhdr *)skb->data;
1514 + len = le16_to_cpu(rxhdr->frame_length);
1515 + if (len == 0) {
1516 + int i = 0;
1517 +
1518 + do {
1519 + udelay(2);
1520 + barrier();
1521 + len = le16_to_cpu(rxhdr->frame_length);
1522 + } while (len == 0 && i++ < 5);
1523 + if (unlikely(len == 0)) {
1524 + /* recycle the descriptor buffer. */
1525 + sync_descbuffer_for_device(ring, meta->dmaaddr,
1526 + ring->rx_buffersize);
1527 + goto drop;
1528 + }
1529 + }
1530 + if (unlikely(len > ring->rx_buffersize)) {
1531 + /* The data did not fit into one descriptor buffer
1532 + * and is split over multiple buffers.
1533 + * This should never happen, as we try to allocate buffers
1534 + * big enough. So simply ignore this packet.
1535 + */
1536 + int cnt = 0;
1537 + s32 tmp = len;
1538 +
1539 + while (1) {
1540 + desc = ring->vbase + *slot;
1541 + meta = ring->meta + *slot;
1542 + /* recycle the descriptor buffer. */
1543 + sync_descbuffer_for_device(ring, meta->dmaaddr,
1544 + ring->rx_buffersize);
1545 + *slot = next_slot(ring, *slot);
1546 + cnt++;
1547 + tmp -= ring->rx_buffersize;
1548 + if (tmp <= 0)
1549 + break;
1550 + }
1551 + printkl(KERN_ERR PFX "DMA RX buffer too small "
1552 + "(len: %u, buffer: %u, nr-dropped: %d)\n",
1553 + len, ring->rx_buffersize, cnt);
1554 + goto drop;
1555 + }
1556 +
1557 + dmaaddr = meta->dmaaddr;
1558 + err = setup_rx_descbuffer(ring, desc, meta, GFP_ATOMIC);
1559 + if (unlikely(err)) {
1560 + dprintkl(KERN_ERR PFX "DMA RX: setup_rx_descbuffer() failed\n");
1561 + sync_descbuffer_for_device(ring, dmaaddr,
1562 + ring->rx_buffersize);
1563 + goto drop;
1564 + }
1565 +
1566 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
1567 + skb_put(skb, len + ring->frameoffset);
1568 + skb_pull(skb, ring->frameoffset);
1569 +
1570 + bcm43xx_rx(ring->bcm, skb, rxhdr);
1571 +drop:
1572 + return;
1573 +}
1574 +
1575 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1576 +{
1577 + u32 status;
1578 + u16 descptr;
1579 + int slot, current_slot;
1580 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1581 + int used_slots = 0;
1582 +#endif
1583 +
1584 + assert(!ring->tx);
1585 + status = bcm43xx_dma_read(ring, BCM43xx_DMA_RX_STATUS);
1586 + descptr = (status & BCM43xx_DMA_RXSTAT_DPTR_MASK);
1587 + current_slot = descptr / sizeof(struct bcm43xx_dmadesc);
1588 + assert(current_slot >= 0 && current_slot < ring->nr_slots);
1589 +
1590 + slot = ring->current_slot;
1591 + for ( ; slot != current_slot; slot = next_slot(ring, slot)) {
1592 + dma_rx(ring, &slot);
1593 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1594 + if (++used_slots > ring->max_used_slots)
1595 + ring->max_used_slots = used_slots;
1596 +#endif
1597 + }
1598 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX,
1599 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1600 + ring->current_slot = slot;
1601 +}
1602 +
1603 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring)
1604 +{
1605 + assert(ring->tx);
1606 + bcm43xx_power_saving_ctl_bits(ring->bcm, -1, 1);
1607 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
1608 + bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
1609 + | BCM43xx_DMA_TXCTRL_SUSPEND);
1610 +}
1611 +
1612 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring)
1613 +{
1614 + assert(ring->tx);
1615 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
1616 + bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
1617 + & ~BCM43xx_DMA_TXCTRL_SUSPEND);
1618 + bcm43xx_power_saving_ctl_bits(ring->bcm, -1, -1);
1619 +}
1620 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h
1621 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h 1970-01-01 01:00:00.000000000 +0100
1622 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h 2006-03-28 22:16:14.000000000 +0200
1623 @@ -0,0 +1,228 @@
1624 +#ifndef BCM43xx_DMA_H_
1625 +#define BCM43xx_DMA_H_
1626 +
1627 +#include <linux/list.h>
1628 +#include <linux/spinlock.h>
1629 +#include <linux/workqueue.h>
1630 +#include <linux/linkage.h>
1631 +#include <asm/atomic.h>
1632 +
1633 +#include "bcm43xx.h"
1634 +
1635 +
1636 +/* DMA-Interrupt reasons. */
1637 +#define BCM43xx_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
1638 + | (1 << 14) | (1 << 15))
1639 +#define BCM43xx_DMAIRQ_NONFATALMASK (1 << 13)
1640 +#define BCM43xx_DMAIRQ_RX_DONE (1 << 16)
1641 +
1642 +/* DMA controller register offsets. (relative to BCM43xx_DMA#_BASE) */
1643 +#define BCM43xx_DMA_TX_CONTROL 0x00
1644 +#define BCM43xx_DMA_TX_DESC_RING 0x04
1645 +#define BCM43xx_DMA_TX_DESC_INDEX 0x08
1646 +#define BCM43xx_DMA_TX_STATUS 0x0c
1647 +#define BCM43xx_DMA_RX_CONTROL 0x10
1648 +#define BCM43xx_DMA_RX_DESC_RING 0x14
1649 +#define BCM43xx_DMA_RX_DESC_INDEX 0x18
1650 +#define BCM43xx_DMA_RX_STATUS 0x1c
1651 +
1652 +/* DMA controller channel control word values. */
1653 +#define BCM43xx_DMA_TXCTRL_ENABLE (1 << 0)
1654 +#define BCM43xx_DMA_TXCTRL_SUSPEND (1 << 1)
1655 +#define BCM43xx_DMA_TXCTRL_LOOPBACK (1 << 2)
1656 +#define BCM43xx_DMA_TXCTRL_FLUSH (1 << 4)
1657 +#define BCM43xx_DMA_RXCTRL_ENABLE (1 << 0)
1658 +#define BCM43xx_DMA_RXCTRL_FRAMEOFF_MASK 0x000000fe
1659 +#define BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT 1
1660 +#define BCM43xx_DMA_RXCTRL_PIO (1 << 8)
1661 +/* DMA controller channel status word values. */
1662 +#define BCM43xx_DMA_TXSTAT_DPTR_MASK 0x00000fff
1663 +#define BCM43xx_DMA_TXSTAT_STAT_MASK 0x0000f000
1664 +#define BCM43xx_DMA_TXSTAT_STAT_DISABLED 0x00000000
1665 +#define BCM43xx_DMA_TXSTAT_STAT_ACTIVE 0x00001000
1666 +#define BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT 0x00002000
1667 +#define BCM43xx_DMA_TXSTAT_STAT_STOPPED 0x00003000
1668 +#define BCM43xx_DMA_TXSTAT_STAT_SUSP 0x00004000
1669 +#define BCM43xx_DMA_TXSTAT_ERROR_MASK 0x000f0000
1670 +#define BCM43xx_DMA_TXSTAT_FLUSHED (1 << 20)
1671 +#define BCM43xx_DMA_RXSTAT_DPTR_MASK 0x00000fff
1672 +#define BCM43xx_DMA_RXSTAT_STAT_MASK 0x0000f000
1673 +#define BCM43xx_DMA_RXSTAT_STAT_DISABLED 0x00000000
1674 +#define BCM43xx_DMA_RXSTAT_STAT_ACTIVE 0x00001000
1675 +#define BCM43xx_DMA_RXSTAT_STAT_IDLEWAIT 0x00002000
1676 +#define BCM43xx_DMA_RXSTAT_STAT_RESERVED 0x00003000
1677 +#define BCM43xx_DMA_RXSTAT_STAT_ERRORS 0x00004000
1678 +#define BCM43xx_DMA_RXSTAT_ERROR_MASK 0x000f0000
1679 +
1680 +/* DMA descriptor control field values. */
1681 +#define BCM43xx_DMADTOR_BYTECNT_MASK 0x00001fff
1682 +#define BCM43xx_DMADTOR_DTABLEEND (1 << 28) /* End of descriptor table */
1683 +#define BCM43xx_DMADTOR_COMPIRQ (1 << 29) /* IRQ on completion request */
1684 +#define BCM43xx_DMADTOR_FRAMEEND (1 << 30)
1685 +#define BCM43xx_DMADTOR_FRAMESTART (1 << 31)
1686 +
1687 +/* Misc DMA constants */
1688 +#define BCM43xx_DMA_RINGMEMSIZE PAGE_SIZE
1689 +#define BCM43xx_DMA_BUSADDRMAX 0x3FFFFFFF
1690 +#define BCM43xx_DMA_DMABUSADDROFFSET (1 << 30)
1691 +#define BCM43xx_DMA1_RX_FRAMEOFFSET 30
1692 +#define BCM43xx_DMA4_RX_FRAMEOFFSET 0
1693 +
1694 +/* DMA engine tuning knobs */
1695 +#define BCM43xx_TXRING_SLOTS 512
1696 +#define BCM43xx_RXRING_SLOTS 64
1697 +#define BCM43xx_DMA1_RXBUFFERSIZE (2304 + 100)
1698 +#define BCM43xx_DMA4_RXBUFFERSIZE 16
1699 +
1700 +
1701 +
1702 +#ifdef CONFIG_BCM43XX_D80211_DMA
1703 +
1704 +
1705 +struct sk_buff;
1706 +struct bcm43xx_private;
1707 +struct bcm43xx_xmitstatus;
1708 +
1709 +
1710 +struct bcm43xx_dmadesc {
1711 + __le32 _control;
1712 + __le32 _address;
1713 +} __attribute__((__packed__));
1714 +
1715 +/* Macros to access the bcm43xx_dmadesc struct */
1716 +#define get_desc_ctl(desc) le32_to_cpu((desc)->_control)
1717 +#define set_desc_ctl(desc, ctl) do { (desc)->_control = cpu_to_le32(ctl); } while (0)
1718 +#define get_desc_addr(desc) le32_to_cpu((desc)->_address)
1719 +#define set_desc_addr(desc, addr) do { (desc)->_address = cpu_to_le32(addr); } while (0)
1720 +
1721 +struct bcm43xx_dmadesc_meta {
1722 + /* The kernel DMA-able buffer. */
1723 + struct sk_buff *skb;
1724 + /* DMA base bus-address of the descriptor buffer. */
1725 + dma_addr_t dmaaddr;
1726 + /* ieee80211 TX status. Only used once per 802.11 frag. */
1727 + u8 must_xmit_txstat:1;
1728 + struct ieee80211_tx_status txstat;
1729 +};
1730 +
1731 +struct bcm43xx_dmaring {
1732 + struct bcm43xx_private *bcm;
1733 + /* Kernel virtual base address of the ring memory. */
1734 + struct bcm43xx_dmadesc *vbase;
1735 + /* DMA memory offset */
1736 + dma_addr_t memoffset;
1737 + /* (Unadjusted) DMA base bus-address of the ring memory. */
1738 + dma_addr_t dmabase;
1739 + /* Meta data about all descriptors. */
1740 + struct bcm43xx_dmadesc_meta *meta;
1741 + /* Number of descriptor slots in the ring. */
1742 + int nr_slots;
1743 + /* Number of used descriptor slots. */
1744 + int used_slots;
1745 + /* Currently used slot in the ring. */
1746 + int current_slot;
1747 + /* Total number of packets sent. Statistics only. */
1748 + unsigned int nr_tx_packets;
1749 + /* Frameoffset in octets. */
1750 + u32 frameoffset;
1751 + /* Descriptor buffer size. */
1752 + u16 rx_buffersize;
1753 + /* The MMIO base register of the DMA controller, this
1754 + * ring is posted to.
1755 + */
1756 + u16 mmio_base;
1757 + u8 tx:1, /* TRUE, if this is a TX ring. */
1758 + suspended:1; /* TRUE, if transfers are suspended on this ring. */
1759 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1760 + /* Maximum number of used slots. */
1761 + int max_used_slots;
1762 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
1763 +};
1764 +
1765 +
1766 +static inline
1767 +u32 bcm43xx_dma_read(struct bcm43xx_dmaring *ring,
1768 + u16 offset)
1769 +{
1770 + return bcm43xx_read32(ring->bcm, ring->mmio_base + offset);
1771 +}
1772 +
1773 +static inline
1774 +void bcm43xx_dma_write(struct bcm43xx_dmaring *ring,
1775 + u16 offset, u32 value)
1776 +{
1777 + bcm43xx_write32(ring->bcm, ring->mmio_base + offset, value);
1778 +}
1779 +
1780 +
1781 +int bcm43xx_dma_init(struct bcm43xx_private *bcm);
1782 +void bcm43xx_dma_free(struct bcm43xx_private *bcm);
1783 +
1784 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1785 + u16 dmacontroller_mmio_base);
1786 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1787 + u16 dmacontroller_mmio_base);
1788 +
1789 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring);
1790 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring);
1791 +
1792 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1793 + struct ieee80211_tx_queue_stats *stats);
1794 +
1795 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1796 + struct sk_buff *skb,
1797 + struct ieee80211_tx_control *ctl);
1798 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1799 + struct bcm43xx_xmitstatus *status);
1800 +
1801 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring);
1802 +
1803 +
1804 +#else /* CONFIG_BCM43XX_D80211_DMA */
1805 +
1806 +
1807 +static inline
1808 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1809 +{
1810 + return 0;
1811 +}
1812 +static inline
1813 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1814 +{
1815 +}
1816 +static inline
1817 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1818 + u16 dmacontroller_mmio_base)
1819 +{
1820 + return 0;
1821 +}
1822 +static inline
1823 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1824 + u16 dmacontroller_mmio_base)
1825 +{
1826 + return 0;
1827 +}
1828 +static inline
1829 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1830 + struct ieee80211_tx_queue_stats *stats)
1831 +{
1832 +}
1833 +static inline
1834 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1835 + struct sk_buff *skb,
1836 + struct ieee80211_tx_control *ctl)
1837 +{
1838 + return 0;
1839 +}
1840 +static inline
1841 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1842 + struct bcm43xx_xmitstatus *status)
1843 +{
1844 +}
1845 +static inline
1846 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1847 +{
1848 +}
1849 +
1850 +#endif /* CONFIG_BCM43XX_D80211_DMA */
1851 +#endif /* BCM43xx_DMA_H_ */
1852 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c
1853 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c 1970-01-01 01:00:00.000000000 +0100
1854 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c 2006-03-28 22:16:14.000000000 +0200
1855 @@ -0,0 +1,50 @@
1856 +/*
1857 +
1858 + Broadcom BCM43xx wireless driver
1859 +
1860 + ethtool support
1861 +
1862 + Copyright (c) 2006 Jason Lunz <lunz@falooley.org>
1863 +
1864 + Some code in this file is derived from the 8139too.c driver
1865 + Copyright (C) 2002 Jeff Garzik
1866 +
1867 + This program is free software; you can redistribute it and/or modify
1868 + it under the terms of the GNU General Public License as published by
1869 + the Free Software Foundation; either version 2 of the License, or
1870 + (at your option) any later version.
1871 +
1872 + This program is distributed in the hope that it will be useful,
1873 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1874 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1875 + GNU General Public License for more details.
1876 +
1877 + You should have received a copy of the GNU General Public License
1878 + along with this program; see the file COPYING. If not, write to
1879 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
1880 + Boston, MA 02110-1301, USA.
1881 +
1882 +*/
1883 +
1884 +#include "bcm43xx.h"
1885 +#include "bcm43xx_ethtool.h"
1886 +
1887 +#include <linux/netdevice.h>
1888 +#include <linux/pci.h>
1889 +#include <linux/string.h>
1890 +#include <linux/version.h>
1891 +
1892 +
1893 +static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1894 +{
1895 + struct bcm43xx_private *bcm = bcm43xx_priv(dev);
1896 +
1897 + strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
1898 + strncpy(info->version, UTS_RELEASE, sizeof(info->version));
1899 + strncpy(info->bus_info, pci_name(bcm->pci_dev), ETHTOOL_BUSINFO_LEN);
1900 +}
1901 +
1902 +struct ethtool_ops bcm43xx_ethtool_ops = {
1903 + .get_drvinfo = bcm43xx_get_drvinfo,
1904 + .get_link = ethtool_op_get_link,
1905 +};
1906 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h
1907 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h 1970-01-01 01:00:00.000000000 +0100
1908 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h 2006-03-28 22:16:14.000000000 +0200
1909 @@ -0,0 +1,8 @@
1910 +#ifndef BCM43xx_ETHTOOL_H_
1911 +#define BCM43xx_ETHTOOL_H_
1912 +
1913 +#include <linux/ethtool.h>
1914 +
1915 +extern struct ethtool_ops bcm43xx_ethtool_ops;
1916 +
1917 +#endif /* BCM43xx_ETHTOOL_H_ */
1918 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h
1919 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h 1970-01-01 01:00:00.000000000 +0100
1920 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h 2006-03-28 22:16:14.000000000 +0200
1921 @@ -0,0 +1,917 @@
1922 +#ifndef BCM43xx_H_
1923 +#define BCM43xx_H_
1924 +
1925 +#include <linux/version.h>
1926 +#include <linux/kernel.h>
1927 +#include <linux/spinlock.h>
1928 +#include <linux/interrupt.h>
1929 +#include <linux/stringify.h>
1930 +#include <linux/netdevice.h>
1931 +#include <linux/pci.h>
1932 +#include <asm/atomic.h>
1933 +#include <asm/io.h>
1934 +
1935 +#include <linux/wireless.h>
1936 +#include <net/d80211.h>
1937 +#include <net/d80211_mgmt.h>
1938 +#include <net/d80211_common.h>
1939 +
1940 +#include "bcm43xx_debugfs.h"
1941 +#include "bcm43xx_leds.h"
1942 +#include "bcm43xx_sysfs.h"
1943 +
1944 +
1945 +#define PFX KBUILD_MODNAME ": "
1946 +
1947 +#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
1948 +#define BCM43xx_IRQWAIT_MAX_RETRIES 50
1949 +
1950 +#define BCM43xx_IO_SIZE 8192
1951 +
1952 +/* Active Core PCI Configuration Register. */
1953 +#define BCM43xx_PCICFG_ACTIVE_CORE 0x80
1954 +/* SPROM control register. */
1955 +#define BCM43xx_PCICFG_SPROMCTL 0x88
1956 +/* Interrupt Control PCI Configuration Register. (Only on PCI cores with rev >= 6) */
1957 +#define BCM43xx_PCICFG_ICR 0x94
1958 +
1959 +/* MMIO offsets */
1960 +#define BCM43xx_MMIO_DMA1_REASON 0x20
1961 +#define BCM43xx_MMIO_DMA1_IRQ_MASK 0x24
1962 +#define BCM43xx_MMIO_DMA2_REASON 0x28
1963 +#define BCM43xx_MMIO_DMA2_IRQ_MASK 0x2C
1964 +#define BCM43xx_MMIO_DMA3_REASON 0x30
1965 +#define BCM43xx_MMIO_DMA3_IRQ_MASK 0x34
1966 +#define BCM43xx_MMIO_DMA4_REASON 0x38
1967 +#define BCM43xx_MMIO_DMA4_IRQ_MASK 0x3C
1968 +#define BCM43xx_MMIO_STATUS_BITFIELD 0x120
1969 +#define BCM43xx_MMIO_STATUS2_BITFIELD 0x124
1970 +#define BCM43xx_MMIO_GEN_IRQ_REASON 0x128
1971 +#define BCM43xx_MMIO_GEN_IRQ_MASK 0x12C
1972 +#define BCM43xx_MMIO_RAM_CONTROL 0x130
1973 +#define BCM43xx_MMIO_RAM_DATA 0x134
1974 +#define BCM43xx_MMIO_PS_STATUS 0x140
1975 +#define BCM43xx_MMIO_RADIO_HWENABLED_HI 0x158
1976 +#define BCM43xx_MMIO_SHM_CONTROL 0x160
1977 +#define BCM43xx_MMIO_SHM_DATA 0x164
1978 +#define BCM43xx_MMIO_SHM_DATA_UNALIGNED 0x166
1979 +#define BCM43xx_MMIO_XMITSTAT_0 0x170
1980 +#define BCM43xx_MMIO_XMITSTAT_1 0x174
1981 +#define BCM43xx_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
1982 +#define BCM43xx_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
1983 +#define BCM43xx_MMIO_DMA1_BASE 0x200
1984 +#define BCM43xx_MMIO_DMA2_BASE 0x220
1985 +#define BCM43xx_MMIO_DMA3_BASE 0x240
1986 +#define BCM43xx_MMIO_DMA4_BASE 0x260
1987 +#define BCM43xx_MMIO_PIO1_BASE 0x300
1988 +#define BCM43xx_MMIO_PIO2_BASE 0x310
1989 +#define BCM43xx_MMIO_PIO3_BASE 0x320
1990 +#define BCM43xx_MMIO_PIO4_BASE 0x330
1991 +#define BCM43xx_MMIO_PHY_VER 0x3E0
1992 +#define BCM43xx_MMIO_PHY_RADIO 0x3E2
1993 +#define BCM43xx_MMIO_ANTENNA 0x3E8
1994 +#define BCM43xx_MMIO_CHANNEL 0x3F0
1995 +#define BCM43xx_MMIO_CHANNEL_EXT 0x3F4
1996 +#define BCM43xx_MMIO_RADIO_CONTROL 0x3F6
1997 +#define BCM43xx_MMIO_RADIO_DATA_HIGH 0x3F8
1998 +#define BCM43xx_MMIO_RADIO_DATA_LOW 0x3FA
1999 +#define BCM43xx_MMIO_PHY_CONTROL 0x3FC
2000 +#define BCM43xx_MMIO_PHY_DATA 0x3FE
2001 +#define BCM43xx_MMIO_MACFILTER_CONTROL 0x420
2002 +#define BCM43xx_MMIO_MACFILTER_DATA 0x422
2003 +#define BCM43xx_MMIO_RADIO_HWENABLED_LO 0x49A
2004 +#define BCM43xx_MMIO_GPIO_CONTROL 0x49C
2005 +#define BCM43xx_MMIO_GPIO_MASK 0x49E
2006 +#define BCM43xx_MMIO_TSF_0 0x632 /* core rev < 3 only */
2007 +#define BCM43xx_MMIO_TSF_1 0x634 /* core rev < 3 only */
2008 +#define BCM43xx_MMIO_TSF_2 0x636 /* core rev < 3 only */
2009 +#define BCM43xx_MMIO_TSF_3 0x638 /* core rev < 3 only */
2010 +#define BCM43xx_MMIO_POWERUP_DELAY 0x6A8
2011 +
2012 +/* SPROM offsets. */
2013 +#define BCM43xx_SPROM_BASE 0x1000
2014 +#define BCM43xx_SPROM_BOARDFLAGS2 0x1c
2015 +#define BCM43xx_SPROM_IL0MACADDR 0x24
2016 +#define BCM43xx_SPROM_ET0MACADDR 0x27
2017 +#define BCM43xx_SPROM_ET1MACADDR 0x2a
2018 +#define BCM43xx_SPROM_ETHPHY 0x2d
2019 +#define BCM43xx_SPROM_BOARDREV 0x2e
2020 +#define BCM43xx_SPROM_PA0B0 0x2f
2021 +#define BCM43xx_SPROM_PA0B1 0x30
2022 +#define BCM43xx_SPROM_PA0B2 0x31
2023 +#define BCM43xx_SPROM_WL0GPIO0 0x32
2024 +#define BCM43xx_SPROM_WL0GPIO2 0x33
2025 +#define BCM43xx_SPROM_MAXPWR 0x34
2026 +#define BCM43xx_SPROM_PA1B0 0x35
2027 +#define BCM43xx_SPROM_PA1B1 0x36
2028 +#define BCM43xx_SPROM_PA1B2 0x37
2029 +#define BCM43xx_SPROM_IDL_TSSI_TGT 0x38
2030 +#define BCM43xx_SPROM_BOARDFLAGS 0x39
2031 +#define BCM43xx_SPROM_ANTENNA_GAIN 0x3a
2032 +#define BCM43xx_SPROM_VERSION 0x3f
2033 +
2034 +/* BCM43xx_SPROM_BOARDFLAGS values */
2035 +#define BCM43xx_BFL_BTCOEXIST 0x0001 /* implements Bluetooth coexistance */
2036 +#define BCM43xx_BFL_PACTRL 0x0002 /* GPIO 9 controlling the PA */
2037 +#define BCM43xx_BFL_AIRLINEMODE 0x0004 /* implements GPIO 13 radio disable indication */
2038 +#define BCM43xx_BFL_RSSI 0x0008 /* software calculates nrssi slope. */
2039 +#define BCM43xx_BFL_ENETSPI 0x0010 /* has ephy roboswitch spi */
2040 +#define BCM43xx_BFL_XTAL_NOSLOW 0x0020 /* no slow clock available */
2041 +#define BCM43xx_BFL_CCKHIPWR 0x0040 /* can do high power CCK transmission */
2042 +#define BCM43xx_BFL_ENETADM 0x0080 /* has ADMtek switch */
2043 +#define BCM43xx_BFL_ENETVLAN 0x0100 /* can do vlan */
2044 +#define BCM43xx_BFL_AFTERBURNER 0x0200 /* supports Afterburner mode */
2045 +#define BCM43xx_BFL_NOPCI 0x0400 /* leaves PCI floating */
2046 +#define BCM43xx_BFL_FEM 0x0800 /* supports the Front End Module */
2047 +#define BCM43xx_BFL_EXTLNA 0x1000 /* has an external LNA */
2048 +#define BCM43xx_BFL_HGPA 0x2000 /* had high gain PA */
2049 +#define BCM43xx_BFL_BTCMOD 0x4000 /* BFL_BTCOEXIST is given in alternate GPIOs */
2050 +#define BCM43xx_BFL_ALTIQ 0x8000 /* alternate I/Q settings */
2051 +
2052 +/* GPIO register offset, in both ChipCommon and PCI core. */
2053 +#define BCM43xx_GPIO_CONTROL 0x6c
2054 +
2055 +/* SHM Routing */
2056 +#define BCM43xx_SHM_SHARED 0x0001
2057 +#define BCM43xx_SHM_WIRELESS 0x0002
2058 +#define BCM43xx_SHM_PCM 0x0003
2059 +#define BCM43xx_SHM_HWMAC 0x0004
2060 +#define BCM43xx_SHM_UCODE 0x0300
2061 +
2062 +/* MacFilter offsets. */
2063 +#define BCM43xx_MACFILTER_SELF 0x0000
2064 +#define BCM43xx_MACFILTER_ASSOC 0x0003
2065 +
2066 +/* Chipcommon registers. */
2067 +#define BCM43xx_CHIPCOMMON_CAPABILITIES 0x04
2068 +#define BCM43xx_CHIPCOMMON_PLLONDELAY 0xB0
2069 +#define BCM43xx_CHIPCOMMON_FREFSELDELAY 0xB4
2070 +#define BCM43xx_CHIPCOMMON_SLOWCLKCTL 0xB8
2071 +#define BCM43xx_CHIPCOMMON_SYSCLKCTL 0xC0
2072 +
2073 +/* PCI core specific registers. */
2074 +#define BCM43xx_PCICORE_BCAST_ADDR 0x50
2075 +#define BCM43xx_PCICORE_BCAST_DATA 0x54
2076 +#define BCM43xx_PCICORE_SBTOPCI2 0x108
2077 +
2078 +/* SBTOPCI2 values. */
2079 +#define BCM43xx_SBTOPCI2_PREFETCH 0x4
2080 +#define BCM43xx_SBTOPCI2_BURST 0x8
2081 +
2082 +/* Chipcommon capabilities. */
2083 +#define BCM43xx_CAPABILITIES_PCTL 0x00040000
2084 +#define BCM43xx_CAPABILITIES_PLLMASK 0x00030000
2085 +#define BCM43xx_CAPABILITIES_PLLSHIFT 16
2086 +#define BCM43xx_CAPABILITIES_FLASHMASK 0x00000700
2087 +#define BCM43xx_CAPABILITIES_FLASHSHIFT 8
2088 +#define BCM43xx_CAPABILITIES_EXTBUSPRESENT 0x00000040
2089 +#define BCM43xx_CAPABILITIES_UARTGPIO 0x00000020
2090 +#define BCM43xx_CAPABILITIES_UARTCLOCKMASK 0x00000018
2091 +#define BCM43xx_CAPABILITIES_UARTCLOCKSHIFT 3
2092 +#define BCM43xx_CAPABILITIES_MIPSBIGENDIAN 0x00000004
2093 +#define BCM43xx_CAPABILITIES_NRUARTSMASK 0x00000003
2094 +
2095 +/* PowerControl */
2096 +#define BCM43xx_PCTL_IN 0xB0
2097 +#define BCM43xx_PCTL_OUT 0xB4
2098 +#define BCM43xx_PCTL_OUTENABLE 0xB8
2099 +#define BCM43xx_PCTL_XTAL_POWERUP 0x40
2100 +#define BCM43xx_PCTL_PLL_POWERDOWN 0x80
2101 +
2102 +/* PowerControl Clock Modes */
2103 +#define BCM43xx_PCTL_CLK_FAST 0x00
2104 +#define BCM43xx_PCTL_CLK_SLOW 0x01
2105 +#define BCM43xx_PCTL_CLK_DYNAMIC 0x02
2106 +
2107 +#define BCM43xx_PCTL_FORCE_SLOW 0x0800
2108 +#define BCM43xx_PCTL_FORCE_PLL 0x1000
2109 +#define BCM43xx_PCTL_DYN_XTAL 0x2000
2110 +
2111 +/* COREIDs */
2112 +#define BCM43xx_COREID_CHIPCOMMON 0x800
2113 +#define BCM43xx_COREID_ILINE20 0x801
2114 +#define BCM43xx_COREID_SDRAM 0x803
2115 +#define BCM43xx_COREID_PCI 0x804
2116 +#define BCM43xx_COREID_MIPS 0x805
2117 +#define BCM43xx_COREID_ETHERNET 0x806
2118 +#define BCM43xx_COREID_V90 0x807
2119 +#define BCM43xx_COREID_USB11_HOSTDEV 0x80a
2120 +#define BCM43xx_COREID_IPSEC 0x80b
2121 +#define BCM43xx_COREID_PCMCIA 0x80d
2122 +#define BCM43xx_COREID_EXT_IF 0x80f
2123 +#define BCM43xx_COREID_80211 0x812
2124 +#define BCM43xx_COREID_MIPS_3302 0x816
2125 +#define BCM43xx_COREID_USB11_HOST 0x817
2126 +#define BCM43xx_COREID_USB11_DEV 0x818
2127 +#define BCM43xx_COREID_USB20_HOST 0x819
2128 +#define BCM43xx_COREID_USB20_DEV 0x81a
2129 +#define BCM43xx_COREID_SDIO_HOST 0x81b
2130 +
2131 +/* Core Information Registers */
2132 +#define BCM43xx_CIR_BASE 0xf00
2133 +#define BCM43xx_CIR_SBTPSFLAG (BCM43xx_CIR_BASE + 0x18)
2134 +#define BCM43xx_CIR_SBIMSTATE (BCM43xx_CIR_BASE + 0x90)
2135 +#define BCM43xx_CIR_SBINTVEC (BCM43xx_CIR_BASE + 0x94)
2136 +#define BCM43xx_CIR_SBTMSTATELOW (BCM43xx_CIR_BASE + 0x98)
2137 +#define BCM43xx_CIR_SBTMSTATEHIGH (BCM43xx_CIR_BASE + 0x9c)
2138 +#define BCM43xx_CIR_SBIMCONFIGLOW (BCM43xx_CIR_BASE + 0xa8)
2139 +#define BCM43xx_CIR_SB_ID_HI (BCM43xx_CIR_BASE + 0xfc)
2140 +
2141 +/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
2142 +#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
2143 +
2144 +/* SBIMCONFIGLOW values/masks. */
2145 +#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK 0x00000007
2146 +#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT 0
2147 +#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK 0x00000070
2148 +#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT 4
2149 +#define BCM43xx_SBIMCONFIGLOW_CONNID_MASK 0x00ff0000
2150 +#define BCM43xx_SBIMCONFIGLOW_CONNID_SHIFT 16
2151 +
2152 +/* sbtmstatelow state flags */
2153 +#define BCM43xx_SBTMSTATELOW_RESET 0x01
2154 +#define BCM43xx_SBTMSTATELOW_REJECT 0x02
2155 +#define BCM43xx_SBTMSTATELOW_CLOCK 0x10000
2156 +#define BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK 0x20000
2157 +
2158 +/* sbtmstatehigh state flags */
2159 +#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
2160 +#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
2161 +
2162 +/* sbimstate flags */
2163 +#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
2164 +#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
2165 +
2166 +/* PHYVersioning */
2167 +#define BCM43xx_PHYTYPE_A 0x00
2168 +#define BCM43xx_PHYTYPE_B 0x01
2169 +#define BCM43xx_PHYTYPE_G 0x02
2170 +
2171 +/* PHYRegisters */
2172 +#define BCM43xx_PHY_ILT_A_CTRL 0x0072
2173 +#define BCM43xx_PHY_ILT_A_DATA1 0x0073
2174 +#define BCM43xx_PHY_ILT_A_DATA2 0x0074
2175 +#define BCM43xx_PHY_G_LO_CONTROL 0x0810
2176 +#define BCM43xx_PHY_ILT_G_CTRL 0x0472
2177 +#define BCM43xx_PHY_ILT_G_DATA1 0x0473
2178 +#define BCM43xx_PHY_ILT_G_DATA2 0x0474
2179 +#define BCM43xx_PHY_A_PCTL 0x007B
2180 +#define BCM43xx_PHY_G_PCTL 0x0029
2181 +#define BCM43xx_PHY_A_CRS 0x0029
2182 +#define BCM43xx_PHY_RADIO_BITFIELD 0x0401
2183 +#define BCM43xx_PHY_G_CRS 0x0429
2184 +#define BCM43xx_PHY_NRSSILT_CTRL 0x0803
2185 +#define BCM43xx_PHY_NRSSILT_DATA 0x0804
2186 +
2187 +/* RadioRegisters */
2188 +#define BCM43xx_RADIOCTL_ID 0x01
2189 +
2190 +/* StatusBitField */
2191 +#define BCM43xx_SBF_MAC_ENABLED 0x00000001
2192 +#define BCM43xx_SBF_2 0x00000002 /*FIXME: fix name*/
2193 +#define BCM43xx_SBF_CORE_READY 0x00000004
2194 +#define BCM43xx_SBF_400 0x00000400 /*FIXME: fix name*/
2195 +#define BCM43xx_SBF_4000 0x00004000 /*FIXME: fix name*/
2196 +#define BCM43xx_SBF_8000 0x00008000 /*FIXME: fix name*/
2197 +#define BCM43xx_SBF_XFER_REG_BYTESWAP 0x00010000
2198 +#define BCM43xx_SBF_MODE_NOTADHOC 0x00020000
2199 +#define BCM43xx_SBF_MODE_AP 0x00040000
2200 +#define BCM43xx_SBF_RADIOREG_LOCK 0x00080000
2201 +#define BCM43xx_SBF_MODE_MONITOR 0x00400000
2202 +#define BCM43xx_SBF_MODE_PROMISC 0x01000000
2203 +#define BCM43xx_SBF_PS1 0x02000000
2204 +#define BCM43xx_SBF_PS2 0x04000000
2205 +#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
2206 +#define BCM43xx_SBF_TIME_UPDATE 0x10000000
2207 +#define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/
2208 +
2209 +/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
2210 +#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
2211 +
2212 +#define BCM43xx_UCODEFLAG_AUTODIV 0x0001
2213 +#define BCM43xx_UCODEFLAG_UNKBGPHY 0x0002
2214 +#define BCM43xx_UCODEFLAG_UNKBPHY 0x0004
2215 +#define BCM43xx_UCODEFLAG_UNKGPHY 0x0020
2216 +#define BCM43xx_UCODEFLAG_UNKPACTRL 0x0040
2217 +#define BCM43xx_UCODEFLAG_JAPAN 0x0080
2218 +
2219 +/* Generic-Interrupt reasons. */
2220 +#define BCM43xx_IRQ_READY (1 << 0)
2221 +#define BCM43xx_IRQ_BEACON (1 << 1)
2222 +#define BCM43xx_IRQ_PS (1 << 2)
2223 +#define BCM43xx_IRQ_REG124 (1 << 5)
2224 +#define BCM43xx_IRQ_PMQ (1 << 6)
2225 +#define BCM43xx_IRQ_PIO_WORKAROUND (1 << 8)
2226 +#define BCM43xx_IRQ_XMIT_ERROR (1 << 11)
2227 +#define BCM43xx_IRQ_RX (1 << 15)
2228 +#define BCM43xx_IRQ_SCAN (1 << 16)
2229 +#define BCM43xx_IRQ_NOISE (1 << 18)
2230 +#define BCM43xx_IRQ_XMIT_STATUS (1 << 29)
2231 +
2232 +#define BCM43xx_IRQ_ALL 0xffffffff
2233 +#define BCM43xx_IRQ_INITIAL (BCM43xx_IRQ_PS | \
2234 + BCM43xx_IRQ_REG124 | \
2235 + BCM43xx_IRQ_PMQ | \
2236 + BCM43xx_IRQ_XMIT_ERROR | \
2237 + BCM43xx_IRQ_RX | \
2238 + BCM43xx_IRQ_SCAN | \
2239 + BCM43xx_IRQ_NOISE | \
2240 + BCM43xx_IRQ_XMIT_STATUS)
2241 +
2242 +/* Bus type PCI. */
2243 +#define BCM43xx_BUSTYPE_PCI 0
2244 +/* Bus type Silicone Backplane Bus. */
2245 +#define BCM43xx_BUSTYPE_SB 1
2246 +/* Bus type PCMCIA. */
2247 +#define BCM43xx_BUSTYPE_PCMCIA 2
2248 +
2249 +/* Rate values. */
2250 +#define BCM43xx_CCK_RATE_1MB 0x02
2251 +#define BCM43xx_CCK_RATE_2MB 0x04
2252 +#define BCM43xx_CCK_RATE_5MB 0x0B
2253 +#define BCM43xx_CCK_RATE_11MB 0x16
2254 +#define BCM43xx_OFDM_RATE_6MB 0x0C
2255 +#define BCM43xx_OFDM_RATE_9MB 0x12
2256 +#define BCM43xx_OFDM_RATE_12MB 0x18
2257 +#define BCM43xx_OFDM_RATE_18MB 0x24
2258 +#define BCM43xx_OFDM_RATE_24MB 0x30
2259 +#define BCM43xx_OFDM_RATE_36MB 0x48
2260 +#define BCM43xx_OFDM_RATE_48MB 0x60
2261 +#define BCM43xx_OFDM_RATE_54MB 0x6C
2262 +
2263 +#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
2264 +#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
2265 +
2266 +/* Max size of a security key */
2267 +#define BCM43xx_SEC_KEYSIZE 16
2268 +/* Security algorithms. */
2269 +enum {
2270 + BCM43xx_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
2271 + BCM43xx_SEC_ALGO_WEP,
2272 + BCM43xx_SEC_ALGO_UNKNOWN,
2273 + BCM43xx_SEC_ALGO_AES,
2274 + BCM43xx_SEC_ALGO_WEP104,
2275 + BCM43xx_SEC_ALGO_TKIP,
2276 +};
2277 +
2278 +
2279 +#ifdef assert
2280 +# undef assert
2281 +#endif
2282 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2283 +#define assert(expr) \
2284 + do { \
2285 + if (unlikely(!(expr))) { \
2286 + printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
2287 + #expr, __FILE__, __LINE__, __FUNCTION__); \
2288 + } \
2289 + } while (0)
2290 +#else
2291 +#define assert(expr) do { /* nothing */ } while (0)
2292 +#endif
2293 +
2294 +/* rate limited printk(). */
2295 +#ifdef printkl
2296 +# undef printkl
2297 +#endif
2298 +#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
2299 +/* rate limited printk() for debugging */
2300 +#ifdef dprintkl
2301 +# undef dprintkl
2302 +#endif
2303 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2304 +# define dprintkl printkl
2305 +#else
2306 +# define dprintkl(f, x...) do { /* nothing */ } while (0)
2307 +#endif
2308 +
2309 +/* debugging printk() */
2310 +#ifdef dprintk
2311 +# undef dprintk
2312 +#endif
2313 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2314 +# define dprintk(f, x...) do { printk(f ,##x); } while (0)
2315 +#else
2316 +# define dprintk(f, x...) do { /* nothing */ } while (0)
2317 +#endif
2318 +
2319 +
2320 +struct net_device;
2321 +struct pci_dev;
2322 +struct bcm43xx_dmaring;
2323 +struct bcm43xx_pioqueue;
2324 +
2325 +struct bcm43xx_initval {
2326 + u16 offset;
2327 + u16 size;
2328 + u32 value;
2329 +} __attribute__((__packed__));
2330 +
2331 +/* Values for bcm430x_sprominfo.locale */
2332 +enum {
2333 + BCM43xx_LOCALE_WORLD = 0,
2334 + BCM43xx_LOCALE_THAILAND,
2335 + BCM43xx_LOCALE_ISRAEL,
2336 + BCM43xx_LOCALE_JORDAN,
2337 + BCM43xx_LOCALE_CHINA,
2338 + BCM43xx_LOCALE_JAPAN,
2339 + BCM43xx_LOCALE_USA_CANADA_ANZ,
2340 + BCM43xx_LOCALE_EUROPE,
2341 + BCM43xx_LOCALE_USA_LOW,
2342 + BCM43xx_LOCALE_JAPAN_HIGH,
2343 + BCM43xx_LOCALE_ALL,
2344 + BCM43xx_LOCALE_NONE,
2345 +};
2346 +
2347 +#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
2348 +struct bcm43xx_sprominfo {
2349 + u16 boardflags2;
2350 + u8 il0macaddr[6];
2351 + u8 et0macaddr[6];
2352 + u8 et1macaddr[6];
2353 + u8 et0phyaddr:5;
2354 + u8 et1phyaddr:5;
2355 + u8 et0mdcport:1;
2356 + u8 et1mdcport:1;
2357 + u8 boardrev;
2358 + u8 locale:4;
2359 + u8 antennas_aphy:2;
2360 + u8 antennas_bgphy:2;
2361 + u16 pa0b0;
2362 + u16 pa0b1;
2363 + u16 pa0b2;
2364 + u8 wl0gpio0;
2365 + u8 wl0gpio1;
2366 + u8 wl0gpio2;
2367 + u8 wl0gpio3;
2368 + u8 maxpower_aphy;
2369 + u8 maxpower_bgphy;
2370 + u16 pa1b0;
2371 + u16 pa1b1;
2372 + u16 pa1b2;
2373 + u8 idle_tssi_tgt_aphy;
2374 + u8 idle_tssi_tgt_bgphy;
2375 + u16 boardflags;
2376 + u16 antennagain_aphy;
2377 + u16 antennagain_bgphy;
2378 +};
2379 +
2380 +/* Value pair to measure the LocalOscillator. */
2381 +struct bcm43xx_lopair {
2382 + s8 low;
2383 + s8 high;
2384 + u8 used:1;
2385 +};
2386 +#define BCM43xx_LO_COUNT (14*4)
2387 +
2388 +struct bcm43xx_phyinfo {
2389 + /* Hardware Data */
2390 + u8 version;
2391 + u8 type;
2392 + u8 rev;
2393 + u16 antenna_diversity;
2394 + u16 savedpctlreg;
2395 + u16 minlowsig[2];
2396 + u16 minlowsigpos[2];
2397 + u8 connected:1,
2398 + calibrated:1,
2399 + is_locked:1, /* used in bcm43xx_phy_{un}lock() */
2400 + dyn_tssi_tbl:1; /* used in bcm43xx_phy_init_tssi2dbm_table() */
2401 + /* LO Measurement Data.
2402 + * Use bcm43xx_get_lopair() to get a value.
2403 + */
2404 + struct bcm43xx_lopair *_lo_pairs;
2405 +
2406 + /* TSSI to dBm table in use */
2407 + const s8 *tssi2dbm;
2408 + /* idle TSSI value */
2409 + s8 idle_tssi;
2410 +
2411 + /* Values from bcm43xx_calc_loopback_gain() */
2412 + u16 loopback_gain[2];
2413 +
2414 + /* PHY lock for core.rev < 3
2415 + * This lock is only used by bcm43xx_phy_{un}lock()
2416 + */
2417 + spinlock_t lock;
2418 +};
2419 +
2420 +
2421 +struct bcm43xx_radioinfo {
2422 + u16 manufact;
2423 + u16 version;
2424 + u8 revision;
2425 +
2426 + /* Desired TX power level (in dBm).
2427 + * This is set by the user and adjusted in bcm43xx_phy_xmitpower(). */
2428 + u8 power_level;
2429 + /* TX Power control values. */
2430 + union {
2431 + /* B/G PHY */
2432 + struct {
2433 + u16 baseband_atten;
2434 + u16 radio_atten;
2435 + u16 txctl1;
2436 + u16 txctl2;
2437 + };
2438 + /* A PHY */
2439 + struct {
2440 + u16 txpwr_offset;
2441 + };
2442 + };
2443 +
2444 + /* Current Interference Mitigation mode */
2445 + int interfmode;
2446 + /* Stack of saved values from the Interference Mitigation code.
2447 + * Each value in the stack is layed out as follows:
2448 + * bit 0-11: offset
2449 + * bit 12-15: register ID
2450 + * bit 16-32: value
2451 + * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
2452 + */
2453 +#define BCM43xx_INTERFSTACK_SIZE 26
2454 + u32 interfstack[BCM43xx_INTERFSTACK_SIZE];
2455 +
2456 + /* Saved values from the NRSSI Slope calculation */
2457 + s16 nrssi[2];
2458 + s32 nrssislope;
2459 + /* In memory nrssi lookup table. */
2460 + s8 nrssi_lt[64];
2461 +
2462 + /* current channel */
2463 + u8 channel;
2464 + u8 initial_channel;
2465 +
2466 + u16 lofcal;
2467 +
2468 + u16 initval;
2469 +
2470 + u8 enabled:1;
2471 + /* ACI (adjacent channel interference) flags. */
2472 + u8 aci_enable:1,
2473 + aci_wlan_automatic:1,
2474 + aci_hw_rssi:1;
2475 +};
2476 +
2477 +/* Data structures for DMA transmission, per 80211 core. */
2478 +struct bcm43xx_dma {
2479 + struct bcm43xx_dmaring *tx_ring0;
2480 + struct bcm43xx_dmaring *tx_ring1;
2481 + struct bcm43xx_dmaring *tx_ring2;
2482 + struct bcm43xx_dmaring *tx_ring3;
2483 + struct bcm43xx_dmaring *rx_ring0;
2484 + struct bcm43xx_dmaring *rx_ring1; /* only available on core.rev < 5 */
2485 +};
2486 +
2487 +/* Data structures for PIO transmission, per 80211 core. */
2488 +struct bcm43xx_pio {
2489 + struct bcm43xx_pioqueue *queue0;
2490 + struct bcm43xx_pioqueue *queue1;
2491 + struct bcm43xx_pioqueue *queue2;
2492 + struct bcm43xx_pioqueue *queue3;
2493 +};
2494 +
2495 +#define BCM43xx_MAX_80211_CORES 2
2496 +
2497 +#ifdef CONFIG_BCM947XX
2498 +#define core_offset(bcm) (bcm)->current_core_offset
2499 +#else
2500 +#define core_offset(bcm) 0
2501 +#endif
2502 +
2503 +/* Generic information about a core. */
2504 +struct bcm43xx_coreinfo {
2505 + u8 available:1,
2506 + enabled:1,
2507 + initialized:1;
2508 + /** core_id ID number */
2509 + u16 id;
2510 + /** core_rev revision number */
2511 + u8 rev;
2512 + /** Index number for _switch_core() */
2513 + u8 index;
2514 +};
2515 +
2516 +/* Additional information for each 80211 core. */
2517 +struct bcm43xx_coreinfo_80211 {
2518 + /* PHY device. */
2519 + struct bcm43xx_phyinfo phy;
2520 + /* Radio device. */
2521 + struct bcm43xx_radioinfo radio;
2522 + union {
2523 + /* DMA context. */
2524 + struct bcm43xx_dma dma;
2525 + /* PIO context. */
2526 + struct bcm43xx_pio pio;
2527 + };
2528 +};
2529 +
2530 +/* Context information for a noise calculation (Link Quality). */
2531 +struct bcm43xx_noise_calculation {
2532 + struct bcm43xx_coreinfo *core_at_start;
2533 + u8 channel_at_start;
2534 + u8 calculation_running:1;
2535 + u8 nr_samples;
2536 + s8 samples[8][4];
2537 +};
2538 +
2539 +struct bcm43xx_stats {
2540 + u8 link_quality;
2541 + /* Store the last TX/RX times here for updating the leds. */
2542 + unsigned long last_tx;
2543 + unsigned long last_rx;
2544 +};
2545 +
2546 +struct bcm43xx_key {
2547 + u8 enabled:1;
2548 + u8 algorithm;
2549 +};
2550 +
2551 +struct bcm43xx_private {
2552 + struct bcm43xx_sysfs sysfs;
2553 +
2554 + struct ieee80211_hw *ieee;
2555 + struct ieee80211_low_level_stats ieee_stats;
2556 + int iw_mode;
2557 +
2558 + struct net_device *net_dev;
2559 + struct pci_dev *pci_dev;
2560 + unsigned int irq;
2561 +
2562 + void __iomem *mmio_addr;
2563 + unsigned int mmio_len;
2564 +
2565 + /* Do not use the lock directly. Use the bcm43xx_lock* helper
2566 + * functions, to be MMIO-safe. */
2567 + spinlock_t _lock;
2568 +
2569 + /* Driver status flags. */
2570 + u32 initialized:1, /* init_board() succeed */
2571 + was_initialized:1, /* for PCI suspend/resume. */
2572 + shutting_down:1, /* free_board() in progress */
2573 + __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
2574 + bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
2575 + reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
2576 + powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
2577 + short_preamble:1, /* TRUE, if short preamble is enabled. */
2578 + short_slot:1, /* TRUE, if short slot timing is enabled. */
2579 + firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
2580 +
2581 + struct bcm43xx_stats stats;
2582 +
2583 + /* Bus type we are connected to.
2584 + * This is currently always BCM43xx_BUSTYPE_PCI
2585 + */
2586 + u8 bustype;
2587 +
2588 + u16 board_vendor;
2589 + u16 board_type;
2590 + u16 board_revision;
2591 +
2592 + u16 chip_id;
2593 + u8 chip_rev;
2594 + u8 chip_package;
2595 +
2596 + struct bcm43xx_sprominfo sprom;
2597 +#define BCM43xx_NR_LEDS 4
2598 + struct bcm43xx_led leds[BCM43xx_NR_LEDS];
2599 +
2600 + /* The currently active core. */
2601 + struct bcm43xx_coreinfo *current_core;
2602 +#ifdef CONFIG_BCM947XX
2603 + /** current core memory offset */
2604 + u32 current_core_offset;
2605 +#endif
2606 + struct bcm43xx_coreinfo *active_80211_core;
2607 + /* coreinfo structs for all possible cores follow.
2608 + * Note that a core might not exist.
2609 + * So check the coreinfo flags before using it.
2610 + */
2611 + struct bcm43xx_coreinfo core_chipcommon;
2612 + struct bcm43xx_coreinfo core_pci;
2613 + struct bcm43xx_coreinfo core_80211[ BCM43xx_MAX_80211_CORES ];
2614 + /* Additional information, specific to the 80211 cores. */
2615 + struct bcm43xx_coreinfo_80211 core_80211_ext[ BCM43xx_MAX_80211_CORES ];
2616 + /* Index of the current 80211 core. If current_core is not
2617 + * an 80211 core, this is -1.
2618 + */
2619 + int current_80211_core_idx;
2620 + /* Number of available 80211 cores. */
2621 + int nr_80211_available;
2622 +
2623 + u32 chipcommon_capabilities;
2624 +
2625 + /* Reason code of the last interrupt. */
2626 + u32 irq_reason;
2627 + u32 dma_reason[4];
2628 + /* saved irq enable/disable state bitfield. */
2629 + u32 irq_savedstate;
2630 + /* Link Quality calculation context. */
2631 + struct bcm43xx_noise_calculation noisecalc;
2632 +
2633 + /* Interrupt Service Routine tasklet (bottom-half) */
2634 + struct tasklet_struct isr_tasklet;
2635 +
2636 + /* Periodic tasks */
2637 + struct timer_list periodic_tasks;
2638 + unsigned int periodic_state;
2639 +
2640 + struct work_struct restart_work;
2641 +
2642 + /* Informational stuff. */
2643 + char nick[IW_ESSID_MAX_SIZE + 1];
2644 + u8 bssid[ETH_ALEN];
2645 +
2646 + /* encryption/decryption */
2647 + u16 security_offset;
2648 + struct bcm43xx_key key[54];
2649 + u8 default_key_idx;
2650 +
2651 + /* Firmware. */
2652 + const struct firmware *ucode;
2653 + const struct firmware *pcm;
2654 + const struct firmware *initvals0;
2655 + const struct firmware *initvals1;
2656 +
2657 + /* Cached beacon template while uploading the template. */
2658 + struct sk_buff *cached_beacon;
2659 +
2660 + /* Debugging stuff follows. */
2661 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2662 + struct bcm43xx_dfsentry *dfsentry;
2663 +#endif
2664 +};
2665 +
2666 +/* bcm43xx_(un)lock() protect struct bcm43xx_private.
2667 + * Note that _NO_ MMIO writes are allowed. If you want to
2668 + * write to the device through MMIO in the critical section, use
2669 + * the *_mmio lock functions.
2670 + * MMIO read-access is allowed, though.
2671 + */
2672 +#define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags)
2673 +#define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags)
2674 +/* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO.
2675 + * MMIO write-access to the device is allowed.
2676 + * All MMIO writes are flushed on unlock, so it is guaranteed to not
2677 + * interfere with other threads writing MMIO registers.
2678 + */
2679 +#define bcm43xx_lock_mmio(bcm, flags) bcm43xx_lock(bcm, flags)
2680 +#define bcm43xx_unlock_mmio(bcm, flags) do { mmiowb(); bcm43xx_unlock(bcm, flags); } while (0)
2681 +
2682 +static inline
2683 +struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
2684 +{
2685 + return ieee80211_dev_hw_data(dev);
2686 +}
2687 +
2688 +/* Helper function, which returns a boolean.
2689 + * TRUE, if PIO is used; FALSE, if DMA is used.
2690 + */
2691 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
2692 +static inline
2693 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2694 +{
2695 + return bcm->__using_pio;
2696 +}
2697 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
2698 +static inline
2699 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2700 +{
2701 + return 0;
2702 +}
2703 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
2704 +static inline
2705 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2706 +{
2707 + return 1;
2708 +}
2709 +#else
2710 +# error "Using neither DMA nor PIO? Confused..."
2711 +#endif
2712 +
2713 +/* Helper functions to access data structures private to the 80211 cores.
2714 + * Note that we _must_ have an 80211 core mapped when calling
2715 + * any of these functions.
2716 + */
2717 +static inline
2718 +struct bcm43xx_pio * bcm43xx_current_pio(struct bcm43xx_private *bcm)
2719 +{
2720 + assert(bcm43xx_using_pio(bcm));
2721 + assert(bcm->current_80211_core_idx >= 0);
2722 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2723 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].pio);
2724 +}
2725 +static inline
2726 +struct bcm43xx_dma * bcm43xx_current_dma(struct bcm43xx_private *bcm)
2727 +{
2728 + assert(!bcm43xx_using_pio(bcm));
2729 + assert(bcm->current_80211_core_idx >= 0);
2730 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2731 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].dma);
2732 +}
2733 +static inline
2734 +struct bcm43xx_phyinfo * bcm43xx_current_phy(struct bcm43xx_private *bcm)
2735 +{
2736 + assert(bcm->current_80211_core_idx >= 0);
2737 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2738 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].phy);
2739 +}
2740 +static inline
2741 +struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
2742 +{
2743 + assert(bcm->current_80211_core_idx >= 0);
2744 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2745 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].radio);
2746 +}
2747 +
2748 +/* Are we running in init_board() context? */
2749 +static inline
2750 +int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
2751 +{
2752 + if (bcm->initialized)
2753 + return 0;
2754 + if (bcm->shutting_down)
2755 + return 0;
2756 + return 1;
2757 +}
2758 +
2759 +static inline
2760 +struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
2761 + u16 radio_attenuation,
2762 + u16 baseband_attenuation)
2763 +{
2764 + return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
2765 +}
2766 +
2767 +
2768 +static inline
2769 +u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
2770 +{
2771 + return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
2772 +}
2773 +
2774 +static inline
2775 +void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
2776 +{
2777 + iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
2778 +}
2779 +
2780 +static inline
2781 +u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
2782 +{
2783 + return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
2784 +}
2785 +
2786 +static inline
2787 +void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
2788 +{
2789 + iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
2790 +}
2791 +
2792 +static inline
2793 +int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
2794 +{
2795 + return pci_read_config_word(bcm->pci_dev, offset, value);
2796 +}
2797 +
2798 +static inline
2799 +int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
2800 +{
2801 + return pci_read_config_dword(bcm->pci_dev, offset, value);
2802 +}
2803 +
2804 +static inline
2805 +int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
2806 +{
2807 + return pci_write_config_word(bcm->pci_dev, offset, value);
2808 +}
2809 +
2810 +static inline
2811 +int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
2812 +{
2813 + return pci_write_config_dword(bcm->pci_dev, offset, value);
2814 +}
2815 +
2816 +/** Limit a value between two limits */
2817 +#ifdef limit_value
2818 +# undef limit_value
2819 +#endif
2820 +#define limit_value(value, min, max) \
2821 + ({ \
2822 + typeof(value) __value = (value); \
2823 + typeof(value) __min = (min); \
2824 + typeof(value) __max = (max); \
2825 + if (__value < __min) \
2826 + __value = __min; \
2827 + else if (__value > __max) \
2828 + __value = __max; \
2829 + __value; \
2830 + })
2831 +
2832 +/** Helpers to print MAC addresses. */
2833 +#define BCM43xx_MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
2834 +#define BCM43xx_MACARG(x) ((u8*)(x))[0], ((u8*)(x))[1], \
2835 + ((u8*)(x))[2], ((u8*)(x))[3], \
2836 + ((u8*)(x))[4], ((u8*)(x))[5]
2837 +
2838 +#endif /* BCM43xx_H_ */
2839 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c
2840 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c 1970-01-01 01:00:00.000000000 +0100
2841 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c 2006-03-28 22:16:14.000000000 +0200
2842 @@ -0,0 +1,337 @@
2843 +/*
2844 +
2845 + Broadcom BCM43xx wireless driver
2846 +
2847 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
2848 + Stefano Brivio <st3@riseup.net>
2849 + Michael Buesch <mbuesch@freenet.de>
2850 + Danny van Dyk <kugelfang@gentoo.org>
2851 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
2852 +
2853 + This program is free software; you can redistribute it and/or modify
2854 + it under the terms of the GNU General Public License as published by
2855 + the Free Software Foundation; either version 2 of the License, or
2856 + (at your option) any later version.
2857 +
2858 + This program is distributed in the hope that it will be useful,
2859 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2860 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2861 + GNU General Public License for more details.
2862 +
2863 + You should have received a copy of the GNU General Public License
2864 + along with this program; see the file COPYING. If not, write to
2865 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
2866 + Boston, MA 02110-1301, USA.
2867 +
2868 +*/
2869 +
2870 +#include "bcm43xx.h"
2871 +#include "bcm43xx_ilt.h"
2872 +#include "bcm43xx_phy.h"
2873 +
2874 +
2875 +/**** Initial Internal Lookup Tables ****/
2876 +
2877 +const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE] = {
2878 + 0xFEB93FFD, 0xFEC63FFD, /* 0 */
2879 + 0xFED23FFD, 0xFEDF3FFD,
2880 + 0xFEEC3FFE, 0xFEF83FFE,
2881 + 0xFF053FFE, 0xFF113FFE,
2882 + 0xFF1E3FFE, 0xFF2A3FFF, /* 8 */
2883 + 0xFF373FFF, 0xFF443FFF,
2884 + 0xFF503FFF, 0xFF5D3FFF,
2885 + 0xFF693FFF, 0xFF763FFF,
2886 + 0xFF824000, 0xFF8F4000, /* 16 */
2887 + 0xFF9B4000, 0xFFA84000,
2888 + 0xFFB54000, 0xFFC14000,
2889 + 0xFFCE4000, 0xFFDA4000,
2890 + 0xFFE74000, 0xFFF34000, /* 24 */
2891 + 0x00004000, 0x000D4000,
2892 + 0x00194000, 0x00264000,
2893 + 0x00324000, 0x003F4000,
2894 + 0x004B4000, 0x00584000, /* 32 */
2895 + 0x00654000, 0x00714000,
2896 + 0x007E4000, 0x008A3FFF,
2897 + 0x00973FFF, 0x00A33FFF,
2898 + 0x00B03FFF, 0x00BC3FFF, /* 40 */
2899 + 0x00C93FFF, 0x00D63FFF,
2900 + 0x00E23FFE, 0x00EF3FFE,
2901 + 0x00FB3FFE, 0x01083FFE,
2902 + 0x01143FFE, 0x01213FFD, /* 48 */
2903 + 0x012E3FFD, 0x013A3FFD,
2904 + 0x01473FFD,
2905 +};
2906 +
2907 +const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE] = {
2908 + 0xDB93CB87, 0xD666CF64, /* 0 */
2909 + 0xD1FDD358, 0xCDA6D826,
2910 + 0xCA38DD9F, 0xC729E2B4,
2911 + 0xC469E88E, 0xC26AEE2B,
2912 + 0xC0DEF46C, 0xC073FA62, /* 8 */
2913 + 0xC01D00D5, 0xC0760743,
2914 + 0xC1560D1E, 0xC2E51369,
2915 + 0xC4ED18FF, 0xC7AC1ED7,
2916 + 0xCB2823B2, 0xCEFA28D9, /* 16 */
2917 + 0xD2F62D3F, 0xD7BB3197,
2918 + 0xDCE53568, 0xE1FE3875,
2919 + 0xE7D13B35, 0xED663D35,
2920 + 0xF39B3EC4, 0xF98E3FA7, /* 24 */
2921 + 0x00004000, 0x06723FA7,
2922 + 0x0C653EC4, 0x129A3D35,
2923 + 0x182F3B35, 0x1E023875,
2924 + 0x231B3568, 0x28453197, /* 32 */
2925 + 0x2D0A2D3F, 0x310628D9,
2926 + 0x34D823B2, 0x38541ED7,
2927 + 0x3B1318FF, 0x3D1B1369,
2928 + 0x3EAA0D1E, 0x3F8A0743, /* 40 */
2929 + 0x3FE300D5, 0x3F8DFA62,
2930 + 0x3F22F46C, 0x3D96EE2B,
2931 + 0x3B97E88E, 0x38D7E2B4,
2932 + 0x35C8DD9F, 0x325AD826, /* 48 */
2933 + 0x2E03D358, 0x299ACF64,
2934 + 0x246DCB87,
2935 +};
2936 +
2937 +const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE] = {
2938 + 0x0082, 0x0082, 0x0102, 0x0182, /* 0 */
2939 + 0x0202, 0x0282, 0x0302, 0x0382,
2940 + 0x0402, 0x0482, 0x0502, 0x0582,
2941 + 0x05E2, 0x0662, 0x06E2, 0x0762,
2942 + 0x07E2, 0x0842, 0x08C2, 0x0942, /* 16 */
2943 + 0x09C2, 0x0A22, 0x0AA2, 0x0B02,
2944 + 0x0B82, 0x0BE2, 0x0C62, 0x0CC2,
2945 + 0x0D42, 0x0DA2, 0x0E02, 0x0E62,
2946 + 0x0EE2, 0x0F42, 0x0FA2, 0x1002, /* 32 */
2947 + 0x1062, 0x10C2, 0x1122, 0x1182,
2948 + 0x11E2, 0x1242, 0x12A2, 0x12E2,
2949 + 0x1342, 0x13A2, 0x1402, 0x1442,
2950 + 0x14A2, 0x14E2, 0x1542, 0x1582, /* 48 */
2951 + 0x15E2, 0x1622, 0x1662, 0x16C1,
2952 + 0x1701, 0x1741, 0x1781, 0x17E1,
2953 + 0x1821, 0x1861, 0x18A1, 0x18E1,
2954 + 0x1921, 0x1961, 0x19A1, 0x19E1, /* 64 */
2955 + 0x1A21, 0x1A61, 0x1AA1, 0x1AC1,
2956 + 0x1B01, 0x1B41, 0x1B81, 0x1BA1,
2957 + 0x1BE1, 0x1C21, 0x1C41, 0x1C81,
2958 + 0x1CA1, 0x1CE1, 0x1D01, 0x1D41, /* 80 */
2959 + 0x1D61, 0x1DA1, 0x1DC1, 0x1E01,
2960 + 0x1E21, 0x1E61, 0x1E81, 0x1EA1,
2961 + 0x1EE1, 0x1F01, 0x1F21, 0x1F41,
2962 + 0x1F81, 0x1FA1, 0x1FC1, 0x1FE1, /* 96 */
2963 + 0x2001, 0x2041, 0x2061, 0x2081,
2964 + 0x20A1, 0x20C1, 0x20E1, 0x2101,
2965 + 0x2121, 0x2141, 0x2161, 0x2181,
2966 + 0x21A1, 0x21C1, 0x21E1, 0x2201, /* 112 */
2967 + 0x2221, 0x2241, 0x2261, 0x2281,
2968 + 0x22A1, 0x22C1, 0x22C1, 0x22E1,
2969 + 0x2301, 0x2321, 0x2341, 0x2361,
2970 + 0x2361, 0x2381, 0x23A1, 0x23C1, /* 128 */
2971 + 0x23E1, 0x23E1, 0x2401, 0x2421,
2972 + 0x2441, 0x2441, 0x2461, 0x2481,
2973 + 0x2481, 0x24A1, 0x24C1, 0x24C1,
2974 + 0x24E1, 0x2501, 0x2501, 0x2521, /* 144 */
2975 + 0x2541, 0x2541, 0x2561, 0x2561,
2976 + 0x2581, 0x25A1, 0x25A1, 0x25C1,
2977 + 0x25C1, 0x25E1, 0x2601, 0x2601,
2978 + 0x2621, 0x2621, 0x2641, 0x2641, /* 160 */
2979 + 0x2661, 0x2661, 0x2681, 0x2681,
2980 + 0x26A1, 0x26A1, 0x26C1, 0x26C1,
2981 + 0x26E1, 0x26E1, 0x2701, 0x2701,
2982 + 0x2721, 0x2721, 0x2740, 0x2740, /* 176 */
2983 + 0x2760, 0x2760, 0x2780, 0x2780,
2984 + 0x2780, 0x27A0, 0x27A0, 0x27C0,
2985 + 0x27C0, 0x27E0, 0x27E0, 0x27E0,
2986 + 0x2800, 0x2800, 0x2820, 0x2820, /* 192 */
2987 + 0x2820, 0x2840, 0x2840, 0x2840,
2988 + 0x2860, 0x2860, 0x2880, 0x2880,
2989 + 0x2880, 0x28A0, 0x28A0, 0x28A0,
2990 + 0x28C0, 0x28C0, 0x28C0, 0x28E0, /* 208 */
2991 + 0x28E0, 0x28E0, 0x2900, 0x2900,
2992 + 0x2900, 0x2920, 0x2920, 0x2920,
2993 + 0x2940, 0x2940, 0x2940, 0x2960,
2994 + 0x2960, 0x2960, 0x2960, 0x2980, /* 224 */
2995 + 0x2980, 0x2980, 0x29A0, 0x29A0,
2996 + 0x29A0, 0x29A0, 0x29C0, 0x29C0,
2997 + 0x29C0, 0x29E0, 0x29E0, 0x29E0,
2998 + 0x29E0, 0x2A00, 0x2A00, 0x2A00, /* 240 */
2999 + 0x2A00, 0x2A20, 0x2A20, 0x2A20,
3000 + 0x2A20, 0x2A40, 0x2A40, 0x2A40,
3001 + 0x2A40, 0x2A60, 0x2A60, 0x2A60,
3002 +};
3003 +
3004 +const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE] = {
3005 + 0x0089, 0x02E9, 0x0409, 0x04E9, /* 0 */
3006 + 0x05A9, 0x0669, 0x0709, 0x0789,
3007 + 0x0829, 0x08A9, 0x0929, 0x0989,
3008 + 0x0A09, 0x0A69, 0x0AC9, 0x0B29,
3009 + 0x0BA9, 0x0BE9, 0x0C49, 0x0CA9, /* 16 */
3010 + 0x0D09, 0x0D69, 0x0DA9, 0x0E09,
3011 + 0x0E69, 0x0EA9, 0x0F09, 0x0F49,
3012 + 0x0FA9, 0x0FE9, 0x1029, 0x1089,
3013 + 0x10C9, 0x1109, 0x1169, 0x11A9, /* 32 */
3014 + 0x11E9, 0x1229, 0x1289, 0x12C9,
3015 + 0x1309, 0x1349, 0x1389, 0x13C9,
3016 + 0x1409, 0x1449, 0x14A9, 0x14E9,
3017 + 0x1529, 0x1569, 0x15A9, 0x15E9, /* 48 */
3018 + 0x1629, 0x1669, 0x16A9, 0x16E8,
3019 + 0x1728, 0x1768, 0x17A8, 0x17E8,
3020 + 0x1828, 0x1868, 0x18A8, 0x18E8,
3021 + 0x1928, 0x1968, 0x19A8, 0x19E8, /* 64 */
3022 + 0x1A28, 0x1A68, 0x1AA8, 0x1AE8,
3023 + 0x1B28, 0x1B68, 0x1BA8, 0x1BE8,
3024 + 0x1C28, 0x1C68, 0x1CA8, 0x1CE8,
3025 + 0x1D28, 0x1D68, 0x1DC8, 0x1E08, /* 80 */
3026 + 0x1E48, 0x1E88, 0x1EC8, 0x1F08,
3027 + 0x1F48, 0x1F88, 0x1FE8, 0x2028,
3028 + 0x2068, 0x20A8, 0x2108, 0x2148,
3029 + 0x2188, 0x21C8, 0x2228, 0x2268, /* 96 */
3030 + 0x22C8, 0x2308, 0x2348, 0x23A8,
3031 + 0x23E8, 0x2448, 0x24A8, 0x24E8,
3032 + 0x2548, 0x25A8, 0x2608, 0x2668,
3033 + 0x26C8, 0x2728, 0x2787, 0x27E7, /* 112 */
3034 + 0x2847, 0x28C7, 0x2947, 0x29A7,
3035 + 0x2A27, 0x2AC7, 0x2B47, 0x2BE7,
3036 + 0x2CA7, 0x2D67, 0x2E47, 0x2F67,
3037 + 0x3247, 0x3526, 0x3646, 0x3726, /* 128 */
3038 + 0x3806, 0x38A6, 0x3946, 0x39E6,
3039 + 0x3A66, 0x3AE6, 0x3B66, 0x3BC6,
3040 + 0x3C45, 0x3CA5, 0x3D05, 0x3D85,
3041 + 0x3DE5, 0x3E45, 0x3EA5, 0x3EE5, /* 144 */
3042 + 0x3F45, 0x3FA5, 0x4005, 0x4045,
3043 + 0x40A5, 0x40E5, 0x4145, 0x4185,
3044 + 0x41E5, 0x4225, 0x4265, 0x42C5,
3045 + 0x4305, 0x4345, 0x43A5, 0x43E5, /* 160 */
3046 + 0x4424, 0x4464, 0x44C4, 0x4504,
3047 + 0x4544, 0x4584, 0x45C4, 0x4604,
3048 + 0x4644, 0x46A4, 0x46E4, 0x4724,
3049 + 0x4764, 0x47A4, 0x47E4, 0x4824, /* 176 */
3050 + 0x4864, 0x48A4, 0x48E4, 0x4924,
3051 + 0x4964, 0x49A4, 0x49E4, 0x4A24,
3052 + 0x4A64, 0x4AA4, 0x4AE4, 0x4B23,
3053 + 0x4B63, 0x4BA3, 0x4BE3, 0x4C23, /* 192 */
3054 + 0x4C63, 0x4CA3, 0x4CE3, 0x4D23,
3055 + 0x4D63, 0x4DA3, 0x4DE3, 0x4E23,
3056 + 0x4E63, 0x4EA3, 0x4EE3, 0x4F23,
3057 + 0x4F63, 0x4FC3, 0x5003, 0x5043, /* 208 */
3058 + 0x5083, 0x50C3, 0x5103, 0x5143,
3059 + 0x5183, 0x51E2, 0x5222, 0x5262,
3060 + 0x52A2, 0x52E2, 0x5342, 0x5382,
3061 + 0x53C2, 0x5402, 0x5462, 0x54A2, /* 224 */
3062 + 0x5502, 0x5542, 0x55A2, 0x55E2,
3063 + 0x5642, 0x5682, 0x56E2, 0x5722,
3064 + 0x5782, 0x57E1, 0x5841, 0x58A1,
3065 + 0x5901, 0x5961, 0x59C1, 0x5A21, /* 240 */
3066 + 0x5AA1, 0x5B01, 0x5B81, 0x5BE1,
3067 + 0x5C61, 0x5D01, 0x5D80, 0x5E20,
3068 + 0x5EE0, 0x5FA0, 0x6080, 0x61C0,
3069 +};
3070 +
3071 +const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE] = {
3072 + 0x0001, 0x0001, 0x0001, 0xFFFE,
3073 + 0xFFFE, 0x3FFF, 0x1000, 0x0393,
3074 +};
3075 +
3076 +const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE] = {
3077 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3078 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3079 +};
3080 +
3081 +const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE] = {
3082 + 0x013C, 0x01F5, 0x031A, 0x0631,
3083 + 0x0001, 0x0001, 0x0001, 0x0001,
3084 +};
3085 +
3086 +const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE] = {
3087 + 0x5484, 0x3C40, 0x0000, 0x0000,
3088 + 0x0000, 0x0000, 0x0000, 0x0000,
3089 +};
3090 +
3091 +const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3092 + 0x6C77, 0x5162, 0x3B40, 0x3335, /* 0 */
3093 + 0x2F2D, 0x2A2A, 0x2527, 0x1F21,
3094 + 0x1A1D, 0x1719, 0x1616, 0x1414,
3095 + 0x1414, 0x1400, 0x1414, 0x1614,
3096 + 0x1716, 0x1A19, 0x1F1D, 0x2521, /* 16 */
3097 + 0x2A27, 0x2F2A, 0x332D, 0x3B35,
3098 + 0x5140, 0x6C62, 0x0077,
3099 +};
3100 +
3101 +const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3102 + 0xD8DD, 0xCBD4, 0xBCC0, 0XB6B7, /* 0 */
3103 + 0xB2B0, 0xADAD, 0xA7A9, 0x9FA1,
3104 + 0x969B, 0x9195, 0x8F8F, 0x8A8A,
3105 + 0x8A8A, 0x8A00, 0x8A8A, 0x8F8A,
3106 + 0x918F, 0x9695, 0x9F9B, 0xA7A1, /* 16 */
3107 + 0xADA9, 0xB2AD, 0xB6B0, 0xBCB7,
3108 + 0xCBC0, 0xD8D4, 0x00DD,
3109 +};
3110 +
3111 +const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3112 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 0 */
3113 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3114 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3115 + 0xA4A4, 0xA400, 0xA4A4, 0xA4A4,
3116 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 16 */
3117 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3118 + 0xA4A4, 0xA4A4, 0x00A4,
3119 +};
3120 +
3121 +const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE] = {
3122 + 0x007A, 0x0075, 0x0071, 0x006C, /* 0 */
3123 + 0x0067, 0x0063, 0x005E, 0x0059,
3124 + 0x0054, 0x0050, 0x004B, 0x0046,
3125 + 0x0042, 0x003D, 0x003D, 0x003D,
3126 + 0x003D, 0x003D, 0x003D, 0x003D, /* 16 */
3127 + 0x003D, 0x003D, 0x003D, 0x003D,
3128 + 0x003D, 0x003D, 0x0000, 0x003D,
3129 + 0x003D, 0x003D, 0x003D, 0x003D,
3130 + 0x003D, 0x003D, 0x003D, 0x003D, /* 32 */
3131 + 0x003D, 0x003D, 0x003D, 0x003D,
3132 + 0x0042, 0x0046, 0x004B, 0x0050,
3133 + 0x0054, 0x0059, 0x005E, 0x0063,
3134 + 0x0067, 0x006C, 0x0071, 0x0075, /* 48 */
3135 + 0x007A,
3136 +};
3137 +
3138 +const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE] = {
3139 + 0x00DE, 0x00DC, 0x00DA, 0x00D8, /* 0 */
3140 + 0x00D6, 0x00D4, 0x00D2, 0x00CF,
3141 + 0x00CD, 0x00CA, 0x00C7, 0x00C4,
3142 + 0x00C1, 0x00BE, 0x00BE, 0x00BE,
3143 + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 16 */
3144 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3145 + 0x00BE, 0x00BE, 0x0000, 0x00BE,
3146 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3147 + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 32 */
3148 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3149 + 0x00C1, 0x00C4, 0x00C7, 0x00CA,
3150 + 0x00CD, 0x00CF, 0x00D2, 0x00D4,
3151 + 0x00D6, 0x00D8, 0x00DA, 0x00DC, /* 48 */
3152 + 0x00DE,
3153 +};
3154 +
3155 +/**** Helper functions to access the device Internal Lookup Tables ****/
3156 +
3157 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
3158 +{
3159 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3160 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3161 + mmiowb();
3162 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val);
3163 + } else {
3164 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3165 + mmiowb();
3166 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val);
3167 + }
3168 +}
3169 +
3170 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
3171 +{
3172 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3173 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3174 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_A_DATA1);
3175 + } else {
3176 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3177 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_G_DATA1);
3178 + }
3179 +}
3180 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h
3181 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h 1970-01-01 01:00:00.000000000 +0100
3182 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h 2006-03-28 22:16:14.000000000 +0200
3183 @@ -0,0 +1,32 @@
3184 +#ifndef BCM43xx_ILT_H_
3185 +#define BCM43xx_ILT_H_
3186 +
3187 +#define BCM43xx_ILT_ROTOR_SIZE 53
3188 +extern const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE];
3189 +#define BCM43xx_ILT_RETARD_SIZE 53
3190 +extern const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE];
3191 +#define BCM43xx_ILT_FINEFREQA_SIZE 256
3192 +extern const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE];
3193 +#define BCM43xx_ILT_FINEFREQG_SIZE 256
3194 +extern const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE];
3195 +#define BCM43xx_ILT_NOISEA2_SIZE 8
3196 +extern const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE];
3197 +#define BCM43xx_ILT_NOISEA3_SIZE 8
3198 +extern const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE];
3199 +#define BCM43xx_ILT_NOISEG1_SIZE 8
3200 +extern const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE];
3201 +#define BCM43xx_ILT_NOISEG2_SIZE 8
3202 +extern const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE];
3203 +#define BCM43xx_ILT_NOISESCALEG_SIZE 27
3204 +extern const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE];
3205 +extern const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE];
3206 +extern const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE];
3207 +#define BCM43xx_ILT_SIGMASQR_SIZE 53
3208 +extern const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE];
3209 +extern const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE];
3210 +
3211 +
3212 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
3213 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
3214 +
3215 +#endif /* BCM43xx_ILT_H_ */
3216 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c
3217 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c 1970-01-01 01:00:00.000000000 +0100
3218 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c 2006-03-28 22:16:14.000000000 +0200
3219 @@ -0,0 +1,293 @@
3220 +/*
3221 +
3222 + Broadcom BCM43xx wireless driver
3223 +
3224 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
3225 + Stefano Brivio <st3@riseup.net>
3226 + Michael Buesch <mbuesch@freenet.de>
3227 + Danny van Dyk <kugelfang@gentoo.org>
3228 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
3229 +
3230 + This program is free software; you can redistribute it and/or modify
3231 + it under the terms of the GNU General Public License as published by
3232 + the Free Software Foundation; either version 2 of the License, or
3233 + (at your option) any later version.
3234 +
3235 + This program is distributed in the hope that it will be useful,
3236 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3237 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3238 + GNU General Public License for more details.
3239 +
3240 + You should have received a copy of the GNU General Public License
3241 + along with this program; see the file COPYING. If not, write to
3242 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
3243 + Boston, MA 02110-1301, USA.
3244 +
3245 +*/
3246 +
3247 +#include "bcm43xx_leds.h"
3248 +#include "bcm43xx.h"
3249 +
3250 +#include <asm/bitops.h>
3251 +
3252 +
3253 +static void bcm43xx_led_changestate(struct bcm43xx_led *led)
3254 +{
3255 + struct bcm43xx_private *bcm = led->bcm;
3256 + const int index = bcm43xx_led_index(led);
3257 + const u16 mask = (1 << index);
3258 + u16 ledctl;
3259 +
3260 + assert(index >= 0 && index < BCM43xx_NR_LEDS);
3261 + assert(led->blink_interval);
3262 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3263 + ledctl = (ledctl & mask) ? (ledctl & ~mask) : (ledctl | mask);
3264 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3265 +}
3266 +
3267 +static void bcm43xx_led_blink(unsigned long d)
3268 +{
3269 + struct bcm43xx_led *led = (struct bcm43xx_led *)d;
3270 + struct bcm43xx_private *bcm = led->bcm;
3271 + unsigned long flags;
3272 +
3273 + bcm43xx_lock_mmio(bcm, flags);
3274 + if (led->blink_interval) {
3275 + bcm43xx_led_changestate(led);
3276 + mod_timer(&led->blink_timer, jiffies + led->blink_interval);
3277 + }
3278 + bcm43xx_unlock_mmio(bcm, flags);
3279 +}
3280 +
3281 +static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
3282 + unsigned long interval)
3283 +{
3284 + if (led->blink_interval)
3285 + return;
3286 + led->blink_interval = interval;
3287 + bcm43xx_led_changestate(led);
3288 + led->blink_timer.expires = jiffies + interval;
3289 + add_timer(&led->blink_timer);
3290 +}
3291 +
3292 +static void bcm43xx_led_blink_stop(struct bcm43xx_led *led, int sync)
3293 +{
3294 + struct bcm43xx_private *bcm = led->bcm;
3295 + const int index = bcm43xx_led_index(led);
3296 + u16 ledctl;
3297 +
3298 + if (!led->blink_interval)
3299 + return;
3300 + if (unlikely(sync))
3301 + del_timer_sync(&led->blink_timer);
3302 + else
3303 + del_timer(&led->blink_timer);
3304 + led->blink_interval = 0;
3305 +
3306 + /* Make sure the LED is turned off. */
3307 + assert(index >= 0 && index < BCM43xx_NR_LEDS);
3308 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3309 + if (led->activelow)
3310 + ledctl |= (1 << index);
3311 + else
3312 + ledctl &= ~(1 << index);
3313 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3314 +}
3315 +
3316 +static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
3317 + struct bcm43xx_led *led,
3318 + int led_index)
3319 +{
3320 + /* This function is called, if the behaviour (and activelow)
3321 + * information for a LED is missing in the SPROM.
3322 + * We hardcode the behaviour values for various devices here.
3323 + * Note that the BCM43xx_LED_TEST_XXX behaviour values can
3324 + * be used to figure out which led is mapped to which index.
3325 + */
3326 +
3327 + switch (led_index) {
3328 + case 0:
3329 + led->behaviour = BCM43xx_LED_ACTIVITY;
3330 + if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
3331 + led->behaviour = BCM43xx_LED_RADIO_ALL;
3332 + break;
3333 + case 1:
3334 + led->behaviour = BCM43xx_LED_RADIO_B;
3335 + if (bcm->board_vendor == PCI_VENDOR_ID_ASUSTEK)
3336 + led->behaviour = BCM43xx_LED_ASSOC;
3337 + break;
3338 + case 2:
3339 + led->behaviour = BCM43xx_LED_RADIO_A;
3340 + break;
3341 + case 3:
3342 + led->behaviour = BCM43xx_LED_OFF;
3343 + break;
3344 + default:
3345 + assert(0);
3346 + }
3347 +}
3348 +
3349 +int bcm43xx_leds_init(struct bcm43xx_private *bcm)
3350 +{
3351 + struct bcm43xx_led *led;
3352 + u8 sprom[4];
3353 + int i;
3354 +
3355 + sprom[0] = bcm->sprom.wl0gpio0;
3356 + sprom[1] = bcm->sprom.wl0gpio1;
3357 + sprom[2] = bcm->sprom.wl0gpio2;
3358 + sprom[3] = bcm->sprom.wl0gpio3;
3359 +
3360 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3361 + led = &(bcm->leds[i]);
3362 + led->bcm = bcm;
3363 + setup_timer(&led->blink_timer,
3364 + bcm43xx_led_blink,
3365 + (unsigned long)led);
3366 +
3367 + if (sprom[i] == 0xFF) {
3368 + bcm43xx_led_init_hardcoded(bcm, led, i);
3369 + } else {
3370 + led->behaviour = sprom[i] & BCM43xx_LED_BEHAVIOUR;
3371 + led->activelow = !!(sprom[i] & BCM43xx_LED_ACTIVELOW);
3372 + }
3373 + }
3374 +
3375 + return 0;
3376 +}
3377 +
3378 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm)
3379 +{
3380 + struct bcm43xx_led *led;
3381 + int i;
3382 +
3383 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3384 + led = &(bcm->leds[i]);
3385 + bcm43xx_led_blink_stop(led, 1);
3386 + }
3387 + bcm43xx_leds_switch_all(bcm, 0);
3388 +}
3389 +
3390 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
3391 +{
3392 + struct bcm43xx_led *led;
3393 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
3394 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3395 + const int transferring = (jiffies - bcm->stats.last_tx) < BCM43xx_LED_XFER_THRES;
3396 + int i, turn_on;
3397 + unsigned long interval = 0;
3398 + u16 ledctl;
3399 +
3400 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3401 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3402 + led = &(bcm->leds[i]);
3403 +
3404 + turn_on = 0;
3405 + switch (led->behaviour) {
3406 + case BCM43xx_LED_INACTIVE:
3407 + continue;
3408 + case BCM43xx_LED_OFF:
3409 + break;
3410 + case BCM43xx_LED_ON:
3411 + turn_on = 1;
3412 + break;
3413 + case BCM43xx_LED_ACTIVITY:
3414 + turn_on = activity;
3415 + break;
3416 + case BCM43xx_LED_RADIO_ALL:
3417 + turn_on = radio->enabled;
3418 + break;
3419 + case BCM43xx_LED_RADIO_A:
3420 + turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
3421 + break;
3422 + case BCM43xx_LED_RADIO_B:
3423 + turn_on = (radio->enabled &&
3424 + (phy->type == BCM43xx_PHYTYPE_B ||
3425 + phy->type == BCM43xx_PHYTYPE_G));
3426 + break;
3427 + case BCM43xx_LED_MODE_BG:
3428 + if (phy->type == BCM43xx_PHYTYPE_G &&
3429 + 1/*FIXME: using G rates.*/)
3430 + turn_on = 1;
3431 + break;
3432 + case BCM43xx_LED_TRANSFER:
3433 + if (transferring)
3434 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3435 + else
3436 + bcm43xx_led_blink_stop(led, 0);
3437 + continue;
3438 + case BCM43xx_LED_APTRANSFER:
3439 + if (bcm->iw_mode == IW_MODE_MASTER) {
3440 + if (transferring) {
3441 + interval = BCM43xx_LEDBLINK_FAST;
3442 + turn_on = 1;
3443 + }
3444 + } else {
3445 + turn_on = 1;
3446 + if (0/*TODO: not assoc*/)
3447 + interval = BCM43xx_LEDBLINK_SLOW;
3448 + else if (transferring)
3449 + interval = BCM43xx_LEDBLINK_FAST;
3450 + else
3451 + turn_on = 0;
3452 + }
3453 + if (turn_on)
3454 + bcm43xx_led_blink_start(led, interval);
3455 + else
3456 + bcm43xx_led_blink_stop(led, 0);
3457 + continue;
3458 + case BCM43xx_LED_WEIRD:
3459 + //TODO
3460 + break;
3461 + case BCM43xx_LED_ASSOC:
3462 + if (1/*bcm->softmac->associated*/)
3463 + turn_on = 1;
3464 + break;
3465 +#ifdef CONFIG_BCM43XX_DEBUG
3466 + case BCM43xx_LED_TEST_BLINKSLOW:
3467 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_SLOW);
3468 + continue;
3469 + case BCM43xx_LED_TEST_BLINKMEDIUM:
3470 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3471 + continue;
3472 + case BCM43xx_LED_TEST_BLINKFAST:
3473 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_FAST);
3474 + continue;
3475 +#endif /* CONFIG_BCM43XX_DEBUG */
3476 + default:
3477 + assert(0);
3478 + };
3479 +
3480 + if (led->activelow)
3481 + turn_on = !turn_on;
3482 + if (turn_on)
3483 + ledctl |= (1 << i);
3484 + else
3485 + ledctl &= ~(1 << i);
3486 + }
3487 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3488 +}
3489 +
3490 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
3491 +{
3492 + struct bcm43xx_led *led;
3493 + u16 ledctl;
3494 + int i;
3495 + int bit_on;
3496 +
3497 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3498 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3499 + led = &(bcm->leds[i]);
3500 + if (led->behaviour == BCM43xx_LED_INACTIVE)
3501 + continue;
3502 + if (on)
3503 + bit_on = led->activelow ? 0 : 1;
3504 + else
3505 + bit_on = led->activelow ? 1 : 0;
3506 + if (bit_on)
3507 + ledctl |= (1 << i);
3508 + else
3509 + ledctl &= ~(1 << i);
3510 + }
3511 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3512 +}
3513 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h
3514 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h 1970-01-01 01:00:00.000000000 +0100
3515 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h 2006-03-28 22:16:14.000000000 +0200
3516 @@ -0,0 +1,56 @@
3517 +#ifndef BCM43xx_LEDS_H_
3518 +#define BCM43xx_LEDS_H_
3519 +
3520 +#include <linux/types.h>
3521 +#include <linux/timer.h>
3522 +
3523 +
3524 +struct bcm43xx_led {
3525 + u8 behaviour:7;
3526 + u8 activelow:1;
3527 +
3528 + struct bcm43xx_private *bcm;
3529 + struct timer_list blink_timer;
3530 + unsigned long blink_interval;
3531 +};
3532 +#define bcm43xx_led_index(led) ((int)((led) - (led)->bcm->leds))
3533 +
3534 +/* Delay between state changes when blinking in jiffies */
3535 +#define BCM43xx_LEDBLINK_SLOW (HZ / 1)
3536 +#define BCM43xx_LEDBLINK_MEDIUM (HZ / 4)
3537 +#define BCM43xx_LEDBLINK_FAST (HZ / 8)
3538 +
3539 +#define BCM43xx_LED_XFER_THRES (HZ / 100)
3540 +
3541 +#define BCM43xx_LED_BEHAVIOUR 0x7F
3542 +#define BCM43xx_LED_ACTIVELOW 0x80
3543 +enum { /* LED behaviour values */
3544 + BCM43xx_LED_OFF,
3545 + BCM43xx_LED_ON,
3546 + BCM43xx_LED_ACTIVITY,
3547 + BCM43xx_LED_RADIO_ALL,
3548 + BCM43xx_LED_RADIO_A,
3549 + BCM43xx_LED_RADIO_B,
3550 + BCM43xx_LED_MODE_BG,
3551 + BCM43xx_LED_TRANSFER,
3552 + BCM43xx_LED_APTRANSFER,
3553 + BCM43xx_LED_WEIRD,//FIXME
3554 + BCM43xx_LED_ASSOC,
3555 + BCM43xx_LED_INACTIVE,
3556 +
3557 + /* Behaviour values for testing.
3558 + * With these values it is easier to figure out
3559 + * the real behaviour of leds, in case the SPROM
3560 + * is missing information.
3561 + */
3562 + BCM43xx_LED_TEST_BLINKSLOW,
3563 + BCM43xx_LED_TEST_BLINKMEDIUM,
3564 + BCM43xx_LED_TEST_BLINKFAST,
3565 +};
3566 +
3567 +int bcm43xx_leds_init(struct bcm43xx_private *bcm);
3568 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm);
3569 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity);
3570 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on);
3571 +
3572 +#endif /* BCM43xx_LEDS_H_ */
3573 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c
3574 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c 1970-01-01 01:00:00.000000000 +0100
3575 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c 2006-03-28 22:16:14.000000000 +0200
3576 @@ -0,0 +1,4491 @@
3577 +/*
3578 +
3579 + Broadcom BCM43xx wireless driver
3580 +
3581 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
3582 + Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
3583 + Copyright (c) 2005, 2006 Michael Buesch <mbuesch@freenet.de>
3584 + Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
3585 + Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
3586 +
3587 + Some parts of the code in this file are derived from the ipw2200
3588 + driver Copyright(c) 2003 - 2004 Intel Corporation.
3589 +
3590 + This program is free software; you can redistribute it and/or modify
3591 + it under the terms of the GNU General Public License as published by
3592 + the Free Software Foundation; either version 2 of the License, or
3593 + (at your option) any later version.
3594 +
3595 + This program is distributed in the hope that it will be useful,
3596 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3597 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3598 + GNU General Public License for more details.
3599 +
3600 + You should have received a copy of the GNU General Public License
3601 + along with this program; see the file COPYING. If not, write to
3602 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
3603 + Boston, MA 02110-1301, USA.
3604 +
3605 +*/
3606 +
3607 +#include <linux/delay.h>
3608 +#include <linux/init.h>
3609 +#include <linux/moduleparam.h>
3610 +#include <linux/if_arp.h>
3611 +#include <linux/etherdevice.h>
3612 +#include <linux/version.h>
3613 +#include <linux/firmware.h>
3614 +#include <linux/wireless.h>
3615 +#include <linux/workqueue.h>
3616 +#include <linux/skbuff.h>
3617 +#include <linux/dma-mapping.h>
3618 +#include <net/iw_handler.h>
3619 +
3620 +#include "bcm43xx.h"
3621 +#include "bcm43xx_main.h"
3622 +#include "bcm43xx_debugfs.h"
3623 +#include "bcm43xx_radio.h"
3624 +#include "bcm43xx_phy.h"
3625 +#include "bcm43xx_dma.h"
3626 +#include "bcm43xx_pio.h"
3627 +#include "bcm43xx_power.h"
3628 +#include "bcm43xx_sysfs.h"
3629 +#include "bcm43xx_ethtool.h"
3630 +#include "bcm43xx_xmit.h"
3631 +
3632 +
3633 +MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
3634 +MODULE_AUTHOR("Martin Langer");
3635 +MODULE_AUTHOR("Stefano Brivio");
3636 +MODULE_AUTHOR("Michael Buesch");
3637 +MODULE_LICENSE("GPL");
3638 +
3639 +#ifdef CONFIG_BCM947XX
3640 +extern char *nvram_get(char *name);
3641 +#endif
3642 +
3643 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
3644 +static int modparam_pio;
3645 +module_param_named(pio, modparam_pio, int, 0444);
3646 +MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
3647 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
3648 +# define modparam_pio 0
3649 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
3650 +# define modparam_pio 1
3651 +#endif
3652 +
3653 +static int modparam_bad_frames_preempt;
3654 +module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
3655 +MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
3656 +
3657 +static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
3658 +module_param_named(short_retry, modparam_short_retry, int, 0444);
3659 +MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
3660 +
3661 +static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
3662 +module_param_named(long_retry, modparam_long_retry, int, 0444);
3663 +MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
3664 +
3665 +static int modparam_noleds;
3666 +module_param_named(noleds, modparam_noleds, int, 0444);
3667 +MODULE_PARM_DESC(noleds, "Turn off all LED activity");
3668 +
3669 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
3670 +static char modparam_fwpostfix[64];
3671 +module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
3672 +MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
3673 +#else
3674 +# define modparam_fwpostfix ""
3675 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
3676 +
3677 +
3678 +/* If you want to debug with just a single device, enable this,
3679 + * where the string is the pci device ID (as given by the kernel's
3680 + * pci_name function) of the device to be used.
3681 + */
3682 +//#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
3683 +
3684 +/* If you want to enable printing of each MMIO access, enable this. */
3685 +//#define DEBUG_ENABLE_MMIO_PRINT
3686 +
3687 +/* If you want to enable printing of MMIO access within
3688 + * ucode/pcm upload, initvals write, enable this.
3689 + */
3690 +//#define DEBUG_ENABLE_UCODE_MMIO_PRINT
3691 +
3692 +/* If you want to enable printing of PCI Config Space access, enable this */
3693 +//#define DEBUG_ENABLE_PCILOG
3694 +
3695 +
3696 +/* Detailed list maintained at:
3697 + * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
3698 + */
3699 +static struct pci_device_id bcm43xx_pci_tbl[] = {
3700 + /* Broadcom 4303 802.11b */
3701 + { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3702 + /* Broadcom 4307 802.11b */
3703 + { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3704 + /* Broadcom 4318 802.11b/g */
3705 + { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3706 + /* Broadcom 4306 802.11b/g */
3707 + { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3708 + /* Broadcom 4306 802.11a */
3709 +// { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3710 + /* Broadcom 4309 802.11a/b/g */
3711 + { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3712 + /* Broadcom 43XG 802.11b/g */
3713 + { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3714 +#ifdef CONFIG_BCM947XX
3715 + /* SB bus on BCM947xx */
3716 + { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3717 +#endif
3718 + { 0 },
3719 +};
3720 +MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
3721 +
3722 +
3723 +static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
3724 +{
3725 + u32 status;
3726 +
3727 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3728 + if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
3729 + val = swab32(val);
3730 +
3731 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
3732 + mmiowb();
3733 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
3734 +}
3735 +
3736 +static inline
3737 +void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
3738 + u16 routing, u16 offset)
3739 +{
3740 + u32 control;
3741 +
3742 + /* "offset" is the WORD offset. */
3743 +
3744 + control = routing;
3745 + control <<= 16;
3746 + control |= offset;
3747 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
3748 +}
3749 +
3750 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
3751 + u16 routing, u16 offset)
3752 +{
3753 + u32 ret;
3754 +
3755 + if (routing == BCM43xx_SHM_SHARED) {
3756 + if (offset & 0x0003) {
3757 + /* Unaligned access */
3758 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3759 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
3760 + ret <<= 16;
3761 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3762 + ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3763 +
3764 + return ret;
3765 + }
3766 + offset >>= 2;
3767 + }
3768 + bcm43xx_shm_control_word(bcm, routing, offset);
3769 + ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
3770 +
3771 + return ret;
3772 +}
3773 +
3774 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
3775 + u16 routing, u16 offset)
3776 +{
3777 + u16 ret;
3778 +
3779 + if (routing == BCM43xx_SHM_SHARED) {
3780 + if (offset & 0x0003) {
3781 + /* Unaligned access */
3782 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3783 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
3784 +
3785 + return ret;
3786 + }
3787 + offset >>= 2;
3788 + }
3789 + bcm43xx_shm_control_word(bcm, routing, offset);
3790 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3791 +
3792 + return ret;
3793 +}
3794 +
3795 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
3796 + u16 routing, u16 offset,
3797 + u32 value)
3798 +{
3799 + if (routing == BCM43xx_SHM_SHARED) {
3800 + if (offset & 0x0003) {
3801 + /* Unaligned access */
3802 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3803 + mmiowb();
3804 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3805 + (value >> 16) & 0xffff);
3806 + mmiowb();
3807 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3808 + mmiowb();
3809 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
3810 + value & 0xffff);
3811 + return;
3812 + }
3813 + offset >>= 2;
3814 + }
3815 + bcm43xx_shm_control_word(bcm, routing, offset);
3816 + mmiowb();
3817 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
3818 +}
3819 +
3820 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
3821 + u16 routing, u16 offset,
3822 + u16 value)
3823 +{
3824 + if (routing == BCM43xx_SHM_SHARED) {
3825 + if (offset & 0x0003) {
3826 + /* Unaligned access */
3827 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3828 + mmiowb();
3829 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3830 + value);
3831 + return;
3832 + }
3833 + offset >>= 2;
3834 + }
3835 + bcm43xx_shm_control_word(bcm, routing, offset);
3836 + mmiowb();
3837 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
3838 +}
3839 +
3840 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
3841 +{
3842 + /* We need to be careful. As we read the TSF from multiple
3843 + * registers, we should take care of register overflows.
3844 + * In theory, the whole tsf read process should be atomic.
3845 + * We try to be atomic here, by restaring the read process,
3846 + * if any of the high registers changed (overflew).
3847 + */
3848 + if (bcm->current_core->rev >= 3) {
3849 + u32 low, high, high2;
3850 +
3851 + do {
3852 + high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
3853 + low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
3854 + high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
3855 + } while (unlikely(high != high2));
3856 +
3857 + *tsf = high;
3858 + *tsf <<= 32;
3859 + *tsf |= low;
3860 + } else {
3861 + u64 tmp;
3862 + u16 v0, v1, v2, v3;
3863 + u16 test1, test2, test3;
3864 +
3865 + do {
3866 + v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
3867 + v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
3868 + v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
3869 + v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
3870 +
3871 + test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
3872 + test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
3873 + test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
3874 + } while (v3 != test3 || v2 != test2 || v1 != test1);
3875 +
3876 + *tsf = v3;
3877 + *tsf <<= 48;
3878 + tmp = v2;
3879 + tmp <<= 32;
3880 + *tsf |= tmp;
3881 + tmp = v1;
3882 + tmp <<= 16;
3883 + *tsf |= tmp;
3884 + *tsf |= v0;
3885 + }
3886 +}
3887 +
3888 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
3889 +{
3890 + u32 status;
3891 +
3892 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3893 + status |= BCM43xx_SBF_TIME_UPDATE;
3894 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
3895 + mmiowb();
3896 +
3897 + /* Be careful with the in-progress timer.
3898 + * First zero out the low register, so we have a full
3899 + * register-overflow duration to complete the operation.
3900 + */
3901 + if (bcm->current_core->rev >= 3) {
3902 + u32 lo = (tsf & 0x00000000FFFFFFFFULL);
3903 + u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
3904 +
3905 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
3906 + mmiowb();
3907 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
3908 + mmiowb();
3909 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
3910 + } else {
3911 + u16 v0 = (tsf & 0x000000000000FFFFULL);
3912 + u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
3913 + u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
3914 + u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
3915 +
3916 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
3917 + mmiowb();
3918 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
3919 + mmiowb();
3920 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
3921 + mmiowb();
3922 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
3923 + mmiowb();
3924 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
3925 + }
3926 +
3927 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3928 + status &= ~BCM43xx_SBF_TIME_UPDATE;
3929 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
3930 +}
3931 +
3932 +static
3933 +void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
3934 + u16 offset,
3935 + const u8 *mac)
3936 +{
3937 + u16 data;
3938 +
3939 + offset |= 0x0020;
3940 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
3941 +
3942 + data = mac[0];
3943 + data |= mac[1] << 8;
3944 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3945 + data = mac[2];
3946 + data |= mac[3] << 8;
3947 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3948 + data = mac[4];
3949 + data |= mac[5] << 8;
3950 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3951 +}
3952 +
3953 +static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
3954 + u16 offset)
3955 +{
3956 + const u8 zero_addr[ETH_ALEN] = { 0 };
3957 +
3958 + bcm43xx_macfilter_set(bcm, offset, zero_addr);
3959 +}
3960 +
3961 +static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
3962 +{
3963 + const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
3964 + const u8 *bssid = bcm->bssid;
3965 + u8 mac_bssid[ETH_ALEN * 2];
3966 + int i;
3967 +
3968 + memcpy(mac_bssid, mac, ETH_ALEN);
3969 + memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
3970 +
3971 + /* Write our MAC address and BSSID to template ram */
3972 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
3973 + bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
3974 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
3975 + bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
3976 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
3977 + bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
3978 +}
3979 +
3980 +static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
3981 +{
3982 + /* slot_time is in usec. */
3983 + if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
3984 + return;
3985 + bcm43xx_write16(bcm, 0x684, 510 + slot_time);
3986 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
3987 +}
3988 +
3989 +static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
3990 +{
3991 + bcm43xx_set_slot_time(bcm, 9);
3992 + bcm->short_slot = 1;
3993 +}
3994 +
3995 +static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
3996 +{
3997 + bcm43xx_set_slot_time(bcm, 20);
3998 + bcm->short_slot = 0;
3999 +}
4000 +
4001 +/* FIXME: To get the MAC-filter working, we need to implement the
4002 + * following functions (and rename them :)
4003 + */
4004 +#if 0
4005 +static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
4006 +{
4007 + bcm43xx_mac_suspend(bcm);
4008 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
4009 +
4010 + bcm43xx_ram_write(bcm, 0x0026, 0x0000);
4011 + bcm43xx_ram_write(bcm, 0x0028, 0x0000);
4012 + bcm43xx_ram_write(bcm, 0x007E, 0x0000);
4013 + bcm43xx_ram_write(bcm, 0x0080, 0x0000);
4014 + bcm43xx_ram_write(bcm, 0x047E, 0x0000);
4015 + bcm43xx_ram_write(bcm, 0x0480, 0x0000);
4016 +
4017 + if (bcm->current_core->rev < 3) {
4018 + bcm43xx_write16(bcm, 0x0610, 0x8000);
4019 + bcm43xx_write16(bcm, 0x060E, 0x0000);
4020 + } else
4021 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
4022 +
4023 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
4024 +
4025 +#if 0
4026 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G &&
4027 + ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
4028 + bcm43xx_short_slot_timing_enable(bcm);
4029 +#endif
4030 +
4031 + bcm43xx_mac_enable(bcm);
4032 +}
4033 +
4034 +static void bcm43xx_associate(struct bcm43xx_private *bcm,
4035 + const u8 *mac)
4036 +{
4037 + bcm43xx_mac_suspend(bcm);
4038 + bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
4039 + bcm43xx_write_mac_bssid_templates(bcm);
4040 + bcm43xx_mac_enable(bcm);
4041 +}
4042 +#endif
4043 +
4044 +/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
4045 + * Returns the _previously_ enabled IRQ mask.
4046 + */
4047 +static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
4048 +{
4049 + u32 old_mask;
4050 +
4051 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4052 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
4053 +
4054 + return old_mask;
4055 +}
4056 +
4057 +/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
4058 + * Returns the _previously_ enabled IRQ mask.
4059 + */
4060 +static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
4061 +{
4062 + u32 old_mask;
4063 +
4064 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4065 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
4066 +
4067 + return old_mask;
4068 +}
4069 +
4070 +/* Make sure we don't receive more data from the device. */
4071 +static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *oldstate)
4072 +{
4073 + u32 old;
4074 + unsigned long flags;
4075 +
4076 + bcm43xx_lock_mmio(bcm, flags);
4077 + if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
4078 + bcm43xx_unlock_mmio(bcm, flags);
4079 + return -EBUSY;
4080 + }
4081 + old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4082 + tasklet_disable(&bcm->isr_tasklet);
4083 + bcm43xx_unlock_mmio(bcm, flags);
4084 + if (oldstate)
4085 + *oldstate = old;
4086 +
4087 + return 0;
4088 +}
4089 +
4090 +static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
4091 +{
4092 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4093 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4094 + u32 radio_id;
4095 + u16 manufact;
4096 + u16 version;
4097 + u8 revision;
4098 + s8 i;
4099 +
4100 + if (bcm->chip_id == 0x4317) {
4101 + if (bcm->chip_rev == 0x00)
4102 + radio_id = 0x3205017F;
4103 + else if (bcm->chip_rev == 0x01)
4104 + radio_id = 0x4205017F;
4105 + else
4106 + radio_id = 0x5205017F;
4107 + } else {
4108 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4109 + radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
4110 + radio_id <<= 16;
4111 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4112 + radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
4113 + }
4114 +
4115 + manufact = (radio_id & 0x00000FFF);
4116 + version = (radio_id & 0x0FFFF000) >> 12;
4117 + revision = (radio_id & 0xF0000000) >> 28;
4118 +
4119 + dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
4120 + radio_id, manufact, version, revision);
4121 +
4122 + switch (phy->type) {
4123 + case BCM43xx_PHYTYPE_A:
4124 + if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
4125 + goto err_unsupported_radio;
4126 + break;
4127 + case BCM43xx_PHYTYPE_B:
4128 + if ((version & 0xFFF0) != 0x2050)
4129 + goto err_unsupported_radio;
4130 + break;
4131 + case BCM43xx_PHYTYPE_G:
4132 + if (version != 0x2050)
4133 + goto err_unsupported_radio;
4134 + break;
4135 + }
4136 +
4137 + radio->manufact = manufact;
4138 + radio->version = version;
4139 + radio->revision = revision;
4140 +
4141 + /* Set default attenuation values. */
4142 + radio->baseband_atten = bcm43xx_default_baseband_attenuation(bcm);
4143 + radio->radio_atten = bcm43xx_default_radio_attenuation(bcm);
4144 + radio->txctl1 = bcm43xx_default_txctl1(bcm);
4145 + radio->txctl2 = 0xFFFF;
4146 + radio->power_level = ~0;
4147 +
4148 + /* Initialize the in-memory nrssi Lookup Table. */
4149 + for (i = 0; i < 64; i++)
4150 + radio->nrssi_lt[i] = i;
4151 +
4152 + return 0;
4153 +
4154 +err_unsupported_radio:
4155 + printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
4156 + return -ENODEV;
4157 +}
4158 +
4159 +static inline u8 bcm43xx_crc8(u8 crc, u8 data)
4160 +{
4161 + static const u8 t[] = {
4162 + 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
4163 + 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
4164 + 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
4165 + 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
4166 + 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
4167 + 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
4168 + 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
4169 + 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
4170 + 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
4171 + 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
4172 + 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
4173 + 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
4174 + 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
4175 + 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
4176 + 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
4177 + 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
4178 + 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
4179 + 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
4180 + 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
4181 + 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
4182 + 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
4183 + 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
4184 + 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
4185 + 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
4186 + 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
4187 + 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
4188 + 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
4189 + 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
4190 + 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
4191 + 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
4192 + 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
4193 + 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
4194 + };
4195 + return t[crc ^ data];
4196 +}
4197 +
4198 +static u8 bcm43xx_sprom_crc(const u16 *sprom)
4199 +{
4200 + int word;
4201 + u8 crc = 0xFF;
4202 +
4203 + for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
4204 + crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
4205 + crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
4206 + }
4207 + crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
4208 + crc ^= 0xFF;
4209 +
4210 + return crc;
4211 +}
4212 +
4213 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
4214 +{
4215 + int i;
4216 + u8 crc, expected_crc;
4217 +
4218 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
4219 + sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
4220 + /* CRC-8 check. */
4221 + crc = bcm43xx_sprom_crc(sprom);
4222 + expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
4223 + if (crc != expected_crc) {
4224 + printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
4225 + "(0x%02X, expected: 0x%02X)\n",
4226 + crc, expected_crc);
4227 + return -EINVAL;
4228 + }
4229 +
4230 + return 0;
4231 +}
4232 +
4233 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
4234 +{
4235 + int i, err;
4236 + u8 crc, expected_crc;
4237 + u32 spromctl;
4238 +
4239 + /* CRC-8 validation of the input data. */
4240 + crc = bcm43xx_sprom_crc(sprom);
4241 + expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
4242 + if (crc != expected_crc) {
4243 + printk(KERN_ERR PFX "SPROM input data: Invalid CRC\n");
4244 + return -EINVAL;
4245 + }
4246 +
4247 + printk(KERN_INFO PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
4248 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_SPROMCTL, &spromctl);
4249 + if (err)
4250 + goto err_ctlreg;
4251 + spromctl |= 0x10; /* SPROM WRITE enable. */
4252 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4253 + if (err)
4254 + goto err_ctlreg;
4255 + /* We must burn lots of CPU cycles here, but that does not
4256 + * really matter as one does not write the SPROM every other minute...
4257 + */
4258 + printk(KERN_INFO PFX "[ 0%%");
4259 + mdelay(500);
4260 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
4261 + if (i == 16)
4262 + printk("25%%");
4263 + else if (i == 32)
4264 + printk("50%%");
4265 + else if (i == 48)
4266 + printk("75%%");
4267 + else if (i % 2)
4268 + printk(".");
4269 + bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
4270 + mmiowb();
4271 + mdelay(20);
4272 + }
4273 + spromctl &= ~0x10; /* SPROM WRITE enable. */
4274 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4275 + if (err)
4276 + goto err_ctlreg;
4277 + mdelay(500);
4278 + printk("100%% ]\n");
4279 + printk(KERN_INFO PFX "SPROM written.\n");
4280 + bcm43xx_controller_restart(bcm, "SPROM update");
4281 +
4282 + return 0;
4283 +err_ctlreg:
4284 + printk(KERN_ERR PFX "Could not access SPROM control register.\n");
4285 + return -ENODEV;
4286 +}
4287 +
4288 +static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
4289 +{
4290 + u16 value;
4291 + u16 *sprom;
4292 +#ifdef CONFIG_BCM947XX
4293 + char *c;
4294 +#endif
4295 +
4296 + sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
4297 + GFP_KERNEL);
4298 + if (!sprom) {
4299 + printk(KERN_ERR PFX "sprom_extract OOM\n");
4300 + return -ENOMEM;
4301 + }
4302 +#ifdef CONFIG_BCM947XX
4303 + sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
4304 + sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
4305 +
4306 + if ((c = nvram_get("il0macaddr")) != NULL)
4307 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
4308 +
4309 + if ((c = nvram_get("et1macaddr")) != NULL)
4310 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
4311 +
4312 + sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
4313 + sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
4314 + sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
4315 +
4316 + sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
4317 + sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
4318 + sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
4319 +
4320 + sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
4321 +#else
4322 + bcm43xx_sprom_read(bcm, sprom);
4323 +#endif
4324 +
4325 + /* boardflags2 */
4326 + value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
4327 + bcm->sprom.boardflags2 = value;
4328 +
4329 + /* il0macaddr */
4330 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
4331 + *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
4332 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
4333 + *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
4334 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
4335 + *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
4336 +
4337 + /* et0macaddr */
4338 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
4339 + *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
4340 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
4341 + *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
4342 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
4343 + *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
4344 +
4345 + /* et1macaddr */
4346 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
4347 + *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
4348 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
4349 + *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
4350 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
4351 + *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
4352 +
4353 + /* ethernet phy settings */
4354 + value = sprom[BCM43xx_SPROM_ETHPHY];
4355 + bcm->sprom.et0phyaddr = (value & 0x001F);
4356 + bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
4357 + bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
4358 + bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
4359 +
4360 + /* boardrev, antennas, locale */
4361 + value = sprom[BCM43xx_SPROM_BOARDREV];
4362 + bcm->sprom.boardrev = (value & 0x00FF);
4363 + bcm->sprom.locale = (value & 0x0F00) >> 8;
4364 + bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
4365 + bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
4366 +
4367 + /* pa0b* */
4368 + value = sprom[BCM43xx_SPROM_PA0B0];
4369 + bcm->sprom.pa0b0 = value;
4370 + value = sprom[BCM43xx_SPROM_PA0B1];
4371 + bcm->sprom.pa0b1 = value;
4372 + value = sprom[BCM43xx_SPROM_PA0B2];
4373 + bcm->sprom.pa0b2 = value;
4374 +
4375 + /* wl0gpio* */
4376 + value = sprom[BCM43xx_SPROM_WL0GPIO0];
4377 + if (value == 0x0000)
4378 + value = 0xFFFF;
4379 + bcm->sprom.wl0gpio0 = value & 0x00FF;
4380 + bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
4381 + value = sprom[BCM43xx_SPROM_WL0GPIO2];
4382 + if (value == 0x0000)
4383 + value = 0xFFFF;
4384 + bcm->sprom.wl0gpio2 = value & 0x00FF;
4385 + bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
4386 +
4387 + /* maxpower */
4388 + value = sprom[BCM43xx_SPROM_MAXPWR];
4389 + bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
4390 + bcm->sprom.maxpower_bgphy = value & 0x00FF;
4391 +
4392 + /* pa1b* */
4393 + value = sprom[BCM43xx_SPROM_PA1B0];
4394 + bcm->sprom.pa1b0 = value;
4395 + value = sprom[BCM43xx_SPROM_PA1B1];
4396 + bcm->sprom.pa1b1 = value;
4397 + value = sprom[BCM43xx_SPROM_PA1B2];
4398 + bcm->sprom.pa1b2 = value;
4399 +
4400 + /* idle tssi target */
4401 + value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
4402 + bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
4403 + bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
4404 +
4405 + /* boardflags */
4406 + value = sprom[BCM43xx_SPROM_BOARDFLAGS];
4407 + if (value == 0xFFFF)
4408 + value = 0x0000;
4409 + bcm->sprom.boardflags = value;
4410 + /* boardflags workarounds */
4411 + if (bcm->board_vendor == PCI_VENDOR_ID_DELL &&
4412 + bcm->chip_id == 0x4301 &&
4413 + bcm->board_revision == 0x74)
4414 + bcm->sprom.boardflags |= BCM43xx_BFL_BTCOEXIST;
4415 + if (bcm->board_vendor == PCI_VENDOR_ID_APPLE &&
4416 + bcm->board_type == 0x4E &&
4417 + bcm->board_revision > 0x40)
4418 + bcm->sprom.boardflags |= BCM43xx_BFL_PACTRL;
4419 +
4420 + /* antenna gain */
4421 + value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
4422 + if (value == 0x0000 || value == 0xFFFF)
4423 + value = 0x0202;
4424 + /* convert values to Q5.2 */
4425 + bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
4426 + bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
4427 +
4428 + kfree(sprom);
4429 +
4430 + return 0;
4431 +}
4432 +
4433 +/* DummyTransmission function, as documented on
4434 + * http://bcm-specs.sipsolutions.net/DummyTransmission
4435 + */
4436 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
4437 +{
4438 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4439 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4440 + unsigned int i, max_loop;
4441 + u16 value = 0;
4442 + u32 buffer[5] = {
4443 + 0x00000000,
4444 + 0x0000D400,
4445 + 0x00000000,
4446 + 0x00000001,
4447 + 0x00000000,
4448 + };
4449 +
4450 + switch (phy->type) {
4451 + case BCM43xx_PHYTYPE_A:
4452 + max_loop = 0x1E;
4453 + buffer[0] = 0xCC010200;
4454 + break;
4455 + case BCM43xx_PHYTYPE_B:
4456 + case BCM43xx_PHYTYPE_G:
4457 + max_loop = 0xFA;
4458 + buffer[0] = 0x6E840B00;
4459 + break;
4460 + default:
4461 + assert(0);
4462 + return;
4463 + }
4464 +
4465 + for (i = 0; i < 5; i++)
4466 + bcm43xx_ram_write(bcm, i * 4, buffer[i]);
4467 +
4468 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
4469 +
4470 + bcm43xx_write16(bcm, 0x0568, 0x0000);
4471 + bcm43xx_write16(bcm, 0x07C0, 0x0000);
4472 + bcm43xx_write16(bcm, 0x050C, ((phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
4473 + bcm43xx_write16(bcm, 0x0508, 0x0000);
4474 + bcm43xx_write16(bcm, 0x050A, 0x0000);
4475 + bcm43xx_write16(bcm, 0x054C, 0x0000);
4476 + bcm43xx_write16(bcm, 0x056A, 0x0014);
4477 + bcm43xx_write16(bcm, 0x0568, 0x0826);
4478 + bcm43xx_write16(bcm, 0x0500, 0x0000);
4479 + bcm43xx_write16(bcm, 0x0502, 0x0030);
4480 +
4481 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4482 + bcm43xx_radio_write16(bcm, 0x0051, 0x0017);
4483 + for (i = 0x00; i < max_loop; i++) {
4484 + value = bcm43xx_read16(bcm, 0x050E);
4485 + if (value & 0x0080)
4486 + break;
4487 + udelay(10);
4488 + }
4489 + for (i = 0x00; i < 0x0A; i++) {
4490 + value = bcm43xx_read16(bcm, 0x050E);
4491 + if (value & 0x0400)
4492 + break;
4493 + udelay(10);
4494 + }
4495 + for (i = 0x00; i < 0x0A; i++) {
4496 + value = bcm43xx_read16(bcm, 0x0690);
4497 + if (!(value & 0x0100))
4498 + break;
4499 + udelay(10);
4500 + }
4501 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4502 + bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
4503 +}
4504 +
4505 +static void key_write(struct bcm43xx_private *bcm,
4506 + u8 index, u8 algorithm, const u16 *key)
4507 +{
4508 + unsigned int i, basic_wep = 0;
4509 + u32 offset;
4510 + u16 value;
4511 +
4512 + /* Write associated key information */
4513 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
4514 + ((index << 4) | (algorithm & 0x0F)));
4515 +
4516 + /* The first 4 WEP keys need extra love */
4517 + if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
4518 + (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
4519 + basic_wep = 1;
4520 +
4521 + /* Write key payload, 8 little endian words */
4522 + offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
4523 + for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
4524 + value = cpu_to_le16(key[i]);
4525 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4526 + offset + (i * 2), value);
4527 +
4528 + if (!basic_wep)
4529 + continue;
4530 +
4531 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4532 + offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
4533 + value);
4534 + }
4535 +}
4536 +
4537 +static void keymac_write(struct bcm43xx_private *bcm,
4538 + u8 index, const u32 *addr)
4539 +{
4540 + /* for keys 0-3 there is no associated mac address */
4541 + if (index < 4)
4542 + return;
4543 +
4544 + index -= 4;
4545 + if (bcm->current_core->rev >= 5) {
4546 + bcm43xx_shm_write32(bcm,
4547 + BCM43xx_SHM_HWMAC,
4548 + index * 2,
4549 + cpu_to_be32(*addr));
4550 + bcm43xx_shm_write16(bcm,
4551 + BCM43xx_SHM_HWMAC,
4552 + (index * 2) + 1,
4553 + cpu_to_be16(*((u16 *)(addr + 1))));
4554 + } else {
4555 + if (index < 8) {
4556 + TODO(); /* Put them in the macaddress filter */
4557 + } else {
4558 + TODO();
4559 + /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
4560 + Keep in mind to update the count of keymacs in 0x003E as well! */
4561 + }
4562 + }
4563 +}
4564 +
4565 +static int bcm43xx_key_write(struct bcm43xx_private *bcm,
4566 + u8 index, u8 algorithm,
4567 + const u8 *_key, int key_len,
4568 + const u8 *mac_addr)
4569 +{
4570 + u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
4571 +
4572 + if (index >= ARRAY_SIZE(bcm->key))
4573 + return -EINVAL;
4574 + if (key_len > ARRAY_SIZE(key))
4575 + return -EINVAL;
4576 + if (algorithm < 1 || algorithm > 5)
4577 + return -EINVAL;
4578 +
4579 + memcpy(key, _key, key_len);
4580 + key_write(bcm, index, algorithm, (const u16 *)key);
4581 + keymac_write(bcm, index, (const u32 *)mac_addr);
4582 +
4583 + bcm->key[index].algorithm = algorithm;
4584 +
4585 + return 0;
4586 +}
4587 +
4588 +static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
4589 +{
4590 + static const u32 zero_mac[2] = { 0 };
4591 + unsigned int i,j, nr_keys = 54;
4592 + u16 offset;
4593 +
4594 + if (bcm->current_core->rev < 5)
4595 + nr_keys = 16;
4596 + assert(nr_keys <= ARRAY_SIZE(bcm->key));
4597 +
4598 + for (i = 0; i < nr_keys; i++) {
4599 + bcm->key[i].enabled = 0;
4600 + /* returns for i < 4 immediately */
4601 + keymac_write(bcm, i, zero_mac);
4602 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4603 + 0x100 + (i * 2), 0x0000);
4604 + for (j = 0; j < 8; j++) {
4605 + offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
4606 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4607 + offset, 0x0000);
4608 + }
4609 + }
4610 + dprintk(KERN_INFO PFX "Keys cleared\n");
4611 +}
4612 +
4613 +/* Lowlevel core-switch function. This is only to be used in
4614 + * bcm43xx_switch_core() and bcm43xx_probe_cores()
4615 + */
4616 +static int _switch_core(struct bcm43xx_private *bcm, int core)
4617 +{
4618 + int err;
4619 + int attempts = 0;
4620 + u32 current_core;
4621 +
4622 + assert(core >= 0);
4623 + while (1) {
4624 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4625 + (core * 0x1000) + 0x18000000);
4626 + if (unlikely(err))
4627 + goto error;
4628 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4629 + &current_core);
4630 + if (unlikely(err))
4631 + goto error;
4632 + current_core = (current_core - 0x18000000) / 0x1000;
4633 + if (current_core == core)
4634 + break;
4635 +
4636 + if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
4637 + goto error;
4638 + udelay(10);
4639 + }
4640 +#ifdef CONFIG_BCM947XX
4641 + if (bcm->pci_dev->bus->number == 0)
4642 + bcm->current_core_offset = 0x1000 * core;
4643 + else
4644 + bcm->current_core_offset = 0;
4645 +#endif
4646 +
4647 + return 0;
4648 +error:
4649 + printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
4650 + return -ENODEV;
4651 +}
4652 +
4653 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
4654 +{
4655 + int err;
4656 +
4657 + if (unlikely(!new_core))
4658 + return 0;
4659 + if (!new_core->available)
4660 + return -ENODEV;
4661 + if (bcm->current_core == new_core)
4662 + return 0;
4663 + err = _switch_core(bcm, new_core->index);
4664 + if (unlikely(err))
4665 + goto out;
4666 +
4667 + bcm->current_core = new_core;
4668 + bcm->current_80211_core_idx = -1;
4669 + if (new_core->id == BCM43xx_COREID_80211)
4670 + bcm->current_80211_core_idx = (int)(new_core - &(bcm->core_80211[0]));
4671 +
4672 +out:
4673 + return err;
4674 +}
4675 +
4676 +static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
4677 +{
4678 + u32 value;
4679 +
4680 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4681 + value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
4682 + | BCM43xx_SBTMSTATELOW_REJECT;
4683 +
4684 + return (value == BCM43xx_SBTMSTATELOW_CLOCK);
4685 +}
4686 +
4687 +/* disable current core */
4688 +static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
4689 +{
4690 + u32 sbtmstatelow;
4691 + u32 sbtmstatehigh;
4692 + int i;
4693 +
4694 + /* fetch sbtmstatelow from core information registers */
4695 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4696 +
4697 + /* core is already in reset */
4698 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
4699 + goto out;
4700 +
4701 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
4702 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4703 + BCM43xx_SBTMSTATELOW_REJECT;
4704 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4705 +
4706 + for (i = 0; i < 1000; i++) {
4707 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4708 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
4709 + i = -1;
4710 + break;
4711 + }
4712 + udelay(10);
4713 + }
4714 + if (i != -1) {
4715 + printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
4716 + return -EBUSY;
4717 + }
4718 +
4719 + for (i = 0; i < 1000; i++) {
4720 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4721 + if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
4722 + i = -1;
4723 + break;
4724 + }
4725 + udelay(10);
4726 + }
4727 + if (i != -1) {
4728 + printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
4729 + return -EBUSY;
4730 + }
4731 +
4732 + sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4733 + BCM43xx_SBTMSTATELOW_REJECT |
4734 + BCM43xx_SBTMSTATELOW_RESET |
4735 + BCM43xx_SBTMSTATELOW_CLOCK |
4736 + core_flags;
4737 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4738 + udelay(10);
4739 + }
4740 +
4741 + sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
4742 + BCM43xx_SBTMSTATELOW_REJECT |
4743 + core_flags;
4744 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4745 +
4746 +out:
4747 + bcm->current_core->enabled = 0;
4748 +
4749 + return 0;
4750 +}
4751 +
4752 +/* enable (reset) current core */
4753 +static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
4754 +{
4755 + u32 sbtmstatelow;
4756 + u32 sbtmstatehigh;
4757 + u32 sbimstate;
4758 + int err;
4759 +
4760 + err = bcm43xx_core_disable(bcm, core_flags);
4761 + if (err)
4762 + goto out;
4763 +
4764 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4765 + BCM43xx_SBTMSTATELOW_RESET |
4766 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4767 + core_flags;
4768 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4769 + udelay(1);
4770 +
4771 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4772 + if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
4773 + sbtmstatehigh = 0x00000000;
4774 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
4775 + }
4776 +
4777 + sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
4778 + if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
4779 + sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
4780 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
4781 + }
4782 +
4783 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4784 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4785 + core_flags;
4786 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4787 + udelay(1);
4788 +
4789 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
4790 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4791 + udelay(1);
4792 +
4793 + bcm->current_core->enabled = 1;
4794 + assert(err == 0);
4795 +out:
4796 + return err;
4797 +}
4798 +
4799 +/* http://bcm-specs.sipsolutions.net/80211CoreReset */
4800 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
4801 +{
4802 + u32 flags = 0x00040000;
4803 +
4804 + if ((bcm43xx_core_enabled(bcm)) &&
4805 + !bcm43xx_using_pio(bcm)) {
4806 +//FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
4807 +#ifndef CONFIG_BCM947XX
4808 + /* reset all used DMA controllers. */
4809 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
4810 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
4811 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
4812 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
4813 + bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
4814 + if (bcm->current_core->rev < 5)
4815 + bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
4816 +#endif
4817 + }
4818 + if (bcm->shutting_down) {
4819 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
4820 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
4821 + & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
4822 + } else {
4823 + if (connect_phy)
4824 + flags |= 0x20000000;
4825 + bcm43xx_phy_connect(bcm, connect_phy);
4826 + bcm43xx_core_enable(bcm, flags);
4827 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
4828 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
4829 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
4830 + | BCM43xx_SBF_400);
4831 + }
4832 +}
4833 +
4834 +static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
4835 +{
4836 + bcm43xx_radio_turn_off(bcm);
4837 + bcm43xx_write16(bcm, 0x03E6, 0x00F4);
4838 + bcm43xx_core_disable(bcm, 0);
4839 +}
4840 +
4841 +/* Mark the current 80211 core inactive.
4842 + * "active_80211_core" is the other 80211 core, which is used.
4843 + */
4844 +static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
4845 + struct bcm43xx_coreinfo *active_80211_core)
4846 +{
4847 + u32 sbtmstatelow;
4848 + struct bcm43xx_coreinfo *old_core;
4849 + int err = 0;
4850 +
4851 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4852 + bcm43xx_radio_turn_off(bcm);
4853 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4854 + sbtmstatelow &= ~0x200a0000;
4855 + sbtmstatelow |= 0xa0000;
4856 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4857 + udelay(1);
4858 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4859 + sbtmstatelow &= ~0xa0000;
4860 + sbtmstatelow |= 0x80000;
4861 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4862 + udelay(1);
4863 +
4864 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
4865 + old_core = bcm->current_core;
4866 + err = bcm43xx_switch_core(bcm, active_80211_core);
4867 + if (err)
4868 + goto out;
4869 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4870 + sbtmstatelow &= ~0x20000000;
4871 + sbtmstatelow |= 0x20000000;
4872 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4873 + err = bcm43xx_switch_core(bcm, old_core);
4874 + }
4875 +
4876 +out:
4877 + return err;
4878 +}
4879 +
4880 +static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
4881 +{
4882 + u32 v0, v1;
4883 + u16 tmp;
4884 + struct bcm43xx_xmitstatus stat;
4885 +
4886 + while (1) {
4887 + v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
4888 + if (!v0)
4889 + break;
4890 + v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
4891 +
4892 + stat.cookie = (v0 >> 16) & 0x0000FFFF;
4893 + tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
4894 + stat.flags = tmp & 0xFF;
4895 + stat.cnt1 = (tmp & 0x0F00) >> 8;
4896 + stat.cnt2 = (tmp & 0xF000) >> 12;
4897 + stat.seq = (u16)(v1 & 0xFFFF);
4898 + stat.unknown = (u16)((v1 >> 16) & 0xFF);
4899 +
4900 + bcm43xx_debugfs_log_txstat(bcm, &stat);
4901 +
4902 + if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
4903 + continue;
4904 + if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK))
4905 + bcm->ieee_stats.dot11ACKFailureCount++;
4906 + //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
4907 +
4908 + if (bcm43xx_using_pio(bcm))
4909 + bcm43xx_pio_handle_xmitstatus(bcm, &stat);
4910 + else
4911 + bcm43xx_dma_handle_xmitstatus(bcm, &stat);
4912 + }
4913 +}
4914 +
4915 +static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
4916 +{
4917 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
4918 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
4919 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
4920 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
4921 + assert(bcm->noisecalc.core_at_start == bcm->current_core);
4922 + assert(bcm->noisecalc.channel_at_start == bcm43xx_current_radio(bcm)->channel);
4923 +}
4924 +
4925 +static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
4926 +{
4927 + /* Top half of Link Quality calculation. */
4928 +
4929 + if (bcm->noisecalc.calculation_running)
4930 + return;
4931 + bcm->noisecalc.core_at_start = bcm->current_core;
4932 + bcm->noisecalc.channel_at_start = bcm43xx_current_radio(bcm)->channel;
4933 + bcm->noisecalc.calculation_running = 1;
4934 + bcm->noisecalc.nr_samples = 0;
4935 +
4936 + bcm43xx_generate_noise_sample(bcm);
4937 +}
4938 +
4939 +static void handle_irq_noise(struct bcm43xx_private *bcm)
4940 +{
4941 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4942 + u16 tmp;
4943 + u8 noise[4];
4944 + u8 i, j;
4945 + s32 average;
4946 +
4947 + /* Bottom half of Link Quality calculation. */
4948 +
4949 + assert(bcm->noisecalc.calculation_running);
4950 + if (bcm->noisecalc.core_at_start != bcm->current_core ||
4951 + bcm->noisecalc.channel_at_start != radio->channel)
4952 + goto drop_calculation;
4953 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
4954 + noise[0] = (tmp & 0x00FF);
4955 + noise[1] = (tmp & 0xFF00) >> 8;
4956 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
4957 + noise[2] = (tmp & 0x00FF);
4958 + noise[3] = (tmp & 0xFF00) >> 8;
4959 + if (noise[0] == 0x7F || noise[1] == 0x7F ||
4960 + noise[2] == 0x7F || noise[3] == 0x7F)
4961 + goto generate_new;
4962 +
4963 + /* Get the noise samples. */
4964 + assert(bcm->noisecalc.nr_samples <= 8);
4965 + i = bcm->noisecalc.nr_samples;
4966 + noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
4967 + noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
4968 + noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
4969 + noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
4970 + bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
4971 + bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
4972 + bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
4973 + bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
4974 + bcm->noisecalc.nr_samples++;
4975 + if (bcm->noisecalc.nr_samples == 8) {
4976 + /* Calculate the Link Quality by the noise samples. */
4977 + average = 0;
4978 + for (i = 0; i < 8; i++) {
4979 + for (j = 0; j < 4; j++)
4980 + average += bcm->noisecalc.samples[i][j];
4981 + }
4982 + average /= (8 * 4);
4983 + average *= 125;
4984 + average += 64;
4985 + average /= 128;
4986 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
4987 + tmp = (tmp / 128) & 0x1F;
4988 + if (tmp >= 8)
4989 + average += 2;
4990 + else
4991 + average -= 25;
4992 + if (tmp == 8)
4993 + average -= 72;
4994 + else
4995 + average -= 48;
4996 +
4997 + if (average > -65)
4998 + bcm->stats.link_quality = 0;
4999 + else if (average > -75)
5000 + bcm->stats.link_quality = 1;
5001 + else if (average > -85)
5002 + bcm->stats.link_quality = 2;
5003 + else
5004 + bcm->stats.link_quality = 3;
5005 +// dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
5006 +drop_calculation:
5007 + bcm->noisecalc.calculation_running = 0;
5008 + return;
5009 + }
5010 +generate_new:
5011 + bcm43xx_generate_noise_sample(bcm);
5012 +}
5013 +
5014 +static void handle_irq_ps(struct bcm43xx_private *bcm)
5015 +{
5016 + if (bcm->iw_mode == IW_MODE_MASTER) {
5017 + ///TODO: PS TBTT
5018 + } else {
5019 + if (1/*FIXME: the last PSpoll frame was sent successfully */)
5020 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5021 + }
5022 + if (bcm->iw_mode == IW_MODE_ADHOC)
5023 + bcm->reg124_set_0x4 = 1;
5024 + //FIXME else set to false?
5025 +}
5026 +
5027 +static void handle_irq_reg124(struct bcm43xx_private *bcm)
5028 +{
5029 + if (!bcm->reg124_set_0x4)
5030 + return;
5031 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
5032 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
5033 + | 0x4);
5034 + //FIXME: reset reg124_set_0x4 to false?
5035 +}
5036 +
5037 +static void handle_irq_pmq(struct bcm43xx_private *bcm)
5038 +{
5039 + u32 tmp;
5040 +
5041 + //TODO: AP mode.
5042 +
5043 + while (1) {
5044 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
5045 + if (!(tmp & 0x00000008))
5046 + break;
5047 + }
5048 + /* 16bit write is odd, but correct. */
5049 + bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
5050 +}
5051 +
5052 +static void bcm43xx_write_beacon_template(struct bcm43xx_private *bcm,
5053 + u16 ram_offset,
5054 + u16 shm_size_offset)
5055 +{
5056 + u32 tmp;
5057 + u16 i, size;
5058 + const u8 *data;
5059 +
5060 + data = (const u8 *)(bcm->cached_beacon->data);
5061 + size = min(bcm->cached_beacon->len, (unsigned int)17);
5062 +
5063 + for (i = 0; i < size; i += sizeof(u32)) {
5064 + tmp = (u32)((data + i)[0]);
5065 + tmp |= (u32)((data + i)[1]) << 8;
5066 + tmp |= (u32)((data + i)[2]) << 16;
5067 + tmp |= (u32)((data + i)[3]) << 24;
5068 + bcm43xx_ram_write(bcm, ram_offset + i, tmp);
5069 + }
5070 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
5071 +}
5072 +
5073 +static void handle_irq_beacon(struct bcm43xx_private *bcm)
5074 +{
5075 + u32 status;
5076 +
5077 + bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
5078 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
5079 +
5080 + if (!bcm->cached_beacon) {
5081 + struct ieee80211_tx_control control;
5082 +
5083 + /* No cached template available, yet.
5084 + * Request the 80211 subsystem to generate a new beacon
5085 + * frame and use it as template.
5086 + */
5087 + bcm->cached_beacon = ieee80211_beacon_get(bcm->net_dev, 0, &control);
5088 + if (unlikely(!bcm->cached_beacon)) {
5089 + dprintkl(KERN_WARNING PFX "Could not generate beacon template.\n");
5090 + goto ack;
5091 + }
5092 + }
5093 +
5094 + if ((status & 0x1) && (status & 0x2)) {
5095 +ack:
5096 + /* ACK beacon IRQ. */
5097 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
5098 + BCM43xx_IRQ_BEACON);
5099 + bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
5100 + if (likely(bcm->cached_beacon))
5101 + kfree_skb(bcm->cached_beacon);
5102 + bcm->cached_beacon = NULL;
5103 + return;
5104 + }
5105 + if (!(status & 0x1)) {
5106 + bcm43xx_write_beacon_template(bcm, 0x68, 0x18);
5107 + status |= 0x1;
5108 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5109 + }
5110 + if (!(status & 0x2)) {
5111 + bcm43xx_write_beacon_template(bcm, 0x468, 0x1A);
5112 + status |= 0x2;
5113 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5114 + }
5115 +}
5116 +
5117 +/* Interrupt handler bottom-half */
5118 +static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
5119 +{
5120 + u32 reason;
5121 + u32 dma_reason[4];
5122 + int activity = 0;
5123 + unsigned long flags;
5124 +
5125 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5126 + u32 _handled = 0x00000000;
5127 +# define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
5128 +#else
5129 +# define bcmirq_handled(irq) do { /* nothing */ } while (0)
5130 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
5131 +
5132 + bcm43xx_lock_mmio(bcm, flags);
5133 + reason = bcm->irq_reason;
5134 + dma_reason[0] = bcm->dma_reason[0];
5135 + dma_reason[1] = bcm->dma_reason[1];
5136 + dma_reason[2] = bcm->dma_reason[2];
5137 + dma_reason[3] = bcm->dma_reason[3];
5138 +
5139 + if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
5140 + /* TX error. We get this when Template Ram is written in wrong endianess
5141 + * in dummy_tx(). We also get this if something is wrong with the TX header
5142 + * on DMA or PIO queues.
5143 + * Maybe we get this in other error conditions, too.
5144 + */
5145 + printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
5146 + bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
5147 + }
5148 + if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_FATALMASK) |
5149 + (dma_reason[1] & BCM43xx_DMAIRQ_FATALMASK) |
5150 + (dma_reason[2] & BCM43xx_DMAIRQ_FATALMASK) |
5151 + (dma_reason[3] & BCM43xx_DMAIRQ_FATALMASK))) {
5152 + printkl(KERN_ERR PFX "FATAL ERROR: Fatal DMA error: "
5153 + "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
5154 + dma_reason[0], dma_reason[1],
5155 + dma_reason[2], dma_reason[3]);
5156 + bcm43xx_controller_restart(bcm, "DMA error");
5157 + bcm43xx_unlock_mmio(bcm, flags);
5158 + return;
5159 + }
5160 + if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
5161 + (dma_reason[1] & BCM43xx_DMAIRQ_NONFATALMASK) |
5162 + (dma_reason[2] & BCM43xx_DMAIRQ_NONFATALMASK) |
5163 + (dma_reason[3] & BCM43xx_DMAIRQ_NONFATALMASK))) {
5164 + printkl(KERN_ERR PFX "DMA error: "
5165 + "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
5166 + dma_reason[0], dma_reason[1],
5167 + dma_reason[2], dma_reason[3]);
5168 + }
5169 +
5170 + if (reason & BCM43xx_IRQ_PS) {
5171 + handle_irq_ps(bcm);
5172 + bcmirq_handled(BCM43xx_IRQ_PS);
5173 + }
5174 +
5175 + if (reason & BCM43xx_IRQ_REG124) {
5176 + handle_irq_reg124(bcm);
5177 + bcmirq_handled(BCM43xx_IRQ_REG124);
5178 + }
5179 +
5180 + if (reason & BCM43xx_IRQ_BEACON) {
5181 + if (bcm->iw_mode == IW_MODE_MASTER)
5182 + handle_irq_beacon(bcm);
5183 + bcmirq_handled(BCM43xx_IRQ_BEACON);
5184 + }
5185 +
5186 + if (reason & BCM43xx_IRQ_PMQ) {
5187 + handle_irq_pmq(bcm);
5188 + bcmirq_handled(BCM43xx_IRQ_PMQ);
5189 + }
5190 +
5191 + if (reason & BCM43xx_IRQ_SCAN) {
5192 + /*TODO*/
5193 + //bcmirq_handled(BCM43xx_IRQ_SCAN);
5194 + }
5195 +
5196 + if (reason & BCM43xx_IRQ_NOISE) {
5197 + handle_irq_noise(bcm);
5198 + bcmirq_handled(BCM43xx_IRQ_NOISE);
5199 + }
5200 +
5201 + /* Check the DMA reason registers for received data. */
5202 + assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
5203 + assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
5204 + if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
5205 + if (bcm43xx_using_pio(bcm))
5206 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue0);
5207 + else
5208 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
5209 + /* We intentionally don't set "activity" to 1, here. */
5210 + }
5211 + if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
5212 + if (bcm43xx_using_pio(bcm))
5213 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
5214 + else
5215 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
5216 + activity = 1;
5217 + }
5218 + bcmirq_handled(BCM43xx_IRQ_RX);
5219 +
5220 + if (reason & BCM43xx_IRQ_XMIT_STATUS) {
5221 + handle_irq_transmit_status(bcm);
5222 + activity = 1;
5223 + //TODO: In AP mode, this also causes sending of powersave responses.
5224 + bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
5225 + }
5226 +
5227 + /* IRQ_PIO_WORKAROUND is handled in the top-half. */
5228 + bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
5229 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5230 + if (unlikely(reason & ~_handled)) {
5231 + printkl(KERN_WARNING PFX
5232 + "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
5233 + "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
5234 + reason, (reason & ~_handled),
5235 + dma_reason[0], dma_reason[1],
5236 + dma_reason[2], dma_reason[3]);
5237 + }
5238 +#endif
5239 +#undef bcmirq_handled
5240 +
5241 + if (!modparam_noleds)
5242 + bcm43xx_leds_update(bcm, activity);
5243 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
5244 + bcm43xx_unlock_mmio(bcm, flags);
5245 +}
5246 +
5247 +static void pio_irq_workaround(struct bcm43xx_private *bcm,
5248 + u16 base, int queueidx)
5249 +{
5250 + u16 rxctl;
5251 +
5252 + rxctl = bcm43xx_read16(bcm, base + BCM43xx_PIO_RXCTL);
5253 + if (rxctl & BCM43xx_PIO_RXCTL_DATAAVAILABLE)
5254 + bcm->dma_reason[queueidx] |= BCM43xx_DMAIRQ_RX_DONE;
5255 + else
5256 + bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
5257 +}
5258 +
5259 +static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
5260 +{
5261 + if (bcm43xx_using_pio(bcm) &&
5262 + (bcm->current_core->rev < 3) &&
5263 + (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
5264 + /* Apply a PIO specific workaround to the dma_reasons */
5265 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO1_BASE, 0);
5266 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO2_BASE, 1);
5267 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO3_BASE, 2);
5268 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO4_BASE, 3);
5269 + }
5270 +
5271 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
5272 +
5273 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
5274 + bcm->dma_reason[0]);
5275 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
5276 + bcm->dma_reason[1]);
5277 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
5278 + bcm->dma_reason[2]);
5279 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
5280 + bcm->dma_reason[3]);
5281 +}
5282 +
5283 +/* Interrupt handler top-half */
5284 +static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
5285 +{
5286 + irqreturn_t ret = IRQ_HANDLED;
5287 + struct bcm43xx_private *bcm = dev_id;
5288 + u32 reason;
5289 +
5290 + if (!bcm)
5291 + return IRQ_NONE;
5292 +
5293 + spin_lock(&bcm->_lock);
5294 +
5295 + reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5296 + if (reason == 0xffffffff) {
5297 + /* irq not for us (shared irq) */
5298 + ret = IRQ_NONE;
5299 + goto out;
5300 + }
5301 + reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
5302 + if (!reason)
5303 + goto out;
5304 +
5305 + bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
5306 + & 0x0001dc00;
5307 + bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
5308 + & 0x0000dc00;
5309 + bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
5310 + & 0x0000dc00;
5311 + bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
5312 + & 0x0001dc00;
5313 +
5314 + bcm43xx_interrupt_ack(bcm, reason);
5315 +
5316 + /* Only accept IRQs, if we are initialized properly.
5317 + * This avoids an RX race while initializing.
5318 + * We should probably not enable IRQs before we are initialized
5319 + * completely, but some careful work is needed to fix this. I think it
5320 + * is best to stay with this cheap workaround for now... .
5321 + */
5322 + if (likely(bcm->initialized)) {
5323 + /* disable all IRQs. They are enabled again in the bottom half. */
5324 + bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
5325 + /* save the reason code and call our bottom half. */
5326 + bcm->irq_reason = reason;
5327 + tasklet_schedule(&bcm->isr_tasklet);
5328 + }
5329 +
5330 +out:
5331 + mmiowb();
5332 + spin_unlock(&bcm->_lock);
5333 +
5334 + return ret;
5335 +}
5336 +
5337 +static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
5338 +{
5339 + if (bcm->firmware_norelease && !force)
5340 + return; /* Suspending or controller reset. */
5341 + release_firmware(bcm->ucode);
5342 + bcm->ucode = NULL;
5343 + release_firmware(bcm->pcm);
5344 + bcm->pcm = NULL;
5345 + release_firmware(bcm->initvals0);
5346 + bcm->initvals0 = NULL;
5347 + release_firmware(bcm->initvals1);
5348 + bcm->initvals1 = NULL;
5349 +}
5350 +
5351 +static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
5352 +{
5353 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5354 + u8 rev = bcm->current_core->rev;
5355 + int err = 0;
5356 + int nr;
5357 + char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
5358 +
5359 + if (!bcm->ucode) {
5360 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
5361 + (rev >= 5 ? 5 : rev),
5362 + modparam_fwpostfix);
5363 + err = request_firmware(&bcm->ucode, buf, &bcm->pci_dev->dev);
5364 + if (err) {
5365 + printk(KERN_ERR PFX
5366 + "Error: Microcode \"%s\" not available or load failed.\n",
5367 + buf);
5368 + goto error;
5369 + }
5370 + }
5371 +
5372 + if (!bcm->pcm) {
5373 + snprintf(buf, ARRAY_SIZE(buf),
5374 + "bcm43xx_pcm%d%s.fw",
5375 + (rev < 5 ? 4 : 5),
5376 + modparam_fwpostfix);
5377 + err = request_firmware(&bcm->pcm, buf, &bcm->pci_dev->dev);
5378 + if (err) {
5379 + printk(KERN_ERR PFX
5380 + "Error: PCM \"%s\" not available or load failed.\n",
5381 + buf);
5382 + goto error;
5383 + }
5384 + }
5385 +
5386 + if (!bcm->initvals0) {
5387 + if (rev == 2 || rev == 4) {
5388 + switch (phy->type) {
5389 + case BCM43xx_PHYTYPE_A:
5390 + nr = 3;
5391 + break;
5392 + case BCM43xx_PHYTYPE_B:
5393 + case BCM43xx_PHYTYPE_G:
5394 + nr = 1;
5395 + break;
5396 + default:
5397 + goto err_noinitval;
5398 + }
5399 +
5400 + } else if (rev >= 5) {
5401 + switch (phy->type) {
5402 + case BCM43xx_PHYTYPE_A:
5403 + nr = 7;
5404 + break;
5405 + case BCM43xx_PHYTYPE_B:
5406 + case BCM43xx_PHYTYPE_G:
5407 + nr = 5;
5408 + break;
5409 + default:
5410 + goto err_noinitval;
5411 + }
5412 + } else
5413 + goto err_noinitval;
5414 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5415 + nr, modparam_fwpostfix);
5416 +
5417 + err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
5418 + if (err) {
5419 + printk(KERN_ERR PFX
5420 + "Error: InitVals \"%s\" not available or load failed.\n",
5421 + buf);
5422 + goto error;
5423 + }
5424 + if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
5425 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5426 + goto error;
5427 + }
5428 + }
5429 +
5430 + if (!bcm->initvals1) {
5431 + if (rev >= 5) {
5432 + u32 sbtmstatehigh;
5433 +
5434 + switch (phy->type) {
5435 + case BCM43xx_PHYTYPE_A:
5436 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
5437 + if (sbtmstatehigh & 0x00010000)
5438 + nr = 9;
5439 + else
5440 + nr = 10;
5441 + break;
5442 + case BCM43xx_PHYTYPE_B:
5443 + case BCM43xx_PHYTYPE_G:
5444 + nr = 6;
5445 + break;
5446 + default:
5447 + goto err_noinitval;
5448 + }
5449 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5450 + nr, modparam_fwpostfix);
5451 +
5452 + err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
5453 + if (err) {
5454 + printk(KERN_ERR PFX
5455 + "Error: InitVals \"%s\" not available or load failed.\n",
5456 + buf);
5457 + goto error;
5458 + }
5459 + if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
5460 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5461 + goto error;
5462 + }
5463 + }
5464 + }
5465 +
5466 +out:
5467 + return err;
5468 +error:
5469 + bcm43xx_release_firmware(bcm, 1);
5470 + goto out;
5471 +err_noinitval:
5472 + printk(KERN_ERR PFX "Error: No InitVals available!\n");
5473 + err = -ENOENT;
5474 + goto error;
5475 +}
5476 +
5477 +static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
5478 +{
5479 + const u32 *data;
5480 + unsigned int i, len;
5481 +
5482 + /* Upload Microcode. */
5483 + data = (u32 *)(bcm->ucode->data);
5484 + len = bcm->ucode->size / sizeof(u32);
5485 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
5486 + for (i = 0; i < len; i++) {
5487 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
5488 + be32_to_cpu(data[i]));
5489 + udelay(10);
5490 + }
5491 +
5492 + /* Upload PCM data. */
5493 + data = (u32 *)(bcm->pcm->data);
5494 + len = bcm->pcm->size / sizeof(u32);
5495 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
5496 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
5497 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
5498 + for (i = 0; i < len; i++) {
5499 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
5500 + be32_to_cpu(data[i]));
5501 + udelay(10);
5502 + }
5503 +}
5504 +
5505 +static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
5506 + const struct bcm43xx_initval *data,
5507 + const unsigned int len)
5508 +{
5509 + u16 offset, size;
5510 + u32 value;
5511 + unsigned int i;
5512 +
5513 + for (i = 0; i < len; i++) {
5514 + offset = be16_to_cpu(data[i].offset);
5515 + size = be16_to_cpu(data[i].size);
5516 + value = be32_to_cpu(data[i].value);
5517 +
5518 + if (unlikely(offset >= 0x1000))
5519 + goto err_format;
5520 + if (size == 2) {
5521 + if (unlikely(value & 0xFFFF0000))
5522 + goto err_format;
5523 + bcm43xx_write16(bcm, offset, (u16)value);
5524 + } else if (size == 4) {
5525 + bcm43xx_write32(bcm, offset, value);
5526 + } else
5527 + goto err_format;
5528 + }
5529 +
5530 + return 0;
5531 +
5532 +err_format:
5533 + printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
5534 + "Please fix your bcm43xx firmware files.\n");
5535 + return -EPROTO;
5536 +}
5537 +
5538 +static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
5539 +{
5540 + int err;
5541 +
5542 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
5543 + bcm->initvals0->size / sizeof(struct bcm43xx_initval));
5544 + if (err)
5545 + goto out;
5546 + if (bcm->initvals1) {
5547 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
5548 + bcm->initvals1->size / sizeof(struct bcm43xx_initval));
5549 + if (err)
5550 + goto out;
5551 + }
5552 +out:
5553 + return err;
5554 +}
5555 +
5556 +static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
5557 +{
5558 + int res;
5559 + unsigned int i;
5560 + u32 data;
5561 +
5562 + bcm->irq = bcm->pci_dev->irq;
5563 +#ifdef CONFIG_BCM947XX
5564 + if (bcm->pci_dev->bus->number == 0) {
5565 + struct pci_dev *d = NULL;
5566 + /* FIXME: we will probably need more device IDs here... */
5567 + d = pci_find_device(PCI_VENDOR_ID_BROADCOM, 0x4324, NULL);
5568 + if (d != NULL) {
5569 + bcm->irq = d->irq;
5570 + }
5571 + }
5572 +#endif
5573 + res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
5574 + SA_SHIRQ, KBUILD_MODNAME, bcm);
5575 + if (res) {
5576 + printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
5577 + return -ENODEV;
5578 + }
5579 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
5580 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
5581 + i = 0;
5582 + while (1) {
5583 + data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5584 + if (data == BCM43xx_IRQ_READY)
5585 + break;
5586 + i++;
5587 + if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
5588 + printk(KERN_ERR PFX "Card IRQ register not responding. "
5589 + "Giving up.\n");
5590 + free_irq(bcm->irq, bcm);
5591 + return -ENODEV;
5592 + }
5593 + udelay(10);
5594 + }
5595 + // dummy read
5596 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5597 +
5598 + return 0;
5599 +}
5600 +
5601 +/* Switch to the core used to write the GPIO register.
5602 + * This is either the ChipCommon, or the PCI core.
5603 + */
5604 +static int switch_to_gpio_core(struct bcm43xx_private *bcm)
5605 +{
5606 + int err;
5607 +
5608 + /* Where to find the GPIO register depends on the chipset.
5609 + * If it has a ChipCommon, its register at offset 0x6c is the GPIO
5610 + * control register. Otherwise the register at offset 0x6c in the
5611 + * PCI core is the GPIO control register.
5612 + */
5613 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
5614 + if (err == -ENODEV) {
5615 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
5616 + if (unlikely(err == -ENODEV)) {
5617 + printk(KERN_ERR PFX "gpio error: "
5618 + "Neither ChipCommon nor PCI core available!\n");
5619 + }
5620 + }
5621 +
5622 + return err;
5623 +}
5624 +
5625 +/* Initialize the GPIOs
5626 + * http://bcm-specs.sipsolutions.net/GPIO
5627 + */
5628 +static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
5629 +{
5630 + struct bcm43xx_coreinfo *old_core;
5631 + int err;
5632 + u32 mask, set;
5633 +
5634 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5635 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5636 + & 0xFFFF3FFF);
5637 +
5638 + bcm43xx_leds_switch_all(bcm, 0);
5639 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5640 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
5641 +
5642 + mask = 0x0000001F;
5643 + set = 0x0000000F;
5644 + if (bcm->chip_id == 0x4301) {
5645 + mask |= 0x0060;
5646 + set |= 0x0060;
5647 + }
5648 + if (0 /* FIXME: conditional unknown */) {
5649 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5650 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5651 + | 0x0100);
5652 + mask |= 0x0180;
5653 + set |= 0x0180;
5654 + }
5655 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
5656 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5657 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5658 + | 0x0200);
5659 + mask |= 0x0200;
5660 + set |= 0x0200;
5661 + }
5662 + if (bcm->current_core->rev >= 2)
5663 + mask |= 0x0010; /* FIXME: This is redundant. */
5664 +
5665 + old_core = bcm->current_core;
5666 + err = switch_to_gpio_core(bcm);
5667 + if (err)
5668 + goto out;
5669 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
5670 + (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
5671 + err = bcm43xx_switch_core(bcm, old_core);
5672 +out:
5673 + return err;
5674 +}
5675 +
5676 +/* Turn off all GPIO stuff. Call this on module unload, for example. */
5677 +static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
5678 +{
5679 + struct bcm43xx_coreinfo *old_core;
5680 + int err;
5681 +
5682 + old_core = bcm->current_core;
5683 + err = switch_to_gpio_core(bcm);
5684 + if (err)
5685 + return err;
5686 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
5687 + err = bcm43xx_switch_core(bcm, old_core);
5688 + assert(err == 0);
5689 +
5690 + return 0;
5691 +}
5692 +
5693 +/* http://bcm-specs.sipsolutions.net/EnableMac */
5694 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
5695 +{
5696 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5697 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5698 + | BCM43xx_SBF_MAC_ENABLED);
5699 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
5700 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
5701 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
5702 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5703 +}
5704 +
5705 +/* http://bcm-specs.sipsolutions.net/SuspendMAC */
5706 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
5707 +{
5708 + int i;
5709 + u32 tmp;
5710 +
5711 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
5712 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5713 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5714 + & ~BCM43xx_SBF_MAC_ENABLED);
5715 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
5716 + for (i = 100000; i; i--) {
5717 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5718 + if (tmp & BCM43xx_IRQ_READY)
5719 + return;
5720 + udelay(10);
5721 + }
5722 + printkl(KERN_ERR PFX "MAC suspend failed\n");
5723 +}
5724 +
5725 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
5726 + int iw_mode)
5727 +{
5728 + struct net_device *net_dev = bcm->net_dev;
5729 + u32 status;
5730 + u16 value;
5731 +
5732 + bcm->iw_mode = iw_mode;
5733 + if (iw_mode == IW_MODE_MONITOR)
5734 + net_dev->type = ARPHRD_IEEE80211;
5735 + else
5736 + net_dev->type = ARPHRD_ETHER;
5737 +
5738 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5739 + /* Reset status to infrastructured mode */
5740 + status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
5741 + status &= ~BCM43xx_SBF_MODE_PROMISC;
5742 + status |= BCM43xx_SBF_MODE_NOTADHOC;
5743 +
5744 +/* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
5745 +status |= BCM43xx_SBF_MODE_PROMISC;
5746 +
5747 + switch (iw_mode) {
5748 + case IW_MODE_MONITOR:
5749 + status |= BCM43xx_SBF_MODE_MONITOR;
5750 + status |= BCM43xx_SBF_MODE_PROMISC;
5751 + break;
5752 + case IW_MODE_ADHOC:
5753 + status &= ~BCM43xx_SBF_MODE_NOTADHOC;
5754 + break;
5755 + case IW_MODE_MASTER:
5756 + status |= BCM43xx_SBF_MODE_AP;
5757 + break;
5758 + case IW_MODE_SECOND:
5759 + case IW_MODE_REPEAT:
5760 + TODO(); /* TODO */
5761 + break;
5762 + case IW_MODE_INFRA:
5763 + /* nothing to be done here... */
5764 + break;
5765 + default:
5766 + dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
5767 + }
5768 + if (net_dev->flags & IFF_PROMISC)
5769 + status |= BCM43xx_SBF_MODE_PROMISC;
5770 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
5771 +
5772 + value = 0x0002;
5773 + if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
5774 + if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
5775 + value = 0x0064;
5776 + else
5777 + value = 0x0032;
5778 + }
5779 + bcm43xx_write16(bcm, 0x0612, value);
5780 +}
5781 +
5782 +/* This is the opposite of bcm43xx_chip_init() */
5783 +static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
5784 +{
5785 + bcm43xx_radio_turn_off(bcm);
5786 + if (!modparam_noleds)
5787 + bcm43xx_leds_exit(bcm);
5788 + bcm43xx_gpio_cleanup(bcm);
5789 + free_irq(bcm->irq, bcm);
5790 + bcm43xx_release_firmware(bcm, 0);
5791 +}
5792 +
5793 +/* Initialize the chip
5794 + * http://bcm-specs.sipsolutions.net/ChipInit
5795 + */
5796 +static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
5797 +{
5798 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5799 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5800 + int err;
5801 + int tmp;
5802 + u32 value32;
5803 + u16 value16;
5804 +
5805 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5806 + BCM43xx_SBF_CORE_READY
5807 + | BCM43xx_SBF_400);
5808 +
5809 + err = bcm43xx_request_firmware(bcm);
5810 + if (err)
5811 + goto out;
5812 + bcm43xx_upload_microcode(bcm);
5813 + err = bcm43xx_initialize_irq(bcm);
5814 + if (err)
5815 + goto err_release_fw;
5816 + err = bcm43xx_gpio_init(bcm);
5817 + if (err)
5818 + goto err_free_irq;
5819 + err = bcm43xx_upload_initvals(bcm);
5820 + if (err)
5821 + goto err_gpio_cleanup;
5822 + bcm43xx_radio_turn_on(bcm);
5823 +
5824 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
5825 + err = bcm43xx_phy_init(bcm);
5826 + if (err)
5827 + goto err_radio_off;
5828 +
5829 + /* Select initial Interference Mitigation. */
5830 + tmp = radio->interfmode;
5831 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
5832 + bcm43xx_radio_set_interference_mitigation(bcm, tmp);
5833 +
5834 + bcm43xx_phy_set_antenna_diversity(bcm);
5835 + bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
5836 + if (phy->type == BCM43xx_PHYTYPE_B) {
5837 + value16 = bcm43xx_read16(bcm, 0x005E);
5838 + value16 |= 0x0004;
5839 + bcm43xx_write16(bcm, 0x005E, value16);
5840 + }
5841 + bcm43xx_write32(bcm, 0x0100, 0x01000000);
5842 + if (bcm->current_core->rev < 5)
5843 + bcm43xx_write32(bcm, 0x010C, 0x01000000);
5844 +
5845 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5846 + value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
5847 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5848 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5849 + value32 |= BCM43xx_SBF_MODE_NOTADHOC;
5850 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5851 +
5852 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5853 + value32 |= 0x100000;
5854 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5855 +
5856 + if (bcm43xx_using_pio(bcm)) {
5857 + bcm43xx_write32(bcm, 0x0210, 0x00000100);
5858 + bcm43xx_write32(bcm, 0x0230, 0x00000100);
5859 + bcm43xx_write32(bcm, 0x0250, 0x00000100);
5860 + bcm43xx_write32(bcm, 0x0270, 0x00000100);
5861 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
5862 + }
5863 +
5864 + /* Probe Response Timeout value */
5865 + /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
5866 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
5867 +
5868 + /* Initially set the wireless operation mode. */
5869 + bcm43xx_set_iwmode(bcm, bcm->iw_mode);
5870 +
5871 + if (bcm->current_core->rev < 3) {
5872 + bcm43xx_write16(bcm, 0x060E, 0x0000);
5873 + bcm43xx_write16(bcm, 0x0610, 0x8000);
5874 + bcm43xx_write16(bcm, 0x0604, 0x0000);
5875 + bcm43xx_write16(bcm, 0x0606, 0x0200);
5876 + } else {
5877 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
5878 + bcm43xx_write32(bcm, 0x018C, 0x02000000);
5879 + }
5880 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
5881 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0001DC00);
5882 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
5883 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0000DC00);
5884 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0001DC00);
5885 +
5886 + value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
5887 + value32 |= 0x00100000;
5888 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
5889 +
5890 + bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
5891 +
5892 + assert(err == 0);
5893 + dprintk(KERN_INFO PFX "Chip initialized\n");
5894 +out:
5895 + return err;
5896 +
5897 +err_radio_off:
5898 + bcm43xx_radio_turn_off(bcm);
5899 +err_gpio_cleanup:
5900 + bcm43xx_gpio_cleanup(bcm);
5901 +err_free_irq:
5902 + free_irq(bcm->irq, bcm);
5903 +err_release_fw:
5904 + bcm43xx_release_firmware(bcm, 1);
5905 + goto out;
5906 +}
5907 +
5908 +/* Validate chip access
5909 + * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
5910 +static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
5911 +{
5912 + u32 value;
5913 + u32 shm_backup;
5914 +
5915 + shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
5916 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
5917 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA)
5918 + goto error;
5919 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
5920 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
5921 + goto error;
5922 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
5923 +
5924 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5925 + if ((value | 0x80000000) != 0x80000400)
5926 + goto error;
5927 +
5928 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5929 + if (value != 0x00000000)
5930 + goto error;
5931 +
5932 + return 0;
5933 +error:
5934 + printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
5935 + return -ENODEV;
5936 +}
5937 +
5938 +static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
5939 +{
5940 + /* Initialize a "phyinfo" structure. The structure is already
5941 + * zeroed out.
5942 + */
5943 + phy->antenna_diversity = 0xFFFF;
5944 + phy->savedpctlreg = 0xFFFF;
5945 + phy->minlowsig[0] = 0xFFFF;
5946 + phy->minlowsig[1] = 0xFFFF;
5947 + spin_lock_init(&phy->lock);
5948 +}
5949 +
5950 +static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
5951 +{
5952 + /* Initialize a "radioinfo" structure. The structure is already
5953 + * zeroed out.
5954 + */
5955 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
5956 + radio->channel = 0xFF;
5957 + radio->initial_channel = 0xFF;
5958 + radio->lofcal = 0xFFFF;
5959 + radio->initval = 0xFFFF;
5960 + radio->nrssi[0] = -1000;
5961 + radio->nrssi[1] = -1000;
5962 +}
5963 +
5964 +static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
5965 +{
5966 + int err, i;
5967 + int current_core;
5968 + u32 core_vendor, core_id, core_rev;
5969 + u32 sb_id_hi, chip_id_32 = 0;
5970 + u16 pci_device, chip_id_16;
5971 + u8 core_count;
5972 +
5973 + memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
5974 + memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
5975 + memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
5976 + * BCM43xx_MAX_80211_CORES);
5977 + memset(&bcm->core_80211_ext, 0, sizeof(struct bcm43xx_coreinfo_80211)
5978 + * BCM43xx_MAX_80211_CORES);
5979 + bcm->current_80211_core_idx = -1;
5980 + bcm->nr_80211_available = 0;
5981 + bcm->current_core = NULL;
5982 + bcm->active_80211_core = NULL;
5983 +
5984 + /* map core 0 */
5985 + err = _switch_core(bcm, 0);
5986 + if (err)
5987 + goto out;
5988 +
5989 + /* fetch sb_id_hi from core information registers */
5990 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
5991 +
5992 + core_id = (sb_id_hi & 0xFFF0) >> 4;
5993 + core_rev = (sb_id_hi & 0xF);
5994 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
5995 +
5996 + /* if present, chipcommon is always core 0; read the chipid from it */
5997 + if (core_id == BCM43xx_COREID_CHIPCOMMON) {
5998 + chip_id_32 = bcm43xx_read32(bcm, 0);
5999 + chip_id_16 = chip_id_32 & 0xFFFF;
6000 + bcm->core_chipcommon.available = 1;
6001 + bcm->core_chipcommon.id = core_id;
6002 + bcm->core_chipcommon.rev = core_rev;
6003 + bcm->core_chipcommon.index = 0;
6004 + /* While we are at it, also read the capabilities. */
6005 + bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
6006 + } else {
6007 + /* without a chipCommon, use a hard coded table. */
6008 + pci_device = bcm->pci_dev->device;
6009 + if (pci_device == 0x4301)
6010 + chip_id_16 = 0x4301;
6011 + else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
6012 + chip_id_16 = 0x4307;
6013 + else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
6014 + chip_id_16 = 0x4402;
6015 + else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
6016 + chip_id_16 = 0x4610;
6017 + else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
6018 + chip_id_16 = 0x4710;
6019 +#ifdef CONFIG_BCM947XX
6020 + else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
6021 + chip_id_16 = 0x4309;
6022 +#endif
6023 + else {
6024 + printk(KERN_ERR PFX "Could not determine Chip ID\n");
6025 + return -ENODEV;
6026 + }
6027 + }
6028 +
6029 + /* ChipCommon with Core Rev >=4 encodes number of cores,
6030 + * otherwise consult hardcoded table */
6031 + if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
6032 + core_count = (chip_id_32 & 0x0F000000) >> 24;
6033 + } else {
6034 + switch (chip_id_16) {
6035 + case 0x4610:
6036 + case 0x4704:
6037 + case 0x4710:
6038 + core_count = 9;
6039 + break;
6040 + case 0x4310:
6041 + core_count = 8;
6042 + break;
6043 + case 0x5365:
6044 + core_count = 7;
6045 + break;
6046 + case 0x4306:
6047 + core_count = 6;
6048 + break;
6049 + case 0x4301:
6050 + case 0x4307:
6051 + core_count = 5;
6052 + break;
6053 + case 0x4402:
6054 + core_count = 3;
6055 + break;
6056 + default:
6057 + /* SOL if we get here */
6058 + assert(0);
6059 + core_count = 1;
6060 + }
6061 + }
6062 +
6063 + bcm->chip_id = chip_id_16;
6064 + bcm->chip_rev = (chip_id_32 & 0x000F0000) >> 16;
6065 + bcm->chip_package = (chip_id_32 & 0x00F00000) >> 20;
6066 +
6067 + dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
6068 + bcm->chip_id, bcm->chip_rev);
6069 + dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
6070 + if (bcm->core_chipcommon.available) {
6071 + dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
6072 + core_id, core_rev, core_vendor,
6073 + bcm43xx_core_enabled(bcm) ? "enabled" : "disabled");
6074 + }
6075 +
6076 + if (bcm->core_chipcommon.available)
6077 + current_core = 1;
6078 + else
6079 + current_core = 0;
6080 + for ( ; current_core < core_count; current_core++) {
6081 + struct bcm43xx_coreinfo *core;
6082 + struct bcm43xx_coreinfo_80211 *ext_80211;
6083 +
6084 + err = _switch_core(bcm, current_core);
6085 + if (err)
6086 + goto out;
6087 + /* Gather information */
6088 + /* fetch sb_id_hi from core information registers */
6089 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
6090 +
6091 + /* extract core_id, core_rev, core_vendor */
6092 + core_id = (sb_id_hi & 0xFFF0) >> 4;
6093 + core_rev = (sb_id_hi & 0xF);
6094 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
6095 +
6096 + dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
6097 + current_core, core_id, core_rev, core_vendor,
6098 + bcm43xx_core_enabled(bcm) ? "enabled" : "disabled" );
6099 +
6100 + core = NULL;
6101 + switch (core_id) {
6102 + case BCM43xx_COREID_PCI:
6103 + core = &bcm->core_pci;
6104 + if (core->available) {
6105 + printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
6106 + continue;
6107 + }
6108 + break;
6109 + case BCM43xx_COREID_80211:
6110 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
6111 + core = &(bcm->core_80211[i]);
6112 + ext_80211 = &(bcm->core_80211_ext[i]);
6113 + if (!core->available)
6114 + break;
6115 + core = NULL;
6116 + }
6117 + if (!core) {
6118 + printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
6119 + BCM43xx_MAX_80211_CORES);
6120 + continue;
6121 + }
6122 + if (i != 0) {
6123 + /* More than one 80211 core is only supported
6124 + * by special chips.
6125 + * There are chips with two 80211 cores, but with
6126 + * dangling pins on the second core. Be careful
6127 + * and ignore these cores here.
6128 + */
6129 + if (bcm->pci_dev->device != 0x4324) {
6130 + dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
6131 + continue;
6132 + }
6133 + }
6134 + switch (core_rev) {
6135 + case 2:
6136 + case 4:
6137 + case 5:
6138 + case 6:
6139 + case 7:
6140 + case 9:
6141 + break;
6142 + default:
6143 + printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
6144 + core_rev);
6145 + err = -ENODEV;
6146 + goto out;
6147 + }
6148 + bcm->nr_80211_available++;
6149 + bcm43xx_init_struct_phyinfo(&ext_80211->phy);
6150 + bcm43xx_init_struct_radioinfo(&ext_80211->radio);
6151 + break;
6152 + case BCM43xx_COREID_CHIPCOMMON:
6153 + printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
6154 + break;
6155 + }
6156 + if (core) {
6157 + core->available = 1;
6158 + core->id = core_id;
6159 + core->rev = core_rev;
6160 + core->index = current_core;
6161 + }
6162 + }
6163 +
6164 + if (!bcm->core_80211[0].available) {
6165 + printk(KERN_ERR PFX "Error: No 80211 core found!\n");
6166 + err = -ENODEV;
6167 + goto out;
6168 + }
6169 +
6170 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
6171 +
6172 + assert(err == 0);
6173 +out:
6174 + return err;
6175 +}
6176 +
6177 +static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
6178 +{
6179 + const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
6180 + u8 *bssid = bcm->bssid;
6181 +
6182 + switch (bcm->iw_mode) {
6183 + case IW_MODE_ADHOC:
6184 + random_ether_addr(bssid);
6185 + break;
6186 + case IW_MODE_MASTER:
6187 + case IW_MODE_INFRA:
6188 + case IW_MODE_REPEAT:
6189 + case IW_MODE_SECOND:
6190 + case IW_MODE_MONITOR:
6191 + memcpy(bssid, mac, ETH_ALEN);
6192 + break;
6193 + default:
6194 + assert(0);
6195 + }
6196 +}
6197 +
6198 +static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
6199 + u16 rate,
6200 + int is_ofdm)
6201 +{
6202 + u16 offset;
6203 +
6204 + if (is_ofdm) {
6205 + offset = 0x480;
6206 + offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
6207 + } else {
6208 + offset = 0x4C0;
6209 + offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
6210 + }
6211 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
6212 + bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
6213 +}
6214 +
6215 +static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
6216 +{
6217 + switch (bcm43xx_current_phy(bcm)->type) {
6218 + case BCM43xx_PHYTYPE_A:
6219 + case BCM43xx_PHYTYPE_G:
6220 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_6MB, 1);
6221 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_12MB, 1);
6222 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_18MB, 1);
6223 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_24MB, 1);
6224 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_36MB, 1);
6225 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_48MB, 1);
6226 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_54MB, 1);
6227 + case BCM43xx_PHYTYPE_B:
6228 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_1MB, 0);
6229 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_2MB, 0);
6230 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_5MB, 0);
6231 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_11MB, 0);
6232 + break;
6233 + default:
6234 + assert(0);
6235 + }
6236 +}
6237 +
6238 +static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
6239 +{
6240 + bcm43xx_chip_cleanup(bcm);
6241 + bcm43xx_pio_free(bcm);
6242 + bcm43xx_dma_free(bcm);
6243 +
6244 + bcm->current_core->initialized = 0;
6245 +}
6246 +
6247 +/* http://bcm-specs.sipsolutions.net/80211Init */
6248 +static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
6249 +{
6250 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6251 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6252 + u32 ucodeflags;
6253 + int err;
6254 + u32 sbimconfiglow;
6255 + u8 limit;
6256 +
6257 + if (bcm->chip_rev < 5) {
6258 + sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
6259 + sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
6260 + sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
6261 + if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
6262 + sbimconfiglow |= 0x32;
6263 + else if (bcm->bustype == BCM43xx_BUSTYPE_SB)
6264 + sbimconfiglow |= 0x53;
6265 + else
6266 + assert(0);
6267 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
6268 + }
6269 +
6270 + bcm43xx_phy_calibrate(bcm);
6271 + err = bcm43xx_chip_init(bcm);
6272 + if (err)
6273 + goto out;
6274 +
6275 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
6276 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
6277 +
6278 + if (0 /*FIXME: which condition has to be used here? */)
6279 + ucodeflags |= 0x00000010;
6280 +
6281 + /* HW decryption needs to be set now. */
6282 + ucodeflags |= 0x40000000;
6283 +
6284 + if (phy->type == BCM43xx_PHYTYPE_G) {
6285 + ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
6286 + if (phy->rev == 1)
6287 + ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
6288 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
6289 + ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
6290 + } else if (phy->type == BCM43xx_PHYTYPE_B) {
6291 + ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
6292 + if (phy->rev >= 2 && radio->version == 0x2050)
6293 + ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
6294 + }
6295 +
6296 + if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
6297 + BCM43xx_UCODEFLAGS_OFFSET)) {
6298 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
6299 + BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
6300 + }
6301 +
6302 + /* Short/Long Retry Limit.
6303 + * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
6304 + * the chip-internal counter.
6305 + */
6306 + limit = limit_value(modparam_short_retry, 0, 0xF);
6307 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
6308 + limit = limit_value(modparam_long_retry, 0, 0xF);
6309 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
6310 +
6311 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
6312 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
6313 +
6314 + bcm43xx_rate_memory_init(bcm);
6315 +
6316 + /* Minimum Contention Window */
6317 + if (phy->type == BCM43xx_PHYTYPE_B)
6318 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
6319 + else
6320 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
6321 + /* Maximum Contention Window */
6322 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
6323 +
6324 + bcm43xx_gen_bssid(bcm);
6325 + bcm43xx_write_mac_bssid_templates(bcm);
6326 +
6327 + if (bcm->current_core->rev >= 5)
6328 + bcm43xx_write16(bcm, 0x043C, 0x000C);
6329 +
6330 + if (bcm43xx_using_pio(bcm))
6331 + err = bcm43xx_pio_init(bcm);
6332 + else
6333 + err = bcm43xx_dma_init(bcm);
6334 + if (err)
6335 + goto err_chip_cleanup;
6336 + bcm43xx_write16(bcm, 0x0612, 0x0050);
6337 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
6338 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
6339 +
6340 + bcm43xx_mac_enable(bcm);
6341 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
6342 +
6343 + bcm->current_core->initialized = 1;
6344 +out:
6345 + return err;
6346 +
6347 +err_chip_cleanup:
6348 + bcm43xx_chip_cleanup(bcm);
6349 + goto out;
6350 +}
6351 +
6352 +static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
6353 +{
6354 + int err;
6355 + u16 pci_status;
6356 +
6357 + err = bcm43xx_pctl_set_crystal(bcm, 1);
6358 + if (err)
6359 + goto out;
6360 + bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
6361 + bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
6362 +
6363 +out:
6364 + return err;
6365 +}
6366 +
6367 +static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
6368 +{
6369 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
6370 + bcm43xx_pctl_set_crystal(bcm, 0);
6371 +}
6372 +
6373 +static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
6374 + u32 address,
6375 + u32 data)
6376 +{
6377 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
6378 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
6379 +}
6380 +
6381 +static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
6382 +{
6383 + int err;
6384 + struct bcm43xx_coreinfo *old_core;
6385 +
6386 + old_core = bcm->current_core;
6387 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6388 + if (err)
6389 + goto out;
6390 +
6391 + bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
6392 +
6393 + bcm43xx_switch_core(bcm, old_core);
6394 + assert(err == 0);
6395 +out:
6396 + return err;
6397 +}
6398 +
6399 +/* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
6400 + * To enable core 0, pass a core_mask of 1<<0
6401 + */
6402 +static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
6403 + u32 core_mask)
6404 +{
6405 + u32 backplane_flag_nr;
6406 + u32 value;
6407 + struct bcm43xx_coreinfo *old_core;
6408 + int err = 0;
6409 +
6410 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
6411 + backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
6412 +
6413 + old_core = bcm->current_core;
6414 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6415 + if (err)
6416 + goto out;
6417 +
6418 + if (bcm->core_pci.rev < 6) {
6419 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
6420 + value |= (1 << backplane_flag_nr);
6421 + bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
6422 + } else {
6423 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
6424 + if (err) {
6425 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6426 + goto out_switch_back;
6427 + }
6428 + value |= core_mask << 8;
6429 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
6430 + if (err) {
6431 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6432 + goto out_switch_back;
6433 + }
6434 + }
6435 +
6436 + value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
6437 + value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
6438 + bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
6439 +
6440 + if (bcm->core_pci.rev < 5) {
6441 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
6442 + value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
6443 + & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
6444 + value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
6445 + & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
6446 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
6447 + err = bcm43xx_pcicore_commit_settings(bcm);
6448 + assert(err == 0);
6449 + }
6450 +
6451 +out_switch_back:
6452 + err = bcm43xx_switch_core(bcm, old_core);
6453 +out:
6454 + return err;
6455 +}
6456 +
6457 +static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
6458 +{
6459 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6460 +
6461 + if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
6462 + return;
6463 +
6464 + bcm43xx_mac_suspend(bcm);
6465 + bcm43xx_phy_lo_g_measure(bcm);
6466 + bcm43xx_mac_enable(bcm);
6467 +}
6468 +
6469 +static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
6470 +{
6471 + bcm43xx_phy_lo_mark_all_unused(bcm);
6472 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
6473 + bcm43xx_mac_suspend(bcm);
6474 + bcm43xx_calc_nrssi_slope(bcm);
6475 + bcm43xx_mac_enable(bcm);
6476 + }
6477 +}
6478 +
6479 +static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
6480 +{
6481 + /* Update device statistics. */
6482 + bcm43xx_calculate_link_quality(bcm);
6483 +}
6484 +
6485 +static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
6486 +{
6487 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6488 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6489 +
6490 + if (phy->type == BCM43xx_PHYTYPE_G) {
6491 + //TODO: update_aci_moving_average
6492 + if (radio->aci_enable && radio->aci_wlan_automatic) {
6493 + bcm43xx_mac_suspend(bcm);
6494 + if (!radio->aci_enable && 1 /*TODO: not scanning? */) {
6495 + if (0 /*TODO: bunch of conditions*/) {
6496 + bcm43xx_radio_set_interference_mitigation(bcm,
6497 + BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
6498 + }
6499 + } else if (1/*TODO*/) {
6500 + /*
6501 + if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
6502 + bcm43xx_radio_set_interference_mitigation(bcm,
6503 + BCM43xx_RADIO_INTERFMODE_NONE);
6504 + }
6505 + */
6506 + }
6507 + bcm43xx_mac_enable(bcm);
6508 + } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
6509 + phy->rev == 1) {
6510 + //TODO: implement rev1 workaround
6511 + }
6512 + }
6513 + bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
6514 + //TODO for APHY (temperature?)
6515 +}
6516 +
6517 +static void bcm43xx_periodic_task_handler(unsigned long d)
6518 +{
6519 + struct bcm43xx_private *bcm = (struct bcm43xx_private *)d;
6520 + unsigned long flags;
6521 + unsigned int state;
6522 +
6523 + bcm43xx_lock_mmio(bcm, flags);
6524 +
6525 + assert(bcm->initialized);
6526 + state = bcm->periodic_state;
6527 + if (state % 8 == 0)
6528 + bcm43xx_periodic_every120sec(bcm);
6529 + if (state % 4 == 0)
6530 + bcm43xx_periodic_every60sec(bcm);
6531 + if (state % 2 == 0)
6532 + bcm43xx_periodic_every30sec(bcm);
6533 + bcm43xx_periodic_every15sec(bcm);
6534 + bcm->periodic_state = state + 1;
6535 +
6536 + mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15));
6537 +
6538 + bcm43xx_unlock_mmio(bcm, flags);
6539 +}
6540 +
6541 +static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
6542 +{
6543 + del_timer_sync(&bcm->periodic_tasks);
6544 +}
6545 +
6546 +static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
6547 +{
6548 + struct timer_list *timer = &(bcm->periodic_tasks);
6549 +
6550 + assert(bcm->initialized);
6551 + setup_timer(timer,
6552 + bcm43xx_periodic_task_handler,
6553 + (unsigned long)bcm);
6554 + timer->expires = jiffies;
6555 + add_timer(timer);
6556 +}
6557 +
6558 +static void bcm43xx_free_modes(struct bcm43xx_private *bcm)
6559 +{
6560 + struct ieee80211_hw *ieee = bcm->ieee;
6561 + int i;
6562 +
6563 + for (i = 0; i < ieee->num_modes; i++) {
6564 + kfree(ieee->modes[i].channels);
6565 + kfree(ieee->modes[i].rates);
6566 + }
6567 + kfree(ieee->modes);
6568 + ieee->modes = NULL;
6569 + ieee->num_modes = 0;
6570 +}
6571 +
6572 +static int bcm43xx_append_mode(struct ieee80211_hw *ieee,
6573 + int mode_id,
6574 + int nr_channels,
6575 + const struct ieee80211_channel *channels,
6576 + int nr_rates,
6577 + const struct ieee80211_rate *rates)
6578 +{
6579 + struct ieee80211_hw_modes *mode;
6580 + int err = -ENOMEM;
6581 +
6582 + mode = &(ieee->modes[ieee->num_modes]);
6583 +
6584 + mode->mode = mode_id;
6585 + mode->num_channels = nr_channels;
6586 + mode->channels = kzalloc(sizeof(*channels) * nr_channels, GFP_KERNEL);
6587 + if (!mode->channels)
6588 + goto out;
6589 + memcpy(mode->channels, channels, sizeof(*channels) * nr_channels);
6590 +
6591 + mode->num_rates = nr_rates;
6592 + mode->rates = kzalloc(sizeof(*rates) * nr_rates, GFP_KERNEL);
6593 + if (!mode->rates)
6594 + goto err_free_channels;
6595 + memcpy(mode->rates, rates, sizeof(*rates) * nr_rates);
6596 +
6597 + ieee->num_modes++;
6598 + err = 0;
6599 +out:
6600 + return err;
6601 +
6602 +err_free_channels:
6603 + kfree(mode->channels);
6604 + goto out;
6605 +}
6606 +
6607 +static int bcm43xx_setup_modes_aphy(struct bcm43xx_private *bcm)
6608 +{
6609 + int err = 0;
6610 +
6611 + static const struct ieee80211_rate rates[] = {
6612 + {
6613 + .rate = 60,
6614 + .val = BCM43xx_OFDM_RATE_6MB,
6615 + .flags = IEEE80211_RATE_OFDM,
6616 + .val2 = BCM43xx_OFDM_RATE_6MB,
6617 + }, {
6618 + .rate = 90,
6619 + .val = BCM43xx_OFDM_RATE_9MB,
6620 + .flags = IEEE80211_RATE_OFDM,
6621 + .val2 = BCM43xx_OFDM_RATE_9MB,
6622 + }, {
6623 + .rate = 120,
6624 + .val = BCM43xx_OFDM_RATE_12MB,
6625 + .flags = IEEE80211_RATE_OFDM,
6626 + .val2 = BCM43xx_OFDM_RATE_12MB,
6627 + }, {
6628 + .rate = 180,
6629 + .val = BCM43xx_OFDM_RATE_18MB,
6630 + .flags = IEEE80211_RATE_OFDM,
6631 + .val2 = BCM43xx_OFDM_RATE_18MB,
6632 + }, {
6633 + .rate = 240,
6634 + .val = BCM43xx_OFDM_RATE_24MB,
6635 + .flags = IEEE80211_RATE_OFDM,
6636 + .val2 = BCM43xx_OFDM_RATE_24MB,
6637 + }, {
6638 + .rate = 360,
6639 + .val = BCM43xx_OFDM_RATE_36MB,
6640 + .flags = IEEE80211_RATE_OFDM,
6641 + .val2 = BCM43xx_OFDM_RATE_36MB,
6642 + }, {
6643 + .rate = 480,
6644 + .val = BCM43xx_OFDM_RATE_48MB,
6645 + .flags = IEEE80211_RATE_OFDM,
6646 + .val2 = BCM43xx_OFDM_RATE_48MB,
6647 + }, {
6648 + .rate = 540,
6649 + .val = BCM43xx_OFDM_RATE_54MB,
6650 + .flags = IEEE80211_RATE_OFDM,
6651 + .val2 = BCM43xx_OFDM_RATE_54MB,
6652 + },
6653 + };
6654 + static const struct ieee80211_channel channels[] = {
6655 + {
6656 + .chan = 36,
6657 + .freq = 5180,
6658 + .val = 36,
6659 + .flag = IEEE80211_CHAN_W_SCAN |
6660 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6661 + IEEE80211_CHAN_W_IBSS,
6662 + .power_level = 0xFF,
6663 + .antenna_max = 0xFF,
6664 + }, {
6665 + .chan = 40,
6666 + .freq = 5200,
6667 + .val = 40,
6668 + .flag = IEEE80211_CHAN_W_SCAN |
6669 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6670 + IEEE80211_CHAN_W_IBSS,
6671 + .power_level = 0xFF,
6672 + .antenna_max = 0xFF,
6673 + }, {
6674 + .chan = 44,
6675 + .freq = 5220,
6676 + .val = 44,
6677 + .flag = IEEE80211_CHAN_W_SCAN |
6678 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6679 + IEEE80211_CHAN_W_IBSS,
6680 + .power_level = 0xFF,
6681 + .antenna_max = 0xFF,
6682 + }, {
6683 + .chan = 48,
6684 + .freq = 5240,
6685 + .val = 48,
6686 + .flag = IEEE80211_CHAN_W_SCAN |
6687 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6688 + IEEE80211_CHAN_W_IBSS,
6689 + .power_level = 0xFF,
6690 + .antenna_max = 0xFF,
6691 + }, {
6692 + .chan = 52,
6693 + .freq = 5260,
6694 + .val = 52,
6695 + .flag = IEEE80211_CHAN_W_SCAN |
6696 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6697 + IEEE80211_CHAN_W_IBSS,
6698 + .power_level = 0xFF,
6699 + .antenna_max = 0xFF,
6700 + }, {
6701 + .chan = 56,
6702 + .freq = 5280,
6703 + .val = 56,
6704 + .flag = IEEE80211_CHAN_W_SCAN |
6705 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6706 + IEEE80211_CHAN_W_IBSS,
6707 + .power_level = 0xFF,
6708 + .antenna_max = 0xFF,
6709 + }, {
6710 + .chan = 60,
6711 + .freq = 5300,
6712 + .val = 60,
6713 + .flag = IEEE80211_CHAN_W_SCAN |
6714 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6715 + IEEE80211_CHAN_W_IBSS,
6716 + .power_level = 0xFF,
6717 + .antenna_max = 0xFF,
6718 + }, {
6719 + .chan = 64,
6720 + .freq = 5320,
6721 + .val = 64,
6722 + .flag = IEEE80211_CHAN_W_SCAN |
6723 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6724 + IEEE80211_CHAN_W_IBSS,
6725 + .power_level = 0xFF,
6726 + .antenna_max = 0xFF,
6727 + }, {
6728 + .chan = 149,
6729 + .freq = 5745,
6730 + .val = 149,
6731 + .flag = IEEE80211_CHAN_W_SCAN |
6732 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6733 + IEEE80211_CHAN_W_IBSS,
6734 + .power_level = 0xFF,
6735 + .antenna_max = 0xFF,
6736 + }, {
6737 + .chan = 153,
6738 + .freq = 5765,
6739 + .val = 153,
6740 + .flag = IEEE80211_CHAN_W_SCAN |
6741 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6742 + IEEE80211_CHAN_W_IBSS,
6743 + .power_level = 0xFF,
6744 + .antenna_max = 0xFF,
6745 + }, {
6746 + .chan = 157,
6747 + .freq = 5785,
6748 + .val = 157,
6749 + .flag = IEEE80211_CHAN_W_SCAN |
6750 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6751 + IEEE80211_CHAN_W_IBSS,
6752 + .power_level = 0xFF,
6753 + .antenna_max = 0xFF,
6754 + }, {
6755 + .chan = 161,
6756 + .freq = 5805,
6757 + .val = 161,
6758 + .flag = IEEE80211_CHAN_W_SCAN |
6759 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6760 + IEEE80211_CHAN_W_IBSS,
6761 + .power_level = 0xFF,
6762 + .antenna_max = 0xFF,
6763 + }, {
6764 + .chan = 165,
6765 + .freq = 5825,
6766 + .val = 165,
6767 + .flag = IEEE80211_CHAN_W_SCAN |
6768 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6769 + IEEE80211_CHAN_W_IBSS,
6770 + .power_level = 0xFF,
6771 + .antenna_max = 0xFF,
6772 + },
6773 + };
6774 +
6775 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
6776 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211A,
6777 + ARRAY_SIZE(channels), channels,
6778 + ARRAY_SIZE(rates), rates);
6779 + }
6780 +
6781 + return err;
6782 +}
6783 +
6784 +static int bcm43xx_setup_modes_bphy(struct bcm43xx_private *bcm)
6785 +{
6786 + int err = 0;
6787 +
6788 + static const struct ieee80211_rate rates[] = {
6789 + {
6790 + .rate = 10,
6791 + .val = BCM43xx_CCK_RATE_1MB,
6792 + .flags = IEEE80211_RATE_CCK,
6793 + .val2 = BCM43xx_CCK_RATE_1MB,
6794 + }, {
6795 + .rate = 20,
6796 + .val = BCM43xx_CCK_RATE_2MB,
6797 + .flags = IEEE80211_RATE_CCK_2,
6798 + .val2 = BCM43xx_CCK_RATE_2MB,
6799 + }, {
6800 + .rate = 55,
6801 + .val = BCM43xx_CCK_RATE_5MB,
6802 + .flags = IEEE80211_RATE_CCK_2,
6803 + .val2 = BCM43xx_CCK_RATE_5MB,
6804 + }, {
6805 + .rate = 110,
6806 + .val = BCM43xx_CCK_RATE_11MB,
6807 + .flags = IEEE80211_RATE_CCK_2,
6808 + .val2 = BCM43xx_CCK_RATE_11MB,
6809 + },
6810 + };
6811 + static const struct ieee80211_channel channels[] = {
6812 + {
6813 + .chan = 1,
6814 + .freq = 2412,
6815 + .val = 1,
6816 + .flag = IEEE80211_CHAN_W_SCAN |
6817 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6818 + IEEE80211_CHAN_W_IBSS,
6819 + .power_level = 0xFF,
6820 + .antenna_max = 0xFF,
6821 + }, {
6822 + .chan = 2,
6823 + .freq = 2417,
6824 + .val = 2,
6825 + .flag = IEEE80211_CHAN_W_SCAN |
6826 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6827 + IEEE80211_CHAN_W_IBSS,
6828 + .power_level = 0xFF,
6829 + .antenna_max = 0xFF,
6830 + }, {
6831 + .chan = 3,
6832 + .freq = 2422,
6833 + .val = 3,
6834 + .flag = IEEE80211_CHAN_W_SCAN |
6835 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6836 + IEEE80211_CHAN_W_IBSS,
6837 + .power_level = 0xFF,
6838 + .antenna_max = 0xFF,
6839 + }, {
6840 + .chan = 4,
6841 + .freq = 2427,
6842 + .val = 4,
6843 + .flag = IEEE80211_CHAN_W_SCAN |
6844 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6845 + IEEE80211_CHAN_W_IBSS,
6846 + .power_level = 0xFF,
6847 + .antenna_max = 0xFF,
6848 + }, {
6849 + .chan = 5,
6850 + .freq = 2432,
6851 + .val = 5,
6852 + .flag = IEEE80211_CHAN_W_SCAN |
6853 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6854 + IEEE80211_CHAN_W_IBSS,
6855 + .power_level = 0xFF,
6856 + .antenna_max = 0xFF,
6857 + }, {
6858 + .chan = 6,
6859 + .freq = 2437,
6860 + .val = 6,
6861 + .flag = IEEE80211_CHAN_W_SCAN |
6862 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6863 + IEEE80211_CHAN_W_IBSS,
6864 + .power_level = 0xFF,
6865 + .antenna_max = 0xFF,
6866 + }, {
6867 + .chan = 7,
6868 + .freq = 2442,
6869 + .val = 7,
6870 + .flag = IEEE80211_CHAN_W_SCAN |
6871 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6872 + IEEE80211_CHAN_W_IBSS,
6873 + .power_level = 0xFF,
6874 + .antenna_max = 0xFF,
6875 + }, {
6876 + .chan = 8,
6877 + .freq = 2447,
6878 + .val = 8,
6879 + .flag = IEEE80211_CHAN_W_SCAN |
6880 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6881 + IEEE80211_CHAN_W_IBSS,
6882 + .power_level = 0xFF,
6883 + .antenna_max = 0xFF,
6884 + }, {
6885 + .chan = 9,
6886 + .freq = 2452,
6887 + .val = 9,
6888 + .flag = IEEE80211_CHAN_W_SCAN |
6889 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6890 + IEEE80211_CHAN_W_IBSS,
6891 + .power_level = 0xFF,
6892 + .antenna_max = 0xFF,
6893 + }, {
6894 + .chan = 10,
6895 + .freq = 2457,
6896 + .val = 10,
6897 + .flag = IEEE80211_CHAN_W_SCAN |
6898 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6899 + IEEE80211_CHAN_W_IBSS,
6900 + .power_level = 0xFF,
6901 + .antenna_max = 0xFF,
6902 + }, {
6903 + .chan = 11,
6904 + .freq = 2462,
6905 + .val = 11,
6906 + .flag = IEEE80211_CHAN_W_SCAN |
6907 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6908 + IEEE80211_CHAN_W_IBSS,
6909 + .power_level = 0xFF,
6910 + .antenna_max = 0xFF,
6911 + }, {
6912 + .chan = 12,
6913 + .freq = 2467,
6914 + .val = 12,
6915 + .flag = IEEE80211_CHAN_W_SCAN |
6916 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6917 + IEEE80211_CHAN_W_IBSS,
6918 + .power_level = 0xFF,
6919 + .antenna_max = 0xFF,
6920 + }, {
6921 + .chan = 13,
6922 + .freq = 2472,
6923 + .val = 13,
6924 + .flag = IEEE80211_CHAN_W_SCAN |
6925 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6926 + IEEE80211_CHAN_W_IBSS,
6927 + .power_level = 0xFF,
6928 + .antenna_max = 0xFF,
6929 + }, /*{
6930 + .chan = 14,
6931 + .freq = 2484,
6932 + .val = 14,
6933 + .flag = IEEE80211_CHAN_W_SCAN |
6934 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6935 + IEEE80211_CHAN_W_IBSS,
6936 + .power_level = 0xFF,
6937 + .antenna_max = 0xFF,
6938 + },*/
6939 + };
6940 +
6941 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_B ||
6942 + bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
6943 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211B,
6944 + ARRAY_SIZE(channels), channels,
6945 + ARRAY_SIZE(rates), rates);
6946 + }
6947 +
6948 + return err;
6949 +}
6950 +
6951 +static int bcm43xx_setup_modes_gphy(struct bcm43xx_private *bcm)
6952 +{
6953 + int err = 0;
6954 +
6955 + static const struct ieee80211_rate rates[] = {
6956 + {
6957 + .rate = 10,
6958 + .val = BCM43xx_CCK_RATE_1MB,
6959 + .flags = IEEE80211_RATE_CCK,
6960 + .val2 = BCM43xx_CCK_RATE_1MB,
6961 + }, {
6962 + .rate = 20,
6963 + .val = BCM43xx_CCK_RATE_2MB,
6964 + .flags = IEEE80211_RATE_CCK_2,
6965 + .val2 = BCM43xx_CCK_RATE_2MB,
6966 + }, {
6967 + .rate = 55,
6968 + .val = BCM43xx_CCK_RATE_5MB,
6969 + .flags = IEEE80211_RATE_CCK_2,
6970 + .val2 = BCM43xx_CCK_RATE_5MB,
6971 + }, {
6972 + .rate = 60,
6973 + .val = BCM43xx_OFDM_RATE_6MB,
6974 + .flags = IEEE80211_RATE_OFDM,
6975 + .val2 = BCM43xx_OFDM_RATE_6MB,
6976 + }, {
6977 + .rate = 90,
6978 + .val = BCM43xx_OFDM_RATE_9MB,
6979 + .flags = IEEE80211_RATE_OFDM,
6980 + .val2 = BCM43xx_OFDM_RATE_9MB,
6981 + }, {
6982 + .rate = 110,
6983 + .val = BCM43xx_CCK_RATE_11MB,
6984 + .flags = IEEE80211_RATE_CCK_2,
6985 + .val2 = BCM43xx_CCK_RATE_11MB,
6986 + }, {
6987 + .rate = 120,
6988 + .val = BCM43xx_OFDM_RATE_12MB,
6989 + .flags = IEEE80211_RATE_OFDM,
6990 + .val2 = BCM43xx_OFDM_RATE_12MB,
6991 + }, {
6992 + .rate = 180,
6993 + .val = BCM43xx_OFDM_RATE_18MB,
6994 + .flags = IEEE80211_RATE_OFDM,
6995 + .val2 = BCM43xx_OFDM_RATE_18MB,
6996 + }, {
6997 + .rate = 240,
6998 + .val = BCM43xx_OFDM_RATE_24MB,
6999 + .flags = IEEE80211_RATE_OFDM,
7000 + .val2 = BCM43xx_OFDM_RATE_24MB,
7001 + }, {
7002 + .rate = 360,
7003 + .val = BCM43xx_OFDM_RATE_36MB,
7004 + .flags = IEEE80211_RATE_OFDM,
7005 + .val2 = BCM43xx_OFDM_RATE_36MB,
7006 + }, {
7007 + .rate = 480,
7008 + .val = BCM43xx_OFDM_RATE_48MB,
7009 + .flags = IEEE80211_RATE_OFDM,
7010 + .val2 = BCM43xx_OFDM_RATE_48MB,
7011 + }, {
7012 + .rate = 540,
7013 + .val = BCM43xx_OFDM_RATE_54MB,
7014 + .flags = IEEE80211_RATE_OFDM,
7015 + .val2 = BCM43xx_OFDM_RATE_54MB,
7016 + },
7017 + };
7018 + static const struct ieee80211_channel channels[] = {
7019 + {
7020 + .chan = 1,
7021 + .freq = 2412,
7022 + .val = 1,
7023 + .flag = IEEE80211_CHAN_W_SCAN |
7024 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7025 + IEEE80211_CHAN_W_IBSS,
7026 + .power_level = 0xFF,
7027 + .antenna_max = 0xFF,
7028 + }, {
7029 + .chan = 2,
7030 + .freq = 2417,
7031 + .val = 2,
7032 + .flag = IEEE80211_CHAN_W_SCAN |
7033 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7034 + IEEE80211_CHAN_W_IBSS,
7035 + .power_level = 0xFF,
7036 + .antenna_max = 0xFF,
7037 + }, {
7038 + .chan = 3,
7039 + .freq = 2422,
7040 + .val = 3,
7041 + .flag = IEEE80211_CHAN_W_SCAN |
7042 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7043 + IEEE80211_CHAN_W_IBSS,
7044 + .power_level = 0xFF,
7045 + .antenna_max = 0xFF,
7046 + }, {
7047 + .chan = 4,
7048 + .freq = 2427,
7049 + .val = 4,
7050 + .flag = IEEE80211_CHAN_W_SCAN |
7051 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7052 + IEEE80211_CHAN_W_IBSS,
7053 + .power_level = 0xFF,
7054 + .antenna_max = 0xFF,
7055 + }, {
7056 + .chan = 5,
7057 + .freq = 2432,
7058 + .val = 5,
7059 + .flag = IEEE80211_CHAN_W_SCAN |
7060 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7061 + IEEE80211_CHAN_W_IBSS,
7062 + .power_level = 0xFF,
7063 + .antenna_max = 0xFF,
7064 + }, {
7065 + .chan = 6,
7066 + .freq = 2437,
7067 + .val = 6,
7068 + .flag = IEEE80211_CHAN_W_SCAN |
7069 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7070 + IEEE80211_CHAN_W_IBSS,
7071 + .power_level = 0xFF,
7072 + .antenna_max = 0xFF,
7073 + }, {
7074 + .chan = 7,
7075 + .freq = 2442,
7076 + .val = 7,
7077 + .flag = IEEE80211_CHAN_W_SCAN |
7078 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7079 + IEEE80211_CHAN_W_IBSS,
7080 + .power_level = 0xFF,
7081 + .antenna_max = 0xFF,
7082 + }, {
7083 + .chan = 8,
7084 + .freq = 2447,
7085 + .val = 8,
7086 + .flag = IEEE80211_CHAN_W_SCAN |
7087 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7088 + IEEE80211_CHAN_W_IBSS,
7089 + .power_level = 0xFF,
7090 + .antenna_max = 0xFF,
7091 + }, {
7092 + .chan = 9,
7093 + .freq = 2452,
7094 + .val = 9,
7095 + .flag = IEEE80211_CHAN_W_SCAN |
7096 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7097 + IEEE80211_CHAN_W_IBSS,
7098 + .power_level = 0xFF,
7099 + .antenna_max = 0xFF,
7100 + }, {
7101 + .chan = 10,
7102 + .freq = 2457,
7103 + .val = 10,
7104 + .flag = IEEE80211_CHAN_W_SCAN |
7105 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7106 + IEEE80211_CHAN_W_IBSS,
7107 + .power_level = 0xFF,
7108 + .antenna_max = 0xFF,
7109 + }, {
7110 + .chan = 11,
7111 + .freq = 2462,
7112 + .val = 11,
7113 + .flag = IEEE80211_CHAN_W_SCAN |
7114 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7115 + IEEE80211_CHAN_W_IBSS,
7116 + .power_level = 0xFF,
7117 + .antenna_max = 0xFF,
7118 + }, {
7119 + .chan = 12,
7120 + .freq = 2467,
7121 + .val = 12,
7122 + .flag = IEEE80211_CHAN_W_SCAN |
7123 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7124 + IEEE80211_CHAN_W_IBSS,
7125 + .power_level = 0xFF,
7126 + .antenna_max = 0xFF,
7127 + }, {
7128 + .chan = 13,
7129 + .freq = 2472,
7130 + .val = 13,
7131 + .flag = IEEE80211_CHAN_W_SCAN |
7132 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7133 + IEEE80211_CHAN_W_IBSS,
7134 + .power_level = 0xFF,
7135 + .antenna_max = 0xFF,
7136 + }, /*{
7137 + .chan = 14,
7138 + .freq = 2484,
7139 + .val = 14,
7140 + .flag = IEEE80211_CHAN_W_SCAN |
7141 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7142 + IEEE80211_CHAN_W_IBSS,
7143 + .power_level = 0xFF,
7144 + .antenna_max = 0xFF,
7145 + },*/
7146 + };
7147 +
7148 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
7149 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211G,
7150 + ARRAY_SIZE(channels), channels,
7151 + ARRAY_SIZE(rates), rates);
7152 + }
7153 +
7154 + return err;
7155 +}
7156 +
7157 +static int bcm43xx_setup_modes(struct bcm43xx_private *bcm)
7158 +{
7159 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7160 + int err = -ENOMEM;
7161 + int nr;
7162 + struct ieee80211_hw *ieee = bcm->ieee;
7163 +
7164 + if (phy->type == BCM43xx_PHYTYPE_A)
7165 + nr = 1;
7166 + else if (phy->type == BCM43xx_PHYTYPE_B)
7167 + nr = 1;
7168 + else
7169 + nr = 2;
7170 + ieee->modes = kzalloc(sizeof(*(ieee->modes)) * nr, GFP_KERNEL);
7171 + if (!ieee->modes)
7172 + goto out;
7173 + ieee->num_modes = 0;
7174 +
7175 + err = bcm43xx_setup_modes_aphy(bcm);
7176 + if (err)
7177 + goto error;
7178 + err = bcm43xx_setup_modes_gphy(bcm);
7179 + if (err)
7180 + goto error;
7181 + err = bcm43xx_setup_modes_bphy(bcm);
7182 + if (err)
7183 + goto error;
7184 +
7185 + assert(ieee->num_modes == nr && nr > 0);
7186 +out:
7187 + return err;
7188 +
7189 +error:
7190 + bcm43xx_free_modes(bcm);
7191 + goto out;
7192 +}
7193 +
7194 +static void bcm43xx_security_init(struct bcm43xx_private *bcm)
7195 +{
7196 + bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
7197 + 0x0056) * 2;
7198 + bcm43xx_clear_keys(bcm);
7199 +}
7200 +
7201 +/* This is the opposite of bcm43xx_init_board() */
7202 +static void bcm43xx_free_board(struct bcm43xx_private *bcm)
7203 +{
7204 + int i, err;
7205 + unsigned long flags;
7206 +
7207 + bcm43xx_sysfs_unregister(bcm);
7208 +
7209 + bcm43xx_periodic_tasks_delete(bcm);
7210 +
7211 + bcm43xx_lock(bcm, flags);
7212 + bcm->initialized = 0;
7213 + bcm->shutting_down = 1;
7214 + bcm43xx_unlock(bcm, flags);
7215 +
7216 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7217 + if (!bcm->core_80211[i].available)
7218 + continue;
7219 + if (!bcm->core_80211[i].initialized)
7220 + continue;
7221 +
7222 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7223 + assert(err == 0);
7224 + bcm43xx_wireless_core_cleanup(bcm);
7225 + }
7226 +
7227 + bcm43xx_pctl_set_crystal(bcm, 0);
7228 + bcm43xx_free_modes(bcm);
7229 +
7230 + bcm43xx_lock(bcm, flags);
7231 + bcm->shutting_down = 0;
7232 + bcm43xx_unlock(bcm, flags);
7233 +}
7234 +
7235 +static int bcm43xx_init_board(struct bcm43xx_private *bcm)
7236 +{
7237 + int i, err;
7238 + int connect_phy;
7239 + unsigned long flags;
7240 +
7241 + might_sleep();
7242 +
7243 + bcm43xx_lock(bcm, flags);
7244 + bcm->initialized = 0;
7245 + bcm->shutting_down = 0;
7246 + bcm43xx_unlock(bcm, flags);
7247 +
7248 + err = bcm43xx_pctl_set_crystal(bcm, 1);
7249 + if (err)
7250 + goto out;
7251 + err = bcm43xx_pctl_init(bcm);
7252 + if (err)
7253 + goto err_crystal_off;
7254 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
7255 + if (err)
7256 + goto err_crystal_off;
7257 +
7258 + tasklet_enable(&bcm->isr_tasklet);
7259 + for (i = 0; i < bcm->nr_80211_available; i++) {
7260 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7261 + assert(err != -ENODEV);
7262 + if (err)
7263 + goto err_80211_unwind;
7264 +
7265 + /* Enable the selected wireless core.
7266 + * Connect PHY only on the first core.
7267 + */
7268 + if (!bcm43xx_core_enabled(bcm)) {
7269 + if (bcm->nr_80211_available == 1) {
7270 + connect_phy = bcm43xx_current_phy(bcm)->connected;
7271 + } else {
7272 + if (i == 0)
7273 + connect_phy = 1;
7274 + else
7275 + connect_phy = 0;
7276 + }
7277 + bcm43xx_wireless_core_reset(bcm, connect_phy);
7278 + }
7279 +
7280 + if (i != 0)
7281 + bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
7282 +
7283 + err = bcm43xx_wireless_core_init(bcm);
7284 + if (err)
7285 + goto err_80211_unwind;
7286 +
7287 + if (i != 0) {
7288 + bcm43xx_mac_suspend(bcm);
7289 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7290 + bcm43xx_radio_turn_off(bcm);
7291 + }
7292 + }
7293 + bcm->active_80211_core = &bcm->core_80211[0];
7294 + if (bcm->nr_80211_available >= 2) {
7295 + bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
7296 + bcm43xx_mac_enable(bcm);
7297 + }
7298 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
7299 + bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
7300 + dprintk(KERN_INFO PFX "80211 cores initialized\n");
7301 + bcm43xx_setup_modes(bcm);
7302 + bcm43xx_security_init(bcm);
7303 + ieee80211_update_hw(bcm->net_dev, bcm->ieee);
7304 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
7305 + ieee80211_netif_oper(bcm->net_dev, NETIF_START);
7306 + ieee80211_netif_oper(bcm->net_dev, NETIF_WAKE);
7307 +
7308 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
7309 +
7310 + if (bcm43xx_current_radio(bcm)->initial_channel != 0xFF) {
7311 + bcm43xx_mac_suspend(bcm);
7312 + bcm43xx_radio_selectchannel(bcm, bcm43xx_current_radio(bcm)->initial_channel, 0);
7313 + bcm43xx_mac_enable(bcm);
7314 + }
7315 +
7316 + /* Initialization of the board is done. Flag it as such. */
7317 + bcm43xx_lock(bcm, flags);
7318 + bcm->initialized = 1;
7319 + bcm43xx_unlock(bcm, flags);
7320 +
7321 + bcm43xx_periodic_tasks_setup(bcm);
7322 + bcm43xx_sysfs_register(bcm);
7323 +
7324 + assert(err == 0);
7325 +out:
7326 + return err;
7327 +
7328 +err_80211_unwind:
7329 + tasklet_disable(&bcm->isr_tasklet);
7330 + /* unwind all 80211 initialization */
7331 + for (i = 0; i < bcm->nr_80211_available; i++) {
7332 + if (!bcm->core_80211[i].initialized)
7333 + continue;
7334 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7335 + bcm43xx_wireless_core_cleanup(bcm);
7336 + }
7337 +err_crystal_off:
7338 + bcm43xx_pctl_set_crystal(bcm, 0);
7339 + goto out;
7340 +}
7341 +
7342 +static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
7343 +{
7344 + struct pci_dev *pci_dev = bcm->pci_dev;
7345 + int i;
7346 +
7347 + bcm43xx_chipset_detach(bcm);
7348 + /* Do _not_ access the chip, after it is detached. */
7349 + iounmap(bcm->mmio_addr);
7350 +
7351 + pci_release_regions(pci_dev);
7352 + pci_disable_device(pci_dev);
7353 +
7354 + /* Free allocated structures/fields */
7355 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7356 + kfree(bcm->core_80211_ext[i].phy._lo_pairs);
7357 + if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
7358 + kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
7359 + }
7360 +}
7361 +
7362 +static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
7363 +{
7364 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7365 + u16 value;
7366 + u8 phy_version;
7367 + u8 phy_type;
7368 + u8 phy_rev;
7369 + int phy_rev_ok = 1;
7370 + void *p;
7371 +
7372 + value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
7373 +
7374 + phy_version = (value & 0xF000) >> 12;
7375 + phy_type = (value & 0x0F00) >> 8;
7376 + phy_rev = (value & 0x000F);
7377 +
7378 + dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
7379 + phy_version, phy_type, phy_rev);
7380 +
7381 + switch (phy_type) {
7382 + case BCM43xx_PHYTYPE_A:
7383 + if (phy_rev >= 4)
7384 + phy_rev_ok = 0;
7385 + break;
7386 + case BCM43xx_PHYTYPE_B:
7387 + if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
7388 + phy_rev_ok = 0;
7389 + break;
7390 + case BCM43xx_PHYTYPE_G:
7391 + if (phy_rev > 7)
7392 + phy_rev_ok = 0;
7393 + break;
7394 + default:
7395 + printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
7396 + phy_type);
7397 + return -ENODEV;
7398 + };
7399 + if (!phy_rev_ok) {
7400 + printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
7401 + phy_rev);
7402 + }
7403 +
7404 + phy->version = phy_version;
7405 + phy->type = phy_type;
7406 + phy->rev = phy_rev;
7407 + if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
7408 + p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
7409 + GFP_KERNEL);
7410 + if (!p)
7411 + return -ENOMEM;
7412 + phy->_lo_pairs = p;
7413 + }
7414 +
7415 + return 0;
7416 +}
7417 +
7418 +static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
7419 +{
7420 + struct pci_dev *pci_dev = bcm->pci_dev;
7421 + struct net_device *net_dev = bcm->net_dev;
7422 + int err;
7423 + int i;
7424 + unsigned long mmio_start, mmio_flags, mmio_len;
7425 + u32 coremask;
7426 +
7427 + err = pci_enable_device(pci_dev);
7428 + if (err) {
7429 + printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
7430 + goto out;
7431 + }
7432 + mmio_start = pci_resource_start(pci_dev, 0);
7433 + mmio_flags = pci_resource_flags(pci_dev, 0);
7434 + mmio_len = pci_resource_len(pci_dev, 0);
7435 + if (!(mmio_flags & IORESOURCE_MEM)) {
7436 + printk(KERN_ERR PFX
7437 + "%s, region #0 not an MMIO resource, aborting\n",
7438 + pci_name(pci_dev));
7439 + err = -ENODEV;
7440 + goto err_pci_disable;
7441 + }
7442 + err = pci_request_regions(pci_dev, KBUILD_MODNAME);
7443 + if (err) {
7444 + printk(KERN_ERR PFX
7445 + "could not access PCI resources (%i)\n", err);
7446 + goto err_pci_disable;
7447 + }
7448 + /* enable PCI bus-mastering */
7449 + pci_set_master(pci_dev);
7450 + bcm->mmio_addr = ioremap(mmio_start, mmio_len);
7451 + if (!bcm->mmio_addr) {
7452 + printk(KERN_ERR PFX "%s: cannot remap MMIO, aborting\n",
7453 + pci_name(pci_dev));
7454 + err = -EIO;
7455 + goto err_pci_release;
7456 + }
7457 + bcm->mmio_len = mmio_len;
7458 + net_dev->base_addr = (unsigned long)bcm->mmio_addr;
7459 +
7460 + bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
7461 + &bcm->board_vendor);
7462 + bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
7463 + &bcm->board_type);
7464 + bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
7465 + &bcm->board_revision);
7466 +
7467 + err = bcm43xx_chipset_attach(bcm);
7468 + if (err)
7469 + goto err_iounmap;
7470 + err = bcm43xx_pctl_init(bcm);
7471 + if (err)
7472 + goto err_chipset_detach;
7473 + err = bcm43xx_probe_cores(bcm);
7474 + if (err)
7475 + goto err_chipset_detach;
7476 +
7477 + /* Attach all IO cores to the backplane. */
7478 + coremask = 0;
7479 + for (i = 0; i < bcm->nr_80211_available; i++)
7480 + coremask |= (1 << bcm->core_80211[i].index);
7481 + //FIXME: Also attach some non80211 cores?
7482 + err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
7483 + if (err) {
7484 + printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
7485 + goto err_chipset_detach;
7486 + }
7487 +
7488 + err = bcm43xx_sprom_extract(bcm);
7489 + if (err)
7490 + goto err_chipset_detach;
7491 + err = bcm43xx_leds_init(bcm);
7492 + if (err)
7493 + goto err_chipset_detach;
7494 +
7495 + for (i = 0; i < bcm->nr_80211_available; i++) {
7496 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7497 + assert(err != -ENODEV);
7498 + if (err)
7499 + goto err_80211_unwind;
7500 +
7501 + /* Enable the selected wireless core.
7502 + * Connect PHY only on the first core.
7503 + */
7504 + bcm43xx_wireless_core_reset(bcm, (i == 0));
7505 +
7506 + err = bcm43xx_read_phyinfo(bcm);
7507 + if (err && (i == 0))
7508 + goto err_80211_unwind;
7509 +
7510 + err = bcm43xx_read_radioinfo(bcm);
7511 + if (err && (i == 0))
7512 + goto err_80211_unwind;
7513 +
7514 + err = bcm43xx_validate_chip(bcm);
7515 + if (err && (i == 0))
7516 + goto err_80211_unwind;
7517 +
7518 + bcm43xx_radio_turn_off(bcm);
7519 + err = bcm43xx_phy_init_tssi2dbm_table(bcm);
7520 + if (err)
7521 + goto err_80211_unwind;
7522 + bcm43xx_wireless_core_disable(bcm);
7523 + }
7524 + bcm43xx_pctl_set_crystal(bcm, 0);
7525 +
7526 + /* Set the MAC address in the networking subsystem */
7527 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
7528 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
7529 + else
7530 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
7531 +
7532 + snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
7533 + "Broadcom %04X", bcm->chip_id);
7534 +
7535 + assert(err == 0);
7536 +out:
7537 + return err;
7538 +
7539 +err_80211_unwind:
7540 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7541 + kfree(bcm->core_80211_ext[i].phy._lo_pairs);
7542 + if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
7543 + kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
7544 + }
7545 +err_chipset_detach:
7546 + bcm43xx_chipset_detach(bcm);
7547 +err_iounmap:
7548 + iounmap(bcm->mmio_addr);
7549 +err_pci_release:
7550 + pci_release_regions(pci_dev);
7551 +err_pci_disable:
7552 + pci_disable_device(pci_dev);
7553 + goto out;
7554 +}
7555 +
7556 +/* hard_start_xmit() callback in struct ieee80211_device */
7557 +static int bcm43xx_net_hard_start_xmit(struct net_device *net_dev,
7558 + struct sk_buff *skb,
7559 + struct ieee80211_tx_control *ctl)
7560 +{
7561 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7562 + int err = -ENODEV;
7563 + unsigned long flags;
7564 +
7565 + bcm43xx_lock_mmio(bcm, flags);
7566 + if (likely(bcm->initialized)) {
7567 + if (bcm43xx_using_pio(bcm))
7568 + err = bcm43xx_pio_tx(bcm, skb, ctl);
7569 + else
7570 + err = bcm43xx_dma_tx(bcm, skb, ctl);
7571 + }
7572 + bcm43xx_unlock_mmio(bcm, flags);
7573 +
7574 + return err;
7575 +}
7576 +
7577 +static int bcm43xx_net_reset(struct net_device *net_dev)
7578 +{
7579 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7580 + unsigned long flags;
7581 +
7582 + bcm43xx_lock_mmio(bcm, flags);
7583 + bcm43xx_controller_restart(bcm, "IEEE reset");
7584 + bcm43xx_unlock_mmio(bcm, flags);
7585 +
7586 + return 0;
7587 +}
7588 +
7589 +static int bcm43xx_net_config(struct net_device *net_dev,
7590 + struct ieee80211_conf *conf)
7591 +{
7592 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7593 + struct bcm43xx_radioinfo *radio;
7594 + struct bcm43xx_phyinfo *phy;
7595 + unsigned long flags;
7596 +
7597 + bcm43xx_lock_mmio(bcm, flags);
7598 + if (!bcm->initialized) {
7599 + bcm43xx_unlock_mmio(bcm, flags);
7600 + return 0;
7601 + }
7602 + radio = bcm43xx_current_radio(bcm);
7603 + phy = bcm43xx_current_phy(bcm);
7604 +
7605 + if (conf->channel != radio->channel)
7606 + bcm43xx_radio_selectchannel(bcm, conf->channel, 0);
7607 +
7608 + if (conf->mode != bcm->iw_mode)
7609 + bcm43xx_set_iwmode(bcm, conf->mode);
7610 +
7611 + if (conf->short_slot_time != bcm->short_slot) {
7612 + assert(phy->type == BCM43xx_PHYTYPE_G);
7613 + if (conf->short_slot_time)
7614 + bcm43xx_short_slot_timing_enable(bcm);
7615 + else
7616 + bcm43xx_short_slot_timing_disable(bcm);
7617 + }
7618 +
7619 + if (conf->power_level != 0) {
7620 + radio->power_level = conf->power_level;
7621 + bcm43xx_phy_xmitpower(bcm);
7622 + }
7623 +//FIXME: This does not seem to wake up:
7624 +#if 0
7625 + if (conf->power_level == 0) {
7626 + if (radio->enabled)
7627 + bcm43xx_radio_turn_off(bcm);
7628 + } else {
7629 + if (!radio->enabled)
7630 + bcm43xx_radio_turn_on(bcm);
7631 + }
7632 +#endif
7633 +
7634 + //TODO: phymode
7635 + //TODO: antennas
7636 +
7637 + bcm43xx_unlock_mmio(bcm, flags);
7638 +
7639 + return 0;
7640 +}
7641 +
7642 +static int bcm43xx_net_set_key(struct net_device *net_dev,
7643 + set_key_cmd cmd,
7644 + u8 *addr,
7645 + struct ieee80211_key_conf *key,
7646 + int aid)
7647 +{
7648 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7649 + unsigned long flags;
7650 + u8 algorithm;
7651 + u8 index;
7652 + int err = -EINVAL;
7653 +
7654 + switch (key->alg) {
7655 + default:
7656 + case ALG_NONE:
7657 + case ALG_NULL:
7658 + algorithm = BCM43xx_SEC_ALGO_NONE;
7659 + break;
7660 + case ALG_WEP:
7661 + if (key->keylen == 5)
7662 + algorithm = BCM43xx_SEC_ALGO_WEP;
7663 + else
7664 + algorithm = BCM43xx_SEC_ALGO_WEP104;
7665 + break;
7666 + case ALG_TKIP:
7667 + algorithm = BCM43xx_SEC_ALGO_TKIP;
7668 + break;
7669 + case ALG_CCMP:
7670 + algorithm = BCM43xx_SEC_ALGO_AES;
7671 + break;
7672 + }
7673 +
7674 + index = (u8)(key->keyidx);
7675 + if (index >= ARRAY_SIZE(bcm->key))
7676 + goto out;
7677 + bcm43xx_lock_mmio(bcm, flags);
7678 + switch (cmd) {
7679 + case SET_KEY:
7680 + err = bcm43xx_key_write(bcm, index, algorithm,
7681 + key->key, key->keylen,
7682 + addr);
7683 + if (err)
7684 + goto out_unlock;
7685 + key->hw_key_idx = index;
7686 + key->force_sw_encrypt = 0;
7687 + if (key->default_tx_key)
7688 + bcm->default_key_idx = index;
7689 + bcm->key[index].enabled = 1;
7690 + break;
7691 + case DISABLE_KEY:
7692 + bcm->key[index].enabled = 0;
7693 + err = 0;
7694 + break;
7695 + case REMOVE_ALL_KEYS:
7696 + bcm43xx_clear_keys(bcm);
7697 + err = 0;
7698 + break;
7699 + case ENABLE_COMPRESSION:
7700 + case DISABLE_COMPRESSION:
7701 + err = 0;
7702 + break;
7703 + }
7704 +out_unlock:
7705 + bcm43xx_unlock_mmio(bcm, flags);
7706 +out:
7707 + return err;
7708 +}
7709 +
7710 +static int bcm43xx_net_conf_tx(struct net_device *net_dev,
7711 + int queue,
7712 + const struct ieee80211_tx_queue_params *params)
7713 +{
7714 + return 0;
7715 +}
7716 +
7717 +static int bcm43xx_net_get_tx_stats(struct net_device *net_dev,
7718 + struct ieee80211_tx_queue_stats *stats)
7719 +{
7720 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7721 + unsigned long flags;
7722 +
7723 + bcm43xx_lock(bcm, flags);
7724 + if (bcm43xx_using_pio(bcm))
7725 + bcm43xx_pio_get_tx_stats(bcm, stats);
7726 + else
7727 + bcm43xx_dma_get_tx_stats(bcm, stats);
7728 + bcm43xx_unlock(bcm, flags);
7729 +
7730 + return 0;
7731 +}
7732 +
7733 +static int bcm43xx_net_get_stats(struct net_device *net_dev,
7734 + struct ieee80211_low_level_stats *stats)
7735 +{
7736 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7737 + unsigned long flags;
7738 +
7739 + bcm43xx_lock(bcm, flags);
7740 + memcpy(stats, &bcm->ieee_stats, sizeof(*stats));
7741 + bcm43xx_unlock(bcm, flags);
7742 +
7743 + return 0;
7744 +}
7745 +
7746 +#ifdef CONFIG_NET_POLL_CONTROLLER
7747 +static void bcm43xx_net_poll_controller(struct net_device *net_dev)
7748 +{
7749 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7750 + unsigned long flags;
7751 +
7752 + local_irq_save(flags);
7753 + bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
7754 + local_irq_restore(flags);
7755 +}
7756 +#endif /* CONFIG_NET_POLL_CONTROLLER */
7757 +
7758 +static int bcm43xx_net_open(struct net_device *net_dev)
7759 +{
7760 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7761 +
7762 + return bcm43xx_init_board(bcm);
7763 +}
7764 +
7765 +static int bcm43xx_net_stop(struct net_device *net_dev)
7766 +{
7767 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7768 +
7769 + if (bcm->initialized) {
7770 + bcm43xx_disable_interrupts_sync(bcm, NULL);
7771 + bcm43xx_free_board(bcm);
7772 + }
7773 +
7774 + return 0;
7775 +}
7776 +
7777 +/* Initialization of struct net_device, just after allocation. */
7778 +static void bcm43xx_netdev_setup(struct net_device *net_dev)
7779 +{
7780 +#ifdef CONFIG_NET_POLL_CONTROLLER
7781 + net_dev->poll_controller = bcm43xx_net_poll_controller;
7782 +#endif
7783 + SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
7784 +}
7785 +
7786 +static int bcm43xx_init_private(struct bcm43xx_private *bcm,
7787 + struct net_device *net_dev,
7788 + struct pci_dev *pci_dev,
7789 + struct ieee80211_hw *ieee)
7790 +{
7791 + int err;
7792 +
7793 + bcm->ieee = ieee;
7794 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
7795 + bcm->pci_dev = pci_dev;
7796 + bcm->net_dev = net_dev;
7797 + bcm->bad_frames_preempt = modparam_bad_frames_preempt;
7798 + spin_lock_init(&bcm->_lock);
7799 + tasklet_init(&bcm->isr_tasklet,
7800 + (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
7801 + (unsigned long)bcm);
7802 + tasklet_disable_nosync(&bcm->isr_tasklet);
7803 + if (modparam_pio) {
7804 + bcm->__using_pio = 1;
7805 + } else {
7806 + err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
7807 + err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
7808 + if (err) {
7809 +#ifdef CONFIG_BCM43XX_D80211_PIO
7810 + printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
7811 + bcm->__using_pio = 1;
7812 +#else
7813 + printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
7814 + "Recompile the driver with PIO support, please.\n");
7815 + return -ENODEV;
7816 +#endif /* CONFIG_BCM43XX_D80211_PIO */
7817 + }
7818 + }
7819 +
7820 + return 0;
7821 +}
7822 +
7823 +static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
7824 + const struct pci_device_id *ent)
7825 +{
7826 + struct net_device *net_dev;
7827 + struct bcm43xx_private *bcm;
7828 + struct ieee80211_hw *ieee;
7829 + int err = -ENOMEM;
7830 +
7831 +#ifdef CONFIG_BCM947XX
7832 + if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
7833 + return -ENODEV;
7834 +#endif
7835 +
7836 +#ifdef DEBUG_SINGLE_DEVICE_ONLY
7837 + if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
7838 + return -ENODEV;
7839 +#endif
7840 +
7841 + ieee = kzalloc(sizeof(*ieee), GFP_KERNEL);
7842 + if (!ieee)
7843 + goto out;
7844 + ieee->version = IEEE80211_VERSION;
7845 + ieee->name = KBUILD_MODNAME;
7846 + ieee->host_gen_beacon = 1;
7847 + ieee->rx_includes_fcs = 1;
7848 + ieee->tx = bcm43xx_net_hard_start_xmit;
7849 + ieee->open = bcm43xx_net_open;
7850 + ieee->stop = bcm43xx_net_stop;
7851 + ieee->reset = bcm43xx_net_reset;
7852 + ieee->config = bcm43xx_net_config;
7853 +//TODO ieee->set_key = bcm43xx_net_set_key;
7854 + ieee->get_stats = bcm43xx_net_get_stats;
7855 + ieee->queues = 1;
7856 + ieee->get_tx_stats = bcm43xx_net_get_tx_stats;
7857 + ieee->conf_tx = bcm43xx_net_conf_tx;
7858 + ieee->wep_include_iv = 1;
7859 +
7860 + net_dev = ieee80211_alloc_hw(sizeof(*bcm), bcm43xx_netdev_setup);
7861 + if (!net_dev) {
7862 + printk(KERN_ERR PFX
7863 + "could not allocate ieee80211 device %s\n",
7864 + pci_name(pdev));
7865 + goto err_free_ieee;
7866 + }
7867 + /* initialize the bcm43xx_private struct */
7868 + bcm = bcm43xx_priv(net_dev);
7869 + memset(bcm, 0, sizeof(*bcm));
7870 + err = bcm43xx_init_private(bcm, net_dev, pdev, ieee);
7871 + if (err)
7872 + goto err_free_netdev;
7873 +
7874 + pci_set_drvdata(pdev, net_dev);
7875 +
7876 + err = bcm43xx_attach_board(bcm);
7877 + if (err)
7878 + goto err_free_netdev;
7879 + err = ieee80211_register_hw(net_dev, ieee);
7880 + if (err)
7881 + goto err_detach_board;
7882 +
7883 + bcm43xx_debugfs_add_device(bcm);
7884 +
7885 + assert(err == 0);
7886 +out:
7887 + return err;
7888 +
7889 +err_detach_board:
7890 + bcm43xx_detach_board(bcm);
7891 +err_free_netdev:
7892 + ieee80211_free_hw(net_dev);
7893 +err_free_ieee:
7894 + kfree(ieee);
7895 + goto out;
7896 +}
7897 +
7898 +static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
7899 +{
7900 + struct net_device *net_dev = pci_get_drvdata(pdev);
7901 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7902 + struct ieee80211_hw *ieee = bcm->ieee;
7903 +
7904 + bcm43xx_debugfs_remove_device(bcm);
7905 +
7906 + /* Bring down the device early to stop all TX and RX operation. */
7907 + ieee80211_netif_oper(net_dev, NETIF_DETACH);
7908 + bcm43xx_net_stop(net_dev);
7909 +
7910 + ieee80211_unregister_hw(net_dev);
7911 + bcm43xx_detach_board(bcm);
7912 + if (bcm->cached_beacon)
7913 + kfree_skb(bcm->cached_beacon);
7914 + bcm->cached_beacon = NULL;
7915 + assert(bcm->ucode == NULL);
7916 + ieee80211_free_hw(net_dev);
7917 + kfree(ieee);
7918 +}
7919 +
7920 +/* Hard-reset the chip. Do not call this directly.
7921 + * Use bcm43xx_controller_restart()
7922 + */
7923 +static void bcm43xx_chip_reset(void *_bcm)
7924 +{
7925 + struct bcm43xx_private *bcm = _bcm;
7926 + struct net_device *net_dev = bcm->net_dev;
7927 + struct pci_dev *pci_dev = bcm->pci_dev;
7928 + struct ieee80211_hw *ieee = bcm->ieee;
7929 + int err;
7930 + int was_initialized = bcm->initialized;
7931 +
7932 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
7933 + tasklet_disable(&bcm->isr_tasklet);
7934 +
7935 + bcm->firmware_norelease = 1;
7936 + if (was_initialized)
7937 + bcm43xx_free_board(bcm);
7938 + bcm->firmware_norelease = 0;
7939 + bcm43xx_detach_board(bcm);
7940 + err = bcm43xx_init_private(bcm, net_dev, pci_dev, ieee);
7941 + if (err)
7942 + goto failure;
7943 + err = bcm43xx_attach_board(bcm);
7944 + if (err)
7945 + goto failure;
7946 + if (was_initialized) {
7947 + err = bcm43xx_init_board(bcm);
7948 + if (err)
7949 + goto failure;
7950 + }
7951 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
7952 + printk(KERN_INFO PFX "Controller restarted\n");
7953 +
7954 + return;
7955 +failure:
7956 + printk(KERN_ERR PFX "Controller restart failed\n");
7957 +}
7958 +
7959 +/* Hard-reset the chip.
7960 + * This can be called from interrupt or process context.
7961 + * Make sure to _not_ re-enable device interrupts after this has been called.
7962 + */
7963 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
7964 +{
7965 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7966 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
7967 + printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
7968 + INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset, bcm);
7969 + schedule_work(&bcm->restart_work);
7970 +}
7971 +
7972 +#ifdef CONFIG_PM
7973 +
7974 +static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
7975 +{
7976 + struct net_device *net_dev = pci_get_drvdata(pdev);
7977 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7978 + unsigned long flags;
7979 + int try_to_shutdown = 0, err;
7980 +
7981 + dprintk(KERN_INFO PFX "Suspending...\n");
7982 +
7983 + bcm43xx_lock(bcm, flags);
7984 + bcm->was_initialized = bcm->initialized;
7985 + if (bcm->initialized)
7986 + try_to_shutdown = 1;
7987 + bcm43xx_unlock(bcm, flags);
7988 +
7989 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
7990 + if (try_to_shutdown) {
7991 + err = bcm43xx_disable_interrupts_sync(bcm, &bcm->irq_savedstate);
7992 + if (unlikely(err)) {
7993 + dprintk(KERN_ERR PFX "Suspend failed.\n");
7994 + return -EAGAIN;
7995 + }
7996 + bcm->firmware_norelease = 1;
7997 + bcm43xx_free_board(bcm);
7998 + bcm->firmware_norelease = 0;
7999 + }
8000 + bcm43xx_chipset_detach(bcm);
8001 +
8002 + pci_save_state(pdev);
8003 + pci_disable_device(pdev);
8004 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
8005 +
8006 + dprintk(KERN_INFO PFX "Device suspended.\n");
8007 +
8008 + return 0;
8009 +}
8010 +
8011 +static int bcm43xx_resume(struct pci_dev *pdev)
8012 +{
8013 + struct net_device *net_dev = pci_get_drvdata(pdev);
8014 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8015 + int err = 0;
8016 +
8017 + dprintk(KERN_INFO PFX "Resuming...\n");
8018 +
8019 + pci_set_power_state(pdev, 0);
8020 + pci_enable_device(pdev);
8021 + pci_restore_state(pdev);
8022 +
8023 + bcm43xx_chipset_attach(bcm);
8024 + if (bcm->was_initialized) {
8025 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
8026 + err = bcm43xx_init_board(bcm);
8027 + }
8028 + if (err) {
8029 + printk(KERN_ERR PFX "Resume failed!\n");
8030 + return err;
8031 + }
8032 +
8033 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8034 +
8035 + dprintk(KERN_INFO PFX "Device resumed.\n");
8036 +
8037 + return 0;
8038 +}
8039 +
8040 +#endif /* CONFIG_PM */
8041 +
8042 +static struct pci_driver bcm43xx_pci_driver = {
8043 + .name = KBUILD_MODNAME,
8044 + .id_table = bcm43xx_pci_tbl,
8045 + .probe = bcm43xx_init_one,
8046 + .remove = __devexit_p(bcm43xx_remove_one),
8047 +#ifdef CONFIG_PM
8048 + .suspend = bcm43xx_suspend,
8049 + .resume = bcm43xx_resume,
8050 +#endif /* CONFIG_PM */
8051 +};
8052 +
8053 +static int __init bcm43xx_init(void)
8054 +{
8055 + printk(KERN_INFO KBUILD_MODNAME " driver\n");
8056 + bcm43xx_debugfs_init();
8057 + return pci_register_driver(&bcm43xx_pci_driver);
8058 +}
8059 +
8060 +static void __exit bcm43xx_exit(void)
8061 +{
8062 + pci_unregister_driver(&bcm43xx_pci_driver);
8063 + bcm43xx_debugfs_exit();
8064 +}
8065 +
8066 +module_init(bcm43xx_init)
8067 +module_exit(bcm43xx_exit)
8068 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h
8069 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h 1970-01-01 01:00:00.000000000 +0100
8070 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h 2006-03-28 22:16:14.000000000 +0200
8071 @@ -0,0 +1,177 @@
8072 +/*
8073 +
8074 + Broadcom BCM43xx wireless driver
8075 +
8076 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
8077 + Stefano Brivio <st3@riseup.net>
8078 + Michael Buesch <mbuesch@freenet.de>
8079 + Danny van Dyk <kugelfang@gentoo.org>
8080 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
8081 +
8082 + Some parts of the code in this file are derived from the ipw2200
8083 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8084 +
8085 + This program is free software; you can redistribute it and/or modify
8086 + it under the terms of the GNU General Public License as published by
8087 + the Free Software Foundation; either version 2 of the License, or
8088 + (at your option) any later version.
8089 +
8090 + This program is distributed in the hope that it will be useful,
8091 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8092 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8093 + GNU General Public License for more details.
8094 +
8095 + You should have received a copy of the GNU General Public License
8096 + along with this program; see the file COPYING. If not, write to
8097 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
8098 + Boston, MA 02110-1301, USA.
8099 +
8100 +*/
8101 +
8102 +#ifndef BCM43xx_MAIN_H_
8103 +#define BCM43xx_MAIN_H_
8104 +
8105 +#include "bcm43xx.h"
8106 +
8107 +#ifdef CONFIG_BCM947XX
8108 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
8109 +
8110 +static inline void e_aton(char *str, char *dest)
8111 +{
8112 + int i = 0;
8113 + u16 *d = (u16 *) dest;
8114 +
8115 + for (;;) {
8116 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
8117 + str += 2;
8118 + if (!*str++ || i == 6)
8119 + break;
8120 + }
8121 + for (i = 0; i < 3; i++)
8122 + d[i] = cpu_to_be16(d[i]);
8123 +}
8124 +#endif
8125 +
8126 +#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
8127 +#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
8128 +/* Magic helper macro to pad structures. Ignore those above. It's magic. */
8129 +#define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
8130 +
8131 +
8132 +/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
8133 +static inline
8134 +u8 bcm43xx_freq_to_channel_a(int freq)
8135 +{
8136 + return ((freq - 5000) / 5);
8137 +}
8138 +static inline
8139 +u8 bcm43xx_freq_to_channel_bg(int freq)
8140 +{
8141 + u8 channel;
8142 +
8143 + if (freq == 2484)
8144 + channel = 14;
8145 + else
8146 + channel = (freq - 2407) / 5;
8147 +
8148 + return channel;
8149 +}
8150 +static inline
8151 +u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
8152 + int freq)
8153 +{
8154 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8155 + return bcm43xx_freq_to_channel_a(freq);
8156 + return bcm43xx_freq_to_channel_bg(freq);
8157 +}
8158 +
8159 +/* Lightweight function to convert a channel number to a frequency (in Mhz). */
8160 +static inline
8161 +int bcm43xx_channel_to_freq_a(u8 channel)
8162 +{
8163 + return (5000 + (5 * channel));
8164 +}
8165 +static inline
8166 +int bcm43xx_channel_to_freq_bg(u8 channel)
8167 +{
8168 + int freq;
8169 +
8170 + if (channel == 14)
8171 + freq = 2484;
8172 + else
8173 + freq = 2407 + (5 * channel);
8174 +
8175 + return freq;
8176 +}
8177 +static inline
8178 +int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
8179 + u8 channel)
8180 +{
8181 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8182 + return bcm43xx_channel_to_freq_a(channel);
8183 + return bcm43xx_channel_to_freq_bg(channel);
8184 +}
8185 +
8186 +/* Lightweight function to check if a channel number is valid.
8187 + * Note that this does _NOT_ check for geographical restrictions!
8188 + */
8189 +static inline
8190 +int bcm43xx_is_valid_channel_a(u8 channel)
8191 +{
8192 + return (channel <= 200);
8193 +}
8194 +static inline
8195 +int bcm43xx_is_valid_channel_bg(u8 channel)
8196 +{
8197 + return (channel >= 1 && channel <= 14);
8198 +}
8199 +static inline
8200 +int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
8201 + u8 channel)
8202 +{
8203 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8204 + return bcm43xx_is_valid_channel_a(channel);
8205 + return bcm43xx_is_valid_channel_bg(channel);
8206 +}
8207 +
8208 +static inline
8209 +int bcm43xx_is_cck_rate(int rate)
8210 +{
8211 + return (rate == BCM43xx_CCK_RATE_1MB ||
8212 + rate == BCM43xx_CCK_RATE_2MB ||
8213 + rate == BCM43xx_CCK_RATE_5MB ||
8214 + rate == BCM43xx_CCK_RATE_11MB);
8215 +}
8216 +
8217 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
8218 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
8219 +
8220 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
8221 + int iw_mode);
8222 +
8223 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
8224 + u16 routing, u16 offset);
8225 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
8226 + u16 routing, u16 offset);
8227 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
8228 + u16 routing, u16 offset,
8229 + u32 value);
8230 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
8231 + u16 routing, u16 offset,
8232 + u16 value);
8233 +
8234 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
8235 +
8236 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
8237 +
8238 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
8239 +
8240 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
8241 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
8242 +
8243 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
8244 +
8245 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
8246 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
8247 +
8248 +#endif /* BCM43xx_MAIN_H_ */
8249 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c
8250 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c 1970-01-01 01:00:00.000000000 +0100
8251 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c 2006-03-28 22:16:14.000000000 +0200
8252 @@ -0,0 +1,2347 @@
8253 +/*
8254 +
8255 + Broadcom BCM43xx wireless driver
8256 +
8257 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
8258 + Stefano Brivio <st3@riseup.net>
8259 + Michael Buesch <mbuesch@freenet.de>
8260 + Danny van Dyk <kugelfang@gentoo.org>
8261 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
8262 +
8263 + Some parts of the code in this file are derived from the ipw2200
8264 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8265 +
8266 + This program is free software; you can redistribute it and/or modify
8267 + it under the terms of the GNU General Public License as published by
8268 + the Free Software Foundation; either version 2 of the License, or
8269 + (at your option) any later version.
8270 +
8271 + This program is distributed in the hope that it will be useful,
8272 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8273 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8274 + GNU General Public License for more details.
8275 +
8276 + You should have received a copy of the GNU General Public License
8277 + along with this program; see the file COPYING. If not, write to
8278 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
8279 + Boston, MA 02110-1301, USA.
8280 +
8281 +*/
8282 +
8283 +#include <linux/delay.h>
8284 +#include <linux/pci.h>
8285 +#include <linux/types.h>
8286 +
8287 +#include "bcm43xx.h"
8288 +#include "bcm43xx_phy.h"
8289 +#include "bcm43xx_main.h"
8290 +#include "bcm43xx_radio.h"
8291 +#include "bcm43xx_ilt.h"
8292 +#include "bcm43xx_power.h"
8293 +
8294 +
8295 +static const s8 bcm43xx_tssi2dbm_b_table[] = {
8296 + 0x4D, 0x4C, 0x4B, 0x4A,
8297 + 0x4A, 0x49, 0x48, 0x47,
8298 + 0x47, 0x46, 0x45, 0x45,
8299 + 0x44, 0x43, 0x42, 0x42,
8300 + 0x41, 0x40, 0x3F, 0x3E,
8301 + 0x3D, 0x3C, 0x3B, 0x3A,
8302 + 0x39, 0x38, 0x37, 0x36,
8303 + 0x35, 0x34, 0x32, 0x31,
8304 + 0x30, 0x2F, 0x2D, 0x2C,
8305 + 0x2B, 0x29, 0x28, 0x26,
8306 + 0x25, 0x23, 0x21, 0x1F,
8307 + 0x1D, 0x1A, 0x17, 0x14,
8308 + 0x10, 0x0C, 0x06, 0x00,
8309 + -7, -7, -7, -7,
8310 + -7, -7, -7, -7,
8311 + -7, -7, -7, -7,
8312 +};
8313 +
8314 +static const s8 bcm43xx_tssi2dbm_g_table[] = {
8315 + 77, 77, 77, 76,
8316 + 76, 76, 75, 75,
8317 + 74, 74, 73, 73,
8318 + 73, 72, 72, 71,
8319 + 71, 70, 70, 69,
8320 + 68, 68, 67, 67,
8321 + 66, 65, 65, 64,
8322 + 63, 63, 62, 61,
8323 + 60, 59, 58, 57,
8324 + 56, 55, 54, 53,
8325 + 52, 50, 49, 47,
8326 + 45, 43, 40, 37,
8327 + 33, 28, 22, 14,
8328 + 5, -7, -20, -20,
8329 + -20, -20, -20, -20,
8330 + -20, -20, -20, -20,
8331 +};
8332 +
8333 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
8334 +
8335 +
8336 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
8337 +{
8338 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8339 +
8340 + assert(irqs_disabled());
8341 + if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
8342 + phy->is_locked = 0;
8343 + return;
8344 + }
8345 + if (bcm->current_core->rev < 3) {
8346 + bcm43xx_mac_suspend(bcm);
8347 + spin_lock(&phy->lock);
8348 + } else {
8349 + if (bcm->iw_mode != IW_MODE_MASTER)
8350 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
8351 + }
8352 + phy->is_locked = 1;
8353 +}
8354 +
8355 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
8356 +{
8357 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8358 +
8359 + assert(irqs_disabled());
8360 + if (bcm->current_core->rev < 3) {
8361 + if (phy->is_locked) {
8362 + spin_unlock(&phy->lock);
8363 + bcm43xx_mac_enable(bcm);
8364 + }
8365 + } else {
8366 + if (bcm->iw_mode != IW_MODE_MASTER)
8367 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
8368 + }
8369 + phy->is_locked = 0;
8370 +}
8371 +
8372 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
8373 +{
8374 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8375 + return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
8376 +}
8377 +
8378 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
8379 +{
8380 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8381 + mmiowb();
8382 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
8383 +}
8384 +
8385 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
8386 +{
8387 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8388 + unsigned long flags;
8389 +
8390 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
8391 + if (phy->calibrated)
8392 + return;
8393 + if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
8394 + /* We do not want to be preempted while calibrating
8395 + * the hardware.
8396 + */
8397 + local_irq_save(flags);
8398 +
8399 + bcm43xx_wireless_core_reset(bcm, 0);
8400 + bcm43xx_phy_initg(bcm);
8401 + bcm43xx_wireless_core_reset(bcm, 1);
8402 +
8403 + local_irq_restore(flags);
8404 + }
8405 + phy->calibrated = 1;
8406 +}
8407 +
8408 +/* Connect the PHY
8409 + * http://bcm-specs.sipsolutions.net/SetPHY
8410 + */
8411 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
8412 +{
8413 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8414 + u32 flags;
8415 +
8416 + if (bcm->current_core->rev < 5)
8417 + goto out;
8418 +
8419 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
8420 + if (connect) {
8421 + if (!(flags & 0x00010000))
8422 + return -ENODEV;
8423 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8424 + flags |= (0x800 << 18);
8425 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8426 + } else {
8427 + if (!(flags & 0x00020000))
8428 + return -ENODEV;
8429 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8430 + flags &= ~(0x800 << 18);
8431 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8432 + }
8433 +out:
8434 + phy->connected = connect;
8435 + if (connect)
8436 + dprintk(KERN_INFO PFX "PHY connected\n");
8437 + else
8438 + dprintk(KERN_INFO PFX "PHY disconnected\n");
8439 +
8440 + return 0;
8441 +}
8442 +
8443 +/* intialize B PHY power control
8444 + * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
8445 + */
8446 +static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
8447 +{
8448 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8449 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8450 + u16 saved_batt = 0, saved_ratt = 0, saved_txctl1 = 0;
8451 + int must_reset_txpower = 0;
8452 +
8453 + assert(phy->type != BCM43xx_PHYTYPE_A);
8454 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8455 + (bcm->board_type == 0x0416))
8456 + return;
8457 +
8458 + bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
8459 + bcm43xx_phy_write(bcm, 0x0028, 0x8018);
8460 +
8461 + if (phy->type == BCM43xx_PHYTYPE_G) {
8462 + if (!phy->connected)
8463 + return;
8464 + bcm43xx_phy_write(bcm, 0x047A, 0xC111);
8465 + }
8466 + if (phy->savedpctlreg != 0xFFFF)
8467 + return;
8468 +
8469 + if (phy->type == BCM43xx_PHYTYPE_B &&
8470 + phy->rev >= 2 &&
8471 + radio->version == 0x2050) {
8472 + bcm43xx_radio_write16(bcm, 0x0076,
8473 + bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
8474 + } else {
8475 + saved_batt = radio->baseband_atten;
8476 + saved_ratt = radio->radio_atten;
8477 + saved_txctl1 = radio->txctl1;
8478 + if ((radio->revision >= 6) && (radio->revision <= 8)
8479 + && /*FIXME: incomplete specs for 5 < revision < 9 */ 0)
8480 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 0x1F, 0);
8481 + else
8482 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
8483 + must_reset_txpower = 1;
8484 + }
8485 + bcm43xx_dummy_transmission(bcm);
8486 +
8487 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
8488 +
8489 + if (must_reset_txpower)
8490 + bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
8491 + else
8492 + bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
8493 + bcm43xx_radio_clear_tssi(bcm);
8494 +}
8495 +
8496 +static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
8497 +{
8498 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8499 + u16 offset = 0x0000;
8500 +
8501 + if (phy->rev == 1)
8502 + offset = 0x4C00;
8503 +
8504 + bcm43xx_ilt_write(bcm, offset, 0x00FE);
8505 + bcm43xx_ilt_write(bcm, offset + 1, 0x000D);
8506 + bcm43xx_ilt_write(bcm, offset + 2, 0x0013);
8507 + bcm43xx_ilt_write(bcm, offset + 3, 0x0019);
8508 +
8509 + if (phy->rev == 1) {
8510 + bcm43xx_ilt_write(bcm, 0x1800, 0x2710);
8511 + bcm43xx_ilt_write(bcm, 0x1801, 0x9B83);
8512 + bcm43xx_ilt_write(bcm, 0x1802, 0x9B83);
8513 + bcm43xx_ilt_write(bcm, 0x1803, 0x0F8D);
8514 + bcm43xx_phy_write(bcm, 0x0455, 0x0004);
8515 + }
8516 +
8517 + bcm43xx_phy_write(bcm, 0x04A5, (bcm43xx_phy_read(bcm, 0x04A5) & 0x00FF) | 0x5700);
8518 + bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xFF80) | 0x000F);
8519 + bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xC07F) | 0x2B80);
8520 + bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xF0FF) | 0x0300);
8521 +
8522 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
8523 +
8524 + bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xFFF0) | 0x0008);
8525 + bcm43xx_phy_write(bcm, 0x04A1, (bcm43xx_phy_read(bcm, 0x04A1) & 0xF0FF) | 0x0600);
8526 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xF0FF) | 0x0700);
8527 + bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xF0FF) | 0x0100);
8528 +
8529 + if (phy->rev == 1)
8530 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
8531 +
8532 + bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xFF00) | 0x001C);
8533 + bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xC0FF) | 0x0200);
8534 + bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0xFF00) | 0x001C);
8535 + bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xFF00) | 0x0020);
8536 + bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xC0FF) | 0x0200);
8537 + bcm43xx_phy_write(bcm, 0x0482, (bcm43xx_phy_read(bcm, 0x0482) & 0xFF00) | 0x002E);
8538 + bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0x00FF) | 0x1A00);
8539 + bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0xFF00) | 0x0028);
8540 + bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0x00FF) | 0x2C00);
8541 +
8542 + if (phy->rev == 1) {
8543 + bcm43xx_phy_write(bcm, 0x0430, 0x092B);
8544 + bcm43xx_phy_write(bcm, 0x041B, (bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1) | 0x0002);
8545 + } else {
8546 + bcm43xx_phy_write(bcm, 0x041B, bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1);
8547 + bcm43xx_phy_write(bcm, 0x041F, 0x287A);
8548 + bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0xFFF0) | 0x0004);
8549 + }
8550 +
8551 + if (phy->rev > 2) {
8552 + bcm43xx_phy_write(bcm, 0x0422, 0x287A);
8553 + bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0x0FFF) | 0x3000);
8554 + }
8555 +
8556 + bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
8557 + bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
8558 +
8559 + if (phy->rev == 1) {
8560 + bcm43xx_phy_write(bcm, 0x04AB, (bcm43xx_phy_read(bcm, 0x04AB) & 0xF0FF) | 0x0600);
8561 + bcm43xx_phy_write(bcm, 0x048B, 0x005E);
8562 + bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xFF00) | 0x001E);
8563 + bcm43xx_phy_write(bcm, 0x048D, 0x0002);
8564 + }
8565 +
8566 + bcm43xx_ilt_write(bcm, offset + 0x0800, 0);
8567 + bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
8568 + bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
8569 + bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
8570 +}
8571 +
8572 +static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
8573 +{
8574 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8575 + u16 i;
8576 +
8577 + assert(phy->type == BCM43xx_PHYTYPE_G);
8578 + if (phy->rev == 1) {
8579 + bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
8580 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
8581 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
8582 + bcm43xx_phy_write(bcm, 0x042C, 0x005A);
8583 + bcm43xx_phy_write(bcm, 0x0427, 0x001A);
8584 +
8585 + for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
8586 + bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
8587 + for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
8588 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
8589 + for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
8590 + bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
8591 + } else {
8592 + /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
8593 + bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
8594 +
8595 + if (phy->rev == 2) {
8596 + bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
8597 + bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
8598 + } else if (phy->rev > 2) {
8599 + bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
8600 + bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
8601 + bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
8602 + }
8603 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
8604 +
8605 + for (i = 0; i < 64; i++)
8606 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8607 + for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
8608 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
8609 + }
8610 +
8611 + if (phy->rev <= 2)
8612 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8613 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
8614 + else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
8615 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8616 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
8617 + else
8618 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8619 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
8620 +
8621 + if (phy->rev == 2)
8622 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8623 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
8624 + else if ((phy->rev > 2) && (phy->rev <= 7))
8625 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8626 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
8627 +
8628 + if (phy->rev == 1) {
8629 + for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
8630 + bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
8631 + for (i = 0; i < 4; i++) {
8632 + bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
8633 + bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
8634 + bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
8635 + bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
8636 + }
8637 + bcm43xx_phy_agcsetup(bcm);
8638 +
8639 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8640 + (bcm->board_type == 0x0416) &&
8641 + (bcm->board_revision == 0x0017))
8642 + return;
8643 +
8644 + bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
8645 + bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
8646 + } else {
8647 + for (i = 0; i <= 0x2F; i++)
8648 + bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
8649 + bcm43xx_phy_agcsetup(bcm);
8650 + bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
8651 + bcm43xx_phy_write(bcm, 0x0403, 0x1000);
8652 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8653 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8654 +
8655 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8656 + (bcm->board_type == 0x0416) &&
8657 + (bcm->board_revision == 0x0017))
8658 + return;
8659 +
8660 + bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
8661 + bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
8662 + }
8663 +}
8664 +
8665 +/* Initialize the noisescaletable for APHY */
8666 +static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
8667 +{
8668 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8669 + int i;
8670 +
8671 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
8672 + for (i = 0; i < 12; i++) {
8673 + if (phy->rev == 2)
8674 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
8675 + else
8676 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8677 + }
8678 + if (phy->rev == 2)
8679 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
8680 + else
8681 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
8682 + for (i = 0; i < 11; i++) {
8683 + if (phy->rev == 2)
8684 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
8685 + else
8686 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8687 + }
8688 + if (phy->rev == 2)
8689 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
8690 + else
8691 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
8692 +}
8693 +
8694 +static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
8695 +{
8696 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8697 + u16 i;
8698 +
8699 + assert(phy->type == BCM43xx_PHYTYPE_A);
8700 + switch (phy->rev) {
8701 + case 2:
8702 + bcm43xx_phy_write(bcm, 0x008E, 0x3800);
8703 + bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
8704 + bcm43xx_phy_write(bcm, 0x0036, 0x0400);
8705 +
8706 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8707 +
8708 + bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
8709 + bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
8710 + bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
8711 + bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
8712 +
8713 + bcm43xx_phy_write(bcm, 0x0024, 0x4680);
8714 + bcm43xx_phy_write(bcm, 0x0020, 0x0003);
8715 + bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
8716 + bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
8717 +
8718 + bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
8719 + bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
8720 + bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
8721 +
8722 + bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
8723 + bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
8724 + bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
8725 + bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
8726 + bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
8727 +
8728 + bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
8729 + bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
8730 + bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
8731 + bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
8732 + bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
8733 + bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
8734 + bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
8735 +
8736 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8737 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8738 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8739 +
8740 + for (i = 0; i < 16; i++)
8741 + bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
8742 +
8743 + bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
8744 + bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
8745 + bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
8746 + bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
8747 +
8748 + for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
8749 + bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
8750 + for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
8751 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
8752 + for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
8753 + bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
8754 + bcm43xx_phy_init_noisescaletbl(bcm);
8755 + for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
8756 + bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
8757 + break;
8758 + case 3:
8759 + for (i = 0; i < 64; i++)
8760 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8761 +
8762 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8763 +
8764 + bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
8765 + bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
8766 + bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
8767 +
8768 + bcm43xx_phy_write(bcm, 0x0024, 0x4680);
8769 + bcm43xx_phy_write(bcm, 0x0020, 0x0003);
8770 + bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
8771 + bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
8772 + bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
8773 +
8774 + bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
8775 + for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
8776 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
8777 + bcm43xx_phy_init_noisescaletbl(bcm);
8778 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8779 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
8780 +
8781 + bcm43xx_phy_write(bcm, 0x0003, 0x1808);
8782 +
8783 + bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
8784 + bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
8785 + bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
8786 + bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
8787 + bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
8788 +
8789 + bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
8790 + bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
8791 + bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
8792 + bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
8793 + bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
8794 + bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
8795 + bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
8796 +
8797 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8798 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8799 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8800 +
8801 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8802 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8803 + break;
8804 + default:
8805 + assert(0);
8806 + }
8807 +}
8808 +
8809 +/* Initialize APHY. This is also called for the GPHY in some cases. */
8810 +static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
8811 +{
8812 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8813 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8814 + u16 tval;
8815 +
8816 + if (phy->type == BCM43xx_PHYTYPE_A) {
8817 + bcm43xx_phy_setupa(bcm);
8818 + } else {
8819 + bcm43xx_phy_setupg(bcm);
8820 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
8821 + bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
8822 + return;
8823 + }
8824 +
8825 + bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
8826 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
8827 + bcm43xx_phy_write(bcm, 0x0034, 0x0001);
8828 +
8829 + TODO();//TODO: RSSI AGC
8830 + bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
8831 + bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
8832 + bcm43xx_radio_init2060(bcm);
8833 +
8834 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
8835 + && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
8836 + if (radio->lofcal == 0xFFFF) {
8837 + TODO();//TODO: LOF Cal
8838 + bcm43xx_radio_set_tx_iq(bcm);
8839 + } else
8840 + bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
8841 + }
8842 +
8843 + bcm43xx_phy_write(bcm, 0x007A, 0xF111);
8844 +
8845 + if (phy->savedpctlreg == 0xFFFF) {
8846 + bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
8847 + bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
8848 +
8849 + tval = bcm43xx_ilt_read(bcm, 0x3001);
8850 + if (phy->rev == 1) {
8851 + bcm43xx_ilt_write(bcm, 0x3001,
8852 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
8853 + | 0x0058);
8854 + } else {
8855 + bcm43xx_ilt_write(bcm, 0x3001,
8856 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
8857 + | 0x002C);
8858 + }
8859 + bcm43xx_dummy_transmission(bcm);
8860 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
8861 + bcm43xx_ilt_write(bcm, 0x3001, tval);
8862 +
8863 + bcm43xx_radio_set_txpower_a(bcm, 0x0018);
8864 + }
8865 + bcm43xx_radio_clear_tssi(bcm);
8866 +}
8867 +
8868 +static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
8869 +{
8870 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8871 + u16 offset, val;
8872 +
8873 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
8874 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
8875 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
8876 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
8877 + bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
8878 + val = 0x3C3D;
8879 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8880 + bcm43xx_phy_write(bcm, offset, val);
8881 + val -= 0x0202;
8882 + }
8883 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8884 + if (radio->channel == 0xFF)
8885 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
8886 + else
8887 + bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
8888 + if (radio->version != 0x2050) {
8889 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
8890 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
8891 + }
8892 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
8893 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
8894 + if (radio->version == 0x2050) {
8895 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
8896 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
8897 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
8898 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
8899 + bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
8900 + bcm43xx_phy_write(bcm, 0x0038, 0x0677);
8901 + bcm43xx_radio_init2050(bcm);
8902 + }
8903 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
8904 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
8905 + bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
8906 + bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
8907 + bcm43xx_phy_lo_b_measure(bcm);
8908 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
8909 + if (radio->version != 0x2050)
8910 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
8911 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
8912 + bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
8913 + if (radio->version != 0x2050)
8914 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
8915 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
8916 + bcm43xx_phy_init_pctl(bcm);
8917 +}
8918 +
8919 +static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
8920 +{
8921 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8922 + u16 offset, val;
8923 +
8924 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
8925 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
8926 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
8927 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
8928 + bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
8929 + val = 0x3C3D;
8930 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8931 + bcm43xx_phy_write(bcm, offset, val);
8932 + val -= 0x0202;
8933 + }
8934 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8935 + if (radio->channel == 0xFF)
8936 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
8937 + else
8938 + bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
8939 + if (radio->version != 0x2050) {
8940 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
8941 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
8942 + }
8943 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
8944 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
8945 + if (radio->version == 0x2050) {
8946 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
8947 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
8948 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
8949 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
8950 + bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
8951 + bcm43xx_phy_write(bcm, 0x0038, 0x0677);
8952 + bcm43xx_radio_init2050(bcm);
8953 + }
8954 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
8955 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
8956 + if (radio->version == 0x2050)
8957 + bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
8958 + bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
8959 +
8960 + bcm43xx_phy_lo_b_measure(bcm);
8961 +
8962 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
8963 + if (radio->version == 0x2050)
8964 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
8965 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
8966 + bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
8967 + if (radio->version == 0x2050)
8968 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
8969 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
8970 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
8971 + bcm43xx_calc_nrssi_slope(bcm);
8972 + bcm43xx_calc_nrssi_threshold(bcm);
8973 + }
8974 + bcm43xx_phy_init_pctl(bcm);
8975 +}
8976 +
8977 +static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
8978 +{
8979 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8980 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8981 + u16 offset;
8982 +
8983 + if (phy->version == 1 &&
8984 + radio->version == 0x2050) {
8985 + bcm43xx_radio_write16(bcm, 0x007A,
8986 + bcm43xx_radio_read16(bcm, 0x007A)
8987 + | 0x0050);
8988 + }
8989 + if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
8990 + (bcm->board_type != 0x0416)) {
8991 + for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
8992 + bcm43xx_phy_write(bcm, offset,
8993 + (bcm43xx_phy_read(bcm, offset) + 0x2020)
8994 + & 0x3F3F);
8995 + }
8996 + }
8997 + bcm43xx_phy_write(bcm, 0x0035,
8998 + (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
8999 + | 0x0700);
9000 + if (radio->version == 0x2050)
9001 + bcm43xx_phy_write(bcm, 0x0038, 0x0667);
9002 +
9003 + if (phy->connected) {
9004 + if (radio->version == 0x2050) {
9005 + bcm43xx_radio_write16(bcm, 0x007A,
9006 + bcm43xx_radio_read16(bcm, 0x007A)
9007 + | 0x0020);
9008 + bcm43xx_radio_write16(bcm, 0x0051,
9009 + bcm43xx_radio_read16(bcm, 0x0051)
9010 + | 0x0004);
9011 + }
9012 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
9013 +
9014 + bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9015 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9016 +
9017 + bcm43xx_phy_write(bcm, 0x001C, 0x186A);
9018 +
9019 + bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
9020 + bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
9021 + bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
9022 + }
9023 +
9024 + if (bcm->bad_frames_preempt) {
9025 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
9026 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
9027 + }
9028 +
9029 + if (phy->version == 1 && radio->version == 0x2050) {
9030 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
9031 + bcm43xx_phy_write(bcm, 0x0021, 0x3763);
9032 + bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
9033 + bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
9034 + bcm43xx_phy_write(bcm, 0x0024, 0x037E);
9035 + } else
9036 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9037 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
9038 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
9039 +
9040 + if (phy->version == 1 && radio->version == 0x2050)
9041 + bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
9042 + else
9043 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
9044 +
9045 + if (phy->version == 0)
9046 + bcm43xx_write16(bcm, 0x03E4, 0x3000);
9047 +
9048 + /* Force to channel 7, even if not supported. */
9049 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9050 +
9051 + if (radio->version != 0x2050) {
9052 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
9053 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
9054 + }
9055 +
9056 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9057 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9058 +
9059 + if (radio->version == 0x2050) {
9060 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9061 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9062 + }
9063 +
9064 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9065 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9066 +
9067 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
9068 +
9069 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9070 +
9071 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9072 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9073 + bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
9074 +
9075 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9076 +
9077 + if (radio->version == 0x2050)
9078 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9079 +
9080 + bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
9081 +}
9082 +
9083 +static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
9084 +{
9085 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9086 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9087 + u16 offset, val;
9088 +
9089 + bcm43xx_phy_write(bcm, 0x003E, 0x817A);
9090 + bcm43xx_radio_write16(bcm, 0x007A,
9091 + (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
9092 + if ((radio->manufact == 0x17F) &&
9093 + (radio->version == 0x2050) &&
9094 + (radio->revision == 3 ||
9095 + radio->revision == 4 ||
9096 + radio->revision == 5)) {
9097 + bcm43xx_radio_write16(bcm, 0x0051, 0x001F);
9098 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9099 + bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
9100 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9101 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9102 + bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
9103 + bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
9104 + bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
9105 + bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
9106 + }
9107 + if ((radio->manufact == 0x17F) &&
9108 + (radio->version == 0x2050) &&
9109 + (radio->revision == 6)) {
9110 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9111 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9112 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9113 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9114 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9115 + bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
9116 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
9117 + bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
9118 + bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
9119 + bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
9120 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9121 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9122 + }
9123 + if ((radio->manufact == 0x17F) &&
9124 + (radio->version == 0x2050) &&
9125 + (radio->revision == 7)) {
9126 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9127 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9128 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9129 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9130 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9131 + bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
9132 + bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
9133 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9134 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
9135 + bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
9136 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9137 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9138 + bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
9139 + }
9140 + if ((radio->manufact == 0x17F) &&
9141 + (radio->version == 0x2050) &&
9142 + (radio->revision == 8)) {
9143 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9144 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9145 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9146 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9147 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9148 + bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
9149 + bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
9150 + if (bcm->sprom.boardflags & 0x8000) {
9151 + bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
9152 + bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
9153 + } else {
9154 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9155 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
9156 + }
9157 + bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
9158 + bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
9159 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9160 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9161 + }
9162 + val = 0x1E1F;
9163 + for (offset = 0x0088; offset < 0x0098; offset++) {
9164 + bcm43xx_phy_write(bcm, offset, val);
9165 + val -= 0x0202;
9166 + }
9167 + val = 0x3E3F;
9168 + for (offset = 0x0098; offset < 0x00A8; offset++) {
9169 + bcm43xx_phy_write(bcm, offset, val);
9170 + val -= 0x0202;
9171 + }
9172 + val = 0x2120;
9173 + for (offset = 0x00A8; offset < 0x00C8; offset++) {
9174 + bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
9175 + val += 0x0202;
9176 + }
9177 + if (phy->type == BCM43xx_PHYTYPE_G) {
9178 + bcm43xx_radio_write16(bcm, 0x007A,
9179 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
9180 + bcm43xx_radio_write16(bcm, 0x0051,
9181 + bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
9182 + bcm43xx_phy_write(bcm, 0x0802,
9183 + bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9184 + bcm43xx_phy_write(bcm, 0x042B,
9185 + bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9186 + }
9187 +
9188 + /* Force to channel 7, even if not supported. */
9189 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9190 +
9191 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9192 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9193 + udelay(40);
9194 + bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002));
9195 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9196 + if (radio->manufact == 0x17F &&
9197 + radio->version == 0x2050 &&
9198 + radio->revision <= 2) {
9199 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9200 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9201 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9202 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9203 + }
9204 + bcm43xx_radio_write16(bcm, 0x007A,
9205 + (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
9206 +
9207 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9208 +
9209 + bcm43xx_phy_write(bcm, 0x0014, 0x0200);
9210 + if (radio->version == 0x2050){
9211 + if (radio->revision == 3 ||
9212 + radio->revision == 4 ||
9213 + radio->revision == 5)
9214 + bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
9215 + else
9216 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
9217 + }
9218 + bcm43xx_phy_write(bcm, 0x0038, 0x0668);
9219 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9220 + if (radio->version == 0x2050) {
9221 + if (radio->revision == 3 ||
9222 + radio->revision == 4 ||
9223 + radio->revision == 5)
9224 + bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
9225 + else if (radio->revision <= 2)
9226 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9227 + }
9228 +
9229 + if (phy->rev == 4)
9230 + bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
9231 + else
9232 + bcm43xx_write16(bcm, 0x03E4, 0x0009);
9233 + if (phy->type == BCM43xx_PHYTYPE_B) {
9234 + bcm43xx_write16(bcm, 0x03E6, 0x8140);
9235 + bcm43xx_phy_write(bcm, 0x0016, 0x0410);
9236 + bcm43xx_phy_write(bcm, 0x0017, 0x0820);
9237 + bcm43xx_phy_write(bcm, 0x0062, 0x0007);
9238 + (void) bcm43xx_radio_calibrationvalue(bcm);
9239 + bcm43xx_phy_lo_b_measure(bcm);
9240 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
9241 + bcm43xx_calc_nrssi_slope(bcm);
9242 + bcm43xx_calc_nrssi_threshold(bcm);
9243 + }
9244 + bcm43xx_phy_init_pctl(bcm);
9245 + } else
9246 + bcm43xx_write16(bcm, 0x03E6, 0x0);
9247 +}
9248 +
9249 +static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
9250 +{
9251 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9252 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9253 + u16 backup_phy[15];
9254 + u16 backup_radio[3];
9255 + u16 backup_bband;
9256 + u16 i;
9257 + u16 loop1_cnt, loop1_done, loop1_omitted;
9258 + u16 loop2_done;
9259 +
9260 + backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
9261 + backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
9262 + backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
9263 + backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
9264 + backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
9265 + backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
9266 + backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
9267 + backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
9268 + backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
9269 + backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
9270 + backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
9271 + backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
9272 + backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
9273 + backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
9274 + backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
9275 + bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
9276 + backup_bband = radio->baseband_atten;
9277 + backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
9278 + backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
9279 + backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
9280 +
9281 + bcm43xx_phy_write(bcm, 0x0429,
9282 + bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
9283 + bcm43xx_phy_write(bcm, 0x0001,
9284 + bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
9285 + bcm43xx_phy_write(bcm, 0x0811,
9286 + bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
9287 + bcm43xx_phy_write(bcm, 0x0812,
9288 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
9289 + bcm43xx_phy_write(bcm, 0x0811,
9290 + bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
9291 + bcm43xx_phy_write(bcm, 0x0812,
9292 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
9293 + bcm43xx_phy_write(bcm, 0x0814,
9294 + bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
9295 + bcm43xx_phy_write(bcm, 0x0815,
9296 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
9297 + bcm43xx_phy_write(bcm, 0x0814,
9298 + bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
9299 + bcm43xx_phy_write(bcm, 0x0815,
9300 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
9301 + bcm43xx_phy_write(bcm, 0x0811,
9302 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
9303 + bcm43xx_phy_write(bcm, 0x0812,
9304 + bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
9305 +
9306 + bcm43xx_phy_write(bcm, 0x0811,
9307 + (bcm43xx_phy_read(bcm, 0x0811)
9308 + & 0xFFCF) | 0x0030);
9309 + bcm43xx_phy_write(bcm, 0x0812,
9310 + (bcm43xx_phy_read(bcm, 0x0812)
9311 + & 0xFFCF) | 0x0010);
9312 +
9313 + bcm43xx_phy_write(bcm, 0x005A, 0x0780);
9314 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
9315 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
9316 + if (phy->version == 0) {
9317 + bcm43xx_phy_write(bcm, 0x0003, 0x0122);
9318 + } else {
9319 + bcm43xx_phy_write(bcm, 0x000A,
9320 + bcm43xx_phy_read(bcm, 0x000A)
9321 + | 0x2000);
9322 + }
9323 + bcm43xx_phy_write(bcm, 0x0814,
9324 + bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
9325 + bcm43xx_phy_write(bcm, 0x0815,
9326 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
9327 + bcm43xx_phy_write(bcm, 0x0003,
9328 + (bcm43xx_phy_read(bcm, 0x0003)
9329 + & 0xFF9F) | 0x0040);
9330 + if (radio->version == 0x2050 && radio->revision == 2) {
9331 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9332 + bcm43xx_radio_write16(bcm, 0x0043,
9333 + (bcm43xx_radio_read16(bcm, 0x0043)
9334 + & 0xFFF0) | 0x0009);
9335 + loop1_cnt = 9;
9336 + } else if (radio->revision == 8) {
9337 + bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
9338 + loop1_cnt = 15;
9339 + } else
9340 + loop1_cnt = 0;
9341 +
9342 + bcm43xx_phy_set_baseband_attenuation(bcm, 11);
9343 +
9344 + if (phy->rev >= 3)
9345 + bcm43xx_phy_write(bcm, 0x080F, 0xC020);
9346 + else
9347 + bcm43xx_phy_write(bcm, 0x080F, 0x8020);
9348 + bcm43xx_phy_write(bcm, 0x0810, 0x0000);
9349 +
9350 + bcm43xx_phy_write(bcm, 0x002B,
9351 + (bcm43xx_phy_read(bcm, 0x002B)
9352 + & 0xFFC0) | 0x0001);
9353 + bcm43xx_phy_write(bcm, 0x002B,
9354 + (bcm43xx_phy_read(bcm, 0x002B)
9355 + & 0xC0FF) | 0x0800);
9356 + bcm43xx_phy_write(bcm, 0x0811,
9357 + bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
9358 + bcm43xx_phy_write(bcm, 0x0812,
9359 + bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
9360 + if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
9361 + if (phy->rev >= 7) {
9362 + bcm43xx_phy_write(bcm, 0x0811,
9363 + bcm43xx_phy_read(bcm, 0x0811)
9364 + | 0x0800);
9365 + bcm43xx_phy_write(bcm, 0x0812,
9366 + bcm43xx_phy_read(bcm, 0x0812)
9367 + | 0x8000);
9368 + }
9369 + }
9370 + bcm43xx_radio_write16(bcm, 0x007A,
9371 + bcm43xx_radio_read16(bcm, 0x007A)
9372 + & 0x00F7);
9373 +
9374 + for (i = 0; i < loop1_cnt; i++) {
9375 + bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
9376 + bcm43xx_phy_write(bcm, 0x0812,
9377 + (bcm43xx_phy_read(bcm, 0x0812)
9378 + & 0xF0FF) | (i << 8));
9379 + bcm43xx_phy_write(bcm, 0x0015,
9380 + (bcm43xx_phy_read(bcm, 0x0015)
9381 + & 0x0FFF) | 0xA000);
9382 + bcm43xx_phy_write(bcm, 0x0015,
9383 + (bcm43xx_phy_read(bcm, 0x0015)
9384 + & 0x0FFF) | 0xF000);
9385 + udelay(20);
9386 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9387 + break;
9388 + }
9389 + loop1_done = i;
9390 + loop1_omitted = loop1_cnt - loop1_done;
9391 +
9392 + loop2_done = 0;
9393 + if (loop1_done >= 8) {
9394 + bcm43xx_phy_write(bcm, 0x0812,
9395 + bcm43xx_phy_read(bcm, 0x0812)
9396 + | 0x0030);
9397 + for (i = loop1_done - 8; i < 16; i++) {
9398 + bcm43xx_phy_write(bcm, 0x0812,
9399 + (bcm43xx_phy_read(bcm, 0x0812)
9400 + & 0xF0FF) | (i << 8));
9401 + bcm43xx_phy_write(bcm, 0x0015,
9402 + (bcm43xx_phy_read(bcm, 0x0015)
9403 + & 0x0FFF) | 0xA000);
9404 + bcm43xx_phy_write(bcm, 0x0015,
9405 + (bcm43xx_phy_read(bcm, 0x0015)
9406 + & 0x0FFF) | 0xF000);
9407 + udelay(20);
9408 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9409 + break;
9410 + }
9411 + }
9412 +
9413 + bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
9414 + bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
9415 + bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
9416 + bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
9417 + bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
9418 + bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
9419 + bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
9420 + bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
9421 + bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
9422 + bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
9423 + bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
9424 +
9425 + bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
9426 +
9427 + bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
9428 + bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
9429 + bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
9430 +
9431 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
9432 + udelay(10);
9433 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
9434 + bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
9435 + bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
9436 + bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
9437 +
9438 + phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
9439 + phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
9440 +}
9441 +
9442 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
9443 +{
9444 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9445 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9446 + u16 tmp;
9447 +
9448 + if (phy->rev == 1)
9449 + bcm43xx_phy_initb5(bcm);
9450 + else if (phy->rev >= 2 && phy->rev <= 7)
9451 + bcm43xx_phy_initb6(bcm);
9452 + if (phy->rev >= 2 || phy->connected)
9453 + bcm43xx_phy_inita(bcm);
9454 +
9455 + if (phy->rev >= 2) {
9456 + bcm43xx_phy_write(bcm, 0x0814, 0x0000);
9457 + bcm43xx_phy_write(bcm, 0x0815, 0x0000);
9458 + if (phy->rev == 2)
9459 + bcm43xx_phy_write(bcm, 0x0811, 0x0000);
9460 + else if (phy->rev >= 3)
9461 + bcm43xx_phy_write(bcm, 0x0811, 0x0400);
9462 + bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
9463 + if (phy->connected) {
9464 + tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
9465 + if (tmp < 6) {
9466 + bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
9467 + bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
9468 + if (tmp != 3) {
9469 + bcm43xx_phy_write(bcm, 0x04CC,
9470 + (bcm43xx_phy_read(bcm, 0x04CC)
9471 + & 0x00FF) | 0x1F00);
9472 + }
9473 + }
9474 + }
9475 + }
9476 + if (phy->rev < 3 && phy->connected)
9477 + bcm43xx_phy_write(bcm, 0x047E, 0x0078);
9478 + if (phy->rev >= 6 && phy->rev <= 8) {
9479 + bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
9480 + bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
9481 + }
9482 + if (phy->rev >= 2 && phy->connected)
9483 + bcm43xx_calc_loopback_gain(bcm);
9484 + if (radio->revision != 8) {
9485 + if (radio->initval == 0xFFFF)
9486 + radio->initval = bcm43xx_radio_init2050(bcm);
9487 + else
9488 + bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
9489 + }
9490 + if (radio->txctl2 == 0xFFFF) {
9491 + bcm43xx_phy_lo_g_measure(bcm);
9492 + } else {
9493 + if (radio->version == 0x2050 && radio->revision == 8) {
9494 + //FIXME
9495 + } else {
9496 + bcm43xx_radio_write16(bcm, 0x0052,
9497 + (bcm43xx_radio_read16(bcm, 0x0052)
9498 + & 0xFFF0) | radio->txctl1);
9499 + }
9500 + if (phy->rev >= 6) {
9501 + /*
9502 + bcm43xx_phy_write(bcm, 0x0036,
9503 + (bcm43xx_phy_read(bcm, 0x0036)
9504 + & 0xF000) | (FIXME << 12));
9505 + */
9506 + }
9507 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
9508 + bcm43xx_phy_write(bcm, 0x002E, 0x8075);
9509 + else
9510 + bcm43xx_phy_write(bcm, 0x003E, 0x807F);
9511 + if (phy->rev < 2)
9512 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
9513 + else
9514 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
9515 + }
9516 + if (phy->connected) {
9517 + bcm43xx_phy_lo_adjust(bcm, 0);
9518 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
9519 + }
9520 +
9521 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
9522 + /* The specs state to update the NRSSI LT with
9523 + * the value 0x7FFFFFFF here. I think that is some weird
9524 + * compiler optimization in the original driver.
9525 + * Essentially, what we do here is resetting all NRSSI LT
9526 + * entries to -32 (see the limit_value() in nrssi_hw_update())
9527 + */
9528 + bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
9529 + bcm43xx_calc_nrssi_threshold(bcm);
9530 + } else if (phy->connected) {
9531 + if (radio->nrssi[0] == -1000) {
9532 + assert(radio->nrssi[1] == -1000);
9533 + bcm43xx_calc_nrssi_slope(bcm);
9534 + } else {
9535 + assert(radio->nrssi[1] != -1000);
9536 + bcm43xx_calc_nrssi_threshold(bcm);
9537 + }
9538 + }
9539 + if (radio->revision == 8)
9540 + bcm43xx_phy_write(bcm, 0x0805, 0x3230);
9541 + bcm43xx_phy_init_pctl(bcm);
9542 + if (bcm->chip_id == 0x4306 && bcm->chip_package != 2) {
9543 + bcm43xx_phy_write(bcm, 0x0429,
9544 + bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
9545 + bcm43xx_phy_write(bcm, 0x04C3,
9546 + bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
9547 + }
9548 +}
9549 +
9550 +static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
9551 +{
9552 + int i;
9553 + u16 ret = 0;
9554 +
9555 + for (i = 0; i < 10; i++){
9556 + bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
9557 + udelay(1);
9558 + bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
9559 + udelay(10);
9560 + bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
9561 + udelay(40);
9562 + ret += bcm43xx_phy_read(bcm, 0x002C);
9563 + }
9564 +
9565 + return ret;
9566 +}
9567 +
9568 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
9569 +{
9570 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9571 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9572 + u16 regstack[12] = { 0 };
9573 + u16 mls;
9574 + u16 fval;
9575 + int i, j;
9576 +
9577 + regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
9578 + regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
9579 +
9580 + if (radio->version == 0x2053) {
9581 + regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
9582 + regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
9583 + regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
9584 + regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
9585 + regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
9586 + regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
9587 +
9588 + regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
9589 + regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
9590 + regstack[10] = bcm43xx_read16(bcm, 0x03EC);
9591 + regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
9592 +
9593 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
9594 + bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
9595 + bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
9596 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
9597 + }
9598 + bcm43xx_phy_write(bcm, 0x0015, 0xB000);
9599 + bcm43xx_phy_write(bcm, 0x002B, 0x0004);
9600 +
9601 + if (radio->version == 0x2053) {
9602 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
9603 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
9604 + }
9605 +
9606 + phy->minlowsig[0] = 0xFFFF;
9607 +
9608 + for (i = 0; i < 4; i++) {
9609 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9610 + bcm43xx_phy_lo_b_r15_loop(bcm);
9611 + }
9612 + for (i = 0; i < 10; i++) {
9613 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9614 + mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
9615 + if (mls < phy->minlowsig[0]) {
9616 + phy->minlowsig[0] = mls;
9617 + phy->minlowsigpos[0] = i;
9618 + }
9619 + }
9620 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
9621 +
9622 + phy->minlowsig[1] = 0xFFFF;
9623 +
9624 + for (i = -4; i < 5; i += 2) {
9625 + for (j = -4; j < 5; j += 2) {
9626 + if (j < 0)
9627 + fval = (0x0100 * i) + j + 0x0100;
9628 + else
9629 + fval = (0x0100 * i) + j;
9630 + bcm43xx_phy_write(bcm, 0x002F, fval);
9631 + mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
9632 + if (mls < phy->minlowsig[1]) {
9633 + phy->minlowsig[1] = mls;
9634 + phy->minlowsigpos[1] = fval;
9635 + }
9636 + }
9637 + }
9638 + phy->minlowsigpos[1] += 0x0101;
9639 +
9640 + bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
9641 + if (radio->version == 0x2053) {
9642 + bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
9643 + bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
9644 + bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
9645 + bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
9646 + bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
9647 + bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
9648 +
9649 + bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
9650 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
9651 +
9652 + bcm43xx_radio_write16(bcm, 0x0052,
9653 + (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
9654 + | regstack[11]);
9655 +
9656 + bcm43xx_write16(bcm, 0x03EC, regstack[10]);
9657 + }
9658 + bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
9659 +}
9660 +
9661 +static inline
9662 +u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
9663 +{
9664 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9665 +
9666 + if (phy->connected) {
9667 + bcm43xx_phy_write(bcm, 0x15, 0xE300);
9668 + control <<= 8;
9669 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
9670 + udelay(5);
9671 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
9672 + udelay(2);
9673 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
9674 + udelay(4);
9675 + bcm43xx_phy_write(bcm, 0x0015, 0xF300);
9676 + udelay(8);
9677 + } else {
9678 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
9679 + udelay(2);
9680 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
9681 + udelay(4);
9682 + bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
9683 + udelay(8);
9684 + }
9685 +
9686 + return bcm43xx_phy_read(bcm, 0x002D);
9687 +}
9688 +
9689 +static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
9690 +{
9691 + int i;
9692 + u32 ret = 0;
9693 +
9694 + for (i = 0; i < 8; i++)
9695 + ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
9696 +
9697 + return ret;
9698 +}
9699 +
9700 +/* Write the LocalOscillator CONTROL */
9701 +static inline
9702 +void bcm43xx_lo_write(struct bcm43xx_private *bcm,
9703 + struct bcm43xx_lopair *pair)
9704 +{
9705 + u16 value;
9706 +
9707 + value = (u8)(pair->low);
9708 + value |= ((u8)(pair->high)) << 8;
9709 +
9710 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
9711 + /* Sanity check. */
9712 + if (pair->low < -8 || pair->low > 8 ||
9713 + pair->high < -8 || pair->high > 8) {
9714 + printk(KERN_WARNING PFX
9715 + "WARNING: Writing invalid LOpair "
9716 + "(low: %d, high: %d, index: %lu)\n",
9717 + pair->low, pair->high,
9718 + (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
9719 + dump_stack();
9720 + }
9721 +#endif
9722 +
9723 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
9724 +}
9725 +
9726 +static inline
9727 +struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
9728 + u16 baseband_attenuation,
9729 + u16 radio_attenuation,
9730 + u16 tx)
9731 +{
9732 + static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
9733 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9734 +
9735 + if (baseband_attenuation > 6)
9736 + baseband_attenuation = 6;
9737 + assert(radio_attenuation < 10);
9738 +
9739 + if (tx == 3) {
9740 + return bcm43xx_get_lopair(phy,
9741 + radio_attenuation,
9742 + baseband_attenuation);
9743 + }
9744 + return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
9745 +}
9746 +
9747 +static inline
9748 +struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
9749 +{
9750 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9751 +
9752 + return bcm43xx_find_lopair(bcm,
9753 + radio->baseband_atten,
9754 + radio->radio_atten,
9755 + radio->txctl1);
9756 +}
9757 +
9758 +/* Adjust B/G LO */
9759 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
9760 +{
9761 + struct bcm43xx_lopair *pair;
9762 +
9763 + if (fixed) {
9764 + /* Use fixed values. Only for initialization. */
9765 + pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
9766 + } else
9767 + pair = bcm43xx_current_lopair(bcm);
9768 + bcm43xx_lo_write(bcm, pair);
9769 +}
9770 +
9771 +static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
9772 +{
9773 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9774 + u16 txctl2 = 0, i;
9775 + u32 smallest, tmp;
9776 +
9777 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9778 + udelay(10);
9779 + smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9780 + for (i = 0; i < 16; i++) {
9781 + bcm43xx_radio_write16(bcm, 0x0052, i);
9782 + udelay(10);
9783 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9784 + if (tmp < smallest) {
9785 + smallest = tmp;
9786 + txctl2 = i;
9787 + }
9788 + }
9789 + radio->txctl2 = txctl2;
9790 +}
9791 +
9792 +static
9793 +void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
9794 + const struct bcm43xx_lopair *in_pair,
9795 + struct bcm43xx_lopair *out_pair,
9796 + u16 r27)
9797 +{
9798 + static const struct bcm43xx_lopair transitions[8] = {
9799 + { .high = 1, .low = 1, },
9800 + { .high = 1, .low = 0, },
9801 + { .high = 1, .low = -1, },
9802 + { .high = 0, .low = -1, },
9803 + { .high = -1, .low = -1, },
9804 + { .high = -1, .low = 0, },
9805 + { .high = -1, .low = 1, },
9806 + { .high = 0, .low = 1, },
9807 + };
9808 + struct bcm43xx_lopair lowest_transition = {
9809 + .high = in_pair->high,
9810 + .low = in_pair->low,
9811 + };
9812 + struct bcm43xx_lopair tmp_pair;
9813 + struct bcm43xx_lopair transition;
9814 + int i = 12;
9815 + int state = 0;
9816 + int found_lower;
9817 + int j, begin, end;
9818 + u32 lowest_deviation;
9819 + u32 tmp;
9820 +
9821 + /* Note that in_pair and out_pair can point to the same pair. Be careful. */
9822 +
9823 + bcm43xx_lo_write(bcm, &lowest_transition);
9824 + lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9825 + do {
9826 + found_lower = 0;
9827 + assert(state >= 0 && state <= 8);
9828 + if (state == 0) {
9829 + begin = 1;
9830 + end = 8;
9831 + } else if (state % 2 == 0) {
9832 + begin = state - 1;
9833 + end = state + 1;
9834 + } else {
9835 + begin = state - 2;
9836 + end = state + 2;
9837 + }
9838 + if (begin < 1)
9839 + begin += 8;
9840 + if (end > 8)
9841 + end -= 8;
9842 +
9843 + j = begin;
9844 + tmp_pair.high = lowest_transition.high;
9845 + tmp_pair.low = lowest_transition.low;
9846 + while (1) {
9847 + assert(j >= 1 && j <= 8);
9848 + transition.high = tmp_pair.high + transitions[j - 1].high;
9849 + transition.low = tmp_pair.low + transitions[j - 1].low;
9850 + if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
9851 + bcm43xx_lo_write(bcm, &transition);
9852 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9853 + if (tmp < lowest_deviation) {
9854 + lowest_deviation = tmp;
9855 + state = j;
9856 + found_lower = 1;
9857 +
9858 + lowest_transition.high = transition.high;
9859 + lowest_transition.low = transition.low;
9860 + }
9861 + }
9862 + if (j == end)
9863 + break;
9864 + if (j == 8)
9865 + j = 1;
9866 + else
9867 + j++;
9868 + }
9869 + } while (i-- && found_lower);
9870 +
9871 + out_pair->high = lowest_transition.high;
9872 + out_pair->low = lowest_transition.low;
9873 +}
9874 +
9875 +/* Set the baseband attenuation value on chip. */
9876 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
9877 + u16 baseband_attenuation)
9878 +{
9879 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9880 + u16 value;
9881 +
9882 + if (phy->version == 0) {
9883 + value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
9884 + value |= (baseband_attenuation & 0x000F);
9885 + bcm43xx_write16(bcm, 0x03E6, value);
9886 + return;
9887 + }
9888 +
9889 + if (phy->version > 1) {
9890 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
9891 + value |= (baseband_attenuation << 2) & 0x003C;
9892 + } else {
9893 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
9894 + value |= (baseband_attenuation << 3) & 0x0078;
9895 + }
9896 + bcm43xx_phy_write(bcm, 0x0060, value);
9897 +}
9898 +
9899 +/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
9900 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
9901 +{
9902 + static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
9903 + const int is_initializing = bcm43xx_is_initializing(bcm);
9904 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9905 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9906 + u16 h, i, oldi = 0, j;
9907 + struct bcm43xx_lopair control;
9908 + struct bcm43xx_lopair *tmp_control;
9909 + u16 tmp;
9910 + u16 regstack[16] = { 0 };
9911 + u8 oldchannel;
9912 +
9913 + //XXX: What are these?
9914 + u8 r27 = 0, r31;
9915 +
9916 + oldchannel = radio->channel;
9917 + /* Setup */
9918 + if (phy->connected) {
9919 + regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
9920 + regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
9921 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
9922 + bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
9923 + }
9924 + regstack[3] = bcm43xx_read16(bcm, 0x03E2);
9925 + bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
9926 + regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
9927 + regstack[5] = bcm43xx_phy_read(bcm, 0x15);
9928 + regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
9929 + regstack[7] = bcm43xx_phy_read(bcm, 0x35);
9930 + regstack[8] = bcm43xx_phy_read(bcm, 0x60);
9931 + regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
9932 + regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
9933 + regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
9934 + if (phy->connected) {
9935 + regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
9936 + regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
9937 + regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
9938 + regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
9939 + }
9940 + bcm43xx_radio_selectchannel(bcm, 6, 0);
9941 + if (phy->connected) {
9942 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
9943 + bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
9944 + bcm43xx_dummy_transmission(bcm);
9945 + }
9946 + bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
9947 +
9948 + bcm43xx_phy_set_baseband_attenuation(bcm, 2);
9949 +
9950 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
9951 + bcm43xx_phy_write(bcm, 0x002E, 0x007F);
9952 + bcm43xx_phy_write(bcm, 0x080F, 0x0078);
9953 + bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
9954 + bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
9955 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
9956 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
9957 + if (phy->connected) {
9958 + bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
9959 + bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
9960 + bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
9961 + bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
9962 + }
9963 + if (is_initializing)
9964 + bcm43xx_phy_lo_g_measure_txctl2(bcm);
9965 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
9966 +
9967 + /* Measure */
9968 + control.low = 0;
9969 + control.high = 0;
9970 + for (h = 0; h < 10; h++) {
9971 + /* Loop over each possible RadioAttenuation (0-9) */
9972 + i = pairorder[h];
9973 + if (is_initializing) {
9974 + if (i == 3) {
9975 + control.low = 0;
9976 + control.high = 0;
9977 + } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
9978 + ((i % 2 == 0) && (oldi % 2 == 0))) {
9979 + tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
9980 + memcpy(&control, tmp_control, sizeof(control));
9981 + } else {
9982 + tmp_control = bcm43xx_get_lopair(phy, 3, 0);
9983 + memcpy(&control, tmp_control, sizeof(control));
9984 + }
9985 + }
9986 + /* Loop over each possible BasebandAttenuation/2 */
9987 + for (j = 0; j < 4; j++) {
9988 + if (is_initializing) {
9989 + tmp = i * 2 + j;
9990 + r27 = 0;
9991 + r31 = 0;
9992 + if (tmp > 14) {
9993 + r31 = 1;
9994 + if (tmp > 17)
9995 + r27 = 1;
9996 + if (tmp > 19)
9997 + r27 = 2;
9998 + }
9999 + } else {
10000 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10001 + if (!tmp_control->used)
10002 + continue;
10003 + memcpy(&control, tmp_control, sizeof(control));
10004 + r27 = 3;
10005 + r31 = 0;
10006 + }
10007 + bcm43xx_radio_write16(bcm, 0x43, i);
10008 + bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
10009 + udelay(10);
10010 +
10011 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10012 +
10013 + tmp = (regstack[10] & 0xFFF0);
10014 + if (r31)
10015 + tmp |= 0x0008;
10016 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
10017 +
10018 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10019 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10020 + }
10021 + oldi = i;
10022 + }
10023 + /* Loop over each possible RadioAttenuation (10-13) */
10024 + for (i = 10; i < 14; i++) {
10025 + /* Loop over each possible BasebandAttenuation/2 */
10026 + for (j = 0; j < 4; j++) {
10027 + if (is_initializing) {
10028 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10029 + memcpy(&control, tmp_control, sizeof(control));
10030 + tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
10031 + r27 = 0;
10032 + r31 = 0;
10033 + if (tmp > 14) {
10034 + r31 = 1;
10035 + if (tmp > 17)
10036 + r27 = 1;
10037 + if (tmp > 19)
10038 + r27 = 2;
10039 + }
10040 + } else {
10041 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10042 + if (!tmp_control->used)
10043 + continue;
10044 + memcpy(&control, tmp_control, sizeof(control));
10045 + r27 = 3;
10046 + r31 = 0;
10047 + }
10048 + bcm43xx_radio_write16(bcm, 0x43, i - 9);
10049 + bcm43xx_radio_write16(bcm, 0x52,
10050 + radio->txctl2
10051 + | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
10052 + udelay(10);
10053 +
10054 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10055 +
10056 + tmp = (regstack[10] & 0xFFF0);
10057 + if (r31)
10058 + tmp |= 0x0008;
10059 + bcm43xx_radio_write16(bcm, 0x7A, tmp);
10060 +
10061 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10062 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10063 + }
10064 + }
10065 +
10066 + /* Restoration */
10067 + if (phy->connected) {
10068 + bcm43xx_phy_write(bcm, 0x0015, 0xE300);
10069 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
10070 + udelay(5);
10071 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
10072 + udelay(2);
10073 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
10074 + } else
10075 + bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
10076 + bcm43xx_phy_lo_adjust(bcm, is_initializing);
10077 + bcm43xx_phy_write(bcm, 0x002E, 0x807F);
10078 + if (phy->connected)
10079 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
10080 + else
10081 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
10082 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
10083 + bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
10084 + bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
10085 + bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
10086 + bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
10087 + bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
10088 + bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
10089 + regstack[11] &= 0x00F0;
10090 + regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
10091 + bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
10092 + bcm43xx_write16(bcm, 0x03E2, regstack[3]);
10093 + if (phy->connected) {
10094 + bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
10095 + bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
10096 + bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
10097 + bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
10098 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
10099 + bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
10100 + }
10101 + bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
10102 +
10103 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
10104 + {
10105 + /* Sanity check for all lopairs. */
10106 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10107 + tmp_control = phy->_lo_pairs + i;
10108 + if (tmp_control->low < -8 || tmp_control->low > 8 ||
10109 + tmp_control->high < -8 || tmp_control->high > 8) {
10110 + printk(KERN_WARNING PFX
10111 + "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
10112 + tmp_control->low, tmp_control->high, i);
10113 + }
10114 + }
10115 + }
10116 +#endif /* CONFIG_BCM43XX_D80211_DEBUG */
10117 +}
10118 +
10119 +static
10120 +void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
10121 +{
10122 + struct bcm43xx_lopair *pair;
10123 +
10124 + pair = bcm43xx_current_lopair(bcm);
10125 + pair->used = 1;
10126 +}
10127 +
10128 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
10129 +{
10130 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10131 + struct bcm43xx_lopair *pair;
10132 + int i;
10133 +
10134 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10135 + pair = phy->_lo_pairs + i;
10136 + pair->used = 0;
10137 + }
10138 +}
10139 +
10140 +/* http://bcm-specs.sipsolutions.net/EstimatePowerOut
10141 + * This function converts a TSSI value to dBm in Q5.2
10142 + */
10143 +static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
10144 +{
10145 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10146 + s8 dbm = 0;
10147 + s32 tmp;
10148 +
10149 + tmp = phy->idle_tssi;
10150 + tmp += tssi;
10151 + tmp -= phy->savedpctlreg;
10152 +
10153 + switch (phy->type) {
10154 + case BCM43xx_PHYTYPE_A:
10155 + tmp += 0x80;
10156 + tmp = limit_value(tmp, 0x00, 0xFF);
10157 + dbm = phy->tssi2dbm[tmp];
10158 + TODO(); //TODO: There's a FIXME on the specs
10159 + break;
10160 + case BCM43xx_PHYTYPE_B:
10161 + case BCM43xx_PHYTYPE_G:
10162 + tmp = limit_value(tmp, 0x00, 0x3F);
10163 + dbm = phy->tssi2dbm[tmp];
10164 + break;
10165 + default:
10166 + assert(0);
10167 + }
10168 +
10169 + return dbm;
10170 +}
10171 +
10172 +/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
10173 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
10174 +{
10175 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10176 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10177 +
10178 + if (phy->savedpctlreg == 0xFFFF)
10179 + return;
10180 + if ((bcm->board_type == 0x0416) &&
10181 + (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
10182 + return;
10183 +
10184 + switch (phy->type) {
10185 + case BCM43xx_PHYTYPE_A: {
10186 +
10187 + TODO(); //TODO: Nothing for A PHYs yet :-/
10188 +
10189 + break;
10190 + }
10191 + case BCM43xx_PHYTYPE_B:
10192 + case BCM43xx_PHYTYPE_G: {
10193 + u16 tmp;
10194 + u16 txpower;
10195 + s8 v0, v1, v2, v3;
10196 + s8 average;
10197 + u8 max_pwr;
10198 + s16 desired_pwr, estimated_pwr, pwr_adjust;
10199 + s16 radio_att_delta, baseband_att_delta;
10200 + s16 radio_attenuation, baseband_attenuation;
10201 + unsigned long phylock_flags;
10202 +
10203 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
10204 + v0 = (s8)(tmp & 0x00FF);
10205 + v1 = (s8)((tmp & 0xFF00) >> 8);
10206 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
10207 + v2 = (s8)(tmp & 0x00FF);
10208 + v3 = (s8)((tmp & 0xFF00) >> 8);
10209 + tmp = 0;
10210 +
10211 + if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
10212 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
10213 + v0 = (s8)(tmp & 0x00FF);
10214 + v1 = (s8)((tmp & 0xFF00) >> 8);
10215 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
10216 + v2 = (s8)(tmp & 0x00FF);
10217 + v3 = (s8)((tmp & 0xFF00) >> 8);
10218 + if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
10219 + return;
10220 + v0 = (v0 + 0x20) & 0x3F;
10221 + v1 = (v1 + 0x20) & 0x3F;
10222 + v2 = (v2 + 0x20) & 0x3F;
10223 + v3 = (v3 + 0x20) & 0x3F;
10224 + tmp = 1;
10225 + }
10226 + bcm43xx_radio_clear_tssi(bcm);
10227 +
10228 + average = (v0 + v1 + v2 + v3 + 2) / 4;
10229 +
10230 + if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
10231 + average -= 13;
10232 +
10233 + estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
10234 +
10235 + max_pwr = bcm->sprom.maxpower_bgphy;
10236 +
10237 + if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
10238 + (phy->type == BCM43xx_PHYTYPE_G))
10239 + max_pwr -= 0x3;
10240 +
10241 + /*TODO:
10242 + max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
10243 + where REG is the max power as per the regulatory domain
10244 + */
10245 +
10246 + desired_pwr = radio->power_level;
10247 + /* Convert the desired_pwr to Q5.2 and limit it. */
10248 + desired_pwr = limit_value((desired_pwr << 2), 0, max_pwr);
10249 +
10250 + pwr_adjust = desired_pwr - estimated_pwr;
10251 + radio_att_delta = -(pwr_adjust + 7) >> 3;
10252 + baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
10253 + if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
10254 + bcm43xx_phy_lo_mark_current_used(bcm);
10255 + return;
10256 + }
10257 +
10258 + /* Calculate the new attenuation values. */
10259 + baseband_attenuation = radio->baseband_atten;
10260 + baseband_attenuation += baseband_att_delta;
10261 + radio_attenuation = radio->radio_atten;
10262 + radio_attenuation += radio_att_delta;
10263 +
10264 + /* Get baseband and radio attenuation values into their permitted ranges.
10265 + * baseband 0-11, radio 0-9.
10266 + * Radio attenuation affects power level 4 times as much as baseband.
10267 + */
10268 + if (radio_attenuation < 0) {
10269 + baseband_attenuation -= (4 * -radio_attenuation);
10270 + radio_attenuation = 0;
10271 + } else if (radio_attenuation > 9) {
10272 + baseband_attenuation += (4 * (radio_attenuation - 9));
10273 + radio_attenuation = 9;
10274 + } else {
10275 + while (baseband_attenuation < 0 && radio_attenuation > 0) {
10276 + baseband_attenuation += 4;
10277 + radio_attenuation--;
10278 + }
10279 + while (baseband_attenuation > 11 && radio_attenuation < 9) {
10280 + baseband_attenuation -= 4;
10281 + radio_attenuation++;
10282 + }
10283 + }
10284 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10285 +
10286 + txpower = radio->txctl1;
10287 + if ((radio->version == 0x2050) && (radio->revision == 2)) {
10288 + if (radio_attenuation <= 1) {
10289 + if (txpower == 0) {
10290 + txpower = 3;
10291 + radio_attenuation += 2;
10292 + baseband_attenuation += 2;
10293 + } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
10294 + baseband_attenuation += 4 * (radio_attenuation - 2);
10295 + radio_attenuation = 2;
10296 + }
10297 + } else if (radio_attenuation > 4 && txpower != 0) {
10298 + txpower = 0;
10299 + if (baseband_attenuation < 3) {
10300 + radio_attenuation -= 3;
10301 + baseband_attenuation += 2;
10302 + } else {
10303 + radio_attenuation -= 2;
10304 + baseband_attenuation -= 2;
10305 + }
10306 + }
10307 + }
10308 + radio->txctl1 = txpower;
10309 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10310 + radio_attenuation = limit_value(radio_attenuation, 0, 9);
10311 +
10312 + bcm43xx_phy_lock(bcm, phylock_flags);
10313 + bcm43xx_radio_lock(bcm);
10314 + bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
10315 + radio_attenuation, txpower);
10316 + bcm43xx_phy_lo_mark_current_used(bcm);
10317 + bcm43xx_radio_unlock(bcm);
10318 + bcm43xx_phy_unlock(bcm, phylock_flags);
10319 + break;
10320 + }
10321 + default:
10322 + assert(0);
10323 + }
10324 +}
10325 +
10326 +static inline
10327 +s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
10328 +{
10329 + if (num < 0)
10330 + return num/den;
10331 + else
10332 + return (num+den/2)/den;
10333 +}
10334 +
10335 +static inline
10336 +s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
10337 +{
10338 + s32 m1, m2, f = 256, q, delta;
10339 + s8 i = 0;
10340 +
10341 + m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
10342 + m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
10343 + do {
10344 + if (i > 15)
10345 + return -EINVAL;
10346 + q = bcm43xx_tssi2dbm_ad(f * 4096 -
10347 + bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
10348 + delta = abs(q - f);
10349 + f = q;
10350 + i++;
10351 + } while (delta >= 2);
10352 + entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
10353 + return 0;
10354 +}
10355 +
10356 +/* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
10357 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
10358 +{
10359 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10360 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10361 + s16 pab0, pab1, pab2;
10362 + u8 idx;
10363 + s8 *dyn_tssi2dbm;
10364 +
10365 + if (phy->type == BCM43xx_PHYTYPE_A) {
10366 + pab0 = (s16)(bcm->sprom.pa1b0);
10367 + pab1 = (s16)(bcm->sprom.pa1b1);
10368 + pab2 = (s16)(bcm->sprom.pa1b2);
10369 + } else {
10370 + pab0 = (s16)(bcm->sprom.pa0b0);
10371 + pab1 = (s16)(bcm->sprom.pa0b1);
10372 + pab2 = (s16)(bcm->sprom.pa0b2);
10373 + }
10374 +
10375 + if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
10376 + phy->idle_tssi = 0x34;
10377 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10378 + return 0;
10379 + }
10380 +
10381 + if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
10382 + pab0 != -1 && pab1 != -1 && pab2 != -1) {
10383 + /* The pabX values are set in SPROM. Use them. */
10384 + if (phy->type == BCM43xx_PHYTYPE_A) {
10385 + if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
10386 + (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
10387 + phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
10388 + else
10389 + phy->idle_tssi = 62;
10390 + } else {
10391 + if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
10392 + (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
10393 + phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
10394 + else
10395 + phy->idle_tssi = 62;
10396 + }
10397 + dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
10398 + if (dyn_tssi2dbm == NULL) {
10399 + printk(KERN_ERR PFX "Could not allocate memory"
10400 + "for tssi2dbm table\n");
10401 + return -ENOMEM;
10402 + }
10403 + for (idx = 0; idx < 64; idx++)
10404 + if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
10405 + phy->tssi2dbm = NULL;
10406 + printk(KERN_ERR PFX "Could not generate "
10407 + "tssi2dBm table\n");
10408 + return -ENODEV;
10409 + }
10410 + phy->tssi2dbm = dyn_tssi2dbm;
10411 + phy->dyn_tssi_tbl = 1;
10412 + } else {
10413 + /* pabX values not set in SPROM. */
10414 + switch (phy->type) {
10415 + case BCM43xx_PHYTYPE_A:
10416 + /* APHY needs a generated table. */
10417 + phy->tssi2dbm = NULL;
10418 + printk(KERN_ERR PFX "Could not generate tssi2dBm "
10419 + "table (wrong SPROM info)!\n");
10420 + return -ENODEV;
10421 + case BCM43xx_PHYTYPE_B:
10422 + phy->idle_tssi = 0x34;
10423 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10424 + break;
10425 + case BCM43xx_PHYTYPE_G:
10426 + phy->idle_tssi = 0x34;
10427 + phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
10428 + break;
10429 + }
10430 + }
10431 +
10432 + return 0;
10433 +}
10434 +
10435 +int bcm43xx_phy_init(struct bcm43xx_private *bcm)
10436 +{
10437 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10438 + int err = -ENODEV;
10439 + unsigned long flags;
10440 +
10441 + /* We do not want to be preempted while calibrating
10442 + * the hardware.
10443 + */
10444 + local_irq_save(flags);
10445 +
10446 + switch (phy->type) {
10447 + case BCM43xx_PHYTYPE_A:
10448 + if (phy->rev == 2 || phy->rev == 3) {
10449 + bcm43xx_phy_inita(bcm);
10450 + err = 0;
10451 + }
10452 + break;
10453 + case BCM43xx_PHYTYPE_B:
10454 + switch (phy->rev) {
10455 + case 2:
10456 + bcm43xx_phy_initb2(bcm);
10457 + err = 0;
10458 + break;
10459 + case 4:
10460 + bcm43xx_phy_initb4(bcm);
10461 + err = 0;
10462 + break;
10463 + case 5:
10464 + bcm43xx_phy_initb5(bcm);
10465 + err = 0;
10466 + break;
10467 + case 6:
10468 + bcm43xx_phy_initb6(bcm);
10469 + err = 0;
10470 + break;
10471 + }
10472 + break;
10473 + case BCM43xx_PHYTYPE_G:
10474 + bcm43xx_phy_initg(bcm);
10475 + err = 0;
10476 + break;
10477 + }
10478 + local_irq_restore(flags);
10479 + if (err)
10480 + printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
10481 +
10482 + return err;
10483 +}
10484 +
10485 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
10486 +{
10487 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10488 + u16 antennadiv;
10489 + u16 offset;
10490 + u16 value;
10491 + u32 ucodeflags;
10492 +
10493 + antennadiv = phy->antenna_diversity;
10494 +
10495 + if (antennadiv == 0xFFFF)
10496 + antennadiv = 3;
10497 + assert(antennadiv <= 3);
10498 +
10499 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
10500 + BCM43xx_UCODEFLAGS_OFFSET);
10501 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
10502 + BCM43xx_UCODEFLAGS_OFFSET,
10503 + ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
10504 +
10505 + switch (phy->type) {
10506 + case BCM43xx_PHYTYPE_A:
10507 + case BCM43xx_PHYTYPE_G:
10508 + if (phy->type == BCM43xx_PHYTYPE_A)
10509 + offset = 0x0000;
10510 + else
10511 + offset = 0x0400;
10512 +
10513 + if (antennadiv == 2)
10514 + value = (3/*automatic*/ << 7);
10515 + else
10516 + value = (antennadiv << 7);
10517 + bcm43xx_phy_write(bcm, offset + 1,
10518 + (bcm43xx_phy_read(bcm, offset + 1)
10519 + & 0x7E7F) | value);
10520 +
10521 + if (antennadiv >= 2) {
10522 + if (antennadiv == 2)
10523 + value = (antennadiv << 7);
10524 + else
10525 + value = (0/*force0*/ << 7);
10526 + bcm43xx_phy_write(bcm, offset + 0x2B,
10527 + (bcm43xx_phy_read(bcm, offset + 0x2B)
10528 + & 0xFEFF) | value);
10529 + }
10530 +
10531 + if (phy->type == BCM43xx_PHYTYPE_G) {
10532 + if (antennadiv >= 2)
10533 + bcm43xx_phy_write(bcm, 0x048C,
10534 + bcm43xx_phy_read(bcm, 0x048C)
10535 + | 0x2000);
10536 + else
10537 + bcm43xx_phy_write(bcm, 0x048C,
10538 + bcm43xx_phy_read(bcm, 0x048C)
10539 + & ~0x2000);
10540 + if (phy->rev >= 2) {
10541 + bcm43xx_phy_write(bcm, 0x0461,
10542 + bcm43xx_phy_read(bcm, 0x0461)
10543 + | 0x0010);
10544 + bcm43xx_phy_write(bcm, 0x04AD,
10545 + (bcm43xx_phy_read(bcm, 0x04AD)
10546 + & 0x00FF) | 0x0015);
10547 + if (phy->rev == 2)
10548 + bcm43xx_phy_write(bcm, 0x0427, 0x0008);
10549 + else
10550 + bcm43xx_phy_write(bcm, 0x0427,
10551 + (bcm43xx_phy_read(bcm, 0x0427)
10552 + & 0x00FF) | 0x0008);
10553 + }
10554 + else if (phy->rev >= 6)
10555 + bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
10556 + } else {
10557 + if (phy->rev < 3)
10558 + bcm43xx_phy_write(bcm, 0x002B,
10559 + (bcm43xx_phy_read(bcm, 0x002B)
10560 + & 0x00FF) | 0x0024);
10561 + else {
10562 + bcm43xx_phy_write(bcm, 0x0061,
10563 + bcm43xx_phy_read(bcm, 0x0061)
10564 + | 0x0010);
10565 + if (phy->rev == 3) {
10566 + bcm43xx_phy_write(bcm, 0x0093, 0x001D);
10567 + bcm43xx_phy_write(bcm, 0x0027, 0x0008);
10568 + } else {
10569 + bcm43xx_phy_write(bcm, 0x0093, 0x003A);
10570 + bcm43xx_phy_write(bcm, 0x0027,
10571 + (bcm43xx_phy_read(bcm, 0x0027)
10572 + & 0x00FF) | 0x0008);
10573 + }
10574 + }
10575 + }
10576 + break;
10577 + case BCM43xx_PHYTYPE_B:
10578 + if (bcm->current_core->rev == 2)
10579 + value = (3/*automatic*/ << 7);
10580 + else
10581 + value = (antennadiv << 7);
10582 + bcm43xx_phy_write(bcm, 0x03E2,
10583 + (bcm43xx_phy_read(bcm, 0x03E2)
10584 + & 0xFE7F) | value);
10585 + break;
10586 + default:
10587 + assert(0);
10588 + }
10589 +
10590 + if (antennadiv >= 2) {
10591 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
10592 + BCM43xx_UCODEFLAGS_OFFSET);
10593 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
10594 + BCM43xx_UCODEFLAGS_OFFSET,
10595 + ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
10596 + }
10597 +
10598 + phy->antenna_diversity = antennadiv;
10599 +}
10600 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h
10601 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h 1970-01-01 01:00:00.000000000 +0100
10602 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h 2006-03-28 22:16:14.000000000 +0200
10603 @@ -0,0 +1,74 @@
10604 +/*
10605 +
10606 + Broadcom BCM43xx wireless driver
10607 +
10608 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
10609 + Stefano Brivio <st3@riseup.net>
10610 + Michael Buesch <mbuesch@freenet.de>
10611 + Danny van Dyk <kugelfang@gentoo.org>
10612 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
10613 +
10614 + Some parts of the code in this file are derived from the ipw2200
10615 + driver Copyright(c) 2003 - 2004 Intel Corporation.
10616 +
10617 + This program is free software; you can redistribute it and/or modify
10618 + it under the terms of the GNU General Public License as published by
10619 + the Free Software Foundation; either version 2 of the License, or
10620 + (at your option) any later version.
10621 +
10622 + This program is distributed in the hope that it will be useful,
10623 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10624 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10625 + GNU General Public License for more details.
10626 +
10627 + You should have received a copy of the GNU General Public License
10628 + along with this program; see the file COPYING. If not, write to
10629 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
10630 + Boston, MA 02110-1301, USA.
10631 +
10632 +*/
10633 +
10634 +#ifndef BCM43xx_PHY_H_
10635 +#define BCM43xx_PHY_H_
10636 +
10637 +#include <linux/types.h>
10638 +
10639 +struct bcm43xx_private;
10640 +
10641 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm);
10642 +#define bcm43xx_phy_lock(bcm, flags) \
10643 + do { \
10644 + local_irq_save(flags); \
10645 + bcm43xx_raw_phy_lock(bcm); \
10646 + } while (0)
10647 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm);
10648 +#define bcm43xx_phy_unlock(bcm, flags) \
10649 + do { \
10650 + bcm43xx_raw_phy_unlock(bcm); \
10651 + local_irq_restore(flags); \
10652 + } while (0)
10653 +
10654 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset);
10655 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
10656 +
10657 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm);
10658 +int bcm43xx_phy_init(struct bcm43xx_private *bcm);
10659 +
10660 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm);
10661 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm);
10662 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect);
10663 +
10664 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm);
10665 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm);
10666 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm);
10667 +
10668 +/* Adjust the LocalOscillator to the saved values.
10669 + * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
10670 + */
10671 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed);
10672 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm);
10673 +
10674 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
10675 + u16 baseband_attenuation);
10676 +
10677 +#endif /* BCM43xx_PHY_H_ */
10678 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c
10679 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c 1970-01-01 01:00:00.000000000 +0100
10680 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c 2006-03-28 22:16:14.000000000 +0200
10681 @@ -0,0 +1,592 @@
10682 +/*
10683 +
10684 + Broadcom BCM43xx wireless driver
10685 +
10686 + PIO Transmission
10687 +
10688 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
10689 +
10690 + This program is free software; you can redistribute it and/or modify
10691 + it under the terms of the GNU General Public License as published by
10692 + the Free Software Foundation; either version 2 of the License, or
10693 + (at your option) any later version.
10694 +
10695 + This program is distributed in the hope that it will be useful,
10696 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10697 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10698 + GNU General Public License for more details.
10699 +
10700 + You should have received a copy of the GNU General Public License
10701 + along with this program; see the file COPYING. If not, write to
10702 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
10703 + Boston, MA 02110-1301, USA.
10704 +
10705 +*/
10706 +
10707 +#include "bcm43xx.h"
10708 +#include "bcm43xx_pio.h"
10709 +#include "bcm43xx_main.h"
10710 +#include "bcm43xx_xmit.h"
10711 +
10712 +#include <linux/delay.h>
10713 +
10714 +
10715 +static void tx_start(struct bcm43xx_pioqueue *queue)
10716 +{
10717 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10718 + BCM43xx_PIO_TXCTL_INIT);
10719 +}
10720 +
10721 +static void tx_octet(struct bcm43xx_pioqueue *queue,
10722 + u8 octet)
10723 +{
10724 + if (queue->need_workarounds) {
10725 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10726 + octet);
10727 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10728 + BCM43xx_PIO_TXCTL_WRITEHI);
10729 + } else {
10730 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10731 + BCM43xx_PIO_TXCTL_WRITEHI);
10732 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10733 + octet);
10734 + }
10735 +}
10736 +
10737 +static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr,
10738 + const u8 *packet,
10739 + unsigned int *pos)
10740 +{
10741 + const u8 *source;
10742 + unsigned int i = *pos;
10743 + u16 ret;
10744 +
10745 + if (i < sizeof(*txhdr)) {
10746 + source = (const u8 *)txhdr;
10747 + } else {
10748 + source = packet;
10749 + i -= sizeof(*txhdr);
10750 + }
10751 + ret = le16_to_cpu( *((u16 *)(source + i)) );
10752 + *pos += 2;
10753 +
10754 + return ret;
10755 +}
10756 +
10757 +static void tx_data(struct bcm43xx_pioqueue *queue,
10758 + struct bcm43xx_txhdr *txhdr,
10759 + const u8 *packet,
10760 + unsigned int octets)
10761 +{
10762 + u16 data;
10763 + unsigned int i = 0;
10764 +
10765 + if (queue->need_workarounds) {
10766 + data = tx_get_next_word(txhdr, packet, &i);
10767 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
10768 + }
10769 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10770 + BCM43xx_PIO_TXCTL_WRITELO |
10771 + BCM43xx_PIO_TXCTL_WRITEHI);
10772 + while (i < octets - 1) {
10773 + data = tx_get_next_word(txhdr, packet, &i);
10774 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
10775 + }
10776 + if (octets % 2)
10777 + tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]);
10778 +}
10779 +
10780 +static void tx_complete(struct bcm43xx_pioqueue *queue,
10781 + struct sk_buff *skb)
10782 +{
10783 + if (queue->need_workarounds) {
10784 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10785 + skb->data[skb->len - 1]);
10786 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10787 + BCM43xx_PIO_TXCTL_WRITEHI |
10788 + BCM43xx_PIO_TXCTL_COMPLETE);
10789 + } else {
10790 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10791 + BCM43xx_PIO_TXCTL_COMPLETE);
10792 + }
10793 +}
10794 +
10795 +static u16 generate_cookie(struct bcm43xx_pioqueue *queue,
10796 + int packetindex)
10797 +{
10798 + u16 cookie = 0x0000;
10799 +
10800 + /* We use the upper 4 bits for the PIO
10801 + * controller ID and the lower 12 bits
10802 + * for the packet index (in the cache).
10803 + */
10804 + switch (queue->mmio_base) {
10805 + case BCM43xx_MMIO_PIO1_BASE:
10806 + break;
10807 + case BCM43xx_MMIO_PIO2_BASE:
10808 + cookie = 0x1000;
10809 + break;
10810 + case BCM43xx_MMIO_PIO3_BASE:
10811 + cookie = 0x2000;
10812 + break;
10813 + case BCM43xx_MMIO_PIO4_BASE:
10814 + cookie = 0x3000;
10815 + break;
10816 + default:
10817 + assert(0);
10818 + }
10819 + assert(((u16)packetindex & 0xF000) == 0x0000);
10820 + cookie |= (u16)packetindex;
10821 +
10822 + return cookie;
10823 +}
10824 +
10825 +static
10826 +struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm,
10827 + u16 cookie,
10828 + struct bcm43xx_pio_txpacket **packet)
10829 +{
10830 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
10831 + struct bcm43xx_pioqueue *queue = NULL;
10832 + int packetindex;
10833 +
10834 + switch (cookie & 0xF000) {
10835 + case 0x0000:
10836 + queue = pio->queue0;
10837 + break;
10838 + case 0x1000:
10839 + queue = pio->queue1;
10840 + break;
10841 + case 0x2000:
10842 + queue = pio->queue2;
10843 + break;
10844 + case 0x3000:
10845 + queue = pio->queue3;
10846 + break;
10847 + default:
10848 + assert(0);
10849 + }
10850 + packetindex = (cookie & 0x0FFF);
10851 + assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS);
10852 + *packet = &(queue->tx_packets_cache[packetindex]);
10853 +
10854 + return queue;
10855 +}
10856 +
10857 +static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue,
10858 + struct sk_buff *skb,
10859 + struct bcm43xx_pio_txpacket *packet)
10860 +{
10861 + struct bcm43xx_txhdr txhdr;
10862 + unsigned int octets;
10863 +
10864 + assert(skb_shinfo(skb)->nr_frags == 0);
10865 + bcm43xx_generate_txhdr(queue->bcm,
10866 + &txhdr, skb->data, skb->len,
10867 + 1,//FIXME
10868 + generate_cookie(queue, pio_txpacket_getindex(packet)),
10869 + packet->ctl);
10870 +
10871 + tx_start(queue);
10872 + octets = skb->len + sizeof(txhdr);
10873 + if (queue->need_workarounds)
10874 + octets--;
10875 + tx_data(queue, &txhdr, (u8 *)skb->data, octets);
10876 + tx_complete(queue, skb);
10877 +}
10878 +
10879 +static void free_txpacket(struct bcm43xx_pio_txpacket *packet,
10880 + int irq_context)
10881 +{
10882 + struct bcm43xx_pioqueue *queue = packet->queue;
10883 +
10884 + if (irq_context)
10885 + dev_kfree_skb_irq(packet->skb);
10886 + else
10887 + dev_kfree_skb(packet->skb);
10888 + list_move(&packet->list, &queue->txfree);
10889 + queue->nr_txfree++;
10890 +}
10891 +
10892 +static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet)
10893 +{
10894 + struct bcm43xx_pioqueue *queue = packet->queue;
10895 + struct sk_buff *skb = packet->skb;
10896 + u16 octets;
10897 +
10898 + octets = (u16)skb->len + sizeof(struct bcm43xx_txhdr);
10899 + if (queue->tx_devq_size < octets) {
10900 + dprintkl(KERN_WARNING PFX "PIO queue too small. "
10901 + "Dropping packet.\n");
10902 + /* Drop it silently (return success) */
10903 + free_txpacket(packet, 1);
10904 + return 0;
10905 + }
10906 + assert(queue->tx_devq_packets <= BCM43xx_PIO_MAXTXDEVQPACKETS);
10907 + assert(queue->tx_devq_used <= queue->tx_devq_size);
10908 + /* Check if there is sufficient free space on the device
10909 + * TX queue. If not, return and let the TX tasklet
10910 + * retry later.
10911 + */
10912 + if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS)
10913 + return -EBUSY;
10914 + if (queue->tx_devq_used + octets > queue->tx_devq_size)
10915 + return -EBUSY;
10916 + /* Now poke the device. */
10917 + pio_tx_write_fragment(queue, skb, packet);
10918 +
10919 + /* Account for the packet size.
10920 + * (We must not overflow the device TX queue)
10921 + */
10922 + queue->tx_devq_packets++;
10923 + queue->tx_devq_used += octets;
10924 +
10925 + /* Transmission started, everything ok, move the
10926 + * packet to the txrunning list.
10927 + */
10928 + list_move_tail(&packet->list, &queue->txrunning);
10929 +
10930 + return 0;
10931 +}
10932 +
10933 +static void tx_tasklet(unsigned long d)
10934 +{
10935 + struct bcm43xx_pioqueue *queue = (struct bcm43xx_pioqueue *)d;
10936 + struct bcm43xx_private *bcm = queue->bcm;
10937 + unsigned long flags;
10938 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
10939 + int err;
10940 +
10941 + bcm43xx_lock_mmio(bcm, flags);
10942 + list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) {
10943 + /* Try to transmit the packet. This can fail, if
10944 + * the device queue is full. In case of failure, the
10945 + * packet is left in the txqueue.
10946 + * If transmission succeed, the packet is moved to txrunning.
10947 + * If it is impossible to transmit the packet, it
10948 + * is dropped.
10949 + */
10950 + err = pio_tx_packet(packet);
10951 + if (err)
10952 + break;
10953 + }
10954 + bcm43xx_unlock_mmio(bcm, flags);
10955 +}
10956 +
10957 +static void setup_txqueues(struct bcm43xx_pioqueue *queue)
10958 +{
10959 + struct bcm43xx_pio_txpacket *packet;
10960 + int i;
10961 +
10962 + queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS;
10963 + for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) {
10964 + packet = &(queue->tx_packets_cache[i]);
10965 +
10966 + packet->queue = queue;
10967 + INIT_LIST_HEAD(&packet->list);
10968 +
10969 + list_add(&packet->list, &queue->txfree);
10970 + }
10971 +}
10972 +
10973 +static
10974 +struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm,
10975 + u16 pio_mmio_base)
10976 +{
10977 + struct bcm43xx_pioqueue *queue;
10978 + u32 value;
10979 + u16 qsize;
10980 +
10981 + queue = kzalloc(sizeof(*queue), GFP_KERNEL);
10982 + if (!queue)
10983 + goto out;
10984 +
10985 + queue->bcm = bcm;
10986 + queue->mmio_base = pio_mmio_base;
10987 + queue->need_workarounds = (bcm->current_core->rev < 3);
10988 +
10989 + INIT_LIST_HEAD(&queue->txfree);
10990 + INIT_LIST_HEAD(&queue->txqueue);
10991 + INIT_LIST_HEAD(&queue->txrunning);
10992 + tasklet_init(&queue->txtask, tx_tasklet,
10993 + (unsigned long)queue);
10994 +
10995 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
10996 + value |= BCM43xx_SBF_XFER_REG_BYTESWAP;
10997 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value);
10998 +
10999 + qsize = bcm43xx_read16(bcm, queue->mmio_base + BCM43xx_PIO_TXQBUFSIZE);
11000 + if (qsize <= BCM43xx_PIO_TXQADJUST) {
11001 + printk(KERN_ERR PFX "PIO tx device-queue too small (%u)\n", qsize);
11002 + goto err_freequeue;
11003 + }
11004 + qsize -= BCM43xx_PIO_TXQADJUST;
11005 + queue->tx_devq_size = qsize;
11006 +
11007 + setup_txqueues(queue);
11008 +
11009 +out:
11010 + return queue;
11011 +
11012 +err_freequeue:
11013 + kfree(queue);
11014 + queue = NULL;
11015 + goto out;
11016 +}
11017 +
11018 +static void cancel_transfers(struct bcm43xx_pioqueue *queue)
11019 +{
11020 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
11021 +
11022 + ieee80211_netif_oper(queue->bcm->net_dev, NETIF_DETACH);
11023 + assert(queue->bcm->shutting_down);
11024 + tasklet_disable(&queue->txtask);
11025 +
11026 + list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list)
11027 + free_txpacket(packet, 0);
11028 + list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list)
11029 + free_txpacket(packet, 0);
11030 +}
11031 +
11032 +static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue)
11033 +{
11034 + if (!queue)
11035 + return;
11036 +
11037 + cancel_transfers(queue);
11038 + kfree(queue);
11039 +}
11040 +
11041 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11042 +{
11043 + struct bcm43xx_pio *pio;
11044 +
11045 + if (!bcm43xx_using_pio(bcm))
11046 + return;
11047 + pio = bcm43xx_current_pio(bcm);
11048 +
11049 + bcm43xx_destroy_pioqueue(pio->queue3);
11050 + pio->queue3 = NULL;
11051 + bcm43xx_destroy_pioqueue(pio->queue2);
11052 + pio->queue2 = NULL;
11053 + bcm43xx_destroy_pioqueue(pio->queue1);
11054 + pio->queue1 = NULL;
11055 + bcm43xx_destroy_pioqueue(pio->queue0);
11056 + pio->queue0 = NULL;
11057 +}
11058 +
11059 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11060 +{
11061 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11062 + struct bcm43xx_pioqueue *queue;
11063 + int err = -ENOMEM;
11064 +
11065 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE);
11066 + if (!queue)
11067 + goto out;
11068 + pio->queue0 = queue;
11069 +
11070 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE);
11071 + if (!queue)
11072 + goto err_destroy0;
11073 + pio->queue1 = queue;
11074 +
11075 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE);
11076 + if (!queue)
11077 + goto err_destroy1;
11078 + pio->queue2 = queue;
11079 +
11080 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE);
11081 + if (!queue)
11082 + goto err_destroy2;
11083 + pio->queue3 = queue;
11084 +
11085 + if (bcm->current_core->rev < 3)
11086 + bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND;
11087 +
11088 + dprintk(KERN_INFO PFX "PIO initialized\n");
11089 + err = 0;
11090 +out:
11091 + return err;
11092 +
11093 +err_destroy2:
11094 + bcm43xx_destroy_pioqueue(pio->queue2);
11095 + pio->queue2 = NULL;
11096 +err_destroy1:
11097 + bcm43xx_destroy_pioqueue(pio->queue1);
11098 + pio->queue1 = NULL;
11099 +err_destroy0:
11100 + bcm43xx_destroy_pioqueue(pio->queue0);
11101 + pio->queue0 = NULL;
11102 + goto out;
11103 +}
11104 +
11105 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11106 + struct sk_buff *skb,
11107 + struct ieee80211_tx_control *ctl)
11108 +{
11109 + struct bcm43xx_pioqueue *queue = bcm43xx_current_pio(bcm)->queue1;
11110 + struct bcm43xx_pio_txpacket *packet;
11111 + u16 tmp;
11112 +
11113 + assert(!queue->tx_suspended);
11114 + assert(!list_empty(&queue->txfree));
11115 +
11116 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
11117 + if (tmp & BCM43xx_PIO_TXCTL_SUSPEND)
11118 + return -EBUSY;
11119 +
11120 + packet = list_entry(queue->txfree.next, struct bcm43xx_pio_txpacket, list);
11121 + packet->skb = skb;
11122 + packet->ctl = ctl;
11123 + list_move_tail(&packet->list, &queue->txqueue);
11124 + queue->nr_txfree--;
11125 + assert(queue->nr_txfree < BCM43xx_PIO_MAXTXPACKETS);
11126 +
11127 + tasklet_schedule(&queue->txtask);
11128 +
11129 + return 0;
11130 +}
11131 +
11132 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11133 + struct bcm43xx_xmitstatus *status)
11134 +{
11135 + struct bcm43xx_pioqueue *queue;
11136 + struct bcm43xx_pio_txpacket *packet;
11137 +
11138 + queue = parse_cookie(bcm, status->cookie, &packet);
11139 + assert(queue);
11140 +//TODO
11141 +if (!queue)
11142 +return;
11143 + free_txpacket(packet, 1);
11144 + /* If there are packets on the txqueue, poke the tasklet. */
11145 + if (!list_empty(&queue->txqueue))
11146 + tasklet_schedule(&queue->txtask);
11147 +}
11148 +
11149 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11150 + struct ieee80211_tx_queue_stats *stats)
11151 +{
11152 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11153 + struct bcm43xx_pioqueue *queue;
11154 + struct ieee80211_tx_queue_stats_data *data;
11155 +
11156 + queue = pio->queue1;
11157 + data = &(stats->data[0]);
11158 + data->len = BCM43xx_PIO_MAXTXPACKETS - queue->nr_txfree;
11159 + data->limit = BCM43xx_PIO_MAXTXPACKETS;
11160 + data->count = queue->nr_tx_packets;
11161 +}
11162 +
11163 +static void pio_rx_error(struct bcm43xx_pioqueue *queue,
11164 + int clear_buffers,
11165 + const char *error)
11166 +{
11167 + int i;
11168 +
11169 + printkl("PIO RX error: %s\n", error);
11170 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11171 + BCM43xx_PIO_RXCTL_READY);
11172 + if (clear_buffers) {
11173 + assert(queue->mmio_base == BCM43xx_MMIO_PIO1_BASE);
11174 + for (i = 0; i < 15; i++) {
11175 + /* Dummy read. */
11176 + bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11177 + }
11178 + }
11179 +}
11180 +
11181 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11182 +{
11183 + u16 preamble[21] = { 0 };
11184 + struct bcm43xx_rxhdr *rxhdr;
11185 + u16 tmp, len, rxflags2;
11186 + int i, preamble_readwords;
11187 + struct sk_buff *skb;
11188 +
11189 +return;
11190 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11191 + if (!(tmp & BCM43xx_PIO_RXCTL_DATAAVAILABLE)) {
11192 + dprintkl(KERN_ERR PFX "PIO RX: No data available\n");//TODO: remove this printk.
11193 + return;
11194 + }
11195 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11196 + BCM43xx_PIO_RXCTL_DATAAVAILABLE);
11197 +
11198 + for (i = 0; i < 10; i++) {
11199 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11200 + if (tmp & BCM43xx_PIO_RXCTL_READY)
11201 + goto data_ready;
11202 + udelay(10);
11203 + }
11204 + dprintkl(KERN_ERR PFX "PIO RX timed out\n");
11205 + return;
11206 +data_ready:
11207 +
11208 +//FIXME: endianess in this function.
11209 + len = le16_to_cpu(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
11210 + if (unlikely(len > 0x700)) {
11211 + pio_rx_error(queue, 0, "len > 0x700");
11212 + return;
11213 + }
11214 + if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) {
11215 + pio_rx_error(queue, 0, "len == 0");
11216 + return;
11217 + }
11218 + preamble[0] = cpu_to_le16(len);
11219 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE)
11220 + preamble_readwords = 14 / sizeof(u16);
11221 + else
11222 + preamble_readwords = 18 / sizeof(u16);
11223 + for (i = 0; i < preamble_readwords; i++) {
11224 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11225 + preamble[i + 1] = cpu_to_be16(tmp);//FIXME?
11226 + }
11227 + rxhdr = (struct bcm43xx_rxhdr *)preamble;
11228 + rxflags2 = le16_to_cpu(rxhdr->flags2);
11229 + if (unlikely(rxflags2 & BCM43xx_RXHDR_FLAGS2_INVALIDFRAME)) {
11230 + pio_rx_error(queue,
11231 + (queue->mmio_base == BCM43xx_MMIO_PIO1_BASE),
11232 + "invalid frame");
11233 + return;
11234 + }
11235 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE) {
11236 + /* We received an xmit status. */
11237 + struct bcm43xx_hwxmitstatus *hw;
11238 + struct bcm43xx_xmitstatus stat;
11239 +
11240 + hw = (struct bcm43xx_hwxmitstatus *)(preamble + 1);
11241 + stat.cookie = le16_to_cpu(hw->cookie);
11242 + stat.flags = hw->flags;
11243 + stat.cnt1 = hw->cnt1;
11244 + stat.cnt2 = hw->cnt2;
11245 + stat.seq = le16_to_cpu(hw->seq);
11246 + stat.unknown = le16_to_cpu(hw->unknown);
11247 +
11248 + bcm43xx_debugfs_log_txstat(queue->bcm, &stat);
11249 + bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat);
11250 +
11251 + return;
11252 + }
11253 +
11254 + skb = dev_alloc_skb(len);
11255 + if (unlikely(!skb)) {
11256 + pio_rx_error(queue, 1, "OOM");
11257 + return;
11258 + }
11259 + skb_put(skb, len);
11260 + for (i = 0; i < len - 1; i += 2) {
11261 + tmp = cpu_to_be16(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
11262 + *((u16 *)(skb->data + i)) = tmp;
11263 + }
11264 + if (len % 2) {
11265 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11266 + skb->data[len - 1] = (tmp & 0x00FF);
11267 + if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME)
11268 + skb->data[0x20] = (tmp & 0xFF00) >> 8;
11269 + else
11270 + skb->data[0x1E] = (tmp & 0xFF00) >> 8;
11271 + }
11272 + bcm43xx_rx(queue->bcm, skb, rxhdr);
11273 +}
11274 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h
11275 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h 1970-01-01 01:00:00.000000000 +0100
11276 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h 2006-03-28 22:16:14.000000000 +0200
11277 @@ -0,0 +1,146 @@
11278 +#ifndef BCM43xx_PIO_H_
11279 +#define BCM43xx_PIO_H_
11280 +
11281 +#include "bcm43xx.h"
11282 +
11283 +#include <linux/interrupt.h>
11284 +#include <linux/list.h>
11285 +#include <linux/skbuff.h>
11286 +
11287 +
11288 +#define BCM43xx_PIO_TXCTL 0x00
11289 +#define BCM43xx_PIO_TXDATA 0x02
11290 +#define BCM43xx_PIO_TXQBUFSIZE 0x04
11291 +#define BCM43xx_PIO_RXCTL 0x08
11292 +#define BCM43xx_PIO_RXDATA 0x0A
11293 +
11294 +#define BCM43xx_PIO_TXCTL_WRITEHI (1 << 0)
11295 +#define BCM43xx_PIO_TXCTL_WRITELO (1 << 1)
11296 +#define BCM43xx_PIO_TXCTL_COMPLETE (1 << 2)
11297 +#define BCM43xx_PIO_TXCTL_INIT (1 << 3)
11298 +#define BCM43xx_PIO_TXCTL_SUSPEND (1 << 7)
11299 +
11300 +#define BCM43xx_PIO_RXCTL_DATAAVAILABLE (1 << 0)
11301 +#define BCM43xx_PIO_RXCTL_READY (1 << 1)
11302 +
11303 +/* PIO constants */
11304 +#define BCM43xx_PIO_MAXTXDEVQPACKETS 31
11305 +#define BCM43xx_PIO_TXQADJUST 80
11306 +
11307 +/* PIO tuning knobs */
11308 +#define BCM43xx_PIO_MAXTXPACKETS 256
11309 +
11310 +
11311 +
11312 +#ifdef CONFIG_BCM43XX_D80211_PIO
11313 +
11314 +
11315 +struct bcm43xx_pioqueue;
11316 +struct bcm43xx_xmitstatus;
11317 +
11318 +struct bcm43xx_pio_txpacket {
11319 + struct bcm43xx_pioqueue *queue;
11320 + struct sk_buff *skb;
11321 + struct ieee80211_tx_control *ctl;
11322 + struct list_head list;
11323 +};
11324 +
11325 +#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
11326 +
11327 +struct bcm43xx_pioqueue {
11328 + struct bcm43xx_private *bcm;
11329 + u16 mmio_base;
11330 +
11331 + u8 tx_suspended:1,
11332 + need_workarounds:1; /* Workarounds needed for core.rev < 3 */
11333 +
11334 + /* Adjusted size of the device internal TX buffer. */
11335 + u16 tx_devq_size;
11336 + /* Used octets of the device internal TX buffer. */
11337 + u16 tx_devq_used;
11338 + /* Used packet slots in the device internal TX buffer. */
11339 + u8 tx_devq_packets;
11340 + /* Packets from the txfree list can
11341 + * be taken on incoming TX requests.
11342 + */
11343 + struct list_head txfree;
11344 + unsigned int nr_txfree;
11345 + /* Packets on the txqueue are queued,
11346 + * but not completely written to the chip, yet.
11347 + */
11348 + struct list_head txqueue;
11349 + /* Packets on the txrunning queue are completely
11350 + * posted to the device. We are waiting for the txstatus.
11351 + */
11352 + struct list_head txrunning;
11353 + /* Total number or packets sent.
11354 + * (This counter can obviously wrap).
11355 + */
11356 + unsigned int nr_tx_packets;
11357 + struct tasklet_struct txtask;
11358 + struct bcm43xx_pio_txpacket tx_packets_cache[BCM43xx_PIO_MAXTXPACKETS];
11359 +};
11360 +
11361 +static inline
11362 +u16 bcm43xx_pio_read(struct bcm43xx_pioqueue *queue,
11363 + u16 offset)
11364 +{
11365 + return bcm43xx_read16(queue->bcm, queue->mmio_base + offset);
11366 +}
11367 +
11368 +static inline
11369 +void bcm43xx_pio_write(struct bcm43xx_pioqueue *queue,
11370 + u16 offset, u16 value)
11371 +{
11372 + bcm43xx_write16(queue->bcm, queue->mmio_base + offset, value);
11373 +}
11374 +
11375 +
11376 +int bcm43xx_pio_init(struct bcm43xx_private *bcm);
11377 +void bcm43xx_pio_free(struct bcm43xx_private *bcm);
11378 +
11379 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11380 + struct sk_buff *skb,
11381 + struct ieee80211_tx_control *ctl);
11382 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11383 + struct bcm43xx_xmitstatus *status);
11384 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11385 + struct ieee80211_tx_queue_stats *stats);
11386 +
11387 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue);
11388 +
11389 +#else /* CONFIG_BCM43XX_D80211_PIO */
11390 +
11391 +static inline
11392 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11393 +{
11394 + return 0;
11395 +}
11396 +static inline
11397 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11398 +{
11399 +}
11400 +static inline
11401 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11402 + struct sk_buff *skb,
11403 + struct ieee80211_tx_control *ctl)
11404 +{
11405 + return 0;
11406 +}
11407 +static inline
11408 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11409 + struct bcm43xx_xmitstatus *status)
11410 +{
11411 +}
11412 +static inline
11413 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11414 + struct ieee80211_tx_queue_stats *stats)
11415 +{
11416 +}
11417 +static inline
11418 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11419 +{
11420 +}
11421 +
11422 +#endif /* CONFIG_BCM43XX_D80211_PIO */
11423 +#endif /* BCM43xx_PIO_H_ */
11424 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c
11425 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c 1970-01-01 01:00:00.000000000 +0100
11426 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c 2006-03-28 22:16:14.000000000 +0200
11427 @@ -0,0 +1,358 @@
11428 +/*
11429 +
11430 + Broadcom BCM43xx wireless driver
11431 +
11432 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11433 + Stefano Brivio <st3@riseup.net>
11434 + Michael Buesch <mbuesch@freenet.de>
11435 + Danny van Dyk <kugelfang@gentoo.org>
11436 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11437 +
11438 + Some parts of the code in this file are derived from the ipw2200
11439 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11440 +
11441 + This program is free software; you can redistribute it and/or modify
11442 + it under the terms of the GNU General Public License as published by
11443 + the Free Software Foundation; either version 2 of the License, or
11444 + (at your option) any later version.
11445 +
11446 + This program is distributed in the hope that it will be useful,
11447 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11448 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11449 + GNU General Public License for more details.
11450 +
11451 + You should have received a copy of the GNU General Public License
11452 + along with this program; see the file COPYING. If not, write to
11453 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11454 + Boston, MA 02110-1301, USA.
11455 +
11456 +*/
11457 +
11458 +#include <linux/delay.h>
11459 +
11460 +#include "bcm43xx.h"
11461 +#include "bcm43xx_power.h"
11462 +#include "bcm43xx_main.h"
11463 +
11464 +
11465 +/* Get max/min slowclock frequency
11466 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11467 + */
11468 +static int bcm43xx_pctl_clockfreqlimit(struct bcm43xx_private *bcm,
11469 + int get_max)
11470 +{
11471 + int limit = 0;
11472 + int divisor;
11473 + int selection;
11474 + int err;
11475 + u32 tmp;
11476 + struct bcm43xx_coreinfo *old_core;
11477 +
11478 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11479 + goto out;
11480 + old_core = bcm->current_core;
11481 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11482 + if (err)
11483 + goto out;
11484 +
11485 + if (bcm->current_core->rev < 6) {
11486 + if ((bcm->bustype == BCM43xx_BUSTYPE_PCMCIA) ||
11487 + (bcm->bustype == BCM43xx_BUSTYPE_SB)) {
11488 + selection = 1;
11489 + divisor = 32;
11490 + } else {
11491 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &tmp);
11492 + if (err) {
11493 + printk(KERN_ERR PFX "clockfreqlimit pcicfg read failure\n");
11494 + goto out_switchback;
11495 + }
11496 + if (tmp & 0x10) {
11497 + /* PCI */
11498 + selection = 2;
11499 + divisor = 64;
11500 + } else {
11501 + /* XTAL */
11502 + selection = 1;
11503 + divisor = 32;
11504 + }
11505 + }
11506 + } else if (bcm->current_core->rev < 10) {
11507 + selection = (tmp & 0x07);
11508 + if (selection) {
11509 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11510 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11511 + } else
11512 + divisor = 1;
11513 + } else {
11514 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SYSCLKCTL);
11515 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11516 + selection = 1;
11517 + }
11518 +
11519 + switch (selection) {
11520 + case 0:
11521 + /* LPO */
11522 + if (get_max)
11523 + limit = 43000;
11524 + else
11525 + limit = 25000;
11526 + break;
11527 + case 1:
11528 + /* XTAL */
11529 + if (get_max)
11530 + limit = 20200000;
11531 + else
11532 + limit = 19800000;
11533 + break;
11534 + case 2:
11535 + /* PCI */
11536 + if (get_max)
11537 + limit = 34000000;
11538 + else
11539 + limit = 25000000;
11540 + break;
11541 + default:
11542 + assert(0);
11543 + }
11544 + limit /= divisor;
11545 +
11546 +out_switchback:
11547 + err = bcm43xx_switch_core(bcm, old_core);
11548 + assert(err == 0);
11549 +
11550 +out:
11551 + return limit;
11552 +}
11553 +
11554 +/* init power control
11555 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11556 + */
11557 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm)
11558 +{
11559 + int err, maxfreq;
11560 + struct bcm43xx_coreinfo *old_core;
11561 +
11562 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11563 + return 0;
11564 + old_core = bcm->current_core;
11565 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11566 + if (err == -ENODEV)
11567 + return 0;
11568 + if (err)
11569 + goto out;
11570 +
11571 + maxfreq = bcm43xx_pctl_clockfreqlimit(bcm, 1);
11572 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY,
11573 + (maxfreq * 150 + 999999) / 1000000);
11574 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_FREFSELDELAY,
11575 + (maxfreq * 15 + 999999) / 1000000);
11576 +
11577 + err = bcm43xx_switch_core(bcm, old_core);
11578 + assert(err == 0);
11579 +
11580 +out:
11581 + return err;
11582 +}
11583 +
11584 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm)
11585 +{
11586 + u16 delay = 0;
11587 + int err;
11588 + u32 pll_on_delay;
11589 + struct bcm43xx_coreinfo *old_core;
11590 + int minfreq;
11591 +
11592 + if (bcm->bustype != BCM43xx_BUSTYPE_PCI)
11593 + goto out;
11594 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11595 + goto out;
11596 + old_core = bcm->current_core;
11597 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11598 + if (err == -ENODEV)
11599 + goto out;
11600 +
11601 + minfreq = bcm43xx_pctl_clockfreqlimit(bcm, 0);
11602 + pll_on_delay = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY);
11603 + delay = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
11604 +
11605 + err = bcm43xx_switch_core(bcm, old_core);
11606 + assert(err == 0);
11607 +
11608 +out:
11609 + return delay;
11610 +}
11611 +
11612 +/* set the powercontrol clock
11613 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11614 + */
11615 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode)
11616 +{
11617 + int err;
11618 + struct bcm43xx_coreinfo *old_core;
11619 + u32 tmp;
11620 +
11621 + old_core = bcm->current_core;
11622 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11623 + if (err == -ENODEV)
11624 + return 0;
11625 + if (err)
11626 + goto out;
11627 +
11628 + if (bcm->core_chipcommon.rev < 6) {
11629 + if (mode == BCM43xx_PCTL_CLK_FAST) {
11630 + err = bcm43xx_pctl_set_crystal(bcm, 1);
11631 + if (err)
11632 + goto out;
11633 + }
11634 + } else {
11635 + if ((bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL) &&
11636 + (bcm->core_chipcommon.rev < 10)) {
11637 + switch (mode) {
11638 + case BCM43xx_PCTL_CLK_FAST:
11639 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11640 + tmp = (tmp & ~BCM43xx_PCTL_FORCE_SLOW) | BCM43xx_PCTL_FORCE_PLL;
11641 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11642 + break;
11643 + case BCM43xx_PCTL_CLK_SLOW:
11644 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11645 + tmp |= BCM43xx_PCTL_FORCE_SLOW;
11646 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11647 + break;
11648 + case BCM43xx_PCTL_CLK_DYNAMIC:
11649 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11650 + tmp &= ~BCM43xx_PCTL_FORCE_SLOW;
11651 + tmp |= BCM43xx_PCTL_FORCE_PLL;
11652 + tmp &= ~BCM43xx_PCTL_DYN_XTAL;
11653 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11654 + }
11655 + }
11656 + }
11657 +
11658 + err = bcm43xx_switch_core(bcm, old_core);
11659 + assert(err == 0);
11660 +
11661 +out:
11662 + return err;
11663 +}
11664 +
11665 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on)
11666 +{
11667 + int err;
11668 + u32 in, out, outenable;
11669 +
11670 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_IN, &in);
11671 + if (err)
11672 + goto err_pci;
11673 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &out);
11674 + if (err)
11675 + goto err_pci;
11676 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUTENABLE, &outenable);
11677 + if (err)
11678 + goto err_pci;
11679 +
11680 + outenable |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11681 +
11682 + if (on) {
11683 + if (in & 0x40)
11684 + return 0;
11685 +
11686 + out |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11687 +
11688 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11689 + if (err)
11690 + goto err_pci;
11691 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11692 + if (err)
11693 + goto err_pci;
11694 + udelay(1000);
11695 +
11696 + out &= ~BCM43xx_PCTL_PLL_POWERDOWN;
11697 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11698 + if (err)
11699 + goto err_pci;
11700 + udelay(5000);
11701 + } else {
11702 + if (bcm->current_core->rev < 5)
11703 + return 0;
11704 + if (bcm->sprom.boardflags & BCM43xx_BFL_XTAL_NOSLOW)
11705 + return 0;
11706 +
11707 +/* XXX: Why BCM43xx_MMIO_RADIO_HWENABLED_xx can't be read at this time?
11708 + * err = bcm43xx_switch_core(bcm, bcm->active_80211_core);
11709 + * if (err)
11710 + * return err;
11711 + * if (((bcm->current_core->rev >= 3) &&
11712 + * (bcm43xx_read32(bcm, BCM43xx_MMIO_RADIO_HWENABLED_HI) & (1 << 16))) ||
11713 + * ((bcm->current_core->rev < 3) &&
11714 + * !(bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_HWENABLED_LO) & (1 << 4))))
11715 + * return 0;
11716 + * err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11717 + * if (err)
11718 + * return err;
11719 + */
11720 +
11721 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
11722 + if (err)
11723 + goto out;
11724 + out &= ~BCM43xx_PCTL_XTAL_POWERUP;
11725 + out |= BCM43xx_PCTL_PLL_POWERDOWN;
11726 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11727 + if (err)
11728 + goto err_pci;
11729 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11730 + if (err)
11731 + goto err_pci;
11732 + }
11733 +
11734 +out:
11735 + return err;
11736 +
11737 +err_pci:
11738 + printk(KERN_ERR PFX "Error: pctl_set_clock() could not access PCI config space!\n");
11739 + err = -EBUSY;
11740 + goto out;
11741 +}
11742 +
11743 +/* Set the PowerSavingControlBits.
11744 + * Bitvalues:
11745 + * 0 => unset the bit
11746 + * 1 => set the bit
11747 + * -1 => calculate the bit
11748 + */
11749 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11750 + int bit25, int bit26)
11751 +{
11752 + int i;
11753 + u32 status;
11754 +
11755 +//FIXME: Force 25 to off and 26 to on for now:
11756 +bit25 = 0;
11757 +bit26 = 1;
11758 +
11759 + if (bit25 == -1) {
11760 + //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
11761 + // and thus is not an AP and we are associated, set bit 25
11762 + }
11763 + if (bit26 == -1) {
11764 + //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
11765 + // or we are associated, or FIXME, or the latest PS-Poll packet sent was
11766 + // successful, set bit26
11767 + }
11768 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11769 + if (bit25)
11770 + status |= BCM43xx_SBF_PS1;
11771 + else
11772 + status &= ~BCM43xx_SBF_PS1;
11773 + if (bit26)
11774 + status |= BCM43xx_SBF_PS2;
11775 + else
11776 + status &= ~BCM43xx_SBF_PS2;
11777 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
11778 + if (bit26 && bcm->current_core->rev >= 5) {
11779 + for (i = 0; i < 100; i++) {
11780 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0040) != 4)
11781 + break;
11782 + udelay(10);
11783 + }
11784 + }
11785 +}
11786 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h
11787 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h 1970-01-01 01:00:00.000000000 +0100
11788 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h 2006-03-28 22:16:14.000000000 +0200
11789 @@ -0,0 +1,47 @@
11790 +/*
11791 +
11792 + Broadcom BCM43xx wireless driver
11793 +
11794 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11795 + Stefano Brivio <st3@riseup.net>
11796 + Michael Buesch <mbuesch@freenet.de>
11797 + Danny van Dyk <kugelfang@gentoo.org>
11798 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11799 +
11800 + Some parts of the code in this file are derived from the ipw2200
11801 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11802 +
11803 + This program is free software; you can redistribute it and/or modify
11804 + it under the terms of the GNU General Public License as published by
11805 + the Free Software Foundation; either version 2 of the License, or
11806 + (at your option) any later version.
11807 +
11808 + This program is distributed in the hope that it will be useful,
11809 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11810 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11811 + GNU General Public License for more details.
11812 +
11813 + You should have received a copy of the GNU General Public License
11814 + along with this program; see the file COPYING. If not, write to
11815 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11816 + Boston, MA 02110-1301, USA.
11817 +
11818 +*/
11819 +
11820 +#ifndef BCM43xx_POWER_H_
11821 +#define BCM43xx_POWER_H_
11822 +
11823 +#include <linux/types.h>
11824 +
11825 +
11826 +struct bcm43xx_private;
11827 +
11828 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm);
11829 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode);
11830 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on);
11831 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm);
11832 +
11833 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11834 + int bit25, int bit26);
11835 +
11836 +#endif /* BCM43xx_POWER_H_ */
11837 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c
11838 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c 1970-01-01 01:00:00.000000000 +0100
11839 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c 2006-03-28 22:16:14.000000000 +0200
11840 @@ -0,0 +1,2026 @@
11841 +/*
11842 +
11843 + Broadcom BCM43xx wireless driver
11844 +
11845 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11846 + Stefano Brivio <st3@riseup.net>
11847 + Michael Buesch <mbuesch@freenet.de>
11848 + Danny van Dyk <kugelfang@gentoo.org>
11849 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11850 +
11851 + Some parts of the code in this file are derived from the ipw2200
11852 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11853 +
11854 + This program is free software; you can redistribute it and/or modify
11855 + it under the terms of the GNU General Public License as published by
11856 + the Free Software Foundation; either version 2 of the License, or
11857 + (at your option) any later version.
11858 +
11859 + This program is distributed in the hope that it will be useful,
11860 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11861 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11862 + GNU General Public License for more details.
11863 +
11864 + You should have received a copy of the GNU General Public License
11865 + along with this program; see the file COPYING. If not, write to
11866 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11867 + Boston, MA 02110-1301, USA.
11868 +
11869 +*/
11870 +
11871 +#include <linux/delay.h>
11872 +
11873 +#include "bcm43xx.h"
11874 +#include "bcm43xx_main.h"
11875 +#include "bcm43xx_phy.h"
11876 +#include "bcm43xx_radio.h"
11877 +#include "bcm43xx_ilt.h"
11878 +
11879 +
11880 +/* Table for bcm43xx_radio_calibrationvalue() */
11881 +static const u16 rcc_table[16] = {
11882 + 0x0002, 0x0003, 0x0001, 0x000F,
11883 + 0x0006, 0x0007, 0x0005, 0x000F,
11884 + 0x000A, 0x000B, 0x0009, 0x000F,
11885 + 0x000E, 0x000F, 0x000D, 0x000F,
11886 +};
11887 +
11888 +/* Reverse the bits of a 4bit value.
11889 + * Example: 1101 is flipped 1011
11890 + */
11891 +static u16 flip_4bit(u16 value)
11892 +{
11893 + u16 flipped = 0x0000;
11894 +
11895 + assert((value & ~0x000F) == 0x0000);
11896 +
11897 + flipped |= (value & 0x0001) << 3;
11898 + flipped |= (value & 0x0002) << 1;
11899 + flipped |= (value & 0x0004) >> 1;
11900 + flipped |= (value & 0x0008) >> 3;
11901 +
11902 + return flipped;
11903 +}
11904 +
11905 +/* Get the freq, as it has to be written to the device. */
11906 +static inline
11907 +u16 channel2freq_bg(u8 channel)
11908 +{
11909 + /* Frequencies are given as frequencies_bg[index] + 2.4GHz
11910 + * Starting with channel 1
11911 + */
11912 + static const u16 frequencies_bg[14] = {
11913 + 12, 17, 22, 27,
11914 + 32, 37, 42, 47,
11915 + 52, 57, 62, 67,
11916 + 72, 84,
11917 + };
11918 +
11919 + assert(channel >= 1 && channel <= 14);
11920 +
11921 + return frequencies_bg[channel - 1];
11922 +}
11923 +
11924 +/* Get the freq, as it has to be written to the device. */
11925 +static inline
11926 +u16 channel2freq_a(u8 channel)
11927 +{
11928 + assert(channel <= 200);
11929 +
11930 + return (5000 + 5 * channel);
11931 +}
11932 +
11933 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm)
11934 +{
11935 + u32 status;
11936 +
11937 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11938 + status |= BCM43xx_SBF_RADIOREG_LOCK;
11939 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
11940 + mmiowb();
11941 + udelay(10);
11942 +}
11943 +
11944 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm)
11945 +{
11946 + u32 status;
11947 +
11948 + bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER); /* dummy read */
11949 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11950 + status &= ~BCM43xx_SBF_RADIOREG_LOCK;
11951 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
11952 + mmiowb();
11953 +}
11954 +
11955 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset)
11956 +{
11957 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
11958 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
11959 +
11960 + switch (phy->type) {
11961 + case BCM43xx_PHYTYPE_A:
11962 + offset |= 0x0040;
11963 + break;
11964 + case BCM43xx_PHYTYPE_B:
11965 + if (radio->version == 0x2053) {
11966 + if (offset < 0x70)
11967 + offset += 0x80;
11968 + else if (offset < 0x80)
11969 + offset += 0x70;
11970 + } else if (radio->version == 0x2050) {
11971 + offset |= 0x80;
11972 + } else
11973 + assert(0);
11974 + break;
11975 + case BCM43xx_PHYTYPE_G:
11976 + offset |= 0x80;
11977 + break;
11978 + }
11979 +
11980 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
11981 + return bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
11982 +}
11983 +
11984 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val)
11985 +{
11986 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
11987 + mmiowb();
11988 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW, val);
11989 +}
11990 +
11991 +static void bcm43xx_set_all_gains(struct bcm43xx_private *bcm,
11992 + s16 first, s16 second, s16 third)
11993 +{
11994 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
11995 + u16 i;
11996 + u16 start = 0x08, end = 0x18;
11997 + u16 offset = 0x0400;
11998 + u16 tmp;
11999 +
12000 + if (phy->rev <= 1) {
12001 + offset = 0x5000;
12002 + start = 0x10;
12003 + end = 0x20;
12004 + }
12005 +
12006 + for (i = 0; i < 4; i++)
12007 + bcm43xx_ilt_write(bcm, offset + i, first);
12008 +
12009 + for (i = start; i < end; i++)
12010 + bcm43xx_ilt_write(bcm, offset + i, second);
12011 +
12012 + if (third != -1) {
12013 + tmp = ((u16)third << 14) | ((u16)third << 6);
12014 + bcm43xx_phy_write(bcm, 0x04A0,
12015 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | tmp);
12016 + bcm43xx_phy_write(bcm, 0x04A1,
12017 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | tmp);
12018 + bcm43xx_phy_write(bcm, 0x04A2,
12019 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | tmp);
12020 + }
12021 + bcm43xx_dummy_transmission(bcm);
12022 +}
12023 +
12024 +static void bcm43xx_set_original_gains(struct bcm43xx_private *bcm)
12025 +{
12026 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12027 + u16 i, tmp;
12028 + u16 offset = 0x0400;
12029 + u16 start = 0x0008, end = 0x0018;
12030 +
12031 + if (phy->rev <= 1) {
12032 + offset = 0x5000;
12033 + start = 0x0010;
12034 + end = 0x0020;
12035 + }
12036 +
12037 + for (i = 0; i < 4; i++) {
12038 + tmp = (i & 0xFFFC);
12039 + tmp |= (i & 0x0001) << 1;
12040 + tmp |= (i & 0x0002) >> 1;
12041 +
12042 + bcm43xx_ilt_write(bcm, offset + i, tmp);
12043 + }
12044 +
12045 + for (i = start; i < end; i++)
12046 + bcm43xx_ilt_write(bcm, offset + i, i - start);
12047 +
12048 + bcm43xx_phy_write(bcm, 0x04A0,
12049 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | 0x4040);
12050 + bcm43xx_phy_write(bcm, 0x04A1,
12051 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | 0x4040);
12052 + bcm43xx_phy_write(bcm, 0x04A2,
12053 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | 0x4000);
12054 + bcm43xx_dummy_transmission(bcm);
12055 +}
12056 +
12057 +/* Synthetic PU workaround */
12058 +static void bcm43xx_synth_pu_workaround(struct bcm43xx_private *bcm, u8 channel)
12059 +{
12060 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12061 +
12062 + if (radio->version != 0x2050 || radio->revision >= 6) {
12063 + /* We do not need the workaround. */
12064 + return;
12065 + }
12066 +
12067 + if (channel <= 10) {
12068 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12069 + channel2freq_bg(channel + 4));
12070 + } else {
12071 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12072 + channel2freq_bg(1));
12073 + }
12074 + udelay(100);
12075 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12076 + channel2freq_bg(channel));
12077 +}
12078 +
12079 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel)
12080 +{
12081 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12082 + u8 ret = 0;
12083 + u16 saved, rssi, temp;
12084 + int i, j = 0;
12085 +
12086 + saved = bcm43xx_phy_read(bcm, 0x0403);
12087 + bcm43xx_radio_selectchannel(bcm, channel, 0);
12088 + bcm43xx_phy_write(bcm, 0x0403, (saved & 0xFFF8) | 5);
12089 + if (radio->aci_hw_rssi)
12090 + rssi = bcm43xx_phy_read(bcm, 0x048A) & 0x3F;
12091 + else
12092 + rssi = saved & 0x3F;
12093 + /* clamp temp to signed 5bit */
12094 + if (rssi > 32)
12095 + rssi -= 64;
12096 + for (i = 0;i < 100; i++) {
12097 + temp = (bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x3F;
12098 + if (temp > 32)
12099 + temp -= 64;
12100 + if (temp < rssi)
12101 + j++;
12102 + if (j >= 20)
12103 + ret = 1;
12104 + }
12105 + bcm43xx_phy_write(bcm, 0x0403, saved);
12106 +
12107 + return ret;
12108 +}
12109 +
12110 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm)
12111 +{
12112 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12113 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12114 + u8 ret[13];
12115 + unsigned int channel = radio->channel;
12116 + unsigned int i, j, start, end;
12117 + unsigned long phylock_flags;
12118 +
12119 + if (!((phy->type == BCM43xx_PHYTYPE_G) && (phy->rev > 0)))
12120 + return 0;
12121 +
12122 + bcm43xx_phy_lock(bcm, phylock_flags);
12123 + bcm43xx_radio_lock(bcm);
12124 + bcm43xx_phy_write(bcm, 0x0802,
12125 + bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
12126 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12127 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
12128 + bcm43xx_set_all_gains(bcm, 3, 8, 1);
12129 +
12130 + start = (channel - 5 > 0) ? channel - 5 : 1;
12131 + end = (channel + 5 < 14) ? channel + 5 : 13;
12132 +
12133 + for (i = start; i <= end; i++) {
12134 + if (abs(channel - i) > 2)
12135 + ret[i-1] = bcm43xx_radio_aci_detect(bcm, i);
12136 + }
12137 + bcm43xx_radio_selectchannel(bcm, channel, 0);
12138 + bcm43xx_phy_write(bcm, 0x0802,
12139 + (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC) | 0x0003);
12140 + bcm43xx_phy_write(bcm, 0x0403,
12141 + bcm43xx_phy_read(bcm, 0x0403) & 0xFFF8);
12142 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12143 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
12144 + bcm43xx_set_original_gains(bcm);
12145 + for (i = 0; i < 13; i++) {
12146 + if (!ret[i])
12147 + continue;
12148 + end = (i + 5 < 13) ? i + 5 : 13;
12149 + for (j = i; j < end; j++)
12150 + ret[j] = 1;
12151 + }
12152 + bcm43xx_radio_unlock(bcm);
12153 + bcm43xx_phy_unlock(bcm, phylock_flags);
12154 +
12155 + return ret[channel - 1];
12156 +}
12157 +
12158 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12159 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val)
12160 +{
12161 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12162 + mmiowb();
12163 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_DATA, (u16)val);
12164 +}
12165 +
12166 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12167 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset)
12168 +{
12169 + u16 val;
12170 +
12171 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12172 + val = bcm43xx_phy_read(bcm, BCM43xx_PHY_NRSSILT_DATA);
12173 +
12174 + return (s16)val;
12175 +}
12176 +
12177 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12178 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val)
12179 +{
12180 + u16 i;
12181 + s16 tmp;
12182 +
12183 + for (i = 0; i < 64; i++) {
12184 + tmp = bcm43xx_nrssi_hw_read(bcm, i);
12185 + tmp -= val;
12186 + tmp = limit_value(tmp, -32, 31);
12187 + bcm43xx_nrssi_hw_write(bcm, i, tmp);
12188 + }
12189 +}
12190 +
12191 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12192 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm)
12193 +{
12194 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12195 + s16 i, delta;
12196 + s32 tmp;
12197 +
12198 + delta = 0x1F - radio->nrssi[0];
12199 + for (i = 0; i < 64; i++) {
12200 + tmp = (i - delta) * radio->nrssislope;
12201 + tmp /= 0x10000;
12202 + tmp += 0x3A;
12203 + tmp = limit_value(tmp, 0, 0x3F);
12204 + radio->nrssi_lt[i] = tmp;
12205 + }
12206 +}
12207 +
12208 +static void bcm43xx_calc_nrssi_offset(struct bcm43xx_private *bcm)
12209 +{
12210 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12211 + u16 backup[20] = { 0 };
12212 + s16 v47F;
12213 + u16 i;
12214 + u16 saved = 0xFFFF;
12215 +
12216 + backup[0] = bcm43xx_phy_read(bcm, 0x0001);
12217 + backup[1] = bcm43xx_phy_read(bcm, 0x0811);
12218 + backup[2] = bcm43xx_phy_read(bcm, 0x0812);
12219 + backup[3] = bcm43xx_phy_read(bcm, 0x0814);
12220 + backup[4] = bcm43xx_phy_read(bcm, 0x0815);
12221 + backup[5] = bcm43xx_phy_read(bcm, 0x005A);
12222 + backup[6] = bcm43xx_phy_read(bcm, 0x0059);
12223 + backup[7] = bcm43xx_phy_read(bcm, 0x0058);
12224 + backup[8] = bcm43xx_phy_read(bcm, 0x000A);
12225 + backup[9] = bcm43xx_phy_read(bcm, 0x0003);
12226 + backup[10] = bcm43xx_radio_read16(bcm, 0x007A);
12227 + backup[11] = bcm43xx_radio_read16(bcm, 0x0043);
12228 +
12229 + bcm43xx_phy_write(bcm, 0x0429,
12230 + bcm43xx_phy_read(bcm, 0x0429) & 0x7FFF);
12231 + bcm43xx_phy_write(bcm, 0x0001,
12232 + (bcm43xx_phy_read(bcm, 0x0001) & 0x3FFF) | 0x4000);
12233 + bcm43xx_phy_write(bcm, 0x0811,
12234 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
12235 + bcm43xx_phy_write(bcm, 0x0812,
12236 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFF3) | 0x0004);
12237 + bcm43xx_phy_write(bcm, 0x0802,
12238 + bcm43xx_phy_read(bcm, 0x0802) & ~(0x1 | 0x2));
12239 + if (phy->rev >= 6) {
12240 + backup[12] = bcm43xx_phy_read(bcm, 0x002E);
12241 + backup[13] = bcm43xx_phy_read(bcm, 0x002F);
12242 + backup[14] = bcm43xx_phy_read(bcm, 0x080F);
12243 + backup[15] = bcm43xx_phy_read(bcm, 0x0810);
12244 + backup[16] = bcm43xx_phy_read(bcm, 0x0801);
12245 + backup[17] = bcm43xx_phy_read(bcm, 0x0060);
12246 + backup[18] = bcm43xx_phy_read(bcm, 0x0014);
12247 + backup[19] = bcm43xx_phy_read(bcm, 0x0478);
12248 +
12249 + bcm43xx_phy_write(bcm, 0x002E, 0);
12250 + bcm43xx_phy_write(bcm, 0x002F, 0);
12251 + bcm43xx_phy_write(bcm, 0x080F, 0);
12252 + bcm43xx_phy_write(bcm, 0x0810, 0);
12253 + bcm43xx_phy_write(bcm, 0x0478,
12254 + bcm43xx_phy_read(bcm, 0x0478) | 0x0100);
12255 + bcm43xx_phy_write(bcm, 0x0801,
12256 + bcm43xx_phy_read(bcm, 0x0801) | 0x0040);
12257 + bcm43xx_phy_write(bcm, 0x0060,
12258 + bcm43xx_phy_read(bcm, 0x0060) | 0x0040);
12259 + bcm43xx_phy_write(bcm, 0x0014,
12260 + bcm43xx_phy_read(bcm, 0x0014) | 0x0200);
12261 + }
12262 + bcm43xx_radio_write16(bcm, 0x007A,
12263 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
12264 + bcm43xx_radio_write16(bcm, 0x007A,
12265 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12266 + udelay(30);
12267 +
12268 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12269 + if (v47F >= 0x20)
12270 + v47F -= 0x40;
12271 + if (v47F == 31) {
12272 + for (i = 7; i >= 4; i--) {
12273 + bcm43xx_radio_write16(bcm, 0x007B, i);
12274 + udelay(20);
12275 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12276 + if (v47F >= 0x20)
12277 + v47F -= 0x40;
12278 + if (v47F < 31 && saved == 0xFFFF)
12279 + saved = i;
12280 + }
12281 + if (saved == 0xFFFF)
12282 + saved = 4;
12283 + } else {
12284 + bcm43xx_radio_write16(bcm, 0x007A,
12285 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12286 + bcm43xx_phy_write(bcm, 0x0814,
12287 + bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
12288 + bcm43xx_phy_write(bcm, 0x0815,
12289 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
12290 + bcm43xx_phy_write(bcm, 0x0811,
12291 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
12292 + bcm43xx_phy_write(bcm, 0x0812,
12293 + bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
12294 + bcm43xx_phy_write(bcm, 0x0811,
12295 + bcm43xx_phy_read(bcm, 0x0811) | 0x0030);
12296 + bcm43xx_phy_write(bcm, 0x0812,
12297 + bcm43xx_phy_read(bcm, 0x0812) | 0x0030);
12298 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12299 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12300 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12301 + if (phy->rev == 0) {
12302 + bcm43xx_phy_write(bcm, 0x0003, 0x0122);
12303 + } else {
12304 + bcm43xx_phy_write(bcm, 0x000A,
12305 + bcm43xx_phy_read(bcm, 0x000A)
12306 + | 0x2000);
12307 + }
12308 + bcm43xx_phy_write(bcm, 0x0814,
12309 + bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
12310 + bcm43xx_phy_write(bcm, 0x0815,
12311 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
12312 + bcm43xx_phy_write(bcm, 0x0003,
12313 + (bcm43xx_phy_read(bcm, 0x0003) & 0xFF9F)
12314 + | 0x0040);
12315 + bcm43xx_radio_write16(bcm, 0x007A,
12316 + bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
12317 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12318 + bcm43xx_radio_write16(bcm, 0x0043,
12319 + (bcm43xx_radio_read16(bcm, 0x0043)
12320 + & 0x00F0) | 0x000F);
12321 + udelay(30);
12322 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12323 + if (v47F >= 0x20)
12324 + v47F -= 0x40;
12325 + if (v47F == -32) {
12326 + for (i = 0; i < 4; i++) {
12327 + bcm43xx_radio_write16(bcm, 0x007B, i);
12328 + udelay(20);
12329 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12330 + if (v47F >= 0x20)
12331 + v47F -= 0x40;
12332 + if (v47F > -31 && saved == 0xFFFF)
12333 + saved = i;
12334 + }
12335 + if (saved == 0xFFFF)
12336 + saved = 3;
12337 + } else
12338 + saved = 0;
12339 + }
12340 + bcm43xx_radio_write16(bcm, 0x007B, saved);
12341 +
12342 + if (phy->rev >= 6) {
12343 + bcm43xx_phy_write(bcm, 0x002E, backup[12]);
12344 + bcm43xx_phy_write(bcm, 0x002F, backup[13]);
12345 + bcm43xx_phy_write(bcm, 0x080F, backup[14]);
12346 + bcm43xx_phy_write(bcm, 0x0810, backup[15]);
12347 + }
12348 + bcm43xx_phy_write(bcm, 0x0814, backup[3]);
12349 + bcm43xx_phy_write(bcm, 0x0815, backup[4]);
12350 + bcm43xx_phy_write(bcm, 0x005A, backup[5]);
12351 + bcm43xx_phy_write(bcm, 0x0059, backup[6]);
12352 + bcm43xx_phy_write(bcm, 0x0058, backup[7]);
12353 + bcm43xx_phy_write(bcm, 0x000A, backup[8]);
12354 + bcm43xx_phy_write(bcm, 0x0003, backup[9]);
12355 + bcm43xx_radio_write16(bcm, 0x0043, backup[11]);
12356 + bcm43xx_radio_write16(bcm, 0x007A, backup[10]);
12357 + bcm43xx_phy_write(bcm, 0x0802,
12358 + bcm43xx_phy_read(bcm, 0x0802) | 0x1 | 0x2);
12359 + bcm43xx_phy_write(bcm, 0x0429,
12360 + bcm43xx_phy_read(bcm, 0x0429) | 0x8000);
12361 + bcm43xx_set_original_gains(bcm);
12362 + if (phy->rev >= 6) {
12363 + bcm43xx_phy_write(bcm, 0x0801, backup[16]);
12364 + bcm43xx_phy_write(bcm, 0x0060, backup[17]);
12365 + bcm43xx_phy_write(bcm, 0x0014, backup[18]);
12366 + bcm43xx_phy_write(bcm, 0x0478, backup[19]);
12367 + }
12368 + bcm43xx_phy_write(bcm, 0x0001, backup[0]);
12369 + bcm43xx_phy_write(bcm, 0x0812, backup[2]);
12370 + bcm43xx_phy_write(bcm, 0x0811, backup[1]);
12371 +}
12372 +
12373 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm)
12374 +{
12375 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12376 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12377 + u16 backup[18] = { 0 };
12378 + u16 tmp;
12379 + s16 nrssi0, nrssi1;
12380 +
12381 + switch (phy->type) {
12382 + case BCM43xx_PHYTYPE_B:
12383 + backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
12384 + backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
12385 + backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
12386 + backup[3] = bcm43xx_phy_read(bcm, 0x0030);
12387 + backup[4] = bcm43xx_phy_read(bcm, 0x0026);
12388 + backup[5] = bcm43xx_phy_read(bcm, 0x0015);
12389 + backup[6] = bcm43xx_phy_read(bcm, 0x002A);
12390 + backup[7] = bcm43xx_phy_read(bcm, 0x0020);
12391 + backup[8] = bcm43xx_phy_read(bcm, 0x005A);
12392 + backup[9] = bcm43xx_phy_read(bcm, 0x0059);
12393 + backup[10] = bcm43xx_phy_read(bcm, 0x0058);
12394 + backup[11] = bcm43xx_read16(bcm, 0x03E2);
12395 + backup[12] = bcm43xx_read16(bcm, 0x03E6);
12396 + backup[13] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
12397 +
12398 + tmp = bcm43xx_radio_read16(bcm, 0x007A);
12399 + tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
12400 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
12401 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
12402 + bcm43xx_write16(bcm, 0x03EC, 0x7F7F);
12403 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
12404 + bcm43xx_phy_write(bcm, 0x0015,
12405 + bcm43xx_phy_read(bcm, 0x0015) | 0x0020);
12406 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
12407 + bcm43xx_radio_write16(bcm, 0x007A,
12408 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12409 +
12410 + nrssi0 = (s16)bcm43xx_phy_read(bcm, 0x0027);
12411 + bcm43xx_radio_write16(bcm, 0x007A,
12412 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12413 + if (phy->rev >= 2) {
12414 + bcm43xx_write16(bcm, 0x03E6, 0x0040);
12415 + } else if (phy->rev == 0) {
12416 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
12417 + } else {
12418 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12419 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) & 0x2000);
12420 + }
12421 + bcm43xx_phy_write(bcm, 0x0020, 0x3F3F);
12422 + bcm43xx_phy_write(bcm, 0x0015, 0xF330);
12423 + bcm43xx_radio_write16(bcm, 0x005A, 0x0060);
12424 + bcm43xx_radio_write16(bcm, 0x0043,
12425 + bcm43xx_radio_read16(bcm, 0x0043) & 0x00F0);
12426 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12427 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12428 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12429 + udelay(20);
12430 +
12431 + nrssi1 = (s16)bcm43xx_phy_read(bcm, 0x0027);
12432 + bcm43xx_phy_write(bcm, 0x0030, backup[3]);
12433 + bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
12434 + bcm43xx_write16(bcm, 0x03E2, backup[11]);
12435 + bcm43xx_phy_write(bcm, 0x0026, backup[4]);
12436 + bcm43xx_phy_write(bcm, 0x0015, backup[5]);
12437 + bcm43xx_phy_write(bcm, 0x002A, backup[6]);
12438 + bcm43xx_synth_pu_workaround(bcm, radio->channel);
12439 + if (phy->rev != 0)
12440 + bcm43xx_write16(bcm, 0x03F4, backup[13]);
12441 +
12442 + bcm43xx_phy_write(bcm, 0x0020, backup[7]);
12443 + bcm43xx_phy_write(bcm, 0x005A, backup[8]);
12444 + bcm43xx_phy_write(bcm, 0x0059, backup[9]);
12445 + bcm43xx_phy_write(bcm, 0x0058, backup[10]);
12446 + bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
12447 + bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
12448 +
12449 + if (nrssi0 == nrssi1)
12450 + radio->nrssislope = 0x00010000;
12451 + else
12452 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12453 +
12454 + if (nrssi0 <= -4) {
12455 + radio->nrssi[0] = nrssi0;
12456 + radio->nrssi[1] = nrssi1;
12457 + }
12458 + break;
12459 + case BCM43xx_PHYTYPE_G:
12460 + if (radio->revision >= 9)
12461 + return;
12462 + if (radio->revision == 8)
12463 + bcm43xx_calc_nrssi_offset(bcm);
12464 +
12465 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12466 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
12467 + bcm43xx_phy_write(bcm, 0x0802,
12468 + bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
12469 + backup[7] = bcm43xx_read16(bcm, 0x03E2);
12470 + bcm43xx_write16(bcm, 0x03E2,
12471 + bcm43xx_read16(bcm, 0x03E2) | 0x8000);
12472 + backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
12473 + backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
12474 + backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
12475 + backup[3] = bcm43xx_phy_read(bcm, 0x0015);
12476 + backup[4] = bcm43xx_phy_read(bcm, 0x005A);
12477 + backup[5] = bcm43xx_phy_read(bcm, 0x0059);
12478 + backup[6] = bcm43xx_phy_read(bcm, 0x0058);
12479 + backup[8] = bcm43xx_read16(bcm, 0x03E6);
12480 + backup[9] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
12481 + if (phy->rev >= 3) {
12482 + backup[10] = bcm43xx_phy_read(bcm, 0x002E);
12483 + backup[11] = bcm43xx_phy_read(bcm, 0x002F);
12484 + backup[12] = bcm43xx_phy_read(bcm, 0x080F);
12485 + backup[13] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_LO_CONTROL);
12486 + backup[14] = bcm43xx_phy_read(bcm, 0x0801);
12487 + backup[15] = bcm43xx_phy_read(bcm, 0x0060);
12488 + backup[16] = bcm43xx_phy_read(bcm, 0x0014);
12489 + backup[17] = bcm43xx_phy_read(bcm, 0x0478);
12490 + bcm43xx_phy_write(bcm, 0x002E, 0);
12491 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, 0);
12492 + switch (phy->rev) {
12493 + case 4: case 6: case 7:
12494 + bcm43xx_phy_write(bcm, 0x0478,
12495 + bcm43xx_phy_read(bcm, 0x0478)
12496 + | 0x0100);
12497 + bcm43xx_phy_write(bcm, 0x0801,
12498 + bcm43xx_phy_read(bcm, 0x0801)
12499 + | 0x0040);
12500 + break;
12501 + case 3: case 5:
12502 + bcm43xx_phy_write(bcm, 0x0801,
12503 + bcm43xx_phy_read(bcm, 0x0801)
12504 + & 0xFFBF);
12505 + break;
12506 + }
12507 + bcm43xx_phy_write(bcm, 0x0060,
12508 + bcm43xx_phy_read(bcm, 0x0060)
12509 + | 0x0040);
12510 + bcm43xx_phy_write(bcm, 0x0014,
12511 + bcm43xx_phy_read(bcm, 0x0014)
12512 + | 0x0200);
12513 + }
12514 + bcm43xx_radio_write16(bcm, 0x007A,
12515 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
12516 + bcm43xx_set_all_gains(bcm, 0, 8, 0);
12517 + bcm43xx_radio_write16(bcm, 0x007A,
12518 + bcm43xx_radio_read16(bcm, 0x007A) & 0x00F7);
12519 + if (phy->rev >= 2) {
12520 + bcm43xx_phy_write(bcm, 0x0811,
12521 + (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0030);
12522 + bcm43xx_phy_write(bcm, 0x0812,
12523 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0010);
12524 + }
12525 + bcm43xx_radio_write16(bcm, 0x007A,
12526 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12527 + udelay(20);
12528 +
12529 + nrssi0 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12530 + if (nrssi0 >= 0x0020)
12531 + nrssi0 -= 0x0040;
12532 +
12533 + bcm43xx_radio_write16(bcm, 0x007A,
12534 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12535 + if (phy->rev >= 2) {
12536 + bcm43xx_phy_write(bcm, 0x0003,
12537 + (bcm43xx_phy_read(bcm, 0x0003)
12538 + & 0xFF9F) | 0x0040);
12539 + }
12540 +
12541 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12542 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
12543 + | 0x2000);
12544 + bcm43xx_radio_write16(bcm, 0x007A,
12545 + bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
12546 + bcm43xx_phy_write(bcm, 0x0015, 0xF330);
12547 + if (phy->rev >= 2) {
12548 + bcm43xx_phy_write(bcm, 0x0812,
12549 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0020);
12550 + bcm43xx_phy_write(bcm, 0x0811,
12551 + (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0020);
12552 + }
12553 +
12554 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12555 + if (radio->revision == 8) {
12556 + bcm43xx_radio_write16(bcm, 0x0043, 0x001F);
12557 + } else {
12558 + tmp = bcm43xx_radio_read16(bcm, 0x0052) & 0xFF0F;
12559 + bcm43xx_radio_write16(bcm, 0x0052, tmp | 0x0060);
12560 + tmp = bcm43xx_radio_read16(bcm, 0x0043) & 0xFFF0;
12561 + bcm43xx_radio_write16(bcm, 0x0043, tmp | 0x0009);
12562 + }
12563 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12564 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12565 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12566 + udelay(20);
12567 + nrssi1 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12568 + if (nrssi1 >= 0x0020)
12569 + nrssi1 -= 0x0040;
12570 + if (nrssi0 == nrssi1)
12571 + radio->nrssislope = 0x00010000;
12572 + else
12573 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12574 + if (nrssi0 >= -4) {
12575 + radio->nrssi[0] = nrssi1;
12576 + radio->nrssi[1] = nrssi0;
12577 + }
12578 + if (phy->rev >= 3) {
12579 + bcm43xx_phy_write(bcm, 0x002E, backup[10]);
12580 + bcm43xx_phy_write(bcm, 0x002F, backup[11]);
12581 + bcm43xx_phy_write(bcm, 0x080F, backup[12]);
12582 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, backup[13]);
12583 + }
12584 + if (phy->rev >= 2) {
12585 + bcm43xx_phy_write(bcm, 0x0812,
12586 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF);
12587 + bcm43xx_phy_write(bcm, 0x0811,
12588 + bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF);
12589 + }
12590 +
12591 + bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
12592 + bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
12593 + bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
12594 + bcm43xx_write16(bcm, 0x03E2, backup[7]);
12595 + bcm43xx_write16(bcm, 0x03E6, backup[8]);
12596 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[9]);
12597 + bcm43xx_phy_write(bcm, 0x0015, backup[3]);
12598 + bcm43xx_phy_write(bcm, 0x005A, backup[4]);
12599 + bcm43xx_phy_write(bcm, 0x0059, backup[5]);
12600 + bcm43xx_phy_write(bcm, 0x0058, backup[6]);
12601 + bcm43xx_synth_pu_workaround(bcm, radio->channel);
12602 + bcm43xx_phy_write(bcm, 0x0802,
12603 + bcm43xx_phy_read(bcm, 0x0802) | (0x0001 | 0x0002));
12604 + bcm43xx_set_original_gains(bcm);
12605 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12606 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
12607 + if (phy->rev >= 3) {
12608 + bcm43xx_phy_write(bcm, 0x0801, backup[14]);
12609 + bcm43xx_phy_write(bcm, 0x0060, backup[15]);
12610 + bcm43xx_phy_write(bcm, 0x0014, backup[16]);
12611 + bcm43xx_phy_write(bcm, 0x0478, backup[17]);
12612 + }
12613 + bcm43xx_nrssi_mem_update(bcm);
12614 + bcm43xx_calc_nrssi_threshold(bcm);
12615 + break;
12616 + default:
12617 + assert(0);
12618 + }
12619 +}
12620 +
12621 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm)
12622 +{
12623 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12624 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12625 + s32 threshold;
12626 + s32 a, b;
12627 + s16 tmp16;
12628 + u16 tmp_u16;
12629 +
12630 + switch (phy->type) {
12631 + case BCM43xx_PHYTYPE_B: {
12632 + if (radio->version != 0x2050)
12633 + return;
12634 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI))
12635 + return;
12636 +
12637 + if (radio->revision >= 6) {
12638 + threshold = (radio->nrssi[1] - radio->nrssi[0]) * 32;
12639 + threshold += 20 * (radio->nrssi[0] + 1);
12640 + threshold /= 40;
12641 + } else
12642 + threshold = radio->nrssi[1] - 5;
12643 +
12644 + threshold = limit_value(threshold, 0, 0x3E);
12645 + bcm43xx_phy_read(bcm, 0x0020); /* dummy read */
12646 + bcm43xx_phy_write(bcm, 0x0020, (((u16)threshold) << 8) | 0x001C);
12647 +
12648 + if (radio->revision >= 6) {
12649 + bcm43xx_phy_write(bcm, 0x0087, 0x0E0D);
12650 + bcm43xx_phy_write(bcm, 0x0086, 0x0C0B);
12651 + bcm43xx_phy_write(bcm, 0x0085, 0x0A09);
12652 + bcm43xx_phy_write(bcm, 0x0084, 0x0808);
12653 + bcm43xx_phy_write(bcm, 0x0083, 0x0808);
12654 + bcm43xx_phy_write(bcm, 0x0082, 0x0604);
12655 + bcm43xx_phy_write(bcm, 0x0081, 0x0302);
12656 + bcm43xx_phy_write(bcm, 0x0080, 0x0100);
12657 + }
12658 + break;
12659 + }
12660 + case BCM43xx_PHYTYPE_G:
12661 + if (!phy->connected ||
12662 + !(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
12663 + tmp16 = bcm43xx_nrssi_hw_read(bcm, 0x20);
12664 + if (tmp16 >= 0x20)
12665 + tmp16 -= 0x40;
12666 + if (tmp16 < 3) {
12667 + bcm43xx_phy_write(bcm, 0x048A,
12668 + (bcm43xx_phy_read(bcm, 0x048A)
12669 + & 0xF000) | 0x09EB);
12670 + } else {
12671 + bcm43xx_phy_write(bcm, 0x048A,
12672 + (bcm43xx_phy_read(bcm, 0x048A)
12673 + & 0xF000) | 0x0AED);
12674 + }
12675 + } else {
12676 + if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
12677 + a = 0xE;
12678 + b = 0xA;
12679 + } else if (!radio->aci_wlan_automatic && radio->aci_enable) {
12680 + a = 0x13;
12681 + b = 0x12;
12682 + } else {
12683 + a = 0xE;
12684 + b = 0x11;
12685 + }
12686 +
12687 + a = a * (radio->nrssi[1] - radio->nrssi[0]);
12688 + a += (radio->nrssi[0] << 6);
12689 + if (a < 32)
12690 + a += 31;
12691 + else
12692 + a += 32;
12693 + a = a >> 6;
12694 + a = limit_value(a, -31, 31);
12695 +
12696 + b = b * (radio->nrssi[1] - radio->nrssi[0]);
12697 + b += (radio->nrssi[0] << 6);
12698 + if (b < 32)
12699 + b += 31;
12700 + else
12701 + b += 32;
12702 + b = b >> 6;
12703 + b = limit_value(b, -31, 31);
12704 +
12705 + tmp_u16 = bcm43xx_phy_read(bcm, 0x048A) & 0xF000;
12706 + tmp_u16 |= ((u32)b & 0x0000003F);
12707 + tmp_u16 |= (((u32)a & 0x0000003F) << 6);
12708 + bcm43xx_phy_write(bcm, 0x048A, tmp_u16);
12709 + }
12710 + break;
12711 + default:
12712 + assert(0);
12713 + }
12714 +}
12715 +
12716 +/* Stack implementation to save/restore values from the
12717 + * interference mitigation code.
12718 + * It is save to restore values in random order.
12719 + */
12720 +static void _stack_save(u32 *_stackptr, size_t *stackidx,
12721 + u8 id, u16 offset, u16 value)
12722 +{
12723 + u32 *stackptr = &(_stackptr[*stackidx]);
12724 +
12725 + assert((offset & 0xF000) == 0x0000);
12726 + assert((id & 0xF0) == 0x00);
12727 + *stackptr = offset;
12728 + *stackptr |= ((u32)id) << 12;
12729 + *stackptr |= ((u32)value) << 16;
12730 + (*stackidx)++;
12731 + assert(*stackidx < BCM43xx_INTERFSTACK_SIZE);
12732 +}
12733 +
12734 +static u16 _stack_restore(u32 *stackptr,
12735 + u8 id, u16 offset)
12736 +{
12737 + size_t i;
12738 +
12739 + assert((offset & 0xF000) == 0x0000);
12740 + assert((id & 0xF0) == 0x00);
12741 + for (i = 0; i < BCM43xx_INTERFSTACK_SIZE; i++, stackptr++) {
12742 + if ((*stackptr & 0x00000FFF) != offset)
12743 + continue;
12744 + if (((*stackptr & 0x0000F000) >> 12) != id)
12745 + continue;
12746 + return ((*stackptr & 0xFFFF0000) >> 16);
12747 + }
12748 + assert(0);
12749 +
12750 + return 0;
12751 +}
12752 +
12753 +#define phy_stacksave(offset) \
12754 + do { \
12755 + _stack_save(stack, &stackidx, 0x1, (offset), \
12756 + bcm43xx_phy_read(bcm, (offset))); \
12757 + } while (0)
12758 +#define phy_stackrestore(offset) \
12759 + do { \
12760 + bcm43xx_phy_write(bcm, (offset), \
12761 + _stack_restore(stack, 0x1, \
12762 + (offset))); \
12763 + } while (0)
12764 +#define radio_stacksave(offset) \
12765 + do { \
12766 + _stack_save(stack, &stackidx, 0x2, (offset), \
12767 + bcm43xx_radio_read16(bcm, (offset))); \
12768 + } while (0)
12769 +#define radio_stackrestore(offset) \
12770 + do { \
12771 + bcm43xx_radio_write16(bcm, (offset), \
12772 + _stack_restore(stack, 0x2, \
12773 + (offset))); \
12774 + } while (0)
12775 +#define ilt_stacksave(offset) \
12776 + do { \
12777 + _stack_save(stack, &stackidx, 0x3, (offset), \
12778 + bcm43xx_ilt_read(bcm, (offset))); \
12779 + } while (0)
12780 +#define ilt_stackrestore(offset) \
12781 + do { \
12782 + bcm43xx_ilt_write(bcm, (offset), \
12783 + _stack_restore(stack, 0x3, \
12784 + (offset))); \
12785 + } while (0)
12786 +
12787 +static void
12788 +bcm43xx_radio_interference_mitigation_enable(struct bcm43xx_private *bcm,
12789 + int mode)
12790 +{
12791 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12792 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12793 + u16 tmp, flipped;
12794 + u32 tmp32;
12795 + size_t stackidx = 0;
12796 + u32 *stack = radio->interfstack;
12797 +
12798 + switch (mode) {
12799 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
12800 + if (phy->rev != 1) {
12801 + bcm43xx_phy_write(bcm, 0x042B,
12802 + bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
12803 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12804 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & ~0x4000);
12805 + break;
12806 + }
12807 + radio_stacksave(0x0078);
12808 + tmp = (bcm43xx_radio_read16(bcm, 0x0078) & 0x001E);
12809 + flipped = flip_4bit(tmp);
12810 + if (flipped < 10 && flipped >= 8)
12811 + flipped = 7;
12812 + else if (flipped >= 10)
12813 + flipped -= 3;
12814 + flipped = flip_4bit(flipped);
12815 + flipped = (flipped << 1) | 0x0020;
12816 + bcm43xx_radio_write16(bcm, 0x0078, flipped);
12817 +
12818 + bcm43xx_calc_nrssi_threshold(bcm);
12819 +
12820 + phy_stacksave(0x0406);
12821 + bcm43xx_phy_write(bcm, 0x0406, 0x7E28);
12822 +
12823 + bcm43xx_phy_write(bcm, 0x042B,
12824 + bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
12825 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
12826 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | 0x1000);
12827 +
12828 + phy_stacksave(0x04A0);
12829 + bcm43xx_phy_write(bcm, 0x04A0,
12830 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xC0C0) | 0x0008);
12831 + phy_stacksave(0x04A1);
12832 + bcm43xx_phy_write(bcm, 0x04A1,
12833 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xC0C0) | 0x0605);
12834 + phy_stacksave(0x04A2);
12835 + bcm43xx_phy_write(bcm, 0x04A2,
12836 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xC0C0) | 0x0204);
12837 + phy_stacksave(0x04A8);
12838 + bcm43xx_phy_write(bcm, 0x04A8,
12839 + (bcm43xx_phy_read(bcm, 0x04A8) & 0xC0C0) | 0x0803);
12840 + phy_stacksave(0x04AB);
12841 + bcm43xx_phy_write(bcm, 0x04AB,
12842 + (bcm43xx_phy_read(bcm, 0x04AB) & 0xC0C0) | 0x0605);
12843 +
12844 + phy_stacksave(0x04A7);
12845 + bcm43xx_phy_write(bcm, 0x04A7, 0x0002);
12846 + phy_stacksave(0x04A3);
12847 + bcm43xx_phy_write(bcm, 0x04A3, 0x287A);
12848 + phy_stacksave(0x04A9);
12849 + bcm43xx_phy_write(bcm, 0x04A9, 0x2027);
12850 + phy_stacksave(0x0493);
12851 + bcm43xx_phy_write(bcm, 0x0493, 0x32F5);
12852 + phy_stacksave(0x04AA);
12853 + bcm43xx_phy_write(bcm, 0x04AA, 0x2027);
12854 + phy_stacksave(0x04AC);
12855 + bcm43xx_phy_write(bcm, 0x04AC, 0x32F5);
12856 + break;
12857 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
12858 + if (bcm43xx_phy_read(bcm, 0x0033) & 0x0800)
12859 + break;
12860 +
12861 + radio->aci_enable = 1;
12862 +
12863 + phy_stacksave(BCM43xx_PHY_RADIO_BITFIELD);
12864 + phy_stacksave(BCM43xx_PHY_G_CRS);
12865 + if (phy->rev < 2) {
12866 + phy_stacksave(0x0406);
12867 + } else {
12868 + phy_stacksave(0x04C0);
12869 + phy_stacksave(0x04C1);
12870 + }
12871 + phy_stacksave(0x0033);
12872 + phy_stacksave(0x04A7);
12873 + phy_stacksave(0x04A3);
12874 + phy_stacksave(0x04A9);
12875 + phy_stacksave(0x04AA);
12876 + phy_stacksave(0x04AC);
12877 + phy_stacksave(0x0493);
12878 + phy_stacksave(0x04A1);
12879 + phy_stacksave(0x04A0);
12880 + phy_stacksave(0x04A2);
12881 + phy_stacksave(0x048A);
12882 + phy_stacksave(0x04A8);
12883 + phy_stacksave(0x04AB);
12884 + if (phy->rev == 2) {
12885 + phy_stacksave(0x04AD);
12886 + phy_stacksave(0x04AE);
12887 + } else if (phy->rev >= 3) {
12888 + phy_stacksave(0x04AD);
12889 + phy_stacksave(0x0415);
12890 + phy_stacksave(0x0416);
12891 + phy_stacksave(0x0417);
12892 + ilt_stacksave(0x1A00 + 0x2);
12893 + ilt_stacksave(0x1A00 + 0x3);
12894 + }
12895 + phy_stacksave(0x042B);
12896 + phy_stacksave(0x048C);
12897 +
12898 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
12899 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
12900 + & ~0x1000);
12901 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12902 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS)
12903 + & 0xFFFC) | 0x0002);
12904 +
12905 + bcm43xx_phy_write(bcm, 0x0033, 0x0800);
12906 + bcm43xx_phy_write(bcm, 0x04A3, 0x2027);
12907 + bcm43xx_phy_write(bcm, 0x04A9, 0x1CA8);
12908 + bcm43xx_phy_write(bcm, 0x0493, 0x287A);
12909 + bcm43xx_phy_write(bcm, 0x04AA, 0x1CA8);
12910 + bcm43xx_phy_write(bcm, 0x04AC, 0x287A);
12911 +
12912 + bcm43xx_phy_write(bcm, 0x04A0,
12913 + (bcm43xx_phy_read(bcm, 0x04A0)
12914 + & 0xFFC0) | 0x001A);
12915 + bcm43xx_phy_write(bcm, 0x04A7, 0x000D);
12916 +
12917 + if (phy->rev < 2) {
12918 + bcm43xx_phy_write(bcm, 0x0406, 0xFF0D);
12919 + } else if (phy->rev == 2) {
12920 + bcm43xx_phy_write(bcm, 0x04C0, 0xFFFF);
12921 + bcm43xx_phy_write(bcm, 0x04C1, 0x00A9);
12922 + } else {
12923 + bcm43xx_phy_write(bcm, 0x04C0, 0x00C1);
12924 + bcm43xx_phy_write(bcm, 0x04C1, 0x0059);
12925 + }
12926 +
12927 + bcm43xx_phy_write(bcm, 0x04A1,
12928 + (bcm43xx_phy_read(bcm, 0x04A1)
12929 + & 0xC0FF) | 0x1800);
12930 + bcm43xx_phy_write(bcm, 0x04A1,
12931 + (bcm43xx_phy_read(bcm, 0x04A1)
12932 + & 0xFFC0) | 0x0015);
12933 + bcm43xx_phy_write(bcm, 0x04A8,
12934 + (bcm43xx_phy_read(bcm, 0x04A8)
12935 + & 0xCFFF) | 0x1000);
12936 + bcm43xx_phy_write(bcm, 0x04A8,
12937 + (bcm43xx_phy_read(bcm, 0x04A8)
12938 + & 0xF0FF) | 0x0A00);
12939 + bcm43xx_phy_write(bcm, 0x04AB,
12940 + (bcm43xx_phy_read(bcm, 0x04AB)
12941 + & 0xCFFF) | 0x1000);
12942 + bcm43xx_phy_write(bcm, 0x04AB,
12943 + (bcm43xx_phy_read(bcm, 0x04AB)
12944 + & 0xF0FF) | 0x0800);
12945 + bcm43xx_phy_write(bcm, 0x04AB,
12946 + (bcm43xx_phy_read(bcm, 0x04AB)
12947 + & 0xFFCF) | 0x0010);
12948 + bcm43xx_phy_write(bcm, 0x04AB,
12949 + (bcm43xx_phy_read(bcm, 0x04AB)
12950 + & 0xFFF0) | 0x0005);
12951 + bcm43xx_phy_write(bcm, 0x04A8,
12952 + (bcm43xx_phy_read(bcm, 0x04A8)
12953 + & 0xFFCF) | 0x0010);
12954 + bcm43xx_phy_write(bcm, 0x04A8,
12955 + (bcm43xx_phy_read(bcm, 0x04A8)
12956 + & 0xFFF0) | 0x0006);
12957 + bcm43xx_phy_write(bcm, 0x04A2,
12958 + (bcm43xx_phy_read(bcm, 0x04A2)
12959 + & 0xF0FF) | 0x0800);
12960 + bcm43xx_phy_write(bcm, 0x04A0,
12961 + (bcm43xx_phy_read(bcm, 0x04A0)
12962 + & 0xF0FF) | 0x0500);
12963 + bcm43xx_phy_write(bcm, 0x04A2,
12964 + (bcm43xx_phy_read(bcm, 0x04A2)
12965 + & 0xFFF0) | 0x000B);
12966 +
12967 + if (phy->rev >= 3) {
12968 + bcm43xx_phy_write(bcm, 0x048A,
12969 + bcm43xx_phy_read(bcm, 0x048A)
12970 + & ~0x8000);
12971 + bcm43xx_phy_write(bcm, 0x0415,
12972 + (bcm43xx_phy_read(bcm, 0x0415)
12973 + & 0x8000) | 0x36D8);
12974 + bcm43xx_phy_write(bcm, 0x0416,
12975 + (bcm43xx_phy_read(bcm, 0x0416)
12976 + & 0x8000) | 0x36D8);
12977 + bcm43xx_phy_write(bcm, 0x0417,
12978 + (bcm43xx_phy_read(bcm, 0x0417)
12979 + & 0xFE00) | 0x016D);
12980 + } else {
12981 + bcm43xx_phy_write(bcm, 0x048A,
12982 + bcm43xx_phy_read(bcm, 0x048A)
12983 + | 0x1000);
12984 + bcm43xx_phy_write(bcm, 0x048A,
12985 + (bcm43xx_phy_read(bcm, 0x048A)
12986 + & 0x9FFF) | 0x2000);
12987 + tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
12988 + BCM43xx_UCODEFLAGS_OFFSET);
12989 + if (!(tmp32 & 0x800)) {
12990 + tmp32 |= 0x800;
12991 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
12992 + BCM43xx_UCODEFLAGS_OFFSET,
12993 + tmp32);
12994 + }
12995 + }
12996 + if (phy->rev >= 2) {
12997 + bcm43xx_phy_write(bcm, 0x042B,
12998 + bcm43xx_phy_read(bcm, 0x042B)
12999 + | 0x0800);
13000 + }
13001 + bcm43xx_phy_write(bcm, 0x048C,
13002 + (bcm43xx_phy_read(bcm, 0x048C)
13003 + & 0xF0FF) | 0x0200);
13004 + if (phy->rev == 2) {
13005 + bcm43xx_phy_write(bcm, 0x04AE,
13006 + (bcm43xx_phy_read(bcm, 0x04AE)
13007 + & 0xFF00) | 0x007F);
13008 + bcm43xx_phy_write(bcm, 0x04AD,
13009 + (bcm43xx_phy_read(bcm, 0x04AD)
13010 + & 0x00FF) | 0x1300);
13011 + } else if (phy->rev >= 6) {
13012 + bcm43xx_ilt_write(bcm, 0x1A00 + 0x3, 0x007F);
13013 + bcm43xx_ilt_write(bcm, 0x1A00 + 0x2, 0x007F);
13014 + bcm43xx_phy_write(bcm, 0x04AD,
13015 + bcm43xx_phy_read(bcm, 0x04AD)
13016 + & 0x00FF);
13017 + }
13018 + bcm43xx_calc_nrssi_slope(bcm);
13019 + break;
13020 + default:
13021 + assert(0);
13022 + }
13023 +}
13024 +
13025 +static void
13026 +bcm43xx_radio_interference_mitigation_disable(struct bcm43xx_private *bcm,
13027 + int mode)
13028 +{
13029 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13030 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13031 + u32 tmp32;
13032 + u32 *stack = radio->interfstack;
13033 +
13034 + switch (mode) {
13035 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13036 + if (phy->rev != 1) {
13037 + bcm43xx_phy_write(bcm, 0x042B,
13038 + bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
13039 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13040 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
13041 + break;
13042 + }
13043 + phy_stackrestore(0x0078);
13044 + bcm43xx_calc_nrssi_threshold(bcm);
13045 + phy_stackrestore(0x0406);
13046 + bcm43xx_phy_write(bcm, 0x042B,
13047 + bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
13048 + if (!bcm->bad_frames_preempt) {
13049 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
13050 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
13051 + & ~(1 << 11));
13052 + }
13053 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13054 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
13055 + phy_stackrestore(0x04A0);
13056 + phy_stackrestore(0x04A1);
13057 + phy_stackrestore(0x04A2);
13058 + phy_stackrestore(0x04A8);
13059 + phy_stackrestore(0x04AB);
13060 + phy_stackrestore(0x04A7);
13061 + phy_stackrestore(0x04A3);
13062 + phy_stackrestore(0x04A9);
13063 + phy_stackrestore(0x0493);
13064 + phy_stackrestore(0x04AA);
13065 + phy_stackrestore(0x04AC);
13066 + break;
13067 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13068 + if (!(bcm43xx_phy_read(bcm, 0x0033) & 0x0800))
13069 + break;
13070 +
13071 + radio->aci_enable = 0;
13072 +
13073 + phy_stackrestore(BCM43xx_PHY_RADIO_BITFIELD);
13074 + phy_stackrestore(BCM43xx_PHY_G_CRS);
13075 + phy_stackrestore(0x0033);
13076 + phy_stackrestore(0x04A3);
13077 + phy_stackrestore(0x04A9);
13078 + phy_stackrestore(0x0493);
13079 + phy_stackrestore(0x04AA);
13080 + phy_stackrestore(0x04AC);
13081 + phy_stackrestore(0x04A0);
13082 + phy_stackrestore(0x04A7);
13083 + if (phy->rev >= 2) {
13084 + phy_stackrestore(0x04C0);
13085 + phy_stackrestore(0x04C1);
13086 + } else
13087 + phy_stackrestore(0x0406);
13088 + phy_stackrestore(0x04A1);
13089 + phy_stackrestore(0x04AB);
13090 + phy_stackrestore(0x04A8);
13091 + if (phy->rev == 2) {
13092 + phy_stackrestore(0x04AD);
13093 + phy_stackrestore(0x04AE);
13094 + } else if (phy->rev >= 3) {
13095 + phy_stackrestore(0x04AD);
13096 + phy_stackrestore(0x0415);
13097 + phy_stackrestore(0x0416);
13098 + phy_stackrestore(0x0417);
13099 + ilt_stackrestore(0x1A00 + 0x2);
13100 + ilt_stackrestore(0x1A00 + 0x3);
13101 + }
13102 + phy_stackrestore(0x04A2);
13103 + phy_stackrestore(0x04A8);
13104 + phy_stackrestore(0x042B);
13105 + phy_stackrestore(0x048C);
13106 + tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13107 + BCM43xx_UCODEFLAGS_OFFSET);
13108 + if (tmp32 & 0x800) {
13109 + tmp32 &= ~0x800;
13110 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13111 + BCM43xx_UCODEFLAGS_OFFSET,
13112 + tmp32);
13113 + }
13114 + bcm43xx_calc_nrssi_slope(bcm);
13115 + break;
13116 + default:
13117 + assert(0);
13118 + }
13119 +}
13120 +
13121 +#undef phy_stacksave
13122 +#undef phy_stackrestore
13123 +#undef radio_stacksave
13124 +#undef radio_stackrestore
13125 +#undef ilt_stacksave
13126 +#undef ilt_stackrestore
13127 +
13128 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm,
13129 + int mode)
13130 +{
13131 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13132 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13133 + int currentmode;
13134 +
13135 + if ((phy->type != BCM43xx_PHYTYPE_G) ||
13136 + (phy->rev == 0) ||
13137 + (!phy->connected))
13138 + return -ENODEV;
13139 +
13140 + radio->aci_wlan_automatic = 0;
13141 + switch (mode) {
13142 + case BCM43xx_RADIO_INTERFMODE_AUTOWLAN:
13143 + radio->aci_wlan_automatic = 1;
13144 + if (radio->aci_enable)
13145 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
13146 + else
13147 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
13148 + break;
13149 + case BCM43xx_RADIO_INTERFMODE_NONE:
13150 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13151 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13152 + break;
13153 + default:
13154 + return -EINVAL;
13155 + }
13156 +
13157 + currentmode = radio->interfmode;
13158 + if (currentmode == mode)
13159 + return 0;
13160 + if (currentmode != BCM43xx_RADIO_INTERFMODE_NONE)
13161 + bcm43xx_radio_interference_mitigation_disable(bcm, currentmode);
13162 +
13163 + if (mode == BCM43xx_RADIO_INTERFMODE_NONE) {
13164 + radio->aci_enable = 0;
13165 + radio->aci_hw_rssi = 0;
13166 + } else
13167 + bcm43xx_radio_interference_mitigation_enable(bcm, mode);
13168 + radio->interfmode = mode;
13169 +
13170 + return 0;
13171 +}
13172 +
13173 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm)
13174 +{
13175 + u16 reg, index, ret;
13176 +
13177 + reg = bcm43xx_radio_read16(bcm, 0x0060);
13178 + index = (reg & 0x001E) >> 1;
13179 + ret = rcc_table[index] << 1;
13180 + ret |= (reg & 0x0001);
13181 + ret |= 0x0020;
13182 +
13183 + return ret;
13184 +}
13185 +
13186 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
13187 +{
13188 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13189 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13190 + u16 backup[19] = { 0 };
13191 + u16 ret;
13192 + u16 i, j;
13193 + u32 tmp1 = 0, tmp2 = 0;
13194 +
13195 + backup[0] = bcm43xx_radio_read16(bcm, 0x0043);
13196 + backup[14] = bcm43xx_radio_read16(bcm, 0x0051);
13197 + backup[15] = bcm43xx_radio_read16(bcm, 0x0052);
13198 + backup[1] = bcm43xx_phy_read(bcm, 0x0015);
13199 + backup[16] = bcm43xx_phy_read(bcm, 0x005A);
13200 + backup[17] = bcm43xx_phy_read(bcm, 0x0059);
13201 + backup[18] = bcm43xx_phy_read(bcm, 0x0058);
13202 + if (phy->type == BCM43xx_PHYTYPE_B) {
13203 + backup[2] = bcm43xx_phy_read(bcm, 0x0030);
13204 + backup[3] = bcm43xx_read16(bcm, 0x03EC);
13205 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
13206 + bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
13207 + } else {
13208 + if (phy->connected) {
13209 + backup[4] = bcm43xx_phy_read(bcm, 0x0811);
13210 + backup[5] = bcm43xx_phy_read(bcm, 0x0812);
13211 + backup[6] = bcm43xx_phy_read(bcm, 0x0814);
13212 + backup[7] = bcm43xx_phy_read(bcm, 0x0815);
13213 + backup[8] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
13214 + backup[9] = bcm43xx_phy_read(bcm, 0x0802);
13215 + bcm43xx_phy_write(bcm, 0x0814,
13216 + (bcm43xx_phy_read(bcm, 0x0814) | 0x0003));
13217 + bcm43xx_phy_write(bcm, 0x0815,
13218 + (bcm43xx_phy_read(bcm, 0x0815) & 0xFFFC));
13219 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13220 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF));
13221 + bcm43xx_phy_write(bcm, 0x0802,
13222 + (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC));
13223 + bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
13224 + bcm43xx_phy_write(bcm, 0x0812, 0x0FB2);
13225 + }
13226 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13227 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) | 0x8000));
13228 + }
13229 + backup[10] = bcm43xx_phy_read(bcm, 0x0035);
13230 + bcm43xx_phy_write(bcm, 0x0035,
13231 + (bcm43xx_phy_read(bcm, 0x0035) & 0xFF7F));
13232 + backup[11] = bcm43xx_read16(bcm, 0x03E6);
13233 + backup[12] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
13234 +
13235 + // Initialization
13236 + if (phy->version == 0) {
13237 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
13238 + } else {
13239 + if (phy->version >= 2)
13240 + bcm43xx_write16(bcm, 0x03E6, 0x0040);
13241 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13242 + (bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) | 0x2000));
13243 + }
13244 +
13245 + ret = bcm43xx_radio_calibrationvalue(bcm);
13246 +
13247 + if (phy->type == BCM43xx_PHYTYPE_B)
13248 + bcm43xx_radio_write16(bcm, 0x0078, 0x0003);
13249 +
13250 + bcm43xx_phy_write(bcm, 0x0015, 0xBFAF);
13251 + bcm43xx_phy_write(bcm, 0x002B, 0x1403);
13252 + if (phy->connected)
13253 + bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
13254 + bcm43xx_phy_write(bcm, 0x0015, 0xBFA0);
13255 + bcm43xx_radio_write16(bcm, 0x0051,
13256 + (bcm43xx_radio_read16(bcm, 0x0051) | 0x0004));
13257 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
13258 + bcm43xx_radio_write16(bcm, 0x0043,
13259 + bcm43xx_radio_read16(bcm, 0x0043) | 0x0009);
13260 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13261 +
13262 + for (i = 0; i < 16; i++) {
13263 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
13264 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
13265 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
13266 + if (phy->connected)
13267 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13268 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13269 + udelay(10);
13270 + if (phy->connected)
13271 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13272 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13273 + udelay(10);
13274 + if (phy->connected)
13275 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13276 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13277 + udelay(10);
13278 + tmp1 += bcm43xx_phy_read(bcm, 0x002D);
13279 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13280 + if (phy->connected)
13281 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13282 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13283 + }
13284 +
13285 + tmp1++;
13286 + tmp1 >>= 9;
13287 + udelay(10);
13288 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13289 +
13290 + for (i = 0; i < 16; i++) {
13291 + bcm43xx_radio_write16(bcm, 0x0078, (flip_4bit(i) << 1) | 0x0020);
13292 + backup[13] = bcm43xx_radio_read16(bcm, 0x0078);
13293 + udelay(10);
13294 + for (j = 0; j < 16; j++) {
13295 + bcm43xx_phy_write(bcm, 0x005A, 0x0D80);
13296 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
13297 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
13298 + if (phy->connected)
13299 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13300 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13301 + udelay(10);
13302 + if (phy->connected)
13303 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13304 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13305 + udelay(10);
13306 + if (phy->connected)
13307 + bcm43xx_phy_write(bcm, 0x0812, 0x30B3); /* 0x30B3 is not a typo */
13308 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13309 + udelay(10);
13310 + tmp2 += bcm43xx_phy_read(bcm, 0x002D);
13311 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13312 + if (phy->connected)
13313 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13314 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13315 + }
13316 + tmp2++;
13317 + tmp2 >>= 8;
13318 + if (tmp1 < tmp2)
13319 + break;
13320 + }
13321 +
13322 + /* Restore the registers */
13323 + bcm43xx_phy_write(bcm, 0x0015, backup[1]);
13324 + bcm43xx_radio_write16(bcm, 0x0051, backup[14]);
13325 + bcm43xx_radio_write16(bcm, 0x0052, backup[15]);
13326 + bcm43xx_radio_write16(bcm, 0x0043, backup[0]);
13327 + bcm43xx_phy_write(bcm, 0x005A, backup[16]);
13328 + bcm43xx_phy_write(bcm, 0x0059, backup[17]);
13329 + bcm43xx_phy_write(bcm, 0x0058, backup[18]);
13330 + bcm43xx_write16(bcm, 0x03E6, backup[11]);
13331 + if (phy->version != 0)
13332 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[12]);
13333 + bcm43xx_phy_write(bcm, 0x0035, backup[10]);
13334 + bcm43xx_radio_selectchannel(bcm, radio->channel, 1);
13335 + if (phy->type == BCM43xx_PHYTYPE_B) {
13336 + bcm43xx_phy_write(bcm, 0x0030, backup[2]);
13337 + bcm43xx_write16(bcm, 0x03EC, backup[3]);
13338 + } else {
13339 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13340 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) & 0x7FFF));
13341 + if (phy->connected) {
13342 + bcm43xx_phy_write(bcm, 0x0811, backup[4]);
13343 + bcm43xx_phy_write(bcm, 0x0812, backup[5]);
13344 + bcm43xx_phy_write(bcm, 0x0814, backup[6]);
13345 + bcm43xx_phy_write(bcm, 0x0815, backup[7]);
13346 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, backup[8]);
13347 + bcm43xx_phy_write(bcm, 0x0802, backup[9]);
13348 + }
13349 + }
13350 + if (i >= 15)
13351 + ret = backup[13];
13352 +
13353 + return ret;
13354 +}
13355 +
13356 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm)
13357 +{
13358 + int err;
13359 +
13360 + bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
13361 + bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
13362 + bcm43xx_radio_write16(bcm, 0x0009, 0x0040);
13363 + bcm43xx_radio_write16(bcm, 0x0005, 0x00AA);
13364 + bcm43xx_radio_write16(bcm, 0x0032, 0x008F);
13365 + bcm43xx_radio_write16(bcm, 0x0006, 0x008F);
13366 + bcm43xx_radio_write16(bcm, 0x0034, 0x008F);
13367 + bcm43xx_radio_write16(bcm, 0x002C, 0x0007);
13368 + bcm43xx_radio_write16(bcm, 0x0082, 0x0080);
13369 + bcm43xx_radio_write16(bcm, 0x0080, 0x0000);
13370 + bcm43xx_radio_write16(bcm, 0x003F, 0x00DA);
13371 + bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
13372 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0010);
13373 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
13374 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
13375 + udelay(400);
13376 +
13377 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020) | 0x0010);
13378 + udelay(400);
13379 +
13380 + bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008) | 0x0008);
13381 + bcm43xx_radio_write16(bcm, 0x0085, bcm43xx_radio_read16(bcm, 0x0085) & ~0x0010);
13382 + bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
13383 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040);
13384 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040) | 0x0040);
13385 + bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0008) | 0x0008);
13386 + bcm43xx_phy_write(bcm, 0x0063, 0xDDC6);
13387 + bcm43xx_phy_write(bcm, 0x0069, 0x07BE);
13388 + bcm43xx_phy_write(bcm, 0x006A, 0x0000);
13389 +
13390 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_A, 0);
13391 + assert(err == 0);
13392 + udelay(1000);
13393 +}
13394 +
13395 +static inline
13396 +u16 freq_r3A_value(u16 frequency)
13397 +{
13398 + u16 value;
13399 +
13400 + if (frequency < 5091)
13401 + value = 0x0040;
13402 + else if (frequency < 5321)
13403 + value = 0x0000;
13404 + else if (frequency < 5806)
13405 + value = 0x0080;
13406 + else
13407 + value = 0x0040;
13408 +
13409 + return value;
13410 +}
13411 +
13412 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm)
13413 +{
13414 + static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
13415 + static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
13416 + u16 tmp = bcm43xx_radio_read16(bcm, 0x001E);
13417 + int i, j;
13418 +
13419 + for (i = 0; i < 5; i++) {
13420 + for (j = 0; j < 5; j++) {
13421 + if (tmp == (data_high[i] << 4 | data_low[j])) {
13422 + bcm43xx_phy_write(bcm, 0x0069, (i - j) << 8 | 0x00C0);
13423 + return;
13424 + }
13425 + }
13426 + }
13427 +}
13428 +
13429 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
13430 + u8 channel,
13431 + int synthetic_pu_workaround)
13432 +{
13433 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13434 + u16 r8, tmp;
13435 + u16 freq;
13436 +
13437 + if ((radio->manufact == 0x17F) &&
13438 + (radio->version == 0x2060) &&
13439 + (radio->revision == 1)) {
13440 + if (channel > 200)
13441 + return -EINVAL;
13442 + freq = channel2freq_a(channel);
13443 +
13444 + r8 = bcm43xx_radio_read16(bcm, 0x0008);
13445 + bcm43xx_write16(bcm, 0x03F0, freq);
13446 + bcm43xx_radio_write16(bcm, 0x0008, r8);
13447 +
13448 + TODO();//TODO: write max channel TX power? to Radio 0x2D
13449 + tmp = bcm43xx_radio_read16(bcm, 0x002E);
13450 + tmp &= 0x0080;
13451 + TODO();//TODO: OR tmp with the Power out estimation for this channel?
13452 + bcm43xx_radio_write16(bcm, 0x002E, tmp);
13453 +
13454 + if (freq >= 4920 && freq <= 5500) {
13455 + /*
13456 + * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
13457 + * = (freq * 0.025862069
13458 + */
13459 + r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
13460 + }
13461 + bcm43xx_radio_write16(bcm, 0x0007, (r8 << 4) | r8);
13462 + bcm43xx_radio_write16(bcm, 0x0020, (r8 << 4) | r8);
13463 + bcm43xx_radio_write16(bcm, 0x0021, (r8 << 4) | r8);
13464 + bcm43xx_radio_write16(bcm, 0x0022,
13465 + (bcm43xx_radio_read16(bcm, 0x0022)
13466 + & 0x000F) | (r8 << 4));
13467 + bcm43xx_radio_write16(bcm, 0x002A, (r8 << 4));
13468 + bcm43xx_radio_write16(bcm, 0x002B, (r8 << 4));
13469 + bcm43xx_radio_write16(bcm, 0x0008,
13470 + (bcm43xx_radio_read16(bcm, 0x0008)
13471 + & 0x00F0) | (r8 << 4));
13472 + bcm43xx_radio_write16(bcm, 0x0029,
13473 + (bcm43xx_radio_read16(bcm, 0x0029)
13474 + & 0xFF0F) | 0x00B0);
13475 + bcm43xx_radio_write16(bcm, 0x0035, 0x00AA);
13476 + bcm43xx_radio_write16(bcm, 0x0036, 0x0085);
13477 + bcm43xx_radio_write16(bcm, 0x003A,
13478 + (bcm43xx_radio_read16(bcm, 0x003A)
13479 + & 0xFF20) | freq_r3A_value(freq));
13480 + bcm43xx_radio_write16(bcm, 0x003D,
13481 + bcm43xx_radio_read16(bcm, 0x003D) & 0x00FF);
13482 + bcm43xx_radio_write16(bcm, 0x0081,
13483 + (bcm43xx_radio_read16(bcm, 0x0081)
13484 + & 0xFF7F) | 0x0080);
13485 + bcm43xx_radio_write16(bcm, 0x0035,
13486 + bcm43xx_radio_read16(bcm, 0x0035) & 0xFFEF);
13487 + bcm43xx_radio_write16(bcm, 0x0035,
13488 + (bcm43xx_radio_read16(bcm, 0x0035)
13489 + & 0xFFEF) | 0x0010);
13490 + bcm43xx_radio_set_tx_iq(bcm);
13491 + TODO(); //TODO: TSSI2dbm workaround
13492 + bcm43xx_phy_xmitpower(bcm);//FIXME correct?
13493 + } else {
13494 + if ((channel < 1) || (channel > 14))
13495 + return -EINVAL;
13496 +
13497 + if (synthetic_pu_workaround)
13498 + bcm43xx_synth_pu_workaround(bcm, channel);
13499 +
13500 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
13501 + channel2freq_bg(channel));
13502 +
13503 + if (channel == 14) {
13504 + if (bcm->sprom.locale == BCM43xx_LOCALE_JAPAN) {
13505 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13506 + BCM43xx_UCODEFLAGS_OFFSET,
13507 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13508 + BCM43xx_UCODEFLAGS_OFFSET)
13509 + & ~(1 << 7));
13510 + } else {
13511 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13512 + BCM43xx_UCODEFLAGS_OFFSET,
13513 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13514 + BCM43xx_UCODEFLAGS_OFFSET)
13515 + | (1 << 7));
13516 + }
13517 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13518 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13519 + | (1 << 11));
13520 + } else {
13521 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13522 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13523 + & 0xF7BF);
13524 + }
13525 + }
13526 +
13527 + radio->channel = channel;
13528 + //XXX: Using the longer of 2 timeouts (8000 vs 2000 usecs). Specs states
13529 + // that 2000 usecs might suffice.
13530 + udelay(8000);
13531 +
13532 + return 0;
13533 +}
13534 +
13535 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val)
13536 +{
13537 + u16 tmp;
13538 +
13539 + val <<= 8;
13540 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0022) & 0xFCFF;
13541 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0022, tmp | val);
13542 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x03A8) & 0xFCFF;
13543 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x03A8, tmp | val);
13544 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0054) & 0xFCFF;
13545 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0054, tmp | val);
13546 +}
13547 +
13548 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
13549 +static u16 bcm43xx_get_txgain_base_band(u16 txpower)
13550 +{
13551 + u16 ret;
13552 +
13553 + assert(txpower <= 63);
13554 +
13555 + if (txpower >= 54)
13556 + ret = 2;
13557 + else if (txpower >= 49)
13558 + ret = 4;
13559 + else if (txpower >= 44)
13560 + ret = 5;
13561 + else
13562 + ret = 6;
13563 +
13564 + return ret;
13565 +}
13566 +
13567 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
13568 +static u16 bcm43xx_get_txgain_freq_power_amp(u16 txpower)
13569 +{
13570 + u16 ret;
13571 +
13572 + assert(txpower <= 63);
13573 +
13574 + if (txpower >= 32)
13575 + ret = 0;
13576 + else if (txpower >= 25)
13577 + ret = 1;
13578 + else if (txpower >= 20)
13579 + ret = 2;
13580 + else if (txpower >= 12)
13581 + ret = 3;
13582 + else
13583 + ret = 4;
13584 +
13585 + return ret;
13586 +}
13587 +
13588 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
13589 +static u16 bcm43xx_get_txgain_dac(u16 txpower)
13590 +{
13591 + u16 ret;
13592 +
13593 + assert(txpower <= 63);
13594 +
13595 + if (txpower >= 54)
13596 + ret = txpower - 53;
13597 + else if (txpower >= 49)
13598 + ret = txpower - 42;
13599 + else if (txpower >= 44)
13600 + ret = txpower - 37;
13601 + else if (txpower >= 32)
13602 + ret = txpower - 32;
13603 + else if (txpower >= 25)
13604 + ret = txpower - 20;
13605 + else if (txpower >= 20)
13606 + ret = txpower - 13;
13607 + else if (txpower >= 12)
13608 + ret = txpower - 8;
13609 + else
13610 + ret = txpower;
13611 +
13612 + return ret;
13613 +}
13614 +
13615 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower)
13616 +{
13617 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13618 + u16 pamp, base, dac, ilt;
13619 +
13620 + txpower = limit_value(txpower, 0, 63);
13621 +
13622 + pamp = bcm43xx_get_txgain_freq_power_amp(txpower);
13623 + pamp <<= 5;
13624 + pamp &= 0x00E0;
13625 + bcm43xx_phy_write(bcm, 0x0019, pamp);
13626 +
13627 + base = bcm43xx_get_txgain_base_band(txpower);
13628 + base &= 0x000F;
13629 + bcm43xx_phy_write(bcm, 0x0017, base | 0x0020);
13630 +
13631 + ilt = bcm43xx_ilt_read(bcm, 0x3001);
13632 + ilt &= 0x0007;
13633 +
13634 + dac = bcm43xx_get_txgain_dac(txpower);
13635 + dac <<= 3;
13636 + dac |= ilt;
13637 +
13638 + bcm43xx_ilt_write(bcm, 0x3001, dac);
13639 +
13640 + radio->txpwr_offset = txpower;
13641 +
13642 + TODO();
13643 + //TODO: FuncPlaceholder (Adjust BB loft cancel)
13644 +}
13645 +
13646 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
13647 + u16 baseband_attenuation, u16 radio_attenuation,
13648 + u16 txpower)
13649 +{
13650 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13651 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13652 +
13653 + if (baseband_attenuation == 0xFFFF)
13654 + baseband_attenuation = radio->baseband_atten;
13655 + if (radio_attenuation == 0xFFFF)
13656 + radio_attenuation = radio->radio_atten;
13657 + if (txpower == 0xFFFF)
13658 + txpower = radio->txctl1;
13659 + radio->baseband_atten = baseband_attenuation;
13660 + radio->radio_atten = radio_attenuation;
13661 + radio->txctl1 = txpower;
13662 +
13663 + assert(/*baseband_attenuation >= 0 &&*/ baseband_attenuation <= 11);
13664 + if (radio->revision < 6)
13665 + assert(/*radio_attenuation >= 0 &&*/ radio_attenuation <= 9);
13666 + else
13667 + assert(/* radio_attenuation >= 0 &&*/ radio_attenuation <= 31);
13668 + assert(/*txpower >= 0 &&*/ txpower <= 7);
13669 +
13670 + bcm43xx_phy_set_baseband_attenuation(bcm, baseband_attenuation);
13671 + bcm43xx_radio_write16(bcm, 0x0043, radio_attenuation);
13672 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0064, radio_attenuation);
13673 + if (radio->version == 0x2050) {
13674 + bcm43xx_radio_write16(bcm, 0x0052,
13675 + (bcm43xx_radio_read16(bcm, 0x0052) & ~0x0070)
13676 + | ((txpower << 4) & 0x0070));
13677 + }
13678 + //FIXME: The spec is very weird and unclear here.
13679 + if (phy->type == BCM43xx_PHYTYPE_G)
13680 + bcm43xx_phy_lo_adjust(bcm, 0);
13681 +}
13682 +
13683 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm)
13684 +{
13685 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13686 +
13687 + if (radio->version == 0x2050 && radio->revision < 6)
13688 + return 0;
13689 + return 2;
13690 +}
13691 +
13692 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm)
13693 +{
13694 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13695 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13696 + u16 att = 0xFFFF;
13697 +
13698 + if (phy->type == BCM43xx_PHYTYPE_A)
13699 + return 0x60;
13700 +
13701 + switch (radio->version) {
13702 + case 0x2053:
13703 + switch (radio->revision) {
13704 + case 1:
13705 + att = 6;
13706 + break;
13707 + }
13708 + break;
13709 + case 0x2050:
13710 + switch (radio->revision) {
13711 + case 0:
13712 + att = 5;
13713 + break;
13714 + case 1:
13715 + if (phy->type == BCM43xx_PHYTYPE_G) {
13716 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13717 + bcm->board_type == 0x421 &&
13718 + bcm->board_revision >= 30)
13719 + att = 3;
13720 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13721 + bcm->board_type == 0x416)
13722 + att = 3;
13723 + else
13724 + att = 1;
13725 + } else {
13726 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13727 + bcm->board_type == 0x421 &&
13728 + bcm->board_revision >= 30)
13729 + att = 7;
13730 + else
13731 + att = 6;
13732 + }
13733 + break;
13734 + case 2:
13735 + if (phy->type == BCM43xx_PHYTYPE_G) {
13736 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13737 + bcm->board_type == 0x421 &&
13738 + bcm->board_revision >= 30)
13739 + att = 3;
13740 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13741 + bcm->board_type == 0x416)
13742 + att = 5;
13743 + else if (bcm->chip_id == 0x4320)
13744 + att = 4;
13745 + else
13746 + att = 3;
13747 + } else
13748 + att = 6;
13749 + break;
13750 + case 3:
13751 + att = 5;
13752 + break;
13753 + case 4:
13754 + case 5:
13755 + att = 1;
13756 + break;
13757 + case 6:
13758 + case 7:
13759 + att = 5;
13760 + break;
13761 + case 8:
13762 + att = 0x1A;
13763 + break;
13764 + case 9:
13765 + default:
13766 + att = 5;
13767 + }
13768 + }
13769 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13770 + bcm->board_type == 0x421) {
13771 + if (bcm->board_revision < 0x43)
13772 + att = 2;
13773 + else if (bcm->board_revision < 0x51)
13774 + att = 3;
13775 + }
13776 + if (att == 0xFFFF)
13777 + att = 5;
13778 +
13779 + return att;
13780 +}
13781 +
13782 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm)
13783 +{
13784 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13785 +
13786 + if (radio->version != 0x2050)
13787 + return 0;
13788 + if (radio->revision == 1)
13789 + return 3;
13790 + if (radio->revision < 6)
13791 + return 2;
13792 + if (radio->revision == 8)
13793 + return 1;
13794 + return 0;
13795 +}
13796 +
13797 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
13798 +{
13799 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13800 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13801 + int err;
13802 +
13803 + if (radio->enabled)
13804 + return;
13805 +
13806 + switch (phy->type) {
13807 + case BCM43xx_PHYTYPE_A:
13808 + bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
13809 + bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
13810 + bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) & 0xFFF7);
13811 + bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) & 0xFFF7);
13812 + bcm43xx_radio_init2060(bcm);
13813 + break;
13814 + case BCM43xx_PHYTYPE_B:
13815 + case BCM43xx_PHYTYPE_G:
13816 + bcm43xx_phy_write(bcm, 0x0015, 0x8000);
13817 + bcm43xx_phy_write(bcm, 0x0015, 0xCC00);
13818 + bcm43xx_phy_write(bcm, 0x0015, (phy->connected ? 0x00C0 : 0x0000));
13819 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 1);
13820 + assert(err == 0);
13821 + break;
13822 + default:
13823 + assert(0);
13824 + }
13825 + radio->enabled = 1;
13826 + dprintk(KERN_INFO PFX "Radio turned on\n");
13827 +}
13828 +
13829 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
13830 +{
13831 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13832 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13833 +
13834 + if (phy->type == BCM43xx_PHYTYPE_A) {
13835 + bcm43xx_radio_write16(bcm, 0x0004, 0x00FF);
13836 + bcm43xx_radio_write16(bcm, 0x0005, 0x00FB);
13837 + bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) | 0x0008);
13838 + bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) | 0x0008);
13839 + }
13840 + if (phy->type == BCM43xx_PHYTYPE_G && bcm->current_core->rev >= 5) {
13841 + bcm43xx_phy_write(bcm, 0x0811, bcm43xx_phy_read(bcm, 0x0811) | 0x008C);
13842 + bcm43xx_phy_write(bcm, 0x0812, bcm43xx_phy_read(bcm, 0x0812) & 0xFF73);
13843 + } else
13844 + bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
13845 + radio->enabled = 0;
13846 + dprintk(KERN_INFO PFX "Radio turned off\n");
13847 +}
13848 +
13849 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
13850 +{
13851 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13852 +
13853 + switch (phy->type) {
13854 + case BCM43xx_PHYTYPE_A:
13855 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0068, 0x7F7F);
13856 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x006a, 0x7F7F);
13857 + break;
13858 + case BCM43xx_PHYTYPE_B:
13859 + case BCM43xx_PHYTYPE_G:
13860 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0058, 0x7F7F);
13861 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x005a, 0x7F7F);
13862 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0070, 0x7F7F);
13863 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0072, 0x7F7F);
13864 + break;
13865 + }
13866 +}
13867 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h
13868 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h 1970-01-01 01:00:00.000000000 +0100
13869 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h 2006-03-28 22:16:14.000000000 +0200
13870 @@ -0,0 +1,99 @@
13871 +/*
13872 +
13873 + Broadcom BCM43xx wireless driver
13874 +
13875 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
13876 + Stefano Brivio <st3@riseup.net>
13877 + Michael Buesch <mbuesch@freenet.de>
13878 + Danny van Dyk <kugelfang@gentoo.org>
13879 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
13880 +
13881 + Some parts of the code in this file are derived from the ipw2200
13882 + driver Copyright(c) 2003 - 2004 Intel Corporation.
13883 +
13884 + This program is free software; you can redistribute it and/or modify
13885 + it under the terms of the GNU General Public License as published by
13886 + the Free Software Foundation; either version 2 of the License, or
13887 + (at your option) any later version.
13888 +
13889 + This program is distributed in the hope that it will be useful,
13890 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13891 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13892 + GNU General Public License for more details.
13893 +
13894 + You should have received a copy of the GNU General Public License
13895 + along with this program; see the file COPYING. If not, write to
13896 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
13897 + Boston, MA 02110-1301, USA.
13898 +
13899 +*/
13900 +
13901 +#ifndef BCM43xx_RADIO_H_
13902 +#define BCM43xx_RADIO_H_
13903 +
13904 +#include "bcm43xx.h"
13905 +
13906 +
13907 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_A 36
13908 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_BG 6
13909 +
13910 +/* Force antenna 0. */
13911 +#define BCM43xx_RADIO_TXANTENNA_0 0
13912 +/* Force antenna 1. */
13913 +#define BCM43xx_RADIO_TXANTENNA_1 1
13914 +/* Use the RX antenna, that was selected for the most recently
13915 + * received good PLCP header.
13916 + */
13917 +#define BCM43xx_RADIO_TXANTENNA_LASTPLCP 3
13918 +#define BCM43xx_RADIO_TXANTENNA_DEFAULT BCM43xx_RADIO_TXANTENNA_LASTPLCP
13919 +
13920 +#define BCM43xx_RADIO_INTERFMODE_NONE 0
13921 +#define BCM43xx_RADIO_INTERFMODE_NONWLAN 1
13922 +#define BCM43xx_RADIO_INTERFMODE_MANUALWLAN 2
13923 +#define BCM43xx_RADIO_INTERFMODE_AUTOWLAN 3
13924 +
13925 +
13926 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm);
13927 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm);
13928 +
13929 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset);
13930 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val);
13931 +
13932 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm);
13933 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
13934 +
13935 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
13936 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
13937 +
13938 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
13939 + int synthetic_pu_workaround);
13940 +
13941 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower);
13942 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
13943 + u16 baseband_attenuation, u16 attenuation,
13944 + u16 txpower);
13945 +
13946 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm);
13947 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm);
13948 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm);
13949 +
13950 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val);
13951 +
13952 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm);
13953 +
13954 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel);
13955 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm);
13956 +
13957 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm, int mode);
13958 +
13959 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm);
13960 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm);
13961 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset);
13962 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val);
13963 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val);
13964 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm);
13965 +
13966 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm);
13967 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm);
13968 +
13969 +#endif /* BCM43xx_RADIO_H_ */
13970 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c
13971 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c 1970-01-01 01:00:00.000000000 +0100
13972 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c 2006-03-28 22:16:14.000000000 +0200
13973 @@ -0,0 +1,322 @@
13974 +/*
13975 +
13976 + Broadcom BCM43xx wireless driver
13977 +
13978 + SYSFS support routines
13979 +
13980 + Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
13981 +
13982 + This program is free software; you can redistribute it and/or modify
13983 + it under the terms of the GNU General Public License as published by
13984 + the Free Software Foundation; either version 2 of the License, or
13985 + (at your option) any later version.
13986 +
13987 + This program is distributed in the hope that it will be useful,
13988 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13989 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13990 + GNU General Public License for more details.
13991 +
13992 + You should have received a copy of the GNU General Public License
13993 + along with this program; see the file COPYING. If not, write to
13994 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
13995 + Boston, MA 02110-1301, USA.
13996 +
13997 +*/
13998 +
13999 +#include "bcm43xx_sysfs.h"
14000 +#include "bcm43xx.h"
14001 +#include "bcm43xx_main.h"
14002 +#include "bcm43xx_radio.h"
14003 +
14004 +#include <linux/capability.h>
14005 +
14006 +
14007 +#define GENERIC_FILESIZE 64
14008 +
14009 +
14010 +static int get_integer(const char *buf, size_t count)
14011 +{
14012 + char tmp[10 + 1] = { 0 };
14013 + int ret = -EINVAL;
14014 +
14015 + if (count == 0)
14016 + goto out;
14017 + count = min(count, (size_t)10);
14018 + memcpy(tmp, buf, count);
14019 + ret = simple_strtol(tmp, NULL, 10);
14020 +out:
14021 + return ret;
14022 +}
14023 +
14024 +static int get_boolean(const char *buf, size_t count)
14025 +{
14026 + if (count != 0) {
14027 + if (buf[0] == '1')
14028 + return 1;
14029 + if (buf[0] == '0')
14030 + return 0;
14031 + if (count >= 4 && memcmp(buf, "true", 4) == 0)
14032 + return 1;
14033 + if (count >= 5 && memcmp(buf, "false", 5) == 0)
14034 + return 0;
14035 + if (count >= 3 && memcmp(buf, "yes", 3) == 0)
14036 + return 1;
14037 + if (count >= 2 && memcmp(buf, "no", 2) == 0)
14038 + return 0;
14039 + if (count >= 2 && memcmp(buf, "on", 2) == 0)
14040 + return 1;
14041 + if (count >= 3 && memcmp(buf, "off", 3) == 0)
14042 + return 0;
14043 + }
14044 + return -EINVAL;
14045 +}
14046 +
14047 +static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
14048 + struct device_attribute *attr,
14049 + char *buf)
14050 +{
14051 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14052 + u16 *sprom;
14053 + unsigned long flags;
14054 + int i, err;
14055 +
14056 + if (!capable(CAP_NET_ADMIN))
14057 + return -EPERM;
14058 +
14059 + assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
14060 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14061 + GFP_KERNEL);
14062 + if (!sprom)
14063 + return -ENOMEM;
14064 + bcm43xx_lock_mmio(bcm, flags);
14065 + assert(bcm->initialized);
14066 + err = bcm43xx_sprom_read(bcm, sprom);
14067 + if (!err) {
14068 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
14069 + buf[i * 2] = sprom[i] & 0x00FF;
14070 + buf[i * 2 + 1] = (sprom[i] & 0xFF00) >> 8;
14071 + }
14072 + }
14073 + bcm43xx_unlock_mmio(bcm, flags);
14074 + kfree(sprom);
14075 +
14076 + return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
14077 +}
14078 +
14079 +static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
14080 + struct device_attribute *attr,
14081 + const char *buf, size_t count)
14082 +{
14083 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14084 + u16 *sprom;
14085 + unsigned long flags;
14086 + int i, err;
14087 +
14088 + if (!capable(CAP_NET_ADMIN))
14089 + return -EPERM;
14090 +
14091 + if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
14092 + return -EINVAL;
14093 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14094 + GFP_KERNEL);
14095 + if (!sprom)
14096 + return -ENOMEM;
14097 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
14098 + sprom[i] = buf[i * 2] & 0xFF;
14099 + sprom[i] |= ((u16)(buf[i * 2 + 1] & 0xFF)) << 8;
14100 + }
14101 + bcm43xx_lock_mmio(bcm, flags);
14102 + assert(bcm->initialized);
14103 + err = bcm43xx_sprom_write(bcm, sprom);
14104 + bcm43xx_unlock_mmio(bcm, flags);
14105 + kfree(sprom);
14106 +
14107 + return err ? err : count;
14108 +
14109 +}
14110 +
14111 +static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
14112 + struct device_attribute *attr,
14113 + char *buf)
14114 +{
14115 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14116 + unsigned long flags;
14117 + int err;
14118 + ssize_t count = 0;
14119 +
14120 + if (!capable(CAP_NET_ADMIN))
14121 + return -EPERM;
14122 +
14123 + bcm43xx_lock(bcm, flags);
14124 + assert(bcm->initialized);
14125 +
14126 + switch (bcm43xx_current_radio(bcm)->interfmode) {
14127 + case BCM43xx_RADIO_INTERFMODE_NONE:
14128 + count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
14129 + break;
14130 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
14131 + count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
14132 + break;
14133 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
14134 + count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
14135 + break;
14136 + default:
14137 + assert(0);
14138 + }
14139 + err = 0;
14140 +
14141 + bcm43xx_unlock(bcm, flags);
14142 +
14143 + return err ? err : count;
14144 +
14145 +}
14146 +
14147 +static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
14148 + struct device_attribute *attr,
14149 + const char *buf, size_t count)
14150 +{
14151 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14152 + unsigned long flags;
14153 + int err;
14154 + int mode;
14155 +
14156 + if (!capable(CAP_NET_ADMIN))
14157 + return -EPERM;
14158 +
14159 + mode = get_integer(buf, count);
14160 + switch (mode) {
14161 + case 0:
14162 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
14163 + break;
14164 + case 1:
14165 + mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
14166 + break;
14167 + case 2:
14168 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
14169 + break;
14170 + case 3:
14171 + mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
14172 + break;
14173 + default:
14174 + return -EINVAL;
14175 + }
14176 +
14177 + bcm43xx_lock_mmio(bcm, flags);
14178 + assert(bcm->initialized);
14179 +
14180 + err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
14181 + if (err) {
14182 + printk(KERN_ERR PFX "Interference Mitigation not "
14183 + "supported by device\n");
14184 + }
14185 +
14186 + bcm43xx_unlock_mmio(bcm, flags);
14187 +
14188 + return err ? err : count;
14189 +}
14190 +
14191 +static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
14192 + struct device_attribute *attr,
14193 + char *buf)
14194 +{
14195 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14196 + unsigned long flags;
14197 + int err;
14198 + ssize_t count;
14199 +
14200 + if (!capable(CAP_NET_ADMIN))
14201 + return -EPERM;
14202 +
14203 + bcm43xx_lock(bcm, flags);
14204 + assert(bcm->initialized);
14205 +
14206 + if (bcm->short_preamble)
14207 + count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
14208 + else
14209 + count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
14210 +
14211 + err = 0;
14212 + bcm43xx_unlock(bcm, flags);
14213 +
14214 + return err ? err : count;
14215 +}
14216 +
14217 +static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
14218 + struct device_attribute *attr,
14219 + const char *buf, size_t count)
14220 +{
14221 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14222 + unsigned long flags;
14223 + int err;
14224 + int value;
14225 +
14226 + if (!capable(CAP_NET_ADMIN))
14227 + return -EPERM;
14228 +
14229 + value = get_boolean(buf, count);
14230 + if (value < 0)
14231 + return value;
14232 + bcm43xx_lock(bcm, flags);
14233 + assert(bcm->initialized);
14234 +
14235 + bcm->short_preamble = !!value;
14236 +
14237 + err = 0;
14238 + bcm43xx_unlock(bcm, flags);
14239 +
14240 + return err ? err : count;
14241 +}
14242 +
14243 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
14244 +{
14245 + struct device *dev = &bcm->pci_dev->dev;
14246 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14247 + int err;
14248 +
14249 + assert(bcm->initialized);
14250 +
14251 + sysfs->attr_sprom.attr.name = "sprom";
14252 + sysfs->attr_sprom.attr.owner = THIS_MODULE;
14253 + sysfs->attr_sprom.attr.mode = 0600;
14254 + sysfs->attr_sprom.show = bcm43xx_attr_sprom_show;
14255 + sysfs->attr_sprom.store = bcm43xx_attr_sprom_store;
14256 + err = device_create_file(dev, &sysfs->attr_sprom);
14257 + if (err)
14258 + goto out;
14259 +
14260 + sysfs->attr_interfmode.attr.name = "interference";
14261 + sysfs->attr_interfmode.attr.owner = THIS_MODULE;
14262 + sysfs->attr_interfmode.attr.mode = 0600;
14263 + sysfs->attr_interfmode.show = bcm43xx_attr_interfmode_show;
14264 + sysfs->attr_interfmode.store = bcm43xx_attr_interfmode_store;
14265 + err = device_create_file(dev, &sysfs->attr_interfmode);
14266 + if (err)
14267 + goto err_remove_sprom;
14268 +
14269 + sysfs->attr_preamble.attr.name = "shortpreamble";
14270 + sysfs->attr_preamble.attr.owner = THIS_MODULE;
14271 + sysfs->attr_preamble.attr.mode = 0600;
14272 + sysfs->attr_preamble.show = bcm43xx_attr_preamble_show;
14273 + sysfs->attr_preamble.store = bcm43xx_attr_preamble_store;
14274 + err = device_create_file(dev, &sysfs->attr_preamble);
14275 + if (err)
14276 + goto err_remove_interfmode;
14277 +
14278 +out:
14279 + return err;
14280 +err_remove_interfmode:
14281 + device_remove_file(dev, &sysfs->attr_interfmode);
14282 +err_remove_sprom:
14283 + device_remove_file(dev, &sysfs->attr_sprom);
14284 + goto out;
14285 +}
14286 +
14287 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
14288 +{
14289 + struct device *dev = &bcm->pci_dev->dev;
14290 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14291 +
14292 + device_remove_file(dev, &sysfs->attr_preamble);
14293 + device_remove_file(dev, &sysfs->attr_interfmode);
14294 + device_remove_file(dev, &sysfs->attr_sprom);
14295 +}
14296 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h
14297 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h 1970-01-01 01:00:00.000000000 +0100
14298 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h 2006-03-28 22:16:14.000000000 +0200
14299 @@ -0,0 +1,25 @@
14300 +#ifndef BCM43xx_SYSFS_H_
14301 +#define BCM43xx_SYSFS_H_
14302 +
14303 +#include <linux/device.h>
14304 +
14305 +
14306 +struct bcm43xx_sysfs {
14307 + struct device_attribute attr_sprom;
14308 + struct device_attribute attr_interfmode;
14309 + struct device_attribute attr_preamble;
14310 +};
14311 +
14312 +#define devattr_to_bcm(attr, attr_name) ({ \
14313 + struct bcm43xx_sysfs *__s; struct bcm43xx_private *__p; \
14314 + __s = container_of((attr), struct bcm43xx_sysfs, attr_name); \
14315 + __p = container_of(__s, struct bcm43xx_private, sysfs); \
14316 + __p; \
14317 + })
14318 +
14319 +struct bcm43xx_private;
14320 +
14321 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
14322 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
14323 +
14324 +#endif /* BCM43xx_SYSFS_H_ */
14325 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c
14326 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c 1970-01-01 01:00:00.000000000 +0100
14327 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c 2006-03-28 22:16:14.000000000 +0200
14328 @@ -0,0 +1,494 @@
14329 +/*
14330 +
14331 + Broadcom BCM43xx wireless driver
14332 +
14333 + Transmission (TX/RX) related functions.
14334 +
14335 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
14336 + Stefano Brivio <st3@riseup.net>
14337 + Michael Buesch <mbuesch@freenet.de>
14338 + Danny van Dyk <kugelfang@gentoo.org>
14339 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
14340 +
14341 + This program is free software; you can redistribute it and/or modify
14342 + it under the terms of the GNU General Public License as published by
14343 + the Free Software Foundation; either version 2 of the License, or
14344 + (at your option) any later version.
14345 +
14346 + This program is distributed in the hope that it will be useful,
14347 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14348 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14349 + GNU General Public License for more details.
14350 +
14351 + You should have received a copy of the GNU General Public License
14352 + along with this program; see the file COPYING. If not, write to
14353 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
14354 + Boston, MA 02110-1301, USA.
14355 +
14356 +*/
14357 +
14358 +#include "bcm43xx_xmit.h"
14359 +
14360 +
14361 +/* Extract the bitrate out of a CCK PLCP header. */
14362 +static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr4 *plcp)
14363 +{
14364 + switch (plcp->raw[0]) {
14365 + case 0x0A:
14366 + return BCM43xx_CCK_RATE_1MB;
14367 + case 0x14:
14368 + return BCM43xx_CCK_RATE_2MB;
14369 + case 0x37:
14370 + return BCM43xx_CCK_RATE_5MB;
14371 + case 0x6E:
14372 + return BCM43xx_CCK_RATE_11MB;
14373 + }
14374 + assert(0);
14375 + return 0;
14376 +}
14377 +
14378 +/* Extract the bitrate out of an OFDM PLCP header. */
14379 +static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr4 *plcp)
14380 +{
14381 + switch (plcp->raw[0] & 0xF) {
14382 + case 0xB:
14383 + return BCM43xx_OFDM_RATE_6MB;
14384 + case 0xF:
14385 + return BCM43xx_OFDM_RATE_9MB;
14386 + case 0xA:
14387 + return BCM43xx_OFDM_RATE_12MB;
14388 + case 0xE:
14389 + return BCM43xx_OFDM_RATE_18MB;
14390 + case 0x9:
14391 + return BCM43xx_OFDM_RATE_24MB;
14392 + case 0xD:
14393 + return BCM43xx_OFDM_RATE_36MB;
14394 + case 0x8:
14395 + return BCM43xx_OFDM_RATE_48MB;
14396 + case 0xC:
14397 + return BCM43xx_OFDM_RATE_54MB;
14398 + }
14399 + assert(0);
14400 + return 0;
14401 +}
14402 +
14403 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
14404 +{
14405 + switch (bitrate) {
14406 + case BCM43xx_CCK_RATE_1MB:
14407 + return 0x0A;
14408 + case BCM43xx_CCK_RATE_2MB:
14409 + return 0x14;
14410 + case BCM43xx_CCK_RATE_5MB:
14411 + return 0x37;
14412 + case BCM43xx_CCK_RATE_11MB:
14413 + return 0x6E;
14414 + }
14415 + assert(0);
14416 + return 0;
14417 +}
14418 +
14419 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
14420 +{
14421 + switch (bitrate) {
14422 + case BCM43xx_OFDM_RATE_6MB:
14423 + return 0xB;
14424 + case BCM43xx_OFDM_RATE_9MB:
14425 + return 0xF;
14426 + case BCM43xx_OFDM_RATE_12MB:
14427 + return 0xA;
14428 + case BCM43xx_OFDM_RATE_18MB:
14429 + return 0xE;
14430 + case BCM43xx_OFDM_RATE_24MB:
14431 + return 0x9;
14432 + case BCM43xx_OFDM_RATE_36MB:
14433 + return 0xD;
14434 + case BCM43xx_OFDM_RATE_48MB:
14435 + return 0x8;
14436 + case BCM43xx_OFDM_RATE_54MB:
14437 + return 0xC;
14438 + }
14439 + assert(0);
14440 + return 0;
14441 +}
14442 +
14443 +static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
14444 + const u16 octets, const u8 bitrate,
14445 + const int ofdm_modulation)
14446 +{
14447 + __le32 *data = &(plcp->data);
14448 + __u8 *raw = plcp->raw;
14449 +
14450 + if (ofdm_modulation) {
14451 + *data = bcm43xx_plcp_get_ratecode_ofdm(bitrate);
14452 + assert(!(octets & 0xF000));
14453 + *data |= (octets << 5);
14454 + *data = cpu_to_le32(*data);
14455 + } else {
14456 + u32 plen;
14457 +
14458 + plen = octets * 16 / bitrate;
14459 + if ((octets * 16 % bitrate) > 0) {
14460 + plen++;
14461 + if ((bitrate == BCM43xx_CCK_RATE_11MB)
14462 + && ((octets * 8 % 11) < 4)) {
14463 + raw[1] = 0x84;
14464 + } else
14465 + raw[1] = 0x04;
14466 + } else
14467 + raw[1] = 0x04;
14468 + *data |= cpu_to_le32(plen << 16);
14469 + raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
14470 + }
14471 +}
14472 +
14473 +static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
14474 +{
14475 + switch (bitrate) {
14476 + case BCM43xx_CCK_RATE_1MB:
14477 + return BCM43xx_CCK_RATE_1MB;
14478 + case BCM43xx_CCK_RATE_2MB:
14479 + return BCM43xx_CCK_RATE_1MB;
14480 + case BCM43xx_CCK_RATE_5MB:
14481 + return BCM43xx_CCK_RATE_2MB;
14482 + case BCM43xx_CCK_RATE_11MB:
14483 + return BCM43xx_CCK_RATE_5MB;
14484 + case BCM43xx_OFDM_RATE_6MB:
14485 + return BCM43xx_CCK_RATE_5MB;
14486 + case BCM43xx_OFDM_RATE_9MB:
14487 + return BCM43xx_OFDM_RATE_6MB;
14488 + case BCM43xx_OFDM_RATE_12MB:
14489 + return BCM43xx_OFDM_RATE_9MB;
14490 + case BCM43xx_OFDM_RATE_18MB:
14491 + return BCM43xx_OFDM_RATE_12MB;
14492 + case BCM43xx_OFDM_RATE_24MB:
14493 + return BCM43xx_OFDM_RATE_18MB;
14494 + case BCM43xx_OFDM_RATE_36MB:
14495 + return BCM43xx_OFDM_RATE_24MB;
14496 + case BCM43xx_OFDM_RATE_48MB:
14497 + return BCM43xx_OFDM_RATE_36MB;
14498 + case BCM43xx_OFDM_RATE_54MB:
14499 + return BCM43xx_OFDM_RATE_48MB;
14500 + }
14501 + assert(0);
14502 + return 0;
14503 +}
14504 +
14505 +static
14506 +__le16 bcm43xx_calc_duration_id(const struct ieee80211_hdr *wireless_header,
14507 + u8 bitrate)
14508 +{
14509 + const u16 frame_ctl = le16_to_cpu(wireless_header->frame_control);
14510 + __le16 duration_id = wireless_header->duration_id;
14511 +
14512 + switch (WLAN_FC_GET_TYPE(frame_ctl)) {
14513 + case WLAN_FC_TYPE_DATA:
14514 + case WLAN_FC_TYPE_MGMT:
14515 + //TODO: Steal the code from ieee80211, once it is completed there.
14516 + break;
14517 + case WLAN_FC_TYPE_CTRL:
14518 + /* Use the original duration/id. */
14519 + break;
14520 + default:
14521 + assert(0);
14522 + }
14523 +
14524 + return duration_id;
14525 +}
14526 +
14527 +static inline
14528 +u16 ceiling_div(u16 dividend, u16 divisor)
14529 +{
14530 + return ((dividend + divisor - 1) / divisor);
14531 +}
14532 +
14533 +static void bcm43xx_generate_rts(const struct bcm43xx_phyinfo *phy,
14534 + struct bcm43xx_txhdr *txhdr,
14535 + u16 *flags,
14536 + u8 bitrate,
14537 + const struct ieee80211_hdr *wlhdr)
14538 +{
14539 + u16 fctl;
14540 + u16 dur;
14541 + u8 fallback_bitrate;
14542 + int ofdm_modulation;
14543 + int fallback_ofdm_modulation;
14544 + u8 *sa, *da;
14545 + u16 flen;
14546 +
14547 + sa = ieee80211_get_SA((struct ieee80211_hdr *)wlhdr);
14548 + da = ieee80211_get_DA((struct ieee80211_hdr *)wlhdr);
14549 + fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
14550 + ofdm_modulation = !(bcm43xx_is_cck_rate(bitrate));
14551 + fallback_ofdm_modulation = !(bcm43xx_is_cck_rate(fallback_bitrate));
14552 +
14553 + flen = sizeof(u16) + sizeof(u16) + ETH_ALEN + ETH_ALEN + FCS_LEN,
14554 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_plcp),
14555 + flen, bitrate,
14556 + !bcm43xx_is_cck_rate(bitrate));
14557 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_fallback_plcp),
14558 + flen, fallback_bitrate,
14559 + !bcm43xx_is_cck_rate(fallback_bitrate));
14560 + fctl = WLAN_FC_TYPE_CTRL << 2;
14561 + fctl |= WLAN_FC_STYPE_RTS << 4;
14562 + dur = le16_to_cpu(wlhdr->duration_id);
14563 +/*FIXME: should we test for dur==0 here and let it unmodified in this case?
14564 + * The following assert checks for this case...
14565 + */
14566 +assert(dur);
14567 +/*FIXME: The duration calculation is not really correct.
14568 + * I am not 100% sure which bitrate to use. We use the RTS rate here,
14569 + * but this is likely to be wrong.
14570 + */
14571 + if (phy->type == BCM43xx_PHYTYPE_A) {
14572 + /* Three times SIFS */
14573 + dur += 16 * 3;
14574 + /* Add ACK duration. */
14575 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14576 + bitrate * 4);
14577 + /* Add CTS duration. */
14578 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14579 + bitrate * 4);
14580 + } else {
14581 + /* Three times SIFS */
14582 + dur += 10 * 3;
14583 + /* Add ACK duration. */
14584 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14585 + bitrate);
14586 + /* Add CTS duration. */
14587 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14588 + bitrate);
14589 + }
14590 +
14591 + txhdr->rts_cts_frame_control = cpu_to_le16(fctl);
14592 + txhdr->rts_cts_dur = cpu_to_le16(dur);
14593 +//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(wlhdr->addr1), BCM43xx_MACARG(wlhdr->addr2), BCM43xx_MACARG(wlhdr->addr3));
14594 +//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(sa), BCM43xx_MACARG(da));
14595 + memcpy(txhdr->rts_cts_mac1, wlhdr->addr1, ETH_ALEN);//FIXME!
14596 + memcpy(txhdr->rts_cts_mac2, sa, ETH_ALEN);
14597 +
14598 + *flags |= BCM43xx_TXHDRFLAG_RTSCTS;
14599 + *flags |= BCM43xx_TXHDRFLAG_RTS;
14600 + if (ofdm_modulation)
14601 + *flags |= BCM43xx_TXHDRFLAG_RTSCTS_OFDM;
14602 + if (fallback_ofdm_modulation)
14603 + *flags |= BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM;
14604 +}
14605 +
14606 +void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
14607 + struct bcm43xx_txhdr *txhdr,
14608 + const unsigned char *fragment_data,
14609 + const unsigned int fragment_len,
14610 + const int is_first_fragment,
14611 + const u16 cookie,
14612 + struct ieee80211_tx_control *txctl)
14613 +{
14614 + const struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14615 + const struct ieee80211_hdr *wireless_header = (const struct ieee80211_hdr *)fragment_data;
14616 + const int use_encryption = (!txctl->do_not_encrypt && txctl->key_idx >= 0);
14617 + u8 bitrate;
14618 + u8 fallback_bitrate;
14619 + int ofdm_modulation;
14620 + int fallback_ofdm_modulation;
14621 + u16 plcp_fragment_len = fragment_len;
14622 + u16 flags = 0;
14623 + u16 control = 0;
14624 + u16 wsec_rate = 0;
14625 +
14626 + /* Now construct the TX header. */
14627 + memset(txhdr, 0, sizeof(*txhdr));
14628 +
14629 + bitrate = txctl->tx_rate;
14630 + ofdm_modulation = !(bcm43xx_is_cck_rate(bitrate));
14631 + fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
14632 + fallback_ofdm_modulation = !(bcm43xx_is_cck_rate(fallback_bitrate));
14633 +
14634 + /* Set Frame Control from 80211 header. */
14635 + txhdr->frame_control = wireless_header->frame_control;
14636 + /* Copy address1 from 80211 header. */
14637 + memcpy(txhdr->mac1, wireless_header->addr1, 6);
14638 + /* Set the fallback duration ID. */
14639 + txhdr->fallback_dur_id = bcm43xx_calc_duration_id(wireless_header,
14640 + fallback_bitrate);
14641 + /* Set the cookie (used as driver internal ID for the frame) */
14642 + txhdr->cookie = cpu_to_le16(cookie);
14643 +
14644 + /* Hardware appends FCS. */
14645 + plcp_fragment_len += FCS_LEN;
14646 + if (use_encryption) {
14647 + u16 key_idx = (u16)(txctl->key_idx);
14648 + struct bcm43xx_key *key = &(bcm->key[key_idx]);
14649 + int wlhdr_len;
14650 +
14651 + if (key->enabled) {
14652 + /* Hardware appends ICV. */
14653 + plcp_fragment_len += txctl->icv_len;
14654 +
14655 + wsec_rate |= ((key_idx & 0x000F) << 4);
14656 + wsec_rate |= key->algorithm;
14657 + wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
14658 + memcpy(txhdr->wep_iv, ((u8 *)wireless_header) + wlhdr_len, 4);
14659 + }
14660 + }
14661 + /* Generate the PLCP header and the fallback PLCP header. */
14662 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp),
14663 + plcp_fragment_len,
14664 + bitrate, ofdm_modulation);
14665 + bcm43xx_generate_plcp_hdr(&txhdr->fallback_plcp, plcp_fragment_len,
14666 + fallback_bitrate, fallback_ofdm_modulation);
14667 +
14668 + /* Set the CONTROL field */
14669 + if (ofdm_modulation)
14670 + control |= BCM43xx_TXHDRCTL_OFDM;
14671 + if (bcm->short_preamble) //FIXME: could be the other way around, please test
14672 + control |= BCM43xx_TXHDRCTL_SHORT_PREAMBLE;
14673 + control |= (phy->antenna_diversity << BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT)
14674 + & BCM43xx_TXHDRCTL_ANTENNADIV_MASK;
14675 +
14676 + /* Set the FLAGS field */
14677 + if (!txctl->no_ack)
14678 + flags |= BCM43xx_TXHDRFLAG_EXPECTACK;
14679 + if (1 /* FIXME: PS poll?? */)
14680 + flags |= 0x10; // FIXME: unknown meaning.
14681 + if (fallback_ofdm_modulation)
14682 + flags |= BCM43xx_TXHDRFLAG_FALLBACKOFDM;
14683 + if (is_first_fragment)
14684 + flags |= BCM43xx_TXHDRFLAG_FIRSTFRAGMENT;
14685 +
14686 + /* Set WSEC/RATE field */
14687 + wsec_rate |= (txhdr->plcp.raw[0] << BCM43xx_TXHDR_RATE_SHIFT)
14688 + & BCM43xx_TXHDR_RATE_MASK;
14689 +
14690 + /* Generate the RTS/CTS packet, if required. */
14691 + /* FIXME: We should first try with CTS-to-self,
14692 + * if we are on 80211g. If we get too many
14693 + * failures (hidden nodes), we should switch back to RTS/CTS.
14694 + */
14695 + if (txctl->use_rts_cts) {
14696 + bcm43xx_generate_rts(phy, txhdr, &flags,
14697 + txctl->rts_cts_rate,
14698 + wireless_header);
14699 + }
14700 +
14701 + txhdr->flags = cpu_to_le16(flags);
14702 + txhdr->control = cpu_to_le16(control);
14703 + txhdr->wsec_rate = cpu_to_le16(wsec_rate);
14704 +}
14705 +
14706 +static s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm,
14707 + u8 in_rssi, int ofdm,
14708 + int adjust_2053, int adjust_2050)
14709 +{
14710 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14711 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14712 + s32 tmp;
14713 +
14714 + switch (radio->version) {
14715 + case 0x2050:
14716 + if (ofdm) {
14717 + tmp = in_rssi;
14718 + if (tmp > 127)
14719 + tmp -= 256;
14720 + tmp *= 73;
14721 + tmp /= 64;
14722 + if (adjust_2050)
14723 + tmp += 25;
14724 + else
14725 + tmp -= 3;
14726 + } else {
14727 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
14728 + if (in_rssi > 63)
14729 + in_rssi = 63;
14730 + tmp = radio->nrssi_lt[in_rssi];
14731 + tmp = 31 - tmp;
14732 + tmp *= -131;
14733 + tmp /= 128;
14734 + tmp -= 57;
14735 + } else {
14736 + tmp = in_rssi;
14737 + tmp = 31 - tmp;
14738 + tmp *= -149;
14739 + tmp /= 128;
14740 + tmp -= 68;
14741 + }
14742 + if (phy->type == BCM43xx_PHYTYPE_G &&
14743 + adjust_2050)
14744 + tmp += 25;
14745 + }
14746 + break;
14747 + case 0x2060:
14748 + if (in_rssi > 127)
14749 + tmp = in_rssi - 256;
14750 + else
14751 + tmp = in_rssi;
14752 + break;
14753 + default:
14754 + tmp = in_rssi;
14755 + tmp -= 11;
14756 + tmp *= 103;
14757 + tmp /= 64;
14758 + if (adjust_2053)
14759 + tmp -= 109;
14760 + else
14761 + tmp -= 83;
14762 + }
14763 +
14764 + return (s8)tmp;
14765 +}
14766 +
14767 +//TODO
14768 +#if 0
14769 +static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm,
14770 + u8 in_rssi)
14771 +{
14772 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14773 + s8 ret;
14774 +
14775 + if (phy->type == BCM43xx_PHYTYPE_A) {
14776 + //TODO: Incomplete specs.
14777 + ret = 0;
14778 + } else
14779 + ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
14780 +
14781 + return ret;
14782 +}
14783 +#endif
14784 +
14785 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14786 + struct sk_buff *skb,
14787 + struct bcm43xx_rxhdr *rxhdr)
14788 +{
14789 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14790 + struct bcm43xx_plcp_hdr4 *plcp;
14791 + struct ieee80211_rx_status status;
14792 + const u16 rxflags1 = le16_to_cpu(rxhdr->flags1);
14793 + const u16 rxflags2 = le16_to_cpu(rxhdr->flags2);
14794 + const u16 rxflags3 = le16_to_cpu(rxhdr->flags3);
14795 + const int is_ofdm = !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_OFDM);
14796 +
14797 + if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME) {
14798 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data + 2);
14799 + /* Skip two unknown bytes and the PLCP header. */
14800 + skb_pull(skb, 2 + sizeof(struct bcm43xx_plcp_hdr6));
14801 + } else {
14802 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
14803 + /* Skip the PLCP header. */
14804 + skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
14805 + }
14806 + /* The SKB contains the PAYLOAD (wireless header + data)
14807 + * at this point.
14808 + */
14809 +
14810 + memset(&status, 0, sizeof(status));
14811 + status.ssi = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm,
14812 + !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ),
14813 + !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ));
14814 + if (is_ofdm)
14815 + status.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
14816 + else
14817 + status.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
14818 + status.channel = radio->channel;
14819 +
14820 + bcm->stats.last_rx = jiffies;
14821 + ieee80211_rx_irqsafe(bcm->net_dev, skb, &status);
14822 +}
14823 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h
14824 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h 1970-01-01 01:00:00.000000000 +0100
14825 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h 2006-03-28 22:16:14.000000000 +0200
14826 @@ -0,0 +1,157 @@
14827 +#ifndef BCM43xx_XMIT_H_
14828 +#define BCM43xx_XMIT_H_
14829 +
14830 +#include "bcm43xx_main.h"
14831 +
14832 +
14833 +#define _bcm43xx_declare_plcp_hdr(size) \
14834 + struct bcm43xx_plcp_hdr##size { \
14835 + union { \
14836 + __le32 data; \
14837 + __u8 raw[size]; \
14838 + } __attribute__((__packed__)); \
14839 + } __attribute__((__packed__))
14840 +
14841 +/* struct bcm43xx_plcp_hdr4 */
14842 +_bcm43xx_declare_plcp_hdr(4);
14843 +/* struct bcm43xx_plcp_hdr6 */
14844 +_bcm43xx_declare_plcp_hdr(6);
14845 +
14846 +#undef _bcm43xx_declare_plcp_hdr
14847 +
14848 +/* Device specific TX header. To be prepended to TX frames. */
14849 +struct bcm43xx_txhdr {
14850 + union {
14851 + struct {
14852 + __le16 flags;
14853 + __le16 wsec_rate;
14854 + __le16 frame_control;
14855 + u16 unknown_zeroed_0;
14856 + __le16 control;
14857 + u8 wep_iv[10];
14858 + u8 unknown_wsec_tkip_data[3]; //FIXME
14859 + PAD_BYTES(3);
14860 + u8 mac1[6];
14861 + u16 unknown_zeroed_1;
14862 + struct bcm43xx_plcp_hdr4 rts_cts_fallback_plcp;
14863 + __le16 rts_cts_dur_fallback;
14864 + struct bcm43xx_plcp_hdr4 fallback_plcp;
14865 + __le16 fallback_dur_id;
14866 + PAD_BYTES(2);
14867 + __le16 cookie;
14868 + __le16 unknown_scb_stuff; //FIXME
14869 + struct bcm43xx_plcp_hdr6 rts_cts_plcp;
14870 + __le16 rts_cts_frame_control;
14871 + __le16 rts_cts_dur;
14872 + u8 rts_cts_mac1[6];
14873 + u8 rts_cts_mac2[6];
14874 + PAD_BYTES(2);
14875 + struct bcm43xx_plcp_hdr6 plcp;
14876 + } __attribute__((__packed__));
14877 + u8 raw[82];
14878 + } __attribute__((__packed__));
14879 +} __attribute__((__packed__));
14880 +
14881 +/* Values/Masks for the device TX header */
14882 +#define BCM43xx_TXHDRFLAG_EXPECTACK 0x0001
14883 +#define BCM43xx_TXHDRFLAG_RTSCTS 0x0002
14884 +#define BCM43xx_TXHDRFLAG_RTS 0x0004
14885 +#define BCM43xx_TXHDRFLAG_FIRSTFRAGMENT 0x0008
14886 +#define BCM43xx_TXHDRFLAG_DESTPSMODE 0x0020
14887 +#define BCM43xx_TXHDRFLAG_RTSCTS_OFDM 0x0080
14888 +#define BCM43xx_TXHDRFLAG_FALLBACKOFDM 0x0100
14889 +#define BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM 0x0200
14890 +#define BCM43xx_TXHDRFLAG_CTS 0x0400
14891 +#define BCM43xx_TXHDRFLAG_FRAMEBURST 0x0800
14892 +
14893 +#define BCM43xx_TXHDRCTL_OFDM 0x0001
14894 +#define BCM43xx_TXHDRCTL_SHORT_PREAMBLE 0x0010
14895 +#define BCM43xx_TXHDRCTL_ANTENNADIV_MASK 0x0030
14896 +#define BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT 8
14897 +
14898 +#define BCM43xx_TXHDR_RATE_MASK 0x0F00
14899 +#define BCM43xx_TXHDR_RATE_SHIFT 8
14900 +#define BCM43xx_TXHDR_RTSRATE_MASK 0xF000
14901 +#define BCM43xx_TXHDR_RTSRATE_SHIFT 12
14902 +#define BCM43xx_TXHDR_WSEC_KEYINDEX_MASK 0x00F0
14903 +#define BCM43xx_TXHDR_WSEC_KEYINDEX_SHIFT 4
14904 +#define BCM43xx_TXHDR_WSEC_ALGO_MASK 0x0003
14905 +#define BCM43xx_TXHDR_WSEC_ALGO_SHIFT 0
14906 +
14907 +void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
14908 + struct bcm43xx_txhdr *txhdr,
14909 + const unsigned char *fragment_data,
14910 + const unsigned int fragment_len,
14911 + const int is_first_fragment,
14912 + const u16 cookie,
14913 + struct ieee80211_tx_control *txctl);
14914 +
14915 +/* RX header as received from the hardware. */
14916 +struct bcm43xx_rxhdr {
14917 + /* Frame Length. Must be generated explicitely in PIO mode. */
14918 + __le16 frame_length;
14919 + PAD_BYTES(2);
14920 + /* Flags field 1 */
14921 + __le16 flags1;
14922 + u8 rssi;
14923 + u8 signal_quality;
14924 + PAD_BYTES(2);
14925 + /* Flags field 3 */
14926 + __le16 flags3;
14927 + /* Flags field 2 */
14928 + __le16 flags2;
14929 + /* Lower 16bits of the TSF at the time the frame started. */
14930 + __le16 mactime;
14931 + PAD_BYTES(14);
14932 +} __attribute__((__packed__));
14933 +
14934 +#define BCM43xx_RXHDR_FLAGS1_OFDM (1 << 0)
14935 +/*#define BCM43xx_RXHDR_FLAGS1_SIGNAL??? (1 << 3) FIXME */
14936 +#define BCM43xx_RXHDR_FLAGS1_SHORTPREAMBLE (1 << 7)
14937 +#define BCM43xx_RXHDR_FLAGS1_2053RSSIADJ (1 << 14)
14938 +
14939 +#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
14940 +#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
14941 +/*FIXME: WEP related flags */
14942 +
14943 +#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
14944 +
14945 +/* Transmit Status as received from the hardware. */
14946 +struct bcm43xx_hwxmitstatus {
14947 + PAD_BYTES(4);
14948 + __le16 cookie;
14949 + u8 flags;
14950 + u8 cnt1:4,
14951 + cnt2:4;
14952 + PAD_BYTES(2);
14953 + __le16 seq;
14954 + __le16 unknown; //FIXME
14955 +} __attribute__((__packed__));
14956 +
14957 +/* Transmit Status in CPU byteorder. */
14958 +struct bcm43xx_xmitstatus {
14959 + u16 cookie;
14960 + u8 flags;
14961 + u8 cnt1:4,
14962 + cnt2:4;
14963 + u16 seq;
14964 + u16 unknown; //FIXME
14965 +};
14966 +
14967 +#define BCM43xx_TXSTAT_FLAG_ACK 0x01
14968 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x02
14969 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x04
14970 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x08
14971 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x10
14972 +#define BCM43xx_TXSTAT_FLAG_IGNORE 0x20
14973 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x40
14974 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x80
14975 +
14976 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
14977 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
14978 +
14979 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14980 + struct sk_buff *skb,
14981 + struct bcm43xx_rxhdr *rxhdr);
14982 +
14983 +#endif /* BCM43xx_XMIT_H_ */
14984 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Kconfig linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Kconfig
14985 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Kconfig 1970-01-01 01:00:00.000000000 +0100
14986 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Kconfig 2006-03-28 22:16:14.000000000 +0200
14987 @@ -0,0 +1,62 @@
14988 +config BCM43XX_D80211
14989 + tristate "Broadcom BCM43xx wireless support (DeviceScape stack)"
14990 + depends on PCI && D80211 && NET_RADIO && EXPERIMENTAL
14991 + select FW_LOADER
14992 + ---help---
14993 + This is an experimental driver for the Broadcom 43xx wireless chip,
14994 + found in the Apple Airport Extreme and various other devices.
14995 +
14996 +config BCM43XX_D80211_DEBUG
14997 + bool "Broadcom BCM43xx debugging (RECOMMENDED)"
14998 + depends on BCM43XX_D80211
14999 + default y
15000 + ---help---
15001 + Broadcom 43xx debugging messages.
15002 + Say Y, because the driver is still very experimental and
15003 + this will help you get it running.
15004 +
15005 +config BCM43XX_D80211_DMA
15006 + bool
15007 +config BCM43XX_D80211_PIO
15008 + bool
15009 +
15010 +choice
15011 + prompt "BCM43xx data transfer mode"
15012 + depends on BCM43XX_D80211
15013 + default BCM43XX_D80211_DMA_AND_PIO_MODE
15014 +
15015 +config BCM43XX_D80211_DMA_AND_PIO_MODE
15016 + bool "DMA + PIO"
15017 + select BCM43XX_D80211_DMA
15018 + select BCM43XX_D80211_PIO
15019 + ---help---
15020 + Include both, Direct Memory Access (DMA) and Programmed I/O (PIO)
15021 + data transfer modes.
15022 + The actually used mode is selectable through the module
15023 + parameter "pio". If the module parameter is pio=0, DMA is used.
15024 + Otherwise PIO is used. DMA is default.
15025 +
15026 + If unsure, choose this option.
15027 +
15028 +config BCM43XX_D80211_DMA_MODE
15029 + bool "DMA (Direct Memory Access) only"
15030 + select BCM43XX_D80211_DMA
15031 + ---help---
15032 + Only include Direct Memory Access (DMA).
15033 + This reduces the size of the driver module, by omitting the PIO code.
15034 +
15035 +config BCM43XX_D80211_PIO_MODE
15036 + bool "PIO (Programmed I/O) only"
15037 + select BCM43XX_D80211_PIO
15038 + ---help---
15039 + Only include Programmed I/O (PIO).
15040 + This reduces the size of the driver module, by omitting the DMA code.
15041 + Please note that PIO transfers are slow (compared to DMA).
15042 +
15043 + Also note that not all devices of the 43xx series support PIO.
15044 + The 4306 (Apple Airport Extreme and others) supports PIO, while
15045 + the 4318 is known to _not_ support PIO.
15046 +
15047 + Only use PIO, if DMA does not work for you.
15048 +
15049 +endchoice
15050 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Makefile linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Makefile
15051 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Makefile 1970-01-01 01:00:00.000000000 +0100
15052 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Makefile 2006-03-28 22:16:14.000000000 +0200
15053 @@ -0,0 +1,12 @@
15054 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211.o
15055 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DEBUG) += bcm43xx_debugfs.o
15056 +
15057 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DMA) += bcm43xx_dma.o
15058 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_PIO) += bcm43xx_pio.o
15059 +
15060 +bcm43xx-d80211-objs := bcm43xx_main.o bcm43xx_ilt.o \
15061 + bcm43xx_radio.o bcm43xx_phy.o \
15062 + bcm43xx_power.o bcm43xx_sysfs.o \
15063 + bcm43xx_leds.o bcm43xx_ethtool.o \
15064 + bcm43xx_xmit.o \
15065 + $(bcm43xx-d80211-obj-y)
15066 diff -Nur linux-2.6.16/drivers/net/wireless/Kconfig linux-2.6.16-bcm43xx/drivers/net/wireless/Kconfig
15067 --- linux-2.6.16/drivers/net/wireless/Kconfig 2006-03-20 06:53:29.000000000 +0100
15068 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/Kconfig 2006-03-28 22:16:38.000000000 +0200
15069 @@ -472,6 +472,7 @@
15070 will be called prism54.ko.
15071
15072 source "drivers/net/wireless/hostap/Kconfig"
15073 +source "drivers/net/wireless/bcm43xx-d80211/Kconfig"
15074
15075 # yes, this works even when no drivers are selected
15076 config NET_WIRELESS
15077 diff -Nur linux-2.6.16/drivers/net/wireless/Makefile linux-2.6.16-bcm43xx/drivers/net/wireless/Makefile
15078 --- linux-2.6.16/drivers/net/wireless/Makefile 2006-03-20 06:53:29.000000000 +0100
15079 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/Makefile 2006-03-28 22:16:46.000000000 +0200
15080 @@ -35,6 +35,7 @@
15081 obj-$(CONFIG_PRISM54) += prism54/
15082
15083 obj-$(CONFIG_HOSTAP) += hostap/
15084 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211/
15085
15086 # 16-bit wireless PCMCIA client drivers
15087 obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
15088 diff -Nur linux-2.6.16/include/net/d80211_common.h linux-2.6.16-bcm43xx/include/net/d80211_common.h
15089 --- linux-2.6.16/include/net/d80211_common.h 1970-01-01 01:00:00.000000000 +0100
15090 +++ linux-2.6.16-bcm43xx/include/net/d80211_common.h 2006-03-28 22:16:14.000000000 +0200
15091 @@ -0,0 +1,98 @@
15092 +/*
15093 + * IEEE 802.11 driver (80211.o) -- hostapd interface
15094 + * Copyright 2002-2004, Instant802 Networks, Inc.
15095 + *
15096 + * This program is free software; you can redistribute it and/or modify
15097 + * it under the terms of the GNU General Public License version 2 as
15098 + * published by the Free Software Foundation.
15099 + */
15100 +
15101 +#ifndef D80211_COMMON_H
15102 +#define D80211_COMMON_H
15103 +
15104 +#include <linux/types.h>
15105 +
15106 +/*
15107 + * This is common header information with user space. It is used on all
15108 + * frames sent to wlan#ap interface.
15109 + */
15110 +
15111 +#define IEEE80211_FI_VERSION 0x80211001
15112 +
15113 +struct ieee80211_frame_info {
15114 + u32 version;
15115 + u32 length;
15116 + u64 mactime;
15117 + u64 hosttime;
15118 + u32 phytype;
15119 + u32 channel;
15120 + u32 datarate;
15121 + u32 antenna;
15122 + u32 priority;
15123 + u32 ssi_type;
15124 + u32 ssi_signal;
15125 + u32 ssi_noise;
15126 + u32 preamble;
15127 + u32 encoding;
15128 +
15129 + /* Note: this structure is otherwise identical to capture format used
15130 + * in linux-wlan-ng, but this additional field is used to provide meta
15131 + * data about the frame to hostapd. This was the easiest method for
15132 + * providing this information, but this might change in the future. */
15133 + u32 msg_type;
15134 +} __attribute__ ((packed));
15135 +
15136 +
15137 +enum ieee80211_msg_type {
15138 + ieee80211_msg_normal = 0,
15139 + ieee80211_msg_tx_callback_ack = 1,
15140 + ieee80211_msg_tx_callback_fail = 2,
15141 + ieee80211_msg_passive_scan = 3,
15142 + ieee80211_msg_wep_frame_unknown_key = 4,
15143 + ieee80211_msg_michael_mic_failure = 5,
15144 + ieee80211_msg_monitor = 6,
15145 + ieee80211_msg_sta_not_assoc = 7,
15146 + ieee80211_msg_set_aid_for_sta = 8 /* used by Intersil MVC driver */,
15147 + ieee80211_msg_key_threshold_notification = 9,
15148 + ieee80211_msg_radar = 11,
15149 +};
15150 +
15151 +struct ieee80211_msg_set_aid_for_sta {
15152 + char sta_address[ETH_ALEN];
15153 + u16 aid;
15154 +};
15155 +
15156 +struct ieee80211_msg_key_notification {
15157 + int tx_rx_count;
15158 + char ifname[IFNAMSIZ];
15159 + u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
15160 +};
15161 +
15162 +
15163 +enum ieee80211_phytype {
15164 + ieee80211_phytype_fhss_dot11_97 = 1,
15165 + ieee80211_phytype_dsss_dot11_97 = 2,
15166 + ieee80211_phytype_irbaseband = 3,
15167 + ieee80211_phytype_dsss_dot11_b = 4,
15168 + ieee80211_phytype_pbcc_dot11_b = 5,
15169 + ieee80211_phytype_ofdm_dot11_g = 6,
15170 + ieee80211_phytype_pbcc_dot11_g = 7,
15171 + ieee80211_phytype_ofdm_dot11_a = 8,
15172 + ieee80211_phytype_dsss_dot11_turbog = 255,
15173 + ieee80211_phytype_dsss_dot11_turbo = 256,
15174 +};
15175 +
15176 +enum ieee80211_ssi_type {
15177 + ieee80211_ssi_none = 0,
15178 + ieee80211_ssi_norm = 1, /* normalized, 0-1000 */
15179 + ieee80211_ssi_dbm = 2,
15180 + ieee80211_ssi_raw = 3, /* raw SSI */
15181 +};
15182 +
15183 +struct ieee80211_radar_info {
15184 + int channel;
15185 + int radar;
15186 + int radar_type;
15187 +};
15188 +
15189 +#endif /* D80211_COMMON_H */
15190 diff -Nur linux-2.6.16/include/net/d80211.h linux-2.6.16-bcm43xx/include/net/d80211.h
15191 --- linux-2.6.16/include/net/d80211.h 1970-01-01 01:00:00.000000000 +0100
15192 +++ linux-2.6.16-bcm43xx/include/net/d80211.h 2006-03-28 22:16:14.000000000 +0200
15193 @@ -0,0 +1,870 @@
15194 +/*
15195 + * Low-level hardware driver -- IEEE 802.11 driver (80211.o) interface
15196 + * Copyright 2002-2005, Devicescape Software, Inc.
15197 + *
15198 + * This program is free software; you can redistribute it and/or modify
15199 + * it under the terms of the GNU General Public License version 2 as
15200 + * published by the Free Software Foundation.
15201 + */
15202 +
15203 +#ifndef D80211_H
15204 +#define D80211_H
15205 +
15206 +#include <linux/kernel.h>
15207 +#include <linux/if_ether.h>
15208 +#include <linux/netdevice.h>
15209 +#include <linux/skbuff.h>
15210 +#include <linux/wireless.h>
15211 +#include "d80211_shared.h"
15212 +
15213 +/* Note! Only ieee80211_tx_status_irqsafe() and ieee80211_rx_irqsave() can be
15214 + * called in hardware interrupt context. The low-level driver must not call any
15215 + * other functions in hardware interrupt context. If there is a need for such
15216 + * call, the low-level driver should first ACK the interrupt and perform the
15217 + * IEEE 802.11 code call after this, e.g., from a scheduled tasklet (in
15218 + * software interrupt context).
15219 + */
15220 +
15221 +/*
15222 + * Frame format used when passing frame between low-level hardware drivers
15223 + * and IEEE 802.11 driver the same as used in the wireless media, i.e.,
15224 + * buffers start with IEEE 802.11 header and include the same octets that
15225 + * are sent over air.
15226 + *
15227 + * If hardware uses IEEE 802.3 headers (and perform 802.3 <-> 802.11
15228 + * conversion in firmware), upper layer 802.11 code needs to be changed to
15229 + * support this.
15230 + *
15231 + * If the receive frame format is not the same as the real frame sent
15232 + * on the wireless media (e.g., due to padding etc.), upper layer 802.11 code
15233 + * could be updated to provide support for such format assuming this would
15234 + * optimize the performance, e.g., by removing need to re-allocation and
15235 + * copying of the data.
15236 + */
15237 +
15238 +/* Interface version (used for compatibility verification) */
15239 +#define IEEE80211_VERSION 2
15240 +
15241 +
15242 +/* Channel information structure. Low-level driver is expected to fill in chan,
15243 + * freq, and val fields. Other fields will be filled in by 80211.o based on
15244 + * hostapd information and low-level driver does not need to use them. The
15245 + * limits for each channel will be provided in 'struct ieee80211_conf' when
15246 + * configuring the low-level driver with hw->config callback. */
15247 +struct ieee80211_channel {
15248 + short chan; /* channel number (IEEE 802.11) */
15249 + short freq; /* frequency in MHz */
15250 + int val; /* hw specific value for the channel */
15251 + int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
15252 + unsigned char power_level;
15253 + unsigned char antenna_max;
15254 +};
15255 +
15256 +struct ieee80211_rate {
15257 + int rate; /* rate in 100 kbps */
15258 + int val; /* hw specific value for the rate */
15259 + int flags; /* IEEE80211_RATE_ flags */
15260 + int val2; /* hw specific value for the rate when using short preamble
15261 + * (only when IEEE80211_RATE_PREAMBLE2 flag is set, i.e., for
15262 + * 2, 5.5, and 11 Mbps) */
15263 + signed char min_rssi_ack;
15264 + unsigned char min_rssi_ack_delta;
15265 +
15266 + /* following fields are set by 80211.o and need not be filled by the
15267 + * low-level driver */
15268 + int rate_inv; /* inverse of the rate (LCM(all rates) / rate) for
15269 + * optimizing channel utilization estimates */
15270 +};
15271 +
15272 +struct ieee80211_hw_modes {
15273 + int mode;
15274 + int num_channels;
15275 + struct ieee80211_channel *channels;
15276 + int num_rates;
15277 + struct ieee80211_rate *rates;
15278 + int xr_end; /* only used with Atheros XR */
15279 +};
15280 +
15281 +struct ieee80211_tx_queue_params {
15282 + int aifs; /* 0 .. 255; -1 = use default */
15283 + int cw_min; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
15284 + int cw_max; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
15285 + int burst_time; /* maximum burst time in 0.1 ms (i.e., 10 = 1 ms);
15286 + * 0 = disabled */
15287 +};
15288 +
15289 +#define NUM_TX_DATA_QUEUES 6
15290 +
15291 +struct ieee80211_tx_queue_stats_data {
15292 + unsigned int len; /* num packets in queue */
15293 + unsigned int limit; /* queue len (soft) limit */
15294 + unsigned int count; /* total num frames sent */
15295 +};
15296 +
15297 +struct ieee80211_tx_queue_stats {
15298 + struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES];
15299 +};
15300 +
15301 +#ifndef IEEE80211_TX_QUEUE_NUMS
15302 +#define IEEE80211_TX_QUEUE_NUMS
15303 +/* TODO: these need to be synchronized with hostapd_ioctl.h; make a shared
15304 + * header file that can be included into low-level drivers, 80211.o, and
15305 + * hostapd */
15306 +enum {
15307 + IEEE80211_TX_QUEUE_DATA0 = 0,
15308 + IEEE80211_TX_QUEUE_DATA1 = 1,
15309 + IEEE80211_TX_QUEUE_DATA2 = 2,
15310 + IEEE80211_TX_QUEUE_DATA3 = 3,
15311 + IEEE80211_TX_QUEUE_DATA4 = 4,
15312 + IEEE80211_TX_QUEUE_SVP = 5,
15313 + IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
15314 + IEEE80211_TX_QUEUE_BEACON = 7
15315 +};
15316 +#endif /* IEEE80211_TX_QUEUE_NUMS */
15317 +
15318 +
15319 +struct ieee80211_low_level_stats {
15320 + unsigned int dot11ACKFailureCount;
15321 + unsigned int dot11RTSFailureCount;
15322 + unsigned int dot11FCSErrorCount;
15323 + unsigned int dot11RTSSuccessCount;
15324 +};
15325 +
15326 +/* Transmit control fields. This data structure is passed to low-level driver
15327 + * with each TX frame. The low-level driver is responsible of configuring
15328 + * hardware to use given values (depending on what is supported). */
15329 +#define HW_KEY_IDX_INVALID -1
15330 +
15331 +struct ieee80211_tx_control {
15332 + enum { PKT_NORMAL = 0, PKT_PROBE_RESP } pkt_type;
15333 + int tx_rate; /* Transmit rate, given as the hw specific value for the
15334 + * rate (from struct ieee80211_rate) */
15335 + int rts_cts_rate; /* Transmit rate for RTS/CTS frame, given as the hw
15336 + * specific value for the rate (from
15337 + * struct ieee80211_rate) */
15338 + /* 1 = only first attempt, 2 = one retry, .. */
15339 + unsigned int retry_limit:8;
15340 + /* duration field for RTS/CTS frame */
15341 + unsigned int rts_cts_duration:16;
15342 + unsigned int req_tx_status:1; /* request TX status callback for this
15343 + * frame */
15344 + unsigned int do_not_encrypt:1; /* send this frame without encryption;
15345 + * e.g., for EAPOL frames */
15346 + unsigned int use_rts_cts:1; /* Use RTS-CTS before sending frame. */
15347 + unsigned int use_cts_protect:1; /* Use CTS protection for the frame
15348 + * (e.g., for combined 802.11g /
15349 + * 802.11b networks) */
15350 + unsigned int no_ack:1; /* Tell the low level not to wait for an ack */
15351 + unsigned int rate_ctrl_probe:1;
15352 + unsigned int clear_dst_mask:1;
15353 + unsigned int requeue:1;
15354 + /* following three flags are only used with Atheros Super A/G */
15355 + unsigned int compress:1;
15356 + unsigned int turbo_prime_notify:1; /* notify HostaAPd after frame
15357 + * transmission */
15358 + unsigned int fast_frame:1;
15359 +
15360 + unsigned int atheros_xr:1; /* only used with Atheros XR */
15361 +
15362 + unsigned int power_level:8; /* per-packet transmit power level, in dBm
15363 + */
15364 + unsigned int antenna_sel:4; /* 0 = default/diversity,
15365 + * 1 = Ant0, 2 = Ant1 */
15366 + int key_idx:8; /* -1 = do not encrypt, >= 0 keyidx from hw->set_key()
15367 + */
15368 + int icv_len:8; /* Length of the ICV/MIC field in octets */
15369 + int iv_len:8; /* Length of the IV field in octets */
15370 + unsigned int queue:4; /* hardware queue to use for this frame;
15371 + * 0 = highest, hw->queues-1 = lowest */
15372 + unsigned int sw_retry_attempt:4; /* no. of times hw has tried to
15373 + * transmit frame (not incl. hw retries) */
15374 +
15375 + int rateidx; /* internal 80211.o rateidx */
15376 + int alt_retry_rate; /* retry rate for the last retries, given as the
15377 + * hw specific value for the rate (from
15378 + * struct ieee80211_rate). To be used to limit
15379 + * packet dropping when probing higher rates, if hw
15380 + * supports multiple retry rates. -1 = not used */
15381 + struct ieee80211_sub_if_data *sdata; /* internal */
15382 +};
15383 +
15384 +/* Stored in sk_buff->cb */
15385 +struct ieee80211_tx_packet_data {
15386 + struct ieee80211_sub_if_data *sdata;
15387 + unsigned long jiffies;
15388 + unsigned int req_tx_status:1;
15389 + unsigned int do_not_encrypt:1;
15390 + unsigned int pkt_probe_resp:1;
15391 + unsigned int requeue:1;
15392 + unsigned int queue:4;
15393 +};
15394 +
15395 +#define RX_FLAG_MMIC_ERROR 0x1
15396 +#define RX_FLAG_DECRYPTED 0x2
15397 +#define RX_FLAG_XR_DOUBLE_CHIRP 0x4
15398 +
15399 +/* Receive status. The low-level driver should provide this information
15400 + * (the subset supported by hardware) to the 802.11 code with each received
15401 + * frame. */
15402 +struct ieee80211_rx_status {
15403 + u64 hosttime;
15404 + u64 mactime;
15405 + int freq; /* receive frequency in Mhz */
15406 + int channel;
15407 + int phymode;
15408 + int ssi;
15409 + int antenna;
15410 + int rate;
15411 + int flag;
15412 +};
15413 +
15414 +/* Transmit status. The low-level driver should provide this information
15415 + * (the subset supported by hardware) to the 802.11 code for each transmit
15416 + * frame. */
15417 +struct ieee80211_tx_status {
15418 + /* copied ieee80211_tx_control structure */
15419 + struct ieee80211_tx_control control;
15420 +
15421 + unsigned int tx_filtered:1;
15422 + unsigned int ack:1; /* whether the TX frame was ACKed */
15423 + int ack_signal; /* measured signal strength of the ACK frame */
15424 + int excessive_retries;
15425 + int retry_count;
15426 +
15427 + /* following two fields are only used with Atheros Super A/G */
15428 + int queue_length; /* information about TX queue */
15429 + int queue_number;
15430 +};
15431 +
15432 +
15433 +struct ieee80211_conf {
15434 + int channel; /* IEEE 802.11 channel number */
15435 + int freq; /* MHz */
15436 + int channel_val; /* hw specific value for the channel */
15437 +
15438 + int mode; /* IW_MODE_ */
15439 +
15440 + int phymode; /* MODE_IEEE80211A, .. */
15441 + unsigned int regulatory_domain;
15442 + int adm_status;
15443 +
15444 + int beacon_int;
15445 +
15446 + /* Bitfields, grouped together */
15447 +
15448 + int sw_encrypt:1;
15449 + int sw_decrypt:1;
15450 + int short_slot_time:1; /* use IEEE 802.11g Short Slot Time */
15451 + int ssid_hidden:1; /* do not broadcast the ssid */
15452 +
15453 + /* these fields are used by low level drivers for hardware
15454 + * that generate beacons independently */
15455 + u8 *ssid;
15456 + size_t ssid_len;
15457 + u8 *generic_elem;
15458 + size_t generic_elem_len;
15459 +
15460 + u8 power_level; /* transmit power limit for current
15461 + * regulatory domain; in dBm */
15462 + u8 antenna_max; /* maximum antenna gain */
15463 + short tx_power_reduction; /* in 0.1 dBm */
15464 +
15465 + int antenna_sel; /* default antenna conf:
15466 + * 0 = default/diversity,
15467 + * 1 = Ant0,
15468 + * 2 = Ant1 */
15469 +
15470 + int calib_int; /* hw/radio calibration interval in
15471 + * seconds */
15472 + int antenna_def;
15473 + int antenna_mode;
15474 +
15475 + u8 bssid_mask[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff = 1 BSSID */
15476 + int bss_count;
15477 +
15478 + int atheros_super_ag_compression;
15479 + int atheros_super_ag_fast_frame;
15480 + int atheros_super_ag_burst;
15481 + int atheros_super_ag_wme_ele;
15482 + int atheros_super_ag_turbo_g;
15483 + int atheros_super_ag_turbo_prime;
15484 +
15485 + int atheros_xr;
15486 +
15487 + u8 client_bssid[ETH_ALEN];
15488 +
15489 + /* Following five fields are used for IEEE 802.11H */
15490 + unsigned int radar_detect;
15491 + unsigned int spect_mgmt;
15492 + unsigned int quiet_duration; /* duration of quiet period */
15493 + unsigned int quiet_offset; /* how far into the beacon is the quiet
15494 + * period */
15495 + unsigned int quiet_period;
15496 + u8 radar_firpwr_threshold;
15497 + u8 radar_rssi_threshold;
15498 + u8 pulse_height_threshold;
15499 + u8 pulse_rssi_threshold;
15500 + u8 pulse_inband_threshold;
15501 +};
15502 +
15503 +
15504 +typedef enum { ALG_NONE, ALG_WEP, ALG_TKIP, ALG_CCMP, ALG_NULL }
15505 +ieee80211_key_alg;
15506 +
15507 +
15508 +struct ieee80211_key_conf {
15509 +
15510 + int hw_key_idx; /* filled + used by low-level driver */
15511 + ieee80211_key_alg alg;
15512 + int keylen;
15513 +
15514 + int force_sw_encrypt:1; /* to be cleared by low-level driver */
15515 + int keyidx:8; /* WEP key index */
15516 + int default_tx_key:1; /* This key is the new default TX key
15517 + * (used only for broadcast keys). */
15518 + int default_wep_only:1; /* static WEP is the only configured security
15519 + * policy; this allows some low-level drivers
15520 + * to determine when hwaccel can be used */
15521 + u8 key[0];
15522 +};
15523 +
15524 +#define IEEE80211_SCAN_START 1
15525 +#define IEEE80211_SCAN_END 2
15526 +
15527 +struct ieee80211_scan_conf {
15528 + int scan_channel; /* IEEE 802.11 channel number to do passive scan
15529 + * on */
15530 + int scan_freq; /* new freq in MHz to switch to for passive scan
15531 + */
15532 + int scan_channel_val; /* hw specific value for the channel */
15533 + int scan_phymode; /* MODE_IEEE80211A, .. */
15534 + unsigned char scan_power_level;
15535 + unsigned char scan_antenna_max;
15536 +
15537 +
15538 + int running_channel; /* IEEE 802.11 channel number we operate on
15539 + * normally */
15540 + int running_freq; /* freq in MHz we're operating on normally */
15541 + int running_channel_val; /* hw specific value for the channel */
15542 + int running_phymode;
15543 + unsigned char running_power_level;
15544 + unsigned char running_antenna_max;
15545 +
15546 + int scan_time; /* time a scan will take in us */
15547 + int tries;
15548 +
15549 + struct sk_buff *skb; /* skb to transmit before changing channels, maybe
15550 + * NULL for none */
15551 + struct ieee80211_tx_control *tx_control;
15552 +
15553 +};
15554 +
15555 +#ifndef IW_MODE_ADHOC
15556 +#define IW_MODE_ADHOC 1
15557 +#endif
15558 +
15559 +#ifndef IW_MODE_INFRA
15560 +#define IW_MODE_INFRA 2
15561 +#endif
15562 +
15563 +#ifndef IW_MODE_MASTER
15564 +#define IW_MODE_MASTER 3
15565 +#endif
15566 +
15567 +#ifndef IW_MODE_MONITOR
15568 +#define IW_MODE_MONITOR 6
15569 +#endif
15570 +
15571 +#define IEEE80211_SEQ_COUNTER_RX 0
15572 +#define IEEE80211_SEQ_COUNTER_TX 1
15573 +
15574 +typedef enum {
15575 + SET_KEY, DISABLE_KEY, REMOVE_ALL_KEYS,
15576 + ENABLE_COMPRESSION, DISABLE_COMPRESSION
15577 +} set_key_cmd;
15578 +
15579 +/* Configuration block used by the low-level driver to tell 802.11 code about
15580 + * supported hardware features and to pass function pointers for callback
15581 + * functions. */
15582 +struct ieee80211_hw {
15583 + int version; /* IEEE80211_VERSION */
15584 +
15585 + /* Driver name */
15586 + char *name;
15587 +
15588 + /* TODO: frame_type 802.11/802.3, sw_encryption requirements */
15589 +
15590 + /* Some wireless LAN chipsets generate beacons in the hardware/firmware
15591 + * and others rely on host generated beacons. This option is used to
15592 + * configure upper layer IEEE 802.11 module to generate beacons. The
15593 + * low-level driver can use ieee80211_beacon_get() to fetch next
15594 + * beacon frame. */
15595 + int host_gen_beacon:1;
15596 +
15597 +
15598 + /* Some devices handle decryption internally and do not
15599 + * indicate whether the frame was encrypted (unencrypted frames
15600 + * will be dropped by the hardware, unless specifically allowed
15601 + * through) */
15602 + int device_hides_wep:1;
15603 +
15604 + /* Whether RX frames passed to ieee80211_rx() include FCS in the end
15605 + */
15606 + int rx_includes_fcs:1;
15607 +
15608 + /* Some wireless LAN chipsets buffer broadcast/multicast frames for
15609 + * power saving stations in the hardware/firmware and others rely on
15610 + * the host system for such buffering. This option is used to
15611 + * configure upper layer IEEE 802.11 to buffer broadcast/multicast
15612 + * frames when there are power saving stations so that low-level driver
15613 + * can fetch them with ieee80211_get_buffered_bc(). */
15614 + int host_broadcast_ps_buffering:1;
15615 +
15616 + int wep_include_iv:1;
15617 + int data_nullfunc_ack:1; /* will data nullfunc frames get proper
15618 + * TX status callback */
15619 +
15620 + /* Force sw version of encryption for TKIP packets if WMM is enabled.
15621 + */
15622 + int no_tkip_wmm_hwaccel:1;
15623 +
15624 + /* 1 if the payload needs to be padded at even boundaries after the
15625 + * header */
15626 + unsigned int extra_hdr_room:1;
15627 +
15628 + /* Some devices handle Michael MIC internally and do not include MIC in
15629 + * the received packets given to 80211.o. device_strips_mic must be set
15630 + * for such devices. ISWEP bit is still expected to be set in the IEEE
15631 + * 802.11 header with this option unlike with device_hides_wep option.
15632 + */
15633 + unsigned int device_strips_mic:1;
15634 +
15635 + /* 1 = low-level driver supports skb fraglist (NETIF_F_FRAGLIST), i.e.,
15636 + * more than one skb per frame */
15637 + unsigned int fraglist;
15638 +
15639 + /* This is the time in us to change channels
15640 + */
15641 + int channel_change_time;
15642 +
15643 + int num_modes;
15644 + struct ieee80211_hw_modes *modes;
15645 +
15646 + /* Handler that 802.11 module calls for each transmitted frame.
15647 + * skb contains the buffer starting from the IEEE 802.11 header.
15648 + * The low-level driver should send the frame out based on
15649 + * configuration in the TX control data. */
15650 + int (*tx)(struct net_device *dev, struct sk_buff *skb,
15651 + struct ieee80211_tx_control *control);
15652 +
15653 + /* Handler for performing hardware reset. */
15654 + int (*reset)(struct net_device *dev);
15655 +
15656 + /* Handler that is called when any netdevice attached to the hardware
15657 + * device is set UP for the first time. This can be used, e.g., to
15658 + * enable interrupts and beacon sending. */
15659 + int (*open)(struct net_device *dev);
15660 +
15661 + /* Handler that is called when the last netdevice attached to the
15662 + * hardware device is set DOWN. This can be used, e.g., to disable
15663 + * interrupts and beacon sending. */
15664 + int (*stop)(struct net_device *dev);
15665 +
15666 + /* Handler for configuration requests. IEEE 802.11 code calls this
15667 + * function to change hardware configuration, e.g., channel. */
15668 + int (*config)(struct net_device *dev, struct ieee80211_conf *conf);
15669 +
15670 + /* Set TIM bit handler. If the hardware/firmware takes care of beacon
15671 + * generation, IEEE 802.11 code uses this function to tell the
15672 + * low-level to set (or clear if set==0) TIM bit for the given aid. If
15673 + * host system is used to generate beacons, this handler is not used
15674 + * and low-level driver should set it to NULL. */
15675 + int (*set_tim)(struct net_device *dev, int aid, int set);
15676 +
15677 + /* Set encryption key. IEEE 802.11 module calls this function to set
15678 + * encryption keys. addr is ff:ff:ff:ff:ff:ff for default keys and
15679 + * station hwaddr for individual keys. aid of the station is given
15680 + * to help low-level driver in selecting which key->hw_key_idx to use
15681 + * for this key. TX control data will use the hw_key_idx selected by
15682 + * the low-level driver. */
15683 + int (*set_key)(struct net_device *dev, set_key_cmd cmd, u8 *addr,
15684 + struct ieee80211_key_conf *key, int aid);
15685 +
15686 + /* Set TX key index for default/broadcast keys. This is needed in cases
15687 + * where wlan card is doing full WEP/TKIP encapsulation (wep_include_iv
15688 + * is not set), in other cases, this function pointer can be set to
15689 + * NULL since 80211.o takes care of selecting the key index for each
15690 + * TX frame. */
15691 + int (*set_key_idx)(struct net_device *dev, int idx);
15692 +
15693 + /* Enable/disable IEEE 802.1X. This item requests wlan card to pass
15694 + * unencrypted EAPOL-Key frames even when encryption is configured.
15695 + * If the wlan card does not require such a configuration, this
15696 + * function pointer can be set to NULL. 80211.o */
15697 + int (*set_ieee8021x)(struct net_device *dev, int use_ieee8021x);
15698 +
15699 + /* Set port authorization state (IEEE 802.1X PAE) to be authorized
15700 + * (authorized=1) or unauthorized (authorized=0). This function can be
15701 + * used if the wlan hardware or low-level driver implements PAE.
15702 + * 80211.o module will anyway filter frames based on authorization
15703 + * state, so this function pointer can be NULL if low-level driver does
15704 + * not require event notification about port state changes. */
15705 + int (*set_port_auth)(struct net_device *dev, u8 *addr, int authorized);
15706 +
15707 + /* Ask the hardware to do a passive scan on a new channel. The hardware
15708 + * will do what ever is required to nicely leave the current channel
15709 + * including transmit any CTS packets, etc. */
15710 + int (*passive_scan)(struct net_device *dev, int state,
15711 + struct ieee80211_scan_conf *conf);
15712 +
15713 + /* return low-level statistics */
15714 + int (*get_stats)(struct net_device *dev,
15715 + struct ieee80211_low_level_stats *stats);
15716 +
15717 + /* Enable/disable test modes; mode = IEEE80211_TEST_* */
15718 + int (*test_mode)(struct net_device *dev, int mode);
15719 +
15720 + /* Configuration of test parameters */
15721 + int (*test_param)(struct net_device *dev, int param, int value);
15722 +
15723 + /* Change MAC address. addr is pointer to struct sockaddr. */
15724 + int (*set_mac_address)(struct net_device *dev, void *addr);
15725 +
15726 + /* For devices that generate their own beacons and probe response
15727 + * or association responses this updates the state of privacy_invoked
15728 + * returns 0 for success or an error number */
15729 +
15730 + int (*set_privacy_invoked)(struct net_device *dev,
15731 + int privacy_invoked);
15732 +
15733 + /* For devices that have internal sequence counters, allow 802.11
15734 + * code to access the current value of a counter */
15735 + int (*get_sequence_counter)(struct net_device *dev,
15736 + u8* addr, u8 keyidx, u8 txrx,
15737 + u32* iv32, u16* iv16);
15738 +
15739 + /* Configuration of RTS threshold (if device needs it) */
15740 + int (*set_rts_threshold)(struct net_device *dev, u32 value);
15741 +
15742 + /* Configuration of fragmentation threshold (if device needs it) */
15743 + int (*set_frag_threshold)(struct net_device *dev, u32 value);
15744 +
15745 + /* Configuration of retry limits (if device needs it) */
15746 + int (*set_retry_limit)(struct net_device *dev, u32 short_retry,
15747 + u32 long_retr);
15748 +
15749 + /* Number of STAs in STA table notification (NULL = disabled) */
15750 + void (*sta_table_notification)(struct net_device *dev, int num_sta);
15751 +
15752 + /* Configure TX queue parameters (EDCF (aifs, cw_min, cw_max),
15753 + * bursting) for a hardware TX queue.
15754 + * queue = IEEE80211_TX_QUEUE_*. */
15755 + int (*conf_tx)(struct net_device *dev, int queue,
15756 + const struct ieee80211_tx_queue_params *params);
15757 +
15758 + /* Get statistics of the current TX queue status. This is used to get
15759 + * number of currently queued packets (queue length), maximum queue
15760 + * size (limit), and total number of packets sent using each TX queue
15761 + * (count). This information is used for WMM to find out which TX
15762 + * queues have room for more packets and by hostapd to provide
15763 + * statistics about the current queueing state to external programs. */
15764 + int (*get_tx_stats)(struct net_device *dev,
15765 + struct ieee80211_tx_queue_stats *stats);
15766 +
15767 + /* Number of available hardware TX queues for data packets.
15768 + * WMM requires at least four queues. */
15769 + int queues;
15770 +
15771 + /* Get the current TSF timer value from firmware/hardware. Currently,
15772 + * this is only used for IBSS mode debugging and, as such, is not a
15773 + * required function. */
15774 + u64 (*get_tsf)(struct net_device *dev);
15775 +
15776 + /* Reset the TSF timer and allow firmware/hardware to synchronize with
15777 + * other STAs in the IBSS. This is only used in IBSS mode. This
15778 + * function is optional if the firmware/hardware takes full care of
15779 + * TSF synchronization. */
15780 + void (*reset_tsf)(struct net_device *dev);
15781 +
15782 + /* Setup beacon data for IBSS beacons. Unlike access point (Master),
15783 + * IBSS uses a fixed beacon frame which is configured using this
15784 + * function. This handler is required only for IBSS mode. */
15785 + int (*beacon_update)(struct net_device *dev, struct sk_buff *skb,
15786 + struct ieee80211_tx_control *control);
15787 +
15788 + /* Determine whether the last IBSS beacon was sent by us. This is
15789 + * needed only for IBSS mode and the result of this function is used to
15790 + * determine whether to reply to Probe Requests. */
15791 + int (*tx_last_beacon)(struct net_device *dev);
15792 +
15793 + /* Optional handler for XR-in-use notification. */
15794 + int (*atheros_xr_in_use)(struct net_device *dev, int in_use);
15795 +};
15796 +
15797 +/* Allocate a new hardware device. This must be called once for each
15798 + * hardware device. The returned pointer must be used to refer to this
15799 + * device when calling other functions. 802.11 code allocates a private data
15800 + * area for the low-level driver. The size of this area is given as
15801 + * priv_data_len. ieee80211_dev_hw_data() is used to get a pointer to the
15802 + * private data area.
15803 + *
15804 + * Note: in this version of the interface the returned pointer is struct
15805 + * net_device *. This may change in the future and low-level driver should
15806 + * not refer the device data directly to remain compatible with the future
15807 + * versions of the interface. */
15808 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
15809 + void (*setup)(struct net_device *));
15810 +
15811 +/* Register hardware device to the IEEE 802.11 code and kernel. Low-level
15812 + * drivers must call this function before using any other IEEE 802.11
15813 + * function. */
15814 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw);
15815 +
15816 +/* This function is allowed to update hardware configuration (e.g., list of
15817 + * supported operation modes and rates). */
15818 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw);
15819 +
15820 +/* Unregister a hardware device. This function instructs 802.11 code to free
15821 + * allocated resources and unregister netdevices from the kernel. */
15822 +void ieee80211_unregister_hw(struct net_device *dev);
15823 +
15824 +/* Free allocated net_device including private data of a driver. */
15825 +void ieee80211_free_hw(struct net_device *dev);
15826 +
15827 +/* Receive frame callback function. The low-level driver uses this function to
15828 + * send received frames to the IEEE 802.11 code. Receive buffer (skb) must
15829 + * start with IEEE 802.11 header. */
15830 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
15831 + struct ieee80211_rx_status *status);
15832 +void ieee80211_rx_irqsafe(struct net_device *dev, struct sk_buff *skb,
15833 + struct ieee80211_rx_status *status);
15834 +
15835 +/* Transmit status callback function. The low-level driver must call this
15836 + * function to report transmit status for all the TX frames that had
15837 + * req_tx_status set in the transmit control fields. In addition, this should
15838 + * be called at least for all unicast frames to provide information for TX rate
15839 + * control algorithm. In order to maintain all statistics, this function is
15840 + * recommended to be called after each frame, including multicast/broadcast, is
15841 + * sent. */
15842 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
15843 + struct ieee80211_tx_status *status);
15844 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
15845 + struct ieee80211_tx_status *status);
15846 +
15847 +/* Beacon generation function. If the beacon frames are generated by the host
15848 + * system (i.e., not in hardware/firmware), the low-level driver uses this
15849 + * function to receive the next beacon frame from the 802.11 code. The
15850 + * low-level is responsible for calling this function before beacon data is
15851 + * needed (e.g., based on hardware interrupt). Returned skb is used only once
15852 + * and low-level driver is responsible of freeing it. */
15853 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
15854 + struct ieee80211_tx_control *control);
15855 +
15856 +/* Function for accessing buffered broadcast and multicast frames. If
15857 + * hardware/firmware does not implement buffering of broadcast/multicast
15858 + * frames when power saving is used, 802.11 code buffers them in the host
15859 + * memory. The low-level driver uses this function to fetch next buffered
15860 + * frame. In most cases, this is used when generating beacon frame. This
15861 + * function returns a pointer to the next buffered skb or NULL if no more
15862 + * buffered frames are available.
15863 + *
15864 + * Note: buffered frames are returned only after DTIM beacon frame was
15865 + * generated with ieee80211_beacon_get() and the low-level driver must thus
15866 + * call ieee80211_beacon_get() first. ieee80211_get_buffered_bc() returns
15867 + * NULL if the previous generated beacon was not DTIM, so the low-level driver
15868 + * does not need to check for DTIM beacons separately and should be able to
15869 + * use common code for all beacons. */
15870 +struct sk_buff *
15871 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
15872 + struct ieee80211_tx_control *control);
15873 +
15874 +/* Low level drivers that have their own MLME and MAC indicate
15875 + * the aid for an associating station with this call */
15876 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
15877 + u16 aid);
15878 +
15879 +
15880 +/* Given an sk_buff with a raw 802.11 header at the data pointer this function
15881 + * returns the 802.11 header length in bytes (not including encryption
15882 + * headers). If the data in the sk_buff is too short to contain a valid 802.11
15883 + * header the function returns 0.
15884 + */
15885 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb);
15886 +
15887 +/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */
15888 +int ieee80211_get_hdrlen(u16 fc);
15889 +
15890 +/* Function for net interface operation. IEEE 802.11 may use multiple kernel
15891 + * netdevices for each hardware device. The low-level driver does not "see"
15892 + * these interfaces, so it should use this function to perform netif
15893 + * operations on all interface. */
15894 +typedef enum {
15895 + NETIF_ATTACH, NETIF_DETACH, NETIF_START, NETIF_STOP, NETIF_WAKE,
15896 + NETIF_IS_STOPPED, NETIF_UPDATE_TX_START
15897 +} Netif_Oper;
15898 +int ieee80211_netif_oper(struct net_device *dev, Netif_Oper op);
15899 +
15900 +
15901 +/*
15902 + * Function to get hardware configuration information
15903 + * by the low level driver should it need it.
15904 + */
15905 +struct ieee80211_conf *
15906 +ieee80211_get_hw_conf(struct net_device *dev);
15907 +
15908 +
15909 +/* Return a pointer to the low-level private data area for the given device. */
15910 +void * ieee80211_dev_hw_data(struct net_device *dev);
15911 +/* Return a pointer to network statistics data area for the given device. */
15912 +void * ieee80211_dev_stats(struct net_device *dev);
15913 +
15914 +/* Function to indicate Radar Detection. The low level driver must call this
15915 + * function to indicate the presence of radar in the current channel.
15916 + * Additionally the radar type also could be sent */
15917 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
15918 + int radar_type);
15919 +
15920 +/* Test modes */
15921 +enum {
15922 + IEEE80211_TEST_DISABLE = 0 /* terminate testing */,
15923 + IEEE80211_TEST_UNMASK_CHANNELS = 1 /* allow all channels to be used */,
15924 + IEEE80211_TEST_CONTINUOUS_TX = 2,
15925 +};
15926 +
15927 +/* Test parameters */
15928 +enum {
15929 + /* TX power in hardware specific raw value */
15930 + IEEE80211_TEST_PARAM_TX_POWER_RAW = 0,
15931 + /* TX rate in hardware specific raw value */
15932 + IEEE80211_TEST_PARAM_TX_RATE_RAW = 1,
15933 + /* Continuous TX pattern (32-bit) */
15934 + IEEE80211_TEST_PARAM_TX_PATTERN = 2,
15935 + /* TX power in 0.1 dBm, 100 = 10 dBm */
15936 + IEEE80211_TEST_PARAM_TX_POWER = 3,
15937 + /* TX rate in 100 kbps, 540 = 54 Mbps */
15938 + IEEE80211_TEST_PARAM_TX_RATE = 4,
15939 + IEEE80211_TEST_PARAM_TX_ANT_SEL_RAW = 5,
15940 +};
15941 +
15942 +/* ieee80211_tx_led called with state == 1 when the first frame is queued
15943 + * with state == 0 when the last frame is transmitted and tx queue is empty
15944 + */
15945 +void ieee80211_tx_led(int state, struct net_device *dev);
15946 +/* ieee80211_rx_led is called each time frame is received, state is not used
15947 + * (== 2)
15948 + */
15949 +void ieee80211_rx_led(int state, struct net_device *dev);
15950 +
15951 +
15952 +/* IEEE 802.11 defines */
15953 +
15954 +#define FCS_LEN 4
15955 +
15956 +#define WLAN_FC_PVER 0x0003
15957 +#define WLAN_FC_TODS 0x0100
15958 +#define WLAN_FC_FROMDS 0x0200
15959 +#define WLAN_FC_MOREFRAG 0x0400
15960 +#define WLAN_FC_RETRY 0x0800
15961 +#define WLAN_FC_PWRMGT 0x1000
15962 +#define WLAN_FC_MOREDATA 0x2000
15963 +#define WLAN_FC_ISWEP 0x4000
15964 +#define WLAN_FC_ORDER 0x8000
15965 +
15966 +#define WLAN_FC_GET_TYPE(fc) (((fc) & 0x000c) >> 2)
15967 +#define WLAN_FC_GET_STYPE(fc) (((fc) & 0x00f0) >> 4)
15968 +
15969 +#define WLAN_GET_SEQ_FRAG(seq) ((seq) & 0x000f)
15970 +#define WLAN_GET_SEQ_SEQ(seq) ((seq) >> 4)
15971 +
15972 +#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
15973 +
15974 +#define WLAN_FC_TYPE_MGMT 0
15975 +#define WLAN_FC_TYPE_CTRL 1
15976 +#define WLAN_FC_TYPE_DATA 2
15977 +
15978 +/* management */
15979 +#define WLAN_FC_STYPE_ASSOC_REQ 0
15980 +#define WLAN_FC_STYPE_ASSOC_RESP 1
15981 +#define WLAN_FC_STYPE_REASSOC_REQ 2
15982 +#define WLAN_FC_STYPE_REASSOC_RESP 3
15983 +#define WLAN_FC_STYPE_PROBE_REQ 4
15984 +#define WLAN_FC_STYPE_PROBE_RESP 5
15985 +#define WLAN_FC_STYPE_BEACON 8
15986 +#define WLAN_FC_STYPE_ATIM 9
15987 +#define WLAN_FC_STYPE_DISASSOC 10
15988 +#define WLAN_FC_STYPE_AUTH 11
15989 +#define WLAN_FC_STYPE_DEAUTH 12
15990 +#define WLAN_FC_STYPE_ACTION 13
15991 +
15992 +/* control */
15993 +#define WLAN_FC_STYPE_PSPOLL 10
15994 +#define WLAN_FC_STYPE_RTS 11
15995 +#define WLAN_FC_STYPE_CTS 12
15996 +#define WLAN_FC_STYPE_ACK 13
15997 +#define WLAN_FC_STYPE_CFEND 14
15998 +#define WLAN_FC_STYPE_CFENDACK 15
15999 +
16000 +/* data */
16001 +#define WLAN_FC_STYPE_DATA 0
16002 +#define WLAN_FC_STYPE_DATA_CFACK 1
16003 +#define WLAN_FC_STYPE_DATA_CFPOLL 2
16004 +#define WLAN_FC_STYPE_DATA_CFACKPOLL 3
16005 +#define WLAN_FC_STYPE_NULLFUNC 4
16006 +#define WLAN_FC_STYPE_CFACK 5
16007 +#define WLAN_FC_STYPE_CFPOLL 6
16008 +#define WLAN_FC_STYPE_CFACKPOLL 7
16009 +#define WLAN_FC_STYPE_QOS_DATA 8
16010 +#define WLAN_FC_STYPE_QOS_DATA_CFACK 9
16011 +#define WLAN_FC_STYPE_QOS_DATA_CFPOLL 10
16012 +#define WLAN_FC_STYPE_QOS_DATA_CFACKPOLL 11
16013 +#define WLAN_FC_STYPE_QOS_NULLFUNC 12
16014 +#define WLAN_FC_STYPE_QOS_CFACK 13
16015 +#define WLAN_FC_STYPE_QOS_CFPOLL 14
16016 +#define WLAN_FC_STYPE_QOS_CFACKPOLL 15
16017 +
16018 +
16019 +#define IEEE80211_MAX_FRAG_THRESHOLD 2346
16020 +#define IEEE80211_MAX_RTS_THRESHOLD 2347
16021 +
16022 +struct ieee80211_hdr {
16023 + u16 frame_control;
16024 + u16 duration_id;
16025 + u8 addr1[6];
16026 + u8 addr2[6];
16027 + u8 addr3[6];
16028 + u16 seq_ctrl;
16029 + u8 addr4[6];
16030 +} __attribute__ ((packed));
16031 +
16032 +/* return a pointer to the source address (SA) */
16033 +static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
16034 +{
16035 + u8 *raw = (u8 *) hdr;
16036 + u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
16037 +
16038 + switch (tofrom) {
16039 + case 2:
16040 + return hdr->addr3;
16041 + case 3:
16042 + return hdr->addr4;
16043 + }
16044 + return hdr->addr2;
16045 +}
16046 +
16047 +/* return a pointer to the destination address (DA) */
16048 +static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
16049 +{
16050 + u8 *raw = (u8 *) hdr;
16051 + u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
16052 +
16053 + if (to_ds)
16054 + return hdr->addr3;
16055 + return hdr->addr1;
16056 +}
16057 +
16058 +static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
16059 +{
16060 + return (le16_to_cpu(hdr->frame_control) & WLAN_FC_MOREFRAG) != 0;
16061 +}
16062 +
16063 +#endif /* D80211_H */
16064 diff -Nur linux-2.6.16/include/net/d80211_mgmt.h linux-2.6.16-bcm43xx/include/net/d80211_mgmt.h
16065 --- linux-2.6.16/include/net/d80211_mgmt.h 1970-01-01 01:00:00.000000000 +0100
16066 +++ linux-2.6.16-bcm43xx/include/net/d80211_mgmt.h 2006-03-28 22:16:14.000000000 +0200
16067 @@ -0,0 +1,197 @@
16068 +/*
16069 + * IEEE 802.11 -- shared defines for 80211.o and hostapd
16070 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
16071 + * Copyright 2002-2004, Instant802 Networks, Inc.
16072 + * Copyright 2005, Devicescape Software, Inc.
16073 + *
16074 + * This program is free software; you can redistribute it and/or modify
16075 + * it under the terms of the GNU General Public License version 2 as
16076 + * published by the Free Software Foundation.
16077 + */
16078 +
16079 +#ifndef D802_11_MGMT_H
16080 +#define D802_11_MGMT_H
16081 +
16082 +#include <linux/types.h>
16083 +
16084 +struct ieee80211_mgmt {
16085 + u16 frame_control;
16086 + u16 duration;
16087 + u8 da[6];
16088 + u8 sa[6];
16089 + u8 bssid[6];
16090 + u16 seq_ctrl;
16091 + union {
16092 + struct {
16093 + u16 auth_alg;
16094 + u16 auth_transaction;
16095 + u16 status_code;
16096 + /* possibly followed by Challenge text */
16097 + u8 variable[0];
16098 + } __attribute__ ((packed)) auth;
16099 + struct {
16100 + u16 reason_code;
16101 + } __attribute__ ((packed)) deauth;
16102 + struct {
16103 + u16 capab_info;
16104 + u16 listen_interval;
16105 + /* followed by SSID and Supported rates */
16106 + u8 variable[0];
16107 + } __attribute__ ((packed)) assoc_req;
16108 + struct {
16109 + u16 capab_info;
16110 + u16 status_code;
16111 + u16 aid;
16112 + /* followed by Supported rates */
16113 + u8 variable[0];
16114 + } __attribute__ ((packed)) assoc_resp, reassoc_resp;
16115 + struct {
16116 + u16 capab_info;
16117 + u16 listen_interval;
16118 + u8 current_ap[6];
16119 + /* followed by SSID and Supported rates */
16120 + u8 variable[0];
16121 + } __attribute__ ((packed)) reassoc_req;
16122 + struct {
16123 + u16 reason_code;
16124 + } __attribute__ ((packed)) disassoc;
16125 + struct {
16126 + u8 timestamp[8];
16127 + u16 beacon_int;
16128 + u16 capab_info;
16129 + /* followed by some of SSID, Supported rates,
16130 + * FH Params, DS Params, CF Params, IBSS Params, TIM */
16131 + u8 variable[0];
16132 + } __attribute__ ((packed)) beacon;
16133 + struct {
16134 + /* only variable items: SSID, Supported rates */
16135 + u8 variable[0];
16136 + } __attribute__ ((packed)) probe_req;
16137 + struct {
16138 + u8 timestamp[8];
16139 + u16 beacon_int;
16140 + u16 capab_info;
16141 + /* followed by some of SSID, Supported rates,
16142 + * FH Params, DS Params, CF Params, IBSS Params */
16143 + u8 variable[0];
16144 + } __attribute__ ((packed)) probe_resp;
16145 + struct {
16146 + u8 category;
16147 + union {
16148 + struct {
16149 + u8 action_code;
16150 + u8 dialog_token;
16151 + u8 status_code;
16152 + u8 variable[0];
16153 + } __attribute__ ((packed)) wme_action;
16154 + struct{
16155 + u8 action_code;
16156 + u8 element_id;
16157 + u8 length;
16158 + u8 switch_mode;
16159 + u8 new_chan;
16160 + u8 switch_count;
16161 + } __attribute__((packed)) chan_switch;
16162 + } u;
16163 + } __attribute__ ((packed)) action;
16164 + } u;
16165 +} __attribute__ ((packed));
16166 +
16167 +
16168 +/* Authentication algorithms */
16169 +#define WLAN_AUTH_OPEN 0
16170 +#define WLAN_AUTH_SHARED_KEY 1
16171 +#define WLAN_AUTH_LEAP 128
16172 +
16173 +#define WLAN_AUTH_CHALLENGE_LEN 128
16174 +
16175 +#define WLAN_CAPABILITY_ESS BIT(0)
16176 +#define WLAN_CAPABILITY_IBSS BIT(1)
16177 +#define WLAN_CAPABILITY_CF_POLLABLE BIT(2)
16178 +#define WLAN_CAPABILITY_CF_POLL_REQUEST BIT(3)
16179 +#define WLAN_CAPABILITY_PRIVACY BIT(4)
16180 +#define WLAN_CAPABILITY_SHORT_PREAMBLE BIT(5)
16181 +#define WLAN_CAPABILITY_PBCC BIT(6)
16182 +#define WLAN_CAPABILITY_CHANNEL_AGILITY BIT(7)
16183 +/* 802.11h */
16184 +#define WLAN_CAPABILITY_SPECTRUM_MGMT BIT(8)
16185 +#define WLAN_CAPABILITY_SHORT_SLOT_TIME BIT(10)
16186 +#define WLAN_CAPABILITY_DSSS_OFDM BIT(13)
16187 +
16188 +/* Status codes */
16189 +#define WLAN_STATUS_SUCCESS 0
16190 +#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
16191 +#define WLAN_STATUS_CAPS_UNSUPPORTED 10
16192 +#define WLAN_STATUS_REASSOC_NO_ASSOC 11
16193 +#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
16194 +#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
16195 +#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
16196 +#define WLAN_STATUS_CHALLENGE_FAIL 15
16197 +#define WLAN_STATUS_AUTH_TIMEOUT 16
16198 +#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
16199 +#define WLAN_STATUS_ASSOC_DENIED_RATES 18
16200 +/* 802.11b */
16201 +#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
16202 +#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
16203 +#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
16204 +/* 802.11h */
16205 +#define WLAN_STATUS_SPEC_MGMT_REQUIRED 22
16206 +#define WLAN_STATUS_PWR_CAPABILITY_NOT_VALID 23
16207 +#define WLAN_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
16208 +/* 802.11g */
16209 +#define WLAN_STATUS_ASSOC_DENOED_NO_SHORT_SLOT_TIME 25
16210 +#define WLAN_STATUS_ASSOC_DENOED_NO_ER_PBCC 26
16211 +#define WLAN_STATUS_ASSOC_DENOED_NO_DSSS_OFDM 27
16212 +
16213 +
16214 +/* Reason codes */
16215 +#define WLAN_REASON_UNSPECIFIED 1
16216 +#define WLAN_REASON_PREV_AUTH_NOT_VALID 2
16217 +#define WLAN_REASON_DEAUTH_LEAVING 3
16218 +#define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
16219 +#define WLAN_REASON_DISASSOC_AP_BUSY 5
16220 +#define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
16221 +#define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
16222 +#define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
16223 +#define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
16224 +/* 802.11h */
16225 +#define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10
16226 +#define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
16227 +
16228 +#define WLAN_REASON_MIC_FAILURE 14
16229 +
16230 +
16231 +/* Information Element IDs */
16232 +#define WLAN_EID_SSID 0
16233 +#define WLAN_EID_SUPP_RATES 1
16234 +#define WLAN_EID_FH_PARAMS 2
16235 +#define WLAN_EID_DS_PARAMS 3
16236 +#define WLAN_EID_CF_PARAMS 4
16237 +#define WLAN_EID_TIM 5
16238 +#define WLAN_EID_IBSS_PARAMS 6
16239 +#define WLAN_EID_COUNTRY 7
16240 +#define WLAN_EID_CHALLENGE 16
16241 +/* EIDs defined as part fo 11h - starts */
16242 +#define WLAN_EID_PWR_CONSTRAINT 32
16243 +#define WLAN_EID_PWR_CAPABILITY 33
16244 +#define WLAN_EID_TPC_REQUEST 34
16245 +#define WLAN_EID_TPC_REPORT 35
16246 +#define WLAN_EID_SUPPORTED_CHANNELS 36
16247 +#define WLAN_EID_CHANNEL_SWITCH 37
16248 +#define WLAN_EID_MEASURE_REQUEST 38
16249 +#define WLAN_EID_MEASURE_REPORT 39
16250 +#define WLAN_EID_QUITE 40
16251 +#define WLAN_EID_IBSS_DFS 41
16252 +/* EIDs defined as part fo 11h - ends */
16253 +#define WLAN_EID_ERP_INFO 42
16254 +#define WLAN_EID_RSN 48
16255 +#define WLAN_EID_EXT_SUPP_RATES 50
16256 +#define WLAN_EID_WPA 221
16257 +#define WLAN_EID_GENERIC 221
16258 +#define WLAN_EID_VENDOR_SPECIFIC 221
16259 +
16260 +
16261 +
16262 +#define ATHEROS_INFO_USEXR BIT(3)
16263 +
16264 +#endif /* D802_11_MGMT_H */
16265 diff -Nur linux-2.6.16/include/net/d80211_shared.h linux-2.6.16-bcm43xx/include/net/d80211_shared.h
16266 --- linux-2.6.16/include/net/d80211_shared.h 1970-01-01 01:00:00.000000000 +0100
16267 +++ linux-2.6.16-bcm43xx/include/net/d80211_shared.h 2006-03-28 22:16:14.000000000 +0200
16268 @@ -0,0 +1,50 @@
16269 +/*
16270 + * IEEE 802.11 -- shared defines for low-level drivers, 80211.o, and hostapd
16271 + * Copyright 2002-2004, Instant802 Networks, Inc.
16272 + * Copyright 2005, Devicescape Software, Inc.
16273 + *
16274 + * This program is free software; you can redistribute it and/or modify
16275 + * it under the terms of the GNU General Public License version 2 as
16276 + * published by the Free Software Foundation.
16277 + */
16278 +
16279 +#ifndef D80211_SHARED_H
16280 +#define D80211_SHARED_H
16281 +
16282 +/* 802.11g is backwards-compatible with 802.11b, so a wlan card can
16283 + * actually be both in 11b and 11g modes at the same time. */
16284 +enum {
16285 + MODE_IEEE80211A = 0 /* IEEE 802.11a */,
16286 + MODE_IEEE80211B = 1 /* IEEE 802.11b only */,
16287 + MODE_ATHEROS_TURBO = 2 /* Atheros Turbo mode (2x.11a at 5 GHz) */,
16288 + MODE_IEEE80211G = 3 /* IEEE 802.11g (and 802.11b compatibility) */,
16289 + MODE_ATHEROS_TURBOG = 4 /* Atheros Turbo mode (2x.11g at 2.4 GHz) */,
16290 + MODE_ATHEROS_PRIME = 5 /* Atheros Dynamic Turbo mode */,
16291 + MODE_ATHEROS_PRIMEG = 6 /* Atheros Dynamic Turbo mode G */,
16292 + MODE_ATHEROS_XR = 7 /* Atheros XR mode */,
16293 + NUM_IEEE80211_MODES = 8
16294 +};
16295 +
16296 +#define IEEE80211_CHAN_W_SCAN 0x00000001
16297 +#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
16298 +#define IEEE80211_CHAN_W_IBSS 0x00000004
16299 +
16300 +/* Low-level driver should set PREAMBLE2, OFDM, CCK, and TURBO flags.
16301 + * BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the
16302 + * configuration. */
16303 +#define IEEE80211_RATE_ERP 0x00000001
16304 +#define IEEE80211_RATE_BASIC 0x00000002
16305 +#define IEEE80211_RATE_PREAMBLE2 0x00000004
16306 +#define IEEE80211_RATE_SUPPORTED 0x00000010
16307 +#define IEEE80211_RATE_OFDM 0x00000020
16308 +#define IEEE80211_RATE_CCK 0x00000040
16309 +#define IEEE80211_RATE_TURBO 0x00000080
16310 +#define IEEE80211_RATE_MANDATORY 0x00000100
16311 +#define IEEE80211_RATE_XR 0x00000200
16312 +
16313 +#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2)
16314 +#define IEEE80211_RATE_MODULATION(f) \
16315 +(f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM))
16316 +
16317 +
16318 +#endif /* D80211_SHARED_H */
16319 diff -Nur linux-2.6.16/include/net/ieee80211_crypt.h linux-2.6.16-bcm43xx/include/net/ieee80211_crypt.h
16320 --- linux-2.6.16/include/net/ieee80211_crypt.h 2006-03-20 06:53:29.000000000 +0100
16321 +++ linux-2.6.16-bcm43xx/include/net/ieee80211_crypt.h 2006-03-28 22:16:14.000000000 +0200
16322 @@ -47,7 +47,8 @@
16323 /* deinitialize crypto context and free allocated private data */
16324 void (*deinit) (void *priv);
16325
16326 - int (*build_iv) (struct sk_buff * skb, int hdr_len, void *priv);
16327 + int (*build_iv) (struct sk_buff * skb, int hdr_len,
16328 + u8 *key, int keylen, void *priv);
16329
16330 /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
16331 * value from decrypt_mpdu is passed as the keyidx value for
16332 diff -Nur linux-2.6.16/include/net/ieee80211.h linux-2.6.16-bcm43xx/include/net/ieee80211.h
16333 --- linux-2.6.16/include/net/ieee80211.h 2006-03-20 06:53:29.000000000 +0100
16334 +++ linux-2.6.16-bcm43xx/include/net/ieee80211.h 2006-03-28 22:16:14.000000000 +0200
16335 @@ -220,6 +220,7 @@
16336 /* Authentication algorithms */
16337 #define WLAN_AUTH_OPEN 0
16338 #define WLAN_AUTH_SHARED_KEY 1
16339 +#define WLAN_AUTH_LEAP 2
16340
16341 #define WLAN_AUTH_CHALLENGE_LEN 128
16342
16343 @@ -299,6 +300,23 @@
16344 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
16345 };
16346
16347 +/* Action categories - 802.11h */
16348 +enum ieee80211_actioncategories {
16349 + WLAN_ACTION_SPECTRUM_MGMT = 0,
16350 + /* Reserved 1-127 */
16351 + /* Error 128-255 */
16352 +};
16353 +
16354 +/* Action details - 802.11h */
16355 +enum ieee80211_actiondetails {
16356 + WLAN_ACTION_CATEGORY_MEASURE_REQUEST = 0,
16357 + WLAN_ACTION_CATEGORY_MEASURE_REPORT = 1,
16358 + WLAN_ACTION_CATEGORY_TPC_REQUEST = 2,
16359 + WLAN_ACTION_CATEGORY_TPC_REPORT = 3,
16360 + WLAN_ACTION_CATEGORY_CHANNEL_SWITCH = 4,
16361 + /* 5 - 255 Reserved */
16362 +};
16363 +
16364 #define IEEE80211_STATMASK_SIGNAL (1<<0)
16365 #define IEEE80211_STATMASK_RSSI (1<<1)
16366 #define IEEE80211_STATMASK_NOISE (1<<2)
16367 @@ -377,6 +395,8 @@
16368 u8 mask;
16369 u8 freq;
16370 u16 len;
16371 + u64 tsf;
16372 + u32 beacon_time;
16373 };
16374
16375 /* IEEE 802.11 requires that STA supports concurrent reception of at least
16376 @@ -608,6 +628,28 @@
16377 struct ieee80211_info_element info_element[0];
16378 } __attribute__ ((packed));
16379
16380 +struct ieee80211_channel_switch {
16381 + u8 id;
16382 + u8 len;
16383 + u8 mode;
16384 + u8 channel;
16385 + u8 count;
16386 +} __attribute__ ((packed));
16387 +
16388 +struct ieee80211_action {
16389 + struct ieee80211_hdr_3addr header;
16390 + u8 category;
16391 + u8 action;
16392 + union {
16393 + struct ieee80211_action_exchange {
16394 + u8 token;
16395 + struct ieee80211_info_element info_element[0];
16396 + } exchange;
16397 + struct ieee80211_channel_switch channel_switch;
16398 +
16399 + } format;
16400 +} __attribute__ ((packed));
16401 +
16402 struct ieee80211_disassoc {
16403 struct ieee80211_hdr_3addr header;
16404 __le16 reason;
16405 @@ -692,7 +734,15 @@
16406 /* QoS structure */
16407 #define NETWORK_HAS_QOS_PARAMETERS (1<<3)
16408 #define NETWORK_HAS_QOS_INFORMATION (1<<4)
16409 -#define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | NETWORK_HAS_QOS_INFORMATION)
16410 +#define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \
16411 + NETWORK_HAS_QOS_INFORMATION)
16412 +
16413 +/* 802.11h */
16414 +#define NETWORK_HAS_POWER_CONSTRAINT (1<<5)
16415 +#define NETWORK_HAS_CSA (1<<6)
16416 +#define NETWORK_HAS_QUIET (1<<7)
16417 +#define NETWORK_HAS_IBSS_DFS (1<<8)
16418 +#define NETWORK_HAS_TPC_REPORT (1<<9)
16419
16420 #define QOS_QUEUE_NUM 4
16421 #define QOS_OUI_LEN 3
16422 @@ -748,6 +798,91 @@
16423
16424 /*******************************************************/
16425
16426 +enum { /* ieee80211_basic_report.map */
16427 + IEEE80211_BASIC_MAP_BSS = (1 << 0),
16428 + IEEE80211_BASIC_MAP_OFDM = (1 << 1),
16429 + IEEE80211_BASIC_MAP_UNIDENTIFIED = (1 << 2),
16430 + IEEE80211_BASIC_MAP_RADAR = (1 << 3),
16431 + IEEE80211_BASIC_MAP_UNMEASURED = (1 << 4),
16432 + /* Bits 5-7 are reserved */
16433 +
16434 +};
16435 +struct ieee80211_basic_report {
16436 + u8 channel;
16437 + __le64 start_time;
16438 + __le16 duration;
16439 + u8 map;
16440 +} __attribute__ ((packed));
16441 +
16442 +enum { /* ieee80211_measurement_request.mode */
16443 + /* Bit 0 is reserved */
16444 + IEEE80211_MEASUREMENT_ENABLE = (1 << 1),
16445 + IEEE80211_MEASUREMENT_REQUEST = (1 << 2),
16446 + IEEE80211_MEASUREMENT_REPORT = (1 << 3),
16447 + /* Bits 4-7 are reserved */
16448 +};
16449 +
16450 +enum {
16451 + IEEE80211_REPORT_BASIC = 0, /* required */
16452 + IEEE80211_REPORT_CCA = 1, /* optional */
16453 + IEEE80211_REPORT_RPI = 2, /* optional */
16454 + /* 3-255 reserved */
16455 +};
16456 +
16457 +struct ieee80211_measurement_params {
16458 + u8 channel;
16459 + __le64 start_time;
16460 + __le16 duration;
16461 +} __attribute__ ((packed));
16462 +
16463 +struct ieee80211_measurement_request {
16464 + struct ieee80211_info_element ie;
16465 + u8 token;
16466 + u8 mode;
16467 + u8 type;
16468 + struct ieee80211_measurement_params params[0];
16469 +} __attribute__ ((packed));
16470 +
16471 +struct ieee80211_measurement_report {
16472 + struct ieee80211_info_element ie;
16473 + u8 token;
16474 + u8 mode;
16475 + u8 type;
16476 + union {
16477 + struct ieee80211_basic_report basic[0];
16478 + } u;
16479 +} __attribute__ ((packed));
16480 +
16481 +struct ieee80211_tpc_report {
16482 + u8 transmit_power;
16483 + u8 link_margin;
16484 +} __attribute__ ((packed));
16485 +
16486 +struct ieee80211_channel_map {
16487 + u8 channel;
16488 + u8 map;
16489 +} __attribute__ ((packed));
16490 +
16491 +struct ieee80211_ibss_dfs {
16492 + struct ieee80211_info_element ie;
16493 + u8 owner[ETH_ALEN];
16494 + u8 recovery_interval;
16495 + struct ieee80211_channel_map channel_map[0];
16496 +};
16497 +
16498 +struct ieee80211_csa {
16499 + u8 mode;
16500 + u8 channel;
16501 + u8 count;
16502 +} __attribute__ ((packed));
16503 +
16504 +struct ieee80211_quiet {
16505 + u8 count;
16506 + u8 period;
16507 + u8 duration;
16508 + u8 offset;
16509 +} __attribute__ ((packed));
16510 +
16511 struct ieee80211_network {
16512 /* These entries are used to identify a unique network */
16513 u8 bssid[ETH_ALEN];
16514 @@ -767,7 +902,7 @@
16515 u8 rates_ex_len;
16516 unsigned long last_scanned;
16517 u8 mode;
16518 - u8 flags;
16519 + u32 flags;
16520 u32 last_associate;
16521 u32 time_stamp[2];
16522 u16 beacon_interval;
16523 @@ -779,6 +914,25 @@
16524 u8 rsn_ie[MAX_WPA_IE_LEN];
16525 size_t rsn_ie_len;
16526 struct ieee80211_tim_parameters tim;
16527 +
16528 + /* 802.11h info */
16529 +
16530 + /* Power Constraint - mandatory if spctrm mgmt required */
16531 + u8 power_constraint;
16532 +
16533 + /* TPC Report - mandatory if spctrm mgmt required */
16534 + struct ieee80211_tpc_report tpc_report;
16535 +
16536 + /* IBSS DFS - mandatory if spctrm mgmt required and IBSS
16537 + * NOTE: This is variable length and so must be allocated dynamically */
16538 + struct ieee80211_ibss_dfs *ibss_dfs;
16539 +
16540 + /* Channel Switch Announcement - optional if spctrm mgmt required */
16541 + struct ieee80211_csa csa;
16542 +
16543 + /* Quiet - optional if spctrm mgmt required */
16544 + struct ieee80211_quiet quiet;
16545 +
16546 struct list_head list;
16547 };
16548
16549 @@ -924,7 +1078,10 @@
16550 int (*handle_auth) (struct net_device * dev,
16551 struct ieee80211_auth * auth);
16552 int (*handle_deauth) (struct net_device * dev,
16553 - struct ieee80211_auth * auth);
16554 + struct ieee80211_deauth * auth);
16555 + int (*handle_action) (struct net_device * dev,
16556 + struct ieee80211_action * action,
16557 + struct ieee80211_rx_stats * stats);
16558 int (*handle_disassoc) (struct net_device * dev,
16559 struct ieee80211_disassoc * assoc);
16560 int (*handle_beacon) (struct net_device * dev,
16561 @@ -1093,6 +1250,7 @@
16562 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
16563 struct ieee80211_hdr_4addr *header,
16564 struct ieee80211_rx_stats *stats);
16565 +extern void ieee80211_network_reset(struct ieee80211_network *network);
16566
16567 /* ieee80211_geo.c */
16568 extern const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device
16569 @@ -1105,6 +1263,11 @@
16570 extern int ieee80211_channel_to_index(struct ieee80211_device *ieee,
16571 u8 channel);
16572 extern u8 ieee80211_freq_to_channel(struct ieee80211_device *ieee, u32 freq);
16573 +extern u8 ieee80211_get_channel_flags(struct ieee80211_device *ieee,
16574 + u8 channel);
16575 +extern const struct ieee80211_channel *ieee80211_get_channel(struct
16576 + ieee80211_device
16577 + *ieee, u8 channel);
16578
16579 /* ieee80211_wx.c */
16580 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
16581 @@ -1122,6 +1285,14 @@
16582 extern int ieee80211_wx_get_encodeext(struct ieee80211_device *ieee,
16583 struct iw_request_info *info,
16584 union iwreq_data *wrqu, char *extra);
16585 +extern int ieee80211_wx_set_auth(struct net_device *dev,
16586 + struct iw_request_info *info,
16587 + union iwreq_data *wrqu,
16588 + char *extra);
16589 +extern int ieee80211_wx_get_auth(struct net_device *dev,
16590 + struct iw_request_info *info,
16591 + union iwreq_data *wrqu,
16592 + char *extra);
16593
16594 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
16595 {
16596 diff -Nur linux-2.6.16/include/net/sock.h linux-2.6.16-bcm43xx/include/net/sock.h
16597 --- linux-2.6.16/include/net/sock.h 2006-03-20 06:53:29.000000000 +0100
16598 +++ linux-2.6.16-bcm43xx/include/net/sock.h 2006-03-28 22:16:14.000000000 +0200
16599 @@ -478,9 +478,9 @@
16600 rc = __condition; \
16601 if (!rc) { \
16602 *(__timeo) = schedule_timeout(*(__timeo)); \
16603 + rc = __condition; \
16604 } \
16605 lock_sock(__sk); \
16606 - rc = __condition; \
16607 rc; \
16608 })
16609
16610 diff -Nur linux-2.6.16/net/core/dev.c linux-2.6.16-bcm43xx/net/core/dev.c
16611 --- linux-2.6.16/net/core/dev.c 2006-03-20 06:53:29.000000000 +0100
16612 +++ linux-2.6.16-bcm43xx/net/core/dev.c 2006-03-28 22:16:14.000000000 +0200
16613 @@ -110,10 +110,8 @@
16614 #include <linux/netpoll.h>
16615 #include <linux/rcupdate.h>
16616 #include <linux/delay.h>
16617 -#ifdef CONFIG_NET_RADIO
16618 -#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
16619 +#include <linux/wireless.h>
16620 #include <net/iw_handler.h>
16621 -#endif /* CONFIG_NET_RADIO */
16622 #include <asm/current.h>
16623
16624 /*
16625 @@ -1448,8 +1446,29 @@
16626 {
16627 struct net_device *dev = skb->dev;
16628
16629 - if (dev->master)
16630 + if (dev->master) {
16631 + /*
16632 + * On bonding slaves other than the currently active
16633 + * slave, suppress duplicates except for 802.3ad
16634 + * ETH_P_SLOW and alb non-mcast/bcast.
16635 + */
16636 + if (dev->priv_flags & IFF_SLAVE_INACTIVE) {
16637 + if (dev->master->priv_flags & IFF_MASTER_ALB) {
16638 + if (skb->pkt_type != PACKET_BROADCAST &&
16639 + skb->pkt_type != PACKET_MULTICAST)
16640 + goto keep;
16641 + }
16642 +
16643 + if (dev->master->priv_flags & IFF_MASTER_8023AD &&
16644 + skb->protocol == __constant_htons(ETH_P_SLOW))
16645 + goto keep;
16646 +
16647 + kfree_skb(skb);
16648 + return NULL;
16649 + }
16650 +keep:
16651 skb->dev = dev->master;
16652 + }
16653
16654 return dev;
16655 }
16656 @@ -1593,6 +1612,9 @@
16657
16658 orig_dev = skb_bond(skb);
16659
16660 + if (!orig_dev)
16661 + return NET_RX_DROP;
16662 +
16663 __get_cpu_var(netdev_rx_stat).total++;
16664
16665 skb->h.raw = skb->nh.raw = skb->data;
16666 @@ -2028,7 +2050,7 @@
16667 .release = seq_release,
16668 };
16669
16670 -#ifdef WIRELESS_EXT
16671 +#ifdef CONFIG_WIRELESS_EXT
16672 extern int wireless_proc_init(void);
16673 #else
16674 #define wireless_proc_init() 0
16675 @@ -2582,7 +2604,7 @@
16676 ret = -EFAULT;
16677 return ret;
16678 }
16679 -#ifdef WIRELESS_EXT
16680 +#ifdef CONFIG_WIRELESS_EXT
16681 /* Take care of Wireless Extensions */
16682 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
16683 /* If command is `set a parameter', or
16684 @@ -2603,7 +2625,7 @@
16685 ret = -EFAULT;
16686 return ret;
16687 }
16688 -#endif /* WIRELESS_EXT */
16689 +#endif /* CONFIG_WIRELESS_EXT */
16690 return -EINVAL;
16691 }
16692 }
16693 diff -Nur linux-2.6.16/net/core/Makefile linux-2.6.16-bcm43xx/net/core/Makefile
16694 --- linux-2.6.16/net/core/Makefile 2006-03-20 06:53:29.000000000 +0100
16695 +++ linux-2.6.16-bcm43xx/net/core/Makefile 2006-03-28 22:16:14.000000000 +0200
16696 @@ -14,5 +14,5 @@
16697 obj-$(CONFIG_SYSFS) += net-sysfs.o
16698 obj-$(CONFIG_NET_DIVERT) += dv.o
16699 obj-$(CONFIG_NET_PKTGEN) += pktgen.o
16700 -obj-$(CONFIG_NET_RADIO) += wireless.o
16701 +obj-$(CONFIG_WIRELESS_EXT) += wireless.o
16702 obj-$(CONFIG_NETPOLL) += netpoll.o
16703 diff -Nur linux-2.6.16/net/d80211/aes.c linux-2.6.16-bcm43xx/net/d80211/aes.c
16704 --- linux-2.6.16/net/d80211/aes.c 1970-01-01 01:00:00.000000000 +0100
16705 +++ linux-2.6.16-bcm43xx/net/d80211/aes.c 2006-03-28 22:16:14.000000000 +0200
16706 @@ -0,0 +1,564 @@
16707 +/* Based on Rijndael implementation that has been placed in the public domain,
16708 + * although heavily modified.
16709 + *
16710 + * Modifications Copyright 2003, Instant802 Networks, Inc.
16711 + *
16712 + * This program is free software; you can redistribute it and/or modify
16713 + * it under the terms of the GNU General Public License version 2 as
16714 + * published by the Free Software Foundation.
16715 + *
16716 + * Optimized both speed and size by removing not used key lengths (only
16717 + * 128-bit is used in IEEE 802.11i).
16718 + */
16719 +
16720 +/* Use 256-byte Te4 table instead of larger 1024-byte */
16721 +#define SMALL_TE4
16722 +
16723 +/* Save data size by using only one 1k table, but with a drawback of having to
16724 + * rotate entries at lookup. This can be useful, if the CPU supports free
16725 + * rotate on memory read. However, if this is not the case, this is much slower
16726 + * than four-table implementation. */
16727 +/* #define ONLY_ONE_TABLE */
16728 +
16729 +
16730 +/* --- start of code that is based on public domain AES implementation --- */
16731 +
16732 +/**
16733 + * rijndael-alg-fst.c
16734 + *
16735 + * @version 3.0 (December 2000)
16736 + *
16737 + * Optimised ANSI C code for the Rijndael cipher (now AES)
16738 + *
16739 + * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
16740 + * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
16741 + * @author Paulo Barreto <paulo.barreto@terra.com.br>
16742 + *
16743 + * This code is hereby placed in the public domain.
16744 + *
16745 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
16746 + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16747 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16748 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
16749 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16750 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
16751 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
16752 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
16753 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
16754 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
16755 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16756 + */
16757 +
16758 +/*
16759 +Te0[x] = S [x].[02, 01, 01, 03];
16760 +Te1[x] = S [x].[03, 02, 01, 01];
16761 +Te2[x] = S [x].[01, 03, 02, 01];
16762 +Te3[x] = S [x].[01, 01, 03, 02];
16763 +Te4[x] = S [x].[01, 01, 01, 01];
16764 +*/
16765 +
16766 +static const u32 Te0[256] =
16767 +{
16768 + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
16769 + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
16770 + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
16771 + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
16772 + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
16773 + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
16774 + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
16775 + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
16776 + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
16777 + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
16778 + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
16779 + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
16780 + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
16781 + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
16782 + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
16783 + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
16784 + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
16785 + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
16786 + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
16787 + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
16788 + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
16789 + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
16790 + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
16791 + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
16792 + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
16793 + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
16794 + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
16795 + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
16796 + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
16797 + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
16798 + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
16799 + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
16800 + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
16801 + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
16802 + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
16803 + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
16804 + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
16805 + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
16806 + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
16807 + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
16808 + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
16809 + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
16810 + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
16811 + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
16812 + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
16813 + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
16814 + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
16815 + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
16816 + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
16817 + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
16818 + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
16819 + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
16820 + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
16821 + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
16822 + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
16823 + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
16824 + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
16825 + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
16826 + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
16827 + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
16828 + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
16829 + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
16830 + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
16831 + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
16832 +};
16833 +
16834 +#ifndef ONLY_ONE_TABLE
16835 +static const u32 Te1[256] =
16836 +{
16837 + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
16838 + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
16839 + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
16840 + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
16841 + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
16842 + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
16843 + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
16844 + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
16845 + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
16846 + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
16847 + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
16848 + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
16849 + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
16850 + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
16851 + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
16852 + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
16853 + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
16854 + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
16855 + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
16856 + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
16857 + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
16858 + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
16859 + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
16860 + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
16861 + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
16862 + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
16863 + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
16864 + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
16865 + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
16866 + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
16867 + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
16868 + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
16869 + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
16870 + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
16871 + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
16872 + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
16873 + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
16874 + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
16875 + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
16876 + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
16877 + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
16878 + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
16879 + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
16880 + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
16881 + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
16882 + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
16883 + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
16884 + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
16885 + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
16886 + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
16887 + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
16888 + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
16889 + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
16890 + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
16891 + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
16892 + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
16893 + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
16894 + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
16895 + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
16896 + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
16897 + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
16898 + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
16899 + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
16900 + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
16901 +};
16902 +
16903 +static const u32 Te2[256] =
16904 +{
16905 + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
16906 + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
16907 + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
16908 + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
16909 + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
16910 + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
16911 + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
16912 + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
16913 + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
16914 + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
16915 + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
16916 + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
16917 + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
16918 + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
16919 + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
16920 + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
16921 + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
16922 + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
16923 + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
16924 + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
16925 + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
16926 + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
16927 + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
16928 + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
16929 + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
16930 + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
16931 + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
16932 + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
16933 + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
16934 + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
16935 + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
16936 + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
16937 + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
16938 + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
16939 + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
16940 + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
16941 + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
16942 + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
16943 + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
16944 + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
16945 + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
16946 + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
16947 + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
16948 + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
16949 + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
16950 + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
16951 + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
16952 + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
16953 + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
16954 + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
16955 + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
16956 + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
16957 + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
16958 + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
16959 + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
16960 + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
16961 + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
16962 + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
16963 + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
16964 + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
16965 + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
16966 + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
16967 + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
16968 + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
16969 +};
16970 +
16971 +static const u32 Te3[256] =
16972 +{
16973 + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
16974 + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
16975 + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
16976 + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
16977 + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
16978 + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
16979 + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
16980 + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
16981 + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
16982 + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
16983 + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
16984 + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
16985 + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
16986 + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
16987 + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
16988 + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
16989 + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
16990 + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
16991 + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
16992 + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
16993 + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
16994 + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
16995 + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
16996 + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
16997 + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
16998 + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
16999 + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
17000 + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
17001 + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
17002 + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
17003 + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
17004 + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
17005 + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
17006 + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
17007 + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
17008 + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
17009 + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
17010 + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
17011 + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
17012 + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
17013 + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
17014 + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
17015 + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
17016 + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
17017 + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
17018 + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
17019 + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
17020 + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
17021 + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
17022 + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
17023 + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
17024 + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
17025 + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
17026 + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
17027 + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
17028 + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
17029 + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
17030 + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
17031 + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
17032 + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
17033 + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
17034 + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
17035 + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
17036 + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
17037 +};
17038 +
17039 +#define TE0(v) (Te0[(v) >> 24])
17040 +#define TE1(v) (Te1[((v) >> 16) & 0xff])
17041 +#define TE2(v) (Te2[((v) >> 8) & 0xff])
17042 +#define TE3(v) (Te3[(v) & 0xff])
17043 +
17044 +#else /* ONLY_ONE_TABLE */
17045 +
17046 +
17047 +static inline u32 ROR8(u32 v)
17048 +{
17049 + return (v >> 8) | (v << 24);
17050 +}
17051 +
17052 +static inline u32 ROR16(u32 v)
17053 +{
17054 + return (v >> 16) | (v << 16);
17055 +}
17056 +
17057 +static inline u32 ROR24(u32 v)
17058 +{
17059 + return (v >> 24) | (v << 8);
17060 +}
17061 +
17062 +#define TE0(v) (Te0[(v) >> 24])
17063 +#define TE1(v) (ROR8(Te0[((v) >> 16) & 0xff]))
17064 +#define TE2(v) (ROR16(Te0[((v) >> 8) & 0xff]))
17065 +#define TE3(v) (ROR24(Te0[(v) & 0xff]))
17066 +
17067 +#endif /* ONLY_ONE_TABLE */
17068 +
17069 +
17070 +
17071 +#ifdef SMALL_TE4
17072 +static const u8 Te4s[256] = {
17073 + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
17074 + 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
17075 + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
17076 + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
17077 + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
17078 + 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
17079 + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
17080 + 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
17081 + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
17082 + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
17083 + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
17084 + 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
17085 + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
17086 + 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
17087 + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
17088 + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
17089 + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
17090 + 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
17091 + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
17092 + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
17093 + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
17094 + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
17095 + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
17096 + 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
17097 + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
17098 + 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
17099 + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
17100 + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
17101 + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
17102 + 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
17103 + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
17104 + 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16,
17105 +};
17106 +
17107 +#define TE4_1(v) (Te4s[(v) & 0xff] << 24)
17108 +#define TE4_2(v) (Te4s[(v) & 0xff] << 16)
17109 +#define TE4_3(v) (Te4s[(v) & 0xff] << 8)
17110 +#define TE4_4(v) (Te4s[(v) & 0xff])
17111 +
17112 +#else /* SMALL_TE4 */
17113 +
17114 +static const u32 Te4[256] =
17115 +{
17116 + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
17117 + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
17118 + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
17119 + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
17120 + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
17121 + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
17122 + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
17123 + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
17124 + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
17125 + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
17126 + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
17127 + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
17128 + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
17129 + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
17130 + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
17131 + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
17132 + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
17133 + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
17134 + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
17135 + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
17136 + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
17137 + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
17138 + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
17139 + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
17140 + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
17141 + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
17142 + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
17143 + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
17144 + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
17145 + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
17146 + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
17147 + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
17148 + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
17149 + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
17150 + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
17151 + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
17152 + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
17153 + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
17154 + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
17155 + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
17156 + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
17157 + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
17158 + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
17159 + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
17160 + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
17161 + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
17162 + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
17163 + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
17164 + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
17165 + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
17166 + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
17167 + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
17168 + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
17169 + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
17170 + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
17171 + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
17172 + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
17173 + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
17174 + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
17175 + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
17176 + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
17177 + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
17178 + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
17179 + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
17180 +};
17181 +
17182 +#define TE4_1(v) (Te4[(v) & 0xff] & 0xff000000)
17183 +#define TE4_2(v) (Te4[(v) & 0xff] & 0x00ff0000)
17184 +#define TE4_3(v) (Te4[(v) & 0xff] & 0x0000ff00)
17185 +#define TE4_4(v) (Te4[(v) & 0xff] & 0x000000ff)
17186 +
17187 +#endif /* SMALL_TE4 */
17188 +
17189 +
17190 +static const u32 rcon[] = {
17191 + 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
17192 + 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
17193 +};
17194 +
17195 +#define GETU32(pt) \
17196 +(((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ \
17197 +((u32)(pt)[3]))
17198 +#define PUTU32(ct, st) \
17199 +{ (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
17200 +(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
17201 +
17202 +
17203 +/* Expand the cipher key into the encryption key schedule. */
17204 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[])
17205 +{
17206 + int i;
17207 + u32 temp;
17208 +
17209 + rk[0] = GETU32(key );
17210 + rk[1] = GETU32(key + 4);
17211 + rk[2] = GETU32(key + 8);
17212 + rk[3] = GETU32(key + 12);
17213 +
17214 + for (i = 0; i < 10; i++) {
17215 + temp = rk[3];
17216 + rk[4] = rk[0] ^ TE4_1(temp >> 16) ^ TE4_2(temp >> 8) ^
17217 + TE4_3(temp) ^ TE4_4(temp >> 24) ^ rcon[i];
17218 + rk[5] = rk[1] ^ rk[4];
17219 + rk[6] = rk[2] ^ rk[5];
17220 + rk[7] = rk[3] ^ rk[6];
17221 + rk += 4;
17222 + }
17223 +}
17224 +
17225 +
17226 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
17227 +{
17228 + const int Nr = 10;
17229 + u32 s0, s1, s2, s3, t0, t1, t2, t3;
17230 +
17231 + /* Map byte array block to cipher state and add initial round key */
17232 + s0 = GETU32(pt ) ^ rk[0];
17233 + s1 = GETU32(pt + 4) ^ rk[1];
17234 + s2 = GETU32(pt + 8) ^ rk[2];
17235 + s3 = GETU32(pt + 12) ^ rk[3];
17236 +
17237 +#define ROUND(r,d,s,i) \
17238 +d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[i]; \
17239 +d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[i + 1]; \
17240 +d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[i + 2]; \
17241 +d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[i + 3]
17242 + ROUND(1,t,s,4);
17243 + ROUND(2,s,t,8);
17244 + ROUND(3,t,s,12);
17245 + ROUND(4,s,t,16);
17246 + ROUND(5,t,s,20);
17247 + ROUND(6,s,t,24);
17248 + ROUND(7,t,s,28);
17249 + ROUND(8,s,t,32);
17250 + ROUND(9,t,s,36);
17251 +#undef ROUND
17252 +
17253 + rk += Nr << 2;
17254 +
17255 + /* Apply the last round and map cipher state to byte array block */
17256 + s0 = TE4_1(t0 >> 24) ^ TE4_2(t1 >> 16) ^ TE4_3(t2 >> 8) ^ TE4_4(t3) ^
17257 + rk[0];
17258 + PUTU32(ct, s0);
17259 + s0 = TE4_1(t1 >> 24) ^ TE4_2(t2 >> 16) ^ TE4_3(t3 >> 8) ^ TE4_4(t0) ^
17260 + rk[1];
17261 + PUTU32(ct + 4, s0);
17262 + s0 = TE4_1(t2 >> 24) ^ TE4_2(t3 >> 16) ^ TE4_3(t0 >> 8) ^ TE4_4(t1) ^
17263 + rk[2];
17264 + PUTU32(ct + 8, s0);
17265 + s0 = TE4_1(t3 >> 24) ^ TE4_2(t0 >> 16) ^ TE4_3(t1 >> 8) ^ TE4_4(t2) ^
17266 + rk[3];
17267 + PUTU32(ct + 12, s0);
17268 +}
17269 +
17270 +/* --- end of code that is based on public domain AES implementation --- */
17271 diff -Nur linux-2.6.16/net/d80211/aes_ccm.c linux-2.6.16-bcm43xx/net/d80211/aes_ccm.c
17272 --- linux-2.6.16/net/d80211/aes_ccm.c 1970-01-01 01:00:00.000000000 +0100
17273 +++ linux-2.6.16-bcm43xx/net/d80211/aes_ccm.c 2006-03-28 22:16:14.000000000 +0200
17274 @@ -0,0 +1,119 @@
17275 +/*
17276 + * Copyright 2003-2004, Instant802 Networks, Inc.
17277 + * Copyright 2005, Devicescape Software, Inc.
17278 + *
17279 + * This program is free software; you can redistribute it and/or modify
17280 + * it under the terms of the GNU General Public License version 2 as
17281 + * published by the Free Software Foundation.
17282 + */
17283 +
17284 +#include <linux/types.h>
17285 +#include <linux/netdevice.h>
17286 +
17287 +#include <net/d80211.h>
17288 +#include "ieee80211_key.h"
17289 +#include "aes_ccm.h"
17290 +
17291 +#include "aes.c"
17292 +
17293 +static inline void aes_ccm_prepare(u32 *rk, u8 *b_0, u8 *aad, u8 *b,
17294 + u8 *s_0, u8 *a)
17295 +{
17296 + int i;
17297 +
17298 + ieee80211_aes_encrypt(rk, b_0, b);
17299 +
17300 + /* Extra Authenticate-only data (always two AES blocks) */
17301 + for (i = 0; i < AES_BLOCK_LEN; i++)
17302 + aad[i] ^= b[i];
17303 + ieee80211_aes_encrypt(rk, aad, b);
17304 +
17305 + aad += AES_BLOCK_LEN;
17306 +
17307 + for (i = 0; i < AES_BLOCK_LEN; i++)
17308 + aad[i] ^= b[i];
17309 + ieee80211_aes_encrypt(rk, aad, a);
17310 +
17311 + /* Mask out bits from auth-only-b_0 */
17312 + b_0[0] &= 0x07;
17313 +
17314 + /* S_0 is used to encrypt T (= MIC) */
17315 + b_0[14] = 0;
17316 + b_0[15] = 0;
17317 + ieee80211_aes_encrypt(rk, b_0, s_0);
17318 +}
17319 +
17320 +
17321 +void ieee80211_aes_ccm_encrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *data,
17322 + size_t data_len, u8 *cdata, u8 *mic)
17323 +{
17324 + int i, j, last_len, num_blocks;
17325 + u8 *pos, *cpos;
17326 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], e[AES_BLOCK_LEN];
17327 +
17328 + num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
17329 + last_len = data_len % AES_BLOCK_LEN;
17330 + aes_ccm_prepare(rk, b_0, aad, b, s_0, b);
17331 +
17332 + /* Process payload blocks */
17333 + pos = data;
17334 + cpos = cdata;
17335 + for (j = 1; j <= num_blocks; j++) {
17336 + int blen = (j == num_blocks && last_len) ?
17337 + last_len : AES_BLOCK_LEN;
17338 +
17339 + /* Authentication followed by encryption */
17340 + for (i = 0; i < blen; i++)
17341 + b[i] ^= pos[i];
17342 + ieee80211_aes_encrypt(rk, b, b);
17343 +
17344 + b_0[14] = (j >> 8) & 0xff;
17345 + b_0[15] = j & 0xff;
17346 + ieee80211_aes_encrypt(rk, b_0, e);
17347 + for (i = 0; i < blen; i++)
17348 + *cpos++ = *pos++ ^ e[i];
17349 + }
17350 +
17351 + for (i = 0; i < CCMP_MIC_LEN; i++)
17352 + mic[i] = b[i] ^ s_0[i];
17353 +}
17354 +
17355 +
17356 +int ieee80211_aes_ccm_decrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *cdata,
17357 + size_t data_len, u8 *mic, u8 *data)
17358 +{
17359 + int i, j, last_len, num_blocks;
17360 + u8 *pos, *cpos;
17361 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], a[AES_BLOCK_LEN];
17362 +
17363 + num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
17364 + last_len = data_len % AES_BLOCK_LEN;
17365 + aes_ccm_prepare(rk, b_0, aad, b, s_0, a);
17366 +
17367 + /* Process payload blocks */
17368 + cpos = cdata;
17369 + pos = data;
17370 + for (j = 1; j <= num_blocks; j++) {
17371 + int blen = (j == num_blocks && last_len) ?
17372 + last_len : AES_BLOCK_LEN;
17373 +
17374 + /* Decryption followed by authentication */
17375 + b_0[14] = (j >> 8) & 0xff;
17376 + b_0[15] = j & 0xff;
17377 + ieee80211_aes_encrypt(rk, b_0, b);
17378 + for (i = 0; i < blen; i++) {
17379 + *pos = *cpos++ ^ b[i];
17380 + a[i] ^= *pos++;
17381 + }
17382 +
17383 + ieee80211_aes_encrypt(rk, a, a);
17384 + }
17385 +
17386 + for (i = 0; i < CCMP_MIC_LEN; i++) {
17387 + if ((mic[i] ^ s_0[i]) != a[i])
17388 + return -1;
17389 + }
17390 +
17391 + return 0;
17392 +}
17393 +
17394 diff -Nur linux-2.6.16/net/d80211/aes_ccm.h linux-2.6.16-bcm43xx/net/d80211/aes_ccm.h
17395 --- linux-2.6.16/net/d80211/aes_ccm.h 1970-01-01 01:00:00.000000000 +0100
17396 +++ linux-2.6.16-bcm43xx/net/d80211/aes_ccm.h 2006-03-28 22:16:14.000000000 +0200
17397 @@ -0,0 +1,24 @@
17398 +/*
17399 + * Copyright 2003-2004, Instant802 Networks, Inc.
17400 + *
17401 + * This program is free software; you can redistribute it and/or modify
17402 + * it under the terms of the GNU General Public License version 2 as
17403 + * published by the Free Software Foundation.
17404 + */
17405 +
17406 +#ifndef AES_CCM_H
17407 +#define AES_CCM_H
17408 +
17409 +#include <linux/types.h>
17410 +
17411 +#define AES_BLOCK_LEN 16
17412 +#define AES_STATE_LEN 44
17413 +
17414 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[]);
17415 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16]);
17416 +void ieee80211_aes_ccm_encrypt(u32 rk[/*44*/], u8 *b_0, u8 *aad, u8 *data,
17417 + size_t data_len, u8 *cdata, u8 *mic);
17418 +int ieee80211_aes_ccm_decrypt(u32 rk[/*44*/], u8 *b_0, u8 *aad, u8 *cdata,
17419 + size_t data_len, u8 *mic, u8 *data);
17420 +
17421 +#endif /* AES_CCM_H */
17422 diff -Nur linux-2.6.16/net/d80211/fifo_qdisc.c linux-2.6.16-bcm43xx/net/d80211/fifo_qdisc.c
17423 --- linux-2.6.16/net/d80211/fifo_qdisc.c 1970-01-01 01:00:00.000000000 +0100
17424 +++ linux-2.6.16-bcm43xx/net/d80211/fifo_qdisc.c 2006-03-28 22:16:14.000000000 +0200
17425 @@ -0,0 +1,103 @@
17426 +/*
17427 + * Copyright 2005, Devicescape Software, Inc.
17428 + *
17429 + * This program is free software; you can redistribute it and/or modify
17430 + * it under the terms of the GNU General Public License version 2 as
17431 + * published by the Free Software Foundation.
17432 + *
17433 + * If building without CONFIG_NET_SCHED we need a simple
17434 + * fifo qdisc to install by default as the sub-qdisc.
17435 + * This is a simple replacement for sch_fifo.
17436 + */
17437 +
17438 +#include <linux/config.h>
17439 +#include <linux/version.h>
17440 +#include <linux/netdevice.h>
17441 +#include <net/d80211.h>
17442 +#include "ieee80211_i.h"
17443 +#include "wme.h"
17444 +
17445 +static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* qd)
17446 +{
17447 + struct sk_buff_head *q = qdisc_priv(qd);
17448 +
17449 + if (skb_queue_len(q) > qd->dev->tx_queue_len) {
17450 + qd->qstats.drops++;
17451 + kfree_skb(skb);
17452 + return NET_XMIT_DROP;
17453 + }
17454 +
17455 + skb_queue_tail(q, skb);
17456 + qd->q.qlen++;
17457 + qd->bstats.bytes += skb->len;
17458 + qd->bstats.packets++;
17459 +
17460 + return NET_XMIT_SUCCESS;
17461 +}
17462 +
17463 +
17464 +static int pfifo_requeue(struct sk_buff *skb, struct Qdisc* qd)
17465 +{
17466 + struct sk_buff_head *q = qdisc_priv(qd);
17467 +
17468 + skb_queue_head(q, skb);
17469 + qd->q.qlen++;
17470 + qd->bstats.bytes += skb->len;
17471 + qd->bstats.packets++;
17472 +
17473 + return NET_XMIT_SUCCESS;
17474 +}
17475 +
17476 +
17477 +static struct sk_buff *pfifo_dequeue(struct Qdisc* qd)
17478 +{
17479 + struct sk_buff_head *q = qdisc_priv(qd);
17480 +
17481 + return skb_dequeue(q);
17482 +}
17483 +
17484 +
17485 +static int pfifo_init(struct Qdisc* qd, struct rtattr *opt)
17486 +{
17487 + struct sk_buff_head *q = qdisc_priv(qd);
17488 +
17489 + skb_queue_head_init(q);
17490 + return 0;
17491 +}
17492 +
17493 +
17494 +static void pfifo_reset(struct Qdisc* qd)
17495 +{
17496 + struct sk_buff_head *q = qdisc_priv(qd);
17497 +
17498 + skb_queue_purge(q);
17499 + qd->q.qlen = 0;
17500 +}
17501 +
17502 +
17503 +static int pfifo_dump(struct Qdisc *qd, struct sk_buff *skb)
17504 +{
17505 + return skb->len;
17506 +}
17507 +
17508 +
17509 +struct Qdisc_ops pfifo_qdisc_ops =
17510 +{
17511 + .next = NULL,
17512 + .cl_ops = NULL,
17513 + .id = "ieee80211_pfifo",
17514 + .priv_size = sizeof(struct sk_buff_head),
17515 +
17516 + .enqueue = pfifo_enqueue,
17517 + .dequeue = pfifo_dequeue,
17518 + .requeue = pfifo_requeue,
17519 + .drop = NULL,
17520 +
17521 + .init = pfifo_init,
17522 + .reset = pfifo_reset,
17523 + .destroy = NULL,
17524 + .change = NULL,
17525 +
17526 + .dump = pfifo_dump,
17527 +};
17528 +
17529 diff -Nur linux-2.6.16/net/d80211/hostapd_ioctl.h linux-2.6.16-bcm43xx/net/d80211/hostapd_ioctl.h
17530 --- linux-2.6.16/net/d80211/hostapd_ioctl.h 1970-01-01 01:00:00.000000000 +0100
17531 +++ linux-2.6.16-bcm43xx/net/d80211/hostapd_ioctl.h 2006-03-28 22:16:14.000000000 +0200
17532 @@ -0,0 +1,439 @@
17533 +/*
17534 + * Host AP (software wireless LAN access point) user space daemon for
17535 + * Host AP kernel driver
17536 + * Copyright 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
17537 + * Copyright 2002-2004, Instant802 Networks, Inc.
17538 + * Copyright 2005, Devicescape Software, Inc.
17539 + *
17540 + * This program is free software; you can redistribute it and/or modify
17541 + * it under the terms of the GNU General Public License version 2 as
17542 + * published by the Free Software Foundation.
17543 + */
17544 +
17545 +#ifndef HOSTAPD_IOCTL_H
17546 +#define HOSTAPD_IOCTL_H
17547 +
17548 +#include <linux/types.h>
17549 +
17550 +#ifndef __KERNEL__
17551 +#include "ieee80211_shared.h"
17552 +#endif /* __KERNEL__ */
17553 +
17554 +#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
17555 +#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
17556 +#define PRISM2_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 3)
17557 +#define PRISM2_IOCTL_TEST_PARAM (SIOCIWFIRSTPRIV + 4)
17558 +
17559 +/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
17560 +enum {
17561 + PRISM2_PARAM_PTYPE = 1,
17562 + PRISM2_PARAM_TXRATECTRL = 2,
17563 + PRISM2_PARAM_BEACON_INT = 3,
17564 + PRISM2_PARAM_PSEUDO_IBSS = 4,
17565 + PRISM2_PARAM_ALC = 5,
17566 + PRISM2_PARAM_TXPOWER = 6,
17567 + PRISM2_PARAM_DUMP = 7,
17568 + PRISM2_PARAM_OTHER_AP_POLICY = 8,
17569 + PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
17570 + PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
17571 + PRISM2_PARAM_DTIM_PERIOD = 11,
17572 + PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
17573 + PRISM2_PARAM_MAX_WDS = 13,
17574 + PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
17575 + PRISM2_PARAM_AP_AUTH_ALGS = 15,
17576 + PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
17577 + PRISM2_PARAM_HOST_ENCRYPT = 17,
17578 + PRISM2_PARAM_HOST_DECRYPT = 18,
17579 + PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
17580 + PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
17581 + PRISM2_PARAM_HOST_ROAMING = 21,
17582 + PRISM2_PARAM_BCRX_STA_KEY = 22,
17583 + PRISM2_PARAM_IEEE_802_1X = 23,
17584 + PRISM2_PARAM_ANTSEL_TX = 24,
17585 + PRISM2_PARAM_ANTSEL_RX = 25,
17586 + PRISM2_PARAM_MONITOR_TYPE = 26,
17587 + PRISM2_PARAM_WDS_TYPE = 27,
17588 + PRISM2_PARAM_HOSTSCAN = 28,
17589 + PRISM2_PARAM_AP_SCAN = 29,
17590 +
17591 + /* Instant802 additions */
17592 + PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES = 1001,
17593 + PRISM2_PARAM_DROP_UNENCRYPTED = 1002,
17594 + PRISM2_PARAM_PREAMBLE = 1003,
17595 + PRISM2_PARAM_RATE_LIMIT = 1004,
17596 + PRISM2_PARAM_RATE_LIMIT_BURST = 1005,
17597 + PRISM2_PARAM_SHORT_SLOT_TIME = 1006,
17598 + PRISM2_PARAM_TEST_MODE = 1007,
17599 + PRISM2_PARAM_NEXT_MODE = 1008,
17600 + PRISM2_PARAM_CLEAR_KEYS = 1009,
17601 + PRISM2_PARAM_ADM_STATUS = 1010,
17602 + PRISM2_PARAM_ANTENNA_SEL = 1011,
17603 + PRISM2_PARAM_CALIB_INT = 1012,
17604 + PRISM2_PARAM_ANTENNA_MODE = 1013,
17605 + PRISM2_PARAM_PRIVACY_INVOKED = 1014,
17606 + PRISM2_PARAM_BROADCAST_SSID = 1015,
17607 + PRISM2_PARAM_STAT_TIME = 1016,
17608 + PRISM2_PARAM_STA_ANTENNA_SEL = 1017,
17609 + PRISM2_PARAM_FORCE_UNICAST_RATE = 1018,
17610 + PRISM2_PARAM_RATE_CTRL_NUM_UP = 1019,
17611 + PRISM2_PARAM_RATE_CTRL_NUM_DOWN = 1020,
17612 + PRISM2_PARAM_MAX_RATECTRL_RATE = 1021,
17613 + PRISM2_PARAM_TX_POWER_REDUCTION = 1022,
17614 + PRISM2_PARAM_EAPOL = 1023,
17615 + PRISM2_PARAM_KEY_TX_RX_THRESHOLD = 1024,
17616 + PRISM2_PARAM_KEY_INDEX = 1025,
17617 + PRISM2_PARAM_DEFAULT_WEP_ONLY = 1026,
17618 + PRISM2_PARAM_WIFI_WME_NOACK_TEST = 1033,
17619 + PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS = 1034,
17620 + PRISM2_PARAM_SCAN_FLAGS = 1035,
17621 + PRISM2_PARAM_HW_MODES = 1036,
17622 + PRISM2_PARAM_CREATE_IBSS = 1037,
17623 + PRISM2_PARAM_WMM_ENABLED = 1038,
17624 + PRISM2_PARAM_MIXED_CELL = 1039,
17625 + PRISM2_PARAM_KEY_MGMT = 1040,
17626 + PRISM2_PARAM_RADAR_DETECT = 1043,
17627 + PRISM2_PARAM_SPECTRUM_MGMT = 1044,
17628 + /* NOTE: Please try to coordinate with other active development
17629 + * branches before allocating new param numbers so that each new param
17630 + * will be unique within all branches and the allocated number will not
17631 + * need to be changed when merging new features. Existing numbers in
17632 + * the mainline (or main devel branch) must not be changed when merging
17633 + * in new features. */
17634 +};
17635 +
17636 +/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
17637 +enum {
17638 + PRISM2_HOSTAPD_FLUSH = 1,
17639 + PRISM2_HOSTAPD_ADD_STA = 2,
17640 + PRISM2_HOSTAPD_REMOVE_STA = 3,
17641 + PRISM2_HOSTAPD_GET_INFO_STA = 4,
17642 + /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
17643 + PRISM2_SET_ENCRYPTION = 6,
17644 + PRISM2_GET_ENCRYPTION = 7,
17645 + PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
17646 + PRISM2_HOSTAPD_GET_RID = 9,
17647 + PRISM2_HOSTAPD_SET_RID = 10,
17648 + PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
17649 + PRISM2_HOSTAPD_MLME = 13,
17650 +
17651 + /* Instant802 additions */
17652 + PRISM2_HOSTAPD_SET_BEACON = 1001,
17653 + PRISM2_HOSTAPD_GET_HW_FEATURES = 1002,
17654 + PRISM2_HOSTAPD_SCAN = 1003,
17655 + PRISM2_HOSTAPD_WPA_TRIGGER = 1004,
17656 + PRISM2_HOSTAPD_SET_RATE_SETS = 1005,
17657 + PRISM2_HOSTAPD_ADD_IF = 1006,
17658 + PRISM2_HOSTAPD_REMOVE_IF = 1007,
17659 + PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE = 1008,
17660 + PRISM2_HOSTAPD_GET_LOAD_STATS = 1009,
17661 + PRISM2_HOSTAPD_SET_STA_VLAN = 1010,
17662 + PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM = 1011,
17663 + PRISM2_HOSTAPD_SET_CHANNEL_FLAG = 1012,
17664 + PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN = 1013,
17665 + PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS = 1014,
17666 + PRISM2_HOSTAPD_SET_BSS = 1015,
17667 + PRISM2_HOSTAPD_GET_TX_STATS = 1016,
17668 + PRISM2_HOSTAPD_UPDATE_IF = 1017,
17669 + PRISM2_HOSTAPD_SCAN_REQ = 1019,
17670 + PRISM2_STA_GET_STATE = 1020,
17671 + PRISM2_HOSTAPD_FLUSH_IFS = 1021,
17672 + PRISM2_HOSTAPD_SET_RADAR_PARAMS = 1023,
17673 + PRISM2_HOSTAPD_SET_QUIET_PARAMS = 1024,
17674 + PRISM2_HOSTAPD_GET_TX_POWER = 1025,
17675 + /* NOTE: Please try to coordinate with other active development
17676 + * branches before allocating new param numbers so that each new param
17677 + * will be unique within all branches and the allocated number will not
17678 + * need to be changed when merging new features. Existing numbers in
17679 + * the mainline (or main devel branch) must not be changed when merging
17680 + * in new features. */
17681 +};
17682 +
17683 + /* these definitions mirror the ieee80211_i.h
17684 + * IEEE80211_DISABLED, ... IEEE80211_ASSOCIATED enumeration */
17685 +enum {
17686 + PRISM2_PARAM_STA_DISABLED,
17687 + PRISM2_PARAM_STA_AUTHENTICATE,
17688 + PRISM2_PARAM_STA_ASSOCIATE,
17689 + PRISM2_PARAM_STA_ASSOCIATED,
17690 +};
17691 +
17692 +#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
17693 +#define HOSTAP_CRYPT_ALG_NAME_LEN 16
17694 +
17695 +/* Use this to make sure that structure elements are correctly aligned
17696 + * for access as other types. Most commonly, this affects the placeholder
17697 + * types used for data at the end of a structure in this union.
17698 + */
17699 +#ifdef __GNUC__
17700 +#undef ALIGNED
17701 +#define ALIGNED __attribute__ ((aligned))
17702 +#else
17703 +/* Check if it has been defined elsewhere */
17704 +#ifndef ALIGNED
17705 +#error "Must define ALIGNED to generate aligned structure elements"
17706 +#endif
17707 +#endif
17708 +
17709 +struct prism2_hostapd_param {
17710 + u32 cmd;
17711 + u8 sta_addr[ETH_ALEN];
17712 + u8 pad[2];
17713 + union {
17714 + struct {
17715 + u16 aid;
17716 + u16 capability;
17717 + u8 supp_rates[32];
17718 + /* atheros_super_ag and enc_flags are only used with
17719 + * IEEE80211_ATHEROS_SUPER_AG
17720 + */
17721 + u8 atheros_super_ag;
17722 + u8 atheros_xr_mode;
17723 + u8 wds_flags;
17724 +#define IEEE80211_STA_DYNAMIC_ENC BIT(0)
17725 + u8 enc_flags;
17726 + } add_sta;
17727 + struct {
17728 + u32 inactive_msec;
17729 + u32 rx_packets;
17730 + u32 tx_packets;
17731 + u32 rx_bytes;
17732 + u32 tx_bytes;
17733 + u32 current_tx_rate; /* in 100 kbps */
17734 + u32 channel_use;
17735 + u32 flags;
17736 + u32 num_ps_buf_frames;
17737 + u32 tx_retry_failed;
17738 + u32 tx_retry_count;
17739 + u32 last_rssi;
17740 + u32 last_ack_rssi;
17741 + } get_info_sta;
17742 + struct {
17743 + u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
17744 + u32 flags;
17745 + u32 err;
17746 + u8 idx;
17747 +#define HOSTAP_SEQ_COUNTER_SIZE 8
17748 + u8 seq_counter[HOSTAP_SEQ_COUNTER_SIZE];
17749 + u16 key_len;
17750 + u8 key[0] ALIGNED;
17751 + } crypt;
17752 + struct {
17753 + u32 flags_and;
17754 + u32 flags_or;
17755 + } set_flags_sta;
17756 + struct {
17757 + u16 rid;
17758 + u16 len;
17759 + u8 data[0] ALIGNED;
17760 + } rid;
17761 + struct {
17762 + u16 head_len;
17763 + u16 tail_len;
17764 + u8 data[0] ALIGNED; /* head_len + tail_len bytes */
17765 + } beacon;
17766 + struct {
17767 + u16 num_modes;
17768 + u16 flags;
17769 + u8 data[0] ALIGNED; /* num_modes * feature data */
17770 + } hw_features;
17771 + struct {
17772 + u8 now;
17773 + s8 our_mode_only;
17774 + s16 last_rx;
17775 + u16 channel;
17776 + s16 interval; /* seconds */
17777 + s32 listen; /* microseconds */
17778 + } scan;
17779 + struct {
17780 +#define WPA_TRIGGER_FAIL_TX_MIC BIT(0)
17781 +#define WPA_TRIGGER_FAIL_TX_ICV BIT(1)
17782 +#define WPA_TRIGGER_FAIL_RX_MIC BIT(2)
17783 +#define WPA_TRIGGER_FAIL_RX_ICV BIT(3)
17784 +#define WPA_TRIGGER_TX_REPLAY BIT(4)
17785 +#define WPA_TRIGGER_TX_REPLAY_FRAG BIT(5)
17786 +#define WPA_TRIGGER_TX_SKIP_SEQ BIT(6)
17787 + u32 trigger;
17788 + } wpa_trigger;
17789 + struct {
17790 + u16 mode; /* MODE_* */
17791 + u16 num_supported_rates;
17792 + u16 num_basic_rates;
17793 + u8 data[0] ALIGNED; /* num_supported_rates * u16 +
17794 + * num_basic_rates * u16 */
17795 + } set_rate_sets;
17796 + struct {
17797 + u8 type; /* WDS, VLAN, etc */
17798 + u8 name[IFNAMSIZ];
17799 + u8 data[0] ALIGNED;
17800 + } if_info;
17801 + struct dot11_counters {
17802 + u32 dot11TransmittedFragmentCount;
17803 + u32 dot11MulticastTransmittedFrameCount;
17804 + u32 dot11FailedCount;
17805 + u32 dot11ReceivedFragmentCount;
17806 + u32 dot11MulticastReceivedFrameCount;
17807 + u32 dot11FCSErrorCount;
17808 + u32 dot11TransmittedFrameCount;
17809 + u32 dot11WEPUndecryptableCount;
17810 + u32 dot11ACKFailureCount;
17811 + u32 dot11RTSFailureCount;
17812 + u32 dot11RTSSuccessCount;
17813 + } dot11CountersTable;
17814 + struct {
17815 +#define LOAD_STATS_CLEAR BIT(1)
17816 + u32 flags;
17817 + u32 channel_use;
17818 + } get_load_stats;
17819 + struct {
17820 + char vlan_name[IFNAMSIZ];
17821 + int vlan_id;
17822 + } set_sta_vlan;
17823 + struct {
17824 + u8 len;
17825 + u8 data[0] ALIGNED;
17826 + } set_generic_info_elem;
17827 + struct {
17828 + u16 mode; /* MODE_* */
17829 + u16 chan;
17830 + u32 flag;
17831 + u8 power_level; /* regulatory limit in dBm */
17832 + u8 antenna_max;
17833 + } set_channel_flag;
17834 + struct {
17835 + u32 rd;
17836 + } set_regulatory_domain;
17837 + struct {
17838 + u32 queue;
17839 + s32 aifs;
17840 + u32 cw_min;
17841 + u32 cw_max;
17842 + u32 burst_time; /* maximum burst time in 0.1 ms, i.e.,
17843 + * 10 = 1 ms */
17844 + } tx_queue_params;
17845 + struct {
17846 + u32 bss_count;
17847 + u8 bssid_mask[ETH_ALEN];
17848 + } set_bss;
17849 + struct ieee80211_tx_stats {
17850 + struct {
17851 + unsigned int len; /* num packets in queue */
17852 + unsigned int limit; /* queue len (soft) limit
17853 + */
17854 + unsigned int count; /* total num frames sent */
17855 + } data[4];
17856 + } get_tx_stats;
17857 + struct {
17858 + u8 ssid_len;
17859 + u8 ssid[0] ALIGNED;
17860 + } scan_req;
17861 + struct {
17862 + u32 state;
17863 + } sta_get_state;
17864 + struct {
17865 +#define MLME_STA_DEAUTH 0
17866 +#define MLME_STA_DISASSOC 1
17867 + u16 cmd;
17868 + u16 reason_code;
17869 + } mlme;
17870 + struct {
17871 + u8 radar_firpwr_threshold;
17872 + u8 radar_rssi_threshold;
17873 + u8 pulse_height_threshold;
17874 + u8 pulse_rssi_threshold;
17875 + u8 pulse_inband_threshold;
17876 + } radar;
17877 + struct {
17878 + unsigned int period;
17879 + unsigned int offset;
17880 + unsigned int duration;
17881 + } quiet;
17882 + struct {
17883 + unsigned int tx_power_min;
17884 + unsigned int tx_power_max;
17885 + } tx_power;
17886 + struct {
17887 + u8 dummy[80]; /* Make sizeof() this struct large enough
17888 + * with some compiler versions. */
17889 + } dummy;
17890 + } u;
17891 +};
17892 +
17893 +
17894 +#ifndef IEEE80211_TX_QUEUE_NUMS
17895 +#define IEEE80211_TX_QUEUE_NUMS
17896 +/* TODO: these need to be synchronized with ieee80211.h; make a shared header
17897 + * file that can be included into low-level drivers, 80211.o, and hostapd */
17898 +/* tx_queue_params - queue */
17899 +enum {
17900 + IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
17901 + IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
17902 + IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
17903 + IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
17904 + IEEE80211_TX_QUEUE_DATA4 = 4,
17905 + IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
17906 + IEEE80211_TX_QUEUE_BEACON = 7
17907 +};
17908 +#endif /* IEEE80211_TX_QUEUE_NUMS */
17909 +
17910 +
17911 +#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
17912 +#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
17913 +
17914 +#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
17915 +#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
17916 +#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
17917 +#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
17918 +#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
17919 +#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
17920 +
17921 +#define HOSTAP_HW_FLAG_NULLFUNC_OK BIT(0)
17922 +
17923 +enum {
17924 + IEEE80211_KEY_MGMT_NONE = 0,
17925 + IEEE80211_KEY_MGMT_IEEE8021X = 1,
17926 + IEEE80211_KEY_MGMT_WPA_PSK = 2,
17927 + IEEE80211_KEY_MGMT_WPA_EAP = 3,
17928 +};
17929 +
17930 +
17931 +/* Data structures used for get_hw_features ioctl */
17932 +struct hostapd_ioctl_hw_modes_hdr {
17933 + int mode;
17934 + int num_channels;
17935 + int num_rates;
17936 +};
17937 +
17938 +struct ieee80211_channel_data {
17939 + short chan; /* channel number (IEEE 802.11) */
17940 + short freq; /* frequency in MHz */
17941 + int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
17942 +};
17943 +
17944 +struct ieee80211_rate_data {
17945 + int rate; /* rate in 100 kbps */
17946 + int flags; /* IEEE80211_RATE_ flags */
17947 +};
17948 +
17949 +
17950 +/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
17951 +enum {
17952 + HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
17953 + HOSTAP_IF_STA = 4
17954 +};
17955 +
17956 +struct hostapd_if_wds {
17957 + u8 remote_addr[ETH_ALEN];
17958 +};
17959 +
17960 +struct hostapd_if_vlan {
17961 + u8 id;
17962 +};
17963 +
17964 +struct hostapd_if_bss {
17965 + u8 bssid[ETH_ALEN];
17966 +};
17967 +
17968 +struct hostapd_if_sta {
17969 +};
17970 +
17971 +#endif /* HOSTAPD_IOCTL_H */
17972 diff -Nur linux-2.6.16/net/d80211/ieee80211.c linux-2.6.16-bcm43xx/net/d80211/ieee80211.c
17973 --- linux-2.6.16/net/d80211/ieee80211.c 1970-01-01 01:00:00.000000000 +0100
17974 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211.c 2006-03-28 22:16:14.000000000 +0200
17975 @@ -0,0 +1,4896 @@
17976 +/*
17977 + * Copyright 2002-2005, Instant802 Networks, Inc.
17978 + * Copyright 2005-2006, Devicescape Software, Inc.
17979 + *
17980 + * This program is free software; you can redistribute it and/or modify
17981 + * it under the terms of the GNU General Public License version 2 as
17982 + * published by the Free Software Foundation.
17983 + */
17984 +
17985 +#include <linux/config.h>
17986 +#include <linux/version.h>
17987 +#include <linux/module.h>
17988 +#include <linux/init.h>
17989 +#include <linux/netdevice.h>
17990 +#include <linux/types.h>
17991 +#include <linux/slab.h>
17992 +#include <linux/skbuff.h>
17993 +#include <linux/etherdevice.h>
17994 +#include <linux/if_arp.h>
17995 +#include <linux/wireless.h>
17996 +#include <net/iw_handler.h>
17997 +#include <linux/compiler.h>
17998 +
17999 +#include <net/d80211.h>
18000 +#include <net/d80211_common.h>
18001 +#include <net/d80211_mgmt.h>
18002 +#include "ieee80211_i.h"
18003 +#include "ieee80211_proc.h"
18004 +#include "rate_control.h"
18005 +#include "wep.h"
18006 +#include "wpa.h"
18007 +#include "tkip.h"
18008 +#include "wme.h"
18009 +
18010 +
18011 +/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
18012 +/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
18013 +static unsigned char rfc1042_header[] =
18014 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
18015 +/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
18016 +static unsigned char bridge_tunnel_header[] =
18017 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
18018 +/* No encapsulation header if EtherType < 0x600 (=length) */
18019 +
18020 +static unsigned char eapol_header[] =
18021 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
18022 +
18023 +
18024 +struct rate_control_algs {
18025 + struct rate_control_algs *next;
18026 + struct rate_control_ops *ops;
18027 +};
18028 +
18029 +static struct rate_control_algs *ieee80211_rate_ctrl_algs;
18030 +
18031 +static int rate_control_initialize(struct ieee80211_local *local);
18032 +
18033 +
18034 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
18035 +
18036 +
18037 +struct ieee80211_key_conf *
18038 +ieee80211_key_data2conf(struct ieee80211_local *local,
18039 + struct ieee80211_key *data)
18040 +{
18041 + struct ieee80211_key_conf *conf;
18042 +
18043 + conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
18044 + if (conf == NULL)
18045 + return NULL;
18046 +
18047 + conf->hw_key_idx = data->hw_key_idx;
18048 + conf->alg = data->alg;
18049 + conf->keylen = data->keylen;
18050 + conf->force_sw_encrypt = data->force_sw_encrypt;
18051 + conf->keyidx = data->keyidx;
18052 + conf->default_tx_key = data->default_tx_key;
18053 + conf->default_wep_only = local->default_wep_only;
18054 + memcpy(conf->key, data->key, data->keylen);
18055 +
18056 + return conf;
18057 +}
18058 +
18059 +
18060 +static int rate_list_match(int *rate_list, int rate)
18061 +{
18062 + int i;
18063 +
18064 + if (rate_list == NULL)
18065 + return 0;
18066 +
18067 + for (i = 0; rate_list[i] >= 0; i++)
18068 + if (rate_list[i] == rate)
18069 + return 1;
18070 +
18071 + return 0;
18072 +}
18073 +
18074 +
18075 +void ieee80211_prepare_rates(struct net_device *dev)
18076 +{
18077 + struct ieee80211_local *local = dev->priv;
18078 + int i;
18079 +
18080 + for (i = 0; i < local->num_curr_rates; i++) {
18081 + struct ieee80211_rate *rate = &local->curr_rates[i];
18082 +
18083 + rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
18084 + IEEE80211_RATE_BASIC);
18085 +
18086 + if (local->supp_rates[local->conf.phymode]) {
18087 + if (!rate_list_match(local->supp_rates
18088 + [local->conf.phymode],
18089 + rate->rate))
18090 + continue;
18091 + }
18092 +
18093 + rate->flags |= IEEE80211_RATE_SUPPORTED;
18094 +
18095 + /* Use configured basic rate set if it is available. If not,
18096 + * use defaults that are sane for most cases. */
18097 + if (local->basic_rates[local->conf.phymode]) {
18098 + if (rate_list_match(local->basic_rates
18099 + [local->conf.phymode],
18100 + rate->rate))
18101 + rate->flags |= IEEE80211_RATE_BASIC;
18102 + } else switch (local->conf.phymode) {
18103 + case MODE_IEEE80211A:
18104 + if (rate->rate == 60 || rate->rate == 120 ||
18105 + rate->rate == 240)
18106 + rate->flags |= IEEE80211_RATE_BASIC;
18107 + break;
18108 + case MODE_IEEE80211B:
18109 + if (rate->rate == 10 || rate->rate == 20)
18110 + rate->flags |= IEEE80211_RATE_BASIC;
18111 + break;
18112 + case MODE_ATHEROS_TURBO:
18113 + if (rate->rate == 120 || rate->rate == 240 ||
18114 + rate->rate == 480)
18115 + rate->flags |= IEEE80211_RATE_BASIC;
18116 + break;
18117 + case MODE_IEEE80211G:
18118 + if (rate->rate == 10 || rate->rate == 20 ||
18119 + rate->rate == 55 || rate->rate == 110)
18120 + rate->flags |= IEEE80211_RATE_BASIC;
18121 + break;
18122 + }
18123 +
18124 + /* Set ERP and MANDATORY flags based on phymode */
18125 + switch (local->conf.phymode) {
18126 + case MODE_IEEE80211A:
18127 + if (rate->rate == 60 || rate->rate == 120 ||
18128 + rate->rate == 240)
18129 + rate->flags |= IEEE80211_RATE_MANDATORY;
18130 + break;
18131 + case MODE_IEEE80211B:
18132 + if (rate->rate == 10)
18133 + rate->flags |= IEEE80211_RATE_MANDATORY;
18134 + break;
18135 + case MODE_ATHEROS_TURBO:
18136 + break;
18137 + case MODE_IEEE80211G:
18138 + if (rate->rate == 10 || rate->rate == 20 ||
18139 + rate->rate == 55 || rate->rate == 110 ||
18140 + rate->rate == 60 || rate->rate == 120 ||
18141 + rate->rate == 240)
18142 + rate->flags |= IEEE80211_RATE_MANDATORY;
18143 + if (rate->rate != 10 && rate->rate != 20 &&
18144 + rate->rate != 55 && rate->rate != 110)
18145 + rate->flags |= IEEE80211_RATE_ERP;
18146 + break;
18147 + }
18148 + }
18149 +}
18150 +
18151 +
18152 +static void ieee80211_key_threshold_notify(struct net_device *dev,
18153 + struct ieee80211_key *key,
18154 + struct sta_info *sta)
18155 +{
18156 + struct sk_buff *skb;
18157 + struct ieee80211_msg_key_notification *msg;
18158 +
18159 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
18160 + sizeof(struct ieee80211_msg_key_notification));
18161 + if (skb == NULL)
18162 + return;
18163 +
18164 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
18165 + msg = (struct ieee80211_msg_key_notification *)
18166 + skb_put(skb, sizeof(struct ieee80211_msg_key_notification));
18167 + msg->tx_rx_count = key->tx_rx_count;
18168 + memcpy(msg->ifname, dev->name, IFNAMSIZ);
18169 + if (sta)
18170 + memcpy(msg->addr, sta->addr, ETH_ALEN);
18171 + else
18172 + memset(msg->addr, 0xff, ETH_ALEN);
18173 +
18174 + key->tx_rx_count = 0;
18175 +
18176 + ieee80211_rx_mgmt(dev, skb, 0,
18177 + ieee80211_msg_key_threshold_notification);
18178 +}
18179 +
18180 +
18181 +int ieee80211_get_hdrlen(u16 fc)
18182 +{
18183 + int hdrlen = 24;
18184 +
18185 + switch (WLAN_FC_GET_TYPE(fc)) {
18186 + case WLAN_FC_TYPE_DATA:
18187 + if ((fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS))
18188 + hdrlen = 30; /* Addr4 */
18189 + if (WLAN_FC_GET_STYPE(fc) & 0x08)
18190 + hdrlen += 2; /* QoS Control Field */
18191 + break;
18192 + case WLAN_FC_TYPE_CTRL:
18193 + switch (WLAN_FC_GET_STYPE(fc)) {
18194 + case WLAN_FC_STYPE_CTS:
18195 + case WLAN_FC_STYPE_ACK:
18196 + hdrlen = 10;
18197 + break;
18198 + default:
18199 + hdrlen = 16;
18200 + break;
18201 + }
18202 + break;
18203 + }
18204 +
18205 + return hdrlen;
18206 +}
18207 +
18208 +
18209 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb)
18210 +{
18211 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18212 + int hdrlen;
18213 +
18214 + if (unlikely(skb->len < 10))
18215 + return 0;
18216 + hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
18217 + if (unlikely(hdrlen > skb->len))
18218 + return 0;
18219 + return hdrlen;
18220 +}
18221 +
18222 +
18223 +#ifdef IEEE80211_VERBOSE_DEBUG_FRAME_DUMP
18224 +static void ieee80211_dump_frame(const char *ifname, const char *title,
18225 + struct sk_buff *skb)
18226 +{
18227 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18228 + u16 fc;
18229 + int hdrlen;
18230 +
18231 + printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
18232 + if (skb->len < 4) {
18233 + printk("\n");
18234 + return;
18235 + }
18236 +
18237 + fc = le16_to_cpu(hdr->frame_control);
18238 + hdrlen = ieee80211_get_hdrlen(fc);
18239 + if (hdrlen > skb->len)
18240 + hdrlen = skb->len;
18241 + if (hdrlen >= 4)
18242 + printk(" FC=0x%04x DUR=0x%04x",
18243 + fc, le16_to_cpu(hdr->duration_id));
18244 + if (hdrlen >= 10)
18245 + printk(" A1=" MACSTR, MAC2STR(hdr->addr1));
18246 + if (hdrlen >= 16)
18247 + printk(" A2=" MACSTR, MAC2STR(hdr->addr2));
18248 + if (hdrlen >= 24)
18249 + printk(" A3=" MACSTR, MAC2STR(hdr->addr3));
18250 + if (hdrlen >= 30)
18251 + printk(" A4=" MACSTR, MAC2STR(hdr->addr4));
18252 + printk("\n");
18253 +}
18254 +#else /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18255 +static inline void ieee80211_dump_frame(const char *ifname, const char *title,
18256 + struct sk_buff *skb)
18257 +{
18258 +}
18259 +#endif /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18260 +
18261 +
18262 +static int ieee80211_is_eapol(struct sk_buff *skb)
18263 +{
18264 + struct ieee80211_hdr *hdr;
18265 + u16 fc;
18266 + int hdrlen;
18267 +
18268 + if (unlikely(skb->len < 10))
18269 + return 0;
18270 +
18271 + hdr = (struct ieee80211_hdr *) skb->data;
18272 + fc = le16_to_cpu(hdr->frame_control);
18273 +
18274 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
18275 + return 0;
18276 +
18277 + hdrlen = ieee80211_get_hdrlen(fc);
18278 +
18279 + if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
18280 + memcmp(skb->data + hdrlen, eapol_header,
18281 + sizeof(eapol_header)) == 0))
18282 + return 1;
18283 +
18284 + return 0;
18285 +}
18286 +
18287 +
18288 +static ieee80211_txrx_result
18289 +ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
18290 +{
18291 + struct rate_control_extra extra;
18292 +
18293 + memset(&extra, 0, sizeof(extra));
18294 + extra.mgmt_data = tx->sdata &&
18295 + tx->sdata->type == IEEE80211_SUB_IF_TYPE_MGMT;
18296 + extra.ethertype = tx->ethertype;
18297 + extra.startidx = 0;
18298 + extra.endidx = tx->local->num_curr_rates;
18299 +
18300 + tx->u.tx.rate = rate_control_get_rate(tx->dev, tx->skb, &extra);
18301 + if (unlikely(extra.probe != NULL)) {
18302 + tx->u.tx.control->rate_ctrl_probe = 1;
18303 + tx->u.tx.probe_last_frag = 1;
18304 + tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
18305 + tx->u.tx.rate = extra.probe;
18306 + } else {
18307 + tx->u.tx.control->alt_retry_rate = -1;
18308 + }
18309 + if (!tx->u.tx.rate)
18310 + return TXRX_DROP;
18311 + if (tx->local->conf.phymode == MODE_IEEE80211G &&
18312 + tx->local->cts_protect_erp_frames && tx->fragmented &&
18313 + extra.nonerp) {
18314 + tx->u.tx.last_frag_rate = tx->u.tx.rate;
18315 + tx->u.tx.last_frag_rateidx = extra.rateidx;
18316 + tx->u.tx.probe_last_frag = extra.probe ? 1 : 0;
18317 +
18318 + tx->u.tx.rate = extra.nonerp;
18319 + tx->u.tx.control->rateidx = extra.nonerp_idx;
18320 + tx->u.tx.control->rate_ctrl_probe = 0;
18321 + } else {
18322 + tx->u.tx.last_frag_rate = tx->u.tx.rate;
18323 + tx->u.tx.last_frag_rateidx = extra.rateidx;
18324 + tx->u.tx.control->rateidx = extra.rateidx;
18325 + }
18326 + tx->u.tx.control->tx_rate = tx->u.tx.rate->val;
18327 + if ((tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
18328 + tx->local->short_preamble &&
18329 + (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
18330 + tx->u.tx.short_preamble = 1;
18331 + tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
18332 + }
18333 +
18334 + return TXRX_CONTINUE;
18335 +}
18336 +
18337 +
18338 +static ieee80211_txrx_result
18339 +ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
18340 +{
18341 + if (tx->sta)
18342 + tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
18343 + else
18344 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
18345 +
18346 + if (unlikely(tx->u.tx.control->do_not_encrypt))
18347 + tx->key = NULL;
18348 + else if (tx->sta && tx->sta->key)
18349 + tx->key = tx->sta->key;
18350 + else if (tx->sdata->default_key)
18351 + tx->key = tx->sdata->default_key;
18352 + else if (tx->sdata->drop_unencrypted &&
18353 + !(tx->sdata->eapol && ieee80211_is_eapol(tx->skb))) {
18354 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
18355 + return TXRX_DROP;
18356 + } else
18357 + tx->key = NULL;
18358 +
18359 + if (tx->key) {
18360 + tx->key->tx_rx_count++;
18361 + if (unlikely(tx->local->key_tx_rx_threshold &&
18362 + tx->key->tx_rx_count >
18363 + tx->local->key_tx_rx_threshold)) {
18364 + ieee80211_key_threshold_notify(tx->dev, tx->key,
18365 + tx->sta);
18366 + }
18367 + }
18368 +
18369 + return TXRX_CONTINUE;
18370 +}
18371 +
18372 +
18373 +static ieee80211_txrx_result
18374 +ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
18375 +{
18376 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18377 + size_t hdrlen, per_fragm, num_fragm, payload_len, left;
18378 + struct sk_buff **frags, *first, *frag;
18379 + int i;
18380 + u8 *pos;
18381 + int frag_threshold = tx->local->fragmentation_threshold;
18382 +
18383 + if (!tx->fragmented)
18384 + return TXRX_CONTINUE;
18385 +
18386 + first = tx->skb;
18387 +
18388 + hdrlen = ieee80211_get_hdrlen(tx->fc);
18389 + payload_len = first->len - hdrlen;
18390 + per_fragm = frag_threshold - hdrlen - 4 /* FCS */;
18391 + num_fragm = (payload_len + per_fragm - 1) / per_fragm;
18392 +
18393 + frags = (struct sk_buff **)
18394 + kmalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
18395 + if (frags == NULL)
18396 + goto fail;
18397 + memset(frags, 0, num_fragm * sizeof(struct sk_buff *));
18398 +
18399 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREFRAG);
18400 + pos = first->data + hdrlen + per_fragm;
18401 + left = payload_len - per_fragm;
18402 + for (i = 0; i < num_fragm - 1; i++) {
18403 + struct ieee80211_hdr *fhdr;
18404 + size_t copylen;
18405 +
18406 + if (left <= 0)
18407 + goto fail;
18408 +
18409 + /* reserve enough extra head and tail room for possible
18410 + * encryption */
18411 +#define IEEE80211_ENCRYPT_HEADROOM 8
18412 +#define IEEE80211_ENCRYPT_TAILROOM 12
18413 + frag = frags[i] =
18414 + dev_alloc_skb(frag_threshold +
18415 + IEEE80211_ENCRYPT_HEADROOM +
18416 + IEEE80211_ENCRYPT_TAILROOM);
18417 + if (!frag)
18418 + goto fail;
18419 + /* Make sure that all fragments use the same priority so
18420 + * that they end up using the same TX queue */
18421 + frag->priority = first->priority;
18422 + skb_reserve(frag, IEEE80211_ENCRYPT_HEADROOM);
18423 + fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
18424 + memcpy(fhdr, first->data, hdrlen);
18425 + if (i == num_fragm - 2)
18426 + fhdr->frame_control &= cpu_to_le16(~WLAN_FC_MOREFRAG);
18427 + fhdr->seq_ctrl = cpu_to_le16(i + 1);
18428 + copylen = left > per_fragm ? per_fragm : left;
18429 + memcpy(skb_put(frag, copylen), pos, copylen);
18430 +
18431 + pos += copylen;
18432 + left -= copylen;
18433 + }
18434 + skb_trim(first, hdrlen + per_fragm);
18435 +
18436 + tx->u.tx.num_extra_frag = num_fragm - 1;
18437 + tx->u.tx.extra_frag = frags;
18438 +
18439 + return TXRX_CONTINUE;
18440 +
18441 + fail:
18442 + printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
18443 + if (frags) {
18444 + for (i = 0; i < num_fragm - 1; i++)
18445 + if (frags[i])
18446 + dev_kfree_skb(frags[i]);
18447 + kfree(frags);
18448 + }
18449 + I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
18450 + return TXRX_DROP;
18451 +}
18452 +
18453 +
18454 +static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
18455 +{
18456 + if (tx->key->force_sw_encrypt || tx->local->conf.sw_encrypt) {
18457 + if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
18458 + return -1;
18459 + } else {
18460 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
18461 + if (tx->local->hw->wep_include_iv) {
18462 + if (ieee80211_wep_add_iv(tx->local, skb, tx->key) ==
18463 + NULL)
18464 + return -1;
18465 + }
18466 + }
18467 + return 0;
18468 +}
18469 +
18470 +
18471 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
18472 +{
18473 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18474 +
18475 + hdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18476 + if (tx->u.tx.extra_frag) {
18477 + struct ieee80211_hdr *fhdr;
18478 + int i;
18479 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18480 + fhdr = (struct ieee80211_hdr *)
18481 + tx->u.tx.extra_frag[i]->data;
18482 + fhdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18483 + }
18484 + }
18485 +}
18486 +
18487 +
18488 +static ieee80211_txrx_result
18489 +ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
18490 +{
18491 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18492 + u16 fc;
18493 +
18494 + fc = le16_to_cpu(hdr->frame_control);
18495 +
18496 + if (!tx->key || tx->key->alg != ALG_WEP ||
18497 + (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA &&
18498 + (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
18499 + WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_AUTH)))
18500 + return TXRX_CONTINUE;
18501 +
18502 + tx->u.tx.control->iv_len = WEP_IV_LEN;
18503 + tx->u.tx.control->icv_len = WEP_ICV_LEN;
18504 + ieee80211_tx_set_iswep(tx);
18505 +
18506 + if (wep_encrypt_skb(tx, tx->skb) < 0) {
18507 + I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
18508 + return TXRX_DROP;
18509 + }
18510 +
18511 + if (tx->u.tx.extra_frag) {
18512 + int i;
18513 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18514 + if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
18515 + I802_DEBUG_INC(tx->local->
18516 + tx_handlers_drop_wep);
18517 + return TXRX_DROP;
18518 + }
18519 + }
18520 + }
18521 +
18522 + return TXRX_CONTINUE;
18523 +}
18524 +
18525 +
18526 +static inline int ceiling_div(int dividend, int divisor)
18527 +{
18528 + return ((dividend + divisor - 1) / divisor);
18529 +}
18530 +
18531 +
18532 +static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
18533 + int rate, int erp, int short_preamble)
18534 +{
18535 + int dur;
18536 +
18537 + /* calculate duration (in microseconds, rounded up to next higher
18538 + * integer if it includes a fractional microsecond) to send frame of
18539 + * len bytes (does not include FCS) at the given rate. Duration will
18540 + * also include SIFS.
18541 + *
18542 + * rate is in 100 kbps, so divident is multiplied by 10 in the
18543 + * ceiling_div() operations.
18544 + */
18545 +
18546 + if (local->conf.phymode == MODE_IEEE80211A || erp ||
18547 + local->conf.phymode == MODE_ATHEROS_TURBO) {
18548 + /*
18549 + * OFDM:
18550 + *
18551 + * N_DBPS = DATARATE x 4
18552 + * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
18553 + * (16 = SIGNAL time, 6 = tail bits)
18554 + * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
18555 + *
18556 + * T_SYM = 4 usec
18557 + * 802.11a - 17.5.2: aSIFSTime = 16 usec
18558 + * 802.11g - 19.8.4: aSIFSTime = 10 usec +
18559 + * signal ext = 6 usec
18560 + */
18561 + /* FIX: Atheros Turbo may have different (shorter) duration? */
18562 + dur = 16; /* SIFS + signal ext */
18563 + dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
18564 + dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
18565 + dur += 4 * ceiling_div((16 + 8 * (len + 4) + 6) * 10,
18566 + 4 * rate); /* T_SYM x N_SYM */
18567 + } else {
18568 + /*
18569 + * 802.11b or 802.11g with 802.11b compatibility:
18570 + * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
18571 + * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
18572 + *
18573 + * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
18574 + * aSIFSTime = 10 usec
18575 + * aPreambleLength = 144 usec or 72 usec with short preamble
18576 + * aPLCPHeaderLength = 48 ms or 24 ms with short preamble
18577 + */
18578 + dur = 10; /* aSIFSTime = 10 usec */
18579 + dur += short_preamble ? (72 + 24) : (144 + 48);
18580 +
18581 + dur += ceiling_div(8 * (len + 4) * 10, rate);
18582 + }
18583 +
18584 + return dur;
18585 +}
18586 +
18587 +
18588 +static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
18589 + int next_frag_len)
18590 +{
18591 + int rate, mrate, erp, dur, i;
18592 + struct ieee80211_rate *txrate = tx->u.tx.rate;
18593 + struct ieee80211_local *local = tx->local;
18594 +
18595 + erp = txrate->flags & IEEE80211_RATE_ERP;
18596 +
18597 + /*
18598 + * data and mgmt (except PS Poll):
18599 + * - during CFP: 32768
18600 + * - during contention period:
18601 + * if addr1 is group address: 0
18602 + * if more fragments = 0 and addr1 is individual address: time to
18603 + * transmit one ACK plus SIFS
18604 + * if more fragments = 1 and addr1 is individual address: time to
18605 + * transmit next fragment plus 2 x ACK plus 3 x SIFS
18606 + *
18607 + * IEEE 802.11, 9.6:
18608 + * - control response frame (CTS or ACK) shall be transmitted using the
18609 + * same rate as the immediately previous frame in the frame exchange
18610 + * sequence, if this rate belongs to the PHY mandatory rates, or else
18611 + * at the highest possible rate belonging to the PHY rates in the
18612 + * BSSBasicRateSet
18613 + */
18614 +
18615 + if (WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_CTRL) {
18616 + /* TODO: These control frames are not currently sent by
18617 + * 80211.o, but should they be implemented, this function
18618 + * needs to be updated to support duration field calculation.
18619 + *
18620 + * RTS: time needed to transmit pending data/mgmt frame plus
18621 + * one CTS frame plus one ACK frame plus 3 x SIFS
18622 + * CTS: duration of immediately previous RTS minus time
18623 + * required to transmit CTS and its SIFS
18624 + * ACK: 0 if immediately previous directed data/mgmt had
18625 + * more=0, with more=1 duration in ACK frame is duration
18626 + * from previous frame minus time needed to transmit ACK
18627 + * and its SIFS
18628 + * PS Poll: BIT(15) | BIT(14) | aid
18629 + */
18630 + return 0;
18631 + }
18632 +
18633 + /* data/mgmt */
18634 + if (0 /* FIX: data/mgmt during CFP */)
18635 + return 32768;
18636 +
18637 + if (group_addr) /* Group address as the destination - no ACK */
18638 + return 0;
18639 +
18640 + /* Individual destination address:
18641 + * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
18642 + * CTS and ACK frames shall be transmitted using the highest rate in
18643 + * basic rate set that is less than or equal to the rate of the
18644 + * immediately previous frame and that is using the same modulation
18645 + * (CCK or OFDM). If no basic rate set matches with these requirements,
18646 + * the highest mandatory rate of the PHY that is less than or equal to
18647 + * the rate of the previous frame is used.
18648 + * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
18649 + */
18650 + rate = -1;
18651 + mrate = 10; /* use 1 Mbps if everything fails */
18652 + for (i = 0; i < local->num_curr_rates; i++) {
18653 + struct ieee80211_rate *r = &local->curr_rates[i];
18654 + if (r->rate > txrate->rate)
18655 + break;
18656 +
18657 + if (IEEE80211_RATE_MODULATION(txrate->flags) !=
18658 + IEEE80211_RATE_MODULATION(r->flags))
18659 + continue;
18660 +
18661 + if (r->flags & IEEE80211_RATE_BASIC)
18662 + rate = r->rate;
18663 + else if (r->flags & IEEE80211_RATE_MANDATORY)
18664 + mrate = r->rate;
18665 + }
18666 + if (rate == -1) {
18667 + /* No matching basic rate found; use highest suitable mandatory
18668 + * PHY rate */
18669 + rate = mrate;
18670 + }
18671 +
18672 + /* Time needed to transmit ACK
18673 + * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
18674 + * to closest integer */
18675 +
18676 + dur = ieee80211_frame_duration(local, 10, rate, erp,
18677 + local->short_preamble);
18678 +
18679 + if (next_frag_len) {
18680 + /* Frame is fragmented: duration increases with time needed to
18681 + * transmit next fragment plus ACK and 2 x SIFS. */
18682 + dur *= 2; /* ACK + SIFS */
18683 + /* next fragment */
18684 + dur += ieee80211_frame_duration(local, next_frag_len,
18685 + txrate->rate, erp,
18686 + local->short_preamble);
18687 + }
18688 +
18689 + return dur;
18690 +}
18691 +
18692 +
18693 +static ieee80211_txrx_result
18694 +ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
18695 +{
18696 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18697 + u16 dur;
18698 + struct ieee80211_tx_control *control = tx->u.tx.control;
18699 +
18700 + if (!MULTICAST_ADDR(hdr->addr1)) {
18701 + if (tx->skb->len >= tx->local->rts_threshold &&
18702 + tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD) {
18703 + control->use_rts_cts = 1;
18704 + control->retry_limit =
18705 + tx->local->long_retry_limit;
18706 + } else {
18707 + control->retry_limit =
18708 + tx->local->short_retry_limit;
18709 + }
18710 + } else {
18711 + control->retry_limit = 1;
18712 + }
18713 +
18714 + if (tx->fragmented) {
18715 + /* Do not use multiple retry rates when sending fragmented
18716 + * frames.
18717 + * TODO: The last fragment could still use multiple retry
18718 + * rates. */
18719 + control->alt_retry_rate = -1;
18720 + }
18721 +
18722 + /* Use CTS protection for unicast frames sent using extended rates if
18723 + * there are associated non-ERP stations and RTS/CTS is not configured
18724 + * for the frame. */
18725 + if (tx->local->conf.phymode == MODE_IEEE80211G &&
18726 + (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
18727 + tx->u.tx.unicast &&
18728 + tx->local->cts_protect_erp_frames &&
18729 + !control->use_rts_cts)
18730 + control->use_cts_protect = 1;
18731 +
18732 + /* Setup duration field for the first fragment of the frame. Duration
18733 + * for remaining fragments will be updated when they are being sent
18734 + * to low-level driver in ieee80211_tx(). */
18735 + dur = ieee80211_duration(tx, MULTICAST_ADDR(hdr->addr1),
18736 + tx->fragmented ? tx->u.tx.extra_frag[0]->len :
18737 + 0);
18738 + hdr->duration_id = cpu_to_le16(dur);
18739 +
18740 + if (control->use_rts_cts || control->use_cts_protect) {
18741 + struct ieee80211_rate *rate;
18742 + int erp = tx->u.tx.rate->flags & IEEE80211_RATE_ERP;
18743 +
18744 + /* Do not use multiple retry rates when using RTS/CTS */
18745 + control->alt_retry_rate = -1;
18746 +
18747 + /* Use min(data rate, max base rate) as CTS/RTS rate */
18748 + rate = tx->u.tx.rate;
18749 + while (rate > tx->local->curr_rates &&
18750 + !(rate->flags & IEEE80211_RATE_BASIC))
18751 + rate--;
18752 +
18753 + if (control->use_rts_cts)
18754 + dur += ieee80211_frame_duration(tx->local, 10,
18755 + rate->rate, erp,
18756 + tx->local->
18757 + short_preamble);
18758 + dur += ieee80211_frame_duration(tx->local, tx->skb->len,
18759 + tx->u.tx.rate->rate, erp,
18760 + tx->u.tx.short_preamble);
18761 + control->rts_cts_duration = dur;
18762 + control->rts_cts_rate = rate->val;
18763 + }
18764 +
18765 + if (tx->sta) {
18766 + tx->sta->tx_packets++;
18767 + tx->sta->tx_fragments++;
18768 + tx->sta->tx_bytes += tx->skb->len;
18769 + if (tx->u.tx.extra_frag) {
18770 + int i;
18771 + tx->sta->tx_fragments += tx->u.tx.num_extra_frag;
18772 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18773 + tx->sta->tx_bytes +=
18774 + tx->u.tx.extra_frag[i]->len;
18775 + }
18776 + }
18777 + }
18778 + tx->local->scan.txrx_count++;
18779 +
18780 + return TXRX_CONTINUE;
18781 +}
18782 +
18783 +
18784 +static void ieee80211_rate_limit(unsigned long data)
18785 +{
18786 + struct ieee80211_local *local = (struct ieee80211_local *) data;
18787 +
18788 + if (local->rate_limit) {
18789 + local->rate_limit_bucket += local->rate_limit;
18790 + if (local->rate_limit_bucket > local->rate_limit_burst)
18791 + local->rate_limit_bucket = local->rate_limit_burst;
18792 + local->rate_limit_timer.expires = jiffies + HZ;
18793 + add_timer(&local->rate_limit_timer);
18794 + }
18795 +}
18796 +
18797 +
18798 +static ieee80211_txrx_result
18799 +ieee80211_tx_h_rate_limit(struct ieee80211_txrx_data *tx)
18800 +{
18801 +
18802 + if (likely(!tx->local->rate_limit || tx->u.tx.unicast))
18803 + return TXRX_CONTINUE;
18804 +
18805 + /* rate limit */
18806 + if (tx->local->rate_limit_bucket) {
18807 + tx->local->rate_limit_bucket--;
18808 + return TXRX_CONTINUE;
18809 + }
18810 +
18811 + I802_DEBUG_INC(tx->local->tx_handlers_drop_rate_limit);
18812 + return TXRX_DROP;
18813 +}
18814 +
18815 +
18816 +static ieee80211_txrx_result
18817 +ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
18818 +{
18819 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
18820 + struct sk_buff *skb = tx->skb;
18821 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18822 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
18823 + u32 sta_flags;
18824 +
18825 + if (unlikely(tx->local->sta_scanning != 0) &&
18826 + (WLAN_FC_GET_TYPE(tx->fc) != WLAN_FC_TYPE_MGMT ||
18827 + WLAN_FC_GET_STYPE(tx->fc) != WLAN_FC_STYPE_PROBE_REQ))
18828 + return TXRX_DROP;
18829 +
18830 + if (tx->u.tx.ps_buffered)
18831 + return TXRX_CONTINUE;
18832 +
18833 + sta_flags = tx->sta ? tx->sta->flags : 0;
18834 +
18835 + if (likely(tx->u.tx.unicast)) {
18836 + if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
18837 + tx->local->conf.mode != IW_MODE_ADHOC &&
18838 + WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_DATA)) {
18839 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
18840 + printk(KERN_DEBUG "%s: dropped data frame to not "
18841 + "associated station " MACSTR "\n",
18842 + tx->dev->name, MAC2STR(hdr->addr1));
18843 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
18844 + I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
18845 + return TXRX_DROP;
18846 + }
18847 + } else {
18848 + if (unlikely(WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_DATA &&
18849 + tx->local->num_sta == 0 &&
18850 + !tx->local->allow_broadcast_always &&
18851 + tx->local->conf.mode != IW_MODE_ADHOC)) {
18852 + /*
18853 + * No associated STAs - no need to send multicast
18854 + * frames.
18855 + */
18856 + return TXRX_DROP;
18857 + }
18858 + return TXRX_CONTINUE;
18859 + }
18860 +
18861 + if (unlikely(!tx->u.tx.mgmt_interface && tx->sdata->ieee802_1x &&
18862 + !(sta_flags & WLAN_STA_AUTHORIZED))) {
18863 +#ifdef CONFIG_D80211_DEBUG
18864 + struct ieee80211_hdr *hdr =
18865 + (struct ieee80211_hdr *) tx->skb->data;
18866 + printk(KERN_DEBUG "%s: dropped frame to " MACSTR
18867 + " (unauthorized port)\n", tx->dev->name,
18868 + MAC2STR(hdr->addr1));
18869 +#endif
18870 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
18871 + return TXRX_DROP;
18872 + }
18873 +
18874 + return TXRX_CONTINUE;
18875 +}
18876 +
18877 +
18878 +/* This function is called whenever the AP is about to exceed the maximum limit
18879 + * of buffered frames for power saving STAs. This situation should not really
18880 + * happen often during normal operation, so dropping the oldest buffered packet
18881 + * from each queue should be OK to make some room for new frames. */
18882 +static void purge_old_ps_buffers(struct ieee80211_local *local)
18883 +{
18884 + int total = 0, purged = 0;
18885 + struct sk_buff *skb;
18886 + struct list_head *ptr;
18887 +
18888 + spin_lock_bh(&local->sub_if_lock);
18889 + list_for_each(ptr, &local->sub_if_list) {
18890 + struct ieee80211_if_ap *ap;
18891 + struct ieee80211_sub_if_data *sdata =
18892 + list_entry(ptr, struct ieee80211_sub_if_data, list);
18893 + if (sdata->dev == local->mdev ||
18894 + sdata->type != IEEE80211_SUB_IF_TYPE_AP)
18895 + continue;
18896 + ap = &sdata->u.ap;
18897 + skb = skb_dequeue(&ap->ps_bc_buf);
18898 + if (skb) {
18899 + purged++;
18900 + dev_kfree_skb(skb);
18901 + }
18902 + total += skb_queue_len(&ap->ps_bc_buf);
18903 + }
18904 + spin_unlock_bh(&local->sub_if_lock);
18905 +
18906 + spin_lock_bh(&local->sta_lock);
18907 + list_for_each(ptr, &local->sta_list) {
18908 + struct sta_info *sta =
18909 + list_entry(ptr, struct sta_info, list);
18910 + skb = skb_dequeue(&sta->ps_tx_buf);
18911 + if (skb) {
18912 + purged++;
18913 + dev_kfree_skb(skb);
18914 + }
18915 + total += skb_queue_len(&sta->ps_tx_buf);
18916 + }
18917 + spin_unlock_bh(&local->sta_lock);
18918 +
18919 + local->total_ps_buffered = total;
18920 + printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
18921 + local->mdev->name, purged);
18922 +}
18923 +
18924 +
18925 +static inline ieee80211_txrx_result
18926 +ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
18927 +{
18928 + /* broadcast/multicast frame */
18929 + /* If any of the associated stations is in power save mode,
18930 + * the frame is buffered to be sent after DTIM beacon frame */
18931 + if (tx->local->hw->host_broadcast_ps_buffering &&
18932 + tx->sdata->type != IEEE80211_SUB_IF_TYPE_WDS &&
18933 + tx->sdata->bss && atomic_read(&tx->sdata->bss->num_sta_ps) &&
18934 + !(tx->fc & WLAN_FC_ORDER)) {
18935 + if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
18936 + purge_old_ps_buffers(tx->local);
18937 + if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
18938 + AP_MAX_BC_BUFFER) {
18939 + if (net_ratelimit()) {
18940 + printk(KERN_DEBUG "%s: BC TX buffer full - "
18941 + "dropping the oldest frame\n",
18942 + tx->dev->name);
18943 + }
18944 + dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
18945 + } else
18946 + tx->local->total_ps_buffered++;
18947 + skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
18948 + return TXRX_QUEUED;
18949 + }
18950 +
18951 + return TXRX_CONTINUE;
18952 +}
18953 +
18954 +
18955 +static inline ieee80211_txrx_result
18956 +ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
18957 +{
18958 + struct sta_info *sta = tx->sta;
18959 +
18960 + if (unlikely(!sta ||
18961 + (WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_MGMT &&
18962 + WLAN_FC_GET_STYPE(tx->fc) == WLAN_FC_STYPE_PROBE_RESP)))
18963 + return TXRX_CONTINUE;
18964 +
18965 + if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
18966 + struct ieee80211_tx_packet_data *pkt_data;
18967 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
18968 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS buffer (entries "
18969 + "before %d)\n",
18970 + MAC2STR(sta->addr), sta->aid,
18971 + skb_queue_len(&sta->ps_tx_buf));
18972 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
18973 + sta->flags |= WLAN_STA_TIM;
18974 + if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
18975 + purge_old_ps_buffers(tx->local);
18976 + if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
18977 + struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
18978 + if (net_ratelimit()) {
18979 + printk(KERN_DEBUG "%s: STA " MACSTR " TX "
18980 + "buffer full - dropping oldest frame\n",
18981 + tx->dev->name, MAC2STR(sta->addr));
18982 + }
18983 + dev_kfree_skb(old);
18984 + } else
18985 + tx->local->total_ps_buffered++;
18986 + /* Queue frame to be sent after STA sends an PS Poll frame */
18987 + if (skb_queue_empty(&sta->ps_tx_buf) && tx->local->hw->set_tim)
18988 + tx->local->hw->set_tim(tx->dev, sta->aid, 1);
18989 + pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
18990 + pkt_data->jiffies = jiffies;
18991 + skb_queue_tail(&sta->ps_tx_buf, tx->skb);
18992 + return TXRX_QUEUED;
18993 + }
18994 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
18995 + else if (unlikely(sta->flags & WLAN_STA_PS)) {
18996 + printk(KERN_DEBUG "%s: STA " MACSTR " in PS mode, but pspoll "
18997 + "set -> send frame\n", tx->dev->name,
18998 + MAC2STR(sta->addr));
18999 + }
19000 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
19001 + sta->pspoll = 0;
19002 +
19003 + return TXRX_CONTINUE;
19004 +}
19005 +
19006 +
19007 +static ieee80211_txrx_result
19008 +ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
19009 +{
19010 + if (unlikely(tx->u.tx.ps_buffered))
19011 + return TXRX_CONTINUE;
19012 +
19013 + if (tx->u.tx.unicast)
19014 + return ieee80211_tx_h_unicast_ps_buf(tx);
19015 + else
19016 + return ieee80211_tx_h_multicast_ps_buf(tx);
19017 +}
19018 +
19019 +
19020 +static void inline ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
19021 + struct sk_buff *skb,
19022 + struct net_device *dev,
19023 + struct ieee80211_tx_control *control)
19024 +{
19025 + struct ieee80211_local *local = dev->priv;
19026 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
19027 + struct ieee80211_tx_packet_data *pkt_data;
19028 + int hdrlen;
19029 +
19030 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19031 +
19032 + memset(tx, 0, sizeof(*tx));
19033 + tx->skb = skb;
19034 + tx->dev = pkt_data->sdata->dev; /* use original interface */
19035 + tx->local = local;
19036 + tx->sdata = pkt_data->sdata;
19037 + tx->sta = sta_info_get(local, hdr->addr1);
19038 + tx->fc = le16_to_cpu(hdr->frame_control);
19039 + control->power_level = local->conf.power_level;
19040 + tx->u.tx.control = control;
19041 + tx->u.tx.unicast = !MULTICAST_ADDR(hdr->addr1);
19042 + control->no_ack = MULTICAST_ADDR(hdr->addr1);
19043 + tx->fragmented = local->fragmentation_threshold <
19044 + IEEE80211_MAX_FRAG_THRESHOLD && tx->u.tx.unicast &&
19045 + skb->len + 4 /* FCS */ > local->fragmentation_threshold &&
19046 + (local->hw->set_frag_threshold == NULL);
19047 + if (tx->sta == NULL)
19048 + control->clear_dst_mask = 1;
19049 + else if (tx->sta->clear_dst_mask) {
19050 + control->clear_dst_mask = 1;
19051 + tx->sta->clear_dst_mask = 0;
19052 + }
19053 + control->antenna_sel = local->conf.antenna_sel;
19054 + if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
19055 + control->antenna_sel = tx->sta->antenna_sel;
19056 + hdrlen = ieee80211_get_hdrlen(tx->fc);
19057 + if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
19058 + u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
19059 + tx->ethertype = (pos[0] << 8) | pos[1];
19060 + }
19061 +
19062 +}
19063 +
19064 +
19065 +static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
19066 + struct ieee80211_tx_control *control, int mgmt)
19067 +{
19068 + struct ieee80211_local *local = dev->priv;
19069 + struct sta_info *sta;
19070 + ieee80211_tx_handler *handler;
19071 + struct ieee80211_txrx_data tx;
19072 + ieee80211_txrx_result res = TXRX_DROP;
19073 + int ret, i;
19074 +
19075 + if (unlikely(skb->len < 10)) {
19076 + dev_kfree_skb(skb);
19077 + return 0;
19078 + }
19079 +
19080 + ieee80211_tx_prepare(&tx, skb, dev, control);
19081 + sta = tx.sta;
19082 + tx.u.tx.mgmt_interface = mgmt;
19083 +
19084 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19085 + res = (*handler)(&tx);
19086 + if (res != TXRX_CONTINUE)
19087 + break;
19088 + }
19089 +
19090 + skb = tx.skb; /* handlers are allowed to change skb */
19091 +
19092 + if (sta)
19093 + sta_info_release(local, sta);
19094 +
19095 + if (unlikely(res == TXRX_DROP)) {
19096 + I802_DEBUG_INC(local->tx_handlers_drop);
19097 + goto drop;
19098 + }
19099 +
19100 + if (unlikely(res == TXRX_QUEUED)) {
19101 + I802_DEBUG_INC(local->tx_handlers_queued);
19102 + return 0;
19103 + }
19104 +
19105 + ieee80211_dump_frame(dev->name, "TX to low-level driver", skb);
19106 + ret = local->hw->tx(dev, skb, control);
19107 +#ifdef IEEE80211_LEDS
19108 + if (!ret && local->tx_led_counter++ == 0) {
19109 + ieee80211_tx_led(1, dev);
19110 + }
19111 +#endif /* IEEE80211_LEDS */
19112 + if (tx.u.tx.extra_frag) {
19113 + if (ret > 0) {
19114 + /* Must free all fragments and return 0 since skb data
19115 + * has been fragmented into multiple buffers.
19116 + * TODO: could free extra fragments and restore skb to
19117 + * the original form since the data is still there and
19118 + * then return nonzero so that Linux netif would
19119 + * retry. */
19120 + goto drop;
19121 + }
19122 +
19123 + skb = NULL; /* skb is now owned by low-level driver */
19124 + control->use_rts_cts = 0;
19125 + control->use_cts_protect = 0;
19126 + control->clear_dst_mask = 0;
19127 + for (i = 0; i < tx.u.tx.num_extra_frag; i++) {
19128 + int next_len, dur;
19129 + struct ieee80211_hdr *hdr =
19130 + (struct ieee80211_hdr *)
19131 + tx.u.tx.extra_frag[i]->data;
19132 + if (i + 1 < tx.u.tx.num_extra_frag)
19133 + next_len = tx.u.tx.extra_frag[i + 1]->len;
19134 + else {
19135 + next_len = 0;
19136 + tx.u.tx.rate = tx.u.tx.last_frag_rate;
19137 + tx.u.tx.control->tx_rate = tx.u.tx.rate->val;
19138 + tx.u.tx.control->rateidx =
19139 + tx.u.tx.last_frag_rateidx;
19140 + tx.u.tx.control->rate_ctrl_probe =
19141 + tx.u.tx.probe_last_frag;
19142 + }
19143 + dur = ieee80211_duration(&tx, 0, next_len);
19144 + hdr->duration_id = cpu_to_le16(dur);
19145 +
19146 + ieee80211_dump_frame(dev->name,
19147 + "TX to low-level driver", skb);
19148 + ret = local->hw->tx(dev, tx.u.tx.extra_frag[i],
19149 + control);
19150 + if (ret > 0)
19151 + goto drop;
19152 +#ifdef IEEE80211_LEDS
19153 + if (local->tx_led_counter++ == 0) {
19154 + ieee80211_tx_led(1, dev);
19155 + }
19156 +#endif /* IEEE80211_LEDS */
19157 + tx.u.tx.extra_frag[i] = NULL;
19158 + }
19159 + kfree(tx.u.tx.extra_frag);
19160 + }
19161 + if (ret == -1)
19162 + ret = 0;
19163 + return ret;
19164 +
19165 + drop:
19166 + if (skb)
19167 + dev_kfree_skb(skb);
19168 + for (i = 0; i < tx.u.tx.num_extra_frag; i++)
19169 + if (tx.u.tx.extra_frag[i])
19170 + dev_kfree_skb(tx.u.tx.extra_frag[i]);
19171 + kfree(tx.u.tx.extra_frag);
19172 + return 0;
19173 +}
19174 +
19175 +
19176 +static int ieee80211_master_start_xmit(struct sk_buff *skb,
19177 + struct net_device *dev)
19178 +{
19179 + struct ieee80211_tx_control control;
19180 + struct ieee80211_tx_packet_data *pkt_data;
19181 + struct ieee80211_sub_if_data *sdata;
19182 + int ret;
19183 +
19184 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19185 +
19186 + /*
19187 + * copy control out of the skb so other people can use skb->cb
19188 + */
19189 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19190 + memset(&control, 0, sizeof(struct ieee80211_tx_control));
19191 + control.sdata = pkt_data->sdata;
19192 + control.req_tx_status = pkt_data->req_tx_status;
19193 + control.do_not_encrypt = pkt_data->do_not_encrypt;
19194 + control.pkt_type =
19195 + pkt_data->pkt_probe_resp ? PKT_PROBE_RESP : PKT_NORMAL;
19196 + control.requeue = pkt_data->requeue;
19197 + control.queue = pkt_data->queue;
19198 +
19199 + ret = ieee80211_tx(dev, skb, &control,
19200 + control.sdata->type == IEEE80211_SUB_IF_TYPE_MGMT);
19201 +
19202 + return ret;
19203 +}
19204 +
19205 +
19206 +/**
19207 + * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
19208 + * subinterfaces (wlan#, WDS, and VLAN interfaces)
19209 + * @skb: packet to be sent
19210 + * @dev: incoming interface
19211 + *
19212 + * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
19213 + * not be freed, and caller is responsible for either retrying later or freeing
19214 + * skb).
19215 + *
19216 + * This function takes in an Ethernet header and encapsulates it with suitable
19217 + * IEEE 802.11 header based on which interface the packet is coming in. The
19218 + * encapsulated packet will then be passed to master interface, wlan#.11, for
19219 + * transmission (through low-level driver).
19220 + */
19221 +static int ieee80211_subif_start_xmit(struct sk_buff *skb,
19222 + struct net_device *dev)
19223 +{
19224 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
19225 + struct ieee80211_tx_packet_data *pkt_data;
19226 + struct ieee80211_sub_if_data *sdata;
19227 + int ret = 1, head_need;
19228 + u16 ethertype, hdrlen, fc;
19229 + struct ieee80211_hdr hdr;
19230 + u8 *encaps_data;
19231 + int encaps_len, skip_header_bytes;
19232 + int nh_pos, h_pos, no_encrypt = 0;
19233 + struct sta_info *sta;
19234 +
19235 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19236 + if (unlikely(skb->len < ETH_HLEN)) {
19237 + printk(KERN_DEBUG "%s: short skb (len=%d)\n",
19238 + dev->name, skb->len);
19239 + ret = 0;
19240 + goto fail;
19241 + }
19242 +
19243 + nh_pos = skb->nh.raw - skb->data;
19244 + h_pos = skb->h.raw - skb->data;
19245 +
19246 + /* convert Ethernet header to proper 802.11 header (based on
19247 + * operation mode) */
19248 + ethertype = (skb->data[12] << 8) | skb->data[13];
19249 + /* TODO: handling for 802.1x authorized/unauthorized port */
19250 + fc = (WLAN_FC_TYPE_DATA << 2) | (WLAN_FC_STYPE_DATA << 4);
19251 +
19252 + if (likely(sdata->type == IEEE80211_SUB_IF_TYPE_AP ||
19253 + sdata->type == IEEE80211_SUB_IF_TYPE_VLAN)) {
19254 + if (local->conf.mode == IW_MODE_MASTER) {
19255 + fc |= WLAN_FC_FROMDS;
19256 + /* DA BSSID SA */
19257 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19258 + memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
19259 + memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
19260 + } else if (local->conf.mode == IW_MODE_INFRA) {
19261 + fc |= WLAN_FC_TODS;
19262 + /* BSSID SA DA */
19263 + memcpy(hdr.addr1, local->bssid, ETH_ALEN);
19264 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19265 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19266 + } else if (local->conf.mode == IW_MODE_ADHOC) {
19267 + /* DA SA BSSID */
19268 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19269 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19270 + memcpy(hdr.addr3, local->bssid, ETH_ALEN);
19271 + }
19272 + hdrlen = 24;
19273 + } else if (sdata->type == IEEE80211_SUB_IF_TYPE_WDS) {
19274 + fc |= WLAN_FC_FROMDS | WLAN_FC_TODS;
19275 + /* RA TA DA SA */
19276 + memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
19277 + memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
19278 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19279 + memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
19280 + hdrlen = 30;
19281 + } else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
19282 + if (local->conf.mode == IW_MODE_INFRA) {
19283 + fc |= WLAN_FC_TODS;
19284 + /* BSSID SA DA */
19285 + memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
19286 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19287 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19288 + } else {
19289 + /* DA SA BSSID */
19290 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19291 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19292 + memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
19293 + }
19294 + hdrlen = 24;
19295 + } else {
19296 + ret = 0;
19297 + goto fail;
19298 + }
19299 +
19300 + /* receiver is QoS enabled, use a QoS type frame */
19301 + sta = sta_info_get(local, hdr.addr1);
19302 + if (sta) {
19303 + if (sta->flags & WLAN_STA_WME) {
19304 + fc |= WLAN_FC_STYPE_QOS_DATA << 4;
19305 + hdrlen += 2;
19306 + }
19307 + sta_info_release(local, sta);
19308 + }
19309 +
19310 + hdr.frame_control = cpu_to_le16(fc);
19311 + hdr.duration_id = 0;
19312 + hdr.seq_ctrl = 0;
19313 +
19314 + skip_header_bytes = ETH_HLEN;
19315 + if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
19316 + encaps_data = bridge_tunnel_header;
19317 + encaps_len = sizeof(bridge_tunnel_header);
19318 + skip_header_bytes -= 2;
19319 + } else if (ethertype >= 0x600) {
19320 + encaps_data = rfc1042_header;
19321 + encaps_len = sizeof(rfc1042_header);
19322 + skip_header_bytes -= 2;
19323 + } else {
19324 + encaps_data = NULL;
19325 + encaps_len = 0;
19326 + }
19327 +
19328 + skb_pull(skb, skip_header_bytes);
19329 + nh_pos -= skip_header_bytes;
19330 + h_pos -= skip_header_bytes;
19331 +
19332 + /* TODO: implement support for fragments so that there is no need to
19333 + * reallocate and copy payload; it might be enough to support one
19334 + * extra fragment that would be copied in the beginning of the frame
19335 + * data.. anyway, it would be nice to include this into skb structure
19336 + * somehow
19337 + *
19338 + * There are few options for this:
19339 + * use skb->cb as an extra space for 802.11 header
19340 + * allocate new buffer if not enough headroom
19341 + * make sure that there is enough headroom in every skb by increasing
19342 + * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
19343 + * alloc_skb() (net/core/skbuff.c)
19344 + */
19345 + head_need = hdrlen + encaps_len + (local->hw->extra_hdr_room ? 2 : 0);
19346 + head_need -= skb_headroom(skb);
19347 +
19348 + /* We are going to modify skb data, so make a copy of it if happens to
19349 + * be cloned. This could happen, e.g., with Linux bridge code passing
19350 + * us broadcast frames. */
19351 +
19352 + if (head_need > 0 || skb_cloned(skb)) {
19353 +#if 0
19354 + printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
19355 + "of headroom\n", dev->name, head_need);
19356 +#endif
19357 +
19358 + if (skb_cloned(skb))
19359 + I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
19360 + else
19361 + I802_DEBUG_INC(local->tx_expand_skb_head);
19362 + /* Since we have to reallocate the buffer, make sure that there
19363 + * is enough room for possible WEP IV/ICV and TKIP (8 bytes
19364 + * before payload and 12 after). */
19365 + if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8),
19366 + 12, GFP_ATOMIC)) {
19367 + printk(KERN_DEBUG "%s: failed to reallocate TX buffer"
19368 + "\n", dev->name);
19369 + goto fail;
19370 + }
19371 + }
19372 +
19373 + if (encaps_data) {
19374 + memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
19375 + nh_pos += encaps_len;
19376 + h_pos += encaps_len;
19377 + }
19378 + memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
19379 + nh_pos += hdrlen;
19380 + h_pos += hdrlen;
19381 +
19382 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19383 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
19384 + pkt_data->sdata = sdata;
19385 + pkt_data->do_not_encrypt = no_encrypt;
19386 +
19387 + skb->dev = sdata->master;
19388 + sdata->stats.tx_packets++;
19389 + sdata->stats.tx_bytes += skb->len;
19390 +
19391 + /* Update skb pointers to various headers since this modified frame
19392 + * is going to go through Linux networking code that may potentially
19393 + * need things like pointer to IP header. */
19394 + skb->mac.raw = skb->data;
19395 + skb->nh.raw = skb->data + nh_pos;
19396 + skb->h.raw = skb->data + h_pos;
19397 +
19398 + dev_queue_xmit(skb);
19399 +
19400 + return 0;
19401 +
19402 + fail:
19403 + if (!ret)
19404 + dev_kfree_skb(skb);
19405 +
19406 + return ret;
19407 +}
19408 +
19409 +
19410 +/*
19411 + * This is the transmit routine for the 802.11 type interfaces
19412 + * called by upper layers of the linux networking
19413 + * stack when it has a frame to transmit
19414 + */
19415 +static int
19416 +ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
19417 +{
19418 + struct ieee80211_sub_if_data *sdata;
19419 + struct ieee80211_tx_packet_data *pkt_data;
19420 + struct ieee80211_hdr *hdr;
19421 + u16 fc;
19422 +
19423 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19424 +
19425 + if (skb->len < 10) {
19426 + dev_kfree_skb(skb);
19427 + return 0;
19428 + }
19429 +
19430 + hdr = (struct ieee80211_hdr *) skb->data;
19431 + fc = le16_to_cpu(hdr->frame_control);
19432 +
19433 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
19434 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
19435 + pkt_data->sdata = sdata;
19436 +
19437 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
19438 + WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP)
19439 + pkt_data->pkt_probe_resp = 1;
19440 +
19441 + skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
19442 + skb->dev = sdata->master;
19443 +
19444 + /*
19445 + * We're using the protocol field of the the frame control header
19446 + * to request TX callback for hostapd. BIT(1) is checked.
19447 + */
19448 + if ((fc & BIT(1)) == BIT(1)) {
19449 + pkt_data->req_tx_status = 1;
19450 + fc &= ~BIT(1);
19451 + hdr->frame_control = cpu_to_le16(fc);
19452 + }
19453 +
19454 + pkt_data->do_not_encrypt = !(fc & WLAN_FC_ISWEP);
19455 +
19456 + sdata->stats.tx_packets++;
19457 + sdata->stats.tx_bytes += skb->len;
19458 +
19459 + dev_queue_xmit(skb);
19460 +
19461 + return 0;
19462 +}
19463 +
19464 +
19465 +static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
19466 + struct ieee80211_if_ap *bss,
19467 + struct sk_buff *skb)
19468 +{
19469 + u8 *pos, *tim;
19470 + int aid0 = 0;
19471 + int i, num_bits = 0, n1, n2;
19472 + u8 bitmap[251];
19473 +
19474 + /* Generate bitmap for TIM only if there are any STAs in power save
19475 + * mode. */
19476 + if (atomic_read(&bss->num_sta_ps) > 0 && bss->max_aid > 0) {
19477 + memset(bitmap, 0, sizeof(bitmap));
19478 + spin_lock_bh(&local->sta_lock);
19479 + for (i = 0; i < bss->max_aid; i++) {
19480 + if (bss->sta_aid[i] &&
19481 + (!skb_queue_empty(&bss->sta_aid[i]->ps_tx_buf) ||
19482 + !skb_queue_empty(&bss->sta_aid[i]->tx_filtered)))
19483 + {
19484 + bitmap[(i + 1) / 8] |= 1 << (i + 1) % 8;
19485 + num_bits++;
19486 + }
19487 + }
19488 + spin_unlock_bh(&local->sta_lock);
19489 + }
19490 +
19491 + if (bss->dtim_count == 0)
19492 + bss->dtim_count = bss->dtim_period - 1;
19493 + else
19494 + bss->dtim_count--;
19495 +
19496 + tim = pos = (u8 *) skb_put(skb, 6);
19497 + *pos++ = WLAN_EID_TIM;
19498 + *pos++ = 4;
19499 + *pos++ = bss->dtim_count;
19500 + *pos++ = bss->dtim_period;
19501 +
19502 + if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) {
19503 + aid0 = 1;
19504 + }
19505 +
19506 + if (num_bits) {
19507 + /* Find largest even number N1 so that bits numbered 1 through
19508 + * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
19509 + * (N2 + 1) x 8 through 2007 are 0. */
19510 + n1 = 0;
19511 + for (i = 0; i < sizeof(bitmap); i++) {
19512 + if (bitmap[i]) {
19513 + n1 = i & 0xfe;
19514 + break;
19515 + }
19516 + }
19517 + n2 = n1;
19518 + for (i = sizeof(bitmap) - 1; i >= n1; i--) {
19519 + if (bitmap[i]) {
19520 + n2 = i;
19521 + break;
19522 + }
19523 + }
19524 +
19525 + /* Bitmap control */
19526 + *pos++ = n1 | (aid0 ? 1 : 0);
19527 + /* Part Virt Bitmap */
19528 + memcpy(pos, bitmap + n1, n2 - n1 + 1);
19529 +
19530 + tim[1] = n2 - n1 + 4;
19531 + skb_put(skb, n2 - n1);
19532 + } else {
19533 + *pos++ = aid0 ? 1 : 0; /* Bitmap control */
19534 + *pos++ = 0; /* Part Virt Bitmap */
19535 + }
19536 +}
19537 +
19538 +
19539 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
19540 + struct ieee80211_tx_control *control)
19541 +{
19542 + struct ieee80211_local *local = dev->priv;
19543 + struct sk_buff *skb;
19544 + struct net_device *bdev;
19545 + struct ieee80211_sub_if_data *sdata = NULL;
19546 + struct ieee80211_if_ap *ap = NULL;
19547 + struct ieee80211_rate *rate;
19548 + struct rate_control_extra extra;
19549 + u8 *b_head, *b_tail;
19550 + int bh_len, bt_len;
19551 +
19552 + spin_lock_bh(&local->sub_if_lock);
19553 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count)
19554 + bdev = NULL;
19555 + else {
19556 + bdev = local->bss_devs[bss_idx];
19557 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19558 + ap = &sdata->u.ap;
19559 + }
19560 + spin_unlock_bh(&local->sub_if_lock);
19561 +
19562 + if (bdev == NULL || ap == NULL || ap->beacon_head == NULL) {
19563 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19564 + if (net_ratelimit())
19565 + printk(KERN_DEBUG "no beacon data avail for idx=%d "
19566 + "(%s)\n", bss_idx, bdev ? bdev->name : "N/A");
19567 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19568 + return NULL;
19569 + }
19570 +
19571 + /* Assume we are generating the normal beacon locally */
19572 + b_head = ap->beacon_head;
19573 + b_tail = ap->beacon_tail;
19574 + bh_len = ap->beacon_head_len;
19575 + bt_len = ap->beacon_tail_len;
19576 +
19577 + skb = dev_alloc_skb(bh_len + bt_len + 256 /* maximum TIM len */);
19578 + if (!skb)
19579 + return NULL;
19580 +
19581 + memcpy(skb_put(skb, bh_len), b_head, bh_len);
19582 +
19583 + ieee80211_beacon_add_tim(local, ap, skb);
19584 +
19585 + if (b_tail) {
19586 + memcpy(skb_put(skb, bt_len), b_tail, bt_len);
19587 + }
19588 +
19589 + memset(&extra, 0, sizeof(extra));
19590 + extra.endidx = local->num_curr_rates;
19591 +
19592 + rate = rate_control_get_rate(dev, skb, &extra);
19593 + if (rate == NULL) {
19594 + if (net_ratelimit()) {
19595 + printk(KERN_DEBUG "%s: ieee80211_beacon_get: no rate "
19596 + "found\n", dev->name);
19597 + }
19598 + dev_kfree_skb(skb);
19599 + return NULL;
19600 + }
19601 +
19602 + control->tx_rate = (local->short_preamble &&
19603 + (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
19604 + rate->val2 : rate->val;
19605 + control->antenna_sel = local->conf.antenna_sel;
19606 + control->power_level = local->conf.power_level;
19607 + control->no_ack = 1;
19608 + control->retry_limit = 1;
19609 + control->rts_cts_duration = 0;
19610 + control->clear_dst_mask = 1;
19611 +
19612 + ap->num_beacons++;
19613 + return skb;
19614 +}
19615 +
19616 +
19617 +struct sk_buff *
19618 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
19619 + struct ieee80211_tx_control *control)
19620 +{
19621 + struct ieee80211_local *local = dev->priv;
19622 + struct sk_buff *skb;
19623 + struct sta_info *sta;
19624 + ieee80211_tx_handler *handler;
19625 + struct ieee80211_txrx_data tx;
19626 + ieee80211_txrx_result res = TXRX_DROP;
19627 + struct net_device *bdev;
19628 + struct ieee80211_sub_if_data *sdata;
19629 + struct ieee80211_if_ap *bss;
19630 +
19631 + spin_lock_bh(&local->sub_if_lock);
19632 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count) {
19633 + bdev = NULL;
19634 + bss = NULL;
19635 + } else {
19636 + bdev = local->bss_devs[bss_idx];
19637 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19638 + bss = &sdata->u.ap;
19639 + }
19640 + spin_unlock_bh(&local->sub_if_lock);
19641 + if (bdev == NULL || bss == NULL || bss->beacon_head == NULL)
19642 + return NULL;
19643 +
19644 + if (bss->dtim_count != 0)
19645 + return NULL; /* send buffered bc/mc only after DTIM beacon */
19646 + skb = skb_dequeue(&bss->ps_bc_buf);
19647 + memset(control, 0, sizeof(*control));
19648 + if (skb == NULL)
19649 + return NULL;
19650 + local->total_ps_buffered--;
19651 +
19652 + if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
19653 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
19654 + /* more buffered multicast/broadcast frames ==> set MoreData
19655 + * flag in IEEE 802.11 header to inform PS STAs */
19656 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
19657 + }
19658 +
19659 + ieee80211_tx_prepare(&tx, skb, dev, control);
19660 + sta = tx.sta;
19661 + tx.u.tx.ps_buffered = 1;
19662 +
19663 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19664 + res = (*handler)(&tx);
19665 + if (res == TXRX_DROP || res == TXRX_QUEUED)
19666 + break;
19667 + }
19668 +
19669 + if (res == TXRX_DROP) {
19670 + I802_DEBUG_INC(local->tx_handlers_drop);
19671 + dev_kfree_skb(skb);
19672 + skb = NULL;
19673 + } else if (res == TXRX_QUEUED) {
19674 + I802_DEBUG_INC(local->tx_handlers_queued);
19675 + skb = NULL;
19676 + }
19677 +
19678 + if (sta)
19679 + sta_info_release(local, sta);
19680 +
19681 + return skb;
19682 +}
19683 +
19684 +
19685 +int ieee80211_hw_config(struct net_device *dev)
19686 +{
19687 + struct ieee80211_local *local = dev->priv;
19688 + int i, ret = 0;
19689 +
19690 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19691 + printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d mode=%d "
19692 + "phymode=%d\n", local->conf.channel, local->conf.freq,
19693 + local->conf.mode, local->conf.phymode);
19694 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19695 +
19696 + if (local->hw->config)
19697 + ret = local->hw->config(dev, &local->conf);
19698 +
19699 + for (i = 0; i < local->hw->num_modes; i++) {
19700 + struct ieee80211_hw_modes *mode = &local->hw->modes[i];
19701 + if (mode->mode == local->conf.phymode) {
19702 + if (local->curr_rates != mode->rates) {
19703 + rate_control_clear(local);
19704 + }
19705 + local->curr_rates = mode->rates;
19706 + local->num_curr_rates = mode->num_rates;
19707 + ieee80211_prepare_rates(dev);
19708 + break;
19709 + }
19710 + }
19711 +
19712 + return ret;
19713 +}
19714 +
19715 +
19716 +struct ieee80211_conf *ieee80211_get_hw_conf(struct net_device *dev)
19717 +{
19718 + struct ieee80211_local *local = dev->priv;
19719 + return &local->conf;
19720 +}
19721 +
19722 +
19723 +static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
19724 +{
19725 + /* FIX: what would be proper limits for MTU?
19726 + * This interface uses 802.3 frames. */
19727 + if (new_mtu < 256 || new_mtu > 2304 - 24 - 6) {
19728 + printk(KERN_WARNING "%s: invalid MTU %d\n",
19729 + dev->name, new_mtu);
19730 + return -EINVAL;
19731 + }
19732 +
19733 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19734 + printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
19735 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19736 + dev->mtu = new_mtu;
19737 + return 0;
19738 +}
19739 +
19740 +
19741 +static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
19742 +{
19743 + /* FIX: what would be proper limits for MTU?
19744 + * This interface uses 802.11 frames. */
19745 + if (new_mtu < 256 || new_mtu > 2304) {
19746 + printk(KERN_WARNING "%s: invalid MTU %d\n",
19747 + dev->name, new_mtu);
19748 + return -EINVAL;
19749 + }
19750 +
19751 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19752 + printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
19753 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19754 + dev->mtu = new_mtu;
19755 + return 0;
19756 +}
19757 +
19758 +
19759 +static void ieee80211_tx_timeout(struct net_device *dev)
19760 +{
19761 + struct ieee80211_local *local = dev->priv;
19762 +
19763 + printk(KERN_WARNING "%s: resetting interface.\n", dev->name);
19764 +
19765 + if (local->hw->reset(dev))
19766 + printk(KERN_ERR "%s: failed to reset interface.\n", dev->name);
19767 + else
19768 + netif_wake_queue(dev);
19769 +}
19770 +
19771 +
19772 +static int ieee80211_set_mac_address(struct net_device *dev, void *addr)
19773 +{
19774 + struct ieee80211_local *local = dev->priv;
19775 + struct sockaddr *a = addr;
19776 + struct list_head *ptr;
19777 + int res;
19778 +
19779 + if (!local->hw->set_mac_address)
19780 + return -EOPNOTSUPP;
19781 +
19782 + res = local->hw->set_mac_address(dev, addr);
19783 + if (res)
19784 + return res;
19785 +
19786 + list_for_each(ptr, &local->sub_if_list) {
19787 + struct ieee80211_sub_if_data *sdata =
19788 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19789 + memcpy(sdata->dev->dev_addr, a->sa_data, ETH_ALEN);
19790 + }
19791 +
19792 + return 0;
19793 +}
19794 +
19795 +
19796 +static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
19797 +{
19798 + struct ieee80211_sub_if_data *sdata;
19799 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19800 + return &(sdata->stats);
19801 +}
19802 +
19803 +
19804 +static int ieee80211_open(struct net_device *dev)
19805 +{
19806 + struct ieee80211_sub_if_data *sdata;
19807 + struct ieee80211_local *local = dev->priv;
19808 + int res;
19809 +
19810 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19811 +
19812 + if (local->open_count == 0) {
19813 + res = local->hw->open(sdata->master);
19814 + if (res)
19815 + return res;
19816 + ieee80211_init_scan(sdata->master);
19817 + }
19818 + local->open_count++;
19819 +
19820 + netif_start_queue(dev);
19821 + return 0;
19822 +}
19823 +
19824 +
19825 +static int ieee80211_stop(struct net_device *dev)
19826 +{
19827 + struct ieee80211_sub_if_data *sdata;
19828 + struct ieee80211_local *local = dev->priv;
19829 + int res;
19830 +
19831 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19832 +
19833 + netif_stop_queue(dev);
19834 +
19835 + local->open_count--;
19836 + if (local->open_count == 0) {
19837 + ieee80211_stop_scan(sdata->master);
19838 + res = local->hw->stop(sdata->master);
19839 + if (res)
19840 + return res;
19841 + }
19842 +
19843 + return 0;
19844 +}
19845 +
19846 +
19847 +static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
19848 +{
19849 + memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
19850 + return ETH_ALEN;
19851 +}
19852 +
19853 +
19854 +static struct net_device *
19855 +ieee80211_get_wds_dev(struct ieee80211_local *local, u8 *addr)
19856 +{
19857 + struct list_head *ptr;
19858 +
19859 + list_for_each(ptr, &local->sub_if_list) {
19860 + struct ieee80211_sub_if_data *sdata =
19861 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19862 + if (sdata->type == IEEE80211_SUB_IF_TYPE_WDS &&
19863 + memcmp(addr, sdata->u.wds.remote_addr, ETH_ALEN) == 0)
19864 + return sdata->dev;
19865 + }
19866 +
19867 + return NULL;
19868 +}
19869 +
19870 +
19871 +static struct net_device * ieee80211_own_bssid(struct ieee80211_local *local,
19872 + u8 *addr)
19873 +{
19874 + int i;
19875 + struct net_device *dev = NULL;
19876 +
19877 + spin_lock_bh(&local->sub_if_lock);
19878 + for (i = 0; i < local->bss_dev_count; i++) {
19879 + if ((memcmp(local->bss_devs[i]->dev_addr, addr, ETH_ALEN) == 0)
19880 + ) {
19881 + dev = local->bss_devs[i];
19882 + break;
19883 + }
19884 + }
19885 + spin_unlock_bh(&local->sub_if_lock);
19886 +
19887 + return dev;
19888 +}
19889 +
19890 +
19891 +static struct net_device * ieee80211_sta_bssid(struct ieee80211_local *local,
19892 + u8 *addr, u8 *a1,
19893 + int *sta_multicast)
19894 +{
19895 + struct list_head *ptr;
19896 + int multicast;
19897 + u8 *own_addr = local->mdev->dev_addr;
19898 +
19899 + multicast = a1[0] & 0x01;
19900 +
19901 + /* Try O(1) lookup for a common case of only one AP being used. */
19902 + if (own_addr[0] == a1[0] && own_addr[1] == a1[1] &&
19903 + own_addr[2] == a1[2]) {
19904 + int index = (((int) a1[3] << 16) | ((int) a1[4] << 8) | a1[5])
19905 + - (((int) own_addr[3] << 16) |
19906 + ((int) own_addr[4] << 8) | own_addr[5]);
19907 + if (index >= 0 && index < local->conf.bss_count &&
19908 + local->sta_devs[index]) {
19909 + struct net_device *dev = local->sta_devs[index];
19910 + struct ieee80211_sub_if_data *sdata;
19911 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19912 + if (memcmp(addr, sdata->u.sta.bssid, ETH_ALEN) == 0) {
19913 + *sta_multicast = multicast;
19914 + return dev;
19915 + }
19916 + }
19917 + }
19918 +
19919 + if (!multicast)
19920 + return NULL;
19921 +
19922 + /* Could not find station interface, resort to O(n) lookup. */
19923 + list_for_each(ptr, &local->sub_if_list) {
19924 + struct ieee80211_sub_if_data *sdata =
19925 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19926 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
19927 + continue;
19928 + if (!multicast &&
19929 + memcmp(a1, sdata->dev->dev_addr, ETH_ALEN) != 0)
19930 + continue;
19931 +
19932 + if (memcmp(addr, sdata->u.sta.bssid, ETH_ALEN) == 0 ||
19933 + (memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0 &&
19934 + local->conf.mode == IW_MODE_ADHOC)) {
19935 + *sta_multicast = multicast;
19936 + return sdata->dev;
19937 + }
19938 + }
19939 +
19940 + return NULL;
19941 +}
19942 +
19943 +
19944 +static int ieee80211_own_addr(struct net_device *dev, u8 *addr)
19945 +{
19946 + struct ieee80211_local *local = dev->priv;
19947 + u8 *own = dev->dev_addr;
19948 + int index;
19949 +
19950 + /* Optimization: assume that BSSID mask does not change for first
19951 + * three octets. */
19952 + if (own[0] != addr[0] || own[1] != addr[1] || own[2] != addr[2])
19953 + return 0;
19954 +
19955 + index = (((int) addr[3] << 16) | ((int) addr[4] << 8) | addr[5]) -
19956 + (((int) own[3] << 16) | ((int) own[4] << 8) | own[5]);
19957 + if (index >= 0 && index < local->conf.bss_count &&
19958 + local->sta_devs[index])
19959 + return 1;
19960 +
19961 + return 0;
19962 +}
19963 +
19964 +
19965 +static ieee80211_txrx_result
19966 +ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
19967 +{
19968 + struct net_device *dev = rx->dev;
19969 + struct ieee80211_local *local = rx->local;
19970 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
19971 + u16 fc, hdrlen, ethertype;
19972 + u8 *payload;
19973 + u8 dst[ETH_ALEN];
19974 + u8 src[ETH_ALEN];
19975 + struct sk_buff *skb = rx->skb, *skb2;
19976 + struct ieee80211_sub_if_data *sdata;
19977 +
19978 + fc = rx->fc;
19979 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA))
19980 + return TXRX_CONTINUE;
19981 +
19982 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
19983 + return TXRX_DROP;
19984 +
19985 + hdrlen = ieee80211_get_hdrlen(fc);
19986 +
19987 + /* convert IEEE 802.11 header + possible LLC headers into Ethernet
19988 + * header
19989 + * IEEE 802.11 address fields:
19990 + * ToDS FromDS Addr1 Addr2 Addr3 Addr4
19991 + * 0 0 DA SA BSSID n/a
19992 + * 0 1 DA BSSID SA n/a
19993 + * 1 0 BSSID SA DA n/a
19994 + * 1 1 RA TA DA SA
19995 + */
19996 +
19997 + switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
19998 + case WLAN_FC_TODS:
19999 + /* BSSID SA DA */
20000 + memcpy(dst, hdr->addr3, ETH_ALEN);
20001 + memcpy(src, hdr->addr2, ETH_ALEN);
20002 +
20003 + if (unlikely(local->conf.mode != IW_MODE_MASTER ||
20004 + !ieee80211_own_bssid(local, hdr->addr1))) {
20005 + printk(KERN_DEBUG "%s: dropped ToDS frame (BSSID="
20006 + MACSTR " SA=" MACSTR " DA=" MACSTR ")\n",
20007 + dev->name, MAC2STR(hdr->addr1),
20008 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3));
20009 + return TXRX_DROP;
20010 + }
20011 + break;
20012 + case (WLAN_FC_TODS | WLAN_FC_FROMDS):
20013 + /* RA TA DA SA */
20014 + memcpy(dst, hdr->addr3, ETH_ALEN);
20015 + memcpy(src, hdr->addr4, ETH_ALEN);
20016 +
20017 + dev = ieee80211_get_wds_dev(local, hdr->addr2);
20018 + if (!dev || memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) != 0) {
20019 + printk(KERN_DEBUG "%s: dropped FromDS&ToDS frame (RA="
20020 + MACSTR " TA=" MACSTR " DA=" MACSTR " SA="
20021 + MACSTR ")\n",
20022 + rx->dev->name, MAC2STR(hdr->addr1),
20023 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3),
20024 + MAC2STR(hdr->addr4));
20025 + return TXRX_DROP;
20026 + }
20027 + break;
20028 + case WLAN_FC_FROMDS:
20029 + /* DA BSSID SA */
20030 + memcpy(dst, hdr->addr1, ETH_ALEN);
20031 + memcpy(src, hdr->addr3, ETH_ALEN);
20032 +
20033 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20034 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA ||
20035 + memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0 ||
20036 + memcmp(hdr->addr2, sdata->u.sta.bssid, ETH_ALEN) != 0) {
20037 + return TXRX_DROP;
20038 + }
20039 + break;
20040 + case 0:
20041 + /* DA SA BSSID */
20042 + memcpy(dst, hdr->addr1, ETH_ALEN);
20043 + memcpy(src, hdr->addr2, ETH_ALEN);
20044 +
20045 + if (local->conf.mode != IW_MODE_ADHOC ||
20046 + memcmp(hdr->addr3, local->bssid, ETH_ALEN) != 0) {
20047 + if (net_ratelimit()) {
20048 + printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
20049 + MACSTR " SA=" MACSTR " BSSID=" MACSTR
20050 + ")\n",
20051 + dev->name, MAC2STR(hdr->addr1),
20052 + MAC2STR(hdr->addr2),
20053 + MAC2STR(hdr->addr3));
20054 + }
20055 + return TXRX_DROP;
20056 + }
20057 + break;
20058 + }
20059 +
20060 + payload = skb->data + hdrlen;
20061 +
20062 + if (unlikely(skb->len - hdrlen < 8)) {
20063 + if (net_ratelimit()) {
20064 + printk(KERN_DEBUG "%s: RX too short data frame "
20065 + "payload\n", dev->name);
20066 + }
20067 + return TXRX_DROP;
20068 + }
20069 +
20070 + ethertype = (payload[6] << 8) | payload[7];
20071 +
20072 + if (likely((memcmp(payload, rfc1042_header, 6) == 0 &&
20073 + ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
20074 + memcmp(payload, bridge_tunnel_header, 6) == 0)) {
20075 + /* remove RFC1042 or Bridge-Tunnel encapsulation and
20076 + * replace EtherType */
20077 + skb_pull(skb, hdrlen + 6);
20078 + memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
20079 + memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
20080 + } else {
20081 + struct ethhdr *ehdr;
20082 + unsigned short len;
20083 + skb_pull(skb, hdrlen);
20084 + len = htons(skb->len);
20085 + ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
20086 + memcpy(ehdr->h_dest, dst, ETH_ALEN);
20087 + memcpy(ehdr->h_source, src, ETH_ALEN);
20088 + ehdr->h_proto = len;
20089 + }
20090 +
20091 + if (rx->sta && !rx->sta->assoc_ap &&
20092 + !(rx->sta && (rx->sta->flags & WLAN_STA_WDS)))
20093 + skb->dev = rx->sta->dev;
20094 + else
20095 + skb->dev = dev;
20096 +
20097 + skb2 = NULL;
20098 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20099 +
20100 + /*
20101 + * don't count the master since the low level code
20102 + * counts it already for us.
20103 + */
20104 + if (skb->dev != sdata->master) {
20105 + sdata->stats.rx_packets++;
20106 + sdata->stats.rx_bytes += skb->len;
20107 + }
20108 +
20109 + if (local->bridge_packets && sdata->type != IEEE80211_SUB_IF_TYPE_WDS
20110 + && sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
20111 + if (MULTICAST_ADDR(skb->data)) {
20112 + /* send multicast frames both to higher layers in
20113 + * local net stack and back to the wireless media */
20114 + skb2 = skb_copy(skb, GFP_ATOMIC);
20115 + if (skb2 == NULL)
20116 + printk(KERN_DEBUG "%s: failed to clone "
20117 + "multicast frame\n", dev->name);
20118 + } else {
20119 + struct sta_info *dsta;
20120 + dsta = sta_info_get(local, skb->data);
20121 + if (dsta && dsta->dev == NULL) {
20122 + printk(KERN_DEBUG "Station with null dev "
20123 + "structure!\n");
20124 + } else if (dsta && dsta->dev == dev) {
20125 + /* Destination station is associated to this
20126 + * AP, so send the frame directly to it and
20127 + * do not pass the frame to local net stack.
20128 + */
20129 + skb2 = skb;
20130 + skb = NULL;
20131 + }
20132 + if (dsta)
20133 + sta_info_release(local, dsta);
20134 + }
20135 + }
20136 +
20137 + if (skb) {
20138 + /* deliver to local stack */
20139 + skb->protocol = eth_type_trans(skb, dev);
20140 + memset(skb->cb, 0, sizeof(skb->cb));
20141 + netif_rx(skb);
20142 + }
20143 +
20144 + if (skb2) {
20145 + /* send to wireless media */
20146 + skb2->protocol = __constant_htons(ETH_P_802_3);
20147 + skb2->mac.raw = skb2->nh.raw = skb2->data;
20148 + dev_queue_xmit(skb2);
20149 + }
20150 +
20151 + return TXRX_QUEUED;
20152 +}
20153 +
20154 +
20155 +static struct ieee80211_rate *
20156 +ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
20157 +{
20158 + int m, r;
20159 +
20160 + for (m = 0; m < local->hw->num_modes; m++) {
20161 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
20162 + if (mode->mode != phymode)
20163 + continue;
20164 + for (r = 0; r < mode->num_rates; r++) {
20165 + struct ieee80211_rate *rate = &mode->rates[r];
20166 + if (rate->val == hw_rate ||
20167 + (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
20168 + rate->val2 == hw_rate))
20169 + return rate;
20170 + }
20171 + }
20172 +
20173 + return NULL;
20174 +}
20175 +
20176 +
20177 +void
20178 +ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
20179 + struct ieee80211_rx_status *status, u32 msg_type)
20180 +{
20181 + struct ieee80211_local *local = dev->priv;
20182 + struct ieee80211_frame_info *fi;
20183 + size_t hlen;
20184 + struct ieee80211_sub_if_data *sdata;
20185 +
20186 + dev = local->apdev;
20187 + skb->dev = dev;
20188 +
20189 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20190 +
20191 + if (skb_headroom(skb) < sizeof(struct ieee80211_frame_info)) {
20192 + I802_DEBUG_INC(local->rx_expand_skb_head);
20193 + if (pskb_expand_head(skb, sizeof(struct ieee80211_frame_info),
20194 + 0, GFP_ATOMIC)) {
20195 + dev_kfree_skb(skb);
20196 + return;
20197 + }
20198 + }
20199 +
20200 + hlen = sizeof(struct ieee80211_frame_info);
20201 + if (msg_type == ieee80211_msg_monitor)
20202 + hlen -= sizeof(fi->msg_type);
20203 +
20204 + fi = (struct ieee80211_frame_info *) skb_push(skb, hlen);
20205 + memset(fi, 0, hlen);
20206 + if (msg_type != ieee80211_msg_monitor)
20207 + fi->msg_type = htonl(msg_type);
20208 + fi->version = htonl(IEEE80211_FI_VERSION);
20209 + fi->length = htonl(hlen);
20210 + if (status) {
20211 + struct timespec ts;
20212 + struct ieee80211_rate *rate;
20213 +
20214 + jiffies_to_timespec(status->hosttime, &ts);
20215 + fi->hosttime = cpu_to_be64(ts.tv_sec * 1000000 +
20216 + ts.tv_nsec / 1000);
20217 + fi->mactime = cpu_to_be64(status->mactime);
20218 + switch (status->phymode) {
20219 + case MODE_IEEE80211A:
20220 + fi->phytype = htonl(ieee80211_phytype_ofdm_dot11_a);
20221 + break;
20222 + case MODE_IEEE80211B:
20223 + fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
20224 + break;
20225 + case MODE_IEEE80211G:
20226 + fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
20227 + break;
20228 + case MODE_ATHEROS_TURBO:
20229 + fi->phytype =
20230 + htonl(ieee80211_phytype_dsss_dot11_turbo);
20231 + break;
20232 + default:
20233 + fi->phytype = 0xAAAAAAAA;
20234 + break;
20235 + }
20236 + fi->channel = htonl(status->channel);
20237 + rate = ieee80211_get_rate(local, status->phymode,
20238 + status->rate);
20239 + if (rate) {
20240 + fi->datarate = htonl(rate->rate);
20241 + if (rate->flags & IEEE80211_RATE_PREAMBLE2) {
20242 + if (status->rate == rate->val)
20243 + fi->preamble = htonl(2); /* long */
20244 + else if (status->rate == rate->val2)
20245 + fi->preamble = htonl(1); /* short */
20246 + } else
20247 + fi->preamble = htonl(0);
20248 + } else {
20249 + fi->datarate = htonl(0);
20250 + fi->preamble = htonl(0);
20251 + }
20252 +
20253 + fi->antenna = htonl(status->antenna);
20254 + fi->priority = 0xffffffff; /* no clue */
20255 + fi->ssi_type = htonl(ieee80211_ssi_raw);
20256 + fi->ssi_signal = htonl(status->ssi);
20257 + fi->ssi_noise = 0x00000000;
20258 + fi->encoding = 0;
20259 + } else {
20260 + fi->ssi_type = htonl(ieee80211_ssi_none);
20261 + }
20262 +
20263 + sdata->stats.rx_packets++;
20264 + sdata->stats.rx_bytes += skb->len;
20265 +
20266 + skb->mac.raw = skb->data;
20267 + skb->ip_summed = CHECKSUM_UNNECESSARY;
20268 + skb->pkt_type = PACKET_OTHERHOST;
20269 + skb->protocol = __constant_htons(ETH_P_802_2);
20270 + memset(skb->cb, 0, sizeof(skb->cb));
20271 + netif_rx(skb);
20272 +}
20273 +
20274 +
20275 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
20276 + int radar_type)
20277 +{
20278 + struct sk_buff *skb;
20279 + struct ieee80211_radar_info *msg;
20280 +
20281 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20282 + sizeof(struct ieee80211_radar_info));
20283 +
20284 + if (skb == NULL)
20285 + return -ENOMEM;
20286 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20287 +
20288 + msg = (struct ieee80211_radar_info *)
20289 + skb_put(skb, sizeof(struct ieee80211_radar_info));
20290 + msg->channel = channel;
20291 + msg->radar = radar;
20292 + msg->radar_type = radar_type;
20293 +
20294 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_radar);
20295 + return 0;
20296 +}
20297 +
20298 +
20299 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
20300 + u16 aid)
20301 +{
20302 + struct sk_buff *skb;
20303 + struct ieee80211_msg_set_aid_for_sta *msg;
20304 +
20305 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20306 + sizeof(struct ieee80211_msg_set_aid_for_sta));
20307 +
20308 + if (skb == NULL)
20309 + return -ENOMEM;
20310 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20311 +
20312 + msg = (struct ieee80211_msg_set_aid_for_sta *)
20313 + skb_put(skb, sizeof(struct ieee80211_msg_set_aid_for_sta));
20314 + memcpy(msg->sta_address, peer_address, ETH_ALEN);
20315 + msg->aid = aid;
20316 +
20317 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_set_aid_for_sta);
20318 + return 0;
20319 +}
20320 +
20321 +
20322 +static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
20323 +{
20324 + struct ieee80211_sub_if_data *sdata;
20325 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20326 +
20327 + if (sdata->bss)
20328 + atomic_inc(&sdata->bss->num_sta_ps);
20329 + sta->flags |= WLAN_STA_PS;
20330 + sta->pspoll = 0;
20331 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20332 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d enters power "
20333 + "save mode\n", dev->name, MAC2STR(sta->addr), sta->aid);
20334 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20335 +}
20336 +
20337 +
20338 +static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
20339 +{
20340 + struct ieee80211_local *local = dev->priv;
20341 + struct sk_buff *skb;
20342 + int sent = 0;
20343 + struct ieee80211_sub_if_data *sdata;
20344 + struct ieee80211_tx_packet_data *pkt_data;
20345 +
20346 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20347 + if (sdata->bss)
20348 + atomic_dec(&sdata->bss->num_sta_ps);
20349 + sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
20350 + sta->pspoll = 0;
20351 + if (!skb_queue_empty(&sta->ps_tx_buf) && local->hw->set_tim)
20352 + local->hw->set_tim(dev, sta->aid, 0);
20353 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20354 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d exits power "
20355 + "save mode\n", dev->name, MAC2STR(sta->addr), sta->aid);
20356 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20357 + /* Send all buffered frames to the station */
20358 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
20359 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
20360 + sent++;
20361 + pkt_data->requeue = 1;
20362 + dev_queue_xmit(skb);
20363 + }
20364 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
20365 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
20366 + local->total_ps_buffered--;
20367 + sent++;
20368 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20369 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d send PS frame "
20370 + "since STA not sleeping anymore\n", dev->name,
20371 + MAC2STR(sta->addr), sta->aid);
20372 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20373 + pkt_data->requeue = 1;
20374 + dev_queue_xmit(skb);
20375 + }
20376 +
20377 + return sent;
20378 +}
20379 +
20380 +
20381 +static ieee80211_txrx_result
20382 +ieee80211_rx_h_ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
20383 +{
20384 + struct sk_buff *skb;
20385 + int no_pending_pkts;
20386 +
20387 + if (likely(!rx->sta || WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_CTRL ||
20388 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_PSPOLL))
20389 + return TXRX_CONTINUE;
20390 +
20391 + skb = skb_dequeue(&rx->sta->tx_filtered);
20392 + if (skb == NULL) {
20393 + skb = skb_dequeue(&rx->sta->ps_tx_buf);
20394 + if (skb)
20395 + rx->local->total_ps_buffered--;
20396 + }
20397 + no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
20398 + skb_queue_empty(&rx->sta->ps_tx_buf);
20399 +
20400 + if (skb) {
20401 + struct ieee80211_hdr *hdr =
20402 + (struct ieee80211_hdr *) skb->data;
20403 +
20404 + /* tell TX path to send one frame even though the STA may
20405 + * still remain is PS mode after this frame exchange */
20406 + rx->sta->pspoll = 1;
20407 +
20408 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20409 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS Poll (entries "
20410 + "after %d)\n",
20411 + MAC2STR(rx->sta->addr), rx->sta->aid,
20412 + skb_queue_len(&rx->sta->ps_tx_buf));
20413 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20414 +
20415 + /* Use MoreData flag to indicate whether there are more
20416 + * buffered frames for this STA */
20417 + if (no_pending_pkts) {
20418 + hdr->frame_control &= cpu_to_le16(~WLAN_FC_MOREDATA);
20419 + rx->sta->flags &= ~WLAN_STA_TIM;
20420 + } else
20421 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
20422 +
20423 + dev_queue_xmit(skb);
20424 +
20425 + if (no_pending_pkts && rx->local->hw->set_tim)
20426 + rx->local->hw->set_tim(rx->dev, rx->sta->aid, 0);
20427 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20428 + } else if (!rx->u.rx.sent_ps_buffered) {
20429 + printk(KERN_DEBUG "%s: STA " MACSTR " sent PS Poll even "
20430 + "though there is no buffered frames for it\n",
20431 + rx->dev->name, MAC2STR(rx->sta->addr));
20432 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20433 +
20434 + }
20435 +
20436 + /* Free PS Poll skb here instead of returning TXRX_DROP that would
20437 + * count as an dropped frame. */
20438 + dev_kfree_skb(rx->skb);
20439 +
20440 + return TXRX_QUEUED;
20441 +}
20442 +
20443 +
20444 +static inline struct ieee80211_fragment_entry *
20445 +ieee80211_reassemble_add(struct ieee80211_local *local,
20446 + unsigned int frag, unsigned int seq, int rx_queue,
20447 + struct sk_buff **skb)
20448 +{
20449 + struct ieee80211_fragment_entry *entry;
20450 + int idx;
20451 +
20452 + idx = local->fragment_next;
20453 + entry = &local->fragments[local->fragment_next++];
20454 + if (local->fragment_next >= IEEE80211_FRAGMENT_MAX)
20455 + local->fragment_next = 0;
20456 +
20457 + if (entry->skb) {
20458 +#ifdef CONFIG_D80211_DEBUG
20459 + struct ieee80211_hdr *hdr =
20460 + (struct ieee80211_hdr *) entry->skb->data;
20461 + printk(KERN_DEBUG "%s: RX reassembly removed oldest "
20462 + "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
20463 + "addr1=" MACSTR " addr2=" MACSTR "\n",
20464 + local->mdev->name, idx,
20465 + jiffies - entry->first_frag_time, entry->seq,
20466 + entry->last_frag, MAC2STR(hdr->addr1),
20467 + MAC2STR(hdr->addr2));
20468 +#endif /* CONFIG_D80211_DEBUG */
20469 + dev_kfree_skb(entry->skb);
20470 + }
20471 +
20472 + entry->skb = *skb;
20473 + *skb = NULL;
20474 + entry->first_frag_time = jiffies;
20475 + entry->seq = seq;
20476 + entry->rx_queue = rx_queue;
20477 + entry->last_frag = frag;
20478 + entry->ccmp = 0;
20479 +
20480 + return entry;
20481 +}
20482 +
20483 +
20484 +static inline struct ieee80211_fragment_entry *
20485 +ieee80211_reassemble_find(struct ieee80211_local *local,
20486 + u16 fc, unsigned int frag, unsigned int seq,
20487 + int rx_queue, struct ieee80211_hdr *hdr)
20488 +{
20489 + struct ieee80211_fragment_entry *entry;
20490 + int i, idx;
20491 +
20492 + idx = local->fragment_next;
20493 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
20494 + struct ieee80211_hdr *f_hdr;
20495 + u16 f_fc;
20496 +
20497 + idx--;
20498 + if (idx < 0)
20499 + idx = IEEE80211_FRAGMENT_MAX - 1;
20500 +
20501 + entry = &local->fragments[idx];
20502 + if (!entry->skb || entry->seq != seq ||
20503 + entry->rx_queue != rx_queue ||
20504 + entry->last_frag + 1 != frag)
20505 + continue;
20506 +
20507 + f_hdr = (struct ieee80211_hdr *) entry->skb->data;
20508 + f_fc = le16_to_cpu(f_hdr->frame_control);
20509 +
20510 + if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_GET_TYPE(f_fc) ||
20511 + memcmp(hdr->addr1, f_hdr->addr1, ETH_ALEN) != 0 ||
20512 + memcmp(hdr->addr2, f_hdr->addr2, ETH_ALEN) != 0)
20513 + continue;
20514 +
20515 + if (entry->first_frag_time + 2 * HZ < jiffies) {
20516 + dev_kfree_skb(entry->skb);
20517 + entry->skb = NULL;
20518 + continue;
20519 + }
20520 + return entry;
20521 + }
20522 +
20523 + return NULL;
20524 +}
20525 +
20526 +
20527 +static ieee80211_txrx_result
20528 +ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
20529 +{
20530 + struct ieee80211_hdr *hdr;
20531 + u16 sc;
20532 + unsigned int frag, seq;
20533 + struct ieee80211_fragment_entry *entry;
20534 +
20535 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20536 + sc = le16_to_cpu(hdr->seq_ctrl);
20537 + frag = WLAN_GET_SEQ_FRAG(sc);
20538 +
20539 + if (likely((!(rx->fc & WLAN_FC_MOREFRAG) && frag == 0) ||
20540 + (rx->skb)->len < 24 || MULTICAST_ADDR(hdr->addr1))) {
20541 + /* not fragmented */
20542 + goto out;
20543 + }
20544 + I802_DEBUG_INC(rx->local->rx_handlers_fragments);
20545 +
20546 + seq = WLAN_GET_SEQ_SEQ(sc);
20547 +
20548 + if (frag == 0) {
20549 + /* This is the first fragment of a new frame. */
20550 + entry = ieee80211_reassemble_add(rx->local, frag, seq,
20551 + rx->u.rx.queue, &(rx->skb));
20552 + if (rx->key && rx->key->alg == ALG_CCMP &&
20553 + (rx->fc & WLAN_FC_ISWEP)) {
20554 + /* Store CCMP PN so that we can verify that the next
20555 + * fragment has a sequential PN value. */
20556 + entry->ccmp = 1;
20557 + memcpy(entry->last_pn,
20558 + rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
20559 + CCMP_PN_LEN);
20560 + }
20561 + return TXRX_QUEUED;
20562 + }
20563 +
20564 + /* This is a fragment for a frame that should already be pending in
20565 + * fragment cache. Add this fragment to the end of the pending entry.
20566 + */
20567 + entry = ieee80211_reassemble_find(rx->local, rx->fc, frag, seq,
20568 + rx->u.rx.queue, hdr);
20569 + if (!entry) {
20570 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20571 + return TXRX_DROP;
20572 + }
20573 +
20574 + /* Verify that MPDUs within one MSDU have sequential PN values.
20575 + * (IEEE 802.11i, 8.3.3.4.5) */
20576 + if (entry->ccmp) {
20577 + int i;
20578 + u8 pn[CCMP_PN_LEN], *rpn;
20579 + if (rx->key == NULL || rx->key->alg != ALG_CCMP)
20580 + return TXRX_DROP;
20581 + memcpy(pn, entry->last_pn, CCMP_PN_LEN);
20582 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
20583 + pn[i]++;
20584 + if (pn[i])
20585 + break;
20586 + }
20587 + rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
20588 + if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
20589 + printk(KERN_DEBUG "%s: defrag: CCMP PN not sequential"
20590 + " A2=" MACSTR " PN=%02x%02x%02x%02x%02x%02x "
20591 + "(expected %02x%02x%02x%02x%02x%02x)\n",
20592 + rx->dev->name, MAC2STR(hdr->addr2),
20593 + rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], rpn[5],
20594 + pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]);
20595 + return TXRX_DROP;
20596 + }
20597 + memcpy(entry->last_pn, pn, CCMP_PN_LEN);
20598 + }
20599 +
20600 + /* TODO: could gather list of skb's and reallocate data buffer only
20601 + * after finding out the total length of the frame */
20602 + skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
20603 + if (skb_tailroom(entry->skb) < rx->skb->len) {
20604 + I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
20605 + if (unlikely(pskb_expand_head(entry->skb, 0, rx->skb->len,
20606 + GFP_ATOMIC))) {
20607 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20608 + return TXRX_DROP;
20609 + }
20610 + }
20611 + memcpy(skb_put(entry->skb, rx->skb->len), rx->skb->data, rx->skb->len);
20612 + entry->last_frag = frag;
20613 + dev_kfree_skb(rx->skb);
20614 +
20615 + if (rx->fc & WLAN_FC_MOREFRAG) {
20616 + rx->skb = NULL;
20617 + return TXRX_QUEUED;
20618 + }
20619 +
20620 + /* Complete frame has been reassembled - process it now */
20621 + rx->skb = entry->skb;
20622 + rx->fragmented = 1;
20623 + entry->skb = NULL;
20624 +
20625 + out:
20626 + if (rx->sta)
20627 + rx->sta->rx_packets++;
20628 + if (MULTICAST_ADDR(hdr->addr1))
20629 + rx->local->dot11MulticastReceivedFrameCount++;
20630 +#ifdef IEEE80211_LEDS
20631 + else
20632 + ieee80211_rx_led(2, rx->dev);
20633 +#endif /* IEEE80211_LEDS */
20634 + return TXRX_CONTINUE;
20635 +}
20636 +
20637 +
20638 +static ieee80211_txrx_result
20639 +ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
20640 +{
20641 + if (rx->local->conf.mode == IW_MODE_MONITOR) {
20642 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20643 + ieee80211_msg_monitor);
20644 + return TXRX_QUEUED;
20645 + }
20646 +
20647 + return TXRX_CONTINUE;
20648 +}
20649 +
20650 +
20651 +static ieee80211_txrx_result
20652 +ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
20653 +{
20654 + struct ieee80211_hdr *hdr;
20655 + int always_sta_key;
20656 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20657 +
20658 + /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
20659 + if (rx->sta && !MULTICAST_ADDR(hdr->addr1)) {
20660 + if (unlikely(rx->fc & WLAN_FC_RETRY &&
20661 + rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
20662 + hdr->seq_ctrl)) {
20663 + rx->local->dot11FrameDuplicateCount++;
20664 + rx->sta->num_duplicates++;
20665 + return TXRX_DROP;
20666 + } else
20667 + rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
20668 + }
20669 +
20670 + if (rx->local->hw->rx_includes_fcs && rx->skb->len > FCS_LEN)
20671 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
20672 +
20673 + if (unlikely(rx->skb->len < 16)) {
20674 + I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
20675 + return TXRX_DROP;
20676 + }
20677 +
20678 + /* Filter out foreign unicast packets when in promiscuous mode.
20679 + * FIX: Filter out multicast to foreign BSSID. */
20680 + if (rx->local->conf.mode == IW_MODE_INFRA &&
20681 + !MULTICAST_ADDR(hdr->addr1) &&
20682 + !ieee80211_own_addr(rx->dev, hdr->addr1))
20683 + return TXRX_DROP;
20684 +
20685 + /* Drop disallowed frame classes based on STA auth/assoc state;
20686 + * IEEE 802.11, Chap 5.5.
20687 + *
20688 + * 80211.o does filtering only based on association state, i.e., it
20689 + * drops Class 3 frames from not associated stations. hostapd sends
20690 + * deauth/disassoc frames when needed. In addition, hostapd is
20691 + * responsible for filtering on both auth and assoc states.
20692 + */
20693 + if (unlikely((WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA ||
20694 + (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_CTRL &&
20695 + WLAN_FC_GET_STYPE(rx->fc) == WLAN_FC_STYPE_PSPOLL)) &&
20696 + rx->local->conf.mode != IW_MODE_ADHOC &&
20697 + (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
20698 + if (!(rx->fc & WLAN_FC_FROMDS) && !(rx->fc & WLAN_FC_TODS)) {
20699 + /* Drop IBSS frames silently. */
20700 + return TXRX_DROP;
20701 + }
20702 +
20703 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20704 + ieee80211_msg_sta_not_assoc);
20705 + return TXRX_QUEUED;
20706 + }
20707 +
20708 + if (rx->local->conf.mode == IW_MODE_INFRA)
20709 + always_sta_key = 0;
20710 + else
20711 + always_sta_key = 1;
20712 +
20713 + if (rx->sta && rx->sta->key && always_sta_key) {
20714 + rx->key = rx->sta->key;
20715 + } else {
20716 + if (!rx->sdata) {
20717 + printk(KERN_DEBUG "%s: sdata was null in packet!!\n",
20718 + rx->dev->name);
20719 + printk(KERN_DEBUG "%s: Addr1: " MACSTR "\n",
20720 + rx->dev->name, MAC2STR(hdr->addr1));
20721 + printk(KERN_DEBUG "%s: Addr2: " MACSTR "\n",
20722 + rx->dev->name, MAC2STR(hdr->addr2));
20723 + printk(KERN_DEBUG "%s: Addr3: " MACSTR "\n",
20724 + rx->dev->name, MAC2STR(hdr->addr3));
20725 + return TXRX_DROP;
20726 + }
20727 + if (rx->sta && rx->sta->key)
20728 + rx->key = rx->sta->key;
20729 + else
20730 + rx->key = rx->sdata->default_key;
20731 +
20732 + if (rx->local->hw->wep_include_iv &&
20733 + rx->fc & WLAN_FC_ISWEP) {
20734 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
20735 +
20736 + if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
20737 + (rx->sta == NULL || rx->sta->key == NULL ||
20738 + keyidx > 0)) {
20739 + rx->key = rx->sdata->keys[keyidx];
20740 + }
20741 + if (!rx->key) {
20742 + printk(KERN_DEBUG "%s: RX WEP frame with "
20743 + "unknown keyidx %d (A1=" MACSTR " A2="
20744 + MACSTR " A3=" MACSTR ")\n",
20745 + rx->dev->name, keyidx,
20746 + MAC2STR(hdr->addr1),
20747 + MAC2STR(hdr->addr2),
20748 + MAC2STR(hdr->addr3));
20749 + ieee80211_rx_mgmt(
20750 + rx->dev, rx->skb, rx->u.rx.status,
20751 + ieee80211_msg_wep_frame_unknown_key);
20752 + return TXRX_QUEUED;
20753 + }
20754 + }
20755 + }
20756 +
20757 + if (rx->fc & WLAN_FC_ISWEP && rx->key) {
20758 + rx->key->tx_rx_count++;
20759 + if (unlikely(rx->local->key_tx_rx_threshold &&
20760 + rx->key->tx_rx_count >
20761 + rx->local->key_tx_rx_threshold)) {
20762 + ieee80211_key_threshold_notify(rx->dev, rx->key,
20763 + rx->sta);
20764 + }
20765 + }
20766 +
20767 + return TXRX_CONTINUE;
20768 +}
20769 +
20770 +
20771 +static ieee80211_txrx_result
20772 +ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
20773 +{
20774 + struct sta_info *sta = rx->sta;
20775 + struct net_device *dev = rx->dev;
20776 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
20777 +
20778 + if (!sta)
20779 + return TXRX_CONTINUE;
20780 +
20781 + /* Update last_rx only for IBSS packets which are for the current
20782 + * BSSID to avoid keeping the current IBSS network alive in cases where
20783 + * other STAs are using different BSSID. */
20784 + if (rx->local->conf.mode == IW_MODE_ADHOC) {
20785 + u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
20786 + if (memcmp(bssid, rx->local->bssid, ETH_ALEN) == 0)
20787 + sta->last_rx = jiffies;
20788 + } else
20789 + if (!MULTICAST_ADDR(hdr->addr1) ||
20790 + rx->local->conf.mode == IW_MODE_INFRA) {
20791 + /* Update last_rx only for unicast frames in order to prevent
20792 + * the Probe Request frames (the only broadcast frames from a
20793 + * STA in infrastructure mode) from keeping a connection alive.
20794 + */
20795 + sta->last_rx = jiffies;
20796 + }
20797 + sta->rx_fragments++;
20798 + sta->rx_bytes += rx->skb->len;
20799 + sta->last_rssi = rx->u.rx.status->ssi;
20800 +
20801 + if (!(rx->fc & WLAN_FC_MOREFRAG)) {
20802 + /* Change STA power saving mode only in the end of a frame
20803 + * exchange sequence */
20804 + if ((sta->flags & WLAN_STA_PS) && !(rx->fc & WLAN_FC_PWRMGT))
20805 + rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
20806 + else if (!(sta->flags & WLAN_STA_PS) &&
20807 + (rx->fc & WLAN_FC_PWRMGT))
20808 + ap_sta_ps_start(dev, sta);
20809 + }
20810 +
20811 + /* Drop data::nullfunc frames silently, since they are used only to
20812 + * control station power saving mode. */
20813 + if (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20814 + WLAN_FC_GET_STYPE(rx->fc) == WLAN_FC_STYPE_NULLFUNC) {
20815 + I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
20816 + /* Update counter and free packet here to avoid counting this
20817 + * as a dropped packed. */
20818 + sta->rx_packets++;
20819 + dev_kfree_skb(rx->skb);
20820 + return TXRX_QUEUED;
20821 + }
20822 +
20823 + return TXRX_CONTINUE;
20824 +}
20825 +
20826 +
20827 +static ieee80211_txrx_result
20828 +ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
20829 +{
20830 + if (!rx->sta || !(rx->fc & WLAN_FC_ISWEP) ||
20831 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA || !rx->key ||
20832 + rx->key->alg != ALG_WEP)
20833 + return TXRX_CONTINUE;
20834 +
20835 + /* Check for weak IVs, if hwaccel did not remove IV from the frame */
20836 + if (rx->local->hw->wep_include_iv ||
20837 + rx->key->force_sw_encrypt || rx->local->conf.sw_decrypt) {
20838 + u8 *iv = ieee80211_wep_is_weak_iv(rx->skb, rx->key);
20839 + if (iv) {
20840 + rx->sta->wep_weak_iv_count++;
20841 + }
20842 + }
20843 +
20844 + return TXRX_CONTINUE;
20845 +}
20846 +
20847 +
20848 +static ieee80211_txrx_result
20849 +ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
20850 +{
20851 + /* If the device handles decryption totally, skip this test */
20852 + if (rx->local->hw->device_hides_wep)
20853 + return TXRX_CONTINUE;
20854 +
20855 + if ((rx->key && rx->key->alg != ALG_WEP) ||
20856 + !(rx->fc & WLAN_FC_ISWEP) ||
20857 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA &&
20858 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_MGMT ||
20859 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_AUTH)))
20860 + return TXRX_CONTINUE;
20861 +
20862 + if (!rx->key) {
20863 + printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
20864 + rx->dev->name);
20865 + return TXRX_DROP;
20866 + }
20867 +
20868 + if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
20869 + rx->key->force_sw_encrypt || rx->local->conf.sw_decrypt) {
20870 + if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
20871 + printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
20872 + "failed\n", rx->dev->name);
20873 + return TXRX_DROP;
20874 + }
20875 + } else if (rx->local->hw->wep_include_iv) {
20876 + ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
20877 + /* remove ICV */
20878 + skb_trim(rx->skb, rx->skb->len - 4);
20879 + }
20880 +
20881 + return TXRX_CONTINUE;
20882 +}
20883 +
20884 +
20885 +static ieee80211_txrx_result
20886 +ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
20887 +{
20888 + if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
20889 + rx->local->conf.mode != IW_MODE_INFRA) {
20890 + /* Pass both encrypted and unencrypted EAPOL frames to user
20891 + * space for processing. */
20892 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20893 + ieee80211_msg_normal);
20894 + return TXRX_QUEUED;
20895 + }
20896 +
20897 + if (unlikely(rx->sdata->ieee802_1x &&
20898 + WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20899 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_NULLFUNC &&
20900 + (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
20901 + !ieee80211_is_eapol(rx->skb))) {
20902 +#ifdef CONFIG_D80211_DEBUG
20903 + struct ieee80211_hdr *hdr =
20904 + (struct ieee80211_hdr *) rx->skb->data;
20905 + printk(KERN_DEBUG "%s: dropped frame from " MACSTR
20906 + " (unauthorized port)\n", rx->dev->name,
20907 + MAC2STR(hdr->addr2));
20908 +#endif /* CONFIG_D80211_DEBUG */
20909 + return TXRX_DROP;
20910 + }
20911 +
20912 + return TXRX_CONTINUE;
20913 +}
20914 +
20915 +
20916 +static ieee80211_txrx_result
20917 +ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
20918 +{
20919 + /* If the device handles decryption totally, skip this test */
20920 + if (rx->local->hw->device_hides_wep)
20921 + return TXRX_CONTINUE;
20922 +
20923 + /* Drop unencrypted frames if key is set. */
20924 + if (unlikely(!(rx->fc & WLAN_FC_ISWEP) &&
20925 + WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20926 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_NULLFUNC &&
20927 + (rx->key || rx->sdata->drop_unencrypted) &&
20928 + (rx->sdata->eapol == 0 ||
20929 + !ieee80211_is_eapol(rx->skb)))) {
20930 + printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
20931 + "encryption\n", rx->dev->name);
20932 + return TXRX_DROP;
20933 + }
20934 + return TXRX_CONTINUE;
20935 +}
20936 +
20937 +
20938 +static ieee80211_txrx_result
20939 +ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
20940 +{
20941 + struct ieee80211_sub_if_data *sdata;
20942 + sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
20943 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
20944 + ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
20945 + } else {
20946 + /* Management frames are sent to hostapd for processing */
20947 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20948 + ieee80211_msg_normal);
20949 + }
20950 + return TXRX_QUEUED;
20951 +}
20952 +
20953 +
20954 +static ieee80211_txrx_result
20955 +ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
20956 +{
20957 + struct ieee80211_local *local = rx->local;
20958 + struct sk_buff *skb = rx->skb;
20959 +
20960 + if (unlikely(local->sta_scanning != 0)) {
20961 + ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
20962 + return TXRX_QUEUED;
20963 + }
20964 +
20965 + if (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA)
20966 + local->scan.txrx_count++;
20967 + if (unlikely(local->scan.in_scan != 0 &&
20968 + rx->u.rx.status->freq == local->scan.freq)) {
20969 + struct ieee80211_hdr *hdr;
20970 + u16 fc;
20971 +
20972 + local->scan.rx_packets++;
20973 +
20974 + hdr = (struct ieee80211_hdr *) skb->data;
20975 + fc = le16_to_cpu(hdr->frame_control);
20976 +
20977 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
20978 + WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
20979 + local->scan.rx_beacon++;
20980 + /* Need to trim FCS here because it is normally
20981 + * removed only after this passive scan handler. */
20982 + if (rx->local->hw->rx_includes_fcs &&
20983 + rx->skb->len > FCS_LEN)
20984 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
20985 +
20986 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20987 + ieee80211_msg_passive_scan);
20988 + return TXRX_QUEUED;
20989 + } else {
20990 + I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
20991 + return TXRX_DROP;
20992 + }
20993 + }
20994 +
20995 + return TXRX_CONTINUE;
20996 +}
20997 +
20998 +
20999 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
21000 +{
21001 + u16 fc;
21002 +
21003 + if (len < 24)
21004 + return NULL;
21005 +
21006 + fc = le16_to_cpu(hdr->frame_control);
21007 +
21008 + switch (WLAN_FC_GET_TYPE(fc)) {
21009 + case WLAN_FC_TYPE_DATA:
21010 + switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
21011 + case WLAN_FC_TODS:
21012 + return hdr->addr1;
21013 + case (WLAN_FC_TODS | WLAN_FC_FROMDS):
21014 + return NULL;
21015 + case WLAN_FC_FROMDS:
21016 + return hdr->addr2;
21017 + case 0:
21018 + return hdr->addr3;
21019 + }
21020 + break;
21021 + case WLAN_FC_TYPE_MGMT:
21022 + return hdr->addr3;
21023 + case WLAN_FC_TYPE_CTRL:
21024 + if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PSPOLL)
21025 + return hdr->addr1;
21026 + else
21027 + return NULL;
21028 + }
21029 +
21030 + return NULL;
21031 +}
21032 +
21033 +
21034 +static struct net_device * ieee80211_get_rx_dev(struct ieee80211_local *local,
21035 + struct ieee80211_hdr *hdr,
21036 + size_t len, int *sta_broadcast)
21037 +{
21038 + u8 *bssid;
21039 + struct net_device *dev;
21040 + u16 fc;
21041 +
21042 + bssid = ieee80211_get_bssid(hdr, len);
21043 + if (bssid) {
21044 + dev = ieee80211_own_bssid(local, bssid);
21045 + if (!dev && (local->conf.mode == IW_MODE_INFRA ||
21046 + local->conf.mode == IW_MODE_ADHOC))
21047 + dev = ieee80211_sta_bssid(local, bssid, hdr->addr1,
21048 + sta_broadcast);
21049 + if (dev)
21050 + return dev;
21051 + }
21052 +
21053 + if (len >= 30) {
21054 + fc = le16_to_cpu(hdr->frame_control);
21055 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
21056 + (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
21057 + (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
21058 + dev = ieee80211_get_wds_dev(local, hdr->addr2);
21059 + if (dev)
21060 + return dev;
21061 + }
21062 + }
21063 +
21064 + /* Default to default device if nothing else matches */
21065 + return local->wdev;
21066 +}
21067 +
21068 +
21069 +static void ieee80211_rx_michael_mic_report(struct net_device *dev,
21070 + struct ieee80211_hdr *hdr,
21071 + struct sta_info *sta,
21072 + struct ieee80211_txrx_data *rx)
21073 +{
21074 + int keyidx, hdrlen;
21075 +
21076 + hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
21077 + if (rx->skb->len >= hdrlen + 4)
21078 + keyidx = rx->skb->data[hdrlen + 3] >> 6;
21079 + else
21080 + keyidx = -1;
21081 +
21082 + /* TODO: verify that this is not triggered by fragmented
21083 + * frames (hw does not verify MIC for them). */
21084 + printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
21085 + "failure from " MACSTR " to " MACSTR " keyidx=%d\n",
21086 + dev->name, MAC2STR(hdr->addr2), MAC2STR(hdr->addr1), keyidx);
21087 +
21088 + if (sta == NULL) {
21089 + /* Some hardware versions seem to generate incorrect
21090 + * Michael MIC reports; ignore them to avoid triggering
21091 + * countermeasures. */
21092 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21093 + "error for unknown address " MACSTR "\n",
21094 + dev->name, MAC2STR(hdr->addr2));
21095 + goto ignore;
21096 + }
21097 +
21098 + if (!(rx->fc & WLAN_FC_ISWEP)) {
21099 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21100 + "error for a frame with no ISWEP flag (src "
21101 + MACSTR ")\n", dev->name, MAC2STR(hdr->addr2));
21102 + goto ignore;
21103 + }
21104 +
21105 + if (rx->local->hw->wep_include_iv &&
21106 + rx->local->conf.mode == IW_MODE_MASTER) {
21107 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
21108 + /* AP with Pairwise keys support should never receive Michael
21109 + * MIC errors for non-zero keyidx because these are reserved
21110 + * for group keys and only the AP is sending real multicast
21111 + * frames in BSS. */
21112 + if (keyidx) {
21113 + printk(KERN_DEBUG "%s: ignored Michael MIC error for "
21114 + "a frame with non-zero keyidx (%d) (src " MACSTR
21115 + ")\n", dev->name, keyidx, MAC2STR(hdr->addr2));
21116 + goto ignore;
21117 + }
21118 + }
21119 +
21120 + if (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA &&
21121 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_MGMT ||
21122 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_AUTH)) {
21123 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21124 + "error for a frame that cannot be encrypted "
21125 + "(fc=0x%04x) (src " MACSTR ")\n",
21126 + dev->name, rx->fc, MAC2STR(hdr->addr2));
21127 + goto ignore;
21128 + }
21129 +
21130 + do {
21131 + union iwreq_data wrqu;
21132 + char *buf = kmalloc(128, GFP_ATOMIC);
21133 + if (buf == NULL)
21134 + break;
21135 +
21136 + /* TODO: needed parameters: count, key type, TSC */
21137 + sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
21138 + "keyid=%d %scast addr=" MACSTR ")",
21139 + keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
21140 + MAC2STR(hdr->addr2));
21141 + memset(&wrqu, 0, sizeof(wrqu));
21142 + wrqu.data.length = strlen(buf);
21143 + wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
21144 + kfree(buf);
21145 + } while (0);
21146 +
21147 + /* TODO: consider verifying the MIC error report with software
21148 + * implementation if we get too many spurious reports from the
21149 + * hardware. */
21150 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21151 + ieee80211_msg_michael_mic_failure);
21152 + return;
21153 +
21154 + ignore:
21155 + dev_kfree_skb(rx->skb);
21156 + rx->skb = NULL;
21157 +}
21158 +
21159 +
21160 +static void ieee80211_sta_rx_broadcast(struct ieee80211_txrx_data *rx)
21161 +{
21162 + struct ieee80211_local *local = rx->dev->priv;
21163 + u8 *_bssid, bssid[ETH_ALEN];
21164 + struct sk_buff *orig_skb = rx->skb, *skb;
21165 + struct ieee80211_hdr *hdr;
21166 + ieee80211_rx_handler *handler;
21167 + ieee80211_txrx_result res;
21168 + struct list_head *ptr;
21169 +
21170 + hdr = (struct ieee80211_hdr *) orig_skb->data;
21171 + _bssid = ieee80211_get_bssid(hdr, orig_skb->len);
21172 + if (_bssid == NULL) {
21173 + dev_kfree_skb(orig_skb);
21174 + return;
21175 + }
21176 + memcpy(bssid, _bssid, ETH_ALEN);
21177 +
21178 + list_for_each(ptr, &local->sub_if_list) {
21179 + struct ieee80211_sub_if_data *sdata =
21180 + list_entry(ptr, struct ieee80211_sub_if_data, list);
21181 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA ||
21182 + (memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) != 0 &&
21183 + !(bssid[0] & 0x01)))
21184 + continue;
21185 +
21186 + skb = skb_copy(orig_skb, GFP_ATOMIC);
21187 + if (skb == NULL) {
21188 + if (net_ratelimit()) {
21189 + printk(KERN_DEBUG "%s: failed to copy "
21190 + "multicast frame for %s",
21191 + rx->dev->name, sdata->dev->name);
21192 + }
21193 + continue;
21194 + }
21195 +
21196 + hdr = (struct ieee80211_hdr *) skb->data;
21197 + rx->skb = skb;
21198 + rx->dev = sdata->dev;
21199 + rx->sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
21200 +
21201 + res = TXRX_DROP;
21202 + for (handler = local->rx_handlers; *handler != NULL; handler++)
21203 + {
21204 + res = (*handler)(rx);
21205 + if (res == TXRX_DROP || res == TXRX_QUEUED)
21206 + break;
21207 + }
21208 +
21209 + if (res == TXRX_DROP || *handler == NULL)
21210 + dev_kfree_skb(skb);
21211 + }
21212 +
21213 + dev_kfree_skb(orig_skb);
21214 +}
21215 +
21216 +
21217 +/*
21218 + * This is the receive path handler. It is called by a low level driver when an
21219 + * 802.11 MPDU is received from the hardware.
21220 + */
21221 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
21222 + struct ieee80211_rx_status *status)
21223 +{
21224 + struct ieee80211_local *local = dev->priv;
21225 + struct sta_info *sta;
21226 + struct ieee80211_hdr *hdr;
21227 + ieee80211_rx_handler *handler;
21228 + struct ieee80211_txrx_data rx;
21229 + ieee80211_txrx_result res = TXRX_DROP;
21230 + u16 type;
21231 + int sta_broadcast = 0;
21232 +
21233 + hdr = (struct ieee80211_hdr *) skb->data;
21234 + memset(&rx, 0, sizeof(rx));
21235 + rx.skb = skb;
21236 + rx.local = local;
21237 + if (skb->len >= 16) {
21238 + sta = rx.sta = sta_info_get(local, hdr->addr2);
21239 + if (unlikely(sta == NULL &&
21240 + local->conf.mode == IW_MODE_ADHOC)) {
21241 + u8 *bssid = ieee80211_get_bssid(hdr, skb->len);
21242 + if (bssid &&
21243 + memcmp(bssid, local->bssid, ETH_ALEN) == 0)
21244 + sta = rx.sta =
21245 + ieee80211_ibss_add_sta(dev, skb, bssid,
21246 + hdr->addr2);
21247 + }
21248 + } else
21249 + sta = rx.sta = NULL;
21250 + if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS))
21251 + rx.dev = sta->dev;
21252 + else
21253 + rx.dev = ieee80211_get_rx_dev(local, hdr, skb->len,
21254 + &sta_broadcast);
21255 +
21256 + rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
21257 + rx.u.rx.status = status;
21258 + rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
21259 + type = WLAN_FC_GET_TYPE(rx.fc);
21260 + if (type == WLAN_FC_TYPE_DATA || type == WLAN_FC_TYPE_MGMT)
21261 + local->dot11ReceivedFragmentCount++;
21262 + if (sta_broadcast) {
21263 + ieee80211_sta_rx_broadcast(&rx);
21264 + goto end;
21265 + }
21266 +
21267 + if ((status->flag & RX_FLAG_MMIC_ERROR)) {
21268 + ieee80211_rx_michael_mic_report(dev, hdr, sta, &rx);
21269 + goto end;
21270 + }
21271 +
21272 + for (handler = local->rx_handlers; *handler != NULL; handler++) {
21273 + res = (*handler)(&rx);
21274 + if (res != TXRX_CONTINUE) {
21275 + if (res == TXRX_DROP) {
21276 + I802_DEBUG_INC(local->rx_handlers_drop);
21277 + if (sta)
21278 + sta->rx_dropped++;
21279 + }
21280 + if (res == TXRX_QUEUED)
21281 + I802_DEBUG_INC(local->rx_handlers_queued);
21282 + break;
21283 + }
21284 + }
21285 + skb = rx.skb; /* handlers are allowed to change skb */
21286 +
21287 + if (res == TXRX_DROP || *handler == NULL)
21288 + dev_kfree_skb(skb);
21289 +
21290 + end:
21291 + if (sta)
21292 + sta_info_release(local, sta);
21293 +}
21294 +
21295 +
21296 +static ieee80211_txrx_result
21297 +ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
21298 +{
21299 + struct ieee80211_local *local = tx->local;
21300 + struct sk_buff *skb = tx->skb;
21301 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21302 + u32 load = 0, hdrtime;
21303 +
21304 + /* TODO: this could be part of tx_status handling, so that the number
21305 + * of retries would be known; TX rate should in that case be stored
21306 + * somewhere with the packet */
21307 +
21308 + /* Estimate total channel use caused by this frame */
21309 +
21310 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21311 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21312 +
21313 + if (local->conf.phymode == MODE_IEEE80211A ||
21314 + local->conf.phymode == MODE_ATHEROS_TURBO ||
21315 + local->conf.phymode == MODE_ATHEROS_TURBOG ||
21316 + (local->conf.phymode == MODE_IEEE80211G &&
21317 + tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
21318 + hdrtime = CHAN_UTIL_HDR_SHORT;
21319 + else
21320 + hdrtime = CHAN_UTIL_HDR_LONG;
21321 +
21322 + load = hdrtime;
21323 + if (!MULTICAST_ADDR(hdr->addr1))
21324 + load += hdrtime;
21325 +
21326 + if (tx->u.tx.control->use_rts_cts)
21327 + load += 2 * hdrtime;
21328 + else if (tx->u.tx.control->use_cts_protect)
21329 + load += hdrtime;
21330 +
21331 + load += skb->len * tx->u.tx.rate->rate_inv;
21332 +
21333 + if (tx->u.tx.extra_frag) {
21334 + int i;
21335 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
21336 + load += 2 * hdrtime;
21337 + load += tx->u.tx.extra_frag[i]->len *
21338 + tx->u.tx.rate->rate;
21339 + }
21340 + }
21341 +
21342 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21343 + load >>= CHAN_UTIL_SHIFT;
21344 + local->channel_use_raw += load;
21345 + if (tx->sta)
21346 + tx->sta->channel_use_raw += load;
21347 + tx->sdata->channel_use_raw += load;
21348 +
21349 + return TXRX_CONTINUE;
21350 +}
21351 +
21352 +
21353 +static ieee80211_txrx_result
21354 +ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
21355 +{
21356 + struct ieee80211_local *local = rx->local;
21357 + struct sk_buff *skb = rx->skb;
21358 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21359 + u32 load = 0, hdrtime;
21360 + struct ieee80211_rate *rate;
21361 + int i;
21362 +
21363 + /* Estimate total channel use caused by this frame */
21364 +
21365 + if (unlikely(local->num_curr_rates < 0))
21366 + return TXRX_CONTINUE;
21367 +
21368 + rate = &local->curr_rates[0];
21369 + for (i = 0; i < local->num_curr_rates; i++) {
21370 + if (local->curr_rates[i].val == rx->u.rx.status->rate) {
21371 + rate = &local->curr_rates[i];
21372 + break;
21373 + }
21374 + }
21375 +
21376 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21377 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21378 +
21379 + if (local->conf.phymode == MODE_IEEE80211A ||
21380 + local->conf.phymode == MODE_ATHEROS_TURBO ||
21381 + local->conf.phymode == MODE_ATHEROS_TURBOG ||
21382 + (local->conf.phymode == MODE_IEEE80211G &&
21383 + rate->flags & IEEE80211_RATE_ERP))
21384 + hdrtime = CHAN_UTIL_HDR_SHORT;
21385 + else
21386 + hdrtime = CHAN_UTIL_HDR_LONG;
21387 +
21388 + load = hdrtime;
21389 + if (!MULTICAST_ADDR(hdr->addr1))
21390 + load += hdrtime;
21391 +
21392 + load += skb->len * rate->rate_inv;
21393 +
21394 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21395 + load >>= CHAN_UTIL_SHIFT;
21396 + local->channel_use_raw += load;
21397 + if (rx->sta)
21398 + rx->sta->channel_use_raw += load;
21399 + rx->sdata->channel_use_raw += load;
21400 +
21401 + return TXRX_CONTINUE;
21402 +}
21403 +
21404 +
21405 +static void ieee80211_stat_refresh(unsigned long data)
21406 +{
21407 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21408 + struct list_head *ptr, *n;
21409 +
21410 + if (!local->stat_time)
21411 + return;
21412 +
21413 + /* go through all stations */
21414 + spin_lock_bh(&local->sta_lock);
21415 + list_for_each(ptr, &local->sta_list) {
21416 + struct sta_info *sta =
21417 + list_entry(ptr, struct sta_info, list);
21418 + sta->channel_use = (sta->channel_use_raw / local->stat_time) /
21419 + CHAN_UTIL_PER_10MS;
21420 + sta->channel_use_raw = 0;
21421 + }
21422 + spin_unlock_bh(&local->sta_lock);
21423 +
21424 + /* go through all subinterfaces */
21425 + list_for_each_safe(ptr, n, &local->sub_if_list) {
21426 + struct ieee80211_sub_if_data *sdata =
21427 + list_entry(ptr, struct ieee80211_sub_if_data, list);
21428 + sdata->channel_use = (sdata->channel_use_raw /
21429 + local->stat_time) / CHAN_UTIL_PER_10MS;
21430 + sdata->channel_use_raw = 0;
21431 +
21432 + }
21433 +
21434 + /* hardware interface */
21435 + local->channel_use = (local->channel_use_raw /
21436 + local->stat_time) / CHAN_UTIL_PER_10MS;
21437 + local->channel_use_raw = 0;
21438 +
21439 + local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
21440 + add_timer(&local->stat_timer);
21441 +}
21442 +
21443 +
21444 +/* This is a version of the rx handler that can be called from hard irq
21445 + * context. Post the skb on the queue and schedule the tasklet */
21446 +void ieee80211_rx_irqsafe(struct net_device *dev, struct sk_buff *skb,
21447 + struct ieee80211_rx_status *status)
21448 +{
21449 + struct ieee80211_local *local = dev->priv;
21450 + struct ieee80211_rx_status *saved;
21451 +
21452 + skb->dev = dev;
21453 + saved = kmalloc(sizeof(struct ieee80211_rx_status), GFP_ATOMIC);
21454 + if (saved)
21455 + memcpy(saved, status, sizeof(struct ieee80211_rx_status));
21456 + memcpy(skb->cb, &saved, sizeof(saved));
21457 + skb->pkt_type = ieee80211_rx_msg;
21458 + skb_queue_tail(&local->skb_queue, skb);
21459 + tasklet_schedule(&local->tasklet);
21460 +}
21461 +
21462 +
21463 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
21464 + struct ieee80211_tx_status *status)
21465 +{
21466 + struct ieee80211_local *local = dev->priv;
21467 + struct ieee80211_tx_status *saved;
21468 + int tmp;
21469 +
21470 + skb->dev = dev;
21471 + saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
21472 + if (saved)
21473 + memcpy(saved, status, sizeof(struct ieee80211_tx_status));
21474 + memcpy(skb->cb, &saved, sizeof(saved));
21475 + skb->pkt_type = ieee80211_tx_status_msg;
21476 + skb_queue_tail(status->control.req_tx_status ?
21477 + &local->skb_queue : &local->skb_queue_unreliable, skb);
21478 + tmp = skb_queue_len(&local->skb_queue) +
21479 + skb_queue_len(&local->skb_queue_unreliable);
21480 + while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
21481 + (skb = skb_dequeue(&local->skb_queue_unreliable))) {
21482 + memcpy(&saved, skb->cb, sizeof(saved));
21483 + kfree(saved);
21484 + dev_kfree_skb_irq(skb);
21485 + tmp--;
21486 + I802_DEBUG_INC(local->tx_status_drop);
21487 + }
21488 + tasklet_schedule(&local->tasklet);
21489 +}
21490 +
21491 +
21492 +static void ieee80211_tasklet_handler(unsigned long data)
21493 +{
21494 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21495 + struct sk_buff *skb;
21496 + struct ieee80211_rx_status *rx_status;
21497 + struct ieee80211_tx_status *tx_status;
21498 +
21499 + while ((skb = skb_dequeue(&local->skb_queue)) ||
21500 + (skb = skb_dequeue(&local->skb_queue_unreliable))) {
21501 + switch (skb->pkt_type) {
21502 + case ieee80211_rx_msg:
21503 + memcpy(&rx_status, skb->cb, sizeof(rx_status));
21504 + if (!rx_status) {
21505 + if (net_ratelimit())
21506 + printk(KERN_WARNING "%s: Not enough "
21507 + "memory, dropping packet",
21508 + skb->dev->name);
21509 + dev_kfree_skb(skb);
21510 + return;
21511 + }
21512 + /* Clear skb->type in order to not confuse kernel
21513 + * netstack. */
21514 + skb->pkt_type = 0;
21515 + __ieee80211_rx(skb->dev, skb, rx_status);
21516 + kfree(rx_status);
21517 + break;
21518 + case ieee80211_tx_status_msg:
21519 + memcpy(&tx_status, skb->cb, sizeof(tx_status));
21520 + if (!tx_status) {
21521 + dev_kfree_skb(skb);
21522 + return;
21523 + }
21524 + skb->pkt_type = 0;
21525 + ieee80211_tx_status(skb->dev, skb, tx_status);
21526 + kfree(tx_status);
21527 + break;
21528 + default: /* should never get here! */
21529 + printk(KERN_ERR "%s: Unknown message type (%d)\n",
21530 + local->wdev->name, skb->pkt_type);
21531 + dev_kfree_skb(skb);
21532 + break;
21533 + }
21534 + }
21535 +}
21536 +
21537 +
21538 +/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
21539 + * make a prepared TX frame (one that has been given to hw) to look like brand
21540 + * new IEEE 802.11 frame that is ready to go through TX processing again.
21541 + * Also, tx_packet_data in cb is restored from tx_control. */
21542 +static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
21543 + struct ieee80211_key *key,
21544 + struct sk_buff *skb,
21545 + struct ieee80211_tx_control *control)
21546 +{
21547 + int hdrlen, iv_len, mic_len;
21548 + struct ieee80211_tx_packet_data *pkt_data;
21549 +
21550 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
21551 + pkt_data->sdata = control->sdata;
21552 + pkt_data->req_tx_status = control->req_tx_status;
21553 + pkt_data->do_not_encrypt = control->do_not_encrypt;
21554 + pkt_data->pkt_probe_resp = (control->pkt_type == PKT_PROBE_RESP);
21555 + pkt_data->requeue = control->requeue;
21556 + pkt_data->queue = control->queue;
21557 +
21558 + if (key == NULL)
21559 + return;
21560 +
21561 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
21562 +
21563 + switch (key->alg) {
21564 + case ALG_WEP:
21565 + iv_len = WEP_IV_LEN;
21566 + mic_len = WEP_ICV_LEN;
21567 + break;
21568 + case ALG_TKIP:
21569 + iv_len = TKIP_IV_LEN;
21570 + mic_len = TKIP_ICV_LEN;
21571 + break;
21572 + case ALG_CCMP:
21573 + iv_len = CCMP_HDR_LEN;
21574 + mic_len = CCMP_MIC_LEN;
21575 + break;
21576 + default:
21577 + return;
21578 + }
21579 +
21580 + if (skb->len >= mic_len && key->force_sw_encrypt)
21581 + skb_trim(skb, skb->len - mic_len);
21582 + if (skb->len >= iv_len && skb->len > hdrlen) {
21583 + memmove(skb->data + iv_len, skb->data, hdrlen);
21584 + skb_pull(skb, iv_len);
21585 + }
21586 +
21587 + {
21588 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21589 + u16 fc = le16_to_cpu(hdr->frame_control);
21590 + if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
21591 + fc &= ~(WLAN_FC_STYPE_QOS_DATA << 4);
21592 + hdr->frame_control = cpu_to_le16(fc);
21593 + memmove(skb->data + 2, skb->data, hdrlen - 2);
21594 + skb_pull(skb, 2);
21595 + }
21596 + }
21597 +}
21598 +
21599 +
21600 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
21601 + struct ieee80211_tx_status *status)
21602 +{
21603 + struct sk_buff *skb2;
21604 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21605 + struct ieee80211_local *local = dev->priv;
21606 + u16 frag, type;
21607 + u32 msg_type;
21608 +
21609 + if (!status) {
21610 + printk(KERN_ERR
21611 + "%s: ieee80211_tx_status called with NULL status\n",
21612 + dev->name);
21613 + dev_kfree_skb(skb);
21614 + return;
21615 + }
21616 +
21617 + if (status->excessive_retries) {
21618 + struct sta_info *sta;
21619 + sta = sta_info_get(local, hdr->addr1);
21620 + if (sta) {
21621 + if (sta->flags & WLAN_STA_PS) {
21622 + /* The STA is in power save mode, so assume
21623 + * that this TX packet failed because of that.
21624 + */
21625 + status->excessive_retries = 0;
21626 + status->tx_filtered = 1;
21627 + }
21628 + sta_info_release(local, sta);
21629 + }
21630 + }
21631 +
21632 + if (status->tx_filtered) {
21633 + struct sta_info *sta;
21634 + sta = sta_info_get(local, hdr->addr1);
21635 + if (sta) {
21636 + sta->tx_filtered_count++;
21637 +
21638 + /* Clear the TX filter mask for this STA when sending
21639 + * the next packet. If the STA went to power save mode,
21640 + * this will happen when it is waking up for the next
21641 + * time. */
21642 + sta->clear_dst_mask = 1;
21643 +
21644 + /* TODO: Is the WLAN_STA_PS flag always set here or is
21645 + * the race between RX and TX status causing some
21646 + * packets to be filtered out before 80211.o gets an
21647 + * update for PS status? This seems to be the case, so
21648 + * no changes are likely to be needed. */
21649 + if (sta->flags & WLAN_STA_PS &&
21650 + skb_queue_len(&sta->tx_filtered) <
21651 + STA_MAX_TX_BUFFER) {
21652 + ieee80211_remove_tx_extra(local, sta->key,
21653 + skb,
21654 + &status->control);
21655 + skb_queue_tail(&sta->tx_filtered, skb);
21656 + } else if (!(sta->flags & WLAN_STA_PS) &&
21657 + !status->control.requeue) {
21658 + /* Software retry the packet once */
21659 + status->control.requeue = 1;
21660 + ieee80211_remove_tx_extra(local, sta->key,
21661 + skb,
21662 + &status->control);
21663 + dev_queue_xmit(skb);
21664 + } else {
21665 + if (net_ratelimit()) {
21666 + printk(KERN_DEBUG "%s: dropped TX "
21667 + "filtered frame queue_len=%d "
21668 + "PS=%d @%lu\n",
21669 + dev->name,
21670 + skb_queue_len(
21671 + &sta->tx_filtered),
21672 + !!(sta->flags & WLAN_STA_PS),
21673 + jiffies);
21674 + }
21675 + dev_kfree_skb(skb);
21676 + }
21677 + sta_info_release(local, sta);
21678 + return;
21679 + }
21680 + } else {
21681 + rate_control_tx_status(dev, skb, status);
21682 + }
21683 +
21684 +#ifdef IEEE80211_LEDS
21685 + if (local->tx_led_counter && (local->tx_led_counter-- == 1)) {
21686 + ieee80211_tx_led(0, dev);
21687 + }
21688 +#endif /* IEEE80211_LEDS */
21689 + /* SNMP counters
21690 + * Fragments are passed to low-level drivers as separate skbs, so these
21691 + * are actually fragments, not frames. Update frame counters only for
21692 + * the first fragment of the frame. */
21693 +
21694 + frag = WLAN_GET_SEQ_FRAG(le16_to_cpu(hdr->seq_ctrl));
21695 + type = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_control));
21696 +
21697 + if (status->ack) {
21698 + if (frag == 0) {
21699 + local->dot11TransmittedFrameCount++;
21700 + if (MULTICAST_ADDR(hdr->addr1))
21701 + local->dot11MulticastTransmittedFrameCount++;
21702 + if (status->retry_count > 0)
21703 + local->dot11RetryCount++;
21704 + if (status->retry_count > 1)
21705 + local->dot11MultipleRetryCount++;
21706 + }
21707 +
21708 + /* This counter shall be incremented for an acknowledged MPDU
21709 + * with an individual address in the address 1 field or an MPDU
21710 + * with a multicast address in the address 1 field of type Data
21711 + * or Management. */
21712 + if (!MULTICAST_ADDR(hdr->addr1) || type == WLAN_FC_TYPE_DATA ||
21713 + type == WLAN_FC_TYPE_MGMT)
21714 + local->dot11TransmittedFragmentCount++;
21715 + } else {
21716 + if (frag == 0)
21717 + local->dot11FailedCount++;
21718 + }
21719 +
21720 + if (!status->control.req_tx_status) {
21721 + dev_kfree_skb(skb);
21722 + return;
21723 + }
21724 +
21725 + msg_type = status->ack ? ieee80211_msg_tx_callback_ack :
21726 + ieee80211_msg_tx_callback_fail;
21727 +
21728 + /* skb was the original skb used for TX. Clone it and give the clone
21729 + * to netif_rx(). Free original skb. */
21730 + skb2 = skb_copy(skb, GFP_ATOMIC);
21731 + if (!skb2) {
21732 + dev_kfree_skb(skb);
21733 + return;
21734 + }
21735 + dev_kfree_skb(skb);
21736 + skb = skb2;
21737 +
21738 + /* Send frame to hostapd */
21739 + ieee80211_rx_mgmt(dev, skb, NULL, msg_type);
21740 +}
21741 +
21742 +
21743 +/* TODO: implement register/unregister functions for adding TX/RX handlers
21744 + * into ordered list */
21745 +
21746 +static ieee80211_rx_handler ieee80211_rx_handlers[] =
21747 +{
21748 + ieee80211_rx_h_parse_qos,
21749 + ieee80211_rx_h_load_stats,
21750 + ieee80211_rx_h_monitor,
21751 + ieee80211_rx_h_passive_scan,
21752 + ieee80211_rx_h_check,
21753 + ieee80211_rx_h_sta_process,
21754 + ieee80211_rx_h_ccmp_decrypt,
21755 + ieee80211_rx_h_tkip_decrypt,
21756 + ieee80211_rx_h_wep_weak_iv_detection,
21757 + ieee80211_rx_h_wep_decrypt,
21758 + ieee80211_rx_h_defragment,
21759 + ieee80211_rx_h_ieee80211_rx_h_ps_poll,
21760 + ieee80211_rx_h_michael_mic_verify,
21761 + /* this must be after decryption - so header is counted in MPDU mic
21762 + * must be before pae and data, so QOS_DATA format frames
21763 + * are not passed to user space by these functions
21764 + */
21765 + ieee80211_rx_h_remove_qos_control,
21766 + ieee80211_rx_h_802_1x_pae,
21767 + ieee80211_rx_h_drop_unencrypted,
21768 + ieee80211_rx_h_data,
21769 + ieee80211_rx_h_mgmt,
21770 + NULL
21771 +};
21772 +
21773 +static ieee80211_tx_handler ieee80211_tx_handlers[] =
21774 +{
21775 + ieee80211_tx_h_rate_limit,
21776 + ieee80211_tx_h_check_assoc,
21777 + ieee80211_tx_h_ps_buf,
21778 + ieee80211_tx_h_select_key,
21779 + ieee80211_tx_h_michael_mic_add,
21780 + ieee80211_tx_h_fragment,
21781 + ieee80211_tx_h_tkip_encrypt,
21782 + ieee80211_tx_h_ccmp_encrypt,
21783 + ieee80211_tx_h_wep_encrypt,
21784 + ieee80211_tx_h_rate_ctrl,
21785 + ieee80211_tx_h_misc,
21786 + ieee80211_tx_h_load_stats,
21787 + NULL
21788 +};
21789 +
21790 +
21791 +static void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
21792 +{
21793 + /* Default values for sub-interface parameters */
21794 + sdata->drop_unencrypted = 0;
21795 + sdata->eapol = 1;
21796 +}
21797 +
21798 +
21799 +static struct net_device *ieee80211_if_add(struct net_device *dev,
21800 + const char *name, int locked)
21801 +{
21802 + struct net_device *wds_dev = NULL, *tmp_dev;
21803 + struct ieee80211_local *local = dev->priv;
21804 + struct ieee80211_sub_if_data *sdata = NULL, *sdata_parent;
21805 + int alloc_size;
21806 + int ret;
21807 + int i;
21808 +
21809 + /* ensure 32-bit alignment of our private data and hw private data */
21810 + alloc_size = sizeof(struct net_device) + 3 +
21811 + sizeof(struct ieee80211_sub_if_data) + 3;
21812 +
21813 + wds_dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
21814 + if (wds_dev == NULL)
21815 + return NULL;
21816 +
21817 + memset(wds_dev, 0, alloc_size);
21818 + wds_dev->priv = local;
21819 + ether_setup(wds_dev);
21820 + if (strlen(name) == 0) {
21821 + i = 0;
21822 + do {
21823 + sprintf(wds_dev->name, "%s.%d", dev->name, i++);
21824 + tmp_dev = dev_get_by_name(wds_dev->name);
21825 + if (tmp_dev == NULL)
21826 + break;
21827 + dev_put(tmp_dev);
21828 + } while (i < 10000);
21829 + } else {
21830 + snprintf(wds_dev->name, IFNAMSIZ, "%s", name);
21831 + }
21832 +
21833 + memcpy(wds_dev->dev_addr, dev->dev_addr, ETH_ALEN);
21834 + wds_dev->hard_start_xmit = ieee80211_subif_start_xmit;
21835 + wds_dev->wireless_handlers =
21836 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
21837 + wds_dev->do_ioctl = ieee80211_ioctl;
21838 + wds_dev->change_mtu = ieee80211_change_mtu;
21839 + wds_dev->tx_timeout = ieee80211_tx_timeout;
21840 + wds_dev->get_stats = ieee80211_get_stats;
21841 + wds_dev->open = ieee80211_open;
21842 + wds_dev->stop = ieee80211_stop;
21843 + wds_dev->base_addr = dev->base_addr;
21844 + wds_dev->irq = dev->irq;
21845 + wds_dev->mem_start = dev->mem_start;
21846 + wds_dev->mem_end = dev->mem_end;
21847 + wds_dev->tx_queue_len = 0;
21848 +
21849 + sdata = IEEE80211_DEV_TO_SUB_IF(wds_dev);
21850 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
21851 + sdata->master = local->mdev;
21852 + sdata->dev = wds_dev;
21853 + sdata->local = local;
21854 + memset(&sdata->stats, 0, sizeof(struct net_device_stats));
21855 + sdata_parent = IEEE80211_DEV_TO_SUB_IF(dev);
21856 + if (sdata_parent->type == IEEE80211_SUB_IF_TYPE_AP)
21857 + sdata->bss = &sdata_parent->u.ap;
21858 + else {
21859 + printk(KERN_DEBUG "%s: could not set BSS pointer for new "
21860 + "interface %s\n", dev->name, wds_dev->name);
21861 + }
21862 + ieee80211_if_sdata_init(sdata);
21863 +
21864 + if (locked)
21865 + ret = register_netdevice(wds_dev);
21866 + else
21867 + ret = register_netdev(wds_dev);
21868 + if (ret) {
21869 + kfree(wds_dev);
21870 + return NULL;
21871 + }
21872 +
21873 + list_add(&sdata->list, &local->sub_if_list);
21874 +
21875 + return wds_dev;
21876 +}
21877 +
21878 +
21879 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
21880 + struct ieee80211_if_wds *wds, int locked)
21881 +{
21882 + struct net_device *wds_dev = NULL;
21883 + struct ieee80211_sub_if_data *sdata = NULL;
21884 +
21885 + if (strlen(name) != 0) {
21886 + wds_dev = dev_get_by_name(name);
21887 + if (wds_dev) {
21888 + dev_put(wds_dev);
21889 + return -EEXIST;
21890 + }
21891 + }
21892 +
21893 + wds_dev = ieee80211_if_add(dev, name, locked);
21894 + if (wds_dev == NULL)
21895 + return -ENOANO;
21896 +
21897 + sdata = IEEE80211_DEV_TO_SUB_IF(wds_dev);
21898 + sdata->type = IEEE80211_SUB_IF_TYPE_WDS;
21899 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
21900 +
21901 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
21902 + printk(KERN_DEBUG
21903 + "%s: Added WDS Link to " MACSTR "\n",
21904 + wds_dev->name, MAC2STR(sdata->u.wds.remote_addr));
21905 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
21906 +
21907 + ieee80211_proc_init_virtual(wds_dev);
21908 +
21909 + return 0;
21910 +}
21911 +
21912 +
21913 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
21914 + struct ieee80211_if_wds *wds, int locked)
21915 +{
21916 + struct net_device *wds_dev = NULL;
21917 + struct ieee80211_local *local = dev->priv;
21918 + struct ieee80211_sub_if_data *sdata = NULL;
21919 + struct sta_info *sta;
21920 + struct list_head *ptr;
21921 +
21922 + list_for_each(ptr, &local->sub_if_list) {
21923 + sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
21924 + if (strcmp(name, sdata->dev->name) == 0) {
21925 + wds_dev = sdata->dev;
21926 + break;
21927 + }
21928 + }
21929 +
21930 + if (wds_dev == NULL || sdata->type != IEEE80211_SUB_IF_TYPE_WDS)
21931 + return -ENODEV;
21932 +
21933 + /* Remove STA entry for the old peer */
21934 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
21935 + if (sta) {
21936 + sta_info_release(local, sta);
21937 + sta_info_free(local, sta, 0);
21938 + } else {
21939 + printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
21940 + "%s peer " MACSTR "\n",
21941 + dev->name, wds_dev->name,
21942 + MAC2STR(sdata->u.wds.remote_addr));
21943 + }
21944 +
21945 + /* Update WDS link data */
21946 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
21947 +
21948 + return 0;
21949 +}
21950 +
21951 +
21952 +static void ieee80211_if_init(struct net_device *dev)
21953 +{
21954 + struct ieee80211_local *local = dev->priv;
21955 +
21956 + spin_lock_init(&local->sub_if_lock);
21957 + INIT_LIST_HEAD(&local->sub_if_list);
21958 +}
21959 +
21960 +
21961 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
21962 + struct ieee80211_if_vlan *vlan, int locked)
21963 +{
21964 + struct net_device *vlan_dev = NULL;
21965 + struct ieee80211_sub_if_data *sdata = NULL;
21966 +
21967 + if (strlen(name) != 0) {
21968 + vlan_dev = dev_get_by_name(name);
21969 + if (vlan_dev) {
21970 + dev_put(vlan_dev);
21971 + return -EEXIST;
21972 + }
21973 + }
21974 +
21975 + vlan_dev = ieee80211_if_add(dev, name, locked);
21976 + if (vlan_dev == NULL)
21977 + return -ENOANO;
21978 +
21979 + sdata = IEEE80211_DEV_TO_SUB_IF(vlan_dev);
21980 + sdata->type = IEEE80211_SUB_IF_TYPE_VLAN;
21981 + ieee80211_proc_init_virtual(vlan_dev);
21982 + return 0;
21983 +}
21984 +
21985 +
21986 +static void ieee80211_if_ap_init(struct ieee80211_sub_if_data *sdata)
21987 +{
21988 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
21989 + sdata->u.ap.dtim_period = 2;
21990 + sdata->u.ap.force_unicast_rateidx = -1;
21991 + sdata->u.ap.max_ratectrl_rateidx = -1;
21992 + skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
21993 + sdata->bss = &sdata->u.ap;
21994 +}
21995 +
21996 +
21997 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
21998 + int locked)
21999 +{
22000 + struct ieee80211_local *local = dev->priv;
22001 + struct net_device *ap_dev = NULL;
22002 + struct ieee80211_sub_if_data *sdata = NULL;
22003 +
22004 + if (local->bss_dev_count >= local->conf.bss_count)
22005 + return -ENOBUFS;
22006 +
22007 + if (strlen(name) != 0) {
22008 + ap_dev = dev_get_by_name(name);
22009 + if (ap_dev) {
22010 + dev_put(ap_dev);
22011 + return -EEXIST;
22012 + }
22013 + }
22014 +
22015 + ap_dev = ieee80211_if_add(dev, name, locked);
22016 + if (ap_dev == NULL)
22017 + return -ENOANO;
22018 +
22019 + memcpy(ap_dev->dev_addr, bssid, ETH_ALEN);
22020 + sdata = IEEE80211_DEV_TO_SUB_IF(ap_dev);
22021 + ieee80211_if_ap_init(sdata);
22022 + ieee80211_proc_init_virtual(ap_dev);
22023 + spin_lock_bh(&local->sub_if_lock);
22024 + local->bss_devs[local->bss_dev_count] = ap_dev;
22025 + local->bss_dev_count++;
22026 + spin_unlock_bh(&local->sub_if_lock);
22027 +
22028 + return 0;
22029 +}
22030 +
22031 +
22032 +static void ieee80211_addr_inc(u8 *addr)
22033 +{
22034 + int pos = 5;
22035 + while (pos >= 0) {
22036 + addr[pos]++;
22037 + if (addr[pos] != 0)
22038 + break;
22039 + pos--;
22040 + }
22041 +}
22042 +
22043 +
22044 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked)
22045 +{
22046 + struct ieee80211_local *local = dev->priv;
22047 + struct net_device *sta_dev;
22048 + struct ieee80211_sub_if_data *sdata;
22049 + struct ieee80211_if_sta *ifsta;
22050 + int i;
22051 +
22052 + if (local->sta_dev_count >= local->conf.bss_count)
22053 + return -ENOBUFS;
22054 +
22055 + if (strlen(name) != 0) {
22056 + sta_dev = dev_get_by_name(name);
22057 + if (sta_dev) {
22058 + dev_put(sta_dev);
22059 + return -EEXIST;
22060 + }
22061 + }
22062 +
22063 + sta_dev = ieee80211_if_add(dev, name, locked);
22064 + if (sta_dev == NULL)
22065 + return -ENOANO;
22066 +
22067 + sdata = IEEE80211_DEV_TO_SUB_IF(sta_dev);
22068 + ifsta = &sdata->u.sta;
22069 + sdata->type = IEEE80211_SUB_IF_TYPE_STA;
22070 + ieee80211_proc_init_virtual(sta_dev);
22071 +
22072 + spin_lock_bh(&local->sub_if_lock);
22073 + for (i = 0; i < local->conf.bss_count; i++) {
22074 + if (local->sta_devs[i] == NULL) {
22075 + local->sta_devs[i] = sta_dev;
22076 + local->sta_dev_count++;
22077 + printk(KERN_DEBUG "%s: using STA entry %d\n",
22078 + sta_dev->name, i);
22079 + while (i > 0) {
22080 + ieee80211_addr_inc(sta_dev->dev_addr);
22081 + i--;
22082 + }
22083 + printk(KERN_DEBUG "%s: MAC address " MACSTR "\n",
22084 + sta_dev->name, MAC2STR(sta_dev->dev_addr));
22085 + break;
22086 + }
22087 + }
22088 + spin_unlock_bh(&local->sub_if_lock);
22089 +
22090 + init_timer(&ifsta->timer);
22091 + ifsta->timer.data = (unsigned long) sta_dev;
22092 + ifsta->timer.function = ieee80211_sta_timer;
22093 +
22094 + ifsta->capab = WLAN_CAPABILITY_ESS;
22095 + ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
22096 + IEEE80211_AUTH_ALG_SHARED_KEY;
22097 + ifsta->create_ibss = 1;
22098 + ifsta->wmm_enabled = 1;
22099 +
22100 + return 0;
22101 +}
22102 +
22103 +
22104 +static void ieee80211_if_del(struct ieee80211_local *local,
22105 + struct ieee80211_sub_if_data *sdata, int locked)
22106 +{
22107 + struct sta_info *sta;
22108 + u8 addr[ETH_ALEN];
22109 + int i, j;
22110 + struct list_head *ptr, *n;
22111 +
22112 + memset(addr, 0xff, ETH_ALEN);
22113 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
22114 + if (!sdata->keys[i])
22115 + continue;
22116 +#if 0
22117 + /* Low-level driver has probably disabled hw
22118 + * already, so there is not really much point
22119 + * in disabling the keys at this point. */
22120 + if (local->hw->set_key)
22121 + local->hw->set_key(dev, DISABLE_KEY, addr,
22122 + local->keys[i], 0);
22123 +#endif
22124 + kfree(sdata->keys[i]);
22125 + }
22126 +
22127 + switch (sdata->type) {
22128 + case IEEE80211_SUB_IF_TYPE_AP:
22129 + /* Remove all virtual interfaces that use this BSS
22130 + * as their sdata->bss */
22131 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22132 + struct ieee80211_sub_if_data *tsdata =
22133 + list_entry(ptr, struct ieee80211_sub_if_data,
22134 + list);
22135 +
22136 + if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
22137 + printk(KERN_DEBUG "%s: removing virtual "
22138 + "interface %s because its BSS interface"
22139 + " is being removed\n",
22140 + sdata->dev->name, tsdata->dev->name);
22141 + ieee80211_if_del(local, tsdata, locked);
22142 + }
22143 + }
22144 +
22145 + kfree(sdata->u.ap.beacon_head);
22146 + kfree(sdata->u.ap.beacon_tail);
22147 + spin_lock_bh(&local->sub_if_lock);
22148 + for (j = 0; j < local->bss_dev_count; j++) {
22149 + if (sdata->dev == local->bss_devs[j]) {
22150 + if (j + 1 < local->bss_dev_count) {
22151 + memcpy(&local->bss_devs[j],
22152 + &local->bss_devs[j + 1],
22153 + (local->bss_dev_count - j - 1) *
22154 + sizeof(local->bss_devs[0]));
22155 + local->bss_devs[local->bss_dev_count -
22156 + 1] = NULL;
22157 + } else
22158 + local->bss_devs[j] = NULL;
22159 + local->bss_dev_count--;
22160 + break;
22161 + }
22162 + }
22163 + spin_unlock_bh(&local->sub_if_lock);
22164 +
22165 + if (sdata->dev != local->mdev) {
22166 + struct sk_buff *skb;
22167 + while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
22168 + local->total_ps_buffered--;
22169 + dev_kfree_skb(skb);
22170 + }
22171 + }
22172 +
22173 + break;
22174 + case IEEE80211_SUB_IF_TYPE_WDS:
22175 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22176 + if (sta) {
22177 + sta_info_release(local, sta);
22178 + sta_info_free(local, sta, 0);
22179 + } else {
22180 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
22181 + printk(KERN_DEBUG "%s: Someone had deleted my STA "
22182 + "entry for the WDS link\n", local->mdev->name);
22183 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
22184 + }
22185 + break;
22186 + case IEEE80211_SUB_IF_TYPE_STA:
22187 + del_timer_sync(&sdata->u.sta.timer);
22188 + if (local->scan_timer.data == (unsigned long) sdata->dev)
22189 + del_timer_sync(&local->scan_timer);
22190 + kfree(sdata->u.sta.extra_ie);
22191 + sdata->u.sta.extra_ie = NULL;
22192 + kfree(sdata->u.sta.assocreq_ies);
22193 + sdata->u.sta.assocreq_ies = NULL;
22194 + kfree(sdata->u.sta.assocresp_ies);
22195 + sdata->u.sta.assocresp_ies = NULL;
22196 + if (sdata->u.sta.probe_resp) {
22197 + dev_kfree_skb(sdata->u.sta.probe_resp);
22198 + sdata->u.sta.probe_resp = NULL;
22199 + }
22200 + for (i = 0; i < local->conf.bss_count; i++) {
22201 + if (local->sta_devs[i] == sdata->dev) {
22202 + local->sta_devs[i] = NULL;
22203 + local->sta_dev_count--;
22204 + break;
22205 + }
22206 + }
22207 +
22208 + break;
22209 + }
22210 +
22211 + /* remove all STAs that are bound to this virtual interface */
22212 + sta_info_flush(local, sdata->dev);
22213 +
22214 + list_del(&sdata->list);
22215 + ieee80211_proc_deinit_virtual(sdata->dev);
22216 + if (locked)
22217 + unregister_netdevice(sdata->dev);
22218 + else
22219 + unregister_netdev(sdata->dev);
22220 + /* Default data device and management device are allocated with the
22221 + * master device. All other devices are separately allocated and will
22222 + * be freed here. */
22223 + if (sdata->dev != local->mdev && sdata->dev != local->wdev &&
22224 + sdata->dev != local->apdev)
22225 + kfree(sdata->dev);
22226 +}
22227 +
22228 +
22229 +static int ieee80211_if_remove(struct net_device *dev, const char *name,
22230 + int id, int locked)
22231 +{
22232 + struct ieee80211_local *local = dev->priv;
22233 + struct list_head *ptr, *n;
22234 +
22235 + /* Make sure not to touch sdata->master since it may
22236 + * have already been deleted, etc. */
22237 +
22238 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22239 + struct ieee80211_sub_if_data *sdata =
22240 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22241 +
22242 + if (sdata->type == id && strcmp(name, sdata->dev->name) == 0) {
22243 + ieee80211_if_del(local, sdata, locked);
22244 + break;
22245 + }
22246 + }
22247 +
22248 + return 0;
22249 +}
22250 +
22251 +
22252 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name,
22253 + int locked)
22254 +{
22255 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_WDS,
22256 + locked);
22257 +}
22258 +
22259 +
22260 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name,
22261 + int locked)
22262 +{
22263 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_VLAN,
22264 + locked);
22265 +}
22266 +
22267 +
22268 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name,
22269 + int locked)
22270 +{
22271 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_AP,
22272 + locked);
22273 +}
22274 +
22275 +
22276 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name,
22277 + int locked)
22278 +{
22279 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_STA,
22280 + locked);
22281 +}
22282 +
22283 +
22284 +int ieee80211_if_flush(struct net_device *dev, int locked)
22285 +{
22286 + struct ieee80211_local *local = dev->priv;
22287 + struct list_head *ptr, *n;
22288 +
22289 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22290 + struct ieee80211_sub_if_data *sdata =
22291 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22292 +
22293 + if (sdata->dev != local->mdev &&
22294 + sdata->dev != local->wdev &&
22295 + sdata->dev != local->apdev)
22296 + ieee80211_if_del(local, sdata, locked);
22297 + }
22298 +
22299 + return 0;
22300 +}
22301 +
22302 +
22303 +static void ieee80211_precalc_rates(struct ieee80211_hw *hw)
22304 +{
22305 + struct ieee80211_hw_modes *mode;
22306 + struct ieee80211_rate *rate;
22307 + int m, r;
22308 +
22309 + for (m = 0; m < hw->num_modes; m++) {
22310 + mode = &hw->modes[m];
22311 + for (r = 0; r < mode->num_rates; r++) {
22312 + rate = &mode->rates[r];
22313 + rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
22314 + }
22315 + }
22316 +}
22317 +
22318 +
22319 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
22320 + void (*setup)(struct net_device *))
22321 +{
22322 + struct net_device *dev, *apdev, *mdev;
22323 + struct ieee80211_local *local;
22324 + struct ieee80211_sub_if_data *sdata;
22325 + int alloc_size;
22326 +
22327 + /* Ensure 32-bit alignment of our private data and hw private data.
22328 + * Each net_device is followed by a sub_if_data which which is used
22329 + * for wds/vlan information; it is aligned as well.
22330 + *
22331 + * Sample memory map looks something like:
22332 + *
22333 + * 0000 *****************
22334 + * * net_dev *
22335 + * 015c *****************
22336 + * * sub_if *
22337 + * 017c *****************
22338 + * * local *
22339 + * 0b84 *****************
22340 + * * hw_priv *
22341 + * 1664 *****************
22342 + * * ap net_dev *
22343 + * 17c0 *****************
22344 + * * sub_if *
22345 + * *****************
22346 + * * master net_dev*
22347 + * *****************
22348 + * * sub_if *
22349 + * *****************
22350 + */
22351 + alloc_size = sizeof(struct net_device) +
22352 + sizeof(struct ieee80211_sub_if_data) + 3 +
22353 + sizeof(struct ieee80211_local) + 3 +
22354 + priv_data_len + 3 +
22355 + sizeof(struct net_device) + 3 +
22356 + sizeof(struct ieee80211_sub_if_data) + 3 +
22357 + sizeof(struct net_device) + 3 +
22358 + sizeof(struct ieee80211_sub_if_data) + 3 +
22359 + 4096;
22360 + mdev = (struct net_device *) kzalloc(alloc_size, GFP_KERNEL);
22361 + if (mdev == NULL)
22362 + return NULL;
22363 +
22364 + mdev->priv = (struct net_device *)
22365 + ((char *) mdev +
22366 + ((sizeof(struct net_device) + 3) & ~3) +
22367 + ((sizeof(struct ieee80211_sub_if_data) + 3) & ~3));
22368 + local = mdev->priv;
22369 + local->hw_priv = (void *)
22370 + ((char *) local + ((sizeof(struct ieee80211_local) + 3) & ~3));
22371 + apdev = (struct net_device *)
22372 + ((char *) local->hw_priv + ((priv_data_len + 3) & ~3));
22373 + dev = (struct net_device *)
22374 + ((char *) apdev +
22375 + ((sizeof(struct net_device) + 3) & ~3) +
22376 + ((sizeof(struct ieee80211_sub_if_data) + 3) & ~3));
22377 + dev->priv = local;
22378 +
22379 + ether_setup(dev);
22380 + memcpy(dev->name, "wlan%d", 7);
22381 +
22382 + dev->hard_start_xmit = ieee80211_subif_start_xmit;
22383 + dev->wireless_handlers =
22384 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
22385 + dev->do_ioctl = ieee80211_ioctl;
22386 + dev->change_mtu = ieee80211_change_mtu;
22387 + dev->tx_timeout = ieee80211_tx_timeout;
22388 + dev->get_stats = ieee80211_get_stats;
22389 + dev->open = ieee80211_open;
22390 + dev->stop = ieee80211_stop;
22391 + dev->tx_queue_len = 0;
22392 + dev->set_mac_address = ieee80211_set_mac_address;
22393 +
22394 + local->dev_index = -1;
22395 + local->wdev = dev;
22396 + local->mdev = mdev;
22397 + local->rx_handlers = ieee80211_rx_handlers;
22398 + local->tx_handlers = ieee80211_tx_handlers;
22399 +
22400 + local->bridge_packets = 1;
22401 +
22402 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
22403 + local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
22404 + local->short_retry_limit = 7;
22405 + local->long_retry_limit = 4;
22406 + local->conf.calib_int = 60;
22407 + local->rate_ctrl_num_up = RATE_CONTROL_NUM_UP;
22408 + local->rate_ctrl_num_down = RATE_CONTROL_NUM_DOWN;
22409 + local->conf.bss_count = 1;
22410 + memset(local->conf.bssid_mask, 0xff, ETH_ALEN);
22411 + local->bss_devs = kmalloc(sizeof(struct net_device *), GFP_KERNEL);
22412 + if (local->bss_devs == NULL)
22413 + goto fail;
22414 + local->bss_devs[0] = local->wdev;
22415 + local->bss_dev_count = 1;
22416 + local->sta_devs = kmalloc(sizeof(struct net_device *), GFP_KERNEL);
22417 + if (local->sta_devs == NULL)
22418 + goto fail;
22419 + local->sta_devs[0] = NULL;
22420 +
22421 + local->scan.in_scan = 0;
22422 + local->hw_modes = (unsigned int) -1;
22423 +
22424 + init_timer(&local->scan.timer); /* clear it out */
22425 +
22426 + spin_lock_init(&local->generic_lock);
22427 + init_timer(&local->rate_limit_timer);
22428 + local->rate_limit_timer.function = ieee80211_rate_limit;
22429 + local->rate_limit_timer.data = (unsigned long) local;
22430 + init_timer(&local->stat_timer);
22431 + local->stat_timer.function = ieee80211_stat_refresh;
22432 + local->stat_timer.data = (unsigned long) local;
22433 + ieee80211_rx_bss_list_init(dev);
22434 +
22435 + sta_info_init(local);
22436 +
22437 + ieee80211_if_init(dev);
22438 +
22439 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22440 + sdata->dev = dev;
22441 + sdata->master = mdev;
22442 + sdata->local = local;
22443 + ieee80211_if_sdata_init(sdata);
22444 + ieee80211_if_ap_init(sdata);
22445 + list_add_tail(&sdata->list, &local->sub_if_list);
22446 +
22447 + if (strlen(dev->name) + 2 >= sizeof(dev->name))
22448 + goto fail;
22449 +
22450 + apdev = (struct net_device *)
22451 + ((char *) local->hw_priv + ((priv_data_len + 3) & ~3));
22452 + local->apdev = apdev;
22453 + ether_setup(apdev);
22454 + apdev->priv = local;
22455 + apdev->hard_start_xmit = ieee80211_mgmt_start_xmit;
22456 + apdev->change_mtu = ieee80211_change_mtu_apdev;
22457 + apdev->get_stats = ieee80211_get_stats;
22458 + apdev->open = ieee80211_open;
22459 + apdev->stop = ieee80211_stop;
22460 + apdev->type = ARPHRD_IEEE80211_PRISM;
22461 + apdev->hard_header_parse = header_parse_80211;
22462 + apdev->tx_queue_len = 0;
22463 + sprintf(apdev->name, "%sap", dev->name);
22464 +
22465 + sdata = IEEE80211_DEV_TO_SUB_IF(apdev);
22466 + sdata->type = IEEE80211_SUB_IF_TYPE_MGMT;
22467 + sdata->dev = apdev;
22468 + sdata->master = mdev;
22469 + sdata->local = local;
22470 + list_add_tail(&sdata->list, &local->sub_if_list);
22471 +
22472 + ether_setup(mdev);
22473 + mdev->hard_start_xmit = ieee80211_master_start_xmit;
22474 + mdev->wireless_handlers =
22475 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
22476 + mdev->do_ioctl = ieee80211_ioctl;
22477 + mdev->change_mtu = ieee80211_change_mtu;
22478 + mdev->tx_timeout = ieee80211_tx_timeout;
22479 + mdev->get_stats = ieee80211_get_stats;
22480 + mdev->open = ieee80211_open;
22481 + mdev->stop = ieee80211_stop;
22482 + mdev->type = ARPHRD_IEEE80211;
22483 + mdev->hard_header_parse = header_parse_80211;
22484 + sprintf(mdev->name, "%s.11", dev->name);
22485 +
22486 + sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
22487 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
22488 + sdata->dev = mdev;
22489 + sdata->master = mdev;
22490 + sdata->local = local;
22491 + list_add_tail(&sdata->list, &local->sub_if_list);
22492 +
22493 + tasklet_init(&local->tasklet,
22494 + ieee80211_tasklet_handler,
22495 + (unsigned long) local);
22496 + skb_queue_head_init(&local->skb_queue);
22497 + skb_queue_head_init(&local->skb_queue_unreliable);
22498 +
22499 + if (setup)
22500 + setup(mdev);
22501 +
22502 + return mdev;
22503 +
22504 + fail:
22505 + ieee80211_free_hw(mdev);
22506 + return NULL;
22507 +}
22508 +
22509 +
22510 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw)
22511 +{
22512 + struct ieee80211_local *local = dev->priv;
22513 + int result;
22514 +
22515 + if (!hw)
22516 + return -1;
22517 +
22518 + if (hw->version != IEEE80211_VERSION) {
22519 + printk("ieee80211_register_hw - version mismatch: 80211.o "
22520 + "version %d, low-level driver version %d\n",
22521 + IEEE80211_VERSION, hw->version);
22522 + return -1;
22523 + }
22524 +
22525 + result = ieee80211_dev_alloc_index(local);
22526 + if (result < 0)
22527 + return -1;
22528 +
22529 + local->class_dev.dev = dev->class_dev.dev;
22530 + result = ieee80211_register_sysfs(local);
22531 + if (result < 0)
22532 + goto fail_sysfs;
22533 +
22534 + local->conf.mode = IW_MODE_MASTER;
22535 + local->conf.beacon_int = 1000;
22536 +
22537 + ieee80211_update_hw(dev, hw); /* Don't care about the result. */
22538 +
22539 + sta_info_start(local);
22540 +
22541 + result = register_netdev(local->wdev);
22542 + if (result < 0)
22543 + goto fail_1st_dev;
22544 +
22545 + result = register_netdev(local->apdev);
22546 + if (result < 0)
22547 + goto fail_2nd_dev;
22548 +
22549 + if (hw->fraglist)
22550 + dev->features |= NETIF_F_FRAGLIST;
22551 + result = register_netdev(dev);
22552 + if (result < 0)
22553 + goto fail_3rd_dev;
22554 +
22555 + if (rate_control_initialize(local) < 0) {
22556 + printk(KERN_DEBUG "%s: Failed to initialize rate control "
22557 + "algorithm\n", dev->name);
22558 + goto fail_rate;
22559 + }
22560 +
22561 + /* TODO: add rtnl locking around device creation and qdisc install */
22562 + ieee80211_install_qdisc(dev);
22563 +
22564 + ieee80211_wep_init(local);
22565 + ieee80211_proc_init_interface(local);
22566 + return 0;
22567 +
22568 +fail_rate:
22569 + unregister_netdev(dev);
22570 +fail_3rd_dev:
22571 + unregister_netdev(local->apdev);
22572 +fail_2nd_dev:
22573 + unregister_netdev(local->wdev);
22574 +fail_1st_dev:
22575 + sta_info_stop(local);
22576 + ieee80211_unregister_sysfs(local);
22577 +fail_sysfs:
22578 + ieee80211_dev_free_index(local);
22579 + return result;
22580 +}
22581 +
22582 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw)
22583 +{
22584 + struct ieee80211_local *local = dev->priv;
22585 +
22586 + local->hw = hw;
22587 +
22588 + /* Backwards compatibility for low-level drivers that do not set number
22589 + * of TX queues. */
22590 + if (hw->queues == 0)
22591 + hw->queues = 1;
22592 +
22593 + memcpy(local->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
22594 + local->apdev->base_addr = dev->base_addr;
22595 + local->apdev->irq = dev->irq;
22596 + local->apdev->mem_start = dev->mem_start;
22597 + local->apdev->mem_end = dev->mem_end;
22598 +
22599 + memcpy(local->wdev->dev_addr, dev->dev_addr, ETH_ALEN);
22600 + local->wdev->base_addr = dev->base_addr;
22601 + local->wdev->irq = dev->irq;
22602 + local->wdev->mem_start = dev->mem_start;
22603 + local->wdev->mem_end = dev->mem_end;
22604 +
22605 + if (!hw->modes || !hw->modes->channels || !hw->modes->rates ||
22606 + !hw->modes->num_channels || !hw->modes->num_rates)
22607 + return -1;
22608 +
22609 + ieee80211_precalc_rates(hw);
22610 + local->conf.phymode = hw->modes[0].mode;
22611 + local->curr_rates = hw->modes[0].rates;
22612 + local->num_curr_rates = hw->modes[0].num_rates;
22613 + ieee80211_prepare_rates(dev);
22614 +
22615 + local->conf.freq = local->hw->modes[0].channels[0].freq;
22616 + local->conf.channel = local->hw->modes[0].channels[0].chan;
22617 + local->conf.channel_val = local->hw->modes[0].channels[0].val;
22618 + /* FIXME: Invoke config to allow driver to set the channel. */
22619 +
22620 + return 0;
22621 +}
22622 +
22623 +
22624 +void ieee80211_unregister_hw(struct net_device *dev)
22625 +{
22626 + struct ieee80211_local *local = dev->priv;
22627 + struct list_head *ptr, *n;
22628 + int i;
22629 +
22630 + tasklet_disable(&local->tasklet);
22631 + /* TODO: skb_queue should be empty here, no need to do anything? */
22632 +
22633 + if (local->rate_limit)
22634 + del_timer_sync(&local->rate_limit_timer);
22635 + if (local->stat_time)
22636 + del_timer_sync(&local->stat_timer);
22637 + if (local->scan_timer.data)
22638 + del_timer_sync(&local->scan_timer);
22639 + ieee80211_rx_bss_list_deinit(dev);
22640 +
22641 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22642 + struct ieee80211_sub_if_data *sdata =
22643 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22644 + ieee80211_if_del(local, sdata, 0);
22645 + }
22646 +
22647 + sta_info_stop(local);
22648 + ieee80211_unregister_sysfs(local);
22649 +
22650 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
22651 + if (local->fragments[i].skb)
22652 + dev_kfree_skb(local->fragments[i].skb);
22653 +
22654 + for (i = 0; i < NUM_IEEE80211_MODES; i++) {
22655 + kfree(local->supp_rates[i]);
22656 + kfree(local->basic_rates[i]);
22657 + }
22658 +
22659 + kfree(local->conf.ssid);
22660 + kfree(local->conf.generic_elem);
22661 +
22662 + ieee80211_proc_deinit_interface(local);
22663 +
22664 + if (skb_queue_len(&local->skb_queue)
22665 + || skb_queue_len(&local->skb_queue_unreliable))
22666 + printk(KERN_WARNING "%s: skb_queue not empty", dev->name);
22667 + skb_queue_purge(&local->skb_queue);
22668 + skb_queue_purge(&local->skb_queue_unreliable);
22669 +
22670 + rate_control_free(local);
22671 + ieee80211_dev_free_index(local);
22672 +}
22673 +
22674 +void ieee80211_free_hw(struct net_device *dev)
22675 +{
22676 + struct ieee80211_local *local = dev->priv;
22677 +
22678 + kfree(local->sta_devs);
22679 + kfree(local->bss_devs);
22680 + kfree(dev);
22681 +}
22682 +
22683 +
22684 +/* Perform netif operations on all configured interfaces */
22685 +int ieee80211_netif_oper(struct net_device *sdev, Netif_Oper op)
22686 +{
22687 + struct ieee80211_local *local = sdev->priv;
22688 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sdev);
22689 + struct net_device *dev = sdata->master;
22690 +
22691 + switch (op) {
22692 + case NETIF_ATTACH:
22693 + netif_device_attach(dev);
22694 + break;
22695 + case NETIF_DETACH:
22696 + netif_device_detach(dev);
22697 + break;
22698 + case NETIF_START:
22699 + netif_start_queue(dev);
22700 + break;
22701 + case NETIF_STOP:
22702 + break;
22703 + case NETIF_WAKE:
22704 + if (local->scan.in_scan == 0) {
22705 + netif_wake_queue(dev);
22706 +#if 1
22707 + if (/* FIX: 802.11 qdisc in use */ 1)
22708 + __netif_schedule(dev);
22709 +#endif
22710 + }
22711 + break;
22712 + case NETIF_IS_STOPPED:
22713 + if (netif_queue_stopped(dev))
22714 + return 1;
22715 + break;
22716 + case NETIF_UPDATE_TX_START:
22717 + dev->trans_start = jiffies;
22718 + break;
22719 + }
22720 +
22721 + return 0;
22722 +}
22723 +
22724 +
22725 +void * ieee80211_dev_hw_data(struct net_device *dev)
22726 +{
22727 + struct ieee80211_local *local = dev->priv;
22728 + return local->hw_priv;
22729 +}
22730 +
22731 +
22732 +void * ieee80211_dev_stats(struct net_device *dev)
22733 +{
22734 + struct ieee80211_sub_if_data *sdata;
22735 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22736 + return &(sdata->stats);
22737 +}
22738 +
22739 +
22740 +int ieee80211_rate_control_register(struct rate_control_ops *ops)
22741 +{
22742 + struct rate_control_algs *alg;
22743 +
22744 + alg = kmalloc(sizeof(*alg), GFP_KERNEL);
22745 + if (alg == NULL) {
22746 + return -1;
22747 + }
22748 + memset(alg, 0, sizeof(*alg));
22749 + alg->next = ieee80211_rate_ctrl_algs;
22750 + alg->ops = ops;
22751 + ieee80211_rate_ctrl_algs = alg;
22752 +
22753 + return 0;
22754 +}
22755 +
22756 +
22757 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops)
22758 +{
22759 + struct rate_control_algs *alg, *prev;
22760 +
22761 + prev = NULL;
22762 + alg = ieee80211_rate_ctrl_algs;
22763 + while (alg) {
22764 + if (alg->ops == ops) {
22765 + if (prev)
22766 + prev->next = alg->next;
22767 + else
22768 + ieee80211_rate_ctrl_algs = alg->next;
22769 + kfree(alg);
22770 + break;
22771 + }
22772 + prev = alg;
22773 + alg = alg->next;
22774 + }
22775 +}
22776 +
22777 +
22778 +static int rate_control_initialize(struct ieee80211_local *local)
22779 +{
22780 + struct rate_control_algs *algs;
22781 +
22782 + if (!ieee80211_rate_ctrl_algs)
22783 + request_module("ieee80211_rate_control");
22784 +
22785 + for (algs = ieee80211_rate_ctrl_algs; algs; algs = algs->next) {
22786 + local->rate_ctrl = algs->ops;
22787 + local->rate_ctrl_priv = rate_control_alloc(local);
22788 + if (local->rate_ctrl_priv) {
22789 + printk(KERN_DEBUG "%s: Selected rate control "
22790 + "algorithm '%s'\n", local->wdev->name,
22791 + local->rate_ctrl->name);
22792 + return 0;
22793 + }
22794 + }
22795 +
22796 + printk(KERN_WARNING "%s: Failed to select rate control algorithm\n",
22797 + local->wdev->name);
22798 + return -1;
22799 +}
22800 +
22801 +
22802 +static int __init ieee80211_init(void)
22803 +{
22804 + struct sk_buff *skb;
22805 + int ret;
22806 +
22807 + if (sizeof(struct ieee80211_tx_packet_data) > (sizeof(skb->cb))) {
22808 + printk("80211: ieee80211_tx_packet_data is bigger "
22809 + "than the skb->cb (%d > %d)\n",
22810 + (int) sizeof(struct ieee80211_tx_packet_data),
22811 + (int) sizeof(skb->cb));
22812 + return -EINVAL;
22813 + }
22814 + if ((ret = ieee80211_sysfs_init())) {
22815 + printk(KERN_WARNING "ieee80211_init: sysfs initialization "
22816 + "failed\n");
22817 + return ret;
22818 + }
22819 +
22820 + ieee80211_proc_init();
22821 + {
22822 + ret = ieee80211_wme_register();
22823 + if (ret) {
22824 + printk(KERN_DEBUG "ieee80211_init: failed to "
22825 + "initialize WME (err=%d)\n", ret);
22826 + ieee80211_proc_deinit();
22827 + return ret;
22828 + }
22829 + }
22830 +
22831 + return 0;
22832 +}
22833 +
22834 +
22835 +static void __exit ieee80211_exit(void)
22836 +{
22837 + ieee80211_wme_unregister();
22838 + ieee80211_proc_deinit();
22839 + ieee80211_sysfs_deinit();
22840 +}
22841 +
22842 +
22843 +EXPORT_SYMBOL(ieee80211_alloc_hw);
22844 +EXPORT_SYMBOL(ieee80211_register_hw);
22845 +EXPORT_SYMBOL(ieee80211_update_hw);
22846 +EXPORT_SYMBOL(ieee80211_unregister_hw);
22847 +EXPORT_SYMBOL(ieee80211_free_hw);
22848 +EXPORT_SYMBOL(__ieee80211_rx);
22849 +EXPORT_SYMBOL(ieee80211_tx_status);
22850 +EXPORT_SYMBOL(ieee80211_beacon_get);
22851 +EXPORT_SYMBOL(ieee80211_get_buffered_bc);
22852 +EXPORT_SYMBOL(ieee80211_netif_oper);
22853 +EXPORT_SYMBOL(ieee80211_dev_hw_data);
22854 +EXPORT_SYMBOL(ieee80211_dev_stats);
22855 +EXPORT_SYMBOL(ieee80211_get_hw_conf);
22856 +EXPORT_SYMBOL(ieee80211_set_aid_for_sta);
22857 +EXPORT_SYMBOL(ieee80211_rx_irqsafe);
22858 +EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
22859 +EXPORT_SYMBOL(ieee80211_get_hdrlen);
22860 +EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
22861 +EXPORT_SYMBOL(ieee80211_rate_control_register);
22862 +EXPORT_SYMBOL(ieee80211_rate_control_unregister);
22863 +EXPORT_SYMBOL(sta_info_get);
22864 +EXPORT_SYMBOL(sta_info_release);
22865 +EXPORT_SYMBOL(ieee80211_radar_status);
22866 +
22867 +module_init(ieee80211_init);
22868 +module_exit(ieee80211_exit);
22869 +
22870 +MODULE_DESCRIPTION("IEEE 802.11 subsystem");
22871 +MODULE_LICENSE("GPL");
22872 diff -Nur linux-2.6.16/net/d80211/ieee80211_dev.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_dev.c
22873 --- linux-2.6.16/net/d80211/ieee80211_dev.c 1970-01-01 01:00:00.000000000 +0100
22874 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_dev.c 2006-03-28 22:16:14.000000000 +0200
22875 @@ -0,0 +1,85 @@
22876 +/*
22877 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
22878 + *
22879 + * This program is free software; you can redistribute it and/or modify
22880 + * it under the terms of the GNU General Public License version 2 as
22881 + * published by the Free Software Foundation.
22882 + */
22883 +
22884 +#include <linux/kernel.h>
22885 +#include <linux/interrupt.h>
22886 +#include <linux/if.h>
22887 +#include <linux/if_ether.h>
22888 +#include <linux/netdevice.h>
22889 +#include <net/d80211.h>
22890 +#include "ieee80211_i.h"
22891 +
22892 +struct ieee80211_dev_list {
22893 + struct list_head list;
22894 + int dev_index;
22895 + struct ieee80211_local *local;
22896 +};
22897 +
22898 +static LIST_HEAD(dev_list);
22899 +static DEFINE_SPINLOCK(dev_list_lock);
22900 +
22901 +
22902 +/* Caller must hold dev_list_lock */
22903 +static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
22904 +{
22905 + struct ieee80211_dev_list *dev_item;
22906 +
22907 + list_for_each_entry(dev_item, &dev_list, list) {
22908 + if (dev_item->dev_index == index)
22909 + return dev_item;
22910 + }
22911 + return NULL;
22912 +}
22913 +
22914 +int ieee80211_dev_alloc_index(struct ieee80211_local *local)
22915 +{
22916 + struct list_head *i;
22917 + struct ieee80211_dev_list *dev_item, *new;
22918 + int index = 0;
22919 +
22920 + new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
22921 + if (!new)
22922 + return -ENOMEM;
22923 + new->local = local;
22924 + spin_lock(&dev_list_lock);
22925 + list_for_each(i, &dev_list) {
22926 + dev_item = list_entry(i, struct ieee80211_dev_list, list);
22927 + if (index < dev_item->dev_index)
22928 + break;
22929 + index++;
22930 + }
22931 + new->dev_index = index;
22932 + list_add_tail(&new->list, i);
22933 + spin_unlock(&dev_list_lock);
22934 + local->dev_index = index;
22935 + return index;
22936 +}
22937 +
22938 +void ieee80211_dev_free_index(struct ieee80211_local *local)
22939 +{
22940 + struct ieee80211_dev_list *dev_item;
22941 +
22942 + spin_lock(&dev_list_lock);
22943 + dev_item = __ieee80211_dev_find(local->dev_index);
22944 + if (dev_item)
22945 + list_del(&dev_item->list);
22946 + spin_unlock(&dev_list_lock);
22947 + if (dev_item)
22948 + kfree(dev_item);
22949 + local->dev_index = -1;
22950 +}
22951 +
22952 +struct ieee80211_local *ieee80211_dev_find(int index)
22953 +{
22954 + struct ieee80211_dev_list *dev_item;
22955 +
22956 + spin_lock(&dev_list_lock);
22957 + dev_item = __ieee80211_dev_find(index);
22958 + spin_unlock(&dev_list_lock);
22959 + return dev_item ? dev_item->local : NULL;
22960 +}
22961 diff -Nur linux-2.6.16/net/d80211/ieee80211_i.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_i.h
22962 --- linux-2.6.16/net/d80211/ieee80211_i.h 1970-01-01 01:00:00.000000000 +0100
22963 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_i.h 2006-03-28 22:16:14.000000000 +0200
22964 @@ -0,0 +1,596 @@
22965 +/*
22966 + * Copyright 2002-2005, Instant802 Networks, Inc.
22967 + * Copyright 2005, Devicescape Software, Inc.
22968 + *
22969 + * This program is free software; you can redistribute it and/or modify
22970 + * it under the terms of the GNU General Public License version 2 as
22971 + * published by the Free Software Foundation.
22972 + */
22973 +
22974 +#ifndef IEEE80211_I_H
22975 +#define IEEE80211_I_H
22976 +
22977 +#include <linux/kernel.h>
22978 +#include <linux/device.h>
22979 +#include <linux/if_ether.h>
22980 +#include <linux/interrupt.h>
22981 +#include <linux/list.h>
22982 +#include <linux/netdevice.h>
22983 +#include <linux/skbuff.h>
22984 +#include "ieee80211_key.h"
22985 +#include "sta_info.h"
22986 +
22987 +/* ieee80211.o internal definitions, etc. These are not included into
22988 + * low-level drivers. */
22989 +
22990 +#ifndef ETH_P_PAE
22991 +#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
22992 +#endif /* ETH_P_PAE */
22993 +
22994 +#define IEEE80211_MAX_SSID_LEN 32
22995 +
22996 +struct ieee80211_local;
22997 +
22998 +#define BIT(x) (1 << (x))
22999 +
23000 +#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
23001 +
23002 +
23003 +/* Maximum number of broadcast/multicast frames to buffer when some of the
23004 + * associated stations are using power saving. */
23005 +#define AP_MAX_BC_BUFFER 128
23006 +
23007 +/* Maximum number of frames buffered to all STAs, including multicast frames.
23008 + * Note: increasing this limit increases the potential memory requirement. Each
23009 + * frame can be up to about 2 kB long. */
23010 +#define TOTAL_MAX_TX_BUFFER 512
23011 +
23012 +
23013 +#define MAC2STR(a) ((a)[0] & 0xff), ((a)[1] & 0xff), ((a)[2] & 0xff), \
23014 + ((a)[3] & 0xff), ((a)[4] & 0xff), ((a)[5] & 0xff)
23015 +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
23016 +
23017 +#define MULTICAST_ADDR(a) ((a)[0] & 0x01)
23018 +
23019 +
23020 +/* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
23021 + * reception of at least three fragmented frames. This limit can be increased
23022 + * by changing this define, at the cost of slower frame reassembly and
23023 + * increased memory use (about 2 kB of RAM per entry). */
23024 +#define IEEE80211_FRAGMENT_MAX 4
23025 +
23026 +struct ieee80211_fragment_entry {
23027 + unsigned long first_frag_time;
23028 + unsigned int seq;
23029 + unsigned int rx_queue;
23030 + unsigned int last_frag;
23031 + struct sk_buff *skb;
23032 + int ccmp; /* Whether fragments were encrypted with CCMP */
23033 + u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
23034 +};
23035 +
23036 +
23037 +struct ieee80211_sta_bss {
23038 + struct list_head list;
23039 + struct ieee80211_sta_bss *hnext;
23040 + atomic_t users;
23041 +
23042 + u8 bssid[ETH_ALEN];
23043 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23044 + size_t ssid_len;
23045 + u16 capability; /* host byte order */
23046 + int hw_mode;
23047 + int channel;
23048 + int freq;
23049 + int rssi;
23050 + u8 *wpa_ie;
23051 + size_t wpa_ie_len;
23052 + u8 *rsn_ie;
23053 + size_t rsn_ie_len;
23054 + u8 *wmm_ie;
23055 + size_t wmm_ie_len;
23056 +#define IEEE80211_MAX_SUPP_RATES 32
23057 + u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
23058 + size_t supp_rates_len;
23059 + int beacon_int;
23060 + u64 timestamp;
23061 +
23062 + int probe_resp;
23063 + unsigned long last_update;
23064 +
23065 +};
23066 +
23067 +
23068 +typedef enum {
23069 + TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
23070 +} ieee80211_txrx_result;
23071 +
23072 +struct ieee80211_txrx_data {
23073 + struct sk_buff *skb;
23074 + struct net_device *dev;
23075 + struct ieee80211_local *local;
23076 + struct ieee80211_sub_if_data *sdata;
23077 + struct sta_info *sta;
23078 + u16 fc, ethertype;
23079 + struct ieee80211_key *key;
23080 + unsigned int fragmented:1; /* whether the MSDU was fragmented */
23081 + union {
23082 + struct {
23083 + struct ieee80211_tx_control *control;
23084 + int unicast:1;
23085 + int ps_buffered:1;
23086 + int short_preamble:1;
23087 + int probe_last_frag:1;
23088 + struct ieee80211_rate *rate;
23089 + /* use this rate (if set) for last fragment; rate can
23090 + * be set to lower rate for the first fragments, e.g.,
23091 + * when using CTS protection with IEEE 802.11g. */
23092 + struct ieee80211_rate *last_frag_rate;
23093 + int last_frag_rateidx;
23094 + int mgmt_interface;
23095 +
23096 + /* Extra fragments (in addition to the first fragment
23097 + * in skb) */
23098 + int num_extra_frag;
23099 + struct sk_buff **extra_frag;
23100 + } tx;
23101 + struct {
23102 + struct ieee80211_rx_status *status;
23103 + int sent_ps_buffered;
23104 + int queue;
23105 + } rx;
23106 + } u;
23107 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23108 + int wpa_test;
23109 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
23110 +};
23111 +
23112 +struct ieee80211_passive_scan {
23113 + unsigned int in_scan:1; /* this must be cleared before calling
23114 + * netif_oper(WAKEUP) */
23115 + unsigned int our_mode_only:1; /* only scan our physical mode a/b/g/etc
23116 + */
23117 + int interval; /* time in seconds between scans */
23118 + int time; /* time in microseconds to scan for */
23119 + int channel; /* channel to be scanned */
23120 + int tries;
23121 +
23122 + int mode_idx;
23123 + int chan_idx;
23124 +
23125 + int freq;
23126 + int rx_packets;
23127 + int rx_beacon;
23128 + int txrx_count;
23129 +
23130 + struct timer_list timer;
23131 +
23132 + struct sk_buff *skb; /* skb to transmit before changing channels,
23133 + * maybe null for none */
23134 + struct ieee80211_tx_control tx_control;
23135 +
23136 + unsigned int num_scans;
23137 +};
23138 +
23139 +typedef ieee80211_txrx_result (*ieee80211_tx_handler)
23140 +(struct ieee80211_txrx_data *tx);
23141 +
23142 +typedef ieee80211_txrx_result (*ieee80211_rx_handler)
23143 +(struct ieee80211_txrx_data *rx);
23144 +
23145 +struct ieee80211_if_ap {
23146 + u8 *beacon_head, *beacon_tail;
23147 + int beacon_head_len, beacon_tail_len;
23148 +
23149 + /* TODO: sta_aid could be replaced by 2008-bit large bitfield of
23150 + * that could be used in TIM element generation. This would also
23151 + * make TIM element generation a bit faster. */
23152 + /* AID mapping to station data. NULL, if AID is free. AID is in the
23153 + * range 1..2007 and sta_aid[i] corresponds to AID i+1. */
23154 + struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
23155 + int max_aid; /* largest aid currently in use */
23156 + atomic_t num_sta_ps; /* number of stations in PS mode */
23157 + struct sk_buff_head ps_bc_buf;
23158 + int dtim_period, dtim_count;
23159 + int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
23160 + int max_ratectrl_rateidx; /* max TX rateidx for rate control */
23161 + int num_beacons; /* number of TXed beacon frames for this BSS */
23162 +};
23163 +
23164 +struct ieee80211_if_wds {
23165 + u8 remote_addr[ETH_ALEN];
23166 + struct sta_info *sta;
23167 +};
23168 +
23169 +struct ieee80211_if_vlan {
23170 + u8 id;
23171 +};
23172 +
23173 +struct ieee80211_if_sta {
23174 + enum {
23175 + IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
23176 + IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
23177 + IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
23178 + } state;
23179 + struct timer_list timer;
23180 + u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
23181 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23182 + size_t ssid_len;
23183 + u16 aid;
23184 + u16 ap_capab, capab;
23185 + u8 *extra_ie; /* to be added to the end of AssocReq */
23186 + size_t extra_ie_len;
23187 +
23188 + /* The last AssocReq/Resp IEs */
23189 + u8 *assocreq_ies, *assocresp_ies;
23190 + size_t assocreq_ies_len, assocresp_ies_len;
23191 +
23192 + int auth_tries, assoc_tries;
23193 +
23194 + int ssid_set:1;
23195 + int bssid_set:1;
23196 + int prev_bssid_set:1;
23197 + int authenticated:1;
23198 + int associated:1;
23199 + int probereq_poll:1;
23200 + int use_protection:1;
23201 + int create_ibss:1;
23202 + int mixed_cell:1;
23203 + int wmm_enabled:1;
23204 +
23205 + int key_mgmt;
23206 + unsigned long last_probe;
23207 +
23208 +#define IEEE80211_AUTH_ALG_OPEN BIT(0)
23209 +#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
23210 +#define IEEE80211_AUTH_ALG_LEAP BIT(2)
23211 + unsigned int auth_algs; /* bitfield of allowed auth algs */
23212 + int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
23213 + int auth_transaction;
23214 +
23215 + unsigned long ibss_join_req;
23216 + struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
23217 + u32 supp_rates_bits;
23218 +
23219 + int wmm_last_param_set;
23220 +};
23221 +
23222 +
23223 +#define IEEE80211_SUB_IF_TYPE_AP 0x00000000
23224 +#define IEEE80211_SUB_IF_TYPE_MGMT 0x00000001
23225 +#define IEEE80211_SUB_IF_TYPE_STA 0x00000002
23226 +#define IEEE80211_SUB_IF_TYPE_WDS 0x5A580211
23227 +#define IEEE80211_SUB_IF_TYPE_VLAN 0x00080211
23228 +
23229 +struct ieee80211_sub_if_data {
23230 + struct list_head list;
23231 + unsigned int type;
23232 +
23233 + struct net_device *dev;
23234 + struct net_device *master;
23235 + struct ieee80211_local *local;
23236 +
23237 + struct net_device_stats stats;
23238 + int drop_unencrypted;
23239 + int eapol; /* 0 = process EAPOL frames as normal data frames,
23240 + * 1 = send EAPOL frames through wlan#ap to hostapd
23241 + * (default) */
23242 + int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
23243 + * port */
23244 +
23245 +#define NUM_DEFAULT_KEYS 4
23246 + struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
23247 + struct ieee80211_key *default_key;
23248 +
23249 + struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
23250 +
23251 + union {
23252 + struct ieee80211_if_ap ap;
23253 + struct ieee80211_if_wds wds;
23254 + struct ieee80211_if_vlan vlan;
23255 + struct ieee80211_if_sta sta;
23256 + } u;
23257 + int channel_use;
23258 + int channel_use_raw;
23259 +};
23260 +
23261 +#define IEEE80211_DEV_TO_SUB_IF(dev) ((struct ieee80211_sub_if_data *) \
23262 + ((char *)(dev) + ((sizeof(struct net_device) + 3) & ~3)))
23263 +#define IEEE80211_SUB_IF_TO_DEV(sub_if) ((struct net_device *) \
23264 + ((char *)(sub_if) - ((sizeof(struct net_device) + 3) & ~3)))
23265 +
23266 +
23267 +struct ieee80211_local {
23268 + struct ieee80211_hw *hw;
23269 + void *hw_priv;
23270 + struct net_device *mdev; /* wlan#.11 - "master" 802.11 device */
23271 + struct net_device *wdev; /* wlan# - default Ethernet (data) devide */
23272 + struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
23273 + int open_count;
23274 + struct ieee80211_conf conf;
23275 +
23276 + int dev_index;
23277 + struct class_device class_dev;
23278 +
23279 + /* Tasklet and skb queue to process calls from IRQ mode. All frames
23280 + * added to skb_queue will be processed, but frames in
23281 + * skb_queue_unreliable may be dropped if the total length of these
23282 + * queues increases over the limit. */
23283 +#define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
23284 + struct tasklet_struct tasklet;
23285 + struct sk_buff_head skb_queue;
23286 + struct sk_buff_head skb_queue_unreliable;
23287 + enum {
23288 + ieee80211_rx_msg = 1,
23289 + ieee80211_tx_status_msg = 2
23290 + } ieee80211_msg_enum;
23291 +
23292 + spinlock_t generic_lock;
23293 + /* Station data structures */
23294 + spinlock_t sta_lock; /* mutex for STA data structures */
23295 + int num_sta; /* number of stations in sta_list */
23296 + struct list_head sta_list;
23297 + struct sta_info *sta_hash[STA_HASH_SIZE];
23298 + struct timer_list sta_cleanup;
23299 +
23300 + /* Current rate table. This is a pointer to hw->modes structure. */
23301 + struct ieee80211_rate *curr_rates;
23302 + int num_curr_rates;
23303 +
23304 + void *rate_ctrl_priv;
23305 + struct rate_control_ops *rate_ctrl;
23306 +
23307 + int next_mode; /* MODE_IEEE80211*
23308 + * The mode preference for next channel change. This is
23309 + * used to select .11g vs. .11b channels (or 4.9 GHz vs.
23310 + * .11a) when the channel number is not unique. */
23311 +
23312 + /* Supported and basic rate filters for different modes. These are
23313 + * pointers to -1 terminated lists and rates in 100 kbps units. */
23314 + int *supp_rates[NUM_IEEE80211_MODES];
23315 + int *basic_rates[NUM_IEEE80211_MODES];
23316 +
23317 + int rts_threshold;
23318 + int cts_protect_erp_frames;
23319 + int fragmentation_threshold;
23320 + int short_retry_limit; /* dot11ShortRetryLimit */
23321 + int long_retry_limit; /* dot11LongRetryLimit */
23322 + int short_preamble; /* use short preamble with IEEE 802.11b */
23323 +
23324 + u32 wep_iv;
23325 + int key_tx_rx_threshold; /* number of times any key can be used in TX
23326 + * or RX before generating a rekey
23327 + * notification; 0 = notification disabled. */
23328 +
23329 + /* Fragment table for host-based reassembly */
23330 + struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
23331 + unsigned int fragment_next;
23332 +
23333 + int bridge_packets; /* bridge packets between associated stations and
23334 + * deliver multicast frames both back to wireless
23335 + * media and to the local net stack */
23336 +
23337 + struct ieee80211_passive_scan scan;
23338 +
23339 +
23340 + ieee80211_rx_handler *rx_handlers;
23341 + ieee80211_tx_handler *tx_handlers;
23342 +
23343 + spinlock_t sub_if_lock; /* mutex for STA data structures */
23344 + struct list_head sub_if_list;
23345 + struct net_device **bss_devs; /* pointer to IF_TYPE_AP devices for
23346 + * quick access to BSS data */
23347 + int bss_dev_count; /* number of used entries in bss_devs; note: the
23348 + * total size of bss_devs array is stored in
23349 + * conf.bss_count */
23350 + struct net_device **sta_devs; /* pointer to IF_TYPE_STA devices */
23351 + int sta_dev_count; /* number of used entries in sta_devs */
23352 + int sta_scanning;
23353 + int scan_hw_mode_idx;
23354 + int scan_channel_idx;
23355 + enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
23356 + unsigned long last_scan_completed;
23357 + struct timer_list scan_timer;
23358 + int scan_oper_channel;
23359 + int scan_oper_channel_val;
23360 + int scan_oper_power_level;
23361 + int scan_oper_freq;
23362 + int scan_oper_phymode;
23363 + int scan_oper_antenna_max;
23364 + u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
23365 + size_t scan_ssid_len;
23366 + int scan_skip_11b;
23367 + struct list_head sta_bss_list;
23368 + struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
23369 + spinlock_t sta_bss_lock;
23370 +#define IEEE80211_SCAN_MATCH_SSID BIT(0)
23371 +#define IEEE80211_SCAN_WPA_ONLY BIT(1)
23372 +#define IEEE80211_SCAN_EXTRA_INFO BIT(2)
23373 + int scan_flags;
23374 +
23375 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23376 + u32 wpa_trigger;
23377 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
23378 + /* SNMP counters */
23379 + /* dot11CountersTable */
23380 + u32 dot11TransmittedFragmentCount;
23381 + u32 dot11MulticastTransmittedFrameCount;
23382 + u32 dot11FailedCount;
23383 + u32 dot11RetryCount;
23384 + u32 dot11MultipleRetryCount;
23385 + u32 dot11FrameDuplicateCount;
23386 + u32 dot11ReceivedFragmentCount;
23387 + u32 dot11MulticastReceivedFrameCount;
23388 + u32 dot11TransmittedFrameCount;
23389 + u32 dot11WEPUndecryptableCount;
23390 +
23391 + int tx_led_counter;
23392 +
23393 + u32 channel_use;
23394 + u32 channel_use_raw;
23395 + u32 stat_time;
23396 + struct timer_list stat_timer;
23397 +
23398 + u8 bssid[ETH_ALEN]; /* BSSID for STA modes (Adhoc/Managed) */
23399 + struct timer_list rate_limit_timer;
23400 + u32 rate_limit;
23401 + u32 rate_limit_burst;
23402 + u32 rate_limit_bucket;
23403 + struct proc_dir_entry *proc, *proc_sta, *proc_iface;
23404 +
23405 + struct work_struct sta_proc_add;
23406 +
23407 + enum {
23408 + STA_ANTENNA_SEL_AUTO = 0,
23409 + STA_ANTENNA_SEL_SW_CTRL = 1,
23410 + STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
23411 + } sta_antenna_sel;
23412 +
23413 + int rate_ctrl_num_up, rate_ctrl_num_down;
23414 +
23415 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
23416 + /* TX/RX handler statistics */
23417 + unsigned int tx_handlers_drop;
23418 + unsigned int tx_handlers_queued;
23419 + unsigned int tx_handlers_drop_unencrypted;
23420 + unsigned int tx_handlers_drop_fragment;
23421 + unsigned int tx_handlers_drop_wep;
23422 + unsigned int tx_handlers_drop_rate_limit;
23423 + unsigned int tx_handlers_drop_not_assoc;
23424 + unsigned int tx_handlers_drop_unauth_port;
23425 + unsigned int rx_handlers_drop;
23426 + unsigned int rx_handlers_queued;
23427 + unsigned int rx_handlers_drop_nullfunc;
23428 + unsigned int rx_handlers_drop_defrag;
23429 + unsigned int rx_handlers_drop_short;
23430 + unsigned int rx_handlers_drop_passive_scan;
23431 + unsigned int tx_expand_skb_head;
23432 + unsigned int tx_expand_skb_head_cloned;
23433 + unsigned int rx_expand_skb_head;
23434 + unsigned int rx_expand_skb_head2;
23435 + unsigned int rx_handlers_fragments;
23436 + unsigned int tx_status_drop;
23437 + unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
23438 + unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
23439 +#define I802_DEBUG_INC(c) (c)++
23440 +#else /* CONFIG_D80211_DEBUG_COUNTERS */
23441 +#define I802_DEBUG_INC(c) do { } while (0)
23442 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
23443 +
23444 +
23445 + int default_wep_only; /* only default WEP keys are used with this
23446 + * interface; this is used to decide when hwaccel
23447 + * can be used with default keys */
23448 + int total_ps_buffered; /* total number of all buffered unicast and
23449 + * multicast packets for power saving stations
23450 + */
23451 + int allow_broadcast_always; /* whether to allow TX of broadcast frames
23452 + * even when there are no associated STAs
23453 + */
23454 +
23455 + int wifi_wme_noack_test;
23456 + unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
23457 +
23458 + unsigned int hw_modes; /* bitfield of allowed hardware modes;
23459 + * (1 << MODE_*) */
23460 +};
23461 +
23462 +
23463 +/* ieee80211.c */
23464 +int ieee80211_hw_config(struct net_device *dev);
23465 +struct ieee80211_key_conf *
23466 +ieee80211_key_data2conf(struct ieee80211_local *local,
23467 + struct ieee80211_key *data);
23468 +void ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
23469 + struct ieee80211_rx_status *status, u32 msg_type);
23470 +void ieee80211_prepare_rates(struct net_device *dev);
23471 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
23472 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
23473 + struct ieee80211_if_wds *wds, int locked);
23474 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
23475 + struct ieee80211_if_vlan *vlan, int locked);
23476 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
23477 + int locked);
23478 +
23479 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name, int locked);
23480 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name, int locked);
23481 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name, int locked);
23482 +int ieee80211_if_flush(struct net_device *dev, int locked);
23483 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
23484 + struct ieee80211_if_wds *wds, int locked);
23485 +
23486 +/* ieee80211_ioctl.c */
23487 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
23488 +extern const struct iw_handler_def ieee80211_iw_handler_def;
23489 +
23490 +/* Set hw encryption from ieee80211 */
23491 +int ieee80211_set_hw_encryption(struct net_device *dev,
23492 + struct sta_info *sta, u8 addr[ETH_ALEN],
23493 + struct ieee80211_key *key);
23494 +
23495 +/* ieee80211_scan.c */
23496 +void ieee80211_init_scan(struct net_device *dev);
23497 +void ieee80211_stop_scan(struct net_device *dev);
23498 +
23499 +
23500 +
23501 +/* Least common multiple of the used rates (in 100 kbps). This is used to
23502 + * calculate rate_inv values for each rate so that only integers are needed. */
23503 +#define CHAN_UTIL_RATE_LCM 95040
23504 +/* 1 usec is 1/8 * (95040/10) = 1188 */
23505 +#define CHAN_UTIL_PER_USEC 1188
23506 +/* Amount of bits to shift the result right to scale the total utilization
23507 + * to values that will not wrap around 32-bit integers. */
23508 +#define CHAN_UTIL_SHIFT 9
23509 +/* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
23510 + * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
23511 + * raw value with about 23 should give utilization in 10th of a percentage
23512 + * (1/1000). However, utilization is only estimated and not all intervals
23513 + * between frames etc. are calculated. 18 seems to give numbers that are closer
23514 + * to the real maximum. */
23515 +#define CHAN_UTIL_PER_10MS 18
23516 +#define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
23517 +#define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
23518 +
23519 +
23520 +
23521 +/* ieee80211.c */
23522 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked);
23523 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name, int locked);
23524 +/* ieee80211_ioctl.c */
23525 +int ieee80211_set_compression(struct ieee80211_local *local,
23526 + struct net_device *dev, struct sta_info *sta);
23527 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
23528 + u8 *bssid_mask);
23529 +/* ieee80211_sta.c */
23530 +void ieee80211_sta_timer(unsigned long ptr);
23531 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
23532 + struct ieee80211_rx_status *rx_status);
23533 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
23534 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
23535 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
23536 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
23537 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
23538 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
23539 + struct ieee80211_rx_status *rx_status);
23540 +void ieee80211_rx_bss_list_init(struct net_device *dev);
23541 +void ieee80211_rx_bss_list_deinit(struct net_device *dev);
23542 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
23543 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
23544 + struct sk_buff *skb, u8 *bssid,
23545 + u8 *addr);
23546 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
23547 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
23548 +
23549 +/* ieee80211_dev.c */
23550 +int ieee80211_dev_alloc_index(struct ieee80211_local *local);
23551 +void ieee80211_dev_free_index(struct ieee80211_local *local);
23552 +struct ieee80211_local *ieee80211_dev_find(int index);
23553 +
23554 +/* ieee80211_sysfs.c */
23555 +int ieee80211_register_sysfs(struct ieee80211_local *local);
23556 +void ieee80211_unregister_sysfs(struct ieee80211_local *local);
23557 +int ieee80211_sysfs_init(void);
23558 +void ieee80211_sysfs_deinit(void);
23559 +
23560 +#endif /* IEEE80211_I_H */
23561 diff -Nur linux-2.6.16/net/d80211/ieee80211_ioctl.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_ioctl.c
23562 --- linux-2.6.16/net/d80211/ieee80211_ioctl.c 1970-01-01 01:00:00.000000000 +0100
23563 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_ioctl.c 2006-03-28 22:16:14.000000000 +0200
23564 @@ -0,0 +1,3040 @@
23565 +/*
23566 + * Copyright 2002-2005, Instant802 Networks, Inc.
23567 + * Copyright 2005-2006, Devicescape Software, Inc.
23568 + *
23569 + * This program is free software; you can redistribute it and/or modify
23570 + * it under the terms of the GNU General Public License version 2 as
23571 + * published by the Free Software Foundation.
23572 + */
23573 +
23574 +#include <linux/config.h>
23575 +#include <linux/version.h>
23576 +#include <linux/module.h>
23577 +#include <linux/init.h>
23578 +#include <linux/netdevice.h>
23579 +#include <linux/types.h>
23580 +#include <linux/slab.h>
23581 +#include <linux/skbuff.h>
23582 +#include <linux/if_arp.h>
23583 +#include <linux/wireless.h>
23584 +#include <net/iw_handler.h>
23585 +#include <asm/uaccess.h>
23586 +
23587 +#include <net/d80211.h>
23588 +#include <net/d80211_mgmt.h>
23589 +#include "ieee80211_i.h"
23590 +#include "hostapd_ioctl.h"
23591 +#include "rate_control.h"
23592 +#include "wpa.h"
23593 +#include "aes_ccm.h"
23594 +
23595 +
23596 +static int ieee80211_regdom = 0x10; /* FCC */
23597 +MODULE_PARM(ieee80211_regdom, "i");
23598 +MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
23599 +
23600 +/*
23601 + * If firmware is upgraded by the vendor, additional channels can be used based
23602 + * on the new Japanese regulatory rules. This is indicated by setting
23603 + * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
23604 + * module.
23605 + */
23606 +static int ieee80211_japan_5ghz /* = 0 */;
23607 +MODULE_PARM(ieee80211_japan_5ghz, "i");
23608 +MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
23609 +
23610 +
23611 +static int ieee80211_ioctl_set_beacon(struct net_device *dev,
23612 + struct prism2_hostapd_param *param,
23613 + int param_len,
23614 + int flag)
23615 +{
23616 + struct ieee80211_sub_if_data *sdata;
23617 + struct ieee80211_if_ap *ap;
23618 + u8 **b_head, **b_tail;
23619 + int *b_head_len, *b_tail_len;
23620 + int len;
23621 +
23622 + len = ((char *) param->u.beacon.data - (char *) param) +
23623 + param->u.beacon.head_len + param->u.beacon.tail_len;
23624 +
23625 + if (param_len > len)
23626 + param_len = len;
23627 + else if (param_len != len)
23628 + return -EINVAL;
23629 +
23630 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23631 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
23632 + return -EINVAL;
23633 + ap = &sdata->u.ap;
23634 +
23635 + switch (flag) {
23636 + case 0:
23637 + b_head = &ap->beacon_head;
23638 + b_tail = &ap->beacon_tail;
23639 + b_head_len = &ap->beacon_head_len;
23640 + b_tail_len = &ap->beacon_tail_len;
23641 + break;
23642 + default:
23643 + printk(KERN_DEBUG "%s: unknown beacon flag %d\n",
23644 + dev->name, flag);
23645 + return -EINVAL;
23646 + }
23647 +
23648 + kfree(*b_head);
23649 + kfree(*b_tail);
23650 + *b_head = NULL;
23651 + *b_tail = NULL;
23652 +
23653 + *b_head_len = param->u.beacon.head_len;
23654 + *b_tail_len = param->u.beacon.tail_len;
23655 +
23656 + *b_head = kmalloc(*b_head_len, GFP_KERNEL);
23657 + if (*b_head)
23658 + memcpy(*b_head, param->u.beacon.data, *b_head_len);
23659 + else {
23660 + printk(KERN_DEBUG "%s: failed to allocate beacon_head\n",
23661 + dev->name);
23662 + return -ENOMEM;
23663 + }
23664 +
23665 + if (*b_tail_len > 0) {
23666 + *b_tail = kmalloc(*b_tail_len, GFP_KERNEL);
23667 + if (*b_tail)
23668 + memcpy(*b_tail, param->u.beacon.data + (*b_head_len),
23669 + (*b_tail_len));
23670 + else {
23671 + printk(KERN_DEBUG "%s: failed to allocate "
23672 + "beacon_tail\n", dev->name);
23673 + return -ENOMEM;
23674 + }
23675 + }
23676 +
23677 + return 0;
23678 +}
23679 +
23680 +
23681 +static int ieee80211_ioctl_get_hw_features(struct net_device *dev,
23682 + struct prism2_hostapd_param *param,
23683 + int param_len)
23684 +{
23685 + struct ieee80211_local *local = dev->priv;
23686 + u8 *pos = param->u.hw_features.data;
23687 + int left = param_len - (pos - (u8 *) param);
23688 + int mode, i;
23689 + struct hostapd_ioctl_hw_modes_hdr *hdr;
23690 + struct ieee80211_rate_data *rate;
23691 + struct ieee80211_channel_data *chan;
23692 +
23693 + param->u.hw_features.flags = 0;
23694 + if (local->hw->data_nullfunc_ack)
23695 + param->u.hw_features.flags |= HOSTAP_HW_FLAG_NULLFUNC_OK;
23696 +
23697 + param->u.hw_features.num_modes = local->hw->num_modes;
23698 + for (mode = 0; mode < local->hw->num_modes; mode++) {
23699 + int clen, rlen;
23700 + struct ieee80211_hw_modes *m = &local->hw->modes[mode];
23701 + clen = m->num_channels * sizeof(struct ieee80211_channel_data);
23702 + rlen = m->num_rates * sizeof(struct ieee80211_rate_data);
23703 + if (left < sizeof(*hdr) + clen + rlen)
23704 + return -E2BIG;
23705 + left -= sizeof(*hdr) + clen + rlen;
23706 +
23707 + hdr = (struct hostapd_ioctl_hw_modes_hdr *) pos;
23708 + hdr->mode = m->mode;
23709 + hdr->num_channels = m->num_channels;
23710 + hdr->num_rates = m->num_rates;
23711 +
23712 + pos = (u8 *) (hdr + 1);
23713 + chan = (struct ieee80211_channel_data *) pos;
23714 + for (i = 0; i < m->num_channels; i++) {
23715 + chan[i].chan = m->channels[i].chan;
23716 + chan[i].freq = m->channels[i].freq;
23717 + chan[i].flag = m->channels[i].flag;
23718 + }
23719 + pos += clen;
23720 +
23721 + rate = (struct ieee80211_rate_data *) pos;
23722 + for (i = 0; i < m->num_rates; i++) {
23723 + rate[i].rate = m->rates[i].rate;
23724 + rate[i].flags = m->rates[i].flags;
23725 + }
23726 + pos += rlen;
23727 + }
23728 +
23729 + return 0;
23730 +}
23731 +
23732 +
23733 +static int ieee80211_ioctl_scan(struct net_device *dev,
23734 + struct prism2_hostapd_param *param)
23735 +{
23736 + struct ieee80211_local *local = dev->priv;
23737 +
23738 + if (local->hw->passive_scan == NULL)
23739 + return -EOPNOTSUPP;
23740 +
23741 + if ((param->u.scan.now == 1) && (local->scan.in_scan == 1))
23742 + return -EBUSY;
23743 +
23744 + if (param->u.scan.our_mode_only >= 0)
23745 + local->scan.our_mode_only = param->u.scan.our_mode_only;
23746 + if (param->u.scan.interval >= 0)
23747 + local->scan.interval = param->u.scan.interval;
23748 + if (param->u.scan.listen >= 0)
23749 + local->scan.time = param->u.scan.listen;
23750 + if (param->u.scan.channel > 0)
23751 + local->scan.channel = param->u.scan.channel;
23752 + if (param->u.scan.now == 1) {
23753 + local->scan.in_scan = 0;
23754 + mod_timer(&local->scan.timer, jiffies);
23755 + }
23756 +
23757 + param->u.scan.our_mode_only = local->scan.our_mode_only;
23758 + param->u.scan.interval = local->scan.interval;
23759 + param->u.scan.listen = local->scan.time;
23760 + if (local->scan.in_scan == 1)
23761 + param->u.scan.last_rx = -1;
23762 + else {
23763 + param->u.scan.last_rx = local->scan.rx_packets;
23764 + local->scan.rx_packets = -1;
23765 + }
23766 + param->u.scan.channel = local->hw->modes[local->scan.mode_idx].
23767 + channels[local->scan.chan_idx].chan;
23768 +
23769 + return 0;
23770 +}
23771 +
23772 +
23773 +static int ieee80211_ioctl_flush(struct net_device *dev,
23774 + struct prism2_hostapd_param *param)
23775 +{
23776 + struct ieee80211_local *local = dev->priv;
23777 + sta_info_flush(local, NULL);
23778 + return 0;
23779 +}
23780 +
23781 +
23782 +static int ieee80211_ioctl_add_sta(struct net_device *dev,
23783 + struct prism2_hostapd_param *param)
23784 +{
23785 + struct ieee80211_local *local = dev->priv;
23786 + struct sta_info *sta;
23787 + u32 rates;
23788 + int i, j;
23789 + struct ieee80211_sub_if_data *sdata;
23790 + int add_key_entry = 1;
23791 +
23792 + sta = sta_info_get(local, param->sta_addr);
23793 +
23794 + if (sta == NULL) {
23795 + sta = sta_info_add(local, dev, param->sta_addr);
23796 + if (sta == NULL)
23797 + return -ENOMEM;
23798 + }
23799 +
23800 + if (sta->dev != dev) {
23801 + /* Binding STA to a new interface, so remove all references to
23802 + * the old BSS. */
23803 + sta_info_remove_aid_ptr(sta);
23804 + }
23805 +
23806 + /* TODO
23807 + * We "steal" the device in case someone owns it
23808 + * This will hurt WDS links and such when we have a
23809 + * WDS link and a client associating from the same station
23810 + */
23811 + sta->dev = dev;
23812 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
23813 +
23814 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
23815 + sta->aid = param->u.add_sta.aid;
23816 + if (sta->aid > MAX_AID_TABLE_SIZE)
23817 + sta->aid = 0;
23818 + if (sta->aid > 0 && sdata->bss)
23819 + sdata->bss->sta_aid[sta->aid - 1] = sta;
23820 + if (sdata->bss && sta->aid > sdata->bss->max_aid)
23821 + sdata->bss->max_aid = sta->aid;
23822 +
23823 + rates = 0;
23824 + for (i = 0; i < sizeof(param->u.add_sta.supp_rates); i++) {
23825 + int rate = (param->u.add_sta.supp_rates[i] & 0x7f) * 5;
23826 + if (local->conf.phymode == MODE_ATHEROS_TURBO ||
23827 + local->conf.phymode == MODE_ATHEROS_TURBOG)
23828 + rate *= 2;
23829 + for (j = 0; j < local->num_curr_rates; j++) {
23830 + if (local->curr_rates[j].rate == rate)
23831 + rates |= BIT(j);
23832 + }
23833 +
23834 + }
23835 + sta->supp_rates = rates;
23836 +
23837 + rate_control_rate_init(local, sta);
23838 +
23839 + if (param->u.add_sta.wds_flags & 0x01)
23840 + sta->flags |= WLAN_STA_WDS;
23841 + else
23842 + sta->flags &= ~WLAN_STA_WDS;
23843 +
23844 + if (add_key_entry && sta->key == NULL && sdata->default_key == NULL &&
23845 + local->hw->set_key) {
23846 + struct ieee80211_key_conf conf;
23847 + /* Add key cache entry with NULL key type because this may used
23848 + * for TX filtering. */
23849 + memset(&conf, 0, sizeof(conf));
23850 + conf.hw_key_idx = HW_KEY_IDX_INVALID;
23851 + conf.alg = ALG_NULL;
23852 + conf.force_sw_encrypt = 1;
23853 + if (local->hw->set_key(dev, SET_KEY, sta->addr, &conf,
23854 + sta->aid)) {
23855 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
23856 + } else {
23857 + sta->key_idx_compression = conf.hw_key_idx;
23858 + }
23859 + }
23860 +
23861 + sta_info_release(local, sta);
23862 +
23863 + return 0;
23864 +}
23865 +
23866 +
23867 +static int ieee80211_ioctl_remove_sta(struct net_device *dev,
23868 + struct prism2_hostapd_param *param)
23869 +{
23870 + struct ieee80211_local *local = dev->priv;
23871 + struct sta_info *sta;
23872 +
23873 + sta = sta_info_get(local, param->sta_addr);
23874 + if (sta) {
23875 + sta_info_release(local, sta);
23876 + sta_info_free(local, sta, 1);
23877 + }
23878 +
23879 + return sta ? 0 : -ENOENT;
23880 +}
23881 +
23882 +
23883 +static int ieee80211_ioctl_get_dot11counterstable(struct net_device *dev,
23884 + struct prism2_hostapd_param *param)
23885 +{
23886 + struct ieee80211_local *local = dev->priv;
23887 + struct ieee80211_low_level_stats stats;
23888 +
23889 + memset(&stats, 0, sizeof(stats));
23890 + if (local->hw->get_stats)
23891 + local->hw->get_stats(dev, &stats);
23892 + param->u.dot11CountersTable.dot11TransmittedFragmentCount =
23893 + local->dot11TransmittedFragmentCount;
23894 + param->u.dot11CountersTable.dot11MulticastTransmittedFrameCount =
23895 + local->dot11MulticastTransmittedFrameCount;
23896 + param->u.dot11CountersTable.dot11ReceivedFragmentCount =
23897 + local->dot11ReceivedFragmentCount;
23898 + param->u.dot11CountersTable.dot11MulticastReceivedFrameCount =
23899 + local->dot11MulticastReceivedFrameCount;
23900 + param->u.dot11CountersTable.dot11TransmittedFrameCount =
23901 + local->dot11TransmittedFrameCount;
23902 + param->u.dot11CountersTable.dot11FCSErrorCount =
23903 + stats.dot11FCSErrorCount;
23904 + param->u.dot11CountersTable.dot11ACKFailureCount =
23905 + stats.dot11ACKFailureCount;
23906 + param->u.dot11CountersTable.dot11RTSFailureCount =
23907 + stats.dot11RTSFailureCount;
23908 + param->u.dot11CountersTable.dot11RTSSuccessCount =
23909 + stats.dot11RTSSuccessCount;
23910 +
23911 + return 0;
23912 +}
23913 +
23914 +
23915 +static int ieee80211_ioctl_get_info_sta(struct net_device *dev,
23916 + struct prism2_hostapd_param *param)
23917 +{
23918 + struct ieee80211_local *local = dev->priv;
23919 + struct sta_info *sta;
23920 +
23921 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
23922 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
23923 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
23924 + struct ieee80211_sub_if_data *sdata;
23925 + struct net_device_stats *stats;
23926 +
23927 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23928 + stats = ieee80211_dev_stats(sdata->master);
23929 + param->u.get_info_sta.rx_bytes = stats->rx_bytes;
23930 + param->u.get_info_sta.tx_bytes = stats->tx_bytes;
23931 + /* go through all STAs and get STA with lowest max. rate */
23932 + param->u.get_info_sta.current_tx_rate =
23933 + local->curr_rates[sta_info_min_txrate_get(local)].rate;
23934 + return 0;
23935 + }
23936 +
23937 + sta = sta_info_get(local, param->sta_addr);
23938 +
23939 + if (!sta)
23940 + return -ENOENT;
23941 +
23942 + param->u.get_info_sta.inactive_msec =
23943 + jiffies_to_msecs(jiffies - sta->last_rx);
23944 + param->u.get_info_sta.rx_packets = sta->rx_packets;
23945 + param->u.get_info_sta.tx_packets = sta->tx_packets;
23946 + param->u.get_info_sta.rx_bytes = sta->rx_bytes;
23947 + param->u.get_info_sta.tx_bytes = sta->tx_bytes;
23948 + param->u.get_info_sta.channel_use = sta->channel_use;
23949 + param->u.get_info_sta.flags = sta->flags;
23950 + if (sta->txrate >= 0 && sta->txrate < local->num_curr_rates)
23951 + param->u.get_info_sta.current_tx_rate =
23952 + local->curr_rates[sta->txrate].rate;
23953 + param->u.get_info_sta.num_ps_buf_frames =
23954 + skb_queue_len(&sta->ps_tx_buf);
23955 + param->u.get_info_sta.tx_retry_failed = sta->tx_retry_failed;
23956 + param->u.get_info_sta.tx_retry_count = sta->tx_retry_count;
23957 + param->u.get_info_sta.last_rssi = sta->last_rssi;
23958 + param->u.get_info_sta.last_ack_rssi = sta->last_ack_rssi[2];
23959 +
23960 + sta_info_release(local, sta);
23961 +
23962 + return 0;
23963 +}
23964 +
23965 +
23966 +static int ieee80211_ioctl_set_flags_sta(struct net_device *dev,
23967 + struct prism2_hostapd_param *param)
23968 +{
23969 + struct ieee80211_local *local = dev->priv;
23970 + struct sta_info *sta;
23971 +
23972 + sta = sta_info_get(local, param->sta_addr);
23973 + if (sta) {
23974 + sta->flags |= param->u.set_flags_sta.flags_or;
23975 + sta->flags &= param->u.set_flags_sta.flags_and;
23976 + if (local->hw->set_port_auth &&
23977 + (param->u.set_flags_sta.flags_or & WLAN_STA_AUTHORIZED) &&
23978 + local->hw->set_port_auth(local->mdev, sta->addr, 1))
23979 + printk(KERN_DEBUG "%s: failed to set low-level driver "
23980 + "PAE state (authorized) for " MACSTR "\n",
23981 + dev->name, MAC2STR(sta->addr));
23982 + if (local->hw->set_port_auth &&
23983 + !(param->u.set_flags_sta.flags_and & WLAN_STA_AUTHORIZED)
23984 + && local->hw->set_port_auth(local->mdev, sta->addr, 0))
23985 + printk(KERN_DEBUG "%s: failed to set low-level driver "
23986 + "PAE state (unauthorized) for " MACSTR "\n",
23987 + dev->name, MAC2STR(sta->addr));
23988 + sta_info_release(local, sta);
23989 + }
23990 +
23991 + return sta ? 0 : -ENOENT;
23992 +}
23993 +
23994 +
23995 +int ieee80211_set_hw_encryption(struct net_device *dev,
23996 + struct sta_info *sta, u8 addr[ETH_ALEN],
23997 + struct ieee80211_key *key)
23998 +{
23999 + struct ieee80211_key_conf *keyconf = NULL;
24000 + struct ieee80211_local *local = dev->priv;
24001 + int rc = 0;
24002 +
24003 + /* default to sw encryption; this will be cleared by low-level
24004 + * driver if the hw supports requested encryption */
24005 + if (key)
24006 + key->force_sw_encrypt = 1;
24007 +
24008 + if (key && local->hw->set_key &&
24009 + (!local->conf.sw_encrypt || !local->conf.sw_decrypt) &&
24010 + (keyconf = ieee80211_key_data2conf(local, key)) != NULL) {
24011 + if (local->hw->set_key(dev, SET_KEY, addr,
24012 + keyconf, sta ? sta->aid : 0)) {
24013 + rc = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24014 + key->force_sw_encrypt = 1;
24015 + key->hw_key_idx = HW_KEY_IDX_INVALID;
24016 + } else {
24017 + key->force_sw_encrypt =
24018 + keyconf->force_sw_encrypt;
24019 + key->hw_key_idx =
24020 + keyconf->hw_key_idx;
24021 +
24022 + }
24023 + }
24024 + kfree(keyconf);
24025 +
24026 + return rc;
24027 +}
24028 +
24029 +
24030 +static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
24031 + int idx, int alg, int set_tx_key, int *err,
24032 + const u8 *_key, size_t key_len)
24033 +{
24034 + struct ieee80211_local *local = dev->priv;
24035 + int ret = 0;
24036 + struct sta_info *sta;
24037 + struct ieee80211_key **key;
24038 + int try_hwaccel = 1;
24039 + struct ieee80211_key_conf *keyconf;
24040 + struct ieee80211_sub_if_data *sdata;
24041 +
24042 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24043 +
24044 + if (sta_addr[0] == 0xff && sta_addr[1] == 0xff &&
24045 + sta_addr[2] == 0xff && sta_addr[3] == 0xff &&
24046 + sta_addr[4] == 0xff && sta_addr[5] == 0xff) {
24047 + sta = NULL;
24048 + if (idx >= NUM_DEFAULT_KEYS) {
24049 + printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
24050 + dev->name, idx);
24051 + return -EINVAL;
24052 + }
24053 + key = &sdata->keys[idx];
24054 +
24055 + /* Disable hwaccel for default keys when the interface is not
24056 + * the default one.
24057 + * TODO: consider adding hwaccel support for these; at least
24058 + * Atheros key cache should be able to handle this since AP is
24059 + * only transmitting frames with default keys. */
24060 + /* FIX: hw key cache can be used when only one virtual
24061 + * STA is associated with each AP. If more than one STA
24062 + * is associated to the same AP, software encryption
24063 + * must be used. This should be done automatically
24064 + * based on configured station devices. For the time
24065 + * being, this can be only set at compile time. */
24066 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24067 + if (0 /* FIX: more than one STA per AP */)
24068 + try_hwaccel = 0;
24069 + } else
24070 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP ||
24071 + dev != local->wdev)
24072 + try_hwaccel = 0;
24073 + } else {
24074 + set_tx_key = 0;
24075 + if (idx != 0) {
24076 + printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
24077 + "individual key\n", dev->name);
24078 + return -EINVAL;
24079 + }
24080 +
24081 + sta = sta_info_get(local, sta_addr);
24082 + if (sta == NULL) {
24083 + if (err)
24084 + *err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24085 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
24086 + printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
24087 + MACSTR "\n",
24088 + dev->name, MAC2STR(sta_addr));
24089 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
24090 +
24091 + return -ENOENT;
24092 + }
24093 +
24094 + key = &sta->key;
24095 + }
24096 +
24097 + /* FIX:
24098 + * Cannot configure default hwaccel keys with WEP algorithm, if
24099 + * any of the virtual interfaces is using static WEP
24100 + * configuration because hwaccel would otherwise try to decrypt
24101 + * these frames.
24102 + *
24103 + * For now, just disable WEP hwaccel for broadcast when there is
24104 + * possibility of conflict with default keys. This can maybe later be
24105 + * optimized by using non-default keys (at least with Atheros ar521x).
24106 + */
24107 + if (!sta && alg == ALG_WEP && !local->default_wep_only &&
24108 + local->conf.mode != IW_MODE_ADHOC &&
24109 + local->conf.mode != IW_MODE_INFRA) {
24110 + try_hwaccel = 0;
24111 + }
24112 +
24113 + if (local->hw->device_hides_wep) {
24114 + /* Software encryption cannot be used with devices that hide
24115 + * encryption from the host system, so always try to use
24116 + * hardware acceleration with such devices. */
24117 + try_hwaccel = 1;
24118 + }
24119 +
24120 + if (local->hw->no_tkip_wmm_hwaccel && alg == ALG_TKIP) {
24121 + if (sta && (sta->flags & WLAN_STA_WME)) {
24122 + /* Hardware does not support hwaccel with TKIP when using WMM.
24123 + */
24124 + try_hwaccel = 0;
24125 + }
24126 + else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24127 + sta = sta_info_get(local, sdata->u.sta.bssid);
24128 + if (sta) {
24129 + if (sta->flags & WLAN_STA_WME) {
24130 + try_hwaccel = 0;
24131 + }
24132 + sta_info_release(local, sta);
24133 + sta = NULL;
24134 + }
24135 + }
24136 + }
24137 +
24138 + if (alg == ALG_NONE) {
24139 + keyconf = NULL;
24140 + if (try_hwaccel && *key && local->hw->set_key &&
24141 + (keyconf = ieee80211_key_data2conf(local, *key)) != NULL &&
24142 + local->hw->set_key(dev, DISABLE_KEY, sta_addr,
24143 + keyconf, sta ? sta->aid : 0)) {
24144 + if (err)
24145 + *err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24146 + printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
24147 + " failed\n", dev->name);
24148 + ret = -EINVAL;
24149 + }
24150 + kfree(keyconf);
24151 +
24152 + if (sdata->default_key == *key)
24153 + sdata->default_key = NULL;
24154 + kfree(*key);
24155 + *key = NULL;
24156 + } else {
24157 + if (*key == NULL || (*key)->keylen < key_len) {
24158 + kfree(*key);
24159 + *key = kmalloc(sizeof(struct ieee80211_key) +
24160 + key_len, GFP_ATOMIC);
24161 + if (*key == NULL) {
24162 + ret = -ENOMEM;
24163 + goto done;
24164 + }
24165 + }
24166 + memset(*key, 0, sizeof(struct ieee80211_key) + key_len);
24167 + /* default to sw encryption; low-level driver sets these if the
24168 + * requested encryption is supported */
24169 + (*key)->hw_key_idx = HW_KEY_IDX_INVALID;
24170 + (*key)->force_sw_encrypt = 1;
24171 +
24172 + (*key)->alg = alg;
24173 + (*key)->keyidx = idx;
24174 + (*key)->keylen = key_len;
24175 + memcpy((*key)->key, _key, key_len);
24176 + if (set_tx_key)
24177 + (*key)->default_tx_key = 1;
24178 +
24179 + if (alg == ALG_CCMP) {
24180 + /* Initialize AES key state here as an optimization
24181 + * so that it does not need to be initialized for every
24182 + * packet. */
24183 + ieee80211_aes_key_setup_encrypt(
24184 + (*key)->u.ccmp.aes_state, (*key)->key);
24185 + }
24186 +
24187 + if (try_hwaccel &&
24188 + (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP)) {
24189 + int e = ieee80211_set_hw_encryption(dev, sta, sta_addr,
24190 + *key);
24191 + if (err)
24192 + *err = e;
24193 + }
24194 + }
24195 +
24196 + if (set_tx_key || (sta == NULL && sdata->default_key == NULL)) {
24197 + sdata->default_key = *key;
24198 + if (local->hw->set_key_idx &&
24199 + local->hw->set_key_idx(dev, idx))
24200 + printk(KERN_DEBUG "%s: failed to set TX key idx for "
24201 + "low-level driver\n", dev->name);
24202 + }
24203 +
24204 + done:
24205 + if (sta)
24206 + sta_info_release(local, sta);
24207 +
24208 + return ret;
24209 +}
24210 +
24211 +
24212 +static int ieee80211_ioctl_set_encryption(struct net_device *dev,
24213 + struct prism2_hostapd_param *param,
24214 + int param_len)
24215 +{
24216 + int alg;
24217 +
24218 + param->u.crypt.err = 0;
24219 + param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
24220 +
24221 + if (param_len <
24222 + (int) ((char *) param->u.crypt.key - (char *) param) +
24223 + param->u.crypt.key_len) {
24224 + printk(KERN_DEBUG "%s: set_encrypt - invalid param_lem\n",
24225 + dev->name);
24226 + return -EINVAL;
24227 + }
24228 +
24229 + if (strcmp(param->u.crypt.alg, "none") == 0)
24230 + alg = ALG_NONE;
24231 + else if (strcmp(param->u.crypt.alg, "WEP") == 0)
24232 + alg = ALG_WEP;
24233 + else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
24234 + if (param->u.crypt.key_len != ALG_TKIP_KEY_LEN) {
24235 + printk(KERN_DEBUG "%s: set_encrypt - invalid TKIP key "
24236 + "length %d\n", dev->name,
24237 + param->u.crypt.key_len);
24238 + return -EINVAL;
24239 + }
24240 + alg = ALG_TKIP;
24241 + } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
24242 + if (param->u.crypt.key_len != ALG_CCMP_KEY_LEN) {
24243 + printk(KERN_DEBUG "%s: set_encrypt - invalid CCMP key "
24244 + "length %d\n", dev->name,
24245 + param->u.crypt.key_len);
24246 + return -EINVAL;
24247 + }
24248 + alg = ALG_CCMP;
24249 + } else {
24250 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
24251 + printk(KERN_DEBUG "%s: set_encrypt - unknown alg\n",
24252 + dev->name);
24253 + return -EINVAL;
24254 + }
24255 +
24256 + return ieee80211_set_encryption(
24257 + dev, param->sta_addr,
24258 + param->u.crypt.idx, alg,
24259 + param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY,
24260 + &param->u.crypt.err, param->u.crypt.key,
24261 + param->u.crypt.key_len);
24262 +}
24263 +
24264 +
24265 +static int ieee80211_ioctl_get_encryption(struct net_device *dev,
24266 + struct prism2_hostapd_param *param,
24267 + int param_len)
24268 +{
24269 + struct ieee80211_local *local = dev->priv;
24270 + int ret = 0;
24271 + struct sta_info *sta;
24272 + struct ieee80211_key **key;
24273 + int max_key_len;
24274 + struct ieee80211_sub_if_data *sdata;
24275 + u8 *pos;
24276 +
24277 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24278 +
24279 + param->u.crypt.err = 0;
24280 +
24281 + max_key_len = param_len -
24282 + (int) ((char *) param->u.crypt.key - (char *) param);
24283 + if (max_key_len < 0)
24284 + return -EINVAL;
24285 +
24286 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
24287 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
24288 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
24289 + sta = NULL;
24290 + if (param->u.crypt.idx > NUM_DEFAULT_KEYS) {
24291 + param->u.crypt.idx = sdata->default_key ?
24292 + sdata->default_key->keyidx : 0;
24293 + return 0;
24294 + } else
24295 + key = &sdata->keys[param->u.crypt.idx];
24296 + } else {
24297 + sta = sta_info_get(local, param->sta_addr);
24298 + if (sta == NULL) {
24299 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24300 + return -EINVAL;
24301 + }
24302 +
24303 + key = &sta->key;
24304 + }
24305 +
24306 + memset(param->u.crypt.seq_counter, 0, HOSTAP_SEQ_COUNTER_SIZE);
24307 + if (*key == NULL) {
24308 + memcpy(param->u.crypt.alg, "none", 5);
24309 + param->u.crypt.key_len = 0;
24310 + param->u.crypt.idx = 0xff;
24311 + } else {
24312 + switch ((*key)->alg) {
24313 + case ALG_WEP:
24314 + memcpy(param->u.crypt.alg, "WEP", 4);
24315 + break;
24316 + case ALG_TKIP:
24317 + {
24318 + u32 iv32;
24319 + u16 iv16;
24320 +
24321 + memcpy(param->u.crypt.alg, "TKIP", 5);
24322 + if (local->hw->get_sequence_counter) {
24323 + /* Get transmit counter from low level driver */
24324 + if (local->hw->get_sequence_counter(dev,
24325 + param->sta_addr,
24326 + (*key)->keyidx,
24327 + IEEE80211_SEQ_COUNTER_TX,
24328 + &iv32,
24329 + &iv16)) {
24330 + /* Error getting value from device */
24331 + return -EIO;
24332 + }
24333 + } else {
24334 + /* Get it from our own local data */
24335 + iv32 = (*key)->u.tkip.iv32;
24336 + iv16 = (*key)->u.tkip.iv16;
24337 + }
24338 + pos = param->u.crypt.seq_counter;
24339 + *pos++ = iv16 & 0xff;
24340 + *pos++ = (iv16 >> 8) & 0xff;
24341 + *pos++ = iv32 & 0xff;
24342 + *pos++ = (iv32 >> 8) & 0xff;
24343 + *pos++ = (iv32 >> 16) & 0xff;
24344 + *pos++ = (iv32 >> 24) & 0xff;
24345 + break;
24346 + }
24347 + case ALG_CCMP:
24348 + {
24349 + u8 *pn;
24350 + memcpy(param->u.crypt.alg, "CCMP", 5);
24351 + pos = param->u.crypt.seq_counter;
24352 + pn = (*key)->u.ccmp.tx_pn;
24353 + *pos++ = pn[5];
24354 + *pos++ = pn[4];
24355 + *pos++ = pn[3];
24356 + *pos++ = pn[2];
24357 + *pos++ = pn[1];
24358 + *pos++ = pn[0];
24359 + break;
24360 + }
24361 + default:
24362 + memcpy(param->u.crypt.alg, "unknown", 8);
24363 + break;
24364 + }
24365 +
24366 + if (max_key_len < (*key)->keylen)
24367 + ret = -E2BIG;
24368 + else {
24369 + param->u.crypt.key_len = (*key)->keylen;
24370 + memcpy(param->u.crypt.key, (*key)->key,
24371 + (*key)->keylen);
24372 + }
24373 + }
24374 +
24375 + if (sta)
24376 + sta_info_release(local, sta);
24377 +
24378 + return ret;
24379 +}
24380 +
24381 +
24382 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24383 +static int ieee80211_ioctl_wpa_trigger(struct net_device *dev,
24384 + struct prism2_hostapd_param *param)
24385 +{
24386 + struct ieee80211_local *local = dev->priv;
24387 + struct sta_info *sta;
24388 +
24389 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
24390 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
24391 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
24392 + local->wpa_trigger = param->u.wpa_trigger.trigger;
24393 + return 0;
24394 + }
24395 +
24396 + sta = sta_info_get(local, param->sta_addr);
24397 + if (sta == NULL) {
24398 + printk(KERN_DEBUG "%s: wpa_trigger - unknown addr\n",
24399 + dev->name);
24400 + return -EINVAL;
24401 + }
24402 +
24403 + sta->wpa_trigger = param->u.wpa_trigger.trigger;
24404 +
24405 + sta_info_release(local, sta);
24406 + return 0;
24407 +}
24408 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24409 +
24410 +
24411 +static int ieee80211_ioctl_set_rate_sets(struct net_device *dev,
24412 + struct prism2_hostapd_param *param,
24413 + int param_len)
24414 +{
24415 + struct ieee80211_local *local = dev->priv;
24416 + u16 *pos = (u16 *) param->u.set_rate_sets.data;
24417 + int left = param_len - ((u8 *) pos - (u8 *) param);
24418 + int i, mode, num_supp, num_basic, *supp, *basic, *prev;
24419 +
24420 + mode = param->u.set_rate_sets.mode;
24421 + num_supp = param->u.set_rate_sets.num_supported_rates;
24422 + num_basic = param->u.set_rate_sets.num_basic_rates;
24423 +
24424 + if (left < (num_supp + num_basic) * 2) {
24425 + printk(KERN_WARNING "%s: invalid length in hostapd set rate "
24426 + "sets ioctl (%d != %d)\n", dev->name, left,
24427 + (num_supp + num_basic) * 2);
24428 + return -EINVAL;
24429 + }
24430 +
24431 + supp = (int *) kmalloc((num_supp + 1) * sizeof(int), GFP_KERNEL);
24432 + basic = (int *) kmalloc((num_basic + 1) * sizeof(int), GFP_KERNEL);
24433 +
24434 + if (!supp || !basic) {
24435 + kfree(supp);
24436 + kfree(basic);
24437 + return -ENOMEM;
24438 + }
24439 +
24440 + for (i = 0; i < num_supp; i++)
24441 + supp[i] = *pos++;
24442 + supp[i] = -1;
24443 +
24444 + for (i = 0; i < num_basic; i++)
24445 + basic[i] = *pos++;
24446 + basic[i] = -1;
24447 +
24448 + if (num_supp == 0) {
24449 + kfree(supp);
24450 + supp = NULL;
24451 + }
24452 +
24453 + if (num_basic == 0) {
24454 + kfree(basic);
24455 + basic = NULL;
24456 + }
24457 +
24458 + prev = local->supp_rates[mode];
24459 + local->supp_rates[mode] = supp;
24460 + kfree(prev);
24461 +
24462 + prev = local->basic_rates[mode];
24463 + local->basic_rates[mode] = basic;
24464 + kfree(prev);
24465 +
24466 + if (mode == local->conf.phymode) {
24467 + /* TODO: should update STA TX rates and remove STAs if they
24468 + * do not have any remaining supported rates after the change
24469 + */
24470 + ieee80211_prepare_rates(dev);
24471 + }
24472 +
24473 + return 0;
24474 +}
24475 +
24476 +
24477 +static int ieee80211_ioctl_add_if(struct net_device *dev,
24478 + struct prism2_hostapd_param *param,
24479 + int param_len)
24480 +{
24481 + u8 *pos = param->u.if_info.data;
24482 + int left = param_len - ((u8 *) pos - (u8 *) param);
24483 +
24484 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24485 + struct ieee80211_if_wds iwds;
24486 + struct hostapd_if_wds *wds =
24487 + (struct hostapd_if_wds *) param->u.if_info.data;
24488 +
24489 + if (left < sizeof(struct ieee80211_if_wds))
24490 + return -EPROTO;
24491 +
24492 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24493 +
24494 + return ieee80211_if_add_wds(dev, param->u.if_info.name,
24495 + &iwds, 1);
24496 + } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
24497 + struct hostapd_if_vlan *vlan = (struct hostapd_if_vlan *) pos;
24498 + struct ieee80211_if_vlan ivlan;
24499 +
24500 + if (left < sizeof(struct hostapd_if_vlan))
24501 + return -EPROTO;
24502 +
24503 + ivlan.id = vlan->id;
24504 +
24505 + return ieee80211_if_add_vlan(dev, param->u.if_info.name,
24506 + &ivlan, 1);
24507 + } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
24508 + struct hostapd_if_bss *bss =
24509 + (struct hostapd_if_bss *) param->u.if_info.data;
24510 +
24511 + if (left < sizeof(struct hostapd_if_bss))
24512 + return -EPROTO;
24513 +
24514 + return ieee80211_if_add_ap(dev, param->u.if_info.name,
24515 + bss->bssid, 1);
24516 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24517 +#if 0
24518 + struct hostapd_if_sta *sta =
24519 + (struct hostapd_if_sta *) param->u.if_info.data;
24520 +#endif
24521 +
24522 + if (left < sizeof(struct hostapd_if_sta))
24523 + return -EPROTO;
24524 +
24525 + return ieee80211_if_add_sta(dev, param->u.if_info.name, 1);
24526 + } else
24527 + return -EINVAL;
24528 +
24529 + return 0;
24530 +}
24531 +
24532 +
24533 +static int ieee80211_ioctl_remove_if(struct net_device *dev,
24534 + struct prism2_hostapd_param *param)
24535 +{
24536 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24537 + return ieee80211_if_remove_wds(dev, param->u.if_info.name, 1);
24538 + } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
24539 + return ieee80211_if_remove_vlan(dev, param->u.if_info.name, 1);
24540 + } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
24541 + return ieee80211_if_remove_ap(dev, param->u.if_info.name, 1);
24542 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24543 + return ieee80211_if_remove_sta(dev, param->u.if_info.name, 1);
24544 + } else {
24545 + return -EINVAL;
24546 + }
24547 +}
24548 +
24549 +
24550 +static int ieee80211_ioctl_update_if(struct net_device *dev,
24551 + struct prism2_hostapd_param *param,
24552 + int param_len)
24553 +{
24554 + u8 *pos = param->u.if_info.data;
24555 + int left = param_len - ((u8 *) pos - (u8 *) param);
24556 +
24557 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24558 + struct ieee80211_if_wds iwds;
24559 + struct hostapd_if_wds *wds =
24560 + (struct hostapd_if_wds *) param->u.if_info.data;
24561 +
24562 + if (left < sizeof(struct ieee80211_if_wds))
24563 + return -EPROTO;
24564 +
24565 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24566 +
24567 + return ieee80211_if_update_wds(dev, param->u.if_info.name,
24568 + &iwds, 1);
24569 + } else {
24570 + return -EOPNOTSUPP;
24571 + }
24572 +}
24573 +
24574 +
24575 +static int ieee80211_ioctl_flush_ifs(struct net_device *dev,
24576 + struct prism2_hostapd_param *param)
24577 +{
24578 + return ieee80211_if_flush(dev, 1);
24579 +}
24580 +
24581 +
24582 +static int ieee80211_ioctl_scan_req(struct net_device *dev,
24583 + struct prism2_hostapd_param *param,
24584 + int param_len)
24585 +{
24586 + u8 *pos = param->u.scan_req.ssid;
24587 + int left = param_len - ((u8 *) pos - (u8 *) param);
24588 + int len = param->u.scan_req.ssid_len;
24589 +
24590 + if (left < len || len > IEEE80211_MAX_SSID_LEN)
24591 + return -EINVAL;
24592 +
24593 + return ieee80211_sta_req_scan(dev, pos, len);
24594 +}
24595 +
24596 +
24597 +static int ieee80211_ioctl_sta_get_state(struct net_device *dev,
24598 + struct prism2_hostapd_param *param)
24599 +{
24600 + struct ieee80211_sub_if_data *sdata;
24601 +
24602 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24603 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24604 + return -EINVAL;
24605 + param->u.sta_get_state.state = sdata->u.sta.state;
24606 + return 0;
24607 +}
24608 +
24609 +
24610 +static int ieee80211_ioctl_mlme(struct net_device *dev,
24611 + struct prism2_hostapd_param *param)
24612 +{
24613 + struct ieee80211_sub_if_data *sdata;
24614 +
24615 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24616 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24617 + return -EINVAL;
24618 + switch (param->u.mlme.cmd) {
24619 + case MLME_STA_DEAUTH:
24620 + ieee80211_sta_deauthenticate(dev, param->u.mlme.reason_code);
24621 + break;
24622 + case MLME_STA_DISASSOC:
24623 + ieee80211_sta_disassociate(dev, param->u.mlme.reason_code);
24624 + break;
24625 + }
24626 + return 0;
24627 +}
24628 +
24629 +
24630 +static int ieee80211_ioctl_get_load_stats(struct net_device *dev,
24631 + struct prism2_hostapd_param *param)
24632 +{
24633 + struct ieee80211_local *local = dev->priv;
24634 +
24635 + param->u.get_load_stats.channel_use = local->channel_use;
24636 +/* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
24637 + local->channel_use = 0; */ /* now it's not raw counter */
24638 +
24639 + return 0;
24640 +}
24641 +
24642 +
24643 +static int ieee80211_ioctl_set_sta_vlan(struct net_device *dev,
24644 + struct prism2_hostapd_param *param)
24645 +{
24646 + struct ieee80211_local *local = dev->priv;
24647 + struct sta_info *sta;
24648 +
24649 + sta = sta_info_get(local, param->sta_addr);
24650 + if (sta) {
24651 + struct net_device *new_vlan_dev;
24652 + new_vlan_dev =
24653 + dev_get_by_name(param->u.set_sta_vlan.vlan_name);
24654 + if (new_vlan_dev) {
24655 +#if 0
24656 + printk("%s: Station " MACSTR " moved to vlan: %s\n",
24657 + dev->name, MAC2STR(param->sta_addr),
24658 + new_vlan_dev->name);
24659 +#endif
24660 + sta->dev = new_vlan_dev;
24661 + sta->vlan_id = param->u.set_sta_vlan.vlan_id;
24662 + dev_put(new_vlan_dev);
24663 + }
24664 + sta_info_release(local, sta);
24665 + }
24666 +
24667 + return sta ? 0 : -ENOENT;
24668 +}
24669 +
24670 +
24671 +static int ieee80211_set_gen_ie(struct net_device *dev, u8 *ie, size_t len)
24672 +{
24673 + struct ieee80211_local *local = dev->priv;
24674 + struct ieee80211_sub_if_data *sdata;
24675 +
24676 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24677 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
24678 + return ieee80211_sta_set_extra_ie(dev, ie, len);
24679 +
24680 + kfree(local->conf.generic_elem);
24681 + local->conf.generic_elem = kmalloc(len, GFP_KERNEL);
24682 + if (local->conf.generic_elem == NULL)
24683 + return -ENOMEM;
24684 + memcpy(local->conf.generic_elem, ie, len);
24685 + local->conf.generic_elem_len = len;
24686 +
24687 + return ieee80211_hw_config(dev);
24688 +}
24689 +
24690 +
24691 +static int
24692 +ieee80211_ioctl_set_generic_info_elem(struct net_device *dev,
24693 + struct prism2_hostapd_param *param,
24694 + int param_len)
24695 +{
24696 + u8 *pos = param->u.set_generic_info_elem.data;
24697 + int left = param_len - ((u8 *) pos - (u8 *) param);
24698 + int len = param->u.set_generic_info_elem.len;
24699 +
24700 + if (left < len)
24701 + return -EINVAL;
24702 +
24703 + return ieee80211_set_gen_ie(dev, pos, len);
24704 +}
24705 +
24706 +
24707 +static int ieee80211_ioctl_set_regulatory_domain(struct net_device *dev,
24708 + struct prism2_hostapd_param *param)
24709 +{
24710 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24711 + conf->regulatory_domain = param->u.set_regulatory_domain.rd;
24712 + return 0;
24713 +}
24714 +
24715 +
24716 +static int ieee80211_ioctl_set_adm_status(struct net_device *dev,
24717 + int val)
24718 +{
24719 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24720 + conf->adm_status = val;
24721 + return ieee80211_hw_config(dev);
24722 +}
24723 +
24724 +static int
24725 +ieee80211_ioctl_set_tx_queue_params(struct net_device *dev,
24726 + struct prism2_hostapd_param *param)
24727 +{
24728 + struct ieee80211_local *local = dev->priv;
24729 + struct ieee80211_tx_queue_params qparam;
24730 +
24731 + if (!local->hw->conf_tx) {
24732 + printk(KERN_DEBUG "%s: low-level driver does not support TX "
24733 + "queue configuration\n", dev->name);
24734 + return -EOPNOTSUPP;
24735 + }
24736 +
24737 + memset(&qparam, 0, sizeof(qparam));
24738 + qparam.aifs = param->u.tx_queue_params.aifs;
24739 + qparam.cw_min = param->u.tx_queue_params.cw_min;
24740 + qparam.cw_max = param->u.tx_queue_params.cw_max;
24741 + qparam.burst_time = param->u.tx_queue_params.burst_time;
24742 +
24743 + return local->hw->conf_tx(dev, param->u.tx_queue_params.queue,
24744 + &qparam);
24745 +}
24746 +
24747 +
24748 +static int ieee80211_ioctl_get_tx_stats(struct net_device *dev,
24749 + struct prism2_hostapd_param *param)
24750 +{
24751 + struct ieee80211_local *local = dev->priv;
24752 + struct ieee80211_tx_queue_stats stats;
24753 + int ret, i;
24754 +
24755 + if (!local->hw->get_tx_stats)
24756 + return -EOPNOTSUPP;
24757 +
24758 + memset(&stats, 0, sizeof(stats));
24759 + ret = local->hw->get_tx_stats(dev, &stats);
24760 + if (ret)
24761 + return ret;
24762 +
24763 + for (i = 0; i < 4; i++) {
24764 + param->u.get_tx_stats.data[i].len = stats.data[i].len;
24765 + param->u.get_tx_stats.data[i].limit = stats.data[i].limit;
24766 + param->u.get_tx_stats.data[i].count = stats.data[i].count;
24767 + }
24768 +
24769 + return 0;
24770 +}
24771 +
24772 +
24773 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
24774 + u8 *bssid_mask)
24775 +{
24776 + struct ieee80211_local *local = dev->priv;
24777 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24778 + int i, bss_count;
24779 + struct net_device **bss_devs, **prev;
24780 + struct net_device **sta_devs, **prev_sta_devs;
24781 +
24782 + bss_count = 0;
24783 + for (i = 0; i < conf->bss_count; i++) {
24784 + if (local->bss_devs[i])
24785 + bss_count++;
24786 + }
24787 +
24788 + if (new_count < bss_count) {
24789 + printk(KERN_DEBUG "%s: invalid BSS count %d (in use: %d)\n",
24790 + dev->name, new_count, bss_count);
24791 + return -EINVAL;
24792 + }
24793 +
24794 + bss_devs = kmalloc(new_count * sizeof(struct net_device *),
24795 + GFP_KERNEL);
24796 + if (bss_devs == NULL)
24797 + return -ENOMEM;
24798 + sta_devs = kmalloc(new_count * sizeof(struct net_device *),
24799 + GFP_KERNEL);
24800 + if (sta_devs == NULL) {
24801 + kfree(bss_devs);
24802 + return -ENOMEM;
24803 + }
24804 +
24805 + spin_lock_bh(&local->sub_if_lock);
24806 + memcpy(bss_devs, local->bss_devs,
24807 + bss_count * sizeof(struct net_device *));
24808 + memset(&bss_devs[bss_count], 0,
24809 + (new_count - bss_count) * sizeof(struct net_device *));
24810 +
24811 + if (bssid_mask)
24812 + memcpy(conf->bssid_mask, bssid_mask, ETH_ALEN);
24813 +
24814 + prev = local->bss_devs;
24815 + local->bss_devs = bss_devs;
24816 + conf->bss_count = new_count;
24817 +
24818 + memcpy(sta_devs, local->sta_devs,
24819 + bss_count * sizeof(struct net_device *));
24820 + memset(&sta_devs[bss_count], 0,
24821 + (new_count - bss_count) * sizeof(struct net_device *));
24822 + prev_sta_devs = local->sta_devs;
24823 + local->sta_devs = sta_devs;
24824 +
24825 + spin_unlock_bh(&local->sub_if_lock);
24826 + kfree(prev);
24827 + kfree(prev_sta_devs);
24828 +
24829 + return ieee80211_hw_config(dev);
24830 +}
24831 +
24832 +static int ieee80211_ioctl_set_bss(struct net_device *dev,
24833 + struct prism2_hostapd_param *param)
24834 +{
24835 + return ieee80211_set_bss_count(dev, param->u.set_bss.bss_count,
24836 + param->u.set_bss.bssid_mask);
24837 +}
24838 +
24839 +
24840 +static int ieee80211_ioctl_set_channel_flag(struct net_device *dev,
24841 + struct prism2_hostapd_param *param)
24842 +{
24843 + struct ieee80211_local *local = dev->priv;
24844 + struct ieee80211_hw_modes *mode = NULL;
24845 + struct ieee80211_channel *chan = NULL;
24846 + int i;
24847 +
24848 + for (i = 0; i < local->hw->num_modes; i++) {
24849 + mode = &local->hw->modes[i];
24850 + if (mode->mode == param->u.set_channel_flag.mode)
24851 + break;
24852 + mode = NULL;
24853 + }
24854 +
24855 + if (!mode)
24856 + return -ENOENT;
24857 +
24858 + for (i = 0; i < mode->num_channels; i++) {
24859 + chan = &mode->channels[i];
24860 + if (chan->chan == param->u.set_channel_flag.chan)
24861 + break;
24862 + chan = NULL;
24863 + }
24864 +
24865 + if (!chan)
24866 + return -ENOENT;
24867 +
24868 + chan->flag = param->u.set_channel_flag.flag;
24869 + chan->power_level = param->u.set_channel_flag.power_level;
24870 + chan->antenna_max = param->u.set_channel_flag.antenna_max;
24871 +
24872 + return 0;
24873 +}
24874 +
24875 +
24876 +static int ieee80211_ioctl_set_quiet_params(struct net_device *dev,
24877 + struct prism2_hostapd_param *param)
24878 +{
24879 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24880 + conf->quiet_duration = param->u.quiet.duration;
24881 + conf->quiet_offset = param->u.quiet.offset;
24882 + conf->quiet_period = param->u.quiet.period;
24883 + return 0;
24884 +}
24885 +
24886 +
24887 +static int ieee80211_ioctl_set_radar_params(struct net_device *dev,
24888 + struct prism2_hostapd_param *param)
24889 +{
24890 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24891 + conf->radar_firpwr_threshold = param->u.radar.radar_firpwr_threshold;
24892 + conf->radar_rssi_threshold = param->u.radar.radar_rssi_threshold;
24893 + conf->pulse_height_threshold = param->u.radar.pulse_height_threshold;
24894 + conf->pulse_rssi_threshold = param->u.radar.pulse_rssi_threshold;
24895 + conf->pulse_inband_threshold = param->u.radar.pulse_inband_threshold;
24896 + return 0;
24897 +}
24898 +
24899 +
24900 +static int ieee80211_ioctl_priv_hostapd(struct net_device *dev,
24901 + struct iw_point *p)
24902 +{
24903 + struct prism2_hostapd_param *param;
24904 + int ret = 0;
24905 +
24906 + if (p->length < sizeof(struct prism2_hostapd_param) ||
24907 + p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) {
24908 + printk(KERN_DEBUG "%s: hostapd ioctl: ptr=%p len=%d min=%d "
24909 + "max=%d\n", dev->name, p->pointer, p->length,
24910 + (int)sizeof(struct prism2_hostapd_param),
24911 + PRISM2_HOSTAPD_MAX_BUF_SIZE);
24912 + return -EINVAL;
24913 + }
24914 +
24915 + param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
24916 + if (param == NULL)
24917 + return -ENOMEM;
24918 +
24919 + if (copy_from_user(param, p->pointer, p->length)) {
24920 + ret = -EFAULT;
24921 + goto out;
24922 + }
24923 +
24924 + switch (param->cmd) {
24925 + case PRISM2_HOSTAPD_FLUSH:
24926 + ret = ieee80211_ioctl_flush(dev, param);
24927 + break;
24928 + case PRISM2_HOSTAPD_ADD_STA:
24929 + ret = ieee80211_ioctl_add_sta(dev, param);
24930 + break;
24931 + case PRISM2_HOSTAPD_REMOVE_STA:
24932 + ret = ieee80211_ioctl_remove_sta(dev, param);
24933 + break;
24934 + case PRISM2_HOSTAPD_GET_INFO_STA:
24935 + ret = ieee80211_ioctl_get_info_sta(dev, param);
24936 + break;
24937 + case PRISM2_SET_ENCRYPTION:
24938 + ret = ieee80211_ioctl_set_encryption(dev, param, p->length);
24939 + break;
24940 + case PRISM2_GET_ENCRYPTION:
24941 + ret = ieee80211_ioctl_get_encryption(dev, param, p->length);
24942 + break;
24943 + case PRISM2_HOSTAPD_SET_FLAGS_STA:
24944 + ret = ieee80211_ioctl_set_flags_sta(dev, param);
24945 + break;
24946 + case PRISM2_HOSTAPD_SET_BEACON:
24947 + ret = ieee80211_ioctl_set_beacon(dev, param, p->length, 0);
24948 + break;
24949 + case PRISM2_HOSTAPD_GET_HW_FEATURES:
24950 + ret = ieee80211_ioctl_get_hw_features(dev, param, p->length);
24951 + break;
24952 + case PRISM2_HOSTAPD_SCAN:
24953 + ret = ieee80211_ioctl_scan(dev, param);
24954 + break;
24955 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24956 + case PRISM2_HOSTAPD_WPA_TRIGGER:
24957 + ret = ieee80211_ioctl_wpa_trigger(dev, param);
24958 + break;
24959 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24960 + case PRISM2_HOSTAPD_SET_RATE_SETS:
24961 + ret = ieee80211_ioctl_set_rate_sets(dev, param, p->length);
24962 + break;
24963 + case PRISM2_HOSTAPD_ADD_IF:
24964 + ret = ieee80211_ioctl_add_if(dev, param, p->length);
24965 + break;
24966 + case PRISM2_HOSTAPD_REMOVE_IF:
24967 + ret = ieee80211_ioctl_remove_if(dev, param);
24968 + break;
24969 + case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE:
24970 + ret = ieee80211_ioctl_get_dot11counterstable(dev, param);
24971 + break;
24972 + case PRISM2_HOSTAPD_GET_LOAD_STATS:
24973 + ret = ieee80211_ioctl_get_load_stats(dev, param);
24974 + break;
24975 + case PRISM2_HOSTAPD_SET_STA_VLAN:
24976 + ret = ieee80211_ioctl_set_sta_vlan(dev, param);
24977 + break;
24978 + case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM:
24979 + ret = ieee80211_ioctl_set_generic_info_elem(dev, param,
24980 + p->length);
24981 + break;
24982 + case PRISM2_HOSTAPD_SET_CHANNEL_FLAG:
24983 + ret = ieee80211_ioctl_set_channel_flag(dev, param);
24984 + break;
24985 + case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN:
24986 + ret = ieee80211_ioctl_set_regulatory_domain(dev, param);
24987 + break;
24988 + case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS:
24989 + ret = ieee80211_ioctl_set_tx_queue_params(dev, param);
24990 + break;
24991 + case PRISM2_HOSTAPD_SET_BSS:
24992 + ret = ieee80211_ioctl_set_bss(dev, param);
24993 + break;
24994 + case PRISM2_HOSTAPD_GET_TX_STATS:
24995 + ret = ieee80211_ioctl_get_tx_stats(dev, param);
24996 + break;
24997 + case PRISM2_HOSTAPD_UPDATE_IF:
24998 + ret = ieee80211_ioctl_update_if(dev, param, p->length);
24999 + break;
25000 + case PRISM2_HOSTAPD_SCAN_REQ:
25001 + ret = ieee80211_ioctl_scan_req(dev, param, p->length);
25002 + break;
25003 + case PRISM2_STA_GET_STATE:
25004 + ret = ieee80211_ioctl_sta_get_state(dev, param);
25005 + break;
25006 + case PRISM2_HOSTAPD_MLME:
25007 + ret = ieee80211_ioctl_mlme(dev, param);
25008 + break;
25009 + case PRISM2_HOSTAPD_FLUSH_IFS:
25010 + ret = ieee80211_ioctl_flush_ifs(dev, param);
25011 + break;
25012 + case PRISM2_HOSTAPD_SET_RADAR_PARAMS:
25013 + ret = ieee80211_ioctl_set_radar_params(dev, param);
25014 + break;
25015 + case PRISM2_HOSTAPD_SET_QUIET_PARAMS:
25016 + ret = ieee80211_ioctl_set_quiet_params(dev, param);
25017 + break;
25018 + default:
25019 + ret = -EOPNOTSUPP;
25020 + break;
25021 + }
25022 +
25023 + if (copy_to_user(p->pointer, param, p->length))
25024 + ret = -EFAULT;
25025 +
25026 + out:
25027 + kfree(param);
25028 +
25029 + return ret;
25030 +}
25031 +
25032 +
25033 +static int ieee80211_ioctl_giwname(struct net_device *dev,
25034 + struct iw_request_info *info,
25035 + char *name, char *extra)
25036 +{
25037 + struct ieee80211_local *local = dev->priv;
25038 +
25039 + switch (local->conf.phymode) {
25040 + case MODE_IEEE80211A:
25041 + strcpy(name, "IEEE 802.11a");
25042 + break;
25043 + case MODE_IEEE80211B:
25044 + strcpy(name, "IEEE 802.11b");
25045 + break;
25046 + case MODE_IEEE80211G:
25047 + strcpy(name, "IEEE 802.11g");
25048 + break;
25049 + case MODE_ATHEROS_TURBO:
25050 + strcpy(name, "5GHz Turbo");
25051 + break;
25052 + default:
25053 + strcpy(name, "IEEE 802.11");
25054 + break;
25055 + }
25056 +
25057 + return 0;
25058 +}
25059 +
25060 +
25061 +static int ieee80211_ioctl_giwrange(struct net_device *dev,
25062 + struct iw_request_info *info,
25063 + struct iw_point *data, char *extra)
25064 +{
25065 + struct iw_range *range = (struct iw_range *) extra;
25066 +
25067 + data->length = sizeof(struct iw_range);
25068 + memset(range, 0, sizeof(struct iw_range));
25069 +
25070 + range->we_version_compiled = WIRELESS_EXT;
25071 + range->we_version_source = 14;
25072 + range->retry_capa = IW_RETRY_LIMIT;
25073 + range->retry_flags = IW_RETRY_LIMIT;
25074 + range->min_retry = 0;
25075 + range->max_retry = 255;
25076 + range->min_rts = 0;
25077 + range->max_rts = 2347;
25078 + range->min_frag = 256;
25079 + range->max_frag = 2346;
25080 +
25081 + return 0;
25082 +}
25083 +
25084 +
25085 +struct ieee80211_channel_range {
25086 + short start_freq;
25087 + short end_freq;
25088 + unsigned char power_level;
25089 + unsigned char antenna_max;
25090 +};
25091 +
25092 +static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
25093 + { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
25094 + { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
25095 + { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
25096 + { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
25097 + { 0 }
25098 +};
25099 +
25100 +static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
25101 + { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
25102 + { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
25103 + { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
25104 + { 0 }
25105 +};
25106 +
25107 +
25108 +static const struct ieee80211_channel_range *channel_range =
25109 + ieee80211_fcc_channels;
25110 +
25111 +
25112 +static void ieee80211_unmask_channel(struct net_device *dev, int mode,
25113 + struct ieee80211_channel *chan)
25114 +{
25115 + int i;
25116 +
25117 + chan->flag = 0;
25118 +
25119 + if (ieee80211_regdom == 64 &&
25120 + (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
25121 + /* Do not allow Turbo modes in Japan. */
25122 + return;
25123 + }
25124 +
25125 + for (i = 0; channel_range[i].start_freq; i++) {
25126 + const struct ieee80211_channel_range *r = &channel_range[i];
25127 + if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
25128 + if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
25129 + chan->freq >= 5260 && chan->freq <= 5320) {
25130 + /*
25131 + * Skip new channels in Japan since the
25132 + * firmware was not marked having been upgraded
25133 + * by the vendor.
25134 + */
25135 + continue;
25136 + }
25137 +
25138 + if (ieee80211_regdom == 0x10 &&
25139 + (chan->freq == 5190 || chan->freq == 5210 ||
25140 + chan->freq == 5230)) {
25141 + /* Skip MKK channels when in FCC domain. */
25142 + continue;
25143 + }
25144 +
25145 + chan->flag |= IEEE80211_CHAN_W_SCAN |
25146 + IEEE80211_CHAN_W_ACTIVE_SCAN |
25147 + IEEE80211_CHAN_W_IBSS;
25148 + chan->power_level = r->power_level;
25149 + chan->antenna_max = r->antenna_max;
25150 +
25151 + if (ieee80211_regdom == 64 &&
25152 + (chan->freq == 5170 || chan->freq == 5190 ||
25153 + chan->freq == 5210 || chan->freq == 5230)) {
25154 + /*
25155 + * New regulatory rules in Japan have backwards
25156 + * compatibility with old channels in 5.15-5.25
25157 + * GHz band, but the station is not allowed to
25158 + * use active scan on these old channels.
25159 + */
25160 + chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
25161 + }
25162 +
25163 + if (ieee80211_regdom == 64 &&
25164 + (chan->freq == 5260 || chan->freq == 5280 ||
25165 + chan->freq == 5300 || chan->freq == 5320)) {
25166 + /*
25167 + * IBSS is not allowed on 5.25-5.35 GHz band
25168 + * due to radar detection requirements.
25169 + */
25170 + chan->flag &= ~IEEE80211_CHAN_W_IBSS;
25171 + }
25172 +
25173 + break;
25174 + }
25175 + }
25176 +}
25177 +
25178 +
25179 +static int ieee80211_unmask_channels(struct net_device *dev)
25180 +{
25181 + struct ieee80211_local *local = dev->priv;
25182 + int m, c;
25183 +
25184 + for (m = 0; m < local->hw->num_modes; m++) {
25185 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25186 + for (c = 0; c < mode->num_channels; c++) {
25187 + ieee80211_unmask_channel(dev, mode->mode,
25188 + &mode->channels[c]);
25189 + }
25190 + }
25191 + return 0;
25192 +}
25193 +
25194 +
25195 +static int ieee80211_init_client(struct net_device *dev)
25196 +{
25197 + if (ieee80211_regdom == 0x40)
25198 + channel_range = ieee80211_mkk_channels;
25199 + ieee80211_unmask_channels(dev);
25200 + ieee80211_ioctl_set_adm_status(dev, 1);
25201 + return 0;
25202 +}
25203 +
25204 +
25205 +static int ieee80211_is_client_mode(int iw_mode)
25206 +{
25207 + return (iw_mode == IW_MODE_INFRA || iw_mode == IW_MODE_ADHOC);
25208 +}
25209 +
25210 +
25211 +static int ieee80211_ioctl_siwmode(struct net_device *dev,
25212 + struct iw_request_info *info,
25213 + __u32 *mode, char *extra)
25214 +{
25215 + struct ieee80211_local *local = dev->priv;
25216 +
25217 + if (!ieee80211_is_client_mode(local->conf.mode) &&
25218 + ieee80211_is_client_mode(*mode)) {
25219 + ieee80211_init_client(dev);
25220 + }
25221 + if (local->conf.mode != *mode) {
25222 + struct ieee80211_sub_if_data *sdata =
25223 + IEEE80211_DEV_TO_SUB_IF(dev);
25224 + sta_info_flush(local, NULL);
25225 + if (local->conf.mode == IW_MODE_ADHOC &&
25226 + sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25227 + /* Clear drop_unencrypted when leaving adhoc mode since
25228 + * only adhoc mode is using automatic setting for this
25229 + * in 80211.o. */
25230 + sdata->drop_unencrypted = 0;
25231 + }
25232 + if (*mode == IW_MODE_MASTER) {
25233 + /* AP mode does not currently use ACM bits to limit
25234 + * TX, so clear the bitfield here. */
25235 + local->wmm_acm = 0;
25236 + }
25237 + }
25238 + local->conf.mode = *mode;
25239 + return ieee80211_hw_config(dev);
25240 +}
25241 +
25242 +
25243 +static int ieee80211_ioctl_giwmode(struct net_device *dev,
25244 + struct iw_request_info *info,
25245 + __u32 *mode, char *extra)
25246 +{
25247 + struct ieee80211_local *local = dev->priv;
25248 + struct ieee80211_sub_if_data *sdata;
25249 +
25250 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25251 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25252 + if (local->conf.mode == IW_MODE_ADHOC)
25253 + *mode = IW_MODE_ADHOC;
25254 + else
25255 + *mode = IW_MODE_INFRA;
25256 + } else
25257 + *mode = local->conf.mode;
25258 + return 0;
25259 +}
25260 +
25261 +
25262 +int ieee80211_ioctl_siwfreq(struct net_device *dev,
25263 + struct iw_request_info *info,
25264 + struct iw_freq *freq, char *extra)
25265 +{
25266 + struct ieee80211_local *local = dev->priv;
25267 + int m, c, nfreq, set = 0;
25268 +
25269 + /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
25270 + if (freq->e == 0)
25271 + nfreq = -1;
25272 + else {
25273 + int i, div = 1000000;
25274 + for (i = 0; i < freq->e; i++)
25275 + div /= 10;
25276 + if (div > 0)
25277 + nfreq = freq->m / div;
25278 + else
25279 + return -EINVAL;
25280 + }
25281 +
25282 + for (m = 0; m < local->hw->num_modes; m++) {
25283 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25284 + for (c = 0; c < mode->num_channels; c++) {
25285 + struct ieee80211_channel *chan = &mode->channels[c];
25286 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
25287 + ((freq->e == 0 && chan->chan == freq->m) ||
25288 + (freq->e > 0 && nfreq == chan->freq)) &&
25289 + (local->hw_modes & (1 << mode->mode))) {
25290 + /* Use next_mode as the mode preference to
25291 + * resolve non-unique channel numbers. */
25292 + if (set && mode->mode != local->next_mode)
25293 + continue;
25294 +
25295 + local->conf.channel = chan->chan;
25296 + local->conf.channel_val = chan->val;
25297 + local->conf.power_level = chan->power_level;
25298 + local->conf.freq = chan->freq;
25299 + local->conf.phymode = mode->mode;
25300 + local->conf.antenna_max = chan->antenna_max;
25301 + set++;
25302 + }
25303 + }
25304 + }
25305 +
25306 + if (set) {
25307 + local->sta_scanning = 0; /* Abort possible scan */
25308 + return ieee80211_hw_config(dev);
25309 + }
25310 +
25311 + return -EINVAL;
25312 +}
25313 +
25314 +
25315 +static int ieee80211_ioctl_giwfreq(struct net_device *dev,
25316 + struct iw_request_info *info,
25317 + struct iw_freq *freq, char *extra)
25318 +{
25319 + struct ieee80211_local *local = dev->priv;
25320 +
25321 + /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
25322 + * driver for the current channel with firmware-based management */
25323 +
25324 + freq->m = local->conf.freq;
25325 + freq->e = 6;
25326 +
25327 + return 0;
25328 +}
25329 +
25330 +
25331 +static int ieee80211_ioctl_siwessid(struct net_device *dev,
25332 + struct iw_request_info *info,
25333 + struct iw_point *data, char *ssid)
25334 +{
25335 + struct ieee80211_local *local = dev->priv;
25336 + struct ieee80211_sub_if_data *sdata;
25337 + size_t len = data->length;
25338 +
25339 + /* iwconfig uses nul termination in SSID.. */
25340 + if (len > 0 && ssid[len - 1] == '\0')
25341 + len--;
25342 +
25343 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25344 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
25345 + return ieee80211_sta_set_ssid(dev, ssid, len);
25346 +
25347 + kfree(local->conf.ssid);
25348 + local->conf.ssid = kmalloc(len + 1, GFP_KERNEL);
25349 + if (local->conf.ssid == NULL)
25350 + return -ENOMEM;
25351 + memcpy(local->conf.ssid, ssid, len);
25352 + local->conf.ssid[len] = '\0';
25353 + local->conf.ssid_len = len;
25354 + return ieee80211_hw_config(dev);
25355 +}
25356 +
25357 +
25358 +static int ieee80211_ioctl_giwessid(struct net_device *dev,
25359 + struct iw_request_info *info,
25360 + struct iw_point *data, char *ssid)
25361 +{
25362 + struct ieee80211_local *local = dev->priv;
25363 + size_t len;
25364 +
25365 + struct ieee80211_sub_if_data *sdata;
25366 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25367 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25368 + int res = ieee80211_sta_get_ssid(dev, ssid, &len);
25369 + if (res == 0)
25370 + data->length = len;
25371 + return res;
25372 + }
25373 +
25374 + len = local->conf.ssid_len;
25375 + if (len > IW_ESSID_MAX_SIZE)
25376 + len = IW_ESSID_MAX_SIZE;
25377 + memcpy(ssid, local->conf.ssid, len);
25378 + data->length = len;
25379 + return 0;
25380 +}
25381 +
25382 +
25383 +static int ieee80211_ioctl_siwap(struct net_device *dev,
25384 + struct iw_request_info *info,
25385 + struct sockaddr *ap_addr, char *extra)
25386 +{
25387 + struct ieee80211_local *local = dev->priv;
25388 + struct ieee80211_sub_if_data *sdata;
25389 +
25390 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25391 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25392 + int changed_bssid = 0;
25393 + if (memcmp(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
25394 + ETH_ALEN) != 0)
25395 + changed_bssid = 1;
25396 + memcpy(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
25397 + ETH_ALEN);
25398 + if (changed_bssid && ieee80211_hw_config(dev)) {
25399 + printk(KERN_DEBUG "%s: Failed to config new BSSID to "
25400 + "the low-level driver\n", dev->name);
25401 + }
25402 + return ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
25403 + }
25404 +
25405 + return -EOPNOTSUPP;
25406 +}
25407 +
25408 +
25409 +static int ieee80211_ioctl_giwap(struct net_device *dev,
25410 + struct iw_request_info *info,
25411 + struct sockaddr *ap_addr, char *extra)
25412 +{
25413 + struct ieee80211_sub_if_data *sdata;
25414 +
25415 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25416 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25417 + ap_addr->sa_family = ARPHRD_ETHER;
25418 + memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
25419 + return 0;
25420 + }
25421 +
25422 + return -EOPNOTSUPP;
25423 +}
25424 +
25425 +
25426 +static int ieee80211_ioctl_siwscan(struct net_device *dev,
25427 + struct iw_request_info *info,
25428 + struct iw_point *data, char *extra)
25429 +{
25430 + struct ieee80211_local *local = dev->priv;
25431 + u8 *ssid = NULL;
25432 + size_t ssid_len = 0;
25433 +
25434 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
25435 + ssid = local->conf.ssid;
25436 + ssid_len = local->conf.ssid_len;
25437 + }
25438 + return ieee80211_sta_req_scan(dev, ssid, ssid_len);
25439 +}
25440 +
25441 +
25442 +static int ieee80211_ioctl_giwscan(struct net_device *dev,
25443 + struct iw_request_info *info,
25444 + struct iw_point *data, char *extra)
25445 +{
25446 + int res;
25447 + struct ieee80211_local *local = dev->priv;
25448 + if (local->sta_scanning)
25449 + return -EAGAIN;
25450 + res = ieee80211_sta_scan_results(dev, extra, IW_SCAN_MAX_DATA);
25451 + if (res >= 0) {
25452 + data->length = res;
25453 + return 0;
25454 + }
25455 + data->length = 0;
25456 + return res;
25457 +}
25458 +
25459 +
25460 +static int ieee80211_ioctl_siwrts(struct net_device *dev,
25461 + struct iw_request_info *info,
25462 + struct iw_param *rts, char *extra)
25463 +{
25464 + struct ieee80211_local *local = dev->priv;
25465 +
25466 + if (rts->disabled)
25467 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
25468 + else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
25469 + return -EINVAL;
25470 + else
25471 + local->rts_threshold = rts->value;
25472 +
25473 + /* If the wlan card performs RTS/CTS in hardware/firmware,
25474 + * configure it here */
25475 +
25476 + if (local->hw->set_rts_threshold) {
25477 + local->hw->set_rts_threshold(dev, local->rts_threshold);
25478 + }
25479 +
25480 + return 0;
25481 +}
25482 +
25483 +static int ieee80211_ioctl_giwrts(struct net_device *dev,
25484 + struct iw_request_info *info,
25485 + struct iw_param *rts, char *extra)
25486 +{
25487 + struct ieee80211_local *local = dev->priv;
25488 +
25489 + rts->value = local->rts_threshold;
25490 + rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
25491 + rts->fixed = 1;
25492 +
25493 + return 0;
25494 +}
25495 +
25496 +
25497 +static int ieee80211_ioctl_siwfrag(struct net_device *dev,
25498 + struct iw_request_info *info,
25499 + struct iw_param *frag, char *extra)
25500 +{
25501 + struct ieee80211_local *local = dev->priv;
25502 +
25503 + if (frag->disabled)
25504 + local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
25505 + else if (frag->value < 256 ||
25506 + frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
25507 + return -EINVAL;
25508 + else {
25509 + /* Fragment length must be even, so strip LSB. */
25510 + local->fragmentation_threshold = frag->value & ~0x1;
25511 + }
25512 +
25513 + /* If the wlan card performs fragmentation in hardware/firmware,
25514 + * configure it here */
25515 +
25516 + if (local->hw->set_frag_threshold) {
25517 + local->hw->set_frag_threshold(
25518 + dev, local->fragmentation_threshold);
25519 + }
25520 +
25521 + return 0;
25522 +}
25523 +
25524 +static int ieee80211_ioctl_giwfrag(struct net_device *dev,
25525 + struct iw_request_info *info,
25526 + struct iw_param *frag, char *extra)
25527 +{
25528 + struct ieee80211_local *local = dev->priv;
25529 +
25530 + frag->value = local->fragmentation_threshold;
25531 + frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
25532 + frag->fixed = 1;
25533 +
25534 + return 0;
25535 +}
25536 +
25537 +
25538 +static int ieee80211_ioctl_siwretry(struct net_device *dev,
25539 + struct iw_request_info *info,
25540 + struct iw_param *retry, char *extra)
25541 +{
25542 + struct ieee80211_local *local = dev->priv;
25543 +
25544 + if (retry->disabled ||
25545 + (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25546 + return -EINVAL;
25547 +
25548 + if (retry->flags & IW_RETRY_MAX)
25549 + local->long_retry_limit = retry->value;
25550 + else if (retry->flags & IW_RETRY_MIN)
25551 + local->short_retry_limit = retry->value;
25552 + else {
25553 + local->long_retry_limit = retry->value;
25554 + local->short_retry_limit = retry->value;
25555 + }
25556 +
25557 + if (local->hw->set_retry_limit) {
25558 + return local->hw->set_retry_limit(
25559 + dev, local->short_retry_limit,
25560 + local->long_retry_limit);
25561 + }
25562 +
25563 + return 0;
25564 +}
25565 +
25566 +
25567 +static int ieee80211_ioctl_giwretry(struct net_device *dev,
25568 + struct iw_request_info *info,
25569 + struct iw_param *retry, char *extra)
25570 +{
25571 + struct ieee80211_local *local = dev->priv;
25572 +
25573 + retry->disabled = 0;
25574 + if ((retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25575 + return -EINVAL;
25576 + if (retry->flags & IW_RETRY_MAX) {
25577 + retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
25578 + retry->value = local->long_retry_limit;
25579 + } else {
25580 + retry->flags = IW_RETRY_LIMIT;
25581 + retry->value = local->short_retry_limit;
25582 + if (local->long_retry_limit != local->short_retry_limit)
25583 + retry->flags |= IW_RETRY_MIN;
25584 + }
25585 +
25586 + return 0;
25587 +}
25588 +
25589 +
25590 +static void ieee80211_ioctl_unmask_channels(struct ieee80211_local *local)
25591 +{
25592 + int m, c;
25593 +
25594 + for (m = 0; m < local->hw->num_modes; m++) {
25595 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25596 + for (c = 0; c < mode->num_channels; c++) {
25597 + struct ieee80211_channel *chan = &mode->channels[c];
25598 + chan->flag |= IEEE80211_CHAN_W_SCAN;
25599 + }
25600 + }
25601 +}
25602 +
25603 +
25604 +static int ieee80211_ioctl_test_mode(struct net_device *dev, int mode)
25605 +{
25606 + struct ieee80211_local *local = dev->priv;
25607 + int ret = -EOPNOTSUPP;
25608 +
25609 + if (mode == IEEE80211_TEST_UNMASK_CHANNELS) {
25610 + ieee80211_ioctl_unmask_channels(local);
25611 + ret = 0;
25612 + }
25613 +
25614 + if (local->hw->test_mode)
25615 + ret = local->hw->test_mode(dev, mode);
25616 +
25617 + return ret;
25618 +}
25619 +
25620 +
25621 +static int ieee80211_ioctl_clear_keys(struct net_device *dev)
25622 +{
25623 + struct ieee80211_local *local = dev->priv;
25624 + struct ieee80211_key_conf key;
25625 + struct list_head *ptr;
25626 + int i;
25627 + u8 addr[ETH_ALEN];
25628 + struct ieee80211_key_conf *keyconf;
25629 +
25630 + memset(addr, 0xff, ETH_ALEN);
25631 + list_for_each(ptr, &local->sub_if_list) {
25632 + struct ieee80211_sub_if_data *sdata =
25633 + list_entry(ptr, struct ieee80211_sub_if_data, list);
25634 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
25635 + keyconf = NULL;
25636 + if (sdata->keys[i] &&
25637 + !sdata->keys[i]->force_sw_encrypt &&
25638 + local->hw->set_key &&
25639 + (keyconf = ieee80211_key_data2conf(local,
25640 + sdata->keys[i]))
25641 + != NULL)
25642 + local->hw->set_key(dev, DISABLE_KEY, addr,
25643 + keyconf, 0);
25644 + kfree(keyconf);
25645 + kfree(sdata->keys[i]);
25646 + sdata->keys[i] = NULL;
25647 + }
25648 + sdata->default_key = NULL;
25649 + }
25650 +
25651 + spin_lock_bh(&local->sta_lock);
25652 + list_for_each(ptr, &local->sta_list) {
25653 + struct sta_info *sta =
25654 + list_entry(ptr, struct sta_info, list);
25655 + keyconf = NULL;
25656 + if (sta->key && !sta->key->force_sw_encrypt &&
25657 + local->hw->set_key &&
25658 + (keyconf = ieee80211_key_data2conf(local, sta->key))
25659 + != NULL)
25660 + local->hw->set_key(dev, DISABLE_KEY, sta->addr,
25661 + keyconf, sta->aid);
25662 + kfree(keyconf);
25663 + kfree(sta->key);
25664 + sta->key = NULL;
25665 + }
25666 + spin_unlock_bh(&local->sta_lock);
25667 +
25668 + memset(&key, 0, sizeof(key));
25669 + if (local->hw->set_key &&
25670 + local->hw->set_key(dev, REMOVE_ALL_KEYS, NULL,
25671 + &key, 0))
25672 + printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
25673 + dev->name);
25674 +
25675 + return 0;
25676 +}
25677 +
25678 +
25679 +static int
25680 +ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
25681 + struct ieee80211_sub_if_data *sdata,
25682 + int rate)
25683 +{
25684 + struct ieee80211_local *local = dev->priv;
25685 + int i;
25686 +
25687 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25688 + return -ENOENT;
25689 +
25690 + if (rate == 0) {
25691 + sdata->u.ap.force_unicast_rateidx = -1;
25692 + return 0;
25693 + }
25694 +
25695 + for (i = 0; i < local->num_curr_rates; i++) {
25696 + if (local->curr_rates[i].rate == rate) {
25697 + sdata->u.ap.force_unicast_rateidx = i;
25698 + return 0;
25699 + }
25700 + }
25701 + return -EINVAL;
25702 +}
25703 +
25704 +
25705 +static int
25706 +ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
25707 + struct ieee80211_sub_if_data *sdata,
25708 + int rate)
25709 +{
25710 + struct ieee80211_local *local = dev->priv;
25711 + int i;
25712 +
25713 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25714 + return -ENOENT;
25715 +
25716 + if (rate == 0) {
25717 + sdata->u.ap.max_ratectrl_rateidx = -1;
25718 + return 0;
25719 + }
25720 +
25721 + for (i = 0; i < local->num_curr_rates; i++) {
25722 + if (local->curr_rates[i].rate == rate) {
25723 + sdata->u.ap.max_ratectrl_rateidx = i;
25724 + return 0;
25725 + }
25726 + }
25727 + return -EINVAL;
25728 +}
25729 +
25730 +
25731 +static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
25732 + struct ieee80211_key *key)
25733 +{
25734 + struct ieee80211_key_conf *keyconf;
25735 + u8 addr[ETH_ALEN];
25736 +
25737 + if (key == NULL || key->alg != ALG_WEP || !key->force_sw_encrypt ||
25738 + local->hw->device_hides_wep)
25739 + return;
25740 +
25741 + memset(addr, 0xff, ETH_ALEN);
25742 + keyconf = ieee80211_key_data2conf(local, key);
25743 + if (keyconf && local->hw->set_key &&
25744 + local->hw->set_key(local->mdev, SET_KEY, addr, keyconf, 0) == 0) {
25745 + key->force_sw_encrypt = keyconf->force_sw_encrypt;
25746 + key->hw_key_idx = keyconf->hw_key_idx;
25747 + }
25748 + kfree(keyconf);
25749 +}
25750 +
25751 +
25752 +static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
25753 + struct ieee80211_key *key)
25754 +{
25755 + struct ieee80211_key_conf *keyconf;
25756 + u8 addr[ETH_ALEN];
25757 +
25758 + if (key == NULL || key->alg != ALG_WEP || key->force_sw_encrypt ||
25759 + local->hw->device_hides_wep)
25760 + return;
25761 +
25762 + memset(addr, 0xff, ETH_ALEN);
25763 + keyconf = ieee80211_key_data2conf(local, key);
25764 + if (keyconf && local->hw->set_key)
25765 + local->hw->set_key(local->mdev, DISABLE_KEY, addr, keyconf, 0);
25766 + kfree(keyconf);
25767 + key->force_sw_encrypt = 1;
25768 +}
25769 +
25770 +
25771 +static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
25772 + int value)
25773 +{
25774 + int i;
25775 + struct list_head *ptr;
25776 +
25777 + local->default_wep_only = value;
25778 + list_for_each(ptr, &local->sub_if_list) {
25779 + struct ieee80211_sub_if_data *sdata =
25780 + list_entry(ptr, struct ieee80211_sub_if_data, list);
25781 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
25782 + if (value) {
25783 + ieee80211_key_enable_hwaccel(local,
25784 + sdata->keys[i]);
25785 + } else {
25786 + ieee80211_key_disable_hwaccel(local,
25787 + sdata->keys[i]);
25788 + }
25789 + }
25790 + }
25791 +
25792 + return 0;
25793 +}
25794 +
25795 +
25796 +static int ieee80211_ioctl_prism2_param(struct net_device *dev,
25797 + struct iw_request_info *info,
25798 + void *wrqu, char *extra)
25799 +{
25800 + struct ieee80211_local *local = dev->priv;
25801 + struct ieee80211_sub_if_data *sdata;
25802 + int *i = (int *) extra;
25803 + int param = *i;
25804 + int value = *(i + 1);
25805 + int ret = 0;
25806 +
25807 + if (!capable(CAP_NET_ADMIN))
25808 + return -EPERM;
25809 +
25810 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25811 +
25812 + switch (param) {
25813 + case PRISM2_PARAM_HOST_ENCRYPT:
25814 + case PRISM2_PARAM_HOST_DECRYPT:
25815 + /* TODO: implement these; return success now to prevent
25816 + * hostapd from aborting */
25817 + break;
25818 +
25819 + case PRISM2_PARAM_BEACON_INT:
25820 + local->conf.beacon_int = value;
25821 + if (ieee80211_hw_config(dev))
25822 + ret = -EINVAL;
25823 + break;
25824 +
25825 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
25826 + local->bridge_packets = value;
25827 + break;
25828 +
25829 + case PRISM2_PARAM_AP_AUTH_ALGS:
25830 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25831 + sdata->u.sta.auth_algs = value;
25832 + } else
25833 + ret = -EOPNOTSUPP;
25834 + break;
25835 +
25836 + case PRISM2_PARAM_DTIM_PERIOD:
25837 + if (value < 1)
25838 + ret = -EINVAL;
25839 + else if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25840 + ret = -ENOENT;
25841 + else
25842 + sdata->u.ap.dtim_period = value;
25843 + break;
25844 +
25845 + case PRISM2_PARAM_IEEE_802_1X:
25846 + sdata->ieee802_1x = value;
25847 + if (local->hw->set_ieee8021x &&
25848 + local->hw->set_ieee8021x(dev, value))
25849 + printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
25850 + "for low-level driver\n", dev->name, value);
25851 + break;
25852 +
25853 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
25854 + local->cts_protect_erp_frames = value;
25855 + break;
25856 +
25857 + case PRISM2_PARAM_DROP_UNENCRYPTED:
25858 + sdata->drop_unencrypted = value;
25859 + break;
25860 +
25861 + case PRISM2_PARAM_PREAMBLE:
25862 + local->short_preamble = value;
25863 + break;
25864 +
25865 + case PRISM2_PARAM_RATE_LIMIT_BURST:
25866 + local->rate_limit_burst = value;
25867 + local->rate_limit_bucket = value;
25868 + break;
25869 +
25870 + case PRISM2_PARAM_RATE_LIMIT:
25871 + /* number of packets (tokens) allowed per second */
25872 + if (!local->rate_limit && value) {
25873 + if (!local->rate_limit_burst) local->rate_limit_burst =
25874 + value;
25875 + local->rate_limit_bucket = local->rate_limit_burst;
25876 + local->rate_limit_timer.expires = jiffies + HZ;
25877 + add_timer(&local->rate_limit_timer);
25878 + } else if (local->rate_limit && !value) {
25879 + del_timer_sync(&local->rate_limit_timer);
25880 + }
25881 + local->rate_limit = value;
25882 + break;
25883 +
25884 + case PRISM2_PARAM_STAT_TIME:
25885 + if (!local->stat_time && value) {
25886 + local->stat_timer.expires = jiffies + HZ * value / 100;
25887 + add_timer(&local->stat_timer);
25888 + } else if (local->stat_time && !value) {
25889 + del_timer_sync(&local->stat_timer);
25890 + }
25891 + local->stat_time = value;
25892 + break;
25893 + case PRISM2_PARAM_SHORT_SLOT_TIME:
25894 + local->conf.short_slot_time = value;
25895 + if (ieee80211_hw_config(dev))
25896 + ret = -EINVAL;
25897 + break;
25898 +
25899 + case PRISM2_PARAM_PRIVACY_INVOKED:
25900 + if (local->hw->set_privacy_invoked)
25901 + ret = local->hw->set_privacy_invoked(dev, value);
25902 + break;
25903 +
25904 + case PRISM2_PARAM_TEST_MODE:
25905 + ret = ieee80211_ioctl_test_mode(dev, value);
25906 + break;
25907 +
25908 + case PRISM2_PARAM_NEXT_MODE:
25909 + local->next_mode = value;
25910 + break;
25911 +
25912 + case PRISM2_PARAM_CLEAR_KEYS:
25913 + ret = ieee80211_ioctl_clear_keys(dev);
25914 + break;
25915 +
25916 + case PRISM2_PARAM_ADM_STATUS:
25917 + ret = ieee80211_ioctl_set_adm_status(dev, value);
25918 + break;
25919 +
25920 + case PRISM2_PARAM_ANTENNA_SEL:
25921 + local->conf.antenna_sel = value;
25922 + if (ieee80211_hw_config(dev))
25923 + ret = -EINVAL;
25924 + break;
25925 +
25926 + case PRISM2_PARAM_CALIB_INT:
25927 + local->conf.calib_int = value;
25928 + if (ieee80211_hw_config(dev))
25929 + ret = -EINVAL;
25930 + break;
25931 +
25932 + case PRISM2_PARAM_ANTENNA_MODE:
25933 + local->conf.antenna_mode = value;
25934 + if (ieee80211_hw_config(dev))
25935 + ret = -EINVAL;
25936 + break;
25937 +
25938 + case PRISM2_PARAM_BROADCAST_SSID:
25939 + if ((value < 0) || (value > 1))
25940 + ret = -EINVAL;
25941 + else
25942 + local->conf.ssid_hidden = value;
25943 + break;
25944 +
25945 + case PRISM2_PARAM_STA_ANTENNA_SEL:
25946 + local->sta_antenna_sel = value;
25947 + break;
25948 +
25949 + case PRISM2_PARAM_FORCE_UNICAST_RATE:
25950 + ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
25951 + break;
25952 +
25953 + case PRISM2_PARAM_MAX_RATECTRL_RATE:
25954 + ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
25955 + break;
25956 +
25957 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
25958 + local->rate_ctrl_num_up = value;
25959 + break;
25960 +
25961 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
25962 + local->rate_ctrl_num_down = value;
25963 + break;
25964 +
25965 + case PRISM2_PARAM_TX_POWER_REDUCTION:
25966 + if (value < 0)
25967 + ret = -EINVAL;
25968 + else
25969 + local->conf.tx_power_reduction = value;
25970 + break;
25971 +
25972 + case PRISM2_PARAM_EAPOL:
25973 + sdata->eapol = value;
25974 + break;
25975 +
25976 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
25977 + local->key_tx_rx_threshold = value;
25978 + break;
25979 +
25980 + case PRISM2_PARAM_KEY_INDEX:
25981 + if (value < 0 || value >= NUM_DEFAULT_KEYS)
25982 + ret = -EINVAL;
25983 + else if (sdata->keys[value] == NULL)
25984 + ret = -ENOENT;
25985 + else
25986 + sdata->default_key = sdata->keys[value];
25987 + break;
25988 +
25989 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
25990 + ret = ieee80211_ioctl_default_wep_only(local, value);
25991 + break;
25992 +
25993 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
25994 + local->wifi_wme_noack_test = value;
25995 + break;
25996 +
25997 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
25998 + local->allow_broadcast_always = value;
25999 + break;
26000 +
26001 + case PRISM2_PARAM_SCAN_FLAGS:
26002 + local->scan_flags = value;
26003 + break;
26004 +
26005 + case PRISM2_PARAM_MIXED_CELL:
26006 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26007 + ret = -EINVAL;
26008 + else
26009 + sdata->u.sta.mixed_cell = !!value;
26010 + break;
26011 +
26012 + case PRISM2_PARAM_KEY_MGMT:
26013 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26014 + ret = -EINVAL;
26015 + else
26016 + sdata->u.sta.key_mgmt = value;
26017 + break;
26018 +
26019 + case PRISM2_PARAM_HW_MODES:
26020 + local->hw_modes = value;
26021 + break;
26022 +
26023 + case PRISM2_PARAM_CREATE_IBSS:
26024 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26025 + ret = -EINVAL;
26026 + else
26027 + sdata->u.sta.create_ibss = !!value;
26028 + break;
26029 + case PRISM2_PARAM_WMM_ENABLED:
26030 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26031 + ret = -EINVAL;
26032 + else
26033 + sdata->u.sta.wmm_enabled = !!value;
26034 + break;
26035 + case PRISM2_PARAM_RADAR_DETECT:
26036 + local->conf.radar_detect = value;
26037 + break;
26038 + case PRISM2_PARAM_SPECTRUM_MGMT:
26039 + local->conf.spect_mgmt = value;
26040 + break;
26041 + default:
26042 + ret = -EOPNOTSUPP;
26043 + break;
26044 + }
26045 +
26046 + return ret;
26047 +}
26048 +
26049 +
26050 +static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
26051 + struct iw_request_info *info,
26052 + void *wrqu, char *extra)
26053 +{
26054 + struct ieee80211_local *local = dev->priv;
26055 + struct ieee80211_sub_if_data *sdata;
26056 + int *param = (int *) extra;
26057 + int ret = 0;
26058 +
26059 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26060 +
26061 + switch (*param) {
26062 + case PRISM2_PARAM_BEACON_INT:
26063 + *param = local->conf.beacon_int;
26064 + break;
26065 +
26066 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
26067 + *param = local->bridge_packets;
26068 + break;
26069 +
26070 + case PRISM2_PARAM_AP_AUTH_ALGS:
26071 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
26072 + *param = sdata->u.sta.auth_algs;
26073 + } else
26074 + ret = -EOPNOTSUPP;
26075 + break;
26076 +
26077 + case PRISM2_PARAM_DTIM_PERIOD:
26078 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
26079 + ret = -ENOENT;
26080 + else
26081 + *param = sdata->u.ap.dtim_period;
26082 + break;
26083 +
26084 + case PRISM2_PARAM_IEEE_802_1X:
26085 + *param = sdata->ieee802_1x;
26086 + break;
26087 +
26088 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
26089 + *param = local->cts_protect_erp_frames;
26090 + break;
26091 +
26092 + case PRISM2_PARAM_DROP_UNENCRYPTED:
26093 + *param = sdata->drop_unencrypted;
26094 + break;
26095 +
26096 + case PRISM2_PARAM_PREAMBLE:
26097 + *param = local->short_preamble;
26098 + break;
26099 +
26100 + case PRISM2_PARAM_RATE_LIMIT_BURST:
26101 + *param = local->rate_limit_burst;
26102 + break;
26103 +
26104 + case PRISM2_PARAM_RATE_LIMIT:
26105 + *param = local->rate_limit;
26106 + break;
26107 +
26108 + case PRISM2_PARAM_STAT_TIME:
26109 + *param = local->stat_time;
26110 + break;
26111 + case PRISM2_PARAM_SHORT_SLOT_TIME:
26112 + *param = local->conf.short_slot_time;
26113 + break;
26114 +
26115 + case PRISM2_PARAM_NEXT_MODE:
26116 + *param = local->next_mode;
26117 + break;
26118 +
26119 + case PRISM2_PARAM_ANTENNA_SEL:
26120 + *param = local->conf.antenna_sel;
26121 + break;
26122 +
26123 + case PRISM2_PARAM_CALIB_INT:
26124 + *param = local->conf.calib_int;
26125 + break;
26126 +
26127 + case PRISM2_PARAM_ANTENNA_MODE:
26128 + *param = local->conf.antenna_mode;
26129 + break;
26130 +
26131 + case PRISM2_PARAM_BROADCAST_SSID:
26132 + *param = local->conf.ssid_hidden;
26133 + break;
26134 +
26135 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26136 + *param = local->sta_antenna_sel;
26137 + break;
26138 +
26139 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26140 + *param = local->rate_ctrl_num_up;
26141 + break;
26142 +
26143 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26144 + *param = local->rate_ctrl_num_down;
26145 + break;
26146 +
26147 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26148 + *param = local->conf.tx_power_reduction;
26149 + break;
26150 +
26151 + case PRISM2_PARAM_EAPOL:
26152 + *param = sdata->eapol;
26153 + break;
26154 +
26155 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26156 + *param = local->key_tx_rx_threshold;
26157 + break;
26158 +
26159 + case PRISM2_PARAM_KEY_INDEX:
26160 + if (sdata->default_key == NULL)
26161 + ret = -ENOENT;
26162 + else if (sdata->default_key == sdata->keys[0])
26163 + *param = 0;
26164 + else if (sdata->default_key == sdata->keys[1])
26165 + *param = 1;
26166 + else if (sdata->default_key == sdata->keys[2])
26167 + *param = 2;
26168 + else if (sdata->default_key == sdata->keys[3])
26169 + *param = 3;
26170 + else
26171 + ret = -ENOENT;
26172 + break;
26173 +
26174 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26175 + *param = local->default_wep_only;
26176 + break;
26177 +
26178 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26179 + *param = local->wifi_wme_noack_test;
26180 + break;
26181 +
26182 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26183 + *param = local->allow_broadcast_always;
26184 + break;
26185 +
26186 + case PRISM2_PARAM_SCAN_FLAGS:
26187 + *param = local->scan_flags;
26188 + break;
26189 +
26190 + case PRISM2_PARAM_HW_MODES:
26191 + *param = local->hw_modes;
26192 + break;
26193 +
26194 + case PRISM2_PARAM_CREATE_IBSS:
26195 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26196 + ret = -EINVAL;
26197 + else
26198 + *param = !!sdata->u.sta.create_ibss;
26199 + break;
26200 +
26201 + case PRISM2_PARAM_MIXED_CELL:
26202 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26203 + ret = -EINVAL;
26204 + else
26205 + *param = !!sdata->u.sta.mixed_cell;
26206 + break;
26207 +
26208 + case PRISM2_PARAM_KEY_MGMT:
26209 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26210 + ret = -EINVAL;
26211 + else
26212 + *param = sdata->u.sta.key_mgmt;
26213 + break;
26214 + case PRISM2_PARAM_WMM_ENABLED:
26215 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26216 + ret = -EINVAL;
26217 + else
26218 + *param = !!sdata->u.sta.wmm_enabled;
26219 + break;
26220 +
26221 + default:
26222 + ret = -EOPNOTSUPP;
26223 + break;
26224 + }
26225 +
26226 + return ret;
26227 +}
26228 +
26229 +
26230 +static int ieee80211_ioctl_test_param(struct net_device *dev,
26231 + struct iw_request_info *info,
26232 + void *wrqu, char *extra)
26233 +{
26234 + struct ieee80211_local *local = dev->priv;
26235 + int *i = (int *) extra;
26236 + int param = *i;
26237 + int value = *(i + 1);
26238 +
26239 + if (!capable(CAP_NET_ADMIN))
26240 + return -EPERM;
26241 +
26242 + if (local->hw->test_param)
26243 + return local->hw->test_param(local->mdev, param, value);
26244 +
26245 + return -EOPNOTSUPP;
26246 +}
26247 +
26248 +
26249 +static int ieee80211_ioctl_siwmlme(struct net_device *dev,
26250 + struct iw_request_info *info,
26251 + struct iw_point *data, char *extra)
26252 +{
26253 + struct ieee80211_sub_if_data *sdata;
26254 + struct iw_mlme *mlme = (struct iw_mlme *) extra;
26255 +
26256 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26257 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26258 + return -EINVAL;
26259 +
26260 + switch (mlme->cmd) {
26261 + case IW_MLME_DEAUTH:
26262 + /* TODO: mlme->addr.sa_data */
26263 + return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
26264 + case IW_MLME_DISASSOC:
26265 + /* TODO: mlme->addr.sa_data */
26266 + return ieee80211_sta_disassociate(dev, mlme->reason_code);
26267 + default:
26268 + return -EOPNOTSUPP;
26269 + }
26270 +}
26271 +
26272 +
26273 +static int ieee80211_ioctl_siwencode(struct net_device *dev,
26274 + struct iw_request_info *info,
26275 + struct iw_point *erq, char *keybuf)
26276 +{
26277 + struct ieee80211_sub_if_data *sdata;
26278 + int idx, i, alg = ALG_WEP;
26279 + u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
26280 +
26281 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26282 +
26283 + idx = erq->flags & IW_ENCODE_INDEX;
26284 + if (idx < 1 || idx > 4) {
26285 + idx = -1;
26286 + if (sdata->default_key == NULL)
26287 + idx = 0;
26288 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26289 + if (sdata->default_key == sdata->keys[i])
26290 + idx = i;
26291 + break;
26292 + }
26293 + if (idx < 0)
26294 + return -EINVAL;
26295 + } else
26296 + idx--;
26297 +
26298 + if (erq->flags & IW_ENCODE_DISABLED)
26299 + alg = ALG_NONE;
26300 + else if (erq->length == 0) {
26301 + /* No key data - just set the default TX key index */
26302 + sdata->default_key = sdata->keys[idx];
26303 + }
26304 +
26305 + return ieee80211_set_encryption(
26306 + dev, bcaddr,
26307 + idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
26308 + sdata->default_key == NULL,
26309 + NULL, keybuf, erq->length);
26310 +
26311 + return 0;
26312 +}
26313 +
26314 +
26315 +static int ieee80211_ioctl_giwencode(struct net_device *dev,
26316 + struct iw_request_info *info,
26317 + struct iw_point *erq, char *key)
26318 +{
26319 + struct ieee80211_sub_if_data *sdata;
26320 + int idx, i;
26321 +
26322 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26323 +
26324 + idx = erq->flags & IW_ENCODE_INDEX;
26325 + if (idx < 1 || idx > 4) {
26326 + idx = -1;
26327 + if (sdata->default_key == NULL)
26328 + idx = 0;
26329 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26330 + if (sdata->default_key == sdata->keys[i])
26331 + idx = i;
26332 + break;
26333 + }
26334 + if (idx < 0)
26335 + return -EINVAL;
26336 + } else
26337 + idx--;
26338 +
26339 + erq->flags = idx + 1;
26340 +
26341 + if (sdata->keys[idx] == NULL) {
26342 + erq->length = 0;
26343 + erq->flags |= IW_ENCODE_DISABLED;
26344 + return 0;
26345 + }
26346 +
26347 + erq->length = 0;
26348 + erq->flags |= IW_ENCODE_ENABLED;
26349 +
26350 + return 0;
26351 +}
26352 +
26353 +
26354 +static int ieee80211_ioctl_siwgenie(struct net_device *dev,
26355 + struct iw_request_info *info,
26356 + struct iw_point *data, char *extra)
26357 +{
26358 + return ieee80211_set_gen_ie(dev, extra, data->length);
26359 +}
26360 +
26361 +
26362 +static int ieee80211_ioctl_siwauth(struct net_device *dev,
26363 + struct iw_request_info *info,
26364 + struct iw_param *data, char *extra)
26365 +{
26366 + struct ieee80211_local *local = dev->priv;
26367 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26368 + int ret = 0;
26369 +
26370 + switch (data->flags & IW_AUTH_INDEX) {
26371 + case IW_AUTH_WPA_VERSION:
26372 + case IW_AUTH_CIPHER_PAIRWISE:
26373 + case IW_AUTH_CIPHER_GROUP:
26374 + case IW_AUTH_WPA_ENABLED:
26375 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
26376 + break;
26377 + case IW_AUTH_KEY_MGMT:
26378 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26379 + ret = -EINVAL;
26380 + else {
26381 + /*
26382 + * TODO: sdata->u.sta.key_mgmt does not match with WE18
26383 + * value completely; could consider modifying this to
26384 + * be closer to WE18. For now, this value is not really
26385 + * used for anything else than Privacy matching, so the
26386 + * current code here should be more or less OK.
26387 + */
26388 + if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
26389 + sdata->u.sta.key_mgmt =
26390 + IEEE80211_KEY_MGMT_WPA_EAP;
26391 + } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
26392 + sdata->u.sta.key_mgmt =
26393 + IEEE80211_KEY_MGMT_WPA_PSK;
26394 + } else {
26395 + sdata->u.sta.key_mgmt =
26396 + IEEE80211_KEY_MGMT_NONE;
26397 + }
26398 + }
26399 + break;
26400 + case IW_AUTH_80211_AUTH_ALG:
26401 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26402 + sdata->u.sta.auth_algs = data->value;
26403 + else
26404 + ret = -EOPNOTSUPP;
26405 + break;
26406 + case IW_AUTH_PRIVACY_INVOKED:
26407 + if (local->hw->set_privacy_invoked)
26408 + ret = local->hw->set_privacy_invoked(dev, data->value);
26409 + break;
26410 + default:
26411 + ret = -EOPNOTSUPP;
26412 + break;
26413 + }
26414 + return ret;
26415 +}
26416 +
26417 +
26418 +static int ieee80211_ioctl_giwauth(struct net_device *dev,
26419 + struct iw_request_info *info,
26420 + struct iw_param *data, char *extra)
26421 +{
26422 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26423 + int ret = 0;
26424 +
26425 + switch (data->flags & IW_AUTH_INDEX) {
26426 + case IW_AUTH_80211_AUTH_ALG:
26427 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26428 + data->value = sdata->u.sta.auth_algs;
26429 + else
26430 + ret = -EOPNOTSUPP;
26431 + break;
26432 + default:
26433 + ret = -EOPNOTSUPP;
26434 + break;
26435 + }
26436 + return ret;
26437 +}
26438 +
26439 +
26440 +static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
26441 + struct iw_request_info *info,
26442 + struct iw_point *erq, char *extra)
26443 +{
26444 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26445 + struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
26446 + int alg, idx, i;
26447 +
26448 + switch (ext->alg) {
26449 + case IW_ENCODE_ALG_NONE:
26450 + alg = ALG_NONE;
26451 + break;
26452 + case IW_ENCODE_ALG_WEP:
26453 + alg = ALG_WEP;
26454 + break;
26455 + case IW_ENCODE_ALG_TKIP:
26456 + alg = ALG_TKIP;
26457 + break;
26458 + case IW_ENCODE_ALG_CCMP:
26459 + alg = ALG_CCMP;
26460 + break;
26461 + default:
26462 + return -EOPNOTSUPP;
26463 + }
26464 +
26465 + if (erq->flags & IW_ENCODE_DISABLED)
26466 + alg = ALG_NONE;
26467 +
26468 + idx = erq->flags & IW_ENCODE_INDEX;
26469 + if (idx < 1 || idx > 4) {
26470 + idx = -1;
26471 + if (sdata->default_key == NULL)
26472 + idx = 0;
26473 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26474 + if (sdata->default_key == sdata->keys[i])
26475 + idx = i;
26476 + break;
26477 + }
26478 + if (idx < 0)
26479 + return -EINVAL;
26480 + } else
26481 + idx--;
26482 +
26483 + return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
26484 + ext->ext_flags &
26485 + IW_ENCODE_EXT_SET_TX_KEY,
26486 + NULL, ext->key, ext->key_len);
26487 +}
26488 +
26489 +
26490 +static const struct iw_priv_args ieee80211_ioctl_priv[] = {
26491 + { PRISM2_IOCTL_PRISM2_PARAM,
26492 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
26493 + { PRISM2_IOCTL_GET_PRISM2_PARAM,
26494 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
26495 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
26496 + { PRISM2_IOCTL_TEST_PARAM,
26497 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "test_param" },
26498 +};
26499 +
26500 +
26501 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
26502 +{
26503 + struct iwreq *wrq = (struct iwreq *) rq;
26504 + int ret = 0;
26505 +
26506 + switch (cmd) {
26507 + /* Private ioctls (iwpriv) that have not yet been converted
26508 + * into new wireless extensions API */
26509 + case PRISM2_IOCTL_TEST_PARAM:
26510 + ret = ieee80211_ioctl_test_param(dev, NULL, &wrq->u,
26511 + (char *) &wrq->u);
26512 + break;
26513 + case PRISM2_IOCTL_HOSTAPD:
26514 + if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
26515 + else ret = ieee80211_ioctl_priv_hostapd(dev, &wrq->u.data);
26516 + break;
26517 + default:
26518 + ret = -EOPNOTSUPP;
26519 + break;
26520 + }
26521 +
26522 + return ret;
26523 +}
26524 +
26525 +
26526 +/* Structures to export the Wireless Handlers */
26527 +
26528 +static const iw_handler ieee80211_handler[] =
26529 +{
26530 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
26531 + (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
26532 + (iw_handler) NULL, /* SIOCSIWNWID */
26533 + (iw_handler) NULL, /* SIOCGIWNWID */
26534 + (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
26535 + (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
26536 + (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
26537 + (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
26538 + (iw_handler) NULL, /* SIOCSIWSENS */
26539 + (iw_handler) NULL, /* SIOCGIWSENS */
26540 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
26541 + (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
26542 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
26543 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
26544 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
26545 + (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
26546 + iw_handler_set_spy, /* SIOCSIWSPY */
26547 + iw_handler_get_spy, /* SIOCGIWSPY */
26548 + iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
26549 + iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
26550 + (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
26551 + (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
26552 + (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
26553 + (iw_handler) NULL, /* SIOCGIWAPLIST */
26554 + (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
26555 + (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
26556 + (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
26557 + (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
26558 + (iw_handler) NULL, /* SIOCSIWNICKN */
26559 + (iw_handler) NULL, /* SIOCGIWNICKN */
26560 + (iw_handler) NULL, /* -- hole -- */
26561 + (iw_handler) NULL, /* -- hole -- */
26562 + (iw_handler) NULL, /* SIOCSIWRATE */
26563 + (iw_handler) NULL, /* SIOCGIWRATE */
26564 + (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
26565 + (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
26566 + (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
26567 + (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
26568 + (iw_handler) NULL, /* SIOCSIWTXPOW */
26569 + (iw_handler) NULL, /* SIOCGIWTXPOW */
26570 + (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
26571 + (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
26572 + (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
26573 + (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
26574 + (iw_handler) NULL, /* SIOCSIWPOWER */
26575 + (iw_handler) NULL, /* SIOCGIWPOWER */
26576 + (iw_handler) NULL, /* -- hole -- */
26577 + (iw_handler) NULL, /* -- hole -- */
26578 + (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
26579 + (iw_handler) NULL, /* SIOCGIWGENIE */
26580 + (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
26581 + (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
26582 + (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
26583 + (iw_handler) NULL, /* SIOCGIWENCODEEXT */
26584 + (iw_handler) NULL, /* SIOCSIWPMKSA */
26585 + (iw_handler) NULL, /* -- hole -- */
26586 +};
26587 +
26588 +static const iw_handler ieee80211_private_handler[] =
26589 +{ /* SIOCIWFIRSTPRIV + */
26590 + (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
26591 + (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
26592 +};
26593 +
26594 +const struct iw_handler_def ieee80211_iw_handler_def =
26595 +{
26596 + .num_standard = sizeof(ieee80211_handler) / sizeof(iw_handler),
26597 + .num_private = sizeof(ieee80211_private_handler) /
26598 + sizeof(iw_handler),
26599 + .num_private_args = sizeof(ieee80211_ioctl_priv) /
26600 + sizeof(struct iw_priv_args),
26601 + .standard = (iw_handler *) ieee80211_handler,
26602 + .private = (iw_handler *) ieee80211_private_handler,
26603 + .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
26604 +};
26605 diff -Nur linux-2.6.16/net/d80211/ieee80211_key.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_key.h
26606 --- linux-2.6.16/net/d80211/ieee80211_key.h 1970-01-01 01:00:00.000000000 +0100
26607 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_key.h 2006-03-28 22:16:14.000000000 +0200
26608 @@ -0,0 +1,83 @@
26609 +/*
26610 + * Copyright 2002-2004, Instant802 Networks, Inc.
26611 + * Copyright 2005, Devicescape Software, Inc.
26612 + *
26613 + * This program is free software; you can redistribute it and/or modify
26614 + * it under the terms of the GNU General Public License version 2 as
26615 + * published by the Free Software Foundation.
26616 + */
26617 +
26618 +#ifndef IEEE80211_KEY_H
26619 +#define IEEE80211_KEY_H
26620 +
26621 +#include <linux/types.h>
26622 +#include <net/d80211.h>
26623 +
26624 +/* ALG_TKIP
26625 + * struct ieee80211_key::key is encoded as a 256-bit (32 byte) data block:
26626 + * Temporal Encryption Key (128 bits)
26627 + * Temporal Authenticator Tx MIC Key (64 bits)
26628 + * Temporal Authenticator Rx MIC Key (64 bits)
26629 + */
26630 +
26631 +#define WEP_IV_LEN 4
26632 +#define WEP_ICV_LEN 4
26633 +
26634 +#define ALG_TKIP_KEY_LEN 32
26635 +/* Starting offsets for each key */
26636 +#define ALG_TKIP_TEMP_ENCR_KEY 0
26637 +#define ALG_TKIP_TEMP_AUTH_TX_MIC_KEY 16
26638 +#define ALG_TKIP_TEMP_AUTH_RX_MIC_KEY 24
26639 +#define TKIP_IV_LEN 8
26640 +#define TKIP_ICV_LEN 4
26641 +
26642 +#define ALG_CCMP_KEY_LEN 16
26643 +#define CCMP_HDR_LEN 8
26644 +#define CCMP_MIC_LEN 8
26645 +#define CCMP_TK_LEN 16
26646 +#define CCMP_PN_LEN 6
26647 +
26648 +#define NUM_RX_DATA_QUEUES 17
26649 +
26650 +struct ieee80211_key {
26651 + int hw_key_idx; /* filled and used by low-level driver */
26652 + ieee80211_key_alg alg;
26653 + union {
26654 + struct {
26655 + /* last used TSC */
26656 + u32 iv32;
26657 + u16 iv16;
26658 + u16 p1k[5];
26659 + int tx_initialized;
26660 +
26661 + /* last received RSC */
26662 + u32 iv32_rx[NUM_RX_DATA_QUEUES];
26663 + u16 iv16_rx[NUM_RX_DATA_QUEUES];
26664 + u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
26665 + int rx_initialized[NUM_RX_DATA_QUEUES];
26666 + } tkip;
26667 + struct {
26668 + u8 tx_pn[6];
26669 + /* TODO: for WME make this replay counter per AC */
26670 + u8 rx_pn[NUM_RX_DATA_QUEUES][6];
26671 +#ifndef AES_STATE_LEN
26672 +#define AES_STATE_LEN 44
26673 +#endif
26674 + u32 aes_state[AES_STATE_LEN];
26675 + u32 replays; /* dot11RSNAStatsCCMPReplays */
26676 + } ccmp;
26677 + } u;
26678 + int tx_rx_count; /* number of times this key has been used */
26679 + int keylen;
26680 +
26681 + /* if the low level driver can provide hardware acceleration it should
26682 + * clear this flag */
26683 + int force_sw_encrypt:1;
26684 + int keyidx:8; /* WEP key index */
26685 + int default_tx_key:1; /* This key is the new default TX key
26686 + * (used only for broadcast keys). */
26687 +
26688 + u8 key[0];
26689 +};
26690 +
26691 +#endif /* IEEE80211_KEY_H */
26692 diff -Nur linux-2.6.16/net/d80211/ieee80211_led.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_led.c
26693 --- linux-2.6.16/net/d80211/ieee80211_led.c 1970-01-01 01:00:00.000000000 +0100
26694 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_led.c 2006-03-28 22:16:14.000000000 +0200
26695 @@ -0,0 +1,32 @@
26696 +/*
26697 + * Copyright 2002-2004, Instant802 Networks, Inc.
26698 + *
26699 + * This program is free software; you can redistribute it and/or modify
26700 + * it under the terms of the GNU General Public License version 2 as
26701 + * published by the Free Software Foundation.
26702 + */
26703 +
26704 +#include <linux/config.h>
26705 +#include <linux/netdevice.h>
26706 +#include <linux/types.h>
26707 +
26708 +#ifdef CONFIG_OAP_LEDS_WLAN
26709 +extern void leds_wlan_set(int unit, int tx, int state);
26710 +#endif
26711 +
26712 +void ieee80211_rx_led(int state, struct net_device *dev) {
26713 +#ifdef CONFIG_OAP_LEDS_WLAN
26714 + static unsigned int count = 0;
26715 +
26716 + if (state == 2) {
26717 + leds_wlan_set(0, 0, (++count) & 1);
26718 + }
26719 +#endif
26720 +}
26721 +
26722 +void ieee80211_tx_led(int state, struct net_device *dev) {
26723 +#ifdef CONFIG_OAP_LEDS_WLAN
26724 + leds_wlan_set(0, 1, state);
26725 +#endif
26726 +}
26727 +
26728 diff -Nur linux-2.6.16/net/d80211/ieee80211_proc.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.c
26729 --- linux-2.6.16/net/d80211/ieee80211_proc.c 1970-01-01 01:00:00.000000000 +0100
26730 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.c 2006-03-28 22:16:14.000000000 +0200
26731 @@ -0,0 +1,777 @@
26732 +/*
26733 + * Copyright 2003-2005, Devicescape Software, Inc.
26734 + *
26735 + * This program is free software; you can redistribute it and/or modify
26736 + * it under the terms of the GNU General Public License version 2 as
26737 + * published by the Free Software Foundation.
26738 + */
26739 +
26740 +#include <linux/config.h>
26741 +#include <linux/version.h>
26742 +#include <linux/module.h>
26743 +#include <linux/netdevice.h>
26744 +#include <linux/proc_fs.h>
26745 +#include <linux/delay.h>
26746 +
26747 +#ifdef CONFIG_PROC_FS
26748 +
26749 +#include <net/d80211.h>
26750 +#include <net/d80211_common.h>
26751 +#include <net/d80211_mgmt.h>
26752 +#include "ieee80211_i.h"
26753 +#include "sta_info.h"
26754 +#include "ieee80211_proc.h"
26755 +#include "rate_control.h"
26756 +
26757 +
26758 +static struct proc_dir_entry *ieee80211_proc;
26759 +
26760 +#define PROC_LIMIT (PAGE_SIZE - 80)
26761 +
26762 +
26763 +static char * ieee80211_proc_key(char *p, struct ieee80211_key *key,
26764 + int idx, int def_key)
26765 +{
26766 + int i;
26767 + u8 *tpn, *rpn;
26768 +
26769 + if (!key)
26770 + return p;
26771 +
26772 + p += sprintf(p, "key[%d]%s len=%d sw_encrypt=%d idx=%d hwidx=%d "
26773 + "tx_rx_count=%d",
26774 + idx, def_key ? "*" : "", key->keylen,
26775 + key->force_sw_encrypt, key->keyidx, key->hw_key_idx,
26776 + key->tx_rx_count);
26777 + switch (key->alg) {
26778 + case ALG_WEP:
26779 + p += sprintf(p, " alg=WEP");
26780 + break;
26781 + case ALG_TKIP:
26782 + p += sprintf(p, " alg=TKIP iv(tx)=%08x %04x",
26783 + key->u.tkip.iv32, key->u.tkip.iv16);
26784 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
26785 + if (key->u.tkip.iv32_rx[i] == 0 &&
26786 + key->u.tkip.iv16_rx[i] == 0)
26787 + continue;
26788 + p += sprintf(p, " iv(rx %d)=%08x %04x", i,
26789 + key->u.tkip.iv32_rx[i],
26790 + key->u.tkip.iv16_rx[i]);
26791 + }
26792 + break;
26793 + case ALG_CCMP:
26794 + tpn = key->u.ccmp.tx_pn;
26795 + p += sprintf(p, " alg=CCMP PN(tx)=%02x%02x%02x%02x%02x%02x",
26796 + tpn[0], tpn[1], tpn[2], tpn[3], tpn[4], tpn[5]);
26797 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
26798 + rpn = key->u.ccmp.rx_pn[i];
26799 + if (memcmp(rpn, "\x00\x00\x00\x00\x00\x00", 6) == 0)
26800 + continue;
26801 + p += sprintf(p, " PN(rx %d)=%02x%02x%02x%02x%02x%02x",
26802 + i, rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
26803 + rpn[5]);
26804 + }
26805 + p += sprintf(p, " replays=%u", key->u.ccmp.replays);
26806 + break;
26807 + default:
26808 + break;
26809 + }
26810 +
26811 + p += sprintf(p, " key=");
26812 + for (i = 0; i < key->keylen; i++)
26813 + p += sprintf(p, "%02x", key->key[i]);
26814 + p += sprintf(p, "\n");
26815 + return p;
26816 +}
26817 +
26818 +
26819 +static char * ieee80211_proc_sub_if_ap(char *p,
26820 + struct ieee80211_if_ap *ap)
26821 +{
26822 + p += sprintf(p, "type=ap\n");
26823 + if (ap->beacon_head)
26824 + p += sprintf(p, "beacon_head_len=%d\n", ap->beacon_head_len);
26825 + if (ap->beacon_tail)
26826 + p += sprintf(p, "beacon_tail_len=%d\n", ap->beacon_tail_len);
26827 + p += sprintf(p,
26828 + "max_aid=%d\n"
26829 + "num_sta_ps=%d\n"
26830 + "num_buffered_multicast=%u\n"
26831 + "dtim_period=%d\n"
26832 + "dtim_count=%d\n"
26833 + "num_beacons=%d\n"
26834 + "force_unicast_rateidx=%d\n"
26835 + "max_ratectrl_rateidx=%d\n",
26836 + ap->max_aid, atomic_read(&ap->num_sta_ps),
26837 + skb_queue_len(&ap->ps_bc_buf),
26838 + ap->dtim_period, ap->dtim_count, ap->num_beacons,
26839 + ap->force_unicast_rateidx, ap->max_ratectrl_rateidx);
26840 + return p;
26841 +}
26842 +
26843 +
26844 +static char * ieee80211_proc_sub_if_sta(char *p,
26845 + struct ieee80211_if_sta *ifsta)
26846 +{
26847 + p += sprintf(p, "type=sta\n");
26848 + p += sprintf(p,
26849 + "state=%d\n"
26850 + "bssid=" MACSTR "\n"
26851 + "prev_bssid=" MACSTR "\n"
26852 + "ssid_len=%zd\n"
26853 + "aid=%d\n"
26854 + "ap_capab=0x%x\n"
26855 + "capab=0x%x\n"
26856 + "extra_ie_len=%zd\n"
26857 + "auth_tries=%d\n"
26858 + "assoc_tries=%d\n"
26859 + "flags=%s%s%s%s%s%s%s\n"
26860 + "auth_algs=0x%x\n"
26861 + "auth_alg=%d\n"
26862 + "auth_transaction=%d\n",
26863 + ifsta->state,
26864 + MAC2STR(ifsta->bssid),
26865 + MAC2STR(ifsta->prev_bssid),
26866 + ifsta->ssid_len,
26867 + ifsta->aid,
26868 + ifsta->ap_capab,
26869 + ifsta->capab,
26870 + ifsta->extra_ie_len,
26871 + ifsta->auth_tries,
26872 + ifsta->assoc_tries,
26873 + ifsta->ssid_set ? "[SSID]" : "",
26874 + ifsta->bssid_set ? "[BSSID]" : "",
26875 + ifsta->prev_bssid_set ? "[prev BSSID" : "",
26876 + ifsta->authenticated ? "[AUTH]" : "",
26877 + ifsta->associated ? "[ASSOC]" : "",
26878 + ifsta->probereq_poll ? "[PROBEREQ POLL]" : "",
26879 + ifsta->use_protection ? "[CTS prot]" : "",
26880 + ifsta->auth_algs,
26881 + ifsta->auth_alg,
26882 + ifsta->auth_transaction);
26883 + return p;
26884 +}
26885 +
26886 +
26887 +static char * ieee80211_proc_sub_if(char *p,
26888 + struct ieee80211_sub_if_data *sdata)
26889 +{
26890 + if (sdata == NULL)
26891 + return p;
26892 +
26893 + if (sdata->bss)
26894 + p += sprintf(p, "bss=%p\n", sdata->bss);
26895 +
26896 + switch (sdata->type) {
26897 + case IEEE80211_SUB_IF_TYPE_AP:
26898 + p = ieee80211_proc_sub_if_ap(p, &sdata->u.ap);
26899 + break;
26900 + case IEEE80211_SUB_IF_TYPE_WDS:
26901 + p += sprintf(p, "type=wds\n");
26902 + p += sprintf(p, "wds.peer=" MACSTR "\n",
26903 + MAC2STR(sdata->u.wds.remote_addr));
26904 + break;
26905 + case IEEE80211_SUB_IF_TYPE_VLAN:
26906 + p += sprintf(p, "type=vlan\n");
26907 + p += sprintf(p, "vlan.id=%d\n", sdata->u.vlan.id);
26908 + break;
26909 + case IEEE80211_SUB_IF_TYPE_STA:
26910 + p = ieee80211_proc_sub_if_sta(p, &sdata->u.sta);
26911 + break;
26912 + }
26913 + p += sprintf(p, "channel_use=%d\n", sdata->channel_use);
26914 + p += sprintf(p, "drop_unencrypted=%d\n", sdata->drop_unencrypted);
26915 + p += sprintf(p, "eapol=%d\n", sdata->eapol);
26916 + p += sprintf(p, "ieee802_1x=%d\n", sdata->ieee802_1x);
26917 +
26918 + return p;
26919 +}
26920 +
26921 +
26922 +static int ieee80211_proc_iface_read(char *page, char **start, off_t off,
26923 + int count, int *eof, void *data)
26924 +{
26925 + char *p = page;
26926 + struct net_device *dev = (struct net_device *) data;
26927 + struct ieee80211_sub_if_data *sdata;
26928 + int i;
26929 +
26930 + if (off != 0) {
26931 + *eof = 1;
26932 + return 0;
26933 + }
26934 +
26935 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26936 + if (!sdata)
26937 + return -1;
26938 +
26939 + p = ieee80211_proc_sub_if(p, sdata);
26940 +
26941 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26942 + if (sdata->keys[i] == NULL)
26943 + continue;
26944 +
26945 + p = ieee80211_proc_key(p, sdata->keys[i], i,
26946 + sdata->keys[i] == sdata->default_key);
26947 + }
26948 +
26949 + return (p - page);
26950 +}
26951 +
26952 +
26953 +static int ieee80211_proc_sta_read(char *page, char **start, off_t off,
26954 + int count, int *eof, void *data)
26955 +{
26956 + char *p = page;
26957 + struct sta_info *sta = (struct sta_info *) data;
26958 + struct ieee80211_local *local;
26959 + int inactive, i;
26960 +
26961 + if (off != 0) {
26962 + *eof = 1;
26963 + return 0;
26964 + }
26965 +
26966 + if (!sta || !sta->dev)
26967 + return -1;
26968 +
26969 + p += sprintf(p, "users=%d\n", atomic_read(&sta->users));
26970 + p += sprintf(p, "aid=%d\n", sta->aid);
26971 + p += sprintf(p, "flags=0x%x %s%s%s%s%s%s%s%s%s%s\n", sta->flags,
26972 + sta->flags & WLAN_STA_AUTH ? "[AUTH]" : "",
26973 + sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : "",
26974 + sta->flags & WLAN_STA_PS ? "[PS]" : "",
26975 + sta->flags & WLAN_STA_TIM ? "[TIM]" : "",
26976 + sta->flags & WLAN_STA_PERM ? "[PERM]" : "",
26977 + sta->flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : "",
26978 + sta->flags & WLAN_STA_SHORT_PREAMBLE ?
26979 + "[SHORT PREAMBLE]" : "",
26980 + sta->flags & WLAN_STA_WME ? "[WME]" : "",
26981 + sta->flags & WLAN_STA_WDS ? "[WDS]" : "",
26982 + sta->flags & WLAN_STA_XR ? "[XR]" : "");
26983 + p += sprintf(p, "key_idx_compression=%d\n",
26984 + sta->key_idx_compression);
26985 + p += sprintf(p, "dev=%s\n", sta->dev->name);
26986 + if (sta->vlan_id > 0)
26987 + p += sprintf(p, "vlan_id=%d\n", sta->vlan_id);
26988 + p += sprintf(p, "rx_packets=%lu\ntx_packets=%lu\nrx_bytes=%lu\n"
26989 + "tx_bytes=%lu\nrx_duplicates=%lu\nrx_fragments=%lu\n"
26990 + "rx_dropped=%lu\ntx_fragments=%lu\ntx_filtered=%lu\n",
26991 + sta->rx_packets, sta->tx_packets,
26992 + sta->rx_bytes, sta->tx_bytes,
26993 + sta->num_duplicates, sta->rx_fragments, sta->rx_dropped,
26994 + sta->tx_fragments, sta->tx_filtered_count);
26995 + p = ieee80211_proc_key(p, sta->key, 0, 1);
26996 +
26997 + local = (struct ieee80211_local *) sta->dev->priv;
26998 + if (sta->txrate >= 0 && sta->txrate < local->num_curr_rates) {
26999 + p += sprintf(p, "txrate=%d\n",
27000 + local->curr_rates[sta->txrate].rate);
27001 + }
27002 + if (sta->last_txrate >= 0 &&
27003 + sta->last_txrate < local->num_curr_rates) {
27004 + p += sprintf(p, "last_txrate=%d\n",
27005 + local->curr_rates[sta->last_txrate].rate);
27006 + }
27007 + p += sprintf(p, "num_ps_buf_frames=%u\n",
27008 + skb_queue_len(&sta->ps_tx_buf));
27009 + p += sprintf(p, "tx_retry_failed=%lu\n", sta->tx_retry_failed);
27010 + p += sprintf(p, "tx_retry_count=%lu\n", sta->tx_retry_count);
27011 + p += sprintf(p, "last_rssi=%d\n", sta->last_rssi);
27012 + p += sprintf(p, "last_ack_rssi=%d %d %d\n",
27013 + sta->last_ack_rssi[0], sta->last_ack_rssi[1],
27014 + sta->last_ack_rssi[2]);
27015 + if (sta->last_ack)
27016 + p += sprintf(p, "last_ack_ms=%d\n",
27017 + jiffies_to_msecs(jiffies - sta->last_ack));
27018 + inactive = jiffies - sta->last_rx;
27019 + p += sprintf(p, "inactive_msec=%d\n", jiffies_to_msecs(inactive));
27020 + p += sprintf(p, "channel_use=%d\n", sta->channel_use);
27021 + p += sprintf(p, "wep_weak_iv_count=%d\n", sta->wep_weak_iv_count);
27022 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
27023 + p += sprintf(p, "wme_rx_queue=");
27024 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27025 + p += sprintf(p, "%u ", sta->wme_rx_queue[i]);
27026 + p += sprintf(p, "\n");
27027 +
27028 + p += sprintf(p, "wme_tx_queue=");
27029 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27030 + p += sprintf(p, "%u ", sta->wme_tx_queue[i]);
27031 + p += sprintf(p, "\n");
27032 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27033 + p += sprintf(p, "last_seq_ctrl=");
27034 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
27035 + p += sprintf(p, "%x ", sta->last_seq_ctrl[i]);
27036 + }
27037 + p += sprintf(p, "\n");
27038 +
27039 + p += rate_control_status_sta(local, sta, p);
27040 +
27041 + return (p - page);
27042 +}
27043 +
27044 +
27045 +static int ieee80211_proc_counters_read(char *page, char **start, off_t off,
27046 + int count, int *eof, void *data)
27047 +{
27048 + char *p = page;
27049 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27050 + struct ieee80211_low_level_stats stats;
27051 +
27052 + if (off != 0) {
27053 + *eof = 1;
27054 + return 0;
27055 + }
27056 +
27057 + p += sprintf(p,
27058 + "TransmittedFragmentCount=%u\n"
27059 + "MulticastTransmittedFrameCount=%u\n"
27060 + "FailedCount=%u\n"
27061 + "RetryCount=%u\n"
27062 + "MultipleRetryCount=%d\n"
27063 + "FrameDuplicateCount=%d\n"
27064 + "ReceivedFragmentCount=%u\n"
27065 + "MulticastReceivedFrameCount=%u\n"
27066 + "TransmittedFrameCount=%u\n"
27067 + "WEPUndecryptableCount=%u\n",
27068 + local->dot11TransmittedFragmentCount,
27069 + local->dot11MulticastTransmittedFrameCount,
27070 + local->dot11FailedCount,
27071 + local->dot11RetryCount,
27072 + local->dot11MultipleRetryCount,
27073 + local->dot11FrameDuplicateCount,
27074 + local->dot11ReceivedFragmentCount,
27075 + local->dot11MulticastReceivedFrameCount,
27076 + local->dot11TransmittedFrameCount,
27077 + local->dot11WEPUndecryptableCount);
27078 +
27079 + memset(&stats, 0, sizeof(stats));
27080 + if (local->hw->get_stats &&
27081 + local->hw->get_stats(local->mdev, &stats) == 0) {
27082 + p += sprintf(p,
27083 + "ACKFailureCount=%u\n"
27084 + "RTSFailureCount=%u\n"
27085 + "FCSErrorCount=%u\n"
27086 + "RTSSuccessCount=%u\n",
27087 + stats.dot11ACKFailureCount,
27088 + stats.dot11RTSFailureCount,
27089 + stats.dot11FCSErrorCount,
27090 + stats.dot11RTSSuccessCount);
27091 + }
27092 +
27093 + return (p - page);
27094 +}
27095 +
27096 +
27097 +static int ieee80211_proc_debug_read(char *page, char **start, off_t off,
27098 + int count, int *eof, void *data)
27099 +{
27100 + char *p = page;
27101 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27102 + int i;
27103 +
27104 + if (off != 0) {
27105 + *eof = 1;
27106 + return 0;
27107 + }
27108 +
27109 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
27110 + p += sprintf(p,
27111 + "tx_handlers_drop=%u\n"
27112 + "tx_handlers_queued=%u\n"
27113 + "tx_handlers_drop_unencrypted=%u\n"
27114 + "tx_handlers_drop_fragment=%u\n"
27115 + "tx_handlers_drop_wep=%u\n"
27116 + "tx_handlers_drop_rate_limit=%u\n"
27117 + "tx_handlers_drop_not_assoc=%u\n"
27118 + "tx_handlers_drop_unauth_port=%u\n"
27119 + "rx_handlers_drop=%u\n"
27120 + "rx_handlers_queued=%u\n"
27121 + "rx_handlers_drop_nullfunc=%u\n"
27122 + "rx_handlers_drop_defrag=%u\n"
27123 + "rx_handlers_drop_short=%u\n"
27124 + "rx_handlers_drop_passive_scan=%u\n"
27125 + "tx_expand_skb_head=%u\n"
27126 + "tx_expand_skb_head_cloned=%u\n"
27127 + "rx_expand_skb_head=%u\n"
27128 + "rx_expand_skb_head2=%u\n"
27129 + "rx_handlers_fragments=%u\n"
27130 + "tx_status_drop=%u\n",
27131 + local->tx_handlers_drop,
27132 + local->tx_handlers_queued,
27133 + local->tx_handlers_drop_unencrypted,
27134 + local->tx_handlers_drop_fragment,
27135 + local->tx_handlers_drop_wep,
27136 + local->tx_handlers_drop_rate_limit,
27137 + local->tx_handlers_drop_not_assoc,
27138 + local->tx_handlers_drop_unauth_port,
27139 + local->rx_handlers_drop,
27140 + local->rx_handlers_queued,
27141 + local->rx_handlers_drop_nullfunc,
27142 + local->rx_handlers_drop_defrag,
27143 + local->rx_handlers_drop_short,
27144 + local->rx_handlers_drop_passive_scan,
27145 + local->tx_expand_skb_head,
27146 + local->tx_expand_skb_head_cloned,
27147 + local->rx_expand_skb_head,
27148 + local->rx_expand_skb_head2,
27149 + local->rx_handlers_fragments,
27150 + local->tx_status_drop);
27151 + {
27152 + int i;
27153 + p += sprintf(p, "wme_rx_queue=");
27154 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27155 + p += sprintf(p, " %u", local->wme_rx_queue[i]);
27156 + p += sprintf(p, "\n");
27157 +
27158 + p += sprintf(p, "wme_tx_queue=");
27159 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27160 + p += sprintf(p, " %u", local->wme_tx_queue[i]);
27161 + p += sprintf(p, "\n");
27162 + }
27163 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27164 +
27165 + p += sprintf(p, "num_scans=%u\n", local->scan.num_scans);
27166 +
27167 + p += sprintf(p,
27168 + "conf.bss_count=%d\n"
27169 + "bss_dev_count=%u\n",
27170 + local->conf.bss_count, local->bss_dev_count);
27171 + for (i = 0; i < local->conf.bss_count; i++) {
27172 + p += sprintf(p, "bss_dev[%d]=%p (%s)\n",
27173 + i, local->bss_devs[i],
27174 + (i < local->bss_dev_count && local->bss_devs[i]) ?
27175 + local->bss_devs[i]->name : "N/A");
27176 + }
27177 +
27178 + return (p - page);
27179 +}
27180 +
27181 +
27182 +static const char * ieee80211_mode_str_short(int mode)
27183 +{
27184 + switch (mode) {
27185 + case MODE_IEEE80211A:
27186 + return "802.11a";
27187 + case MODE_IEEE80211B:
27188 + return "802.11b";
27189 + case MODE_IEEE80211G:
27190 + return "802.11g";
27191 + case MODE_ATHEROS_TURBO:
27192 + return "AtherosTurbo";
27193 + default:
27194 + return "UNKNOWN";
27195 + }
27196 +}
27197 +
27198 +
27199 +static const char * ieee80211_mode_str(int mode)
27200 +{
27201 + switch (mode) {
27202 + case MODE_IEEE80211A:
27203 + return "IEEE 802.11a";
27204 + case MODE_IEEE80211B:
27205 + return "IEEE 802.11b";
27206 + case MODE_IEEE80211G:
27207 + return "IEEE 802.11g";
27208 + case MODE_ATHEROS_TURBO:
27209 + return "Atheros Turbo (5 GHz)";
27210 + default:
27211 + return "UNKNOWN";
27212 + }
27213 +}
27214 +
27215 +
27216 +static int ieee80211_proc_info_read(char *page, char **start, off_t off,
27217 + int count, int *eof, void *data)
27218 +{
27219 + char *p = page;
27220 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27221 + int m;
27222 + struct ieee80211_hw_modes *mode;
27223 +
27224 + if (off != 0) {
27225 + *eof = 1;
27226 + return 0;
27227 + }
27228 +
27229 + p += sprintf(p, "hw_name=%s\n", local->hw->name);
27230 + p += sprintf(p, "modes=");
27231 + for (m = 0; m < local->hw->num_modes; m++) {
27232 + mode = &local->hw->modes[m];
27233 + p += sprintf(p, "[%s]", ieee80211_mode_str_short(mode->mode));
27234 + }
27235 + p += sprintf(p, "\n");
27236 + if (local->rate_ctrl && local->rate_ctrl_priv)
27237 + p+= sprintf(p, "rate_ctrl_alg=%s\n", local->rate_ctrl->name);
27238 + return (p - page);
27239 +}
27240 +
27241 +
27242 +static int ieee80211_proc_config_read(char *page, char **start, off_t off,
27243 + int count, int *eof, void *data)
27244 +{
27245 + char *p = page;
27246 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27247 +
27248 + if (off != 0) {
27249 + *eof = 1;
27250 + return 0;
27251 + }
27252 +
27253 + p += sprintf(p,
27254 + "low_level_driver=%s\n"
27255 + "channel=%d\n"
27256 + "freq=%d\n"
27257 + "mode=%s\n"
27258 + "802.11h=%d\n"
27259 + "wep_iv=0x%06x\n"
27260 + "antenna_sel=%d\n"
27261 + "calib_int=%d\n"
27262 + "tx_power_reduction=%d.%d dBm\n"
27263 + "bridge_packets=%d\n"
27264 + "key_tx_rx_threshold=%d\n"
27265 + "rts_threshold=%d\n"
27266 + "fragmentation_threshold=%d\n"
27267 + "short_retry_limit=%d\n"
27268 + "long_retry_limit=%d\n"
27269 + "total_ps_buffered=%d\n",
27270 + local->hw->name ? local->hw->name : "N/A",
27271 + local->conf.channel,
27272 + local->conf.freq,
27273 + ieee80211_mode_str(local->conf.phymode),
27274 + local->conf.radar_detect,
27275 + local->wep_iv & 0xffffff,
27276 + local->conf.antenna_sel,
27277 + local->conf.calib_int,
27278 + local->conf.tx_power_reduction / 10,
27279 + local->conf.tx_power_reduction % 10,
27280 + local->bridge_packets,
27281 + local->key_tx_rx_threshold,
27282 + local->rts_threshold,
27283 + local->fragmentation_threshold,
27284 + local->short_retry_limit,
27285 + local->long_retry_limit,
27286 + local->total_ps_buffered);
27287 +
27288 + return (p - page);
27289 +}
27290 +
27291 +
27292 +static int ieee80211_proc_channels_read(char *page, char **start, off_t off,
27293 + int count, int *eof, void *data)
27294 +{
27295 + char *p = page;
27296 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27297 + int m, c;
27298 + struct ieee80211_hw_modes *mode;
27299 + struct ieee80211_channel *chan;
27300 +
27301 + if (off != 0) {
27302 + *eof = 1;
27303 + return 0;
27304 + }
27305 +
27306 + p += sprintf(p, "MODE CHAN FREQ TXPOWER ANTMAX FLAGS\n");
27307 + for (m = 0; m < local->hw->num_modes; m++) {
27308 + mode = &local->hw->modes[m];
27309 + for (c = 0; c < mode->num_channels; c++) {
27310 + chan = &mode->channels[c];
27311 + p += sprintf(p, "%d %d %d %d %d %s%s%s\n",
27312 + mode->mode, chan->chan, chan->freq,
27313 + chan->power_level, chan->antenna_max,
27314 + chan->flag & IEEE80211_CHAN_W_SCAN ?
27315 + "[W_SCAN]" : "",
27316 + chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN
27317 + ? "[W_ACTIVE_SCAN]" : "",
27318 + chan->flag & IEEE80211_CHAN_W_IBSS ?
27319 + "[W_IBSS]" : "");
27320 + }
27321 + }
27322 + return (p - page);
27323 +}
27324 +
27325 +
27326 +static int ieee80211_proc_rates_read(char *page, char **start, off_t off,
27327 + int count, int *eof, void *data)
27328 +{
27329 + char *p = page;
27330 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27331 + int r;
27332 + struct ieee80211_rate *rate;
27333 +
27334 + if (off != 0) {
27335 + *eof = 1;
27336 + return 0;
27337 + }
27338 +
27339 + p += sprintf(p, "RATE VAL VAL2 MIN_RSSI_ACK MIN_RSSI_ACK_DELTA "
27340 + "FLAGS\n");
27341 + for (r = 0; r < local->num_curr_rates; r++) {
27342 + rate = &local->curr_rates[r];
27343 + p += sprintf(p, "%d %d %d %d %d 0x%x %s%s%s%s%s%s%s%s\n",
27344 + rate->rate, rate->val, rate->val2,
27345 + rate->min_rssi_ack, rate->min_rssi_ack_delta,
27346 + rate->flags,
27347 + rate->flags & IEEE80211_RATE_ERP ? "[ERP]" : "",
27348 + rate->flags & IEEE80211_RATE_BASIC ?
27349 + "[BASIC]" : "",
27350 + rate->flags & IEEE80211_RATE_PREAMBLE2 ?
27351 + "[PREAMBLE2]" : "",
27352 + rate->flags & IEEE80211_RATE_SUPPORTED ?
27353 + "[SUPPORTED]" : "",
27354 + rate->flags & IEEE80211_RATE_OFDM ? "[OFDM]" : "",
27355 + rate->flags & IEEE80211_RATE_CCK ? "[CCK]" : "",
27356 + rate->flags & IEEE80211_RATE_TURBO ?
27357 + "[TURBO]" : "",
27358 + rate->flags & IEEE80211_RATE_MANDATORY ?
27359 + "[MANDATORY]" : "");
27360 + }
27361 + return (p - page);
27362 +}
27363 +
27364 +
27365 +static int ieee80211_proc_multicast_read(char *page, char **start, off_t off,
27366 + int count, int *eof, void *data)
27367 +{
27368 + char *p = page;
27369 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27370 +
27371 + if (off != 0) {
27372 + *eof = 1;
27373 + return 0;
27374 + }
27375 +
27376 + return rate_control_status_global(local, p);
27377 +
27378 +}
27379 +
27380 +
27381 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27382 + struct sta_info *sta)
27383 +{
27384 + char buf[30];
27385 + struct proc_dir_entry *entry;
27386 +
27387 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27388 +
27389 + if (!local->proc_sta)
27390 + return;
27391 +
27392 + entry = create_proc_read_entry(buf, 0, local->proc_sta,
27393 + ieee80211_proc_sta_read, sta);
27394 + if (entry) {
27395 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27396 + sta->proc_entry_added = 1;
27397 + }
27398 +}
27399 +
27400 +
27401 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27402 + struct sta_info *sta)
27403 +{
27404 + char buf[30];
27405 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27406 + if (local->proc_sta) {
27407 + remove_proc_entry(buf, local->proc_sta);
27408 + sta->proc_entry_added = 0;
27409 + }
27410 +}
27411 +
27412 +
27413 +void ieee80211_proc_init_virtual(struct net_device *dev)
27414 +{
27415 + struct proc_dir_entry *entry;
27416 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27417 +
27418 + if (!local->proc_iface)
27419 + return;
27420 +
27421 + entry = create_proc_read_entry(dev->name, 0, local->proc_iface,
27422 + ieee80211_proc_iface_read, dev);
27423 + if (entry)
27424 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27425 +}
27426 +
27427 +
27428 +void ieee80211_proc_deinit_virtual(struct net_device *dev)
27429 +{
27430 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27431 +
27432 + if (local->proc_iface)
27433 + remove_proc_entry(dev->name, local->proc_iface);
27434 +}
27435 +
27436 +
27437 +void ieee80211_proc_init_interface(struct ieee80211_local *local)
27438 +{
27439 + if (!ieee80211_proc)
27440 + return;
27441 +
27442 + local->proc = proc_mkdir(local->wdev->name, ieee80211_proc);
27443 + if (!local->proc)
27444 + return;
27445 +
27446 + local->proc_sta = proc_mkdir("sta", local->proc);
27447 + local->proc_iface = proc_mkdir("iface", local->proc);
27448 + create_proc_read_entry("counters", 0, local->proc,
27449 + ieee80211_proc_counters_read, local);
27450 + create_proc_read_entry("config", 0, local->proc,
27451 + ieee80211_proc_config_read, local);
27452 + create_proc_read_entry("channels", 0, local->proc,
27453 + ieee80211_proc_channels_read, local);
27454 + create_proc_read_entry("rates", 0, local->proc,
27455 + ieee80211_proc_rates_read, local);
27456 + create_proc_read_entry("multicast", 0, local->proc,
27457 + ieee80211_proc_multicast_read, local);
27458 + create_proc_read_entry("debug", 0, local->proc,
27459 + ieee80211_proc_debug_read, local);
27460 + create_proc_read_entry("info", 0, local->proc,
27461 + ieee80211_proc_info_read, local);
27462 + ieee80211_proc_init_virtual(local->wdev);
27463 +}
27464 +
27465 +
27466 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local)
27467 +{
27468 + if (!local->proc)
27469 + return;
27470 +
27471 + ieee80211_proc_deinit_virtual(local->wdev);
27472 + remove_proc_entry("iface", local->proc);
27473 + remove_proc_entry("sta", local->proc);
27474 + remove_proc_entry("counters", local->proc);
27475 + remove_proc_entry("debug", local->proc);
27476 + remove_proc_entry("config", local->proc);
27477 + remove_proc_entry("channels", local->proc);
27478 + remove_proc_entry("rates", local->proc);
27479 + remove_proc_entry("multicast", local->proc);
27480 + remove_proc_entry("info", local->proc);
27481 + local->proc = NULL;
27482 + remove_proc_entry(local->wdev->name, ieee80211_proc);
27483 +}
27484 +
27485 +
27486 +void ieee80211_proc_init(void)
27487 +{
27488 + if (proc_net == NULL) {
27489 + ieee80211_proc = NULL;
27490 + return;
27491 + }
27492 +
27493 + ieee80211_proc = proc_mkdir("ieee80211", proc_net);
27494 + if (!ieee80211_proc)
27495 + printk(KERN_WARNING "Failed to mkdir /proc/net/ieee80211\n");
27496 +}
27497 +
27498 +
27499 +void ieee80211_proc_deinit(void)
27500 +{
27501 + if (!ieee80211_proc)
27502 + return;
27503 +
27504 + ieee80211_proc = NULL;
27505 + remove_proc_entry("ieee80211", proc_net);
27506 +}
27507 +
27508 +#endif /* CONFIG_PROC_FS */
27509 diff -Nur linux-2.6.16/net/d80211/ieee80211_proc.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.h
27510 --- linux-2.6.16/net/d80211/ieee80211_proc.h 1970-01-01 01:00:00.000000000 +0100
27511 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.h 2006-03-28 22:16:14.000000000 +0200
27512 @@ -0,0 +1,45 @@
27513 +/*
27514 + * Copyright 2003-2004, Instant802 Networks, Inc.
27515 + *
27516 + * This program is free software; you can redistribute it and/or modify
27517 + * it under the terms of the GNU General Public License version 2 as
27518 + * published by the Free Software Foundation.
27519 + */
27520 +
27521 +#ifndef IEEE80211_PROC_H
27522 +#define IEEE80211_PROC_H
27523 +
27524 +#include <linux/netdevice.h>
27525 +#include "ieee80211_i.h"
27526 +#include "sta_info.h"
27527 +
27528 +#ifdef CONFIG_PROC_FS
27529 +
27530 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27531 + struct sta_info *sta);
27532 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27533 + struct sta_info *sta);
27534 +void ieee80211_proc_init_virtual(struct net_device *dev);
27535 +void ieee80211_proc_deinit_virtual(struct net_device *dev);
27536 +void ieee80211_proc_init_interface(struct ieee80211_local *local);
27537 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local);
27538 +void ieee80211_proc_init(void);
27539 +void ieee80211_proc_deinit(void);
27540 +
27541 +#else /* CONFIG_PROC_FS */
27542 +
27543 +static inline void ieee80211_proc_init_sta(struct ieee80211_local *local,
27544 + struct sta_info *sta) {}
27545 +static inline void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27546 + struct sta_info *sta) {}
27547 +static inline void ieee80211_proc_init_virtual(struct net_device *dev) {}
27548 +static inline void ieee80211_proc_deinit_virtual(struct net_device *dev) {}
27549 +static inline void
27550 +ieee80211_proc_init_interface(struct ieee80211_local *local) {}
27551 +static inline void
27552 +ieee80211_proc_deinit_interface(struct ieee80211_local *local) {}
27553 +static inline void ieee80211_proc_init(void) {}
27554 +static inline void ieee80211_proc_deinit(void) {}
27555 +#endif /* CONFIG_PROC_FS */
27556 +
27557 +#endif /* IEEE80211_PROC_H */
27558 diff -Nur linux-2.6.16/net/d80211/ieee80211_scan.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_scan.c
27559 --- linux-2.6.16/net/d80211/ieee80211_scan.c 1970-01-01 01:00:00.000000000 +0100
27560 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_scan.c 2006-03-28 22:16:14.000000000 +0200
27561 @@ -0,0 +1,352 @@
27562 +/*
27563 + * Copyright 2002-2004, Instant802 Networks, Inc.
27564 + *
27565 + * This program is free software; you can redistribute it and/or modify
27566 + * it under the terms of the GNU General Public License version 2 as
27567 + * published by the Free Software Foundation.
27568 + */
27569 +
27570 +#include <linux/config.h>
27571 +#include <linux/version.h>
27572 +#include <linux/module.h>
27573 +#include <linux/netdevice.h>
27574 +#include <linux/types.h>
27575 +#include <linux/slab.h>
27576 +#include <linux/skbuff.h>
27577 +
27578 +#include <net/d80211.h>
27579 +#include "ieee80211_i.h"
27580 +#include "rate_control.h"
27581 +
27582 +
27583 +/* Maximum number of seconds to wait for the traffic load to get below
27584 + * threshold before forcing a passive scan. */
27585 +#define MAX_SCAN_WAIT 60
27586 +/* Threshold (pkts/sec TX or RX) for delaying passive scan */
27587 +#define SCAN_TXRX_THRESHOLD 75
27588 +
27589 +static void get_channel_params(struct ieee80211_local *local, int channel,
27590 + struct ieee80211_hw_modes **mode,
27591 + struct ieee80211_channel **chan)
27592 +{
27593 + int m;
27594 +
27595 + for (m = 0; m < local->hw->num_modes; m++) {
27596 + *mode = &local->hw->modes[m];
27597 + if ((*mode)->mode == local->conf.phymode)
27598 + break;
27599 + }
27600 + local->scan.mode_idx = m;
27601 + local->scan.chan_idx = 0;
27602 + do {
27603 + *chan = &(*mode)->channels[local->scan.chan_idx];
27604 + if ((*chan)->chan == channel) {
27605 + return;
27606 + }
27607 + local->scan.chan_idx++;
27608 + } while (local->scan.chan_idx < (*mode)->num_channels);
27609 + *chan = NULL;
27610 +}
27611 +
27612 +
27613 +static void next_chan_same_mode(struct ieee80211_local *local,
27614 + struct ieee80211_hw_modes **mode,
27615 + struct ieee80211_channel **chan)
27616 +{
27617 + int m, prev;
27618 +
27619 + for (m = 0; m < local->hw->num_modes; m++) {
27620 + *mode = &local->hw->modes[m];
27621 + if ((*mode)->mode == local->conf.phymode)
27622 + break;
27623 + }
27624 + local->scan.mode_idx = m;
27625 +
27626 + /* Select next channel - scan only channels marked with W_SCAN flag */
27627 + prev = local->scan.chan_idx;
27628 + do {
27629 + local->scan.chan_idx++;
27630 + if (local->scan.chan_idx >= (*mode)->num_channels)
27631 + local->scan.chan_idx = 0;
27632 + *chan = &(*mode)->channels[local->scan.chan_idx];
27633 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27634 + break;
27635 + } while (local->scan.chan_idx != prev);
27636 +}
27637 +
27638 +
27639 +static void next_chan_all_modes(struct ieee80211_local *local,
27640 + struct ieee80211_hw_modes **mode,
27641 + struct ieee80211_channel **chan)
27642 +{
27643 + int prev, prev_m;
27644 +
27645 + if (local->scan.mode_idx >= local->hw->num_modes) {
27646 + local->scan.mode_idx = 0;
27647 + local->scan.chan_idx = 0;
27648 + }
27649 +
27650 + /* Select next channel - scan only channels marked with W_SCAN flag */
27651 + prev = local->scan.chan_idx;
27652 + prev_m = local->scan.mode_idx;
27653 + do {
27654 + *mode = &local->hw->modes[local->scan.mode_idx];
27655 + local->scan.chan_idx++;
27656 + if (local->scan.chan_idx >= (*mode)->num_channels) {
27657 + local->scan.chan_idx = 0;
27658 + local->scan.mode_idx++;
27659 + if (local->scan.mode_idx >= local->hw->num_modes)
27660 + local->scan.mode_idx = 0;
27661 + *mode = &local->hw->modes[local->scan.mode_idx];
27662 + }
27663 + *chan = &(*mode)->channels[local->scan.chan_idx];
27664 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27665 + break;
27666 + } while (local->scan.chan_idx != prev ||
27667 + local->scan.mode_idx != prev_m);
27668 +}
27669 +
27670 +
27671 +static void ieee80211_scan_start(struct net_device *dev,
27672 + struct ieee80211_scan_conf *conf)
27673 +{
27674 + struct ieee80211_local *local = dev->priv;
27675 + int old_mode_idx = local->scan.mode_idx;
27676 + int old_chan_idx = local->scan.chan_idx;
27677 + struct ieee80211_hw_modes *mode = NULL;
27678 + struct ieee80211_channel *chan = NULL;
27679 + int ret;
27680 +
27681 + if (local->hw->passive_scan == 0) {
27682 + printk(KERN_DEBUG "%s: Scan handler called, yet the hardware "
27683 + "does not support passive scanning. Disabled.\n",
27684 + dev->name);
27685 + return;
27686 + }
27687 +
27688 + if ((local->scan.tries < MAX_SCAN_WAIT &&
27689 + local->scan.txrx_count > SCAN_TXRX_THRESHOLD)) {
27690 + local->scan.tries++;
27691 + /* Count TX/RX packets during one second interval and allow
27692 + * scan to start only if the number of packets is below the
27693 + * threshold. */
27694 + local->scan.txrx_count = 0;
27695 + local->scan.timer.expires = jiffies + HZ;
27696 + add_timer(&local->scan.timer);
27697 + return;
27698 + }
27699 +
27700 + if (local->scan.skb == NULL) {
27701 + printk(KERN_DEBUG "%s: Scan start called even though scan.skb "
27702 + "is not set\n", dev->name);
27703 + }
27704 +
27705 + if (local->scan.our_mode_only) {
27706 + if (local->scan.channel > 0) {
27707 + get_channel_params(local, local->scan.channel, &mode,
27708 + &chan);
27709 + } else
27710 + next_chan_same_mode(local, &mode, &chan);
27711 + }
27712 + else
27713 + next_chan_all_modes(local, &mode, &chan);
27714 +
27715 + conf->scan_channel = chan->chan;
27716 + conf->scan_freq = chan->freq;
27717 + conf->scan_channel_val = chan->val;
27718 + conf->scan_phymode = mode->mode;
27719 + conf->scan_power_level = chan->power_level;
27720 + conf->scan_antenna_max = chan->antenna_max;
27721 + conf->scan_time = 2 * local->hw->channel_change_time +
27722 + local->scan.time; /* 10ms scan time+hardware changes */
27723 + conf->skb = local->scan.skb ?
27724 + skb_clone(local->scan.skb, GFP_ATOMIC) : NULL;
27725 + conf->tx_control = &local->scan.tx_control;
27726 +#if 0
27727 + printk(KERN_DEBUG "%s: Doing scan on mode: %d freq: %d chan: %d "
27728 + "for %d ms\n",
27729 + dev->name, conf->scan_phymode, conf->scan_freq,
27730 + conf->scan_channel, conf->scan_time);
27731 +#endif
27732 + local->scan.rx_packets = 0;
27733 + local->scan.rx_beacon = 0;
27734 + local->scan.freq = chan->freq;
27735 + local->scan.in_scan = 1;
27736 +
27737 + ieee80211_netif_oper(dev, NETIF_STOP);
27738 +
27739 + ret = local->hw->passive_scan(dev, IEEE80211_SCAN_START, conf);
27740 +
27741 + if (ret == 0) {
27742 + long usec = local->hw->channel_change_time +
27743 + local->scan.time;
27744 + usec += 1000000L / HZ - 1;
27745 + usec /= 1000000L / HZ;
27746 + local->scan.timer.expires = jiffies + usec;
27747 + } else {
27748 + local->scan.in_scan = 0;
27749 + if (conf->skb)
27750 + dev_kfree_skb(conf->skb);
27751 + ieee80211_netif_oper(dev, NETIF_WAKE);
27752 + if (ret == -EAGAIN) {
27753 + local->scan.timer.expires = jiffies +
27754 + (local->scan.interval * HZ / 100);
27755 + local->scan.mode_idx = old_mode_idx;
27756 + local->scan.chan_idx = old_chan_idx;
27757 + } else {
27758 + printk(KERN_DEBUG "%s: Got unknown error from "
27759 + "passive_scan %d\n", dev->name, ret);
27760 + local->scan.timer.expires = jiffies +
27761 + (local->scan.interval * HZ);
27762 + }
27763 + local->scan.in_scan = 0;
27764 + }
27765 +
27766 + add_timer(&local->scan.timer);
27767 +}
27768 +
27769 +
27770 +static void ieee80211_scan_stop(struct net_device *dev,
27771 + struct ieee80211_scan_conf *conf)
27772 +{
27773 + struct ieee80211_local *local = dev->priv;
27774 + struct ieee80211_hw_modes *mode;
27775 + struct ieee80211_channel *chan;
27776 + int wait;
27777 +
27778 + if (local->hw->passive_scan == NULL)
27779 + return;
27780 +
27781 + if (local->scan.mode_idx >= local->hw->num_modes) {
27782 + local->scan.mode_idx = 0;
27783 + local->scan.chan_idx = 0;
27784 + }
27785 +
27786 + mode = &local->hw->modes[local->scan.mode_idx];
27787 +
27788 + if (local->scan.chan_idx >= mode->num_channels) {
27789 + local->scan.chan_idx = 0;
27790 + }
27791 +
27792 + chan = &mode->channels[local->scan.chan_idx];
27793 +
27794 + local->hw->passive_scan(dev, IEEE80211_SCAN_END, conf);
27795 +
27796 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
27797 + printk(KERN_DEBUG "%s: Did scan on mode: %d freq: %d chan: %d "
27798 + "GOT: %d Beacon: %d (%d)\n",
27799 + dev->name,
27800 + mode->mode, chan->freq, chan->chan,
27801 + local->scan.rx_packets, local->scan.rx_beacon,
27802 + local->scan.tries);
27803 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
27804 + local->scan.num_scans++;
27805 +
27806 + local->scan.in_scan = 0;
27807 + ieee80211_netif_oper(dev, NETIF_WAKE);
27808 +
27809 + local->scan.tries = 0;
27810 + /* Use random interval of scan.interval .. 2 * scan.interval */
27811 + wait = (local->scan.interval * HZ * ((net_random() & 127) + 128)) /
27812 + 128;
27813 + local->scan.timer.expires = jiffies + wait;
27814 +
27815 + add_timer(&local->scan.timer);
27816 +}
27817 +
27818 +
27819 +static void ieee80211_scan_handler(unsigned long uldev)
27820 +{
27821 + struct net_device *dev = (struct net_device *) uldev;
27822 + struct ieee80211_local *local = dev->priv;
27823 + struct ieee80211_scan_conf conf;
27824 +
27825 + if (local->scan.interval == 0 && !local->scan.in_scan) {
27826 + /* Passive scanning is disabled - keep the timer always
27827 + * running to make code cleaner. */
27828 + local->scan.timer.expires = jiffies + 10 * HZ;
27829 + add_timer(&local->scan.timer);
27830 + return;
27831 + }
27832 +
27833 + memset(&conf, 0, sizeof(struct ieee80211_scan_conf));
27834 + conf.running_freq = local->conf.freq;
27835 + conf.running_channel = local->conf.channel;
27836 + conf.running_phymode = local->conf.phymode;
27837 + conf.running_channel_val = local->conf.channel_val;
27838 + conf.running_power_level = local->conf.power_level;
27839 + conf.running_antenna_max = local->conf.antenna_max;
27840 +
27841 + if (local->scan.in_scan == 0)
27842 + ieee80211_scan_start(dev, &conf);
27843 + else
27844 + ieee80211_scan_stop(dev, &conf);
27845 +}
27846 +
27847 +
27848 +void ieee80211_init_scan(struct net_device *dev)
27849 +{
27850 + struct ieee80211_local *local = dev->priv;
27851 + struct ieee80211_hdr hdr;
27852 + u16 fc;
27853 + int len = 10;
27854 + struct rate_control_extra extra;
27855 +
27856 + /* Only initialize passive scanning if the hardware supports it */
27857 + if (!local->hw->passive_scan) {
27858 + local->scan.skb = NULL;
27859 + memset(&local->scan.tx_control, 0,
27860 + sizeof(local->scan.tx_control));
27861 + printk(KERN_DEBUG "%s: Does not support passive scan, "
27862 + "disabled\n", dev->name);
27863 + return;
27864 + }
27865 +
27866 + local->scan.interval = 0;
27867 + local->scan.our_mode_only = 1;
27868 + local->scan.time = 10000;
27869 + local->scan.timer.function = ieee80211_scan_handler;
27870 + local->scan.timer.data = (unsigned long) dev;
27871 + local->scan.timer.expires = jiffies + local->scan.interval * HZ;
27872 + add_timer(&local->scan.timer);
27873 +
27874 + /* Create a CTS from for broadcasting before
27875 + * the low level changes channels */
27876 + local->scan.skb = alloc_skb(len, GFP_KERNEL);
27877 + if (local->scan.skb == NULL) {
27878 + printk(KERN_WARNING "%s: Failed to allocate CTS packet for "
27879 + "passive scan\n", dev->name);
27880 + return;
27881 + }
27882 +
27883 + fc = (WLAN_FC_TYPE_CTRL << 2) | (WLAN_FC_STYPE_CTS << 4);
27884 + hdr.frame_control = cpu_to_le16(fc);
27885 + hdr.duration_id =
27886 + cpu_to_le16(2 * local->hw->channel_change_time +
27887 + local->scan.time);
27888 + memcpy(hdr.addr1, dev->dev_addr, ETH_ALEN); /* DA */
27889 + hdr.seq_ctrl = 0;
27890 +
27891 + memcpy(skb_put(local->scan.skb, len), &hdr, len);
27892 +
27893 + memset(&local->scan.tx_control, 0, sizeof(local->scan.tx_control));
27894 + local->scan.tx_control.key_idx = HW_KEY_IDX_INVALID;
27895 + local->scan.tx_control.do_not_encrypt = 1;
27896 + memset(&extra, 0, sizeof(extra));
27897 + extra.endidx = local->num_curr_rates;
27898 + local->scan.tx_control.tx_rate =
27899 + rate_control_get_rate(dev, local->scan.skb, &extra)->val;
27900 + local->scan.tx_control.no_ack = 1;
27901 +}
27902 +
27903 +
27904 +void ieee80211_stop_scan(struct net_device *dev)
27905 +{
27906 + struct ieee80211_local *local = dev->priv;
27907 +
27908 + if (local->hw->passive_scan != 0) {
27909 + del_timer_sync(&local->scan.timer);
27910 + dev_kfree_skb(local->scan.skb);
27911 + local->scan.skb = NULL;
27912 + }
27913 +}
27914 diff -Nur linux-2.6.16/net/d80211/ieee80211_sta.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_sta.c
27915 --- linux-2.6.16/net/d80211/ieee80211_sta.c 1970-01-01 01:00:00.000000000 +0100
27916 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_sta.c 2006-03-28 22:16:14.000000000 +0200
27917 @@ -0,0 +1,2866 @@
27918 +/*
27919 + * BSS client mode implementation
27920 + * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
27921 + * Copyright 2004, Instant802 Networks, Inc.
27922 + * Copyright 2005, Devicescape Software, Inc.
27923 + *
27924 + * This program is free software; you can redistribute it and/or modify
27925 + * it under the terms of the GNU General Public License version 2 as
27926 + * published by the Free Software Foundation.
27927 + */
27928 +
27929 +/* TODO:
27930 + * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs
27931 + * order BSS list by RSSI(?) ("quality of AP")
27932 + * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
27933 + * SSID)
27934 + */
27935 +#include <linux/config.h>
27936 +#include <linux/version.h>
27937 +#include <linux/if_ether.h>
27938 +#include <linux/skbuff.h>
27939 +#include <linux/netdevice.h>
27940 +#include <linux/if_arp.h>
27941 +#include <linux/wireless.h>
27942 +#include <linux/random.h>
27943 +#include <net/iw_handler.h>
27944 +#include <asm/types.h>
27945 +#include <asm/delay.h>
27946 +
27947 +#include <net/d80211.h>
27948 +#include <net/d80211_mgmt.h>
27949 +#include "ieee80211_i.h"
27950 +#include "rate_control.h"
27951 +#include "hostapd_ioctl.h"
27952 +
27953 +/* #define IEEE80211_IBSS_DEBUG */
27954 +
27955 +#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
27956 +#define IEEE80211_AUTH_MAX_TRIES 3
27957 +#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
27958 +#define IEEE80211_ASSOC_MAX_TRIES 3
27959 +#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
27960 +#define IEEE80211_PROBE_INTERVAL (60 * HZ)
27961 +#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
27962 +#define IEEE80211_SCAN_INTERVAL (2 * HZ)
27963 +#define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
27964 +#define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
27965 +
27966 +#define IEEE80211_PROBE_DELAY (HZ / 33)
27967 +#define IEEE80211_CHANNEL_TIME (HZ / 33)
27968 +#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
27969 +#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
27970 +#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
27971 +#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
27972 +
27973 +#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
27974 +
27975 +
27976 +#define IEEE80211_FC(type, stype) cpu_to_le16((type << 2) | (stype << 4))
27977 +
27978 +#define ERP_INFO_USE_PROTECTION BIT(1)
27979 +
27980 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
27981 + u8 *ssid, size_t ssid_len);
27982 +static struct ieee80211_sta_bss *
27983 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid);
27984 +static void ieee80211_rx_bss_put(struct net_device *dev,
27985 + struct ieee80211_sta_bss *bss);
27986 +static int ieee80211_sta_find_ibss(struct net_device *dev,
27987 + struct ieee80211_if_sta *ifsta);
27988 +static int ieee80211_sta_wep_configured(struct net_device *dev);
27989 +
27990 +
27991 +/* Parsed Information Elements */
27992 +struct ieee802_11_elems {
27993 + u8 *ssid;
27994 + u8 ssid_len;
27995 + u8 *supp_rates;
27996 + u8 supp_rates_len;
27997 + u8 *fh_params;
27998 + u8 fh_params_len;
27999 + u8 *ds_params;
28000 + u8 ds_params_len;
28001 + u8 *cf_params;
28002 + u8 cf_params_len;
28003 + u8 *tim;
28004 + u8 tim_len;
28005 + u8 *ibss_params;
28006 + u8 ibss_params_len;
28007 + u8 *challenge;
28008 + u8 challenge_len;
28009 + u8 *wpa;
28010 + u8 wpa_len;
28011 + u8 *rsn;
28012 + u8 rsn_len;
28013 + u8 *erp_info;
28014 + u8 erp_info_len;
28015 + u8 *ext_supp_rates;
28016 + u8 ext_supp_rates_len;
28017 + u8 *wmm_info;
28018 + u8 wmm_info_len;
28019 + u8 *wmm_param;
28020 + u8 wmm_param_len;
28021 +};
28022 +
28023 +typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
28024 +
28025 +
28026 +static ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
28027 + struct ieee802_11_elems *elems)
28028 +{
28029 + size_t left = len;
28030 + u8 *pos = start;
28031 + int unknown = 0;
28032 +
28033 + memset(elems, 0, sizeof(*elems));
28034 +
28035 + while (left >= 2) {
28036 + u8 id, elen;
28037 +
28038 + id = *pos++;
28039 + elen = *pos++;
28040 + left -= 2;
28041 +
28042 + if (elen > left) {
28043 +#if 0
28044 + if (net_ratelimit())
28045 + printk(KERN_DEBUG "IEEE 802.11 element parse "
28046 + "failed (id=%d elen=%d left=%d)\n",
28047 + id, elen, left);
28048 +#endif
28049 + return ParseFailed;
28050 + }
28051 +
28052 + switch (id) {
28053 + case WLAN_EID_SSID:
28054 + elems->ssid = pos;
28055 + elems->ssid_len = elen;
28056 + break;
28057 + case WLAN_EID_SUPP_RATES:
28058 + elems->supp_rates = pos;
28059 + elems->supp_rates_len = elen;
28060 + break;
28061 + case WLAN_EID_FH_PARAMS:
28062 + elems->fh_params = pos;
28063 + elems->fh_params_len = elen;
28064 + break;
28065 + case WLAN_EID_DS_PARAMS:
28066 + elems->ds_params = pos;
28067 + elems->ds_params_len = elen;
28068 + break;
28069 + case WLAN_EID_CF_PARAMS:
28070 + elems->cf_params = pos;
28071 + elems->cf_params_len = elen;
28072 + break;
28073 + case WLAN_EID_TIM:
28074 + elems->tim = pos;
28075 + elems->tim_len = elen;
28076 + break;
28077 + case WLAN_EID_IBSS_PARAMS:
28078 + elems->ibss_params = pos;
28079 + elems->ibss_params_len = elen;
28080 + break;
28081 + case WLAN_EID_CHALLENGE:
28082 + elems->challenge = pos;
28083 + elems->challenge_len = elen;
28084 + break;
28085 + case WLAN_EID_WPA:
28086 + if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
28087 + pos[2] == 0xf2) {
28088 + /* Microsoft OUI (00:50:F2) */
28089 + if (pos[3] == 1) {
28090 + /* OUI Type 1 - WPA IE */
28091 + elems->wpa = pos;
28092 + elems->wpa_len = elen;
28093 + } else if (elen >= 5 && pos[3] == 2) {
28094 + if (pos[4] == 0) {
28095 + elems->wmm_info = pos;
28096 + elems->wmm_info_len = elen;
28097 + } else if (pos[4] == 1) {
28098 + elems->wmm_param = pos;
28099 + elems->wmm_param_len = elen;
28100 + }
28101 + }
28102 + }
28103 + break;
28104 + case WLAN_EID_RSN:
28105 + elems->rsn = pos;
28106 + elems->rsn_len = elen;
28107 + break;
28108 + case WLAN_EID_ERP_INFO:
28109 + elems->erp_info = pos;
28110 + elems->erp_info_len = elen;
28111 + break;
28112 + case WLAN_EID_EXT_SUPP_RATES:
28113 + elems->ext_supp_rates = pos;
28114 + elems->ext_supp_rates_len = elen;
28115 + break;
28116 + default:
28117 +#if 0
28118 + printk(KERN_DEBUG "IEEE 802.11 element parse ignored "
28119 + "unknown element (id=%d elen=%d)\n",
28120 + id, elen);
28121 +#endif
28122 + unknown++;
28123 + break;
28124 + }
28125 +
28126 + left -= elen;
28127 + pos += elen;
28128 + }
28129 +
28130 + /* Do not trigger error if left == 1 as Apple Airport base stations
28131 + * send AssocResps that are one spurious byte too long. */
28132 +
28133 + return unknown ? ParseUnknown : ParseOK;
28134 +}
28135 +
28136 +
28137 +
28138 +
28139 +static int ecw2cw(int ecw)
28140 +{
28141 + int cw = 1;
28142 + while (ecw > 0) {
28143 + cw <<= 1;
28144 + ecw--;
28145 + }
28146 + return cw - 1;
28147 +}
28148 +
28149 +
28150 +static void ieee80211_sta_wmm_params(struct net_device *dev,
28151 + struct ieee80211_if_sta *ifsta,
28152 + u8 *wmm_param, size_t wmm_param_len)
28153 +{
28154 + struct ieee80211_local *local = dev->priv;
28155 + struct ieee80211_tx_queue_params params;
28156 + size_t left;
28157 + int count;
28158 + u8 *pos;
28159 +
28160 + if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
28161 + return;
28162 + count = wmm_param[6] & 0x0f;
28163 + if (count == ifsta->wmm_last_param_set)
28164 + return;
28165 + ifsta->wmm_last_param_set = count;
28166 +
28167 + pos = wmm_param + 8;
28168 + left = wmm_param_len - 8;
28169 +
28170 + memset(&params, 0, sizeof(params));
28171 +
28172 + if (local->hw->conf_tx == NULL)
28173 + return;
28174 +
28175 + local->wmm_acm = 0;
28176 + for (; left >= 4; left -= 4, pos += 4) {
28177 + int aci = (pos[0] >> 5) & 0x03;
28178 + int acm = (pos[0] >> 4) & 0x01;
28179 + int queue;
28180 +
28181 + switch (aci) {
28182 + case 1:
28183 + queue = IEEE80211_TX_QUEUE_DATA3;
28184 + if (acm) {
28185 + local->wmm_acm |= BIT(1) | BIT(2);
28186 + }
28187 + break;
28188 + case 2:
28189 + queue = IEEE80211_TX_QUEUE_DATA1;
28190 + if (acm) {
28191 + local->wmm_acm |= BIT(4) | BIT(5);
28192 + }
28193 + break;
28194 + case 3:
28195 + queue = IEEE80211_TX_QUEUE_DATA0;
28196 + if (acm) {
28197 + local->wmm_acm |= BIT(6) | BIT(7);
28198 + }
28199 + break;
28200 + case 0:
28201 + default:
28202 + queue = IEEE80211_TX_QUEUE_DATA2;
28203 + if (acm) {
28204 + local->wmm_acm |= BIT(0) | BIT(3);
28205 + }
28206 + break;
28207 + }
28208 +
28209 + params.aifs = pos[0] & 0x0f;
28210 + params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
28211 + params.cw_min = ecw2cw(pos[1] & 0x0f);
28212 + /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
28213 + params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
28214 + printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
28215 + "cWmin=%d cWmax=%d burst=%d\n",
28216 + dev->name, queue, aci, acm, params.aifs, params.cw_min,
28217 + params.cw_max, params.burst_time);
28218 + /* TODO: handle ACM (block TX, fallback to next lowest allowed
28219 + * AC for now) */
28220 + if (local->hw->conf_tx(local->mdev, queue, &params)) {
28221 + printk(KERN_DEBUG "%s: failed to set TX queue "
28222 + "parameters for queue %d\n", dev->name, queue);
28223 + }
28224 + }
28225 +}
28226 +
28227 +
28228 +static void ieee80211_sta_send_associnfo(struct net_device *dev,
28229 + struct ieee80211_if_sta *ifsta)
28230 +{
28231 + char *buf;
28232 + size_t len;
28233 + int i;
28234 + union iwreq_data wrqu;
28235 +
28236 + if (ifsta->assocreq_ies == NULL && ifsta->assocresp_ies == NULL)
28237 + return;
28238 +
28239 + buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
28240 + ifsta->assocresp_ies_len), GFP_ATOMIC);
28241 + if (buf == NULL)
28242 + return;
28243 +
28244 + len = sprintf(buf, "ASSOCINFO(");
28245 + if (ifsta->assocreq_ies) {
28246 + len += sprintf(buf + len, "ReqIEs=");
28247 + for (i = 0; i < ifsta->assocreq_ies_len; i++) {
28248 + len += sprintf(buf + len, "%02x",
28249 + ifsta->assocreq_ies[i]);
28250 + }
28251 + }
28252 + if (ifsta->assocresp_ies) {
28253 + if (ifsta->assocreq_ies)
28254 + len += sprintf(buf + len, " ");
28255 + len += sprintf(buf + len, "RespIEs=");
28256 + for (i = 0; i < ifsta->assocresp_ies_len; i++) {
28257 + len += sprintf(buf + len, "%02x",
28258 + ifsta->assocresp_ies[i]);
28259 + }
28260 + }
28261 + len += sprintf(buf + len, ")");
28262 +
28263 + if (len > IW_CUSTOM_MAX) {
28264 + len = sprintf(buf, "ASSOCRESPIE=");
28265 + for (i = 0; i < ifsta->assocresp_ies_len; i++) {
28266 + len += sprintf(buf + len, "%02x",
28267 + ifsta->assocresp_ies[i]);
28268 + }
28269 + }
28270 +
28271 + memset(&wrqu, 0, sizeof(wrqu));
28272 + wrqu.data.length = len;
28273 + wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
28274 +
28275 + kfree(buf);
28276 +}
28277 +
28278 +
28279 +static void ieee80211_set_associated(struct net_device *dev,
28280 + struct ieee80211_if_sta *ifsta, int assoc)
28281 +{
28282 + union iwreq_data wrqu;
28283 +
28284 + if (ifsta->associated == assoc)
28285 + return;
28286 +
28287 + ifsta->associated = assoc;
28288 +
28289 + if (assoc) {
28290 + struct ieee80211_sub_if_data *sdata;
28291 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28292 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
28293 + return;
28294 + ifsta->prev_bssid_set = 1;
28295 + memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
28296 + memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
28297 + ieee80211_sta_send_associnfo(dev, ifsta);
28298 + } else {
28299 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28300 + }
28301 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28302 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28303 + ifsta->last_probe = jiffies;
28304 +}
28305 +
28306 +
28307 +static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
28308 + int encrypt, int probe_resp)
28309 +{
28310 + struct ieee80211_sub_if_data *sdata;
28311 + struct ieee80211_tx_packet_data *pkt_data;
28312 +
28313 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28314 + skb->dev = sdata->master;
28315 + skb->mac.raw = skb->nh.raw = skb->h.raw = skb->data;
28316 +
28317 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
28318 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
28319 + pkt_data->sdata = sdata;
28320 + pkt_data->do_not_encrypt = !encrypt;
28321 + if (probe_resp)
28322 + pkt_data->pkt_probe_resp = 1;
28323 +
28324 + dev_queue_xmit(skb);
28325 +}
28326 +
28327 +
28328 +static void ieee80211_send_auth(struct net_device *dev,
28329 + struct ieee80211_if_sta *ifsta,
28330 + int transaction, u8 *extra, size_t extra_len,
28331 + int encrypt)
28332 +{
28333 + struct sk_buff *skb;
28334 + struct ieee80211_mgmt *mgmt;
28335 +
28336 + skb = dev_alloc_skb(sizeof(*mgmt) + 6 + extra_len);
28337 + if (skb == NULL) {
28338 + printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
28339 + "frame\n", dev->name);
28340 + return;
28341 + }
28342 +
28343 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
28344 + memset(mgmt, 0, 24 + 6);
28345 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28346 + WLAN_FC_STYPE_AUTH);
28347 + if (encrypt)
28348 + mgmt->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
28349 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28350 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28351 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28352 + mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
28353 + mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
28354 + ifsta->auth_transaction = transaction + 1;
28355 + mgmt->u.auth.status_code = cpu_to_le16(0);
28356 + if (extra)
28357 + memcpy(skb_put(skb, extra_len), extra, extra_len);
28358 +
28359 + ieee80211_sta_tx(dev, skb, encrypt, 0);
28360 +}
28361 +
28362 +
28363 +static void ieee80211_authenticate(struct net_device *dev,
28364 + struct ieee80211_if_sta *ifsta)
28365 +{
28366 + ifsta->auth_tries++;
28367 + if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
28368 + printk(KERN_DEBUG "%s: authentication with AP " MACSTR
28369 + " timed out\n",
28370 + dev->name, MAC2STR(ifsta->bssid));
28371 + return;
28372 + }
28373 +
28374 + ifsta->state = IEEE80211_AUTHENTICATE;
28375 + printk(KERN_DEBUG "%s: authenticate with AP " MACSTR "\n",
28376 + dev->name, MAC2STR(ifsta->bssid));
28377 +
28378 + ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
28379 +
28380 + mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
28381 +}
28382 +
28383 +
28384 +static void ieee80211_send_assoc(struct net_device *dev,
28385 + struct ieee80211_if_sta *ifsta)
28386 +{
28387 + struct ieee80211_local *local = dev->priv;
28388 + struct sk_buff *skb;
28389 + struct ieee80211_mgmt *mgmt;
28390 + u8 *pos, *ies;
28391 + int i, len;
28392 + u16 capab;
28393 + struct ieee80211_sta_bss *bss;
28394 + int wmm = 0;
28395 +
28396 + skb = dev_alloc_skb(sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
28397 + ifsta->ssid_len);
28398 + if (skb == NULL) {
28399 + printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
28400 + "frame\n", dev->name);
28401 + return;
28402 + }
28403 +
28404 + capab = ifsta->capab;
28405 + if (local->conf.phymode == MODE_IEEE80211G) {
28406 + capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
28407 + WLAN_CAPABILITY_SHORT_PREAMBLE;
28408 + }
28409 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28410 + if (bss) {
28411 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
28412 + capab |= WLAN_CAPABILITY_PRIVACY;
28413 + if (bss->wmm_ie) {
28414 + wmm = 1;
28415 + }
28416 + ieee80211_rx_bss_put(dev, bss);
28417 + }
28418 +
28419 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28420 + memset(mgmt, 0, 24);
28421 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28422 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28423 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28424 +
28425 + if (ifsta->prev_bssid_set) {
28426 + skb_put(skb, 10);
28427 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28428 + WLAN_FC_STYPE_REASSOC_REQ);
28429 + mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
28430 + mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
28431 + memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
28432 + ETH_ALEN);
28433 + } else {
28434 + skb_put(skb, 4);
28435 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28436 + WLAN_FC_STYPE_ASSOC_REQ);
28437 + mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
28438 + mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
28439 + }
28440 +
28441 + /* SSID */
28442 + ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
28443 + *pos++ = WLAN_EID_SSID;
28444 + *pos++ = ifsta->ssid_len;
28445 + memcpy(pos, ifsta->ssid, ifsta->ssid_len);
28446 +
28447 + len = local->num_curr_rates;
28448 + if (len > 8)
28449 + len = 8;
28450 + pos = skb_put(skb, len + 2);
28451 + *pos++ = WLAN_EID_SUPP_RATES;
28452 + *pos++ = len;
28453 + for (i = 0; i < len; i++) {
28454 + int rate = local->curr_rates[i].rate;
28455 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28456 + rate /= 2;
28457 + *pos++ = (u8) (rate / 5);
28458 + }
28459 +
28460 + if (local->num_curr_rates > len) {
28461 + pos = skb_put(skb, local->num_curr_rates - len + 2);
28462 + *pos++ = WLAN_EID_EXT_SUPP_RATES;
28463 + *pos++ = local->num_curr_rates - len;
28464 + for (i = len; i < local->num_curr_rates; i++) {
28465 + int rate = local->curr_rates[i].rate;
28466 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28467 + rate /= 2;
28468 + *pos++ = (u8) (rate / 5);
28469 + }
28470 + }
28471 +
28472 + if (ifsta->extra_ie) {
28473 + pos = skb_put(skb, ifsta->extra_ie_len);
28474 + memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
28475 + }
28476 +
28477 + if (wmm && ifsta->wmm_enabled) {
28478 + pos = skb_put(skb, 9);
28479 + *pos++ = WLAN_EID_VENDOR_SPECIFIC;
28480 + *pos++ = 7; /* len */
28481 + *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
28482 + *pos++ = 0x50;
28483 + *pos++ = 0xf2;
28484 + *pos++ = 2; /* WME */
28485 + *pos++ = 0; /* WME info */
28486 + *pos++ = 1; /* WME ver */
28487 + *pos++ = 0;
28488 + }
28489 +
28490 + kfree(ifsta->assocreq_ies);
28491 + ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
28492 + ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_ATOMIC);
28493 + if (ifsta->assocreq_ies)
28494 + memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
28495 +
28496 + ieee80211_sta_tx(dev, skb, 0, 0);
28497 +}
28498 +
28499 +
28500 +static void ieee80211_send_deauth(struct net_device *dev,
28501 + struct ieee80211_if_sta *ifsta, u16 reason)
28502 +{
28503 + struct sk_buff *skb;
28504 + struct ieee80211_mgmt *mgmt;
28505 +
28506 + skb = dev_alloc_skb(sizeof(*mgmt));
28507 + if (skb == NULL) {
28508 + printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
28509 + "frame\n", dev->name);
28510 + return;
28511 + }
28512 +
28513 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28514 + memset(mgmt, 0, 24);
28515 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28516 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28517 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28518 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28519 + WLAN_FC_STYPE_DEAUTH);
28520 + skb_put(skb, 2);
28521 + mgmt->u.deauth.reason_code = cpu_to_le16(reason);
28522 +
28523 + ieee80211_sta_tx(dev, skb, 0, 0);
28524 +}
28525 +
28526 +
28527 +static void ieee80211_send_disassoc(struct net_device *dev,
28528 + struct ieee80211_if_sta *ifsta, u16 reason)
28529 +{
28530 + struct sk_buff *skb;
28531 + struct ieee80211_mgmt *mgmt;
28532 +
28533 + skb = dev_alloc_skb(sizeof(*mgmt));
28534 + if (skb == NULL) {
28535 + printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
28536 + "frame\n", dev->name);
28537 + return;
28538 + }
28539 +
28540 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28541 + memset(mgmt, 0, 24);
28542 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28543 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28544 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28545 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28546 + WLAN_FC_STYPE_DISASSOC);
28547 + skb_put(skb, 2);
28548 + mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
28549 +
28550 + ieee80211_sta_tx(dev, skb, 0, 0);
28551 +}
28552 +
28553 +
28554 +static int ieee80211_privacy_mismatch(struct net_device *dev,
28555 + struct ieee80211_if_sta *ifsta)
28556 +{
28557 + struct ieee80211_sta_bss *bss;
28558 + int res = 0;
28559 +
28560 + if (ifsta == NULL || ifsta->mixed_cell ||
28561 + ifsta->key_mgmt != IEEE80211_KEY_MGMT_NONE)
28562 + return 0;
28563 +
28564 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28565 + if (bss == NULL)
28566 + return 0;
28567 +
28568 + if (ieee80211_sta_wep_configured(dev) !=
28569 + !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
28570 + res = 1;
28571 +
28572 + ieee80211_rx_bss_put(dev, bss);
28573 +
28574 + return res;
28575 +}
28576 +
28577 +
28578 +static void ieee80211_associate(struct net_device *dev,
28579 + struct ieee80211_if_sta *ifsta)
28580 +{
28581 + ifsta->assoc_tries++;
28582 + if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
28583 + printk(KERN_DEBUG "%s: association with AP " MACSTR
28584 + " timed out\n",
28585 + dev->name, MAC2STR(ifsta->bssid));
28586 + return;
28587 + }
28588 +
28589 + ifsta->state = IEEE80211_ASSOCIATE;
28590 + printk(KERN_DEBUG "%s: associate with AP " MACSTR "\n",
28591 + dev->name, MAC2STR(ifsta->bssid));
28592 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
28593 + printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
28594 + "mixed-cell disabled - abort association\n", dev->name);
28595 + return;
28596 + }
28597 +
28598 + ieee80211_send_assoc(dev, ifsta);
28599 +
28600 + mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
28601 +}
28602 +
28603 +
28604 +static void ieee80211_associated(struct net_device *dev,
28605 + struct ieee80211_if_sta *ifsta)
28606 +{
28607 + struct ieee80211_local *local = dev->priv;
28608 + struct sta_info *sta;
28609 + int disassoc;
28610 +
28611 + /* TODO: start monitoring current AP signal quality and number of
28612 + * missed beacons. Scan other channels every now and then and search
28613 + * for better APs. */
28614 + /* TODO: remove expired BSSes */
28615 +
28616 + ifsta->state = IEEE80211_ASSOCIATED;
28617 +
28618 + sta = sta_info_get(local, ifsta->bssid);
28619 + if (sta == NULL) {
28620 + printk(KERN_DEBUG "%s: No STA entry for own AP " MACSTR "\n",
28621 + dev->name, MAC2STR(ifsta->bssid));
28622 + disassoc = 1;
28623 + } else {
28624 + disassoc = 0;
28625 + if (time_after(jiffies,
28626 + sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
28627 + if (ifsta->probereq_poll) {
28628 + printk(KERN_DEBUG "%s: No ProbeResp from "
28629 + "current AP " MACSTR " - assume out of "
28630 + "range\n",
28631 + dev->name, MAC2STR(ifsta->bssid));
28632 + disassoc = 1;
28633 + } else {
28634 + ieee80211_send_probe_req(dev, ifsta->bssid,
28635 + local->scan_ssid,
28636 + local->scan_ssid_len);
28637 + ifsta->probereq_poll = 1;
28638 + }
28639 + } else {
28640 + ifsta->probereq_poll = 0;
28641 + if (time_after(jiffies, ifsta->last_probe +
28642 + IEEE80211_PROBE_INTERVAL)) {
28643 + ifsta->last_probe = jiffies;
28644 + ieee80211_send_probe_req(dev, ifsta->bssid,
28645 + ifsta->ssid,
28646 + ifsta->ssid_len);
28647 + }
28648 + }
28649 + sta_info_release(local, sta);
28650 + }
28651 + if (disassoc) {
28652 + union iwreq_data wrqu;
28653 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28654 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28655 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28656 + mod_timer(&ifsta->timer,
28657 + jiffies + IEEE80211_MONITORING_INTERVAL + 30 * HZ);
28658 + } else {
28659 + mod_timer(&ifsta->timer,
28660 + jiffies + IEEE80211_MONITORING_INTERVAL);
28661 + }
28662 +}
28663 +
28664 +
28665 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
28666 + u8 *ssid, size_t ssid_len)
28667 +{
28668 + struct ieee80211_local *local = dev->priv;
28669 + struct sk_buff *skb;
28670 + struct ieee80211_mgmt *mgmt;
28671 + u8 *pos, *supp_rates, *esupp_rates = NULL;
28672 + int i;
28673 +
28674 + skb = dev_alloc_skb(sizeof(*mgmt) + 200);
28675 + if (skb == NULL) {
28676 + printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
28677 + "request\n", dev->name);
28678 + return;
28679 + }
28680 +
28681 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28682 + memset(mgmt, 0, 24);
28683 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28684 + WLAN_FC_STYPE_PROBE_REQ);
28685 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28686 + if (dst) {
28687 + memcpy(mgmt->da, dst, ETH_ALEN);
28688 + memcpy(mgmt->bssid, dst, ETH_ALEN);
28689 + } else {
28690 + memset(mgmt->da, 0xff, ETH_ALEN);
28691 + memset(mgmt->bssid, 0xff, ETH_ALEN);
28692 + }
28693 + pos = skb_put(skb, 2 + ssid_len);
28694 + *pos++ = WLAN_EID_SSID;
28695 + *pos++ = ssid_len;
28696 + memcpy(pos, ssid, ssid_len);
28697 +
28698 + supp_rates = skb_put(skb, 2);
28699 + supp_rates[0] = WLAN_EID_SUPP_RATES;
28700 + supp_rates[1] = 0;
28701 + for (i = 0; i < local->num_curr_rates; i++) {
28702 + struct ieee80211_rate *rate = &local->curr_rates[i];
28703 + if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
28704 + continue;
28705 + if (esupp_rates) {
28706 + pos = skb_put(skb, 1);
28707 + esupp_rates[1]++;
28708 + } else if (supp_rates[1] == 8) {
28709 + esupp_rates = skb_put(skb, 3);
28710 + esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
28711 + esupp_rates[1] = 1;
28712 + pos = &esupp_rates[2];
28713 + } else {
28714 + pos = skb_put(skb, 1);
28715 + supp_rates[1]++;
28716 + }
28717 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28718 + *pos = rate->rate / 10;
28719 + else
28720 + *pos = rate->rate / 5;
28721 + }
28722 +
28723 + ieee80211_sta_tx(dev, skb, 0, 0);
28724 +}
28725 +
28726 +
28727 +static int ieee80211_sta_wep_configured(struct net_device *dev)
28728 +{
28729 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28730 + if (sdata == NULL || sdata->default_key == NULL ||
28731 + sdata->default_key->alg != ALG_WEP)
28732 + return 0;
28733 + return 1;
28734 +}
28735 +
28736 +
28737 +static void ieee80211_auth_completed(struct net_device *dev,
28738 + struct ieee80211_if_sta *ifsta)
28739 +{
28740 + printk(KERN_DEBUG "%s: authenticated\n", dev->name);
28741 + ifsta->authenticated = 1;
28742 + ieee80211_associate(dev, ifsta);
28743 +}
28744 +
28745 +
28746 +static void ieee80211_auth_challenge(struct net_device *dev,
28747 + struct ieee80211_if_sta *ifsta,
28748 + struct ieee80211_mgmt *mgmt,
28749 + size_t len,
28750 + struct ieee80211_rx_status *rx_status)
28751 +{
28752 + u8 *pos;
28753 + struct ieee802_11_elems elems;
28754 +
28755 + printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
28756 + pos = mgmt->u.auth.variable;
28757 + if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems)
28758 + == ParseFailed) {
28759 + printk(KERN_DEBUG "%s: failed to parse Auth(challenge)\n",
28760 + dev->name);
28761 + return;
28762 + }
28763 + if (elems.challenge == NULL) {
28764 + printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
28765 + "frame\n", dev->name);
28766 + return;
28767 + }
28768 + ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
28769 + elems.challenge_len + 2, 1);
28770 +}
28771 +
28772 +
28773 +static void ieee80211_rx_mgmt_auth(struct net_device *dev,
28774 + struct ieee80211_if_sta *ifsta,
28775 + struct ieee80211_mgmt *mgmt,
28776 + size_t len,
28777 + struct ieee80211_rx_status *rx_status)
28778 +{
28779 + struct ieee80211_local *local = dev->priv;
28780 + u16 auth_alg, auth_transaction, status_code;
28781 +
28782 + if (ifsta->state != IEEE80211_AUTHENTICATE &&
28783 + local->conf.mode != IW_MODE_ADHOC) {
28784 + printk(KERN_DEBUG "%s: authentication frame received from "
28785 + MACSTR ", but not in authenticate state - ignored\n",
28786 + dev->name, MAC2STR(mgmt->sa));
28787 + return;
28788 + }
28789 +
28790 + if (len < 24 + 6) {
28791 + printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
28792 + "received from " MACSTR " - ignored\n",
28793 + dev->name, len, MAC2STR(mgmt->sa));
28794 + return;
28795 + }
28796 +
28797 + if (local->conf.mode != IW_MODE_ADHOC &&
28798 + memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
28799 + printk(KERN_DEBUG "%s: authentication frame received from "
28800 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
28801 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28802 + MAC2STR(mgmt->bssid));
28803 + return;
28804 + }
28805 +
28806 + if (local->conf.mode == IW_MODE_ADHOC &&
28807 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
28808 + printk(KERN_DEBUG "%s: authentication frame received from "
28809 + "unknown BSSID (SA=" MACSTR " BSSID=" MACSTR ") - "
28810 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28811 + MAC2STR(mgmt->bssid));
28812 + return;
28813 + }
28814 +
28815 + auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
28816 + auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
28817 + status_code = le16_to_cpu(mgmt->u.auth.status_code);
28818 +
28819 + printk(KERN_DEBUG "%s: RX authentication from " MACSTR " (alg=%d "
28820 + "transaction=%d status=%d)\n",
28821 + dev->name, MAC2STR(mgmt->sa), auth_alg,
28822 + auth_transaction, status_code);
28823 +
28824 + if (local->conf.mode == IW_MODE_ADHOC) {
28825 + /* IEEE 802.11 standard does not require authentication in IBSS
28826 + * networks and most implementations do not seem to use it.
28827 + * However, try to reply to authentication attempts if someone
28828 + * has actually implemented this.
28829 + * TODO: Could implement shared key authentication. */
28830 + if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
28831 + printk(KERN_DEBUG "%s: unexpected IBSS authentication "
28832 + "frame (alg=%d transaction=%d)\n",
28833 + dev->name, auth_alg, auth_transaction);
28834 + return;
28835 + }
28836 + ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
28837 + }
28838 +
28839 + if (auth_alg != ifsta->auth_alg ||
28840 + auth_transaction != ifsta->auth_transaction) {
28841 + printk(KERN_DEBUG "%s: unexpected authentication frame "
28842 + "(alg=%d transaction=%d)\n",
28843 + dev->name, auth_alg, auth_transaction);
28844 + return;
28845 + }
28846 +
28847 + if (status_code != WLAN_STATUS_SUCCESS) {
28848 + printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
28849 + "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
28850 + if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
28851 + const int num_algs = 3;
28852 + u8 algs[num_algs];
28853 + int i, pos;
28854 + algs[0] = algs[1] = algs[2] = 0xff;
28855 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
28856 + algs[0] = WLAN_AUTH_OPEN;
28857 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
28858 + algs[1] = WLAN_AUTH_SHARED_KEY;
28859 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
28860 + algs[2] = WLAN_AUTH_LEAP;
28861 + if (ifsta->auth_alg == WLAN_AUTH_OPEN)
28862 + pos = 0;
28863 + else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
28864 + pos = 1;
28865 + else
28866 + pos = 2;
28867 + for (i = 0; i < num_algs; i++) {
28868 + pos++;
28869 + if (pos >= num_algs)
28870 + pos = 0;
28871 + if (algs[pos] == ifsta->auth_alg ||
28872 + algs[pos] == 0xff)
28873 + continue;
28874 + if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
28875 + !ieee80211_sta_wep_configured(dev))
28876 + continue;
28877 + ifsta->auth_alg = algs[pos];
28878 + printk(KERN_DEBUG "%s: set auth_alg=%d for "
28879 + "next try\n",
28880 + dev->name, ifsta->auth_alg);
28881 + break;
28882 + }
28883 + }
28884 + return;
28885 + }
28886 +
28887 + switch (ifsta->auth_alg) {
28888 + case WLAN_AUTH_OPEN:
28889 + case WLAN_AUTH_LEAP:
28890 + ieee80211_auth_completed(dev, ifsta);
28891 + break;
28892 + case WLAN_AUTH_SHARED_KEY:
28893 + if (ifsta->auth_transaction == 4)
28894 + ieee80211_auth_completed(dev, ifsta);
28895 + else
28896 + ieee80211_auth_challenge(dev, ifsta, mgmt, len,
28897 + rx_status);
28898 + break;
28899 + }
28900 +}
28901 +
28902 +
28903 +static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
28904 + struct ieee80211_if_sta *ifsta,
28905 + struct ieee80211_mgmt *mgmt,
28906 + size_t len,
28907 + struct ieee80211_rx_status *rx_status)
28908 +{
28909 + u16 reason_code;
28910 +
28911 + if (len < 24 + 2) {
28912 + printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
28913 + "received from " MACSTR " - ignored\n",
28914 + dev->name, len, MAC2STR(mgmt->sa));
28915 + return;
28916 + }
28917 +
28918 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
28919 + printk(KERN_DEBUG "%s: deauthentication frame received from "
28920 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
28921 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28922 + MAC2STR(mgmt->bssid));
28923 + return;
28924 + }
28925 +
28926 + reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
28927 +
28928 + printk(KERN_DEBUG "%s: RX deauthentication from " MACSTR
28929 + " (reason=%d)\n",
28930 + dev->name, MAC2STR(mgmt->sa), reason_code);
28931 +
28932 + if (ifsta->authenticated) {
28933 + printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
28934 + }
28935 +
28936 + if (ifsta->state == IEEE80211_AUTHENTICATE ||
28937 + ifsta->state == IEEE80211_ASSOCIATE ||
28938 + ifsta->state == IEEE80211_ASSOCIATED) {
28939 + ifsta->state = IEEE80211_AUTHENTICATE;
28940 + mod_timer(&ifsta->timer,
28941 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
28942 + }
28943 +
28944 + ieee80211_set_associated(dev, ifsta, 0);
28945 + ifsta->authenticated = 0;
28946 +}
28947 +
28948 +
28949 +static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
28950 + struct ieee80211_if_sta *ifsta,
28951 + struct ieee80211_mgmt *mgmt,
28952 + size_t len,
28953 + struct ieee80211_rx_status *rx_status)
28954 +{
28955 + u16 reason_code;
28956 +
28957 + if (len < 24 + 2) {
28958 + printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
28959 + "received from " MACSTR " - ignored\n",
28960 + dev->name, len, MAC2STR(mgmt->sa));
28961 + return;
28962 + }
28963 +
28964 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
28965 + printk(KERN_DEBUG "%s: disassociation frame received from "
28966 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
28967 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28968 + MAC2STR(mgmt->bssid));
28969 + return;
28970 + }
28971 +
28972 + reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
28973 +
28974 + printk(KERN_DEBUG "%s: RX disassociation from " MACSTR
28975 + " (reason=%d)\n",
28976 + dev->name, MAC2STR(mgmt->sa), reason_code);
28977 +
28978 + if (ifsta->associated)
28979 + printk(KERN_DEBUG "%s: disassociated\n", dev->name);
28980 +
28981 + if (ifsta->state == IEEE80211_ASSOCIATED) {
28982 + ifsta->state = IEEE80211_ASSOCIATE;
28983 + mod_timer(&ifsta->timer,
28984 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
28985 + }
28986 +
28987 + ieee80211_set_associated(dev, ifsta, 0);
28988 +}
28989 +
28990 +
28991 +static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
28992 + struct ieee80211_if_sta *ifsta,
28993 + struct ieee80211_mgmt *mgmt,
28994 + size_t len,
28995 + struct ieee80211_rx_status *rx_status,
28996 + int reassoc)
28997 +{
28998 + struct ieee80211_local *local = dev->priv;
28999 + struct sta_info *sta;
29000 + u32 rates;
29001 + u16 capab_info, status_code, aid;
29002 + struct ieee802_11_elems elems;
29003 + u8 *pos;
29004 + int i, j;
29005 +
29006 + /* AssocResp and ReassocResp have identical structure, so process both
29007 + * of them in this function. */
29008 +
29009 + if (ifsta->state != IEEE80211_ASSOCIATE) {
29010 + printk(KERN_DEBUG "%s: association frame received from "
29011 + MACSTR ", but not in associate state - ignored\n",
29012 + dev->name, MAC2STR(mgmt->sa));
29013 + return;
29014 + }
29015 +
29016 + if (len < 24 + 6) {
29017 + printk(KERN_DEBUG "%s: too short (%zd) association frame "
29018 + "received from " MACSTR " - ignored\n",
29019 + dev->name, len, MAC2STR(mgmt->sa));
29020 + return;
29021 + }
29022 +
29023 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
29024 + printk(KERN_DEBUG "%s: association frame received from "
29025 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
29026 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
29027 + MAC2STR(mgmt->bssid));
29028 + return;
29029 + }
29030 +
29031 + capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
29032 + status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
29033 + aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
29034 + if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
29035 + printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
29036 + "set\n", dev->name, aid);
29037 + aid &= ~(BIT(15) | BIT(14));
29038 +
29039 + printk(KERN_DEBUG "%s: RX %sssocResp from " MACSTR " (capab=0x%x "
29040 + "status=%d aid=%d)\n",
29041 + dev->name, reassoc ? "Rea" : "A", MAC2STR(mgmt->sa),
29042 + capab_info, status_code, aid);
29043 +
29044 + if (status_code != WLAN_STATUS_SUCCESS) {
29045 + printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
29046 + dev->name, status_code);
29047 + return;
29048 + }
29049 +
29050 + pos = mgmt->u.assoc_resp.variable;
29051 + if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems)
29052 + == ParseFailed) {
29053 + printk(KERN_DEBUG "%s: failed to parse AssocResp\n",
29054 + dev->name);
29055 + return;
29056 + }
29057 +
29058 + if (elems.supp_rates == NULL) {
29059 + printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
29060 + dev->name);
29061 + return;
29062 + }
29063 +
29064 + printk(KERN_DEBUG "%s: associated\n", dev->name);
29065 + ifsta->aid = aid;
29066 + ifsta->ap_capab = capab_info;
29067 +
29068 + kfree(ifsta->assocresp_ies);
29069 + ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
29070 + ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_ATOMIC);
29071 + if (ifsta->assocresp_ies)
29072 + memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
29073 +
29074 + ieee80211_set_associated(dev, ifsta, 1);
29075 +
29076 + /* Add STA entry for the AP */
29077 + sta = sta_info_get(local, ifsta->bssid);
29078 + if (sta == NULL) {
29079 + sta = sta_info_add(local, dev, ifsta->bssid);
29080 + if (sta == NULL) {
29081 + printk(KERN_DEBUG "%s: failed to add STA entry for the"
29082 + " AP\n", dev->name);
29083 + return;
29084 + }
29085 + }
29086 +
29087 + sta->dev = dev;
29088 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
29089 + sta->assoc_ap = 1;
29090 +
29091 + rates = 0;
29092 + for (i = 0; i < elems.supp_rates_len; i++) {
29093 + int rate = (elems.supp_rates[i] & 0x7f) * 5;
29094 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
29095 + rate *= 2;
29096 + for (j = 0; j < local->num_curr_rates; j++)
29097 + if (local->curr_rates[j].rate == rate)
29098 + rates |= BIT(j);
29099 + }
29100 + for (i = 0; i < elems.ext_supp_rates_len; i++) {
29101 + int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
29102 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
29103 + rate *= 2;
29104 + for (j = 0; j < local->num_curr_rates; j++)
29105 + if (local->curr_rates[j].rate == rate)
29106 + rates |= BIT(j);
29107 + }
29108 + sta->supp_rates = rates;
29109 +
29110 + rate_control_rate_init(local, sta);
29111 +
29112 + if (elems.wmm_param && ifsta->wmm_enabled) {
29113 + sta->flags |= WLAN_STA_WME;
29114 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29115 + elems.wmm_param_len);
29116 + }
29117 +
29118 +
29119 + sta_info_release(local, sta);
29120 +
29121 + ieee80211_associated(dev, ifsta);
29122 +}
29123 +
29124 +
29125 +/* Caller must hold local->sta_bss_lock */
29126 +static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
29127 + struct ieee80211_sta_bss *bss)
29128 +{
29129 + struct ieee80211_local *local = dev->priv;
29130 + bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
29131 + local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
29132 +}
29133 +
29134 +
29135 +/* Caller must hold local->sta_bss_lock */
29136 +static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
29137 + struct ieee80211_sta_bss *bss)
29138 +{
29139 + struct ieee80211_local *local = dev->priv;
29140 + struct ieee80211_sta_bss *b, *prev = NULL;
29141 + b = local->sta_bss_hash[STA_HASH(bss->bssid)];
29142 + while (b) {
29143 + if (b == bss) {
29144 + if (prev == NULL) {
29145 + local->sta_bss_hash[STA_HASH(bss->bssid)] =
29146 + bss->hnext;
29147 + } else {
29148 + prev->hnext = bss->hnext;
29149 + }
29150 + break;
29151 + }
29152 + prev = b;
29153 + b = b->hnext;
29154 + }
29155 +}
29156 +
29157 +
29158 +static struct ieee80211_sta_bss *
29159 +ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid)
29160 +{
29161 + struct ieee80211_local *local = dev->priv;
29162 + struct ieee80211_sta_bss *bss;
29163 +
29164 + bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
29165 + if (bss == NULL)
29166 + return NULL;
29167 + memset(bss, 0, sizeof(*bss));
29168 + atomic_inc(&bss->users);
29169 + atomic_inc(&bss->users);
29170 + memcpy(bss->bssid, bssid, ETH_ALEN);
29171 +
29172 + spin_lock_bh(&local->sta_bss_lock);
29173 + /* TODO: order by RSSI? */
29174 + list_add_tail(&bss->list, &local->sta_bss_list);
29175 + __ieee80211_rx_bss_hash_add(dev, bss);
29176 + spin_unlock_bh(&local->sta_bss_lock);
29177 + return bss;
29178 +}
29179 +
29180 +
29181 +static struct ieee80211_sta_bss *
29182 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid)
29183 +{
29184 + struct ieee80211_local *local = dev->priv;
29185 + struct ieee80211_sta_bss *bss;
29186 +
29187 + spin_lock_bh(&local->sta_bss_lock);
29188 + bss = local->sta_bss_hash[STA_HASH(bssid)];
29189 + while (bss) {
29190 + if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
29191 + atomic_inc(&bss->users);
29192 + break;
29193 + }
29194 + bss = bss->hnext;
29195 + }
29196 + spin_unlock_bh(&local->sta_bss_lock);
29197 + return bss;
29198 +}
29199 +
29200 +
29201 +static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
29202 +{
29203 + kfree(bss->wpa_ie);
29204 + kfree(bss->rsn_ie);
29205 + kfree(bss->wmm_ie);
29206 + kfree(bss);
29207 +}
29208 +
29209 +
29210 +static void ieee80211_rx_bss_put(struct net_device *dev,
29211 + struct ieee80211_sta_bss *bss)
29212 +{
29213 + struct ieee80211_local *local = dev->priv;
29214 + if (!atomic_dec_and_test(&bss->users))
29215 + return;
29216 +
29217 + spin_lock_bh(&local->sta_bss_lock);
29218 + __ieee80211_rx_bss_hash_del(dev, bss);
29219 + list_del(&bss->list);
29220 + spin_unlock_bh(&local->sta_bss_lock);
29221 + ieee80211_rx_bss_free(bss);
29222 +}
29223 +
29224 +
29225 +void ieee80211_rx_bss_list_init(struct net_device *dev)
29226 +{
29227 + struct ieee80211_local *local = dev->priv;
29228 + spin_lock_init(&local->sta_bss_lock);
29229 + INIT_LIST_HEAD(&local->sta_bss_list);
29230 +}
29231 +
29232 +
29233 +void ieee80211_rx_bss_list_deinit(struct net_device *dev)
29234 +{
29235 + struct ieee80211_local *local = dev->priv;
29236 + struct ieee80211_sta_bss *bss;
29237 + struct list_head *ptr;
29238 +
29239 + for (;;) {
29240 + ptr = local->sta_bss_list.next;
29241 + if (!ptr || ptr == &local->sta_bss_list)
29242 + break;
29243 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
29244 + ieee80211_rx_bss_put(dev, bss);
29245 + }
29246 +}
29247 +
29248 +
29249 +static void ieee80211_rx_bss_info(struct net_device *dev,
29250 + struct ieee80211_mgmt *mgmt,
29251 + size_t len,
29252 + struct ieee80211_rx_status *rx_status,
29253 + int beacon)
29254 +{
29255 + struct ieee80211_local *local = dev->priv;
29256 + struct ieee802_11_elems elems;
29257 + size_t baselen;
29258 + int channel, invalid = 0, clen;
29259 + struct ieee80211_sta_bss *bss;
29260 + struct sta_info *sta;
29261 + struct ieee80211_sub_if_data *sdata;
29262 + u64 timestamp;
29263 + u8 *pos;
29264 +
29265 + if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
29266 + return; /* ignore ProbeResp to foreign address */
29267 +
29268 +#if 0
29269 + printk(KERN_DEBUG "%s: RX %s from " MACSTR " to " MACSTR "\n",
29270 + dev->name, beacon ? "Beacon" : "Probe Response",
29271 + MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
29272 +#endif
29273 +
29274 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29275 + if (baselen > len)
29276 + return;
29277 +
29278 + pos = mgmt->u.beacon.timestamp;
29279 + timestamp = ((u64) pos[7] << 56) | ((u64) pos[6] << 48) |
29280 + ((u64) pos[5] << 40) | ((u64) pos[4] << 32) |
29281 + ((u64) pos[3] << 24) | ((u64) pos[2] << 16) |
29282 + ((u64) pos[1] << 8) | ((u64) pos[0]);
29283 +
29284 + if (local->conf.mode == IW_MODE_ADHOC && beacon &&
29285 + memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0) {
29286 +#ifdef IEEE80211_IBSS_DEBUG
29287 + static unsigned long last_tsf_debug = 0;
29288 + u64 tsf;
29289 + if (local->hw->get_tsf)
29290 + tsf = local->hw->get_tsf(local->mdev);
29291 + else
29292 + tsf = -1LLU;
29293 + if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
29294 + printk(KERN_DEBUG "RX beacon SA=" MACSTR " BSSID="
29295 + MACSTR " TSF=0x%llx BCN=0x%llx diff=%lld "
29296 + "@%ld\n",
29297 + MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
29298 + tsf, timestamp, tsf - timestamp, jiffies);
29299 + last_tsf_debug = jiffies;
29300 + }
29301 +#endif /* IEEE80211_IBSS_DEBUG */
29302 + }
29303 +
29304 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29305 + &elems) == ParseFailed)
29306 + invalid = 1;
29307 +
29308 + if (local->conf.mode == IW_MODE_ADHOC && elems.supp_rates &&
29309 + memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0 &&
29310 + (sta = sta_info_get(local, mgmt->sa)) &&
29311 + (sdata = IEEE80211_DEV_TO_SUB_IF(dev)) &&
29312 + sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
29313 + struct ieee80211_rate *rates;
29314 + size_t num_rates;
29315 + u32 supp_rates, prev_rates;
29316 + int i, j, oper_mode;
29317 +
29318 + rates = local->curr_rates;
29319 + num_rates = local->num_curr_rates;
29320 + oper_mode = local->sta_scanning ? local->scan_oper_phymode :
29321 + local->conf.phymode;
29322 + for (i = 0; i < local->hw->num_modes; i++) {
29323 + struct ieee80211_hw_modes *mode = &local->hw->modes[i];
29324 + if (oper_mode == mode->mode) {
29325 + rates = mode->rates;
29326 + num_rates = mode->num_rates;
29327 + break;
29328 + }
29329 + }
29330 +
29331 + supp_rates = 0;
29332 + for (i = 0; i < elems.supp_rates_len +
29333 + elems.ext_supp_rates_len; i++) {
29334 + u8 rate = 0;
29335 + int own_rate;
29336 + if (i < elems.supp_rates_len)
29337 + rate = elems.supp_rates[i];
29338 + else if (elems.ext_supp_rates)
29339 + rate = elems.ext_supp_rates
29340 + [i - elems.supp_rates_len];
29341 + own_rate = 5 * (rate & 0x7f);
29342 + if (oper_mode == MODE_ATHEROS_TURBO)
29343 + own_rate *= 2;
29344 + for (j = 0; j < num_rates; j++)
29345 + if (rates[j].rate == own_rate)
29346 + supp_rates |= BIT(j);
29347 + }
29348 +
29349 + prev_rates = sta->supp_rates;
29350 + sta->supp_rates &= supp_rates;
29351 + if (sta->supp_rates == 0) {
29352 + /* No matching rates - this should not really happen.
29353 + * Make sure that at least one rate is marked
29354 + * supported to avoid issues with TX rate ctrl. */
29355 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
29356 + }
29357 + if (sta->supp_rates != prev_rates) {
29358 + printk(KERN_DEBUG "%s: updated supp_rates set for "
29359 + MACSTR " based on beacon info (0x%x & 0x%x -> "
29360 + "0x%x)\n",
29361 + dev->name, MAC2STR(sta->addr), prev_rates,
29362 + supp_rates, sta->supp_rates);
29363 + }
29364 + sta_info_release(local, sta);
29365 + }
29366 +
29367 + if (elems.ssid == NULL)
29368 + return;
29369 +
29370 + if (elems.ds_params && elems.ds_params_len == 1)
29371 + channel = elems.ds_params[0];
29372 + else
29373 + channel = rx_status->channel;
29374 +
29375 + bss = ieee80211_rx_bss_get(dev, mgmt->bssid);
29376 + if (bss == NULL) {
29377 + bss = ieee80211_rx_bss_add(dev, mgmt->bssid);
29378 + if (bss == NULL)
29379 + return;
29380 + } else {
29381 +#if 0
29382 + /* TODO: order by RSSI? */
29383 + spin_lock_bh(&local->sta_bss_lock);
29384 + list_move_tail(&bss->list, &local->sta_bss_list);
29385 + spin_unlock_bh(&local->sta_bss_lock);
29386 +#endif
29387 + }
29388 +
29389 + if (bss->probe_resp && beacon) {
29390 + /* Do not allow beacon to override data from Probe Response. */
29391 + ieee80211_rx_bss_put(dev, bss);
29392 + return;
29393 + }
29394 +
29395 + bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
29396 + bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
29397 + if (elems.ssid && elems.ssid_len <= IEEE80211_MAX_SSID_LEN) {
29398 + memcpy(bss->ssid, elems.ssid, elems.ssid_len);
29399 + bss->ssid_len = elems.ssid_len;
29400 + }
29401 +
29402 + bss->supp_rates_len = 0;
29403 + if (elems.supp_rates) {
29404 + clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
29405 + if (clen > elems.supp_rates_len)
29406 + clen = elems.supp_rates_len;
29407 + memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
29408 + clen);
29409 + bss->supp_rates_len += clen;
29410 + }
29411 + if (elems.ext_supp_rates) {
29412 + clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
29413 + if (clen > elems.ext_supp_rates_len)
29414 + clen = elems.ext_supp_rates_len;
29415 + memcpy(&bss->supp_rates[bss->supp_rates_len],
29416 + elems.ext_supp_rates, clen);
29417 + bss->supp_rates_len += clen;
29418 + }
29419 +
29420 + if (elems.wpa &&
29421 + (bss->wpa_ie == NULL || bss->wpa_ie_len != elems.wpa_len ||
29422 + memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
29423 + kfree(bss->wpa_ie);
29424 + bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
29425 + if (bss->wpa_ie) {
29426 + memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
29427 + bss->wpa_ie_len = elems.wpa_len + 2;
29428 + } else
29429 + bss->wpa_ie_len = 0;
29430 + } else if (!elems.wpa && bss->wpa_ie) {
29431 + kfree(bss->wpa_ie);
29432 + bss->wpa_ie = NULL;
29433 + bss->wpa_ie_len = 0;
29434 + }
29435 +
29436 + if (elems.rsn &&
29437 + (bss->rsn_ie == NULL || bss->rsn_ie_len != elems.rsn_len ||
29438 + memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
29439 + kfree(bss->rsn_ie);
29440 + bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
29441 + if (bss->rsn_ie) {
29442 + memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
29443 + bss->rsn_ie_len = elems.rsn_len + 2;
29444 + } else
29445 + bss->rsn_ie_len = 0;
29446 + } else if (!elems.rsn && bss->rsn_ie) {
29447 + kfree(bss->rsn_ie);
29448 + bss->rsn_ie = NULL;
29449 + bss->rsn_ie_len = 0;
29450 + }
29451 +
29452 + if (elems.wmm_param &&
29453 + (bss->wmm_ie == NULL || bss->wmm_ie_len != elems.wmm_param_len ||
29454 + memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
29455 + kfree(bss->wmm_ie);
29456 + bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
29457 + if (bss->wmm_ie) {
29458 + memcpy(bss->wmm_ie, elems.wmm_param - 2,
29459 + elems.wmm_param_len + 2);
29460 + bss->wmm_ie_len = elems.wmm_param_len + 2;
29461 + } else
29462 + bss->wmm_ie_len = 0;
29463 + } else if (!elems.wmm_param && bss->wmm_ie) {
29464 + kfree(bss->wmm_ie);
29465 + bss->wmm_ie = NULL;
29466 + bss->wmm_ie_len = 0;
29467 + }
29468 +
29469 +
29470 + bss->hw_mode = local->conf.phymode;
29471 + bss->channel = channel;
29472 + bss->freq = local->conf.freq;
29473 + if (channel != local->conf.channel &&
29474 + (local->conf.phymode == MODE_IEEE80211G ||
29475 + local->conf.phymode == MODE_IEEE80211B) &&
29476 + channel >= 1 && channel <= 14) {
29477 + static const int freq_list[] = {
29478 + 2412, 2417, 2422, 2427, 2432, 2437, 2442,
29479 + 2447, 2452, 2457, 2462, 2467, 2472, 2484
29480 + };
29481 + /* IEEE 802.11g/b mode can receive packets from neighboring
29482 + * channels, so map the channel into frequency. */
29483 + bss->freq = freq_list[channel - 1];
29484 + }
29485 + bss->timestamp = timestamp;
29486 + bss->last_update = jiffies;
29487 + bss->rssi = rx_status->ssi;
29488 + if (!beacon)
29489 + bss->probe_resp++;
29490 + ieee80211_rx_bss_put(dev, bss);
29491 +}
29492 +
29493 +
29494 +static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
29495 + struct ieee80211_mgmt *mgmt,
29496 + size_t len,
29497 + struct ieee80211_rx_status *rx_status)
29498 +{
29499 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
29500 +}
29501 +
29502 +
29503 +static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
29504 + struct ieee80211_mgmt *mgmt,
29505 + size_t len,
29506 + struct ieee80211_rx_status *rx_status)
29507 +{
29508 + struct ieee80211_local *local = dev->priv;
29509 + struct ieee80211_sub_if_data *sdata;
29510 + struct ieee80211_if_sta *ifsta;
29511 + int use_protection;
29512 + size_t baselen;
29513 + struct ieee802_11_elems elems;
29514 +
29515 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
29516 +
29517 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29518 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
29519 + return;
29520 + ifsta = &sdata->u.sta;
29521 +
29522 + if (!ifsta->associated ||
29523 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
29524 + return;
29525 +
29526 + /* Process beacon from the current BSS */
29527 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29528 + if (baselen > len)
29529 + return;
29530 +
29531 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29532 + &elems) == ParseFailed)
29533 + return;
29534 +
29535 + use_protection = 0;
29536 + if (elems.erp_info && elems.erp_info_len >= 1) {
29537 + use_protection =
29538 + (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
29539 + }
29540 +
29541 + if (use_protection != !!ifsta->use_protection) {
29542 + if (net_ratelimit()) {
29543 + printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
29544 + MACSTR ")\n",
29545 + dev->name,
29546 + use_protection ? "enabled" : "disabled",
29547 + MAC2STR(ifsta->bssid));
29548 + }
29549 + ifsta->use_protection = use_protection ? 1 : 0;
29550 + local->cts_protect_erp_frames = use_protection;
29551 + }
29552 +
29553 + if (elems.wmm_param && ifsta->wmm_enabled) {
29554 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29555 + elems.wmm_param_len);
29556 + }
29557 +}
29558 +
29559 +
29560 +static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
29561 + struct ieee80211_if_sta *ifsta,
29562 + struct ieee80211_mgmt *mgmt,
29563 + size_t len,
29564 + struct ieee80211_rx_status *rx_status)
29565 +{
29566 + struct ieee80211_local *local = dev->priv;
29567 + int tx_last_beacon;
29568 + struct sk_buff *skb;
29569 + struct ieee80211_mgmt *resp;
29570 + u8 *pos, *end;
29571 +
29572 + if (local->conf.mode != IW_MODE_ADHOC ||
29573 + ifsta->state != IEEE80211_IBSS_JOINED ||
29574 + len < 24 + 2 || ifsta->probe_resp == NULL)
29575 + return;
29576 +
29577 + if (local->hw->tx_last_beacon)
29578 + tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
29579 + else
29580 + tx_last_beacon = 1;
29581 +
29582 +#ifdef IEEE80211_IBSS_DEBUG
29583 + printk(KERN_DEBUG "%s: RX ProbeReq SA=" MACSTR " DA=" MACSTR " BSSID="
29584 + MACSTR " (tx_last_beacon=%d)\n",
29585 + dev->name, MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
29586 + MAC2STR(mgmt->bssid), tx_last_beacon);
29587 +#endif /* IEEE80211_IBSS_DEBUG */
29588 +
29589 + if (!tx_last_beacon)
29590 + return;
29591 +
29592 + if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
29593 + memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
29594 + return;
29595 +
29596 + end = ((u8 *) mgmt) + len;
29597 + pos = mgmt->u.probe_req.variable;
29598 + if (pos[0] != WLAN_EID_SSID ||
29599 + pos + 2 + pos[1] > end) {
29600 + if (net_ratelimit()) {
29601 + printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
29602 + "from " MACSTR "\n",
29603 + dev->name, MAC2STR(mgmt->sa));
29604 + }
29605 + return;
29606 + }
29607 + if (pos[1] != 0 &&
29608 + (pos[1] != ifsta->ssid_len ||
29609 + memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
29610 + /* Ignore ProbeReq for foreign SSID */
29611 + return;
29612 + }
29613 +
29614 + /* Reply with ProbeResp */
29615 + skb = skb_copy(ifsta->probe_resp, GFP_ATOMIC);
29616 + if (skb == NULL)
29617 + return;
29618 +
29619 + resp = (struct ieee80211_mgmt *) skb->data;
29620 + memcpy(resp->da, mgmt->sa, ETH_ALEN);
29621 +#ifdef IEEE80211_IBSS_DEBUG
29622 + printk(KERN_DEBUG "%s: Sending ProbeResp to " MACSTR "\n",
29623 + dev->name, MAC2STR(resp->da));
29624 +#endif /* IEEE80211_IBSS_DEBUG */
29625 + ieee80211_sta_tx(dev, skb, 0, 1);
29626 +}
29627 +
29628 +
29629 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
29630 + struct ieee80211_rx_status *rx_status)
29631 +{
29632 + struct ieee80211_sub_if_data *sdata;
29633 + struct ieee80211_if_sta *ifsta;
29634 + struct ieee80211_mgmt *mgmt;
29635 + u16 fc;
29636 +
29637 + if (skb->len < 24)
29638 + goto fail;
29639 +
29640 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29641 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
29642 + printk(KERN_DEBUG "%s: ieee80211_sta_rx_mgmt: non-STA "
29643 + "interface (type=%d)\n", dev->name, sdata->type);
29644 + goto fail;
29645 + }
29646 + ifsta = &sdata->u.sta;
29647 +
29648 + mgmt = (struct ieee80211_mgmt *) skb->data;
29649 + fc = le16_to_cpu(mgmt->frame_control);
29650 +
29651 + switch (WLAN_FC_GET_STYPE(fc)) {
29652 + case WLAN_FC_STYPE_PROBE_REQ:
29653 + ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
29654 + rx_status);
29655 + break;
29656 + case WLAN_FC_STYPE_PROBE_RESP:
29657 + ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
29658 + break;
29659 + case WLAN_FC_STYPE_BEACON:
29660 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
29661 + break;
29662 + case WLAN_FC_STYPE_AUTH:
29663 + ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len, rx_status);
29664 + break;
29665 + case WLAN_FC_STYPE_ASSOC_RESP:
29666 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29667 + rx_status, 0);
29668 + break;
29669 + case WLAN_FC_STYPE_REASSOC_RESP:
29670 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29671 + rx_status, 1);
29672 + break;
29673 + case WLAN_FC_STYPE_DEAUTH:
29674 + ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len,
29675 + rx_status);
29676 + break;
29677 + case WLAN_FC_STYPE_DISASSOC:
29678 + ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len,
29679 + rx_status);
29680 + break;
29681 + default:
29682 + printk(KERN_DEBUG "%s: received unknown management frame - "
29683 + "stype=%d\n", dev->name, WLAN_FC_GET_STYPE(fc));
29684 + break;
29685 + }
29686 +
29687 + fail:
29688 + dev_kfree_skb(skb);
29689 +}
29690 +
29691 +
29692 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
29693 + struct ieee80211_rx_status *rx_status)
29694 +{
29695 + struct ieee80211_mgmt *mgmt;
29696 + u16 fc;
29697 +
29698 + if (skb->len < 24) {
29699 + dev_kfree_skb(skb);
29700 + return;
29701 + }
29702 +
29703 + mgmt = (struct ieee80211_mgmt *) skb->data;
29704 + fc = le16_to_cpu(mgmt->frame_control);
29705 +
29706 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT) {
29707 + if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
29708 + ieee80211_rx_mgmt_probe_resp(dev, mgmt,
29709 + skb->len, rx_status);
29710 + } else if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
29711 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
29712 + rx_status);
29713 + }
29714 + }
29715 +
29716 + dev_kfree_skb(skb);
29717 +}
29718 +
29719 +
29720 +static int ieee80211_sta_active_ibss(struct net_device *dev)
29721 +{
29722 + struct ieee80211_local *local = dev->priv;
29723 + struct list_head *ptr;
29724 + int active = 0;
29725 + struct sta_info *sta;
29726 +
29727 + spin_lock_bh(&local->sta_lock);
29728 + list_for_each(ptr, &local->sta_list) {
29729 + sta = list_entry(ptr, struct sta_info, list);
29730 + if (sta->dev == dev &&
29731 + time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
29732 + jiffies)) {
29733 + active++;
29734 + break;
29735 + }
29736 + }
29737 + spin_unlock_bh(&local->sta_lock);
29738 +
29739 + return active;
29740 +}
29741 +
29742 +
29743 +static void ieee80211_sta_expire(struct net_device *dev)
29744 +{
29745 + struct ieee80211_local *local = dev->priv;
29746 + struct list_head *ptr, *n;
29747 + struct sta_info *sta;
29748 +
29749 + spin_lock_bh(&local->sta_lock);
29750 + list_for_each_safe(ptr, n, &local->sta_list) {
29751 + sta = list_entry(ptr, struct sta_info, list);
29752 + if (time_after(jiffies, sta->last_rx +
29753 + IEEE80211_IBSS_INACTIVITY_LIMIT)) {
29754 + printk(KERN_DEBUG "%s: expiring inactive STA " MACSTR
29755 + "\n", dev->name, MAC2STR(sta->addr));
29756 + sta_info_free(local, sta, 1);
29757 + }
29758 + }
29759 + spin_unlock_bh(&local->sta_lock);
29760 +}
29761 +
29762 +
29763 +static void ieee80211_sta_merge_ibss(struct net_device *dev,
29764 + struct ieee80211_if_sta *ifsta)
29765 +{
29766 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
29767 +
29768 + ieee80211_sta_expire(dev);
29769 + if (ieee80211_sta_active_ibss(dev))
29770 + return;
29771 +
29772 + printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
29773 + "IBSS networks with same SSID (merge)\n", dev->name);
29774 + ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
29775 +}
29776 +
29777 +
29778 +void ieee80211_sta_timer(unsigned long ptr)
29779 +{
29780 + struct net_device *dev;
29781 + struct ieee80211_sub_if_data *sdata;
29782 + struct ieee80211_if_sta *ifsta;
29783 +
29784 + dev = (struct net_device *) ptr;
29785 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29786 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
29787 + printk(KERN_DEBUG "%s: ieee80211_sta_timer: non-STA interface "
29788 + "(type=%d)\n", dev->name, sdata->type);
29789 + return;
29790 + }
29791 + ifsta = &sdata->u.sta;
29792 +
29793 + switch (ifsta->state) {
29794 + case IEEE80211_DISABLED:
29795 + break;
29796 + case IEEE80211_AUTHENTICATE:
29797 + ieee80211_authenticate(dev, ifsta);
29798 + break;
29799 + case IEEE80211_ASSOCIATE:
29800 + ieee80211_associate(dev, ifsta);
29801 + break;
29802 + case IEEE80211_ASSOCIATED:
29803 + ieee80211_associated(dev, ifsta);
29804 + break;
29805 + case IEEE80211_IBSS_SEARCH:
29806 + ieee80211_sta_find_ibss(dev, ifsta);
29807 + break;
29808 + case IEEE80211_IBSS_JOINED:
29809 + ieee80211_sta_merge_ibss(dev, ifsta);
29810 + break;
29811 + default:
29812 + printk(KERN_DEBUG "ieee80211_sta_timer: Unknown state %d\n",
29813 + ifsta->state);
29814 + break;
29815 + }
29816 +
29817 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
29818 + printk(KERN_DEBUG "%s: privacy configuration mismatch and "
29819 + "mixed-cell disabled - disassociate\n", dev->name);
29820 +
29821 + ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
29822 + ieee80211_set_associated(dev, ifsta, 0);
29823 + }
29824 +}
29825 +
29826 +
29827 +static void ieee80211_sta_new_auth(struct net_device *dev,
29828 + struct ieee80211_if_sta *ifsta)
29829 +{
29830 + struct ieee80211_local *local = dev->priv;
29831 +
29832 + if (local->conf.mode != IW_MODE_INFRA)
29833 + return;
29834 +
29835 + if (local->hw->reset_tsf) {
29836 + /* Reset own TSF to allow time synchronization work. */
29837 + local->hw->reset_tsf(local->mdev);
29838 + }
29839 +
29840 + ifsta->wmm_last_param_set = -1; /* allow any WMM update */
29841 +
29842 +
29843 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
29844 + ifsta->auth_alg = WLAN_AUTH_OPEN;
29845 + else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
29846 + ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
29847 + else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
29848 + ifsta->auth_alg = WLAN_AUTH_LEAP;
29849 + else
29850 + ifsta->auth_alg = WLAN_AUTH_OPEN;
29851 + printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
29852 + ifsta->auth_alg);
29853 + ifsta->auth_transaction = -1;
29854 + ifsta->auth_tries = ifsta->assoc_tries = 0;
29855 + ieee80211_authenticate(dev, ifsta);
29856 +}
29857 +
29858 +
29859 +static int ieee80211_ibss_allowed(struct ieee80211_local *local)
29860 +{
29861 + int m, c;
29862 +
29863 + for (m = 0; m < local->hw->num_modes; m++) {
29864 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
29865 + if (mode->mode != local->conf.phymode)
29866 + continue;
29867 + for (c = 0; c < mode->num_channels; c++) {
29868 + struct ieee80211_channel *chan = &mode->channels[c];
29869 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
29870 + chan->chan == local->conf.channel) {
29871 + if (chan->flag & IEEE80211_CHAN_W_IBSS)
29872 + return 1;
29873 + break;
29874 + }
29875 + }
29876 + }
29877 +
29878 + return 0;
29879 +}
29880 +
29881 +
29882 +extern int ieee80211_ioctl_siwfreq(struct net_device *dev,
29883 + struct iw_request_info *info,
29884 + struct iw_freq *freq, char *extra);
29885 +
29886 +static int ieee80211_sta_join_ibss(struct net_device *dev,
29887 + struct ieee80211_if_sta *ifsta,
29888 + struct ieee80211_sta_bss *bss)
29889 +{
29890 + struct ieee80211_local *local = dev->priv;
29891 + struct iw_freq rq;
29892 + int res, rates, i, j;
29893 + struct sk_buff *skb;
29894 + struct ieee80211_mgmt *mgmt;
29895 + struct ieee80211_tx_control control;
29896 + struct ieee80211_rate *rate;
29897 + struct rate_control_extra extra;
29898 + u8 *pos;
29899 + struct ieee80211_sub_if_data *sdata;
29900 +
29901 + /* Remove possible STA entries from other IBSS networks. */
29902 + sta_info_flush(local, NULL);
29903 +
29904 + if (local->hw->reset_tsf) {
29905 + /* Reset own TSF to allow time synchronization work. */
29906 + local->hw->reset_tsf(local->mdev);
29907 + }
29908 + memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
29909 + memcpy(local->bssid, bss->bssid, ETH_ALEN);
29910 + memcpy(local->conf.client_bssid, bss->bssid, ETH_ALEN);
29911 +
29912 + local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
29913 +
29914 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29915 + sdata->drop_unencrypted = bss->capability &
29916 + cpu_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
29917 +
29918 + memset(&rq, 0, sizeof(rq));
29919 + rq.m = bss->freq * 100000;
29920 + rq.e = 1;
29921 + res = ieee80211_ioctl_siwfreq(dev, NULL, &rq, NULL);
29922 +
29923 + if (!ieee80211_ibss_allowed(local)) {
29924 + printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
29925 + "(%d MHz)\n", dev->name, local->conf.channel,
29926 + local->conf.freq);
29927 + return -1;
29928 + }
29929 +
29930 + /* Set beacon template based on scan results */
29931 + skb = dev_alloc_skb(400);
29932 + do {
29933 + if (skb == NULL)
29934 + break;
29935 +
29936 + mgmt = (struct ieee80211_mgmt *)
29937 + skb_put(skb, 24 + sizeof(mgmt->u.beacon));
29938 + memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
29939 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
29940 + WLAN_FC_STYPE_BEACON);
29941 + memset(mgmt->da, 0xff, ETH_ALEN);
29942 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
29943 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
29944 + mgmt->u.beacon.beacon_int =
29945 + cpu_to_le16(local->conf.beacon_int);
29946 + mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
29947 +
29948 + pos = skb_put(skb, 2 + ifsta->ssid_len);
29949 + *pos++ = WLAN_EID_SSID;
29950 + *pos++ = ifsta->ssid_len;
29951 + memcpy(pos, ifsta->ssid, ifsta->ssid_len);
29952 +
29953 + rates = bss->supp_rates_len;
29954 + if (rates > 8)
29955 + rates = 8;
29956 + pos = skb_put(skb, 2 + rates);
29957 + *pos++ = WLAN_EID_SUPP_RATES;
29958 + *pos++ = rates;
29959 + memcpy(pos, bss->supp_rates, rates);
29960 +
29961 + pos = skb_put(skb, 2 + 1);
29962 + *pos++ = WLAN_EID_DS_PARAMS;
29963 + *pos++ = 1;
29964 + *pos++ = bss->channel;
29965 +
29966 + pos = skb_put(skb, 2 + 2);
29967 + *pos++ = WLAN_EID_IBSS_PARAMS;
29968 + *pos++ = 2;
29969 + /* FIX: set ATIM window based on scan results */
29970 + *pos++ = 0;
29971 + *pos++ = 0;
29972 +
29973 + if (bss->supp_rates_len > 8) {
29974 + rates = bss->supp_rates_len - 8;
29975 + pos = skb_put(skb, 2 + rates);
29976 + *pos++ = WLAN_EID_EXT_SUPP_RATES;
29977 + *pos++ = rates;
29978 + memcpy(pos, &bss->supp_rates[8], rates);
29979 + }
29980 +
29981 + memset(&control, 0, sizeof(control));
29982 + control.pkt_type = PKT_PROBE_RESP;
29983 + memset(&extra, 0, sizeof(extra));
29984 + extra.endidx = local->num_curr_rates;
29985 + rate = rate_control_get_rate(dev, skb, &extra);
29986 + if (rate == NULL) {
29987 + printk(KERN_DEBUG "%s: Failed to determine TX rate "
29988 + "for IBSS beacon\n", dev->name);
29989 + break;
29990 + }
29991 + control.tx_rate = (local->short_preamble &&
29992 + (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
29993 + rate->val2 : rate->val;
29994 + control.antenna_sel = local->conf.antenna_sel;
29995 + control.power_level = local->conf.power_level;
29996 + control.no_ack = 1;
29997 + control.retry_limit = 1;
29998 + control.rts_cts_duration = 0;
29999 +
30000 + ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
30001 + if (ifsta->probe_resp) {
30002 + mgmt = (struct ieee80211_mgmt *)
30003 + ifsta->probe_resp->data;
30004 + mgmt->frame_control =
30005 + IEEE80211_FC(WLAN_FC_TYPE_MGMT,
30006 + WLAN_FC_STYPE_PROBE_RESP);
30007 + } else {
30008 + printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
30009 + "template for IBSS\n", dev->name);
30010 + }
30011 +
30012 + if (local->hw->beacon_update &&
30013 + local->hw->beacon_update(dev, skb, &control) == 0) {
30014 + printk(KERN_DEBUG "%s: Configured IBSS beacon "
30015 + "template based on scan results\n", dev->name);
30016 + skb = NULL;
30017 + }
30018 +
30019 + rates = 0;
30020 + for (i = 0; i < bss->supp_rates_len; i++) {
30021 + int rate = (bss->supp_rates[i] & 0x7f) * 5;
30022 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
30023 + rate *= 2;
30024 + for (j = 0; j < local->num_curr_rates; j++)
30025 + if (local->curr_rates[j].rate == rate)
30026 + rates |= BIT(j);
30027 + }
30028 + ifsta->supp_rates_bits = rates;
30029 + } while (0);
30030 +
30031 + if (skb) {
30032 + printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
30033 + "template\n", dev->name);
30034 + dev_kfree_skb(skb);
30035 + }
30036 +
30037 + ifsta->state = IEEE80211_IBSS_JOINED;
30038 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30039 +
30040 + ieee80211_rx_bss_put(dev, bss);
30041 +
30042 + return res;
30043 +}
30044 +
30045 +
30046 +static int ieee80211_sta_create_ibss(struct net_device *dev,
30047 + struct ieee80211_if_sta *ifsta)
30048 +{
30049 + struct ieee80211_local *local = dev->priv;
30050 + struct ieee80211_sta_bss *bss;
30051 + struct ieee80211_sub_if_data *sdata;
30052 + u8 bssid[ETH_ALEN], *pos;
30053 + int i;
30054 +
30055 +#if 0
30056 + /* Easier testing, use fixed BSSID. */
30057 + memset(bssid, 0xfe, ETH_ALEN);
30058 +#else
30059 + /* Generate random, not broadcast, locally administered BSSID. Mix in
30060 + * own MAC address to make sure that devices that do not have proper
30061 + * random number generator get different BSSID. */
30062 + get_random_bytes(bssid, ETH_ALEN);
30063 + for (i = 0; i < ETH_ALEN; i++)
30064 + bssid[i] ^= dev->dev_addr[i];
30065 + bssid[0] &= ~0x01;
30066 + bssid[0] |= 0x02;
30067 +#endif
30068 +
30069 + printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID " MACSTR "\n",
30070 + dev->name, MAC2STR(bssid));
30071 +
30072 + bss = ieee80211_rx_bss_add(dev, bssid);
30073 + if (bss == NULL)
30074 + return -ENOMEM;
30075 +
30076 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30077 +
30078 + if (local->conf.beacon_int == 0)
30079 + local->conf.beacon_int = 100;
30080 + bss->beacon_int = local->conf.beacon_int;
30081 + bss->hw_mode = local->conf.phymode;
30082 + bss->channel = local->conf.channel;
30083 + bss->freq = local->conf.freq;
30084 + bss->last_update = jiffies;
30085 + bss->capability = cpu_to_le16(WLAN_CAPABILITY_IBSS);
30086 + if (sdata->default_key) {
30087 + bss->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
30088 + } else
30089 + sdata->drop_unencrypted = 0;
30090 + bss->supp_rates_len = local->num_curr_rates;
30091 + pos = bss->supp_rates;
30092 + for (i = 0; i < local->num_curr_rates; i++) {
30093 + int rate = local->curr_rates[i].rate;
30094 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
30095 + rate /= 2;
30096 + *pos++ = (u8) (rate / 5);
30097 + }
30098 +
30099 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30100 +}
30101 +
30102 +
30103 +static int ieee80211_sta_find_ibss(struct net_device *dev,
30104 + struct ieee80211_if_sta *ifsta)
30105 +{
30106 + struct ieee80211_local *local = dev->priv;
30107 + struct ieee80211_sta_bss *bss;
30108 + int found = 0;
30109 + u8 bssid[ETH_ALEN];
30110 + struct list_head *ptr;
30111 + int active_ibss;
30112 +
30113 + if (ifsta->ssid_len == 0)
30114 + return -EINVAL;
30115 +
30116 + active_ibss = ieee80211_sta_active_ibss(dev);
30117 +#ifdef IEEE80211_IBSS_DEBUG
30118 + printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
30119 + dev->name, active_ibss);
30120 +#endif /* IEEE80211_IBSS_DEBUG */
30121 + spin_lock_bh(&local->sta_bss_lock);
30122 + list_for_each(ptr, &local->sta_bss_list) {
30123 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
30124 + if (ifsta->ssid_len != bss->ssid_len ||
30125 + memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
30126 + || !(bss->capability & WLAN_CAPABILITY_IBSS))
30127 + continue;
30128 +#ifdef IEEE80211_IBSS_DEBUG
30129 + printk(KERN_DEBUG " bssid=" MACSTR " found\n",
30130 + MAC2STR(bss->bssid));
30131 +#endif /* IEEE80211_IBSS_DEBUG */
30132 + memcpy(bssid, bss->bssid, ETH_ALEN);
30133 + found = 1;
30134 + if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
30135 + break;
30136 + }
30137 + spin_unlock_bh(&local->sta_bss_lock);
30138 +
30139 +#ifdef IEEE80211_IBSS_DEBUG
30140 + printk(KERN_DEBUG " sta_find_ibss: selected " MACSTR " current "
30141 + MACSTR "\n", MAC2STR(bssid), MAC2STR(ifsta->bssid));
30142 +#endif /* IEEE80211_IBSS_DEBUG */
30143 + if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
30144 + (bss = ieee80211_rx_bss_get(dev, bssid))) {
30145 + printk(KERN_DEBUG "%s: Selected IBSS BSSID " MACSTR
30146 + " based on configured SSID\n",
30147 + dev->name, MAC2STR(bssid));
30148 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30149 + }
30150 +#ifdef IEEE80211_IBSS_DEBUG
30151 + printk(KERN_DEBUG " did not try to join ibss\n");
30152 +#endif /* IEEE80211_IBSS_DEBUG */
30153 +
30154 + /* Selected IBSS not found in current scan results - try to scan */
30155 + if (ifsta->state == IEEE80211_IBSS_JOINED &&
30156 + !ieee80211_sta_active_ibss(dev)) {
30157 + mod_timer(&ifsta->timer,
30158 + jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30159 + } else if (time_after(jiffies, local->last_scan_completed +
30160 + IEEE80211_SCAN_INTERVAL)) {
30161 + printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
30162 + "join\n", dev->name);
30163 + return ieee80211_sta_req_scan(dev, ifsta->ssid,
30164 + ifsta->ssid_len);
30165 + } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
30166 + int interval = IEEE80211_SCAN_INTERVAL;
30167 +
30168 + if (time_after(jiffies, ifsta->ibss_join_req +
30169 + IEEE80211_IBSS_JOIN_TIMEOUT)) {
30170 + if (ifsta->create_ibss &&
30171 + ieee80211_ibss_allowed(local))
30172 + return ieee80211_sta_create_ibss(dev, ifsta);
30173 + if (ifsta->create_ibss) {
30174 + printk(KERN_DEBUG "%s: IBSS not allowed on the"
30175 + " configured channel %d (%d MHz)\n",
30176 + dev->name, local->conf.channel,
30177 + local->conf.freq);
30178 + }
30179 +
30180 + /* No IBSS found - decrease scan interval and continue
30181 + * scanning. */
30182 + interval = IEEE80211_SCAN_INTERVAL_SLOW;
30183 + }
30184 +
30185 + ifsta->state = IEEE80211_IBSS_SEARCH;
30186 + mod_timer(&ifsta->timer, jiffies + interval);
30187 + return 0;
30188 + }
30189 +
30190 + return 0;
30191 +}
30192 +
30193 +
30194 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
30195 +{
30196 + struct ieee80211_sub_if_data *sdata;
30197 + struct ieee80211_if_sta *ifsta;
30198 + struct ieee80211_local *local = dev->priv;
30199 +
30200 + if (len > IEEE80211_MAX_SSID_LEN)
30201 + return -EINVAL;
30202 +
30203 + /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
30204 + * not defined. */
30205 + if (local->hw->conf_tx) {
30206 + struct ieee80211_tx_queue_params qparam;
30207 + int i;
30208 +
30209 + memset(&qparam, 0, sizeof(qparam));
30210 + /* TODO: are these ok defaults for all hw_modes? */
30211 + qparam.aifs = 2;
30212 + qparam.cw_min =
30213 + local->conf.phymode == MODE_IEEE80211B ? 31 : 15;
30214 + qparam.cw_max = 1023;
30215 + qparam.burst_time = 0;
30216 + for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
30217 + {
30218 + local->hw->conf_tx(dev, i + IEEE80211_TX_QUEUE_DATA0,
30219 + &qparam);
30220 + }
30221 + /* IBSS uses different parameters for Beacon sending */
30222 + qparam.cw_min++;
30223 + qparam.cw_min *= 2;
30224 + qparam.cw_min--;
30225 + local->hw->conf_tx(dev, IEEE80211_TX_QUEUE_BEACON, &qparam);
30226 + }
30227 +
30228 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30229 + ifsta = &sdata->u.sta;
30230 +
30231 + if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
30232 + ifsta->prev_bssid_set = 0;
30233 + memcpy(ifsta->ssid, ssid, len);
30234 + memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
30235 + ifsta->ssid_len = len;
30236 +
30237 + ifsta->ssid_set = 1;
30238 + if (local->conf.mode == IW_MODE_ADHOC && !ifsta->bssid_set) {
30239 + ifsta->ibss_join_req = jiffies;
30240 + ifsta->state = IEEE80211_IBSS_SEARCH;
30241 + return ieee80211_sta_find_ibss(dev, ifsta);
30242 + }
30243 +
30244 + if (ifsta->bssid_set && ifsta->state != IEEE80211_AUTHENTICATE)
30245 + ieee80211_sta_new_auth(dev, ifsta);
30246 +
30247 + return 0;
30248 +}
30249 +
30250 +
30251 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
30252 +{
30253 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30254 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30255 + memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
30256 + *len = ifsta->ssid_len;
30257 + return 0;
30258 +}
30259 +
30260 +
30261 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
30262 +{
30263 + struct ieee80211_local *local = dev->priv;
30264 + struct ieee80211_sub_if_data *sdata;
30265 + struct ieee80211_if_sta *ifsta;
30266 +
30267 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30268 + ifsta = &sdata->u.sta;
30269 +
30270 + memcpy(ifsta->bssid, bssid, ETH_ALEN);
30271 + if (local->conf.mode == IW_MODE_ADHOC)
30272 + memcpy(local->bssid, bssid, ETH_ALEN);
30273 +
30274 + if (memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
30275 + ifsta->bssid_set = 0;
30276 + else
30277 + ifsta->bssid_set = 1;
30278 + if (ifsta->ssid_set)
30279 + ieee80211_sta_new_auth(dev, ifsta);
30280 +
30281 + return 0;
30282 +}
30283 +
30284 +
30285 +static void ieee80211_sta_save_oper_chan(struct net_device *dev)
30286 +{
30287 + struct ieee80211_local *local = dev->priv;
30288 + local->scan_oper_channel = local->conf.channel;
30289 + local->scan_oper_channel_val = local->conf.channel_val;
30290 + local->scan_oper_power_level = local->conf.power_level;
30291 + local->scan_oper_freq = local->conf.freq;
30292 + local->scan_oper_phymode = local->conf.phymode;
30293 + local->scan_oper_antenna_max = local->conf.antenna_max;
30294 +}
30295 +
30296 +
30297 +static int ieee80211_sta_restore_oper_chan(struct net_device *dev)
30298 +{
30299 + struct ieee80211_local *local = dev->priv;
30300 + local->conf.channel = local->scan_oper_channel;
30301 + local->conf.channel_val = local->scan_oper_channel_val;
30302 + local->conf.power_level = local->scan_oper_power_level;
30303 + local->conf.freq = local->scan_oper_freq;
30304 + local->conf.phymode = local->scan_oper_phymode;
30305 + local->conf.antenna_max = local->scan_oper_antenna_max;
30306 + return ieee80211_hw_config(dev);
30307 +}
30308 +
30309 +
30310 +static int ieee80211_active_scan(struct ieee80211_local *local)
30311 +{
30312 + int m, c;
30313 +
30314 + for (m = 0; m < local->hw->num_modes; m++) {
30315 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
30316 + if (mode->mode != local->conf.phymode)
30317 + continue;
30318 + for (c = 0; c < mode->num_channels; c++) {
30319 + struct ieee80211_channel *chan = &mode->channels[c];
30320 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
30321 + chan->chan == local->conf.channel) {
30322 + if (chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN)
30323 + return 1;
30324 + break;
30325 + }
30326 + }
30327 + }
30328 +
30329 + return 0;
30330 +}
30331 +
30332 +
30333 +static void ieee80211_sta_scan_timer(unsigned long ptr)
30334 +{
30335 + struct net_device *dev = (struct net_device *) ptr;
30336 + struct ieee80211_local *local = dev->priv;
30337 + struct ieee80211_hw_modes *mode;
30338 + struct ieee80211_channel *chan;
30339 + int skip;
30340 + union iwreq_data wrqu;
30341 +
30342 + if (!local->sta_scanning)
30343 + return;
30344 +
30345 + switch (local->scan_state) {
30346 + case SCAN_SET_CHANNEL:
30347 + mode = &local->hw->modes[local->scan_hw_mode_idx];
30348 + if (local->scan_hw_mode_idx >= local->hw->num_modes ||
30349 + (local->scan_hw_mode_idx + 1 == local->hw->num_modes &&
30350 + local->scan_channel_idx >= mode->num_channels)) {
30351 + if (ieee80211_sta_restore_oper_chan(dev)) {
30352 + printk(KERN_DEBUG "%s: failed to restore "
30353 + "operational channel after scan\n",
30354 + dev->name);
30355 + }
30356 + printk(KERN_DEBUG "%s: scan completed\n", dev->name);
30357 + local->sta_scanning = 0;
30358 + local->last_scan_completed = jiffies;
30359 + memset(&wrqu, 0, sizeof(wrqu));
30360 + wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
30361 + if (local->conf.mode == IW_MODE_ADHOC) {
30362 + struct ieee80211_sub_if_data *sdata =
30363 + IEEE80211_DEV_TO_SUB_IF(dev);
30364 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30365 + if (!ifsta->bssid_set ||
30366 + (ifsta->state == IEEE80211_IBSS_JOINED &&
30367 + !ieee80211_sta_active_ibss(dev)))
30368 + ieee80211_sta_find_ibss(dev, ifsta);
30369 + }
30370 + return;
30371 + }
30372 + skip = !(local->hw_modes & (1 << mode->mode));
30373 + chan = &mode->channels[local->scan_channel_idx];
30374 + if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
30375 + (local->conf.mode == IW_MODE_ADHOC &&
30376 + !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
30377 + (local->hw_modes & (1 << MODE_IEEE80211G) &&
30378 + mode->mode == MODE_IEEE80211B && local->scan_skip_11b))
30379 + skip = 1;
30380 +
30381 + if (!skip) {
30382 +#if 0
30383 + printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
30384 + dev->name, chan->chan, chan->freq);
30385 +#endif
30386 +
30387 + local->conf.channel = chan->chan;
30388 + local->conf.channel_val = chan->val;
30389 + local->conf.power_level = chan->power_level;
30390 + local->conf.freq = chan->freq;
30391 + local->conf.phymode = mode->mode;
30392 + local->conf.antenna_max = chan->antenna_max;
30393 + if (ieee80211_hw_config(dev)) {
30394 + printk(KERN_DEBUG "%s: failed to set channel "
30395 + "%d (%d MHz) for scan\n", dev->name,
30396 + chan->chan, chan->freq);
30397 + skip = 1;
30398 + }
30399 + }
30400 +
30401 + local->scan_channel_idx++;
30402 + if (local->scan_channel_idx >=
30403 + local->hw->modes[local->scan_hw_mode_idx].num_channels) {
30404 + local->scan_hw_mode_idx++;
30405 + local->scan_channel_idx = 0;
30406 + }
30407 +
30408 + if (skip) {
30409 + local->scan_timer.expires = jiffies;
30410 + break;
30411 + }
30412 +
30413 + local->scan_timer.expires = jiffies + IEEE80211_PROBE_DELAY;
30414 + local->scan_state = SCAN_SEND_PROBE;
30415 + break;
30416 + case SCAN_SEND_PROBE:
30417 + if (ieee80211_active_scan(local)) {
30418 + ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
30419 + local->scan_ssid_len);
30420 + local->scan_timer.expires =
30421 + jiffies + IEEE80211_CHANNEL_TIME;
30422 + } else {
30423 + local->scan_timer.expires =
30424 + jiffies + IEEE80211_PASSIVE_CHANNEL_TIME;
30425 + }
30426 + local->scan_state = SCAN_SET_CHANNEL;
30427 + break;
30428 + }
30429 +
30430 + add_timer(&local->scan_timer);
30431 +}
30432 +
30433 +
30434 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
30435 +{
30436 + struct ieee80211_local *local = dev->priv;
30437 +
30438 + if (ssid_len > IEEE80211_MAX_SSID_LEN)
30439 + return -EINVAL;
30440 +
30441 + /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
30442 + * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
30443 + * BSSID: MACAddress
30444 + * SSID
30445 + * ScanType: ACTIVE, PASSIVE
30446 + * ProbeDelay: delay (in microseconds) to be used prior to transmitting
30447 + * a Probe frame during active scanning
30448 + * ChannelList
30449 + * MinChannelTime (>= ProbeDelay), in TU
30450 + * MaxChannelTime: (>= MinChannelTime), in TU
30451 + */
30452 +
30453 + /* MLME-SCAN.confirm
30454 + * BSSDescriptionSet
30455 + * ResultCode: SUCCESS, INVALID_PARAMETERS
30456 + */
30457 +
30458 + /* TODO: if assoc, move to power save mode for the duration of the
30459 + * scan */
30460 +
30461 + if (local->sta_scanning)
30462 + return -EBUSY;
30463 +
30464 + printk(KERN_DEBUG "%s: starting scan\n", dev->name);
30465 +
30466 + ieee80211_sta_save_oper_chan(dev);
30467 +
30468 + local->sta_scanning = 1;
30469 + /* TODO: stop TX queue? */
30470 +
30471 + if (ssid) {
30472 + local->scan_ssid_len = ssid_len;
30473 + memcpy(local->scan_ssid, ssid, ssid_len);
30474 + } else
30475 + local->scan_ssid_len = 0;
30476 + local->scan_skip_11b = 1; /* FIX: clear this is 11g is not supported */
30477 + local->scan_state = SCAN_SET_CHANNEL;
30478 + local->scan_hw_mode_idx = 0;
30479 + local->scan_channel_idx = 0;
30480 + init_timer(&local->scan_timer);
30481 + local->scan_timer.data = (unsigned long) dev;
30482 + local->scan_timer.function = ieee80211_sta_scan_timer;
30483 + local->scan_timer.expires = jiffies + 1;
30484 + add_timer(&local->scan_timer);
30485 +
30486 + return 0;
30487 +}
30488 +
30489 +
30490 +static char *
30491 +ieee80211_sta_scan_result(struct net_device *dev,
30492 + struct ieee80211_sta_bss *bss,
30493 + char *current_ev, char *end_buf)
30494 +{
30495 + struct ieee80211_local *local = dev->priv;
30496 + struct iw_event iwe;
30497 +
30498 + if (time_after(jiffies,
30499 + bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
30500 + return current_ev;
30501 +
30502 + if (!(local->hw_modes & (1 << bss->hw_mode)))
30503 + return current_ev;
30504 +
30505 + if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY &&
30506 + bss->wpa_ie == NULL && bss->rsn_ie == NULL)
30507 + return current_ev;
30508 +
30509 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID &&
30510 + (local->scan_ssid_len != bss->ssid_len ||
30511 + memcmp(local->scan_ssid, bss->ssid, bss->ssid_len) != 0))
30512 + return current_ev;
30513 +
30514 + memset(&iwe, 0, sizeof(iwe));
30515 + iwe.cmd = SIOCGIWAP;
30516 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
30517 + memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
30518 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30519 + IW_EV_ADDR_LEN);
30520 +
30521 + memset(&iwe, 0, sizeof(iwe));
30522 + iwe.cmd = SIOCGIWESSID;
30523 + iwe.u.data.length = bss->ssid_len;
30524 + iwe.u.data.flags = 1;
30525 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30526 + bss->ssid);
30527 +
30528 + if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
30529 + memset(&iwe, 0, sizeof(iwe));
30530 + iwe.cmd = SIOCGIWMODE;
30531 + if (bss->capability & WLAN_CAPABILITY_ESS)
30532 + iwe.u.mode = IW_MODE_MASTER;
30533 + else
30534 + iwe.u.mode = IW_MODE_ADHOC;
30535 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30536 + IW_EV_UINT_LEN);
30537 + }
30538 +
30539 + memset(&iwe, 0, sizeof(iwe));
30540 + iwe.cmd = SIOCGIWFREQ;
30541 + iwe.u.freq.m = bss->freq * 100000;
30542 + iwe.u.freq.e = 1;
30543 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30544 + IW_EV_FREQ_LEN);
30545 +
30546 + memset(&iwe, 0, sizeof(iwe));
30547 + iwe.cmd = SIOCGIWENCODE;
30548 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
30549 + iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
30550 + else
30551 + iwe.u.data.flags = IW_ENCODE_DISABLED;
30552 + iwe.u.data.length = 0;
30553 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
30554 +
30555 + if (bss && bss->wpa_ie) {
30556 + char *buf, *p;
30557 + int i;
30558 + buf = kmalloc(30 + bss->wpa_ie_len * 2, GFP_ATOMIC);
30559 + if (buf) {
30560 + p = buf;
30561 + p += sprintf(p, "wpa_ie=");
30562 + for (i = 0; i < bss->wpa_ie_len; i++)
30563 + p+= sprintf(p, "%02x", bss->wpa_ie[i]);
30564 + memset(&iwe, 0, sizeof(iwe));
30565 + iwe.cmd = IWEVCUSTOM;
30566 + iwe.u.data.length = strlen(buf);
30567 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30568 + &iwe, buf);
30569 + kfree(buf);
30570 + }
30571 + }
30572 +
30573 + if (bss && bss->rsn_ie) {
30574 + char *buf, *p;
30575 + int i;
30576 + buf = kmalloc(30 + bss->rsn_ie_len * 2, GFP_ATOMIC);
30577 + if (buf) {
30578 + p = buf;
30579 + p += sprintf(p, "rsn_ie=");
30580 + for (i = 0; i < bss->rsn_ie_len; i++)
30581 + p+= sprintf(p, "%02x", bss->rsn_ie[i]);
30582 + memset(&iwe, 0, sizeof(iwe));
30583 + iwe.cmd = IWEVCUSTOM;
30584 + iwe.u.data.length = strlen(buf);
30585 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30586 + &iwe, buf);
30587 + kfree(buf);
30588 + }
30589 + }
30590 +
30591 + if (bss) {
30592 + char *buf;
30593 + buf = kmalloc(30, GFP_ATOMIC);
30594 + if (buf) {
30595 + memset(&iwe, 0, sizeof(iwe));
30596 + iwe.cmd = IWEVCUSTOM;
30597 + sprintf(buf, "tsf=%016llx", bss->timestamp);
30598 + iwe.u.data.length = strlen(buf);
30599 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30600 + &iwe, buf);
30601 + kfree(buf);
30602 + }
30603 + }
30604 +
30605 + do {
30606 + char *buf, *p;
30607 + int i;
30608 +
30609 + if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO))
30610 + break;
30611 +
30612 + buf = kmalloc(100, GFP_ATOMIC);
30613 + if (buf == NULL)
30614 + break;
30615 +
30616 + memset(&iwe, 0, sizeof(iwe));
30617 + iwe.cmd = IWEVCUSTOM;
30618 + sprintf(buf, "bcn_int=%d", bss->beacon_int);
30619 + iwe.u.data.length = strlen(buf);
30620 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30621 + buf);
30622 +
30623 + memset(&iwe, 0, sizeof(iwe));
30624 + iwe.cmd = IWEVCUSTOM;
30625 + sprintf(buf, "rssi=%d", bss->rssi);
30626 + iwe.u.data.length = strlen(buf);
30627 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30628 + buf);
30629 +
30630 + memset(&iwe, 0, sizeof(iwe));
30631 + iwe.cmd = IWEVCUSTOM;
30632 + sprintf(buf, "capab=0x%04x", bss->capability);
30633 + iwe.u.data.length = strlen(buf);
30634 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30635 + buf);
30636 +
30637 + p = buf;
30638 + p += sprintf(p, "supp_rates=");
30639 + for (i = 0; i < bss->supp_rates_len; i++)
30640 + p+= sprintf(p, "%02x", bss->supp_rates[i]);
30641 + memset(&iwe, 0, sizeof(iwe));
30642 + iwe.cmd = IWEVCUSTOM;
30643 + iwe.u.data.length = strlen(buf);
30644 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30645 + buf);
30646 +
30647 + kfree(buf);
30648 + break;
30649 + } while (0);
30650 +
30651 + return current_ev;
30652 +}
30653 +
30654 +
30655 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
30656 +{
30657 + struct ieee80211_local *local = dev->priv;
30658 + struct list_head *ptr;
30659 + char *current_ev = buf;
30660 + char *end_buf = buf + len;
30661 + struct ieee80211_sta_bss *bss;
30662 +
30663 + spin_lock_bh(&local->sta_bss_lock);
30664 + list_for_each(ptr, &local->sta_bss_list) {
30665 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
30666 + current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
30667 + end_buf);
30668 + }
30669 + spin_unlock_bh(&local->sta_bss_lock);
30670 + return current_ev - buf;
30671 +}
30672 +
30673 +
30674 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
30675 +{
30676 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30677 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30678 + kfree(ifsta->extra_ie);
30679 + if (len == 0) {
30680 + ifsta->extra_ie = NULL;
30681 + ifsta->extra_ie_len = 0;
30682 + return 0;
30683 + }
30684 + ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
30685 + if (ifsta->extra_ie == NULL) {
30686 + ifsta->extra_ie_len = 0;
30687 + return -ENOMEM;
30688 + }
30689 + memcpy(ifsta->extra_ie, ie, len);
30690 + ifsta->extra_ie_len = len;
30691 + if (ifsta->bssid_set && ifsta->ssid_set &&
30692 + ifsta->state != IEEE80211_AUTHENTICATE)
30693 + ieee80211_sta_new_auth(dev, ifsta);
30694 + return 0;
30695 +}
30696 +
30697 +
30698 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
30699 + struct sk_buff *skb, u8 *bssid,
30700 + u8 *addr)
30701 +{
30702 + struct ieee80211_local *local = dev->priv;
30703 + struct list_head *ptr;
30704 + struct sta_info *sta;
30705 + struct ieee80211_sub_if_data *sdata = NULL;
30706 + struct net_device *sta_dev = NULL;
30707 +
30708 + /* TODO: Could consider removing the least recently used entry and
30709 + * allow new one to be added. */
30710 + if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
30711 + if (net_ratelimit()) {
30712 + printk(KERN_DEBUG "%s: No room for a new IBSS STA "
30713 + "entry " MACSTR "\n", dev->name, MAC2STR(addr));
30714 + }
30715 + return NULL;
30716 + }
30717 +
30718 + spin_lock_bh(&local->sub_if_lock);
30719 + list_for_each(ptr, &local->sub_if_list) {
30720 + sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
30721 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA &&
30722 + memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
30723 + sta_dev = sdata->dev;
30724 + break;
30725 + }
30726 + }
30727 + spin_unlock_bh(&local->sub_if_lock);
30728 +
30729 + if (sta_dev == NULL)
30730 + return NULL;
30731 +
30732 + printk(KERN_DEBUG "%s: Adding new IBSS station " MACSTR " (dev=%s)\n",
30733 + dev->name, MAC2STR(addr), sta_dev->name);
30734 +
30735 + sta = sta_info_add(local, dev, addr);
30736 + if (sta == NULL) {
30737 + return NULL;
30738 + }
30739 +
30740 + sta->dev = sta_dev;
30741 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
30742 +
30743 + rate_control_rate_init(local, sta);
30744 +
30745 + return sta; /* caller will call sta_info_release() */
30746 +}
30747 +
30748 +
30749 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
30750 +{
30751 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30752 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30753 +
30754 + printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
30755 + dev->name, reason);
30756 +
30757 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30758 + return -EINVAL;
30759 +
30760 + ieee80211_send_deauth(dev, ifsta, reason);
30761 + ieee80211_set_associated(dev, ifsta, 0);
30762 + return 0;
30763 +}
30764 +
30765 +
30766 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
30767 +{
30768 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30769 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30770 +
30771 + printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
30772 + dev->name, reason);
30773 +
30774 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30775 + return -EINVAL;
30776 +
30777 + if (!ifsta->associated)
30778 + return -1;
30779 +
30780 + ieee80211_send_disassoc(dev, ifsta, reason);
30781 + ieee80211_set_associated(dev, ifsta, 0);
30782 + return 0;
30783 +}
30784 diff -Nur linux-2.6.16/net/d80211/ieee80211_sysfs.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_sysfs.c
30785 --- linux-2.6.16/net/d80211/ieee80211_sysfs.c 1970-01-01 01:00:00.000000000 +0100
30786 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_sysfs.c 2006-03-28 22:16:14.000000000 +0200
30787 @@ -0,0 +1,135 @@
30788 +/*
30789 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
30790 + *
30791 + * This program is free software; you can redistribute it and/or modify
30792 + * it under the terms of the GNU General Public License version 2 as
30793 + * published by the Free Software Foundation.
30794 + */
30795 +
30796 +#include <linux/kernel.h>
30797 +#include <linux/device.h>
30798 +#include <linux/if.h>
30799 +#include <linux/interrupt.h>
30800 +#include <linux/rtnetlink.h>
30801 +#include <net/d80211.h>
30802 +#include "ieee80211_i.h"
30803 +
30804 +#define to_ieee80211_local(class) container_of(class, struct ieee80211_local, class_dev)
30805 +
30806 +
30807 +static ssize_t store_add_iface(struct class_device *dev,
30808 + const char *buf, size_t len)
30809 +{
30810 + struct ieee80211_local *local = to_ieee80211_local(dev);
30811 + int res;
30812 +
30813 + if (!capable(CAP_NET_ADMIN))
30814 + return -EPERM;
30815 + if (len > IFNAMSIZ)
30816 + return -EINVAL;
30817 + /* Cannot call ieee80211_if_add_sta() with 'locked' parameter equal
30818 + * to zero as it would lead to call to register_netdev() and
30819 + * interpreting '%d' character in an interface name. */
30820 + rtnl_lock();
30821 + res = ieee80211_if_add_sta(local->mdev, buf, 1);
30822 + rtnl_unlock();
30823 + return res < 0 ? res : len;
30824 +}
30825 +
30826 +static ssize_t store_remove_iface(struct class_device *dev,
30827 + const char *buf, size_t len)
30828 +{
30829 + struct ieee80211_local *local = to_ieee80211_local(dev);
30830 + int res;
30831 +
30832 + if (!capable(CAP_NET_ADMIN))
30833 + return -EPERM;
30834 + if (len > IFNAMSIZ)
30835 + return -EINVAL;
30836 + res = ieee80211_if_remove_sta(local->mdev, buf, 0);
30837 + return res < 0 ? res : len;
30838 +}
30839 +
30840 +static ssize_t show_max_iface_count(struct class_device *dev,
30841 + char *buf)
30842 +{
30843 + struct ieee80211_local *local = to_ieee80211_local(dev);
30844 +
30845 + return sprintf(buf, "%d\n", local->conf.bss_count);
30846 +}
30847 +
30848 +static ssize_t store_max_iface_count(struct class_device *dev,
30849 + const char *buf, size_t len)
30850 +{
30851 + struct ieee80211_local *local = to_ieee80211_local(dev);
30852 + unsigned long new_count;
30853 + char *endp;
30854 + int res;
30855 +
30856 + if (!capable(CAP_NET_ADMIN))
30857 + return -EPERM;
30858 + new_count = simple_strtoul(buf, &endp, 0);
30859 + if (endp == buf)
30860 + return -EINVAL;
30861 + rtnl_lock();
30862 + res = ieee80211_set_bss_count(local->mdev, new_count, NULL);
30863 + rtnl_unlock();
30864 + return res < 0 ? res : len;
30865 +}
30866 +
30867 +#ifdef CONFIG_HOTPLUG
30868 +static int ieee80211_uevent(struct class_device *cd, char **envp,
30869 + int num_envp, char *buf, int size)
30870 +{
30871 + struct ieee80211_local *local = to_ieee80211_local(cd);
30872 +
30873 + if (num_envp < 2)
30874 + return -ENOMEM;
30875 + envp[0] = buf;
30876 + if (snprintf(buf, size, "IEEE80211_DEV=phy%d",
30877 + local->dev_index) + 1 >= size)
30878 + return -ENOMEM;
30879 + envp[1] = NULL;
30880 + return 0;
30881 +}
30882 +#endif
30883 +
30884 +static struct class_device_attribute ieee80211_class_dev_attrs[] = {
30885 + __ATTR(add_iface, S_IWUSR, NULL, store_add_iface),
30886 + __ATTR(remove_iface, S_IWUSR, NULL, store_remove_iface),
30887 + __ATTR(max_iface_count, S_IRUGO | S_IWUSR,
30888 + show_max_iface_count, store_max_iface_count),
30889 + {}
30890 +};
30891 +
30892 +static struct class ieee80211_class = {
30893 + .name = "ieee80211",
30894 + .class_dev_attrs = ieee80211_class_dev_attrs,
30895 +#ifdef CONFIG_HOTPLUG
30896 + .uevent = ieee80211_uevent,
30897 +#endif
30898 +};
30899 +
30900 +int ieee80211_register_sysfs(struct ieee80211_local *local)
30901 +{
30902 + local->class_dev.class = &ieee80211_class;
30903 + local->class_dev.class_data = local;
30904 + snprintf(local->class_dev.class_id, BUS_ID_SIZE,
30905 + "phy%d", local->dev_index);
30906 + return class_device_register(&local->class_dev);
30907 +}
30908 +
30909 +void ieee80211_unregister_sysfs(struct ieee80211_local *local)
30910 +{
30911 + class_device_del(&local->class_dev);
30912 +}
30913 +
30914 +int ieee80211_sysfs_init(void)
30915 +{
30916 + return class_register(&ieee80211_class);
30917 +}
30918 +
30919 +void ieee80211_sysfs_deinit(void)
30920 +{
30921 + class_unregister(&ieee80211_class);
30922 +}
30923 diff -Nur linux-2.6.16/net/d80211/Kconfig linux-2.6.16-bcm43xx/net/d80211/Kconfig
30924 --- linux-2.6.16/net/d80211/Kconfig 1970-01-01 01:00:00.000000000 +0100
30925 +++ linux-2.6.16-bcm43xx/net/d80211/Kconfig 2006-03-28 22:16:14.000000000 +0200
30926 @@ -0,0 +1,31 @@
30927 +config D80211
30928 + tristate "Generic IEEE 802.11 Networking Stack (dscape)"
30929 + ---help---
30930 + This option enables the hardware independent IEEE 802.11
30931 + networking stack.
30932 +
30933 +config D80211_DEBUG
30934 + bool "Enable debugging output"
30935 + depends on D80211
30936 + ---help---
30937 + This option will enable debug tracing output for the
30938 + ieee80211 network stack.
30939 +
30940 + If you are not trying to debug or develop the ieee80211
30941 + subsystem, you most likely want to say N here.
30942 +
30943 +config D80211_VERBOSE_DEBUG
30944 + bool "Verbose debugging output"
30945 + depends on D80211_DEBUG
30946 +
30947 +config TKIP_DEBUG
30948 + bool "TKIP debugging"
30949 + depends on D80211_DEBUG
30950 +
30951 +config D80211_DEBUG_COUNTERS
30952 + bool "Extra statistics for TX/RX debugging"
30953 + depends on D80211_DEBUG
30954 +
30955 +config HOSTAPD_WPA_TESTING
30956 + bool "Support for TKIP countermeasures testing"
30957 + depends on D80211_DEBUG
30958 diff -Nur linux-2.6.16/net/d80211/Makefile linux-2.6.16-bcm43xx/net/d80211/Makefile
30959 --- linux-2.6.16/net/d80211/Makefile 1970-01-01 01:00:00.000000000 +0100
30960 +++ linux-2.6.16-bcm43xx/net/d80211/Makefile 2006-03-28 22:16:14.000000000 +0200
30961 @@ -0,0 +1,26 @@
30962 +obj-$(CONFIG_D80211) += 80211.o rate_control.o
30963 +
30964 +80211-objs := \
30965 + ieee80211.o \
30966 + ieee80211_ioctl.o \
30967 + sta_info.o \
30968 + wep.o \
30969 + wpa.o \
30970 + ieee80211_proc.o \
30971 + ieee80211_scan.o \
30972 + ieee80211_sta.o \
30973 + ieee80211_dev.o \
30974 + ieee80211_sysfs.o \
30975 + michael.o \
30976 + tkip.o \
30977 + aes_ccm.o \
30978 + wme.o
30979 +
30980 +ifeq ($(CONFIG_NET_SCHED),)
30981 + 80211-objs += fifo_qdisc.o
30982 +endif
30983 +
30984 +ifeq ($(CONFIG_D80211_LEDS),y)
30985 + 80211-objs += ieee80211_led.o
30986 +endif
30987 +
30988 diff -Nur linux-2.6.16/net/d80211/michael.c linux-2.6.16-bcm43xx/net/d80211/michael.c
30989 --- linux-2.6.16/net/d80211/michael.c 1970-01-01 01:00:00.000000000 +0100
30990 +++ linux-2.6.16-bcm43xx/net/d80211/michael.c 2006-03-28 22:16:14.000000000 +0200
30991 @@ -0,0 +1,104 @@
30992 +/*
30993 + * Michael MIC implementation - optimized for TKIP MIC operations
30994 + * Copyright 2002-2003, Instant802 Networks, Inc.
30995 + *
30996 + * This program is free software; you can redistribute it and/or modify
30997 + * it under the terms of the GNU General Public License version 2 as
30998 + * published by the Free Software Foundation.
30999 + */
31000 +
31001 +#include <linux/types.h>
31002 +
31003 +#include "michael.h"
31004 +
31005 +static inline u32 rotr(u32 val, int bits)
31006 +{
31007 + return (val >> bits) | (val << (32 - bits));
31008 +}
31009 +
31010 +
31011 +static inline u32 rotl(u32 val, int bits)
31012 +{
31013 + return (val << bits) | (val >> (32 - bits));
31014 +}
31015 +
31016 +
31017 +static inline u32 xswap(u32 val)
31018 +{
31019 + return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
31020 +}
31021 +
31022 +
31023 +#define michael_block(l, r) \
31024 +do { \
31025 + r ^= rotl(l, 17); \
31026 + l += r; \
31027 + r ^= xswap(l); \
31028 + l += r; \
31029 + r ^= rotl(l, 3); \
31030 + l += r; \
31031 + r ^= rotr(l, 2); \
31032 + l += r; \
31033 +} while (0)
31034 +
31035 +
31036 +static inline u32 michael_get32(u8 *data)
31037 +{
31038 + return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
31039 +}
31040 +
31041 +
31042 +static inline void michael_put32(u32 val, u8 *data)
31043 +{
31044 + data[0] = val & 0xff;
31045 + data[1] = (val >> 8) & 0xff;
31046 + data[2] = (val >> 16) & 0xff;
31047 + data[3] = (val >> 24) & 0xff;
31048 +}
31049 +
31050 +
31051 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31052 + u8 *data, size_t data_len, u8 *mic)
31053 +{
31054 + u32 l, r, val;
31055 + size_t block, blocks, left;
31056 +
31057 + l = michael_get32(key);
31058 + r = michael_get32(key + 4);
31059 +
31060 + /* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC
31061 + * calculation, but it is _not_ transmitted */
31062 + l ^= michael_get32(da);
31063 + michael_block(l, r);
31064 + l ^= da[4] | (da[5] << 8) | (sa[0] << 16) | (sa[1] << 24);
31065 + michael_block(l, r);
31066 + l ^= michael_get32(&sa[2]);
31067 + michael_block(l, r);
31068 + l ^= priority;
31069 + michael_block(l, r);
31070 +
31071 + /* Real data */
31072 + blocks = data_len / 4;
31073 + left = data_len % 4;
31074 +
31075 + for (block = 0; block < blocks; block++) {
31076 + l ^= michael_get32(&data[block * 4]);
31077 + michael_block(l, r);
31078 + }
31079 +
31080 + /* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
31081 + * total length a multiple of 4. */
31082 + val = 0x5a;
31083 + while (left > 0) {
31084 + val <<= 8;
31085 + left--;
31086 + val |= data[blocks * 4 + left];
31087 + }
31088 + l ^= val;
31089 + michael_block(l, r);
31090 + /* last block is zero, so l ^ 0 = l */
31091 + michael_block(l, r);
31092 +
31093 + michael_put32(l, mic);
31094 + michael_put32(r, mic + 4);
31095 +}
31096 diff -Nur linux-2.6.16/net/d80211/michael.h linux-2.6.16-bcm43xx/net/d80211/michael.h
31097 --- linux-2.6.16/net/d80211/michael.h 1970-01-01 01:00:00.000000000 +0100
31098 +++ linux-2.6.16-bcm43xx/net/d80211/michael.h 2006-03-28 22:16:14.000000000 +0200
31099 @@ -0,0 +1,20 @@
31100 +/*
31101 + * Michael MIC implementation - optimized for TKIP MIC operations
31102 + * Copyright 2002-2003, Instant802 Networks, Inc.
31103 + *
31104 + * This program is free software; you can redistribute it and/or modify
31105 + * it under the terms of the GNU General Public License version 2 as
31106 + * published by the Free Software Foundation.
31107 + */
31108 +
31109 +#ifndef MICHAEL_H
31110 +#define MICHAEL_H
31111 +
31112 +#include <linux/types.h>
31113 +
31114 +#define MICHAEL_MIC_LEN 8
31115 +
31116 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31117 + u8 *data, size_t data_len, u8 *mic);
31118 +
31119 +#endif /* MICHAEL_H */
31120 diff -Nur linux-2.6.16/net/d80211/rate_control.c linux-2.6.16-bcm43xx/net/d80211/rate_control.c
31121 --- linux-2.6.16/net/d80211/rate_control.c 1970-01-01 01:00:00.000000000 +0100
31122 +++ linux-2.6.16-bcm43xx/net/d80211/rate_control.c 2006-03-28 22:16:14.000000000 +0200
31123 @@ -0,0 +1,385 @@
31124 +/*
31125 + * Copyright 2002-2005, Instant802 Networks, Inc.
31126 + * Copyright 2005, Devicescape Software, Inc.
31127 + *
31128 + * This program is free software; you can redistribute it and/or modify
31129 + * it under the terms of the GNU General Public License version 2 as
31130 + * published by the Free Software Foundation.
31131 + */
31132 +
31133 +#include <linux/config.h>
31134 +#include <linux/version.h>
31135 +#include <linux/module.h>
31136 +#include <linux/init.h>
31137 +#include <linux/netdevice.h>
31138 +#include <linux/types.h>
31139 +#include <linux/slab.h>
31140 +#include <linux/skbuff.h>
31141 +#include <linux/compiler.h>
31142 +
31143 +#include <net/d80211.h>
31144 +#include "ieee80211_i.h"
31145 +#include "rate_control.h"
31146 +
31147 +
31148 +/* This is a minimal implementation of TX rate controlling that can be used
31149 + * as the default when no improved mechanisms are available. */
31150 +
31151 +
31152 +#define RATE_CONTROL_EMERG_DEC 2
31153 +#define RATE_CONTROL_INTERVAL (HZ / 20)
31154 +#define RATE_CONTROL_MIN_TX 10
31155 +
31156 +MODULE_ALIAS("ieee80211_rate_control");
31157 +
31158 +static void rate_control_rate_inc(struct ieee80211_local *local,
31159 + struct sta_info *sta)
31160 +{
31161 + struct ieee80211_sub_if_data *sdata;
31162 + int i = sta->txrate;
31163 + int maxrate;
31164 +
31165 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31166 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
31167 + /* forced unicast rate - do not change STA rate */
31168 + return;
31169 + }
31170 +
31171 + maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
31172 +
31173 + if (i > local->num_curr_rates)
31174 + i = local->num_curr_rates - 2;
31175 +
31176 + while (i + 1 < local->num_curr_rates) {
31177 + i++;
31178 + if (sta->supp_rates & BIT(i) &&
31179 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED &&
31180 + (maxrate < 0 || i <= maxrate)) {
31181 + sta->txrate = i;
31182 + break;
31183 + }
31184 + }
31185 +}
31186 +
31187 +
31188 +static void rate_control_rate_dec(struct ieee80211_local *local,
31189 + struct sta_info *sta)
31190 +{
31191 + struct ieee80211_sub_if_data *sdata;
31192 + int i = sta->txrate;
31193 +
31194 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31195 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
31196 + /* forced unicast rate - do not change STA rate */
31197 + return;
31198 + }
31199 +
31200 + if (i > local->num_curr_rates)
31201 + i = local->num_curr_rates;
31202 +
31203 + while (i > 0) {
31204 + i--;
31205 + if (sta->supp_rates & BIT(i) &&
31206 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED) {
31207 + sta->txrate = i;
31208 + break;
31209 + }
31210 + }
31211 +}
31212 +
31213 +
31214 +static struct ieee80211_rate *
31215 +rate_control_lowest_rate(struct ieee80211_local *local)
31216 +{
31217 + int i;
31218 +
31219 + for (i = 0; i < local->num_curr_rates; i++) {
31220 + struct ieee80211_rate *rate = &local->curr_rates[i];
31221 +
31222 + if (rate->flags & IEEE80211_RATE_SUPPORTED
31223 + )
31224 + return rate;
31225 + }
31226 +
31227 + printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
31228 + "found\n");
31229 + return &local->curr_rates[0];
31230 +}
31231 +
31232 +
31233 +struct global_rate_control {
31234 + int dummy;
31235 +};
31236 +
31237 +struct sta_rate_control {
31238 + unsigned long last_rate_change;
31239 + u32 tx_num_failures;
31240 + u32 tx_num_xmit;
31241 +
31242 + unsigned long avg_rate_update;
31243 + u32 tx_avg_rate_sum;
31244 + u32 tx_avg_rate_num;
31245 +};
31246 +
31247 +
31248 +static void rate_control_simple_tx_status(struct net_device *dev,
31249 + struct sk_buff *skb,
31250 + struct ieee80211_tx_status *status)
31251 +{
31252 + struct ieee80211_local *local = dev->priv;
31253 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
31254 + struct sta_info *sta;
31255 + struct sta_rate_control *srctrl;
31256 +
31257 + sta = sta_info_get(local, hdr->addr1);
31258 +
31259 + if (!sta)
31260 + return;
31261 +
31262 + srctrl = sta->rate_ctrl_priv;
31263 + srctrl->tx_num_xmit++;
31264 + if (status->excessive_retries) {
31265 + sta->antenna_sel = sta->antenna_sel == 1 ? 2 : 1;
31266 + if (local->sta_antenna_sel == STA_ANTENNA_SEL_SW_CTRL_DEBUG) {
31267 + printk(KERN_DEBUG "%s: " MACSTR " TX antenna --> %d "
31268 + "(@%lu)\n",
31269 + dev->name, MAC2STR(hdr->addr1),
31270 + sta->antenna_sel, jiffies);
31271 + }
31272 + srctrl->tx_num_failures++;
31273 + sta->tx_retry_failed++;
31274 + sta->tx_num_consecutive_failures++;
31275 + sta->tx_num_mpdu_fail++;
31276 + } else {
31277 + sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
31278 + sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
31279 + sta->last_ack_rssi[2] = status->ack_signal;
31280 + sta->tx_num_consecutive_failures = 0;
31281 + sta->tx_num_mpdu_ok++;
31282 + }
31283 + sta->tx_retry_count += status->retry_count;
31284 + sta->tx_num_mpdu_fail += status->retry_count;
31285 +
31286 + if (time_after(jiffies,
31287 + srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
31288 + srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
31289 + u32 per_failed;
31290 + srctrl->last_rate_change = jiffies;
31291 +
31292 + per_failed = (100 * sta->tx_num_mpdu_fail) /
31293 + (sta->tx_num_mpdu_fail + sta->tx_num_mpdu_ok);
31294 + /* TODO: calculate average per_failed to make adjusting
31295 + * parameters easier */
31296 +#if 0
31297 + if (net_ratelimit()) {
31298 + printk(KERN_DEBUG "MPDU fail=%d ok=%d per_failed=%d\n",
31299 + sta->tx_num_mpdu_fail, sta->tx_num_mpdu_ok,
31300 + per_failed);
31301 + }
31302 +#endif
31303 +
31304 + if (per_failed > local->rate_ctrl_num_down) {
31305 + rate_control_rate_dec(local, sta);
31306 + } else if (per_failed < local->rate_ctrl_num_up) {
31307 + rate_control_rate_inc(local, sta);
31308 + }
31309 + srctrl->tx_avg_rate_sum += local->curr_rates[sta->txrate].rate;
31310 + srctrl->tx_avg_rate_num++;
31311 + srctrl->tx_num_failures = 0;
31312 + srctrl->tx_num_xmit = 0;
31313 + } else if (sta->tx_num_consecutive_failures >=
31314 + RATE_CONTROL_EMERG_DEC) {
31315 + rate_control_rate_dec(local, sta);
31316 + }
31317 +
31318 + if (srctrl->avg_rate_update + 60 * HZ < jiffies) {
31319 + srctrl->avg_rate_update = jiffies;
31320 + if (srctrl->tx_avg_rate_num > 0) {
31321 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31322 + printk(KERN_DEBUG "%s: STA " MACSTR " Average rate: "
31323 + "%d (%d/%d)\n",
31324 + dev->name, MAC2STR(sta->addr),
31325 + srctrl->tx_avg_rate_sum /
31326 + srctrl->tx_avg_rate_num,
31327 + srctrl->tx_avg_rate_sum,
31328 + srctrl->tx_avg_rate_num);
31329 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31330 + srctrl->tx_avg_rate_sum = 0;
31331 + srctrl->tx_avg_rate_num = 0;
31332 + }
31333 + }
31334 +
31335 + sta_info_release(local, sta);
31336 +}
31337 +
31338 +
31339 +static struct ieee80211_rate *
31340 +rate_control_simple_get_rate(struct net_device *dev, struct sk_buff *skb,
31341 + struct rate_control_extra *extra)
31342 +{
31343 + struct ieee80211_local *local = dev->priv;
31344 + struct ieee80211_sub_if_data *sdata;
31345 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
31346 + struct sta_info *sta;
31347 + int rateidx, nonerp_idx;
31348 + u16 fc;
31349 +
31350 + memset(extra, 0, sizeof(*extra));
31351 +
31352 + fc = le16_to_cpu(hdr->frame_control);
31353 + if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA ||
31354 + (hdr->addr1[0] & 0x01)) {
31355 + /* Send management frames and broadcast/multicast data using
31356 + * lowest rate. */
31357 + /* TODO: this could probably be improved.. */
31358 + return rate_control_lowest_rate(local);
31359 + }
31360 +
31361 + sta = sta_info_get(local, hdr->addr1);
31362 +
31363 + if (!sta)
31364 + return rate_control_lowest_rate(local);
31365 +
31366 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
31367 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
31368 + sta->txrate = sdata->bss->force_unicast_rateidx;
31369 +
31370 + rateidx = sta->txrate;
31371 +
31372 + if (rateidx >= local->num_curr_rates)
31373 + rateidx = local->num_curr_rates - 1;
31374 +
31375 + sta->last_txrate = rateidx;
31376 + nonerp_idx = rateidx;
31377 + while (nonerp_idx > 0 &&
31378 + ((local->curr_rates[nonerp_idx].flags & IEEE80211_RATE_ERP) ||
31379 + !(local->curr_rates[nonerp_idx].flags &
31380 + IEEE80211_RATE_SUPPORTED) ||
31381 + !(sta->supp_rates & BIT(nonerp_idx))))
31382 + nonerp_idx--;
31383 + extra->nonerp_idx = nonerp_idx;
31384 + extra->nonerp = &local->curr_rates[extra->nonerp_idx];
31385 +
31386 + sta_info_release(local, sta);
31387 +
31388 + return &local->curr_rates[rateidx];
31389 +}
31390 +
31391 +
31392 +static void rate_control_simple_rate_init(struct ieee80211_local *local,
31393 + struct sta_info *sta)
31394 +{
31395 + int i;
31396 + sta->txrate = 0;
31397 + /* TODO: what is a good starting rate for STA? About middle? Maybe not
31398 + * the lowest or the highest rate.. Could consider using RSSI from
31399 + * previous packets? Need to have IEEE 802.1X auth succeed immediately
31400 + * after assoc.. */
31401 + for (i = 0; i < local->num_curr_rates; i++) {
31402 + if ((sta->supp_rates & BIT(i)) &&
31403 + (local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED))
31404 + sta->txrate = i;
31405 + }
31406 +}
31407 +
31408 +
31409 +static void * rate_control_simple_alloc(struct ieee80211_local *local)
31410 +{
31411 + struct global_rate_control *rctrl;
31412 +
31413 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31414 + if (rctrl == NULL) {
31415 + return NULL;
31416 + }
31417 + memset(rctrl, 0, sizeof(*rctrl));
31418 + return rctrl;
31419 +}
31420 +
31421 +
31422 +static void rate_control_simple_free(void *priv)
31423 +{
31424 + struct global_rate_control *rctrl = priv;
31425 + kfree(rctrl);
31426 +}
31427 +
31428 +
31429 +static void rate_control_simple_clear(void *priv)
31430 +{
31431 +}
31432 +
31433 +
31434 +static void * rate_control_simple_alloc_sta(void)
31435 +{
31436 + struct sta_rate_control *rctrl;
31437 +
31438 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31439 + if (rctrl == NULL) {
31440 + return NULL;
31441 + }
31442 + memset(rctrl, 0, sizeof(*rctrl));
31443 + return rctrl;
31444 +}
31445 +
31446 +
31447 +static void rate_control_simple_free_sta(void *priv)
31448 +{
31449 + struct sta_rate_control *rctrl = priv;
31450 + kfree(rctrl);
31451 +}
31452 +
31453 +
31454 +static int rate_control_simple_status_sta(struct ieee80211_local *local,
31455 + struct sta_info *sta, char *buf)
31456 +{
31457 + char *p = buf;
31458 + struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
31459 +
31460 + p += sprintf(p, "tx_avg_rate_sum=%d\n", srctrl->tx_avg_rate_sum);
31461 + p += sprintf(p, "tx_avg_rate_num=%d\n", srctrl->tx_avg_rate_num);
31462 + if (srctrl->tx_avg_rate_num)
31463 + p += sprintf(p, "tx_avg_rate_avg=%d\n",
31464 + srctrl->tx_avg_rate_sum /
31465 + srctrl->tx_avg_rate_num);
31466 + return p - buf;
31467 +}
31468 +
31469 +
31470 +static int rate_control_simple_status_global(struct ieee80211_local *local,
31471 + char *buf)
31472 +{
31473 + return 0;
31474 +}
31475 +
31476 +
31477 +static struct rate_control_ops rate_control_simple = {
31478 + .name = "simple",
31479 + .tx_status = rate_control_simple_tx_status,
31480 + .get_rate = rate_control_simple_get_rate,
31481 + .rate_init = rate_control_simple_rate_init,
31482 + .clear = rate_control_simple_clear,
31483 + .status_sta = rate_control_simple_status_sta,
31484 + .status_global = rate_control_simple_status_global,
31485 + .alloc = rate_control_simple_alloc,
31486 + .free = rate_control_simple_free,
31487 + .alloc_sta = rate_control_simple_alloc_sta,
31488 + .free_sta = rate_control_simple_free_sta,
31489 +};
31490 +
31491 +
31492 +int __init rate_control_simple_init(void)
31493 +{
31494 + return ieee80211_rate_control_register(&rate_control_simple);
31495 +}
31496 +
31497 +
31498 +static void __exit rate_control_simple_exit(void)
31499 +{
31500 + ieee80211_rate_control_unregister(&rate_control_simple);
31501 +}
31502 +
31503 +
31504 +module_init(rate_control_simple_init);
31505 +module_exit(rate_control_simple_exit);
31506 +
31507 +MODULE_DESCRIPTION("Simple rate control algorithm for ieee80211");
31508 +MODULE_LICENSE("GPL");
31509 diff -Nur linux-2.6.16/net/d80211/rate_control.h linux-2.6.16-bcm43xx/net/d80211/rate_control.h
31510 --- linux-2.6.16/net/d80211/rate_control.h 1970-01-01 01:00:00.000000000 +0100
31511 +++ linux-2.6.16-bcm43xx/net/d80211/rate_control.h 2006-03-28 22:16:14.000000000 +0200
31512 @@ -0,0 +1,135 @@
31513 +/*
31514 + * Copyright 2002-2005, Instant802 Networks, Inc.
31515 + * Copyright 2005, Devicescape Software, Inc.
31516 + *
31517 + * This program is free software; you can redistribute it and/or modify
31518 + * it under the terms of the GNU General Public License version 2 as
31519 + * published by the Free Software Foundation.
31520 + */
31521 +
31522 +#ifndef RATE_CONTROL
31523 +#define RATE_CONTROL
31524 +
31525 +#include <linux/netdevice.h>
31526 +#include <linux/skbuff.h>
31527 +#include <linux/types.h>
31528 +#include <net/d80211.h>
31529 +#include "ieee80211_i.h"
31530 +#include "sta_info.h"
31531 +
31532 +#define RATE_CONTROL_NUM_DOWN 20
31533 +#define RATE_CONTROL_NUM_UP 15
31534 +
31535 +
31536 +struct rate_control_extra {
31537 + /* values from rate_control_get_rate() to the caller: */
31538 + struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
31539 + * probing */
31540 + int startidx, endidx, rateidx;
31541 + struct ieee80211_rate *nonerp;
31542 + int nonerp_idx;
31543 +
31544 + /* parameters from the caller to rate_control_get_rate(): */
31545 + int mgmt_data; /* this is data frame that is used for management
31546 + * (e.g., IEEE 802.1X EAPOL) */
31547 + u16 ethertype;
31548 +};
31549 +
31550 +
31551 +struct rate_control_ops {
31552 + const char *name;
31553 + void (*tx_status)(struct net_device *dev, struct sk_buff *skb,
31554 + struct ieee80211_tx_status *status);
31555 + struct ieee80211_rate *
31556 + (*get_rate)(struct net_device *dev, struct sk_buff *skb,
31557 + struct rate_control_extra *extra);
31558 + void (*rate_init)(struct ieee80211_local *local, struct sta_info *sta);
31559 + void (*clear)(void *priv);
31560 + int (*status_sta)(struct ieee80211_local *local,
31561 + struct sta_info *sta, char *buf);
31562 + int (*status_global)(struct ieee80211_local *local, char *buf);
31563 +
31564 + void * (*alloc)(struct ieee80211_local *local);
31565 + void (*free)(void *priv);
31566 + void * (*alloc_sta)(void);
31567 + void (*free_sta)(void *priv);
31568 +};
31569 +
31570 +
31571 +int ieee80211_rate_control_register(struct rate_control_ops *ops);
31572 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
31573 +
31574 +
31575 +static inline void rate_control_tx_status(struct net_device *dev,
31576 + struct sk_buff *skb,
31577 + struct ieee80211_tx_status *status)
31578 +{
31579 + struct ieee80211_local *local = dev->priv;
31580 + local->rate_ctrl->tx_status(dev, skb, status);
31581 +}
31582 +
31583 +
31584 +static inline struct ieee80211_rate *
31585 +rate_control_get_rate(struct net_device *dev, struct sk_buff *skb,
31586 + struct rate_control_extra *extra)
31587 +{
31588 + struct ieee80211_local *local = dev->priv;
31589 + return local->rate_ctrl->get_rate(dev, skb, extra);
31590 +}
31591 +
31592 +
31593 +static inline void rate_control_rate_init(struct ieee80211_local *local,
31594 + struct sta_info *sta)
31595 +{
31596 + local->rate_ctrl->rate_init(local, sta);
31597 +}
31598 +
31599 +
31600 +static inline void rate_control_clear(struct ieee80211_local *local)
31601 +{
31602 + local->rate_ctrl->clear(local->rate_ctrl_priv);
31603 +}
31604 +
31605 +
31606 +static inline int rate_control_status_sta(struct ieee80211_local *local,
31607 + struct sta_info *sta, char *buf)
31608 +{
31609 + return local->rate_ctrl->status_sta(local, sta, buf);
31610 +}
31611 +
31612 +
31613 +static inline int rate_control_status_global(struct ieee80211_local *local,
31614 + char *buf)
31615 +{
31616 + return local->rate_ctrl->status_global(local, buf);
31617 +}
31618 +
31619 +
31620 +static inline void * rate_control_alloc(struct ieee80211_local *local)
31621 +{
31622 + return local->rate_ctrl->alloc(local);
31623 +}
31624 +
31625 +
31626 +static inline void rate_control_free(struct ieee80211_local *local)
31627 +{
31628 + if (local->rate_ctrl == NULL || local->rate_ctrl_priv == NULL)
31629 + return;
31630 + local->rate_ctrl->free(local->rate_ctrl_priv);
31631 + local->rate_ctrl_priv = NULL;
31632 +}
31633 +
31634 +
31635 +static inline void * rate_control_alloc_sta(struct ieee80211_local *local)
31636 +{
31637 + return local->rate_ctrl->alloc_sta();
31638 +}
31639 +
31640 +
31641 +static inline void rate_control_free_sta(struct ieee80211_local *local,
31642 + void *priv)
31643 +{
31644 + local->rate_ctrl->free_sta(priv);
31645 +}
31646 +
31647 +#endif /* RATE_CONTROL */
31648 diff -Nur linux-2.6.16/net/d80211/sta_info.c linux-2.6.16-bcm43xx/net/d80211/sta_info.c
31649 --- linux-2.6.16/net/d80211/sta_info.c 1970-01-01 01:00:00.000000000 +0100
31650 +++ linux-2.6.16-bcm43xx/net/d80211/sta_info.c 2006-03-28 22:16:14.000000000 +0200
31651 @@ -0,0 +1,413 @@
31652 +/*
31653 + * Copyright 2002-2005, Instant802 Networks, Inc.
31654 + *
31655 + * This program is free software; you can redistribute it and/or modify
31656 + * it under the terms of the GNU General Public License version 2 as
31657 + * published by the Free Software Foundation.
31658 + */
31659 +
31660 +#include <linux/config.h>
31661 +#include <linux/version.h>
31662 +#include <linux/module.h>
31663 +#include <linux/init.h>
31664 +#include <linux/netdevice.h>
31665 +#include <linux/types.h>
31666 +#include <linux/slab.h>
31667 +#include <linux/skbuff.h>
31668 +#include <linux/if_arp.h>
31669 +
31670 +#include <net/d80211.h>
31671 +#include "ieee80211_i.h"
31672 +#include "ieee80211_proc.h"
31673 +#include "rate_control.h"
31674 +
31675 +
31676 +/* Caller must hold local->sta_lock */
31677 +static void sta_info_hash_add(struct ieee80211_local *local,
31678 + struct sta_info *sta)
31679 +{
31680 + sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
31681 + local->sta_hash[STA_HASH(sta->addr)] = sta;
31682 +}
31683 +
31684 +
31685 +/* Caller must hold local->sta_lock */
31686 +static void sta_info_hash_del(struct ieee80211_local *local,
31687 + struct sta_info *sta)
31688 +{
31689 + struct sta_info *s;
31690 +
31691 + s = local->sta_hash[STA_HASH(sta->addr)];
31692 + if (s == NULL)
31693 + return;
31694 + if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
31695 + local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
31696 + return;
31697 + }
31698 +
31699 + while (s->hnext != NULL &&
31700 + memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
31701 + s = s->hnext;
31702 + if (s->hnext != NULL)
31703 + s->hnext = s->hnext->hnext;
31704 + else
31705 + printk(KERN_ERR "%s: could not remove STA " MACSTR " from "
31706 + "hash table\n", local->mdev->name, MAC2STR(sta->addr));
31707 +}
31708 +
31709 +
31710 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr)
31711 +{
31712 + struct sta_info *sta;
31713 +
31714 + spin_lock_bh(&local->sta_lock);
31715 + sta = local->sta_hash[STA_HASH(addr)];
31716 + while (sta) {
31717 + if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
31718 + atomic_inc(&sta->users);
31719 + break;
31720 + }
31721 + sta = sta->hnext;
31722 + }
31723 + spin_unlock_bh(&local->sta_lock);
31724 +
31725 + return sta;
31726 +}
31727 +
31728 +
31729 +int sta_info_min_txrate_get(struct ieee80211_local *local)
31730 +{
31731 + struct sta_info *sta;
31732 + int min_txrate = 9999999;
31733 + int i;
31734 +
31735 + spin_lock_bh(&local->sta_lock);
31736 + for (i = 0; i < STA_HASH_SIZE; i++) {
31737 + sta = local->sta_hash[i];
31738 + while (sta) {
31739 + if (sta->txrate < min_txrate)
31740 + min_txrate = sta->txrate;
31741 + sta = sta->hnext;
31742 + }
31743 + }
31744 + spin_unlock_bh(&local->sta_lock);
31745 + if (min_txrate == 9999999)
31746 + min_txrate = 0;
31747 +
31748 + return min_txrate;
31749 +}
31750 +
31751 +
31752 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta)
31753 +{
31754 + struct sk_buff *skb;
31755 +
31756 + if (!atomic_dec_and_test(&sta->users))
31757 + return;
31758 +
31759 + /* free sta structure; it has already been removed from
31760 + * hash table etc. external structures. Make sure that all
31761 + * buffered frames are release (one might have been added
31762 + * after sta_info_free() was called). */
31763 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31764 + local->total_ps_buffered--;
31765 + dev_kfree_skb_any(skb);
31766 + }
31767 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31768 + dev_kfree_skb_any(skb);
31769 + }
31770 + rate_control_free_sta(local, sta->rate_ctrl_priv);
31771 + kfree(sta);
31772 +}
31773 +
31774 +
31775 +struct sta_info * sta_info_add(struct ieee80211_local *local,
31776 + struct net_device *dev, u8 *addr)
31777 +{
31778 + struct sta_info *sta;
31779 +
31780 + sta = kmalloc(sizeof(*sta), GFP_ATOMIC);
31781 + if (!sta)
31782 + return NULL;
31783 +
31784 + memset(sta, 0, sizeof(*sta));
31785 +
31786 + sta->rate_ctrl_priv = rate_control_alloc_sta(local);
31787 + if (sta->rate_ctrl_priv == NULL) {
31788 + kfree(sta);
31789 + return NULL;
31790 + }
31791 +
31792 + memcpy(sta->addr, addr, ETH_ALEN);
31793 + sta->dev = dev;
31794 + skb_queue_head_init(&sta->ps_tx_buf);
31795 + skb_queue_head_init(&sta->tx_filtered);
31796 + atomic_inc(&sta->users); /* sta in hashlist etc, decremented by
31797 + * sta_info_free() */
31798 + atomic_inc(&sta->users); /* sta used by caller, decremented by
31799 + * sta_info_release() */
31800 + spin_lock_bh(&local->sta_lock);
31801 + list_add(&sta->list, &local->sta_list);
31802 + local->num_sta++;
31803 + sta_info_hash_add(local, sta);
31804 + spin_unlock_bh(&local->sta_lock);
31805 + if (local->hw->sta_table_notification)
31806 + local->hw->sta_table_notification(local->mdev, local->num_sta);
31807 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
31808 +
31809 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31810 + printk(KERN_DEBUG "%s: Added STA " MACSTR "\n",
31811 + local->mdev->name, MAC2STR(addr));
31812 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31813 +
31814 + if (!in_interrupt()) {
31815 + ieee80211_proc_init_sta(local, sta);
31816 + } else {
31817 + /* procfs entry adding might sleep, so schedule process context
31818 + * task for adding proc entry for STAs that do not yet have
31819 + * one. */
31820 + schedule_work(&local->sta_proc_add);
31821 + }
31822 +
31823 + return sta;
31824 +}
31825 +
31826 +
31827 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
31828 + int locked)
31829 +{
31830 + struct sk_buff *skb;
31831 + struct ieee80211_sub_if_data *sdata;
31832 +
31833 + if (!locked)
31834 + spin_lock_bh(&local->sta_lock);
31835 + sta_info_hash_del(local, sta);
31836 + list_del(&sta->list);
31837 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31838 + if (sta->flags & WLAN_STA_PS) {
31839 + sta->flags &= ~WLAN_STA_PS;
31840 + if (sdata->bss)
31841 + atomic_dec(&sdata->bss->num_sta_ps);
31842 + }
31843 + local->num_sta--;
31844 + sta_info_remove_aid_ptr(sta);
31845 + if (!locked)
31846 + spin_unlock_bh(&local->sta_lock);
31847 + if (local->hw->sta_table_notification)
31848 + local->hw->sta_table_notification(local->mdev, local->num_sta);
31849 +
31850 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31851 + local->total_ps_buffered--;
31852 + dev_kfree_skb_any(skb);
31853 + }
31854 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31855 + dev_kfree_skb_any(skb);
31856 + }
31857 +
31858 + if (sta->key) {
31859 + if (local->hw->set_key) {
31860 + struct ieee80211_key_conf *key;
31861 + key = ieee80211_key_data2conf(local, sta->key);
31862 + if (key) {
31863 + local->hw->set_key(local->mdev, DISABLE_KEY,
31864 + sta->addr, key, sta->aid);
31865 + kfree(key);
31866 + }
31867 + }
31868 + kfree(sta->key);
31869 + sta->key = NULL;
31870 + } else if (sta->key_idx_compression != HW_KEY_IDX_INVALID) {
31871 + struct ieee80211_key_conf conf;
31872 + memset(&conf, 0, sizeof(conf));
31873 + conf.hw_key_idx = sta->key_idx_compression;
31874 + conf.alg = ALG_NULL;
31875 + conf.force_sw_encrypt = 1;
31876 + local->hw->set_key(local->mdev, DISABLE_KEY, sta->addr, &conf,
31877 + sta->aid);
31878 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
31879 + }
31880 +
31881 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31882 + printk(KERN_DEBUG "%s: Removed STA " MACSTR "\n",
31883 + local->mdev->name, MAC2STR(sta->addr));
31884 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31885 +
31886 + ieee80211_proc_deinit_sta(local, sta);
31887 +
31888 + if (atomic_read(&sta->users) != 1) {
31889 + /* This is OK, but printed for debugging. The station structure
31890 + * will be removed when the other user of the data calls
31891 + * sta_info_release(). */
31892 + printk(KERN_DEBUG "%s: STA " MACSTR " users count %d when "
31893 + "removing it\n", local->mdev->name, MAC2STR(sta->addr),
31894 + atomic_read(&sta->users));
31895 + }
31896 +
31897 + sta_info_release(local, sta);
31898 +}
31899 +
31900 +
31901 +static inline int sta_info_buffer_expired(struct sk_buff *skb)
31902 +{
31903 + struct ieee80211_tx_packet_data *pkt_data;
31904 + if (!skb)
31905 + return 0;
31906 +
31907 + /* TODO: this could be improved by passing STA listen interval into
31908 + * the kernel driver and expiring frames after 2 x listen_interval x
31909 + * beacon interval */
31910 +
31911 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
31912 + return time_after(jiffies, pkt_data->jiffies + STA_TX_BUFFER_EXPIRE);
31913 +}
31914 +
31915 +
31916 +static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
31917 + struct sta_info *sta)
31918 +{
31919 + unsigned long flags;
31920 + struct sk_buff *skb;
31921 +
31922 + if (skb_queue_empty(&sta->ps_tx_buf))
31923 + return;
31924 +
31925 + for (;;) {
31926 + spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
31927 + skb = skb_peek(&sta->ps_tx_buf);
31928 + if (sta_info_buffer_expired(skb))
31929 + skb = __skb_dequeue(&sta->ps_tx_buf);
31930 + else
31931 + skb = NULL;
31932 + spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
31933 +
31934 + if (skb) {
31935 + local->total_ps_buffered--;
31936 + printk(KERN_DEBUG "Buffered frame expired (STA "
31937 + MACSTR ")\n", MAC2STR(sta->addr));
31938 + dev_kfree_skb(skb);
31939 + } else
31940 + break;
31941 + }
31942 +}
31943 +
31944 +
31945 +static void sta_info_cleanup(unsigned long data)
31946 +{
31947 + struct ieee80211_local *local = (struct ieee80211_local *) data;
31948 + struct list_head *ptr;
31949 +
31950 + spin_lock_bh(&local->sta_lock);
31951 + ptr = local->sta_list.next;
31952 + while (ptr && ptr != &local->sta_list) {
31953 + struct sta_info *sta = (struct sta_info *) ptr;
31954 + atomic_inc(&sta->users);
31955 + sta_info_cleanup_expire_buffered(local, sta);
31956 + sta_info_release(local, sta);
31957 + ptr = ptr->next;
31958 + }
31959 + spin_unlock_bh(&local->sta_lock);
31960 +
31961 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
31962 + add_timer(&local->sta_cleanup);
31963 +}
31964 +
31965 +
31966 +static void sta_info_proc_add_task(void *data)
31967 +{
31968 + struct ieee80211_local *local = data;
31969 + struct list_head *ptr;
31970 + struct sta_info *sta;
31971 + int max_adds = 100;
31972 +
31973 + while (max_adds > 0) {
31974 + sta = NULL;
31975 + spin_lock_bh(&local->sta_lock);
31976 + list_for_each(ptr, &local->sta_list) {
31977 + sta = list_entry(ptr, struct sta_info, list);
31978 + if (!sta->proc_entry_added) {
31979 + atomic_inc(&sta->users);
31980 + break;
31981 + }
31982 + sta = NULL;
31983 + }
31984 + spin_unlock_bh(&local->sta_lock);
31985 +
31986 + if (!sta)
31987 + break;
31988 +
31989 + ieee80211_proc_init_sta(local, sta);
31990 + atomic_dec(&sta->users);
31991 +
31992 + max_adds--;
31993 + }
31994 +}
31995 +
31996 +
31997 +void sta_info_init(struct ieee80211_local *local)
31998 +{
31999 + spin_lock_init(&local->sta_lock);
32000 + INIT_LIST_HEAD(&local->sta_list);
32001 +
32002 + init_timer(&local->sta_cleanup);
32003 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
32004 + local->sta_cleanup.data = (unsigned long) local;
32005 + local->sta_cleanup.function = sta_info_cleanup;
32006 +
32007 + INIT_WORK(&local->sta_proc_add, sta_info_proc_add_task, local);
32008 +}
32009 +
32010 +void sta_info_start(struct ieee80211_local *local)
32011 +{
32012 + add_timer(&local->sta_cleanup);
32013 +}
32014 +
32015 +void sta_info_stop(struct ieee80211_local *local)
32016 +{
32017 + struct list_head *ptr;
32018 +
32019 + del_timer(&local->sta_cleanup);
32020 +
32021 + ptr = local->sta_list.next;
32022 + while (ptr && ptr != &local->sta_list) {
32023 + struct sta_info *sta = (struct sta_info *) ptr;
32024 + ptr = ptr->next;
32025 + sta_info_free(local, sta, 0);
32026 + }
32027 +}
32028 +
32029 +
32030 +void sta_info_remove_aid_ptr(struct sta_info *sta)
32031 +{
32032 + struct ieee80211_sub_if_data *sdata;
32033 +
32034 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
32035 + if (sta->aid <= 0 || !sdata->bss)
32036 + return;
32037 +
32038 + sdata->bss->sta_aid[sta->aid - 1] = NULL;
32039 + if (sta->aid == sdata->bss->max_aid) {
32040 + while (sdata->bss->max_aid > 0 &&
32041 + sdata->bss->sta_aid[sdata->bss->max_aid - 1] == NULL)
32042 + sdata->bss->max_aid--;
32043 + }
32044 +}
32045 +
32046 +
32047 +/**
32048 + * sta_info_flush - flush matching STA entries from the STA table
32049 + * @local: local interface data
32050 + * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
32051 + */
32052 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
32053 +{
32054 + struct list_head *ptr, *n;
32055 +
32056 + spin_lock_bh(&local->sta_lock);
32057 +
32058 + list_for_each_safe(ptr, n, &local->sta_list) {
32059 + struct sta_info *sta = list_entry(ptr, struct sta_info, list);
32060 + if (dev == NULL || dev == sta->dev)
32061 + sta_info_free(local, sta, 1);
32062 + }
32063 + spin_unlock_bh(&local->sta_lock);
32064 +}
32065 diff -Nur linux-2.6.16/net/d80211/sta_info.h linux-2.6.16-bcm43xx/net/d80211/sta_info.h
32066 --- linux-2.6.16/net/d80211/sta_info.h 1970-01-01 01:00:00.000000000 +0100
32067 +++ linux-2.6.16-bcm43xx/net/d80211/sta_info.h 2006-03-28 22:16:14.000000000 +0200
32068 @@ -0,0 +1,148 @@
32069 +/*
32070 + * Copyright 2002-2005, Devicescape Software, Inc.
32071 + *
32072 + * This program is free software; you can redistribute it and/or modify
32073 + * it under the terms of the GNU General Public License version 2 as
32074 + * published by the Free Software Foundation.
32075 + */
32076 +
32077 +#ifndef STA_INFO_H
32078 +#define STA_INFO_H
32079 +
32080 +#include <linux/if_ether.h>
32081 +#include <linux/types.h>
32082 +#include "ieee80211_i.h"
32083 +#include "ieee80211_key.h"
32084 +
32085 +/* Stations flags (struct sta_info::flags) */
32086 +#define WLAN_STA_AUTH BIT(0)
32087 +#define WLAN_STA_ASSOC BIT(1)
32088 +#define WLAN_STA_PS BIT(2)
32089 +#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
32090 +#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
32091 +#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
32092 + * controlling whether STA is authorized to
32093 + * send and receive non-IEEE 802.1X frames
32094 + */
32095 +#define WLAN_STA_SHORT_PREAMBLE BIT(7)
32096 +#define WLAN_STA_WME BIT(9)
32097 +#define WLAN_STA_XR BIT(26)
32098 +#define WLAN_STA_WDS BIT(27)
32099 +
32100 +
32101 +struct sta_info {
32102 + struct list_head list;
32103 + struct sta_info *hnext; /* next entry in hash table list */
32104 + atomic_t users; /* number of users (do not remove if > 0) */
32105 +
32106 + u8 addr[ETH_ALEN];
32107 + u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
32108 + u32 flags; /* WLAN_STA_ */
32109 +
32110 + struct sk_buff_head ps_tx_buf; /* buffer of TX frames for station in
32111 + * power saving state */
32112 + int pspoll; /* whether STA has send a PS Poll frame */
32113 + struct sk_buff_head tx_filtered; /* buffer of TX frames that were
32114 + * already given to low-level driver,
32115 + * but were filtered */
32116 + int clear_dst_mask;
32117 +
32118 + unsigned long rx_packets, tx_packets; /* number of RX/TX MSDUs */
32119 + unsigned long rx_bytes, tx_bytes;
32120 + unsigned long tx_retry_failed, tx_retry_count;
32121 + unsigned long tx_filtered_count;
32122 +
32123 + unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
32124 +
32125 + unsigned long last_rx;
32126 + u32 supp_rates; /* bitmap of supported rates in local->curr_rates */
32127 + int txrate; /* index in local->curr_rates */
32128 + int last_txrate; /* last rate used to send a frame to this STA */
32129 + int last_nonerp_idx;
32130 +
32131 + struct net_device *dev; /* which net device is this station associated
32132 + * to */
32133 +
32134 + struct ieee80211_key *key;
32135 +
32136 + u32 tx_num_consecutive_failures;
32137 + u32 tx_num_mpdu_ok;
32138 + u32 tx_num_mpdu_fail;
32139 +
32140 + void *rate_ctrl_priv;
32141 +
32142 + /* last received seq/frag number from this STA (per RX queue) */
32143 + u16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
32144 + unsigned long num_duplicates; /* number of duplicate frames received
32145 + * from this STA */
32146 + unsigned long tx_fragments; /* number of transmitted MPDUs */
32147 + unsigned long rx_fragments; /* number of received MPDUs */
32148 + unsigned long rx_dropped; /* number of dropped MPDUs from this STA */
32149 +
32150 + int last_rssi; /* RSSI of last received frame from this STA */
32151 + int last_ack_rssi[3]; /* RSSI of last received ACKs from this STA */
32152 + unsigned long last_ack;
32153 + int channel_use;
32154 + int channel_use_raw;
32155 +
32156 + int antenna_sel;
32157 +
32158 +
32159 + int key_idx_compression; /* key table index for compression and TX
32160 + * filtering; used only if sta->key is not
32161 + * set */
32162 +
32163 + int proc_entry_added:1;
32164 + int assoc_ap:1; /* whether this is an AP that we are associated with
32165 + * as a client */
32166 +
32167 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
32168 + u32 wpa_trigger;
32169 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
32170 +
32171 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
32172 + unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
32173 + unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
32174 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
32175 +
32176 + int vlan_id;
32177 +};
32178 +
32179 +
32180 +/* Maximum number of concurrently registered stations */
32181 +#define MAX_STA_COUNT 2007
32182 +
32183 +/* Maximum number of AIDs to use for STAs; must be 2007 or lower
32184 + * (IEEE 802.11 beacon format limitation) */
32185 +#define MAX_AID_TABLE_SIZE 2007
32186 +
32187 +#define STA_HASH_SIZE 256
32188 +#define STA_HASH(sta) (sta[5])
32189 +
32190 +
32191 +/* Maximum number of frames to buffer per power saving station */
32192 +#define STA_MAX_TX_BUFFER 128
32193 +
32194 +/* Buffered frame expiry time */
32195 +#define STA_TX_BUFFER_EXPIRE (10 * HZ)
32196 +
32197 +/* How often station data is cleaned up (e.g., expiration of buffered frames)
32198 + */
32199 +#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
32200 +
32201 +struct ieee80211_local;
32202 +
32203 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
32204 +int sta_info_min_txrate_get(struct ieee80211_local *local);
32205 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta);
32206 +struct sta_info * sta_info_add(struct ieee80211_local *local,
32207 + struct net_device *dev, u8 *addr);
32208 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
32209 + int locked);
32210 +void sta_info_init(struct ieee80211_local *local);
32211 +void sta_info_start(struct ieee80211_local *local);
32212 +void sta_info_stop(struct ieee80211_local *local);
32213 +void sta_info_remove_aid_ptr(struct sta_info *sta);
32214 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev);
32215 +
32216 +#endif /* STA_INFO_H */
32217 diff -Nur linux-2.6.16/net/d80211/tkip.c linux-2.6.16-bcm43xx/net/d80211/tkip.c
32218 --- linux-2.6.16/net/d80211/tkip.c 1970-01-01 01:00:00.000000000 +0100
32219 +++ linux-2.6.16-bcm43xx/net/d80211/tkip.c 2006-03-28 22:16:14.000000000 +0200
32220 @@ -0,0 +1,341 @@
32221 +/*
32222 + * Copyright 2002-2004, Instant802 Networks, Inc.
32223 + * Copyright 2005, Devicescape Software, Inc.
32224 + *
32225 + * This program is free software; you can redistribute it and/or modify
32226 + * it under the terms of the GNU General Public License version 2 as
32227 + * published by the Free Software Foundation.
32228 + */
32229 +
32230 +#ifdef CONFIG_TKIP_DEBUG
32231 +#include <linux/config.h>
32232 +#include <linux/version.h>
32233 +#include <linux/module.h>
32234 +#include <linux/kernel.h>
32235 +#include <linux/skbuff.h>
32236 +#endif /* CONFIG_TKIP_DEBUG */
32237 +
32238 +#include <linux/types.h>
32239 +#include <linux/netdevice.h>
32240 +
32241 +#include <net/d80211.h>
32242 +#include "ieee80211_key.h"
32243 +#ifdef CONFIG_TKIP_DEBUG
32244 +#include "ieee80211_i.h"
32245 +#endif /* CONFIG_TKIP_DEBUG */
32246 +#include "tkip.h"
32247 +
32248 +/* Dummy prototypes for structures used in wep.h, but not really needed for
32249 + * TKIP. */
32250 +struct ieee80211_local;
32251 +struct sk_buff;
32252 +#include "wep.h"
32253 +
32254 +
32255 +/* TKIP key mixing functions */
32256 +
32257 +
32258 +#define PHASE1_LOOP_COUNT 8
32259 +
32260 +
32261 +/* 2-byte by 2-byte subset of the full AES S-box table; second part of this
32262 + * table is identical to first part but byte-swapped */
32263 +static const u16 tkip_sbox[256] =
32264 +{
32265 + 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
32266 + 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
32267 + 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
32268 + 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
32269 + 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
32270 + 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
32271 + 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
32272 + 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
32273 + 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
32274 + 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
32275 + 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
32276 + 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
32277 + 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
32278 + 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
32279 + 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
32280 + 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
32281 + 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
32282 + 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
32283 + 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
32284 + 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
32285 + 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
32286 + 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
32287 + 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
32288 + 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
32289 + 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
32290 + 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
32291 + 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
32292 + 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
32293 + 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
32294 + 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
32295 + 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
32296 + 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
32297 +};
32298 +
32299 +
32300 +static inline u16 Mk16(u8 x, u8 y)
32301 +{
32302 + return ((u16) x << 8) | (u16) y;
32303 +}
32304 +
32305 +
32306 +static inline u8 Hi8(u16 v)
32307 +{
32308 + return v >> 8;
32309 +}
32310 +
32311 +
32312 +static inline u8 Lo8(u16 v)
32313 +{
32314 + return v & 0xff;
32315 +}
32316 +
32317 +
32318 +static inline u16 Hi16(u32 v)
32319 +{
32320 + return v >> 16;
32321 +}
32322 +
32323 +
32324 +static inline u16 Lo16(u32 v)
32325 +{
32326 + return v & 0xffff;
32327 +}
32328 +
32329 +
32330 +static inline u16 RotR1(u16 v)
32331 +{
32332 + return (v >> 1) | ((v & 0x0001) << 15);
32333 +}
32334 +
32335 +
32336 +static inline u16 tkip_S(u16 val)
32337 +{
32338 + u16 a = tkip_sbox[Hi8(val)];
32339 +
32340 + return tkip_sbox[Lo8(val)] ^ Hi8(a) ^ (Lo8(a) << 8);
32341 +}
32342 +
32343 +
32344 +
32345 +/* P1K := Phase1(TA, TK, TSC)
32346 + * TA = transmitter address (48 bits)
32347 + * TK = dot11DefaultKeyValue or dot11KeyMappingValue (128 bits)
32348 + * TSC = TKIP sequence counter (48 bits, only 32 msb bits used)
32349 + * P1K: 80 bits
32350 + */
32351 +static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
32352 + u16 *p1k)
32353 +{
32354 + int i, j;
32355 +
32356 + p1k[0] = Lo16(tsc_IV32);
32357 + p1k[1] = Hi16(tsc_IV32);
32358 + p1k[2] = Mk16(ta[1], ta[0]);
32359 + p1k[3] = Mk16(ta[3], ta[2]);
32360 + p1k[4] = Mk16(ta[5], ta[4]);
32361 +
32362 + for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
32363 + j = 2 * (i & 1);
32364 + p1k[0] += tkip_S(p1k[4] ^ Mk16(tk[ 1 + j], tk[ 0 + j]));
32365 + p1k[1] += tkip_S(p1k[0] ^ Mk16(tk[ 5 + j], tk[ 4 + j]));
32366 + p1k[2] += tkip_S(p1k[1] ^ Mk16(tk[ 9 + j], tk[ 8 + j]));
32367 + p1k[3] += tkip_S(p1k[2] ^ Mk16(tk[13 + j], tk[12 + j]));
32368 + p1k[4] += tkip_S(p1k[3] ^ Mk16(tk[ 1 + j], tk[ 0 + j])) + i;
32369 + }
32370 +}
32371 +
32372 +
32373 +static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
32374 + u8 *rc4key)
32375 +{
32376 + u16 ppk[6];
32377 + int i;
32378 +
32379 + ppk[0] = p1k[0];
32380 + ppk[1] = p1k[1];
32381 + ppk[2] = p1k[2];
32382 + ppk[3] = p1k[3];
32383 + ppk[4] = p1k[4];
32384 + ppk[5] = p1k[4] + tsc_IV16;
32385 +
32386 + ppk[0] += tkip_S(ppk[5] ^ Mk16(tk[ 1], tk[ 0]));
32387 + ppk[1] += tkip_S(ppk[0] ^ Mk16(tk[ 3], tk[ 2]));
32388 + ppk[2] += tkip_S(ppk[1] ^ Mk16(tk[ 5], tk[ 4]));
32389 + ppk[3] += tkip_S(ppk[2] ^ Mk16(tk[ 7], tk[ 6]));
32390 + ppk[4] += tkip_S(ppk[3] ^ Mk16(tk[ 9], tk[ 8]));
32391 + ppk[5] += tkip_S(ppk[4] ^ Mk16(tk[11], tk[10]));
32392 + ppk[0] += RotR1(ppk[5] ^ Mk16(tk[13], tk[12]));
32393 + ppk[1] += RotR1(ppk[0] ^ Mk16(tk[15], tk[14]));
32394 + ppk[2] += RotR1(ppk[1]);
32395 + ppk[3] += RotR1(ppk[2]);
32396 + ppk[4] += RotR1(ppk[3]);
32397 + ppk[5] += RotR1(ppk[4]);
32398 +
32399 + rc4key[0] = Hi8(tsc_IV16);
32400 + rc4key[1] = (Hi8(tsc_IV16) | 0x20) & 0x7f;
32401 + rc4key[2] = Lo8(tsc_IV16);
32402 + rc4key[3] = Lo8((ppk[5] ^ Mk16(tk[1], tk[0])) >> 1);
32403 +
32404 + for (i = 0; i < 6; i++) {
32405 + rc4key[4 + 2 * i] = Lo8(ppk[i]);
32406 + rc4key[5 + 2 * i] = Hi8(ppk[i]);
32407 + }
32408 +}
32409 +
32410 +
32411 +/* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets
32412 + * of the IV. Returns pointer to the octet following IVs (i.e., beginning of
32413 + * the packet payload). */
32414 +u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
32415 + u8 iv0, u8 iv1, u8 iv2)
32416 +{
32417 + *pos++ = iv0;
32418 + *pos++ = iv1;
32419 + *pos++ = iv2;
32420 + *pos++ = (key->keyidx << 6) | (1 << 5) /* Ext IV */;
32421 + *pos++ = key->u.tkip.iv32 & 0xff;
32422 + *pos++ = (key->u.tkip.iv32 >> 8) & 0xff;
32423 + *pos++ = (key->u.tkip.iv32 >> 16) & 0xff;
32424 + *pos++ = (key->u.tkip.iv32 >> 24) & 0xff;
32425 + return pos;
32426 +}
32427 +
32428 +
32429 +/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the
32430 + * beginning of the buffer containing payload. This payload must include
32431 + * headroom of eight octets for IV and Ext. IV and taildroom of four octets
32432 + * for ICV. @payload_len is the length of payload (_not_ including extra
32433 + * headroom and tailroom). @ta is the transmitter addresses. */
32434 +void ieee80211_tkip_encrypt_data(struct ieee80211_key *key, u8 *pos,
32435 + size_t payload_len, u8 *ta)
32436 +{
32437 + u8 rc4key[16];
32438 +
32439 + /* Calculate per-packet key */
32440 + if (key->u.tkip.iv16 == 0 || !key->u.tkip.tx_initialized) {
32441 + /* IV16 wrapped around - perform TKIP phase 1 */
32442 + tkip_mixing_phase1(ta, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32443 + key->u.tkip.iv32, key->u.tkip.p1k);
32444 + key->u.tkip.tx_initialized = 1;
32445 + }
32446 +
32447 + tkip_mixing_phase2(key->u.tkip.p1k, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32448 + key->u.tkip.iv16, rc4key);
32449 +
32450 + pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]);
32451 + ieee80211_wep_encrypt_data(rc4key, 16, pos, payload_len);
32452 +}
32453 +
32454 +
32455 +/* Decrypt packet payload with TKIP using @key. @pos is a pointer to the
32456 + * beginning of the buffer containing IEEE 802.11 header payload, i.e.,
32457 + * including IV, Ext. IV, real data, Michael MIC, ICV. @payload_len is the
32458 + * length of payload, including IV, Ext. IV, MIC, ICV. */
32459 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32460 + size_t payload_len, u8 *ta, int only_iv,
32461 + int queue)
32462 +{
32463 + u32 iv32;
32464 + u32 iv16;
32465 + u8 rc4key[16], keyid, *pos = payload;
32466 + int res;
32467 +
32468 + if (payload_len < 12)
32469 + return -1;
32470 +
32471 + iv16 = (pos[0] << 8) | pos[2];
32472 + keyid = pos[3];
32473 + iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
32474 + pos += 8;
32475 +#ifdef CONFIG_TKIP_DEBUG
32476 + {
32477 + int i;
32478 + printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len);
32479 + for (i = 0; i < payload_len; i++)
32480 + printk(" %02x", payload[i]);
32481 + printk("\n");
32482 + printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n",
32483 + iv16, iv32);
32484 + }
32485 +#endif /* CONFIG_TKIP_DEBUG */
32486 +
32487 + if (!(keyid & (1 << 5)))
32488 + return TKIP_DECRYPT_NO_EXT_IV;
32489 +
32490 + if ((keyid >> 6) != key->keyidx)
32491 + return TKIP_DECRYPT_INVALID_KEYIDX;
32492 +
32493 + if (key->u.tkip.rx_initialized[queue] &&
32494 + (iv32 < key->u.tkip.iv32_rx[queue] ||
32495 + (iv32 == key->u.tkip.iv32_rx[queue] &&
32496 + iv16 <= key->u.tkip.iv16_rx[queue]))) {
32497 +#ifdef CONFIG_TKIP_DEBUG
32498 + printk(KERN_DEBUG "TKIP replay detected for RX frame from "
32499 + MACSTR " (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
32500 + MAC2STR(ta),
32501 + iv32, iv16, key->u.tkip.iv32_rx[queue],
32502 + key->u.tkip.iv16_rx[queue]);
32503 +#endif /* CONFIG_TKIP_DEBUG */
32504 + return TKIP_DECRYPT_REPLAY;
32505 + }
32506 +
32507 + if (only_iv) {
32508 + res = TKIP_DECRYPT_OK;
32509 + goto done;
32510 + }
32511 +
32512 + if (!key->u.tkip.rx_initialized[queue] ||
32513 + key->u.tkip.iv32_rx[queue] != iv32) {
32514 + key->u.tkip.rx_initialized[queue] = 1;
32515 + /* IV16 wrapped around - perform TKIP phase 1 */
32516 + tkip_mixing_phase1(ta, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32517 + iv32, key->u.tkip.p1k_rx[queue]);
32518 +#ifdef CONFIG_TKIP_DEBUG
32519 + {
32520 + int i;
32521 + printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=" MACSTR
32522 + " TK=", MAC2STR(ta));
32523 + for (i = 0; i < 16; i++)
32524 + printk("%02x ",
32525 + key->key[ALG_TKIP_TEMP_ENCR_KEY + i]);
32526 + printk("\n");
32527 + printk(KERN_DEBUG "TKIP decrypt: P1K=");
32528 + for (i = 0; i < 5; i++)
32529 + printk("%04x ", key->u.tkip.p1k_rx[queue][i]);
32530 + printk("\n");
32531 + }
32532 +#endif /* CONFIG_TKIP_DEBUG */
32533 + }
32534 +
32535 + tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
32536 + &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32537 + iv16, rc4key);
32538 +#ifdef CONFIG_TKIP_DEBUG
32539 + {
32540 + int i;
32541 + printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key=");
32542 + for (i = 0; i < 16; i++)
32543 + printk("%02x ", rc4key[i]);
32544 + printk("\n");
32545 + }
32546 +#endif /* CONFIG_TKIP_DEBUG */
32547 +
32548 + res = ieee80211_wep_decrypt_data(rc4key, 16, pos, payload_len - 12);
32549 + done:
32550 + if (res == TKIP_DECRYPT_OK) {
32551 + /* FIX: these should be updated only after Michael MIC has been
32552 + * verified */
32553 + /* Record previously received IV */
32554 + key->u.tkip.iv32_rx[queue] = iv32;
32555 + key->u.tkip.iv16_rx[queue] = iv16;
32556 + }
32557 +
32558 + return res;
32559 +}
32560 +
32561 +
32562 diff -Nur linux-2.6.16/net/d80211/tkip.h linux-2.6.16-bcm43xx/net/d80211/tkip.h
32563 --- linux-2.6.16/net/d80211/tkip.h 1970-01-01 01:00:00.000000000 +0100
32564 +++ linux-2.6.16-bcm43xx/net/d80211/tkip.h 2006-03-28 22:16:14.000000000 +0200
32565 @@ -0,0 +1,29 @@
32566 +/*
32567 + * Copyright 2002-2004, Instant802 Networks, Inc.
32568 + *
32569 + * This program is free software; you can redistribute it and/or modify
32570 + * it under the terms of the GNU General Public License version 2 as
32571 + * published by the Free Software Foundation.
32572 + */
32573 +
32574 +#ifndef TKIP_H
32575 +#define TKIP_H
32576 +
32577 +#include <linux/types.h>
32578 +#include "ieee80211_key.h"
32579 +
32580 +u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
32581 + u8 iv0, u8 iv1, u8 iv2);
32582 +void ieee80211_tkip_encrypt_data(struct ieee80211_key *key, u8 *pos,
32583 + size_t payload_len, u8 *ta);
32584 +enum {
32585 + TKIP_DECRYPT_OK = 0,
32586 + TKIP_DECRYPT_NO_EXT_IV = -1,
32587 + TKIP_DECRYPT_INVALID_KEYIDX = -2,
32588 + TKIP_DECRYPT_REPLAY = -3,
32589 +};
32590 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32591 + size_t payload_len, u8 *ta, int only_iv,
32592 + int queue);
32593 +
32594 +#endif /* TKIP_H */
32595 diff -Nur linux-2.6.16/net/d80211/wep.c linux-2.6.16-bcm43xx/net/d80211/wep.c
32596 --- linux-2.6.16/net/d80211/wep.c 1970-01-01 01:00:00.000000000 +0100
32597 +++ linux-2.6.16-bcm43xx/net/d80211/wep.c 2006-03-28 22:16:14.000000000 +0200
32598 @@ -0,0 +1,423 @@
32599 +/*
32600 + * Software WEP encryption implementation
32601 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
32602 + * Copyright 2003, Instant802 Networks, Inc.
32603 + *
32604 + * This program is free software; you can redistribute it and/or modify
32605 + * it under the terms of the GNU General Public License version 2 as
32606 + * published by the Free Software Foundation.
32607 + */
32608 +
32609 +#include <linux/config.h>
32610 +#include <linux/version.h>
32611 +#include <linux/netdevice.h>
32612 +#include <linux/types.h>
32613 +#include <linux/random.h>
32614 +#include <linux/compiler.h>
32615 +
32616 +#include <net/d80211.h>
32617 +#include "ieee80211_i.h"
32618 +#include "wep.h"
32619 +
32620 +
32621 +static const __u32 crc32_table[256] = {
32622 + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
32623 + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
32624 + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
32625 + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
32626 + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
32627 + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
32628 + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
32629 + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
32630 + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
32631 + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
32632 + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
32633 + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
32634 + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
32635 + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
32636 + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
32637 + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
32638 + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
32639 + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
32640 + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
32641 + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
32642 + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
32643 + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
32644 + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
32645 + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
32646 + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
32647 + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
32648 + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
32649 + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
32650 + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
32651 + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
32652 + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
32653 + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
32654 + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
32655 + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
32656 + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
32657 + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
32658 + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
32659 + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
32660 + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
32661 + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
32662 + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
32663 + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
32664 + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
32665 + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
32666 + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
32667 + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
32668 + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
32669 + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
32670 + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
32671 + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
32672 + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
32673 + 0x2d02ef8dL
32674 +};
32675 +
32676 +
32677 +void ieee80211_wep_init(struct ieee80211_local *local)
32678 +{
32679 + /* start WEP IV from a random value */
32680 + get_random_bytes(&local->wep_iv, WEP_IV_LEN);
32681 +}
32682 +
32683 +
32684 +static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
32685 +{
32686 + /* Fluhrer, Mantin, and Shamir have reported weaknesses in the
32687 + * key scheduling algorithm of RC4. At least IVs (KeyByte + 3,
32688 + * 0xff, N) can be used to speedup attacks, so avoid using them. */
32689 + if ((iv & 0xff00) == 0xff00) {
32690 + u8 B = (iv >> 16) & 0xff;
32691 + if (B >= 3 && B < 3 + keylen)
32692 + return 1;
32693 + }
32694 + return 0;
32695 +}
32696 +
32697 +
32698 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
32699 + struct ieee80211_key *key, u8 *iv)
32700 +{
32701 + local->wep_iv++;
32702 + if (ieee80211_wep_weak_iv(local->wep_iv, key->keylen))
32703 + local->wep_iv += 0x0100;
32704 +
32705 + if (iv == NULL)
32706 + return;
32707 +
32708 + *iv++ = (local->wep_iv >> 16) & 0xff;
32709 + *iv++ = (local->wep_iv >> 8) & 0xff;
32710 + *iv++ = local->wep_iv & 0xff;
32711 + *iv++ = key->keyidx << 6;
32712 +}
32713 +
32714 +
32715 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
32716 + struct sk_buff *skb,
32717 + struct ieee80211_key *key)
32718 +{
32719 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32720 + u16 fc;
32721 + int hdrlen;
32722 + u8 *newhdr;
32723 +
32724 + fc = le16_to_cpu(hdr->frame_control);
32725 + fc |= WLAN_FC_ISWEP;
32726 + hdr->frame_control = cpu_to_le16(fc);
32727 +
32728 + if ((skb_headroom(skb) < WEP_IV_LEN ||
32729 + skb_tailroom(skb) < WEP_ICV_LEN)) {
32730 + I802_DEBUG_INC(local->tx_expand_skb_head);
32731 + if (unlikely(pskb_expand_head(skb, WEP_IV_LEN, WEP_ICV_LEN,
32732 + GFP_ATOMIC)))
32733 + return NULL;
32734 + }
32735 +
32736 + hdrlen = ieee80211_get_hdrlen(fc);
32737 + newhdr = skb_push(skb, WEP_IV_LEN);
32738 + memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen);
32739 + ieee80211_wep_get_iv(local, key, newhdr + hdrlen);
32740 + return newhdr + hdrlen;
32741 +}
32742 +
32743 +
32744 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
32745 + struct sk_buff *skb,
32746 + struct ieee80211_key *key)
32747 +{
32748 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32749 + u16 fc;
32750 + int hdrlen;
32751 +
32752 + fc = le16_to_cpu(hdr->frame_control);
32753 + hdrlen = ieee80211_get_hdrlen(fc);
32754 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
32755 + skb_pull(skb, WEP_IV_LEN);
32756 +}
32757 +
32758 +
32759 +/* Perform WEP encryption using given key. data buffer must have tailroom
32760 + * for 4-byte ICV. data_len must not include this ICV. Note: this function
32761 + * does _not_ add IV. data = RC4(data | CRC32(data)) */
32762 +void ieee80211_wep_encrypt_data(u8 *rc4key, size_t klen, u8 *data,
32763 + size_t data_len)
32764 +{
32765 + u32 i, j, k, crc;
32766 + u8 S[256];
32767 + u8 kpos, *pos;
32768 +#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
32769 +
32770 + /* Setup RC4 state */
32771 + for (i = 0; i < 256; i++)
32772 + S[i] = i;
32773 + j = 0;
32774 + kpos = 0;
32775 + for (i = 0; i < 256; i++) {
32776 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32777 + kpos++;
32778 + if (kpos >= klen)
32779 + kpos = 0;
32780 + S_SWAP(i, j);
32781 + }
32782 +
32783 + /* Compute CRC32 over unencrypted data and apply RC4 to data */
32784 + pos = data;
32785 + crc = ~0;
32786 + i = j = 0;
32787 + for (k = 0; k < data_len; k++) {
32788 + crc = crc32_table[(crc ^ *pos) & 0xff] ^ (crc >> 8);
32789 + i = (i + 1) & 0xff;
32790 + j = (j + S[i]) & 0xff;
32791 + S_SWAP(i, j);
32792 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32793 + }
32794 + crc = ~crc;
32795 +
32796 + /* Append little-endian CRC32 and encrypt it to produce ICV */
32797 + pos[0] = crc;
32798 + pos[1] = crc >> 8;
32799 + pos[2] = crc >> 16;
32800 + pos[3] = crc >> 24;
32801 + for (k = 0; k < 4; k++) {
32802 + i = (i + 1) & 0xff;
32803 + j = (j + S[i]) & 0xff;
32804 + S_SWAP(i, j);
32805 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32806 + }
32807 +}
32808 +
32809 +
32810 +/* Perform WEP encryption on given skb. 4 bytes of extra space (IV) in the
32811 + * beginning of the buffer 4 bytes of extra space (ICV) in the end of the
32812 + * buffer will be added. Both IV and ICV will be transmitted, so the
32813 + * payload length increases with 8 bytes.
32814 + *
32815 + * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
32816 + */
32817 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
32818 + struct ieee80211_key *key)
32819 +{
32820 + u32 klen;
32821 + u8 *rc4key, *iv;
32822 + size_t len;
32823 +
32824 + if (key == NULL || key->alg != ALG_WEP)
32825 + return -1;
32826 +
32827 + klen = 3 + key->keylen;
32828 + rc4key = kmalloc(klen, GFP_ATOMIC);
32829 + if (rc4key == NULL)
32830 + return -1;
32831 +
32832 + iv = ieee80211_wep_add_iv(local, skb, key);
32833 + if (iv == NULL) {
32834 + kfree(rc4key);
32835 + return -1;
32836 + }
32837 +
32838 + len = skb->len - (iv + WEP_IV_LEN - skb->data);
32839 +
32840 + /* Prepend 24-bit IV to RC4 key */
32841 + memcpy(rc4key, iv, 3);
32842 +
32843 + /* Copy rest of the WEP key (the secret part) */
32844 + memcpy(rc4key + 3, key->key, key->keylen);
32845 +
32846 + /* Add room for ICV */
32847 + skb_put(skb, WEP_ICV_LEN);
32848 +
32849 + ieee80211_wep_encrypt_data(rc4key, klen, iv + WEP_IV_LEN, len);
32850 +
32851 + kfree(rc4key);
32852 +
32853 + return 0;
32854 +}
32855 +
32856 +
32857 +/* Perform WEP decryption using given key. data buffer includes encrypted
32858 + * payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
32859 + * Return 0 on success and -1 on ICV mismatch. */
32860 +int ieee80211_wep_decrypt_data(u8 *rc4key, size_t klen, u8 *data,
32861 + size_t data_len)
32862 +{
32863 + u32 i, j, k, crc;
32864 + u8 S[256];
32865 + u8 kpos, *pos, crcbuf[WEP_ICV_LEN], *cpos;
32866 +
32867 + /* Setup RC4 state */
32868 + for (i = 0; i < 256; i++)
32869 + S[i] = i;
32870 + j = 0;
32871 + kpos = 0;
32872 + for (i = 0; i < 256; i++) {
32873 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32874 + kpos++;
32875 + if (kpos >= klen)
32876 + kpos = 0;
32877 + S_SWAP(i, j);
32878 + }
32879 +
32880 + /* Apply RC4 to data and compute CRC32 over decrypted data */
32881 + pos = data;
32882 + crc = ~0;
32883 + i = j = 0;
32884 + for (k = 0; k < data_len; k++) {
32885 + i = (i + 1) & 0xff;
32886 + j = (j + S[i]) & 0xff;
32887 + S_SWAP(i, j);
32888 + *pos ^= S[(S[i] + S[j]) & 0xff];
32889 + crc = crc32_table[(crc ^ *pos++) & 0xff] ^ (crc >> 8);
32890 + }
32891 + crc = ~crc;
32892 +
32893 + /* Decrypt little-endian CRC32 and verify that it matches with the
32894 + * received ICV */
32895 + cpos = crcbuf;
32896 + crcbuf[0] = crc;
32897 + crcbuf[1] = crc >> 8;
32898 + crcbuf[2] = crc >> 16;
32899 + crcbuf[3] = crc >> 24;
32900 + for (k = 0; k < WEP_ICV_LEN; k++) {
32901 + i = (i + 1) & 0xff;
32902 + j = (j + S[i]) & 0xff;
32903 + S_SWAP(i, j);
32904 + if (*cpos++ != (*pos++ ^ S[(S[i] + S[j]) & 0xff])) {
32905 + /* ICV mismatch */
32906 + return -1;
32907 + }
32908 + }
32909 +
32910 + return 0;
32911 +}
32912 +
32913 +
32914 +/* Perform WEP decryption on given skb. Buffer includes whole WEP part of
32915 + * the frame: IV (4 bytes), encrypted payload (including SNAP header),
32916 + * ICV (4 bytes). skb->len includes both IV and ICV.
32917 + *
32918 + * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on
32919 + * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload
32920 + * is moved to the beginning of the skb and skb length will be reduced.
32921 + */
32922 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
32923 + struct ieee80211_key *key)
32924 +{
32925 + u32 klen;
32926 + u8 *rc4key;
32927 + u8 keyidx;
32928 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32929 + u16 fc;
32930 + int hdrlen;
32931 + size_t len;
32932 + int ret = 0;
32933 +
32934 + fc = le16_to_cpu(hdr->frame_control);
32935 + if (!(fc & WLAN_FC_ISWEP))
32936 + return -1;
32937 +
32938 + hdrlen = ieee80211_get_hdrlen(fc);
32939 +
32940 + if (skb->len < 8 + hdrlen)
32941 + return -1;
32942 +
32943 + len = skb->len - hdrlen - 8;
32944 +
32945 + keyidx = skb->data[hdrlen + 3] >> 6;
32946 +
32947 + if (key == NULL || keyidx != key->keyidx || key->alg != ALG_WEP)
32948 + return -1;
32949 +
32950 + klen = 3 + key->keylen;
32951 +
32952 + rc4key = kmalloc(klen, GFP_ATOMIC);
32953 + if (rc4key == NULL)
32954 + return -1;
32955 +
32956 + /* Prepend 24-bit IV to RC4 key */
32957 + memcpy(rc4key, skb->data + hdrlen, 3);
32958 +
32959 + /* Copy rest of the WEP key (the secret part) */
32960 + memcpy(rc4key + 3, key->key, key->keylen);
32961 +
32962 + if (ieee80211_wep_decrypt_data(rc4key, klen,
32963 + skb->data + hdrlen + WEP_IV_LEN,
32964 + len)) {
32965 + printk(KERN_DEBUG "WEP decrypt failed (ICV)\n");
32966 + ret = -1;
32967 + }
32968 +
32969 + kfree(rc4key);
32970 +
32971 + /* Trim ICV */
32972 + skb_trim(skb, skb->len - WEP_ICV_LEN);
32973 +
32974 + /* Remove IV */
32975 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
32976 + skb_pull(skb, WEP_IV_LEN);
32977 +
32978 + return ret;
32979 +}
32980 +
32981 +
32982 +int ieee80211_wep_get_keyidx(struct sk_buff *skb)
32983 +{
32984 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32985 + u16 fc;
32986 + int hdrlen;
32987 +
32988 + fc = le16_to_cpu(hdr->frame_control);
32989 + if (!(fc & WLAN_FC_ISWEP))
32990 + return -1;
32991 +
32992 + hdrlen = ieee80211_get_hdrlen(fc);
32993 +
32994 + if (skb->len < 8 + hdrlen)
32995 + return -1;
32996 +
32997 + return skb->data[hdrlen + 3] >> 6;
32998 +}
32999 +
33000 +
33001 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
33002 +{
33003 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33004 + u16 fc;
33005 + int hdrlen;
33006 + u8 *ivpos;
33007 + u32 iv;
33008 +
33009 + fc = le16_to_cpu(hdr->frame_control);
33010 + if (!(fc & WLAN_FC_ISWEP))
33011 + return NULL;
33012 +
33013 + hdrlen = ieee80211_get_hdrlen(fc);
33014 + ivpos = skb->data + hdrlen;
33015 + iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
33016 +
33017 + if (ieee80211_wep_weak_iv(iv, key->keylen))
33018 + return ivpos;
33019 +
33020 + return NULL;
33021 +}
33022 diff -Nur linux-2.6.16/net/d80211/wep.h linux-2.6.16-bcm43xx/net/d80211/wep.h
33023 --- linux-2.6.16/net/d80211/wep.h 1970-01-01 01:00:00.000000000 +0100
33024 +++ linux-2.6.16-bcm43xx/net/d80211/wep.h 2006-03-28 22:16:14.000000000 +0200
33025 @@ -0,0 +1,39 @@
33026 +/*
33027 + * Software WEP encryption implementation
33028 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
33029 + * Copyright 2003, Instant802 Networks, Inc.
33030 + *
33031 + * This program is free software; you can redistribute it and/or modify
33032 + * it under the terms of the GNU General Public License version 2 as
33033 + * published by the Free Software Foundation.
33034 + */
33035 +
33036 +#ifndef WEP_H
33037 +#define WEP_H
33038 +
33039 +#include <linux/skbuff.h>
33040 +#include <linux/types.h>
33041 +#include "ieee80211_i.h"
33042 +#include "ieee80211_key.h"
33043 +
33044 +void ieee80211_wep_init(struct ieee80211_local *local);
33045 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
33046 + struct ieee80211_key *key, u8 *iv);
33047 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
33048 + struct sk_buff *skb,
33049 + struct ieee80211_key *key);
33050 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
33051 + struct sk_buff *skb,
33052 + struct ieee80211_key *key);
33053 +void ieee80211_wep_encrypt_data(u8 *rc4key, size_t klen, u8 *data,
33054 + size_t data_len);
33055 +int ieee80211_wep_decrypt_data(u8 *rc4key, size_t klen, u8 *data,
33056 + size_t data_len);
33057 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
33058 + struct ieee80211_key *key);
33059 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
33060 + struct ieee80211_key *key);
33061 +int ieee80211_wep_get_keyidx(struct sk_buff *skb);
33062 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
33063 +
33064 +#endif /* WEP_H */
33065 diff -Nur linux-2.6.16/net/d80211/wme.c linux-2.6.16-bcm43xx/net/d80211/wme.c
33066 --- linux-2.6.16/net/d80211/wme.c 1970-01-01 01:00:00.000000000 +0100
33067 +++ linux-2.6.16-bcm43xx/net/d80211/wme.c 2006-03-28 22:16:14.000000000 +0200
33068 @@ -0,0 +1,695 @@
33069 +/*
33070 + * Copyright 2004, Instant802 Networks, Inc.
33071 + *
33072 + * This program is free software; you can redistribute it and/or modify
33073 + * it under the terms of the GNU General Public License version 2 as
33074 + * published by the Free Software Foundation.
33075 + */
33076 +
33077 +#include <linux/config.h>
33078 +#include <linux/version.h>
33079 +#include <linux/netdevice.h>
33080 +#include <linux/skbuff.h>
33081 +#include <linux/module.h>
33082 +#include <linux/if_arp.h>
33083 +#include <net/ip.h>
33084 +
33085 +#include <net/d80211.h>
33086 +#include "ieee80211_i.h"
33087 +#include "wme.h"
33088 +
33089 +#define CHILD_QDISC_OPS pfifo_qdisc_ops
33090 +
33091 +static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
33092 +{
33093 + return (fc & 0x8C) == 0x88;
33094 +}
33095 +
33096 +
33097 +ieee80211_txrx_result
33098 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
33099 +{
33100 + u8 *data = rx->skb->data;
33101 + int tid;
33102 +
33103 + /* does the frame have a qos control field? */
33104 + if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
33105 + u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
33106 + /* frame has qos control */
33107 + tid = qc[0] & QOS_CONTROL_TID_MASK;
33108 + } else {
33109 + if (unlikely(WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_MGMT)) {
33110 + /* Separate TID for management frames */
33111 + tid = NUM_RX_DATA_QUEUES - 1;
33112 + } else {
33113 + /* no qos control present */
33114 + tid = 0; /* 802.1d - Best Effort */
33115 + }
33116 + }
33117 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
33118 + I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
33119 + if (rx->sta) {
33120 + I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
33121 + }
33122 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
33123 +
33124 + rx->u.rx.queue = tid;
33125 + /* Set skb->priority to 1d tag if highest order bit of TID is not set.
33126 + * For now, set skb->priority to 0 for other cases. */
33127 + rx->skb->priority = (tid > 7) ? 0 : tid;
33128 +
33129 + return TXRX_CONTINUE;
33130 +}
33131 +
33132 +
33133 +ieee80211_txrx_result
33134 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
33135 +{
33136 + u16 fc = rx->fc;
33137 + u8 *data = rx->skb->data;
33138 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
33139 +
33140 + if (!WLAN_FC_IS_QOS_DATA(fc))
33141 + return TXRX_CONTINUE;
33142 +
33143 + /* remove the qos control field, update frame type and meta-data */
33144 + memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
33145 + hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
33146 + /* change frame type to non QOS */
33147 + rx->fc = fc &= ~(WLAN_FC_STYPE_QOS_DATA << 4);
33148 + hdr->frame_control = cpu_to_le16(fc);
33149 +
33150 + return TXRX_CONTINUE;
33151 +}
33152 +
33153 +
33154 +/* maximum number of hardware queues we support. */
33155 +#define TC_80211_MAX_QUEUES 8
33156 +
33157 +struct ieee80211_sched_data
33158 +{
33159 + struct tcf_proto *filter_list;
33160 + struct Qdisc *queues[TC_80211_MAX_QUEUES];
33161 + struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
33162 +};
33163 +
33164 +
33165 +/* given a data frame determine the 802.1p/1d tag to use */
33166 +static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
33167 +{
33168 + struct iphdr *ip;
33169 + int dscp;
33170 + int offset;
33171 +
33172 +#ifdef CONFIG_NET_SCHED
33173 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33174 + struct tcf_result res = { -1, 0 };
33175 +
33176 + /* if there is a user set filter list, call out to that */
33177 + if (q->filter_list) {
33178 + tc_classify(skb, q->filter_list, &res);
33179 + if (res.class != -1)
33180 + return res.class;
33181 + }
33182 +#endif /* CONFIG_NET_SCHED */
33183 +
33184 + /* skb->priority values from 256->263 are magic values to
33185 + * directly indicate a specific 802.1d priority.
33186 + * This is used to allow 802.1d priority to be passed directly in
33187 + * from VLAN tags, etc. */
33188 + if (skb->priority >= 256 && skb->priority <= 263)
33189 + return skb->priority - 256;
33190 +
33191 + /* check there is a valid IP header present */
33192 + offset = ieee80211_get_hdrlen_from_skb(skb) + 8 /* LLC + proto */;
33193 + if (skb->protocol != __constant_htons(ETH_P_IP) ||
33194 + skb->len < offset + sizeof(*ip))
33195 + return 0;
33196 +
33197 + ip = (struct iphdr *) (skb->data + offset);
33198 +
33199 + dscp = ip->tos & 0xfc;
33200 + switch (dscp) {
33201 + case 0x20:
33202 + return 2;
33203 + case 0x40:
33204 + return 1;
33205 + case 0x60:
33206 + return 3;
33207 + case 0x80:
33208 + return 4;
33209 + case 0xa0:
33210 + return 5;
33211 + case 0xc0:
33212 + return 6;
33213 + case 0xe0:
33214 + return 7;
33215 + default:
33216 + return 0;
33217 + }
33218 +}
33219 +
33220 +
33221 +static inline int wme_downgrade_ac(struct sk_buff *skb)
33222 +{
33223 + switch (skb->priority) {
33224 + case 6:
33225 + case 7:
33226 + skb->priority = 5; /* VO -> VI */
33227 + return 0;
33228 + case 4:
33229 + case 5:
33230 + skb->priority = 3; /* VI -> BE */
33231 + return 0;
33232 + case 0:
33233 + case 3:
33234 + skb->priority = 2; /* BE -> BK */
33235 + return 0;
33236 + default:
33237 + return -1;
33238 + }
33239 +}
33240 +
33241 +
33242 +/* positive return value indicates which queue to use
33243 + * negative return value indicates to drop the frame */
33244 +static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
33245 +{
33246 + struct ieee80211_local *local = qd->dev->priv;
33247 + struct ieee80211_tx_packet_data *pkt_data =
33248 + (struct ieee80211_tx_packet_data *) skb->cb;
33249 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33250 + unsigned short fc = le16_to_cpu(hdr->frame_control);
33251 + int qos;
33252 + const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
33253 +
33254 + /* see if frame is data or non data frame */
33255 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA)) {
33256 + /* management frames go on AC_VO queue, but are sent
33257 + * without QoS control fields */
33258 + return IEEE80211_TX_QUEUE_DATA0;
33259 + }
33260 +
33261 + if (unlikely(pkt_data->sdata->type == IEEE80211_SUB_IF_TYPE_MGMT)) {
33262 + /* Data frames from hostapd (mainly, EAPOL) use AC_VO
33263 + * and they will include QoS control fields if
33264 + * the target STA is using WME. */
33265 + skb->priority = 7;
33266 + return ieee802_1d_to_ac[skb->priority];
33267 + }
33268 +
33269 + /* is this a QoS frame? */
33270 + qos = fc & (WLAN_FC_STYPE_QOS_DATA << 4);
33271 +
33272 + if (!qos) {
33273 + skb->priority = 0; /* required for correct WPA/11i MIC */
33274 + return ieee802_1d_to_ac[skb->priority];
33275 + }
33276 +
33277 + /* use the data classifier to determine what 802.1d tag the
33278 + * data frame has */
33279 + skb->priority = classify_1d(skb, qd);
33280 +
33281 + /* incase we are a client verify acm is not set for this ac */
33282 + for (; unlikely(local->wmm_acm & BIT(skb->priority)); )
33283 + {
33284 + if (wme_downgrade_ac(skb)) {
33285 + /* No AC with lower priority has acm=0,
33286 + * drop packet. */
33287 + return -1;
33288 + }
33289 + }
33290 +
33291 + /* look up which queue to use for frames with this 1d tag */
33292 + return ieee802_1d_to_ac[skb->priority];
33293 +}
33294 +
33295 +
33296 +static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
33297 +{
33298 + struct ieee80211_local *local = qd->dev->priv;
33299 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33300 + struct ieee80211_tx_packet_data *pkt_data =
33301 + (struct ieee80211_tx_packet_data *) skb->cb;
33302 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33303 + unsigned short fc = le16_to_cpu(hdr->frame_control);
33304 + struct Qdisc *qdisc;
33305 + int err, queue;
33306 +
33307 + if (pkt_data->requeue) {
33308 + skb_queue_tail(&q->requeued[pkt_data->queue], skb);
33309 + return 0;
33310 + }
33311 +
33312 + queue = classify80211(skb, qd);
33313 +
33314 + /* now we know the 1d priority, fill in the QoS header if there is one
33315 + */
33316 + if (WLAN_FC_IS_QOS_DATA(fc)) {
33317 + struct qos_control *qc = (struct qos_control *)
33318 + (skb->data + ieee80211_get_hdrlen(fc) - 2);
33319 + u8 *p = (u8 *) qc;
33320 + *p++ = 0; /* do this due to gcc's lack of optimization on
33321 + * bitfield ops */
33322 + *p = 0;
33323 + qc->tag1d = skb->priority;
33324 + if (local->wifi_wme_noack_test)
33325 + qc->ack_policy = 1;
33326 + }
33327 +
33328 + if (unlikely(queue >= local->hw->queues)) {
33329 +#if 0
33330 + if (net_ratelimit()) {
33331 + printk(KERN_DEBUG "%s - queue=%d (hw does not "
33332 + "support) -> %d\n",
33333 + __func__, queue, local->hw->queues - 1);
33334 + }
33335 +#endif
33336 + queue = local->hw->queues - 1;
33337 + }
33338 +
33339 + if (unlikely(queue < 0)) {
33340 + kfree_skb(skb);
33341 + err = NET_XMIT_DROP;
33342 + } else {
33343 + pkt_data->queue = (unsigned int) queue;
33344 + qdisc = q->queues[queue];
33345 + err = qdisc->enqueue(skb, qdisc);
33346 + if (err == NET_XMIT_SUCCESS) {
33347 + qd->q.qlen++;
33348 + qd->bstats.bytes += skb->len;
33349 + qd->bstats.packets++;
33350 + return NET_XMIT_SUCCESS;
33351 + }
33352 + }
33353 + qd->qstats.drops++;
33354 + return err;
33355 +}
33356 +
33357 +
33358 +/* TODO: clean up the cases where master_hard_start_xmit
33359 + * returns non 0 - it shouldn't ever do that. Once done we
33360 + * can remove this function */
33361 +static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
33362 +{
33363 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33364 + struct ieee80211_tx_packet_data *pkt_data =
33365 + (struct ieee80211_tx_packet_data *) skb->cb;
33366 + struct Qdisc *qdisc;
33367 + int err;
33368 +
33369 + /* we recorded which queue to use earlier! */
33370 + qdisc = q->queues[pkt_data->queue];
33371 +
33372 + if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
33373 + qd->q.qlen++;
33374 + return 0;
33375 + }
33376 + qd->qstats.drops++;
33377 + return err;
33378 +}
33379 +
33380 +
33381 +static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
33382 +{
33383 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33384 + struct net_device *dev = qd->dev;
33385 + struct ieee80211_local *local = dev->priv;
33386 + struct ieee80211_hw *hw = local->hw;
33387 + struct ieee80211_tx_queue_stats stats;
33388 + struct sk_buff *skb;
33389 + struct Qdisc *qdisc;
33390 + int queue;
33391 +
33392 + /* find which hardware queues have space in them */
33393 + hw->get_tx_stats(dev, &stats);
33394 +
33395 + /* check all the h/w queues in numeric/priority order */
33396 + for (queue = 0; queue < hw->queues; queue++) {
33397 + /* see if there is room in this hardware queue */
33398 + if (stats.data[queue].len >= stats.data[queue].limit)
33399 + continue;
33400 +
33401 + /* there is space - try and get a frame */
33402 + skb = skb_dequeue(&q->requeued[queue]);
33403 + if (skb)
33404 + return skb;
33405 +
33406 + qdisc = q->queues[queue];
33407 + skb = qdisc->dequeue(qdisc);
33408 + if (skb) {
33409 + qd->q.qlen--;
33410 + return skb;
33411 + }
33412 + }
33413 + /* returning a NULL here when all the h/w queues are full means we
33414 + * never need to call netif_stop_queue in the driver */
33415 + return NULL;
33416 +}
33417 +
33418 +
33419 +static void wme_qdiscop_reset(struct Qdisc* qd)
33420 +{
33421 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33422 + struct ieee80211_local *local = qd->dev->priv;
33423 + struct ieee80211_hw *hw = local->hw;
33424 + int queue;
33425 +
33426 + /* QUESTION: should we have some hardware flush functionality here? */
33427 +
33428 + for (queue = 0; queue < hw->queues; queue++) {
33429 + skb_queue_purge(&q->requeued[queue]);
33430 + qdisc_reset(q->queues[queue]);
33431 + }
33432 + qd->q.qlen = 0;
33433 +}
33434 +
33435 +
33436 +static void wme_qdiscop_destroy(struct Qdisc* qd)
33437 +{
33438 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33439 + struct ieee80211_local *local = qd->dev->priv;
33440 + struct ieee80211_hw *hw = local->hw;
33441 + struct tcf_proto *tp;
33442 + int queue;
33443 +
33444 + while ((tp = q->filter_list) != NULL) {
33445 + q->filter_list = tp->next;
33446 + tp->ops->destroy(tp);
33447 + }
33448 +
33449 + for (queue=0; queue < hw->queues; queue++) {
33450 + skb_queue_purge(&q->requeued[queue]);
33451 + qdisc_destroy(q->queues[queue]);
33452 + q->queues[queue] = &noop_qdisc;
33453 + }
33454 +}
33455 +
33456 +
33457 +/* called whenever parameters are updated on existing qdisc */
33458 +static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
33459 +{
33460 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33461 +*/
33462 + /* check our options block is the right size */
33463 + /* copy any options to our local structure */
33464 +/* Ignore options block for now - always use static mapping
33465 + struct tc_ieee80211_qopt *qopt = RTA_DATA(opt);
33466 +
33467 + if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
33468 + return -EINVAL;
33469 + memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
33470 +*/
33471 + return 0;
33472 +}
33473 +
33474 +
33475 +/* called during initial creation of qdisc on device */
33476 +static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
33477 +{
33478 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33479 + struct net_device *dev = qd->dev;
33480 + struct ieee80211_local *local = dev->priv;
33481 + int queues = local->hw->queues;
33482 + int err = 0, i;
33483 +
33484 + /* check this device is an ieee80211 master type device */
33485 + if (dev->type != ARPHRD_IEEE80211)
33486 + return -EINVAL;
33487 +
33488 + /* check that there is no qdisc currently attached to device
33489 + * this ensures that we will be the root qdisc. (I can't find a better
33490 + * way to test this explicitly) */
33491 + if (dev->qdisc_sleeping != &noop_qdisc)
33492 + return -EINVAL;
33493 +
33494 + if (qd->flags & TCQ_F_INGRESS)
33495 + return -EINVAL;
33496 +
33497 + /* if options were passed in, set them */
33498 + if (opt) {
33499 + err = wme_qdiscop_tune(qd, opt);
33500 + }
33501 +
33502 + /* create child queues */
33503 + for (i = 0; i < queues; i++) {
33504 + skb_queue_head_init(&q->requeued[i]);
33505 + q->queues[i] = qdisc_create_dflt(qd->dev, &CHILD_QDISC_OPS);
33506 + if (q->queues[i] == 0) {
33507 + q->queues[i] = &noop_qdisc;
33508 + printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
33509 + }
33510 + }
33511 +
33512 + return err;
33513 +}
33514 +
33515 +static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
33516 +{
33517 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33518 + unsigned char *p = skb->tail;
33519 + struct tc_ieee80211_qopt opt;
33520 +
33521 + memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
33522 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
33523 +*/ return skb->len;
33524 +/*
33525 +rtattr_failure:
33526 + skb_trim(skb, p - skb->data);*/
33527 + return -1;
33528 +}
33529 +
33530 +
33531 +static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
33532 + struct Qdisc *new, struct Qdisc **old)
33533 +{
33534 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33535 + struct ieee80211_local *local = qd->dev->priv;
33536 + struct ieee80211_hw *hw = local->hw;
33537 + unsigned long queue = arg - 1;
33538 +
33539 + if (queue >= hw->queues)
33540 + return -EINVAL;
33541 +
33542 + if (new == NULL)
33543 + new = &noop_qdisc;
33544 +
33545 + sch_tree_lock(qd);
33546 + *old = q->queues[queue];
33547 + q->queues[queue] = new;
33548 + qdisc_reset(*old);
33549 + sch_tree_unlock(qd);
33550 +
33551 + return 0;
33552 +}
33553 +
33554 +
33555 +static struct Qdisc *
33556 +wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
33557 +{
33558 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33559 + struct ieee80211_local *local = qd->dev->priv;
33560 + struct ieee80211_hw *hw = local->hw;
33561 + unsigned long queue = arg - 1;
33562 +
33563 + if (queue >= hw->queues)
33564 + return NULL;
33565 +
33566 + return q->queues[queue];
33567 +}
33568 +
33569 +
33570 +static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
33571 +{
33572 + struct ieee80211_local *local = qd->dev->priv;
33573 + struct ieee80211_hw *hw = local->hw;
33574 + unsigned long queue = TC_H_MIN(classid);
33575 +
33576 + if (queue - 1 >= hw->queues)
33577 + return 0;
33578 +
33579 + return queue;
33580 +}
33581 +
33582 +
33583 +static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
33584 + u32 classid)
33585 +{
33586 + return wme_classop_get(qd, classid);
33587 +}
33588 +
33589 +
33590 +static void wme_classop_put(struct Qdisc *q, unsigned long cl)
33591 +{
33592 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33593 +}
33594 +
33595 +
33596 +static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
33597 + struct rtattr **tca, unsigned long *arg)
33598 +{
33599 + unsigned long cl = *arg;
33600 + struct ieee80211_local *local = qd->dev->priv;
33601 + struct ieee80211_hw *hw = local->hw;
33602 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33603 +
33604 + if (cl - 1 > hw->queues)
33605 + return -ENOENT;
33606 +
33607 + /* TODO: put code to program hardware queue parameters here,
33608 + * to allow programming from tc command line */
33609 +
33610 + return 0;
33611 +}
33612 +
33613 +
33614 +/* we don't support deleting hardware queues
33615 + * when we add WMM-SA support - TSPECs may be deleted here */
33616 +static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
33617 +{
33618 + struct ieee80211_local *local = qd->dev->priv;
33619 + struct ieee80211_hw *hw = local->hw;
33620 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33621 +
33622 + if (cl - 1 > hw->queues)
33623 + return -ENOENT;
33624 + return 0;
33625 +}
33626 +
33627 +
33628 +static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
33629 + struct sk_buff *skb, struct tcmsg *tcm)
33630 +{
33631 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33632 + struct ieee80211_local *local = qd->dev->priv;
33633 + struct ieee80211_hw *hw = local->hw;
33634 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33635 +
33636 + if (cl - 1 > hw->queues)
33637 + return -ENOENT;
33638 + tcm->tcm_handle = TC_H_MIN(cl);
33639 + tcm->tcm_parent = qd->handle;
33640 + tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
33641 + return 0;
33642 +}
33643 +
33644 +
33645 +static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
33646 +{
33647 + struct ieee80211_local *local = qd->dev->priv;
33648 + struct ieee80211_hw *hw = local->hw;
33649 + int queue;
33650 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33651 +
33652 + if (arg->stop)
33653 + return;
33654 +
33655 + for (queue = 0; queue < hw->queues; queue++) {
33656 + if (arg->count < arg->skip) {
33657 + arg->count++;
33658 + continue;
33659 + }
33660 + /* we should return classids for our internal queues here
33661 + * as well as the external ones */
33662 + if (arg->fn(qd, queue+1, arg) < 0) {
33663 + arg->stop = 1;
33664 + break;
33665 + }
33666 + arg->count++;
33667 + }
33668 +}
33669 +
33670 +
33671 +static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
33672 + unsigned long cl)
33673 +{
33674 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33675 + /* printk("entering %s\n", __func__); */
33676 +
33677 + if (cl)
33678 + return NULL;
33679 +
33680 + return &q->filter_list;
33681 +}
33682 +
33683 +
33684 +/* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
33685 + * - these are the operations on the classes */
33686 +static struct Qdisc_class_ops class_ops =
33687 +{
33688 + .graft = wme_classop_graft,
33689 + .leaf = wme_classop_leaf,
33690 +
33691 + .get = wme_classop_get,
33692 + .put = wme_classop_put,
33693 + .change = wme_classop_change,
33694 + .delete = wme_classop_delete,
33695 + .walk = wme_classop_walk,
33696 +
33697 + .tcf_chain = wme_classop_find_tcf,
33698 + .bind_tcf = wme_classop_bind,
33699 + .unbind_tcf = wme_classop_put,
33700 +
33701 + .dump = wme_classop_dump_class,
33702 +};
33703 +
33704 +
33705 +/* queueing discipline operations */
33706 +static struct Qdisc_ops wme_qdisc_ops =
33707 +{
33708 + .next = NULL,
33709 + .cl_ops = &class_ops,
33710 + .id = "ieee80211",
33711 + .priv_size = sizeof(struct ieee80211_sched_data),
33712 +
33713 + .enqueue = wme_qdiscop_enqueue,
33714 + .dequeue = wme_qdiscop_dequeue,
33715 + .requeue = wme_qdiscop_requeue,
33716 + .drop = NULL, /* drop not needed since we are always the root qdisc */
33717 +
33718 + .init = wme_qdiscop_init,
33719 + .reset = wme_qdiscop_reset,
33720 + .destroy = wme_qdiscop_destroy,
33721 + .change = wme_qdiscop_tune,
33722 +
33723 + .dump = wme_qdiscop_dump,
33724 +};
33725 +
33726 +
33727 +void ieee80211_install_qdisc(struct net_device *dev)
33728 +{
33729 + struct Qdisc *qdisc;
33730 +
33731 + qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops);
33732 + if (qdisc == NULL) {
33733 + printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
33734 + return;
33735 + }
33736 +
33737 + /* same handle as would be allocated by qdisc_alloc_handle() */
33738 + qdisc->handle = 0x80010000;
33739 +
33740 + qdisc_lock_tree(dev);
33741 + list_add_tail(&qdisc->list, &dev->qdisc_list);
33742 + dev->qdisc_sleeping = qdisc;
33743 + qdisc_unlock_tree(dev);
33744 +}
33745 +
33746 +
33747 +int ieee80211_wme_register(void)
33748 +{
33749 + int err = 0;
33750 +
33751 +#ifdef CONFIG_NET_SCHED
33752 + err = register_qdisc(&wme_qdisc_ops);
33753 +#endif
33754 + return err;
33755 +}
33756 +
33757 +
33758 +void ieee80211_wme_unregister(void)
33759 +{
33760 +#ifdef CONFIG_NET_SCHED
33761 + unregister_qdisc(&wme_qdisc_ops);
33762 +#endif
33763 +}
33764 diff -Nur linux-2.6.16/net/d80211/wme.h linux-2.6.16-bcm43xx/net/d80211/wme.h
33765 --- linux-2.6.16/net/d80211/wme.h 1970-01-01 01:00:00.000000000 +0100
33766 +++ linux-2.6.16-bcm43xx/net/d80211/wme.h 2006-03-28 22:16:14.000000000 +0200
33767 @@ -0,0 +1,59 @@
33768 +/*
33769 + * IEEE 802.11 driver (80211.o) - QoS datatypes
33770 + * Copyright 2004, Instant802 Networks, Inc.
33771 + * Copyright 2005, Devicescape Software, Inc.
33772 + *
33773 + * This program is free software; you can redistribute it and/or modify
33774 + * it under the terms of the GNU General Public License version 2 as
33775 + * published by the Free Software Foundation.
33776 + */
33777 +
33778 +#ifndef _WME_H
33779 +#define _WME_H
33780 +
33781 +#include <asm/byteorder.h>
33782 +#include <linux/netdevice.h>
33783 +#include <linux/types.h>
33784 +#include <net/pkt_sched.h>
33785 +
33786 +#define QOS_CONTROL_LEN 2
33787 +
33788 +#define QOS_CONTROL_ACK_POLICY_NORMAL 0
33789 +#define QOS_CONTROL_ACK_POLICY_NOACK 1
33790 +
33791 +#define QOS_CONTROL_TID_MASK 0x0f
33792 +#define QOS_CONTROL_ACK_POLICY_SHIFT 5
33793 +
33794 +/* This bit field structure should not be used; it can cause compiler to
33795 + * generate unaligned accesses and inefficient code. */
33796 +struct qos_control {
33797 +#if defined(__LITTLE_ENDIAN_BITFIELD)
33798 + u8 tag1d:3, /* bits 0-2 */
33799 + reserved1:1,
33800 + eosp:1,
33801 + ack_policy:2,
33802 + reserved2:1;
33803 +#elif defined (__BIG_ENDIAN_BITFIELD)
33804 + u8 reserved2:1,
33805 + ack_policy:2,
33806 + eosp:1,
33807 + reserved1:1,
33808 + tag1d:3; /* bits 0-2 */
33809 +#else
33810 +#error "Please fix <asm/byteorder.h>"
33811 +#endif
33812 + u8 reserved;
33813 +} __attribute__ ((packed));
33814 +
33815 +ieee80211_txrx_result
33816 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx);
33817 +
33818 +ieee80211_txrx_result
33819 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx);
33820 +
33821 +void ieee80211_install_qdisc(struct net_device *dev);
33822 +
33823 +int ieee80211_wme_register(void);
33824 +void ieee80211_wme_unregister(void);
33825 +
33826 +#endif
33827 diff -Nur linux-2.6.16/net/d80211/wpa.c linux-2.6.16-bcm43xx/net/d80211/wpa.c
33828 --- linux-2.6.16/net/d80211/wpa.c 1970-01-01 01:00:00.000000000 +0100
33829 +++ linux-2.6.16-bcm43xx/net/d80211/wpa.c 2006-03-28 22:16:14.000000000 +0200
33830 @@ -0,0 +1,825 @@
33831 +/*
33832 + * Copyright 2002-2004, Instant802 Networks, Inc.
33833 + *
33834 + * This program is free software; you can redistribute it and/or modify
33835 + * it under the terms of the GNU General Public License version 2 as
33836 + * published by the Free Software Foundation.
33837 + */
33838 +
33839 +#include <linux/config.h>
33840 +#include <linux/version.h>
33841 +#include <linux/module.h>
33842 +#include <linux/netdevice.h>
33843 +#include <linux/types.h>
33844 +#include <linux/slab.h>
33845 +#include <linux/skbuff.h>
33846 +#include <linux/compiler.h>
33847 +#include <linux/wireless.h>
33848 +#include <net/iw_handler.h>
33849 +
33850 +#include <net/d80211.h>
33851 +#include <net/d80211_common.h>
33852 +#include "ieee80211_i.h"
33853 +#include "michael.h"
33854 +#include "tkip.h"
33855 +#include "aes_ccm.h"
33856 +#include "wpa.h"
33857 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33858 +#include "hostapd_ioctl.h"
33859 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33860 +
33861 +
33862 +#define MICHAEL_MIC_HWACCEL
33863 +
33864 +
33865 +int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
33866 + u8 *qos_tid, u8 **data, size_t *data_len)
33867 +{
33868 + struct ieee80211_hdr *hdr;
33869 + size_t hdrlen;
33870 + u16 fc;
33871 + int a4_included;
33872 + u8 *pos;
33873 +
33874 + hdr = (struct ieee80211_hdr *) skb->data;
33875 + fc = le16_to_cpu(hdr->frame_control);
33876 +
33877 + hdrlen = 24;
33878 + if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) ==
33879 + (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
33880 + hdrlen += ETH_ALEN;
33881 + *sa = hdr->addr4;
33882 + *da = hdr->addr3;
33883 + } else if (fc & WLAN_FC_FROMDS) {
33884 + *sa = hdr->addr3;
33885 + *da = hdr->addr1;
33886 + } else if (fc & WLAN_FC_TODS) {
33887 + *sa = hdr->addr2;
33888 + *da = hdr->addr3;
33889 + } else {
33890 + *sa = hdr->addr2;
33891 + *da = hdr->addr1;
33892 + }
33893 +
33894 + if (fc & 0x80)
33895 + hdrlen += 2;
33896 +
33897 + *data = skb->data + hdrlen;
33898 + *data_len = skb->len - hdrlen;
33899 +
33900 + a4_included = (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
33901 + (WLAN_FC_TODS | WLAN_FC_FROMDS);
33902 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
33903 + WLAN_FC_GET_STYPE(fc) & 0x08) {
33904 + pos = (u8 *) &hdr->addr4;
33905 + if (a4_included)
33906 + pos += 6;
33907 + *qos_tid = pos[0] & 0x0f;
33908 + *qos_tid |= 0x80; /* qos_included flag */
33909 + } else
33910 + *qos_tid = 0;
33911 +
33912 + return skb->len < hdrlen ? -1 : 0;
33913 +}
33914 +
33915 +
33916 +ieee80211_txrx_result
33917 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
33918 +{
33919 + u8 *data, *sa, *da, *key, *mic, qos_tid;
33920 + size_t data_len;
33921 + u16 fc;
33922 + struct sk_buff *skb = tx->skb;
33923 + int authenticator;
33924 +#if defined(CONFIG_HOSTAPD_WPA_TESTING) || defined(MICHAEL_MIC_HWACCEL)
33925 + int wpa_test = 0;
33926 +#endif
33927 +
33928 + fc = tx->fc;
33929 +
33930 + if (!tx->key || tx->key->alg != ALG_TKIP || skb->len < 24 ||
33931 + !WLAN_FC_DATA_PRESENT(fc))
33932 + return TXRX_CONTINUE;
33933 +
33934 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
33935 + return TXRX_DROP;
33936 +
33937 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33938 + if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) ||
33939 + (!tx->u.tx.unicast &&
33940 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC)) {
33941 + wpa_test = 1;
33942 + }
33943 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33944 +
33945 +#ifdef MICHAEL_MIC_HWACCEL
33946 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
33947 + !tx->fragmented && !wpa_test) {
33948 + /* hwaccel - with no need for preallocated room for Michael MIC
33949 + */
33950 + return TXRX_CONTINUE;
33951 + }
33952 +#endif /* MICHAEL_MIC_HWACCEL */
33953 +
33954 + if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
33955 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
33956 + if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN,
33957 + MICHAEL_MIC_LEN + TKIP_ICV_LEN,
33958 + GFP_ATOMIC))) {
33959 + printk(KERN_DEBUG "%s: failed to allocate more memory "
33960 + "for Michael MIC\n", tx->dev->name);
33961 + return TXRX_DROP;
33962 + }
33963 + }
33964 +
33965 +#if 0
33966 + authenticator = fc & WLAN_FC_FROMDS; /* FIX */
33967 +#else
33968 + authenticator = 1;
33969 +#endif
33970 + key = &tx->key->key[authenticator ? ALG_TKIP_TEMP_AUTH_TX_MIC_KEY :
33971 + ALG_TKIP_TEMP_AUTH_RX_MIC_KEY];
33972 + mic = skb_put(skb, MICHAEL_MIC_LEN);
33973 + michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
33974 +
33975 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33976 + if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
33977 + printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
33978 + "for STA " MACSTR "\n",
33979 + tx->dev->name, MAC2STR(tx->sta->addr));
33980 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
33981 + tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
33982 + tx->wpa_test = 1;
33983 + mic[0]++;
33984 + } else if (!tx->u.tx.unicast &&
33985 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
33986 + printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
33987 + "for Group Key\n", tx->dev->name);
33988 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
33989 + tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
33990 + tx->wpa_test = 1;
33991 + mic[0]++;
33992 + }
33993 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33994 +
33995 + return TXRX_CONTINUE;
33996 +}
33997 +
33998 +
33999 +ieee80211_txrx_result
34000 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
34001 +{
34002 + u8 *data, *sa, *da, *key = NULL, qos_tid;
34003 + size_t data_len;
34004 + u16 fc;
34005 + u8 mic[MICHAEL_MIC_LEN];
34006 + struct sk_buff *skb = rx->skb;
34007 + int authenticator = 1, wpa_test = 0;
34008 +
34009 + fc = rx->fc;
34010 +
34011 + /* If device handles decryption totally, skip this check */
34012 + if (rx->local->hw->device_hides_wep ||
34013 + rx->local->hw->device_strips_mic)
34014 + return TXRX_CONTINUE;
34015 +
34016 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34017 + !(rx->fc & WLAN_FC_ISWEP) || !WLAN_FC_DATA_PRESENT(fc))
34018 + return TXRX_CONTINUE;
34019 +
34020 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34021 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34022 + wpa_test = 1;
34023 + }
34024 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34025 +
34026 +#ifdef MICHAEL_MIC_HWACCEL
34027 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34028 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34029 + if (rx->local->hw->wep_include_iv) {
34030 + if (skb->len < MICHAEL_MIC_LEN)
34031 + return TXRX_DROP;
34032 + }
34033 + /* Need to verify Michael MIC sometimes in software even when
34034 + * hwaccel is used. Atheros ar5212: fragmented frames and QoS
34035 + * frames. */
34036 + if (!rx->fragmented && !wpa_test)
34037 + goto remove_mic;
34038 + }
34039 +#endif /* MICHAEL_MIC_HWACCEL */
34040 +
34041 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
34042 + || data_len < MICHAEL_MIC_LEN)
34043 + return TXRX_DROP;
34044 +
34045 + data_len -= MICHAEL_MIC_LEN;
34046 +
34047 +#if 0
34048 + authenticator = fc & WLAN_FC_TODS; /* FIX */
34049 +#else
34050 + authenticator = 1;
34051 +#endif
34052 + key = &rx->key->key[authenticator ? ALG_TKIP_TEMP_AUTH_RX_MIC_KEY :
34053 + ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
34054 + michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
34055 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34056 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34057 + printk(KERN_INFO "%s: WPA testing - corrupting RX Michael MIC "
34058 + "for STA " MACSTR "\n",
34059 + rx->dev->name, MAC2STR(rx->sta->addr));
34060 + rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_MIC;
34061 + mic[0]++;
34062 + }
34063 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34064 + if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
34065 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34066 + int i;
34067 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34068 + printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
34069 + MACSTR "\n", rx->dev->name, MAC2STR(sa));
34070 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34071 + printk(KERN_DEBUG " received");
34072 + for (i = 0; i < MICHAEL_MIC_LEN; i++)
34073 + printk(" %02x", data[data_len + i]);
34074 + printk(" expected");
34075 + for (i = 0; i < MICHAEL_MIC_LEN; i++)
34076 + printk(" %02x", mic[i]);
34077 + printk("\n");
34078 + printk(KERN_DEBUG " SA=" MACSTR " DA=" MACSTR " key",
34079 + MAC2STR(sa), MAC2STR(da));
34080 + for (i = 0; i < 8; i++)
34081 + printk(" %02x", key[i]);
34082 + printk(" (%d)\n", authenticator);
34083 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34084 +
34085 + do {
34086 + struct ieee80211_hdr *hdr;
34087 + union iwreq_data wrqu;
34088 + char *buf = kmalloc(128, GFP_ATOMIC);
34089 + if (buf == NULL)
34090 + break;
34091 +
34092 + /* TODO: needed parameters: count, key type, TSC */
34093 + hdr = (struct ieee80211_hdr *) skb->data;
34094 + sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
34095 + "keyid=%d %scast addr=" MACSTR ")",
34096 + rx->key->keyidx,
34097 + hdr->addr1[0] & 0x01 ? "broad" : "uni",
34098 + MAC2STR(hdr->addr2));
34099 + memset(&wrqu, 0, sizeof(wrqu));
34100 + wrqu.data.length = strlen(buf);
34101 + wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
34102 + kfree(buf);
34103 + } while (0);
34104 +
34105 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
34106 + ieee80211_msg_michael_mic_failure);
34107 +
34108 + return TXRX_QUEUED;
34109 + }
34110 +
34111 +#ifdef MICHAEL_MIC_HWACCEL
34112 + remove_mic:
34113 +#endif /* MICHAEL_MIC_HWACCEL */
34114 + /* remove Michael MIC from payload */
34115 + skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
34116 +
34117 + return TXRX_CONTINUE;
34118 +}
34119 +
34120 +
34121 +static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
34122 + struct sk_buff *skb, int test)
34123 +{
34124 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34125 + struct ieee80211_key *key = tx->key;
34126 + int hdrlen, len, tailneed;
34127 + u16 fc;
34128 + u8 *pos;
34129 +
34130 + fc = le16_to_cpu(hdr->frame_control);
34131 + hdrlen = ieee80211_get_hdrlen(fc);
34132 + len = skb->len - hdrlen;
34133 +
34134 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34135 + ? 0 : TKIP_ICV_LEN;
34136 + if ((skb_headroom(skb) < TKIP_IV_LEN ||
34137 + skb_tailroom(skb) < tailneed)) {
34138 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
34139 + if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN, tailneed,
34140 + GFP_ATOMIC)))
34141 + return -1;
34142 + }
34143 +
34144 + pos = skb_push(skb, TKIP_IV_LEN);
34145 + memmove(pos, pos + TKIP_IV_LEN, hdrlen);
34146 + pos += hdrlen;
34147 +
34148 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34149 + if (test & WPA_TRIGGER_TX_REPLAY)
34150 + goto skip_iv_inc;
34151 +iv_inc:
34152 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34153 +
34154 + /* Increase IV for the frame */
34155 + key->u.tkip.iv16++;
34156 + if (key->u.tkip.iv16 == 0)
34157 + key->u.tkip.iv32++;
34158 +
34159 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34160 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34161 + test = 0;
34162 + goto iv_inc;
34163 + }
34164 +skip_iv_inc:
34165 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34166 +
34167 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt
34168 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34169 + && !tx->wpa_test
34170 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34171 + ) {
34172 + /* hwaccel - with preallocated room for IV */
34173 +
34174 + ieee80211_tkip_add_iv(pos, key,
34175 + (u8) (key->u.tkip.iv16 >> 8),
34176 + (u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
34177 + 0x7f),
34178 + (u8) key->u.tkip.iv16);
34179 +
34180 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34181 + return 0;
34182 + }
34183 +
34184 + /* Add room for ICV */
34185 + skb_put(skb, TKIP_ICV_LEN);
34186 +
34187 + hdr = (struct ieee80211_hdr *) skb->data;
34188 + ieee80211_tkip_encrypt_data(key, pos, len, hdr->addr2);
34189 + return 0;
34190 +}
34191 +
34192 +
34193 +ieee80211_txrx_result
34194 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx)
34195 +{
34196 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34197 + u16 fc;
34198 + struct ieee80211_key *key = tx->key;
34199 + struct sk_buff *skb = tx->skb;
34200 + int wpa_test = 0, test = 0;
34201 +
34202 + fc = le16_to_cpu(hdr->frame_control);
34203 +
34204 + if (!key || key->alg != ALG_TKIP || !WLAN_FC_DATA_PRESENT(fc))
34205 + return TXRX_CONTINUE;
34206 +
34207 + tx->u.tx.control->icv_len = TKIP_ICV_LEN;
34208 + tx->u.tx.control->iv_len = TKIP_IV_LEN;
34209 + ieee80211_tx_set_iswep(tx);
34210 +
34211 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34212 + if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) ||
34213 + (!tx->u.tx.unicast &&
34214 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV)) {
34215 + wpa_test = 1;
34216 + }
34217 +
34218 + if (tx->sta) {
34219 + test = tx->sta->wpa_trigger;
34220 + tx->sta->wpa_trigger &=
34221 + ~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34222 + WPA_TRIGGER_TX_SKIP_SEQ);
34223 + } else {
34224 + test = tx->local->wpa_trigger;
34225 + tx->local->wpa_trigger &=
34226 + ~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34227 + WPA_TRIGGER_TX_SKIP_SEQ);
34228 + }
34229 + if (test &
34230 + (WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34231 + WPA_TRIGGER_TX_SKIP_SEQ)) {
34232 + printk(KERN_INFO "%s: WPA testing - TKIP TX packet number "
34233 + "%s%s%s%s\n", tx->dev->name,
34234 + tx->sta ? "[UNICAST]" : "[MULTICAST]",
34235 + test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
34236 + test & WPA_TRIGGER_TX_REPLAY_FRAG ?
34237 + "[REPLAY FRAG]" : "",
34238 + test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
34239 + }
34240 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34241 +
34242 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
34243 + !tx->local->hw->wep_include_iv && !wpa_test) {
34244 + /* hwaccel - with no need for preallocated room for IV/ICV */
34245 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34246 + return TXRX_CONTINUE;
34247 + }
34248 +
34249 + if (tkip_encrypt_skb(tx, skb, test) < 0)
34250 + return TXRX_DROP;
34251 +
34252 + if (tx->u.tx.extra_frag) {
34253 + int i;
34254 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34255 + if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
34256 + test |= WPA_TRIGGER_TX_REPLAY;
34257 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34258 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
34259 + if (tkip_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
34260 + < 0)
34261 + return TXRX_DROP;
34262 + }
34263 + }
34264 +
34265 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34266 + if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
34267 + printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
34268 + "for STA " MACSTR "\n",
34269 + tx->dev->name, MAC2STR(tx->sta->addr));
34270 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34271 + tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
34272 + skb->data[skb->len - 1]++;
34273 + } else if (!tx->u.tx.unicast &&
34274 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
34275 + printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
34276 + "for Group Key\n",
34277 + tx->dev->name);
34278 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34279 + tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
34280 + skb->data[skb->len - 1]++;
34281 + }
34282 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34283 +
34284 + return TXRX_CONTINUE;
34285 +}
34286 +
34287 +
34288 +ieee80211_txrx_result
34289 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx)
34290 +{
34291 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34292 + u16 fc;
34293 + int hdrlen, res, hwaccel = 0, wpa_test = 0;
34294 + struct ieee80211_key *key = rx->key;
34295 + struct sk_buff *skb = rx->skb;
34296 +
34297 + fc = le16_to_cpu(hdr->frame_control);
34298 + hdrlen = ieee80211_get_hdrlen(fc);
34299 +
34300 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34301 + !(rx->fc & WLAN_FC_ISWEP) ||
34302 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA)
34303 + return TXRX_CONTINUE;
34304 +
34305 + if (!rx->sta || skb->len - hdrlen < 12)
34306 + return TXRX_DROP;
34307 +
34308 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34309 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_ICV) {
34310 + printk(KERN_INFO "%s: WPA testing - corrupting RX TKIP ICV "
34311 + "for STA " MACSTR "\n",
34312 + rx->dev->name, MAC2STR(rx->sta->addr));
34313 + rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_ICV;
34314 + skb->data[skb->len - 1]++;
34315 + wpa_test = 1;
34316 + }
34317 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34318 +
34319 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34320 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34321 + if (!rx->local->hw->wep_include_iv) {
34322 + /* Hardware takes care of all processing, including
34323 + * replay protection, so no need to continue here. */
34324 + return TXRX_CONTINUE;
34325 + }
34326 +
34327 + /* let TKIP code verify IV, but skip decryption */
34328 + hwaccel = 1;
34329 + }
34330 +
34331 + res = ieee80211_tkip_decrypt_data(key, skb->data + hdrlen,
34332 + skb->len - hdrlen, rx->sta->addr,
34333 + hwaccel, rx->u.rx.queue);
34334 + if (res != TKIP_DECRYPT_OK || wpa_test) {
34335 + printk(KERN_DEBUG "%s: TKIP decrypt failed for RX frame from "
34336 + MACSTR " (res=%d)\n",
34337 + rx->dev->name, MAC2STR(rx->sta->addr), res);
34338 + return TXRX_DROP;
34339 + }
34340 +
34341 + /* Trim ICV */
34342 + skb_trim(skb, skb->len - TKIP_ICV_LEN);
34343 +
34344 + /* Remove IV */
34345 + memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
34346 + skb_pull(skb, TKIP_IV_LEN);
34347 +
34348 + return TXRX_CONTINUE;
34349 +}
34350 +
34351 +
34352 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
34353 + int encrypted)
34354 +{
34355 + u16 fc;
34356 + int a4_included, qos_included;
34357 + u8 qos_tid, *fc_pos, *data, *sa, *da;
34358 + int len_a;
34359 + size_t data_len;
34360 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34361 +
34362 + fc_pos = (u8 *) &hdr->frame_control;
34363 + fc = fc_pos[0] ^ (fc_pos[1] << 8);
34364 + a4_included = (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
34365 + (WLAN_FC_TODS | WLAN_FC_FROMDS);
34366 +
34367 + ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len);
34368 + data_len -= CCMP_HDR_LEN + (encrypted ? CCMP_MIC_LEN : 0);
34369 + if (qos_tid & 0x80) {
34370 + qos_included = 1;
34371 + qos_tid &= 0x0f;
34372 + } else
34373 + qos_included = 0;
34374 + /* First block, b_0 */
34375 +
34376 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
34377 + /* Nonce: QoS Priority | A2 | PN */
34378 + b_0[1] = qos_tid;
34379 + memcpy(&b_0[2], hdr->addr2, 6);
34380 + memcpy(&b_0[8], pn, CCMP_PN_LEN);
34381 + /* l(m) */
34382 + b_0[14] = (data_len >> 8) & 0xff;
34383 + b_0[15] = data_len & 0xff;
34384 +
34385 +
34386 + /* AAD (extra authenticate-only data) / masked 802.11 header
34387 + * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
34388 +
34389 + len_a = a4_included ? 28 : 22;
34390 + if (qos_included)
34391 + len_a += 2;
34392 +
34393 + aad[0] = 0; /* (len_a >> 8) & 0xff; */
34394 + aad[1] = len_a & 0xff;
34395 + /* Mask FC: zero subtype b4 b5 b6 */
34396 + aad[2] = fc_pos[0] & ~(BIT(4) | BIT(5) | BIT(6));
34397 + /* Retry, PwrMgt, MoreData; set Protected */
34398 + aad[3] = (fc_pos[1] & ~(BIT(3) | BIT(4) | BIT(5))) | BIT(6);
34399 + memcpy(&aad[4], &hdr->addr1, 18);
34400 +
34401 + /* Mask Seq#, leave Frag# */
34402 + aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
34403 + aad[23] = 0;
34404 + if (a4_included) {
34405 + memcpy(&aad[24], hdr->addr4, 6);
34406 + aad[30] = 0;
34407 + aad[31] = 0;
34408 + } else
34409 + memset(&aad[24], 0, 8);
34410 + if (qos_included) {
34411 + u8 *dpos = &aad[a4_included ? 30 : 24];
34412 +
34413 + /* Mask QoS Control field */
34414 + dpos[0] = qos_tid;
34415 + dpos[1] = 0;
34416 + }
34417 +}
34418 +
34419 +
34420 +static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
34421 +{
34422 + hdr[0] = pn[5];
34423 + hdr[1] = pn[4];
34424 + hdr[2] = 0;
34425 + hdr[3] = 0x20 | (key_id << 6);
34426 + hdr[4] = pn[3];
34427 + hdr[5] = pn[2];
34428 + hdr[6] = pn[1];
34429 + hdr[7] = pn[0];
34430 +}
34431 +
34432 +
34433 +static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
34434 +{
34435 + pn[0] = hdr[7];
34436 + pn[1] = hdr[6];
34437 + pn[2] = hdr[5];
34438 + pn[3] = hdr[4];
34439 + pn[4] = hdr[1];
34440 + pn[5] = hdr[0];
34441 + return (hdr[3] >> 6) & 0x03;
34442 +}
34443 +
34444 +
34445 +static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
34446 + struct sk_buff *skb, int test)
34447 +{
34448 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34449 + struct ieee80211_key *key = tx->key;
34450 + int hdrlen, len, tailneed;
34451 + u16 fc;
34452 + u8 *pos, *pn;
34453 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34454 + int i;
34455 +
34456 + fc = le16_to_cpu(hdr->frame_control);
34457 + hdrlen = ieee80211_get_hdrlen(fc);
34458 + len = skb->len - hdrlen;
34459 +
34460 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34461 + ? 0 : CCMP_MIC_LEN;
34462 +
34463 + if ((skb_headroom(skb) < CCMP_HDR_LEN ||
34464 + skb_tailroom(skb) < tailneed)) {
34465 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
34466 + if (unlikely(pskb_expand_head(skb, CCMP_HDR_LEN, tailneed,
34467 + GFP_ATOMIC)))
34468 + return -1;
34469 + }
34470 +
34471 + pos = skb_push(skb, CCMP_HDR_LEN);
34472 + memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
34473 + hdr = (struct ieee80211_hdr *) pos;
34474 + pos += hdrlen;
34475 +
34476 + /* PN = PN + 1 */
34477 + pn = key->u.ccmp.tx_pn;
34478 +
34479 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34480 + if (test & WPA_TRIGGER_TX_REPLAY)
34481 + goto skip_pn_inc;
34482 +pn_inc:
34483 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34484 +
34485 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
34486 + pn[i]++;
34487 + if (pn[i])
34488 + break;
34489 + }
34490 +
34491 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34492 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34493 + test = 0;
34494 + goto pn_inc;
34495 + }
34496 +skip_pn_inc:
34497 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34498 +
34499 + ccmp_pn2hdr(pos, pn, key->keyidx);
34500 +
34501 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt) {
34502 + /* hwaccel - with preallocated room for CCMP header */
34503 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34504 + return 0;
34505 + }
34506 +
34507 + pos += CCMP_HDR_LEN;
34508 + ccmp_special_blocks(skb, pn, b_0, aad, 0);
34509 + ieee80211_aes_ccm_encrypt(key->u.ccmp.aes_state, b_0, aad, pos, len,
34510 + pos, skb_put(skb, CCMP_MIC_LEN));
34511 +
34512 + return 0;
34513 +}
34514 +
34515 +
34516 +ieee80211_txrx_result
34517 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx)
34518 +{
34519 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34520 + struct ieee80211_key *key = tx->key;
34521 + u16 fc;
34522 + struct sk_buff *skb = tx->skb;
34523 + int test = 0;
34524 +
34525 + fc = le16_to_cpu(hdr->frame_control);
34526 +
34527 + if (!key || key->alg != ALG_CCMP || !WLAN_FC_DATA_PRESENT(fc))
34528 + return TXRX_CONTINUE;
34529 +
34530 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34531 + if (tx->sta) {
34532 + test = tx->sta->wpa_trigger;
34533 + tx->sta->wpa_trigger = 0;
34534 + } else {
34535 + test = tx->local->wpa_trigger;
34536 + tx->local->wpa_trigger = 0;
34537 + }
34538 + if (test &
34539 + (WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34540 + WPA_TRIGGER_TX_SKIP_SEQ)) {
34541 + printk(KERN_INFO "%s: WPA testing - CCMP TX packet number "
34542 + "%s%s%s%s\n", tx->dev->name,
34543 + tx->sta ? "[UNICAST]" : "[MULTICAST]",
34544 + test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
34545 + test & WPA_TRIGGER_TX_REPLAY_FRAG ?
34546 + "[REPLAY FRAG]" : "",
34547 + test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
34548 + }
34549 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34550 +
34551 + tx->u.tx.control->icv_len = CCMP_MIC_LEN;
34552 + tx->u.tx.control->iv_len = CCMP_HDR_LEN;
34553 + ieee80211_tx_set_iswep(tx);
34554 +
34555 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
34556 + !tx->local->hw->wep_include_iv) {
34557 + /* hwaccel - with no need for preallocated room for CCMP "
34558 + * header or MIC fields */
34559 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34560 + return TXRX_CONTINUE;
34561 + }
34562 +
34563 + if (ccmp_encrypt_skb(tx, skb, test) < 0)
34564 + return TXRX_DROP;
34565 +
34566 + if (tx->u.tx.extra_frag) {
34567 + int i;
34568 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34569 + if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
34570 + test |= WPA_TRIGGER_TX_REPLAY;
34571 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34572 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
34573 + if (ccmp_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
34574 + < 0)
34575 + return TXRX_DROP;
34576 + }
34577 + }
34578 +
34579 + return TXRX_CONTINUE;
34580 +}
34581 +
34582 +
34583 +ieee80211_txrx_result
34584 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx)
34585 +{
34586 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34587 + u16 fc;
34588 + int hdrlen;
34589 + struct ieee80211_key *key = rx->key;
34590 + struct sk_buff *skb = rx->skb;
34591 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34592 + u8 pn[CCMP_PN_LEN];
34593 + int data_len;
34594 +
34595 + fc = le16_to_cpu(hdr->frame_control);
34596 + hdrlen = ieee80211_get_hdrlen(fc);
34597 +
34598 + if (!rx->key || rx->key->alg != ALG_CCMP ||
34599 + !(rx->fc & WLAN_FC_ISWEP) ||
34600 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA)
34601 + return TXRX_CONTINUE;
34602 +
34603 + data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
34604 + if (!rx->sta || data_len < 0)
34605 + return TXRX_DROP;
34606 +
34607 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34608 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt &&
34609 + !rx->local->hw->wep_include_iv)
34610 + return TXRX_CONTINUE;
34611 +
34612 + (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
34613 +
34614 + if (memcmp(pn, key->u.ccmp.rx_pn[rx->u.rx.queue], CCMP_PN_LEN) <= 0) {
34615 +#ifdef CONFIG_D80211_DEBUG
34616 + u8 *ppn = key->u.ccmp.rx_pn[rx->u.rx.queue];
34617 + printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
34618 + MACSTR " (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
34619 + "%02x%02x%02x%02x%02x%02x)\n", rx->dev->name,
34620 + MAC2STR(rx->sta->addr),
34621 + pn[0], pn[1], pn[2], pn[3], pn[4], pn[5],
34622 + ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
34623 +#endif /* CONFIG_D80211_DEBUG */
34624 + key->u.ccmp.replays++;
34625 + return TXRX_DROP;
34626 + }
34627 +
34628 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34629 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34630 + /* hwaccel has already decrypted frame and verified MIC */
34631 + } else {
34632 + ccmp_special_blocks(skb, pn, b_0, aad, 1);
34633 +
34634 + if (ieee80211_aes_ccm_decrypt(
34635 + key->u.ccmp.aes_state, b_0, aad,
34636 + skb->data + hdrlen + CCMP_HDR_LEN, data_len,
34637 + skb->data + skb->len - CCMP_MIC_LEN,
34638 + skb->data + hdrlen + CCMP_HDR_LEN)) {
34639 + printk(KERN_DEBUG "%s: CCMP decrypt failed for RX "
34640 + "frame from " MACSTR "\n", rx->dev->name,
34641 + MAC2STR(rx->sta->addr));
34642 + return TXRX_DROP;
34643 + }
34644 + }
34645 +
34646 + memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
34647 +
34648 + /* Remove CCMP header and MIC */
34649 + skb_trim(skb, skb->len - CCMP_MIC_LEN);
34650 + memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
34651 + skb_pull(skb, CCMP_HDR_LEN);
34652 +
34653 + return TXRX_CONTINUE;
34654 +}
34655 +
34656 diff -Nur linux-2.6.16/net/d80211/wpa.h linux-2.6.16-bcm43xx/net/d80211/wpa.h
34657 --- linux-2.6.16/net/d80211/wpa.h 1970-01-01 01:00:00.000000000 +0100
34658 +++ linux-2.6.16-bcm43xx/net/d80211/wpa.h 2006-03-28 22:16:14.000000000 +0200
34659 @@ -0,0 +1,34 @@
34660 +/*
34661 + * Copyright 2002-2004, Instant802 Networks, Inc.
34662 + *
34663 + * This program is free software; you can redistribute it and/or modify
34664 + * it under the terms of the GNU General Public License version 2 as
34665 + * published by the Free Software Foundation.
34666 + */
34667 +
34668 +#ifndef WPA_H
34669 +#define WPA_H
34670 +
34671 +#include <linux/skbuff.h>
34672 +#include <linux/types.h>
34673 +#include "ieee80211_i.h"
34674 +
34675 +ieee80211_txrx_result
34676 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx);
34677 +ieee80211_txrx_result
34678 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx);
34679 +
34680 +ieee80211_txrx_result
34681 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx);
34682 +ieee80211_txrx_result
34683 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx);
34684 +
34685 +ieee80211_txrx_result
34686 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx);
34687 +ieee80211_txrx_result
34688 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx);
34689 +
34690 +int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
34691 + u8 *qos_tid, u8 **data, size_t *data_len);
34692 +
34693 +#endif /* WPA_H */
34694 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt.c
34695 --- linux-2.6.16/net/ieee80211/ieee80211_crypt.c 2006-03-20 06:53:29.000000000 +0100
34696 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt.c 2006-03-28 22:16:14.000000000 +0200
34697 @@ -18,7 +18,6 @@
34698 #include <linux/string.h>
34699 #include <net/ieee80211.h>
34700
34701 -
34702 MODULE_AUTHOR("Jouni Malinen");
34703 MODULE_DESCRIPTION("HostAP crypto");
34704 MODULE_LICENSE("GPL");
34705 @@ -33,11 +32,11 @@
34706
34707 void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
34708 {
34709 - struct ieee80211_crypt_data *entry, *next;
34710 + struct ieee80211_crypt_data *entry, *next;
34711 unsigned long flags;
34712
34713 spin_lock_irqsave(&ieee->lock, flags);
34714 - list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
34715 + list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
34716 if (atomic_read(&entry->refcnt) != 0 && !force)
34717 continue;
34718
34719 @@ -141,9 +140,9 @@
34720 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34721 return -EINVAL;
34722
34723 - found:
34724 + found:
34725 printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
34726 - "'%s'\n", ops->name);
34727 + "'%s'\n", ops->name);
34728 list_del(&alg->list);
34729 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34730 kfree(alg);
34731 @@ -163,7 +162,7 @@
34732 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34733 return NULL;
34734
34735 - found:
34736 + found:
34737 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34738 return alg->ops;
34739 }
34740 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_ccmp.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_ccmp.c
34741 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_ccmp.c 2006-03-20 06:53:29.000000000 +0100
34742 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_ccmp.c 2006-03-28 22:16:14.000000000 +0200
34743 @@ -190,7 +190,8 @@
34744 ieee80211_ccmp_aes_encrypt(tfm, b0, s0);
34745 }
34746
34747 -static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len, void *priv)
34748 +static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len,
34749 + u8 *aeskey, int keylen, void *priv)
34750 {
34751 struct ieee80211_ccmp_data *key = priv;
34752 int i;
34753 @@ -199,6 +200,9 @@
34754 if (skb_headroom(skb) < CCMP_HDR_LEN || skb->len < hdr_len)
34755 return -1;
34756
34757 + if (aeskey != NULL && keylen >= CCMP_TK_LEN)
34758 + memcpy(aeskey, key->key, CCMP_TK_LEN);
34759 +
34760 pos = skb_push(skb, CCMP_HDR_LEN);
34761 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
34762 pos += hdr_len;
34763 @@ -238,7 +242,7 @@
34764 return -1;
34765
34766 data_len = skb->len - hdr_len;
34767 - len = ieee80211_ccmp_hdr(skb, hdr_len, priv);
34768 + len = ieee80211_ccmp_hdr(skb, hdr_len, NULL, 0, priv);
34769 if (len < 0)
34770 return -1;
34771
34772 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_tkip.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_tkip.c
34773 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_tkip.c 2006-03-20 06:53:29.000000000 +0100
34774 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_tkip.c 2006-03-28 22:16:14.000000000 +0200
34775 @@ -80,10 +80,9 @@
34776 {
34777 struct ieee80211_tkip_data *priv;
34778
34779 - priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
34780 + priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
34781 if (priv == NULL)
34782 goto fail;
34783 - memset(priv, 0, sizeof(*priv));
34784
34785 priv->key_idx = key_idx;
34786
34787 @@ -271,34 +270,33 @@
34788 #endif
34789 }
34790
34791 -static u8 *ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, void *priv)
34792 +static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
34793 + u8 * rc4key, int keylen, void *priv)
34794 {
34795 struct ieee80211_tkip_data *tkey = priv;
34796 int len;
34797 - u8 *rc4key, *pos, *icv;
34798 + u8 *pos;
34799 struct ieee80211_hdr_4addr *hdr;
34800 - u32 crc;
34801
34802 hdr = (struct ieee80211_hdr_4addr *)skb->data;
34803
34804 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
34805 - return NULL;
34806 + return -1;
34807 +
34808 + if (rc4key == NULL || keylen < 16)
34809 + return -1;
34810
34811 if (!tkey->tx_phase1_done) {
34812 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
34813 tkey->tx_iv32);
34814 tkey->tx_phase1_done = 1;
34815 }
34816 - rc4key = kmalloc(16, GFP_ATOMIC);
34817 - if (!rc4key)
34818 - return NULL;
34819 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
34820
34821 len = skb->len - hdr_len;
34822 pos = skb_push(skb, 8);
34823 memmove(pos, pos + 8, hdr_len);
34824 pos += hdr_len;
34825 - icv = skb_put(skb, 4);
34826
34827 *pos++ = *rc4key;
34828 *pos++ = *(rc4key + 1);
34829 @@ -309,28 +307,28 @@
34830 *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
34831 *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
34832
34833 - crc = ~crc32_le(~0, pos, len);
34834 - icv[0] = crc;
34835 - icv[1] = crc >> 8;
34836 - icv[2] = crc >> 16;
34837 - icv[3] = crc >> 24;
34838 + tkey->tx_iv16++;
34839 + if (tkey->tx_iv16 == 0) {
34840 + tkey->tx_phase1_done = 0;
34841 + tkey->tx_iv32++;
34842 + }
34843
34844 - return rc4key;
34845 + return 8;
34846 }
34847
34848 static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
34849 {
34850 struct ieee80211_tkip_data *tkey = priv;
34851 int len;
34852 - const u8 *rc4key;
34853 - u8 *pos;
34854 + u8 rc4key[16], *pos, *icv;
34855 + u32 crc;
34856 struct scatterlist sg;
34857
34858 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
34859 if (net_ratelimit()) {
34860 struct ieee80211_hdr_4addr *hdr =
34861 (struct ieee80211_hdr_4addr *)skb->data;
34862 - printk(KERN_DEBUG "TKIP countermeasures: dropped "
34863 + printk(KERN_DEBUG ": TKIP countermeasures: dropped "
34864 "TX packet to " MAC_FMT "\n",
34865 MAC_ARG(hdr->addr1));
34866 }
34867 @@ -343,22 +341,23 @@
34868 len = skb->len - hdr_len;
34869 pos = skb->data + hdr_len;
34870
34871 - rc4key = ieee80211_tkip_hdr(skb, hdr_len, priv);
34872 - if (!rc4key)
34873 + if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
34874 return -1;
34875
34876 + icv = skb_put(skb, 4);
34877 +
34878 + crc = ~crc32_le(~0, pos, len);
34879 + icv[0] = crc;
34880 + icv[1] = crc >> 8;
34881 + icv[2] = crc >> 16;
34882 + icv[3] = crc >> 24;
34883 +
34884 crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16);
34885 sg.page = virt_to_page(pos);
34886 sg.offset = offset_in_page(pos);
34887 sg.length = len + 4;
34888 crypto_cipher_encrypt(tkey->tfm_arc4, &sg, &sg, len + 4);
34889
34890 - tkey->tx_iv16++;
34891 - if (tkey->tx_iv16 == 0) {
34892 - tkey->tx_phase1_done = 0;
34893 - tkey->tx_iv32++;
34894 - }
34895 -
34896 return 0;
34897 }
34898
34899 @@ -379,7 +378,7 @@
34900
34901 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
34902 if (net_ratelimit()) {
34903 - printk(KERN_DEBUG "TKIP countermeasures: dropped "
34904 + printk(KERN_DEBUG ": TKIP countermeasures: dropped "
34905 "received packet from " MAC_FMT "\n",
34906 MAC_ARG(hdr->addr2));
34907 }
34908 @@ -695,6 +694,7 @@
34909 .name = "TKIP",
34910 .init = ieee80211_tkip_init,
34911 .deinit = ieee80211_tkip_deinit,
34912 + .build_iv = ieee80211_tkip_hdr,
34913 .encrypt_mpdu = ieee80211_tkip_encrypt,
34914 .decrypt_mpdu = ieee80211_tkip_decrypt,
34915 .encrypt_msdu = ieee80211_michael_mic_add,
34916 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_wep.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_wep.c
34917 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_wep.c 2006-03-20 06:53:29.000000000 +0100
34918 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_wep.c 2006-03-28 22:16:14.000000000 +0200
34919 @@ -76,7 +76,8 @@
34920 }
34921
34922 /* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
34923 -static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len, void *priv)
34924 +static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len,
34925 + u8 *key, int keylen, void *priv)
34926 {
34927 struct prism2_wep_data *wep = priv;
34928 u32 klen, len;
34929 @@ -131,7 +132,7 @@
34930 return -1;
34931
34932 /* add the IV to the frame */
34933 - if (prism2_wep_build_iv(skb, hdr_len, priv))
34934 + if (prism2_wep_build_iv(skb, hdr_len, NULL, 0, priv))
34935 return -1;
34936
34937 /* Copy the IV into the first 3 bytes of the key */
34938 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_geo.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_geo.c
34939 --- linux-2.6.16/net/ieee80211/ieee80211_geo.c 2006-03-20 06:53:29.000000000 +0100
34940 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_geo.c 2006-03-28 22:16:14.000000000 +0200
34941 @@ -50,7 +50,8 @@
34942
34943 /* Driver needs to initialize the geography map before using
34944 * these helper functions */
34945 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
34946 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
34947 + return 0;
34948
34949 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
34950 for (i = 0; i < ieee->geo.bg_channels; i++)
34951 @@ -58,13 +59,15 @@
34952 * this is a B only channel, we don't see it
34953 * as valid. */
34954 if ((ieee->geo.bg[i].channel == channel) &&
34955 + !(ieee->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
34956 (!(ieee->mode & IEEE_G) ||
34957 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
34958 return IEEE80211_24GHZ_BAND;
34959
34960 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
34961 for (i = 0; i < ieee->geo.a_channels; i++)
34962 - if (ieee->geo.a[i].channel == channel)
34963 + if ((ieee->geo.a[i].channel == channel) &&
34964 + !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
34965 return IEEE80211_52GHZ_BAND;
34966
34967 return 0;
34968 @@ -76,7 +79,8 @@
34969
34970 /* Driver needs to initialize the geography map before using
34971 * these helper functions */
34972 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
34973 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
34974 + return -1;
34975
34976 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
34977 for (i = 0; i < ieee->geo.bg_channels; i++)
34978 @@ -97,7 +101,8 @@
34979
34980 /* Driver needs to initialize the geography map before using
34981 * these helper functions */
34982 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
34983 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
34984 + return 0;
34985
34986 freq /= 100000;
34987
34988 @@ -133,6 +138,41 @@
34989 return &ieee->geo;
34990 }
34991
34992 +u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
34993 +{
34994 + int index = ieee80211_channel_to_index(ieee, channel);
34995 +
34996 + if (index == -1)
34997 + return IEEE80211_CH_INVALID;
34998 +
34999 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35000 + return ieee->geo.bg[index].flags;
35001 +
35002 + return ieee->geo.a[index].flags;
35003 +}
35004 +
35005 +static const struct ieee80211_channel bad_channel = {
35006 + .channel = 0,
35007 + .flags = IEEE80211_CH_INVALID,
35008 + .max_power = 0,
35009 +};
35010 +
35011 +const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
35012 + *ieee, u8 channel)
35013 +{
35014 + int index = ieee80211_channel_to_index(ieee, channel);
35015 +
35016 + if (index == -1)
35017 + return &bad_channel;
35018 +
35019 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35020 + return &ieee->geo.bg[index];
35021 +
35022 + return &ieee->geo.a[index];
35023 +}
35024 +
35025 +EXPORT_SYMBOL(ieee80211_get_channel);
35026 +EXPORT_SYMBOL(ieee80211_get_channel_flags);
35027 EXPORT_SYMBOL(ieee80211_is_valid_channel);
35028 EXPORT_SYMBOL(ieee80211_freq_to_channel);
35029 EXPORT_SYMBOL(ieee80211_channel_to_index);
35030 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_module.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_module.c
35031 --- linux-2.6.16/net/ieee80211/ieee80211_module.c 2006-03-20 06:53:29.000000000 +0100
35032 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_module.c 2006-03-28 22:16:14.000000000 +0200
35033 @@ -82,10 +82,28 @@
35034 return 0;
35035 }
35036
35037 +void ieee80211_network_reset(struct ieee80211_network *network)
35038 +{
35039 + if (!network)
35040 + return;
35041 +
35042 + if (network->ibss_dfs) {
35043 + kfree(network->ibss_dfs);
35044 + network->ibss_dfs = NULL;
35045 + }
35046 +}
35047 +
35048 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
35049 {
35050 + int i;
35051 +
35052 if (!ieee->networks)
35053 return;
35054 +
35055 + for (i = 0; i < MAX_NETWORK_COUNT; i++)
35056 + if (ieee->networks[i].ibss_dfs)
35057 + kfree(ieee->networks[i].ibss_dfs);
35058 +
35059 kfree(ieee->networks);
35060 ieee->networks = NULL;
35061 }
35062 @@ -195,7 +213,7 @@
35063
35064 static int debug = 0;
35065 u32 ieee80211_debug_level = 0;
35066 -struct proc_dir_entry *ieee80211_proc = NULL;
35067 +static struct proc_dir_entry *ieee80211_proc = NULL;
35068
35069 static int show_debug_level(char *page, char **start, off_t offset,
35070 int count, int *eof, void *data)
35071 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_rx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_rx.c
35072 --- linux-2.6.16/net/ieee80211/ieee80211_rx.c 2006-03-20 06:53:29.000000000 +0100
35073 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_rx.c 2006-03-28 22:16:14.000000000 +0200
35074 @@ -369,8 +369,8 @@
35075
35076 /* Put this code here so that we avoid duplicating it in all
35077 * Rx paths. - Jean II */
35078 +#ifdef CONFIG_WIRELESS_EXT
35079 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
35080 -#ifdef CONFIG_NET_RADIO
35081 /* If spy monitoring on */
35082 if (ieee->spy_data.spy_number > 0) {
35083 struct iw_quality wstats;
35084 @@ -397,8 +397,8 @@
35085 /* Update spy records */
35086 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
35087 }
35088 -#endif /* CONFIG_NET_RADIO */
35089 #endif /* IW_WIRELESS_SPY */
35090 +#endif /* CONFIG_WIRELESS_EXT */
35091
35092 #ifdef NOT_YET
35093 hostap_update_rx_stats(local->ap, hdr, rx_stats);
35094 @@ -574,7 +574,7 @@
35095 /* skb: hdr + (possibly fragmented) plaintext payload */
35096 // PR: FIXME: hostap has additional conditions in the "if" below:
35097 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
35098 - if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
35099 + if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
35100 int flen;
35101 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
35102 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
35103 @@ -754,7 +754,14 @@
35104 memset(skb->cb, 0, sizeof(skb->cb));
35105 skb->dev = dev;
35106 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
35107 - netif_rx(skb);
35108 + if (netif_rx(skb) == NET_RX_DROP) {
35109 + /* netif_rx always succeeds, but it might drop
35110 + * the packet. If it drops the packet, we log that
35111 + * in our stats. */
35112 + IEEE80211_DEBUG_DROP
35113 + ("RX: netif_rx dropped the packet\n");
35114 + stats->rx_dropped++;
35115 + }
35116 }
35117
35118 rx_exit:
35119 @@ -930,6 +937,45 @@
35120 return rc;
35121 }
35122
35123 +#ifdef CONFIG_IEEE80211_DEBUG
35124 +#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
35125 +
35126 +static const char *get_info_element_string(u16 id)
35127 +{
35128 + switch (id) {
35129 + MFIE_STRING(SSID);
35130 + MFIE_STRING(RATES);
35131 + MFIE_STRING(FH_SET);
35132 + MFIE_STRING(DS_SET);
35133 + MFIE_STRING(CF_SET);
35134 + MFIE_STRING(TIM);
35135 + MFIE_STRING(IBSS_SET);
35136 + MFIE_STRING(COUNTRY);
35137 + MFIE_STRING(HOP_PARAMS);
35138 + MFIE_STRING(HOP_TABLE);
35139 + MFIE_STRING(REQUEST);
35140 + MFIE_STRING(CHALLENGE);
35141 + MFIE_STRING(POWER_CONSTRAINT);
35142 + MFIE_STRING(POWER_CAPABILITY);
35143 + MFIE_STRING(TPC_REQUEST);
35144 + MFIE_STRING(TPC_REPORT);
35145 + MFIE_STRING(SUPP_CHANNELS);
35146 + MFIE_STRING(CSA);
35147 + MFIE_STRING(MEASURE_REQUEST);
35148 + MFIE_STRING(MEASURE_REPORT);
35149 + MFIE_STRING(QUIET);
35150 + MFIE_STRING(IBSS_DFS);
35151 + MFIE_STRING(ERP_INFO);
35152 + MFIE_STRING(RSN);
35153 + MFIE_STRING(RATES_EX);
35154 + MFIE_STRING(GENERIC);
35155 + MFIE_STRING(QOS_PARAMETER);
35156 + default:
35157 + return "UNKNOWN";
35158 + }
35159 +}
35160 +#endif
35161 +
35162 static int ieee80211_parse_info_param(struct ieee80211_info_element
35163 *info_element, u16 length,
35164 struct ieee80211_network *network)
35165 @@ -1040,7 +1086,9 @@
35166 break;
35167
35168 case MFIE_TYPE_TIM:
35169 - IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: ignored\n");
35170 + network->tim.tim_count = info_element->data[0];
35171 + network->tim.tim_period = info_element->data[1];
35172 + IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
35173 break;
35174
35175 case MFIE_TYPE_ERP_INFO:
35176 @@ -1091,10 +1139,49 @@
35177 printk(KERN_ERR
35178 "QoS Error need to parse QOS_PARAMETER IE\n");
35179 break;
35180 + /* 802.11h */
35181 + case MFIE_TYPE_POWER_CONSTRAINT:
35182 + network->power_constraint = info_element->data[0];
35183 + network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
35184 + break;
35185 +
35186 + case MFIE_TYPE_CSA:
35187 + network->power_constraint = info_element->data[0];
35188 + network->flags |= NETWORK_HAS_CSA;
35189 + break;
35190 +
35191 + case MFIE_TYPE_QUIET:
35192 + network->quiet.count = info_element->data[0];
35193 + network->quiet.period = info_element->data[1];
35194 + network->quiet.duration = info_element->data[2];
35195 + network->quiet.offset = info_element->data[3];
35196 + network->flags |= NETWORK_HAS_QUIET;
35197 + break;
35198 +
35199 + case MFIE_TYPE_IBSS_DFS:
35200 + if (network->ibss_dfs)
35201 + break;
35202 + network->ibss_dfs =
35203 + kmalloc(info_element->len, GFP_ATOMIC);
35204 + if (!network->ibss_dfs)
35205 + return 1;
35206 + memcpy(network->ibss_dfs, info_element->data,
35207 + info_element->len);
35208 + network->flags |= NETWORK_HAS_IBSS_DFS;
35209 + break;
35210 +
35211 + case MFIE_TYPE_TPC_REPORT:
35212 + network->tpc_report.transmit_power =
35213 + info_element->data[0];
35214 + network->tpc_report.link_margin = info_element->data[1];
35215 + network->flags |= NETWORK_HAS_TPC_REPORT;
35216 + break;
35217
35218 default:
35219 - IEEE80211_DEBUG_MGMT("unsupported IE %d\n",
35220 - info_element->id);
35221 + IEEE80211_DEBUG_MGMT
35222 + ("Unsupported info element: %s (%d)\n",
35223 + get_info_element_string(info_element->id),
35224 + info_element->id);
35225 break;
35226 }
35227
35228 @@ -1110,7 +1197,9 @@
35229 static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
35230 *frame, struct ieee80211_rx_stats *stats)
35231 {
35232 - struct ieee80211_network network_resp;
35233 + struct ieee80211_network network_resp = {
35234 + .ibss_dfs = NULL,
35235 + };
35236 struct ieee80211_network *network = &network_resp;
35237 struct net_device *dev = ieee->dev;
35238
35239 @@ -1253,7 +1342,22 @@
35240 int qos_active;
35241 u8 old_param;
35242
35243 - memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
35244 + ieee80211_network_reset(dst);
35245 + dst->ibss_dfs = src->ibss_dfs;
35246 +
35247 + /* We only update the statistics if they were created by receiving
35248 + * the network information on the actual channel the network is on.
35249 + *
35250 + * This keeps beacons received on neighbor channels from bringing
35251 + * down the signal level of an AP. */
35252 + if (dst->channel == src->stats.received_channel)
35253 + memcpy(&dst->stats, &src->stats,
35254 + sizeof(struct ieee80211_rx_stats));
35255 + else
35256 + IEEE80211_DEBUG_SCAN("Network " MAC_FMT " info received "
35257 + "off channel (%d vs. %d)\n", MAC_ARG(src->bssid),
35258 + dst->channel, src->stats.received_channel);
35259 +
35260 dst->capability = src->capability;
35261 memcpy(dst->rates, src->rates, src->rates_len);
35262 dst->rates_len = src->rates_len;
35263 @@ -1269,6 +1373,7 @@
35264 dst->listen_interval = src->listen_interval;
35265 dst->atim_window = src->atim_window;
35266 dst->erp_value = src->erp_value;
35267 + dst->tim = src->tim;
35268
35269 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
35270 dst->wpa_ie_len = src->wpa_ie_len;
35271 @@ -1313,7 +1418,9 @@
35272 *stats)
35273 {
35274 struct net_device *dev = ieee->dev;
35275 - struct ieee80211_network network;
35276 + struct ieee80211_network network = {
35277 + .ibss_dfs = NULL,
35278 + };
35279 struct ieee80211_network *target;
35280 struct ieee80211_network *oldest = NULL;
35281 #ifdef CONFIG_IEEE80211_DEBUG
35282 @@ -1386,6 +1493,7 @@
35283 escape_essid(target->ssid,
35284 target->ssid_len),
35285 MAC_ARG(target->bssid));
35286 + ieee80211_network_reset(target);
35287 } else {
35288 /* Otherwise just pull from the free list */
35289 target = list_entry(ieee->network_free_list.next,
35290 @@ -1402,6 +1510,7 @@
35291 "BEACON" : "PROBE RESPONSE");
35292 #endif
35293 memcpy(target, &network, sizeof(*target));
35294 + network.ibss_dfs = NULL;
35295 list_add_tail(&target->list, &ieee->network_list);
35296 } else {
35297 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
35298 @@ -1411,6 +1520,7 @@
35299 is_beacon(beacon->header.frame_ctl) ?
35300 "BEACON" : "PROBE RESPONSE");
35301 update_network(target, &network);
35302 + network.ibss_dfs = NULL;
35303 }
35304
35305 spin_unlock_irqrestore(&ieee->lock, flags);
35306 @@ -1495,10 +1605,43 @@
35307 header);
35308 break;
35309
35310 + case IEEE80211_STYPE_ACTION:
35311 + IEEE80211_DEBUG_MGMT("ACTION\n");
35312 + if (ieee->handle_action)
35313 + ieee->handle_action(ieee->dev,
35314 + (struct ieee80211_action *)
35315 + header, stats);
35316 + break;
35317 +
35318 + case IEEE80211_STYPE_REASSOC_REQ:
35319 + IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
35320 + WLAN_FC_GET_STYPE(le16_to_cpu
35321 + (header->frame_ctl)));
35322 +
35323 + IEEE80211_WARNING("%s: IEEE80211_REASSOC_REQ received\n",
35324 + ieee->dev->name);
35325 + if (ieee->handle_reassoc_request != NULL)
35326 + ieee->handle_reassoc_request(ieee->dev,
35327 + (struct ieee80211_reassoc_request *)
35328 + header);
35329 + break;
35330 +
35331 + case IEEE80211_STYPE_ASSOC_REQ:
35332 + IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
35333 + WLAN_FC_GET_STYPE(le16_to_cpu
35334 + (header->frame_ctl)));
35335 +
35336 + IEEE80211_WARNING("%s: IEEE80211_ASSOC_REQ received\n",
35337 + ieee->dev->name);
35338 + if (ieee->handle_assoc_request != NULL)
35339 + ieee->handle_assoc_request(ieee->dev);
35340 + break;
35341 +
35342 case IEEE80211_STYPE_DEAUTH:
35343 - printk("DEAUTH from AP\n");
35344 + IEEE80211_DEBUG_MGMT("DEAUTH\n");
35345 if (ieee->handle_deauth != NULL)
35346 - ieee->handle_deauth(ieee->dev, (struct ieee80211_auth *)
35347 + ieee->handle_deauth(ieee->dev,
35348 + (struct ieee80211_deauth *)
35349 header);
35350 break;
35351 default:
35352 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_tx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_tx.c
35353 --- linux-2.6.16/net/ieee80211/ieee80211_tx.c 2006-03-20 06:53:29.000000000 +0100
35354 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_tx.c 2006-03-28 22:16:14.000000000 +0200
35355 @@ -56,7 +56,18 @@
35356 `--------------------------------------------------| |------'
35357 Total: 28 non-data bytes `----.----'
35358 |
35359 - .- 'Frame data' expands to <---------------------------'
35360 + .- 'Frame data' expands, if WEP enabled, to <----------'
35361 + |
35362 + V
35363 + ,-----------------------.
35364 +Bytes | 4 | 0-2296 | 4 |
35365 + |-----|-----------|-----|
35366 +Desc. | IV | Encrypted | ICV |
35367 + | | Packet | |
35368 + `-----| |-----'
35369 + `-----.-----'
35370 + |
35371 + .- 'Encrypted Packet' expands to
35372 |
35373 V
35374 ,---------------------------------------------------.
35375 @@ -65,18 +76,7 @@
35376 Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
35377 | DSAP | SSAP | | | | Packet |
35378 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
35379 - `-----------------------------------------| |
35380 -Total: 8 non-data bytes `----.----'
35381 - |
35382 - .- 'IP Packet' expands, if WEP enabled, to <--'
35383 - |
35384 - V
35385 - ,-----------------------.
35386 -Bytes | 4 | 0-2296 | 4 |
35387 - |-----|-----------|-----|
35388 -Desc. | IV | Encrypted | ICV |
35389 - | | IP Packet | |
35390 - `-----------------------'
35391 + `----------------------------------------------------
35392 Total: 8 non-data bytes
35393
35394 802.3 Ethernet Data Frame
35395 @@ -470,7 +470,9 @@
35396 atomic_inc(&crypt->refcnt);
35397 if (crypt->ops->build_iv)
35398 crypt->ops->build_iv(skb_frag, hdr_len,
35399 - crypt->priv);
35400 + ieee->sec.keys[ieee->sec.active_key],
35401 + ieee->sec.key_sizes[ieee->sec.active_key],
35402 + crypt->priv);
35403 atomic_dec(&crypt->refcnt);
35404 }
35405
35406 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_wx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_wx.c
35407 --- linux-2.6.16/net/ieee80211/ieee80211_wx.c 2006-03-20 06:53:29.000000000 +0100
35408 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_wx.c 2006-03-28 22:16:14.000000000 +0200
35409 @@ -149,9 +149,7 @@
35410 iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID |
35411 IW_QUAL_LEVEL_INVALID;
35412 iwe.u.qual.qual = 0;
35413 - iwe.u.qual.level = 0;
35414 } else {
35415 - iwe.u.qual.level = network->stats.rssi;
35416 if (ieee->perfect_rssi == ieee->worst_rssi)
35417 iwe.u.qual.qual = 100;
35418 else
35419 @@ -179,6 +177,13 @@
35420 iwe.u.qual.noise = network->stats.noise;
35421 }
35422
35423 + if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) {
35424 + iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
35425 + iwe.u.qual.level = 0;
35426 + } else {
35427 + iwe.u.qual.level = network->stats.signal;
35428 + }
35429 +
35430 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
35431
35432 iwe.cmd = IWEVCUSTOM;
35433 @@ -188,33 +193,21 @@
35434 if (iwe.u.data.length)
35435 start = iwe_stream_add_point(start, stop, &iwe, custom);
35436
35437 + memset(&iwe, 0, sizeof(iwe));
35438 if (network->wpa_ie_len) {
35439 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35440 -
35441 - u8 *p = buf;
35442 - p += sprintf(p, "wpa_ie=");
35443 - for (i = 0; i < network->wpa_ie_len; i++) {
35444 - p += sprintf(p, "%02x", network->wpa_ie[i]);
35445 - }
35446 -
35447 - memset(&iwe, 0, sizeof(iwe));
35448 - iwe.cmd = IWEVCUSTOM;
35449 - iwe.u.data.length = strlen(buf);
35450 + char buf[MAX_WPA_IE_LEN];
35451 + memcpy(buf, network->wpa_ie, network->wpa_ie_len);
35452 + iwe.cmd = IWEVGENIE;
35453 + iwe.u.data.length = network->wpa_ie_len;
35454 start = iwe_stream_add_point(start, stop, &iwe, buf);
35455 }
35456
35457 + memset(&iwe, 0, sizeof(iwe));
35458 if (network->rsn_ie_len) {
35459 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35460 -
35461 - u8 *p = buf;
35462 - p += sprintf(p, "rsn_ie=");
35463 - for (i = 0; i < network->rsn_ie_len; i++) {
35464 - p += sprintf(p, "%02x", network->rsn_ie[i]);
35465 - }
35466 -
35467 - memset(&iwe, 0, sizeof(iwe));
35468 - iwe.cmd = IWEVCUSTOM;
35469 - iwe.u.data.length = strlen(buf);
35470 + char buf[MAX_WPA_IE_LEN];
35471 + memcpy(buf, network->rsn_ie, network->rsn_ie_len);
35472 + iwe.cmd = IWEVGENIE;
35473 + iwe.u.data.length = network->rsn_ie_len;
35474 start = iwe_stream_add_point(start, stop, &iwe, buf);
35475 }
35476
35477 @@ -229,6 +222,28 @@
35478 if (iwe.u.data.length)
35479 start = iwe_stream_add_point(start, stop, &iwe, custom);
35480
35481 + /* Add spectrum management information */
35482 + iwe.cmd = -1;
35483 + p = custom;
35484 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Channel flags: ");
35485 +
35486 + if (ieee80211_get_channel_flags(ieee, network->channel) &
35487 + IEEE80211_CH_INVALID) {
35488 + iwe.cmd = IWEVCUSTOM;
35489 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "INVALID ");
35490 + }
35491 +
35492 + if (ieee80211_get_channel_flags(ieee, network->channel) &
35493 + IEEE80211_CH_RADAR_DETECT) {
35494 + iwe.cmd = IWEVCUSTOM;
35495 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "DFS ");
35496 + }
35497 +
35498 + if (iwe.cmd == IWEVCUSTOM) {
35499 + iwe.u.data.length = p - custom;
35500 + start = iwe_stream_add_point(start, stop, &iwe, custom);
35501 + }
35502 +
35503 return start;
35504 }
35505
35506 @@ -734,9 +749,98 @@
35507 return 0;
35508 }
35509
35510 +int ieee80211_wx_set_auth(struct net_device *dev,
35511 + struct iw_request_info *info,
35512 + union iwreq_data *wrqu,
35513 + char *extra)
35514 +{
35515 + struct ieee80211_device *ieee = netdev_priv(dev);
35516 + unsigned long flags;
35517 + int err = 0;
35518 +
35519 + spin_lock_irqsave(&ieee->lock, flags);
35520 +
35521 + switch (wrqu->param.flags & IW_AUTH_INDEX) {
35522 + case IW_AUTH_WPA_VERSION:
35523 + case IW_AUTH_CIPHER_PAIRWISE:
35524 + case IW_AUTH_CIPHER_GROUP:
35525 + case IW_AUTH_KEY_MGMT:
35526 + /*
35527 + * Host AP driver does not use these parameters and allows
35528 + * wpa_supplicant to control them internally.
35529 + */
35530 + break;
35531 + case IW_AUTH_TKIP_COUNTERMEASURES:
35532 + break; /* FIXME */
35533 + case IW_AUTH_DROP_UNENCRYPTED:
35534 + ieee->drop_unencrypted = !!wrqu->param.value;
35535 + break;
35536 + case IW_AUTH_80211_AUTH_ALG:
35537 + break; /* FIXME */
35538 + case IW_AUTH_WPA_ENABLED:
35539 + ieee->privacy_invoked = ieee->wpa_enabled = !!wrqu->param.value;
35540 + break;
35541 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35542 + ieee->ieee802_1x = !!wrqu->param.value;
35543 + break;
35544 + case IW_AUTH_PRIVACY_INVOKED:
35545 + ieee->privacy_invoked = !!wrqu->param.value;
35546 + break;
35547 + default:
35548 + err = -EOPNOTSUPP;
35549 + break;
35550 + }
35551 + spin_unlock_irqrestore(&ieee->lock, flags);
35552 + return err;
35553 +}
35554 +
35555 +int ieee80211_wx_get_auth(struct net_device *dev,
35556 + struct iw_request_info *info,
35557 + union iwreq_data *wrqu,
35558 + char *extra)
35559 +{
35560 + struct ieee80211_device *ieee = netdev_priv(dev);
35561 + unsigned long flags;
35562 + int err = 0;
35563 +
35564 + spin_lock_irqsave(&ieee->lock, flags);
35565 +
35566 + switch (wrqu->param.flags & IW_AUTH_INDEX) {
35567 + case IW_AUTH_WPA_VERSION:
35568 + case IW_AUTH_CIPHER_PAIRWISE:
35569 + case IW_AUTH_CIPHER_GROUP:
35570 + case IW_AUTH_KEY_MGMT:
35571 + case IW_AUTH_TKIP_COUNTERMEASURES: /* FIXME */
35572 + case IW_AUTH_80211_AUTH_ALG: /* FIXME */
35573 + /*
35574 + * Host AP driver does not use these parameters and allows
35575 + * wpa_supplicant to control them internally.
35576 + */
35577 + err = -EOPNOTSUPP;
35578 + break;
35579 + case IW_AUTH_DROP_UNENCRYPTED:
35580 + wrqu->param.value = ieee->drop_unencrypted;
35581 + break;
35582 + case IW_AUTH_WPA_ENABLED:
35583 + wrqu->param.value = ieee->wpa_enabled;
35584 + break;
35585 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35586 + wrqu->param.value = ieee->ieee802_1x;
35587 + break;
35588 + default:
35589 + err = -EOPNOTSUPP;
35590 + break;
35591 + }
35592 + spin_unlock_irqrestore(&ieee->lock, flags);
35593 + return err;
35594 +}
35595 +
35596 EXPORT_SYMBOL(ieee80211_wx_set_encodeext);
35597 EXPORT_SYMBOL(ieee80211_wx_get_encodeext);
35598
35599 EXPORT_SYMBOL(ieee80211_wx_get_scan);
35600 EXPORT_SYMBOL(ieee80211_wx_set_encode);
35601 EXPORT_SYMBOL(ieee80211_wx_get_encode);
35602 +
35603 +EXPORT_SYMBOL_GPL(ieee80211_wx_set_auth);
35604 +EXPORT_SYMBOL_GPL(ieee80211_wx_get_auth);
35605 diff -Nur linux-2.6.16/net/Kconfig linux-2.6.16-bcm43xx/net/Kconfig
35606 --- linux-2.6.16/net/Kconfig 2006-03-20 06:53:29.000000000 +0100
35607 +++ linux-2.6.16-bcm43xx/net/Kconfig 2006-03-28 22:16:14.000000000 +0200
35608 @@ -222,8 +222,12 @@
35609 source "net/ax25/Kconfig"
35610 source "net/irda/Kconfig"
35611 source "net/bluetooth/Kconfig"
35612 +source "net/d80211/Kconfig"
35613 source "net/ieee80211/Kconfig"
35614
35615 +config WIRELESS_EXT
35616 + bool
35617 +
35618 endif # if NET
35619 endmenu # Networking
35620
35621 diff -Nur linux-2.6.16/net/Makefile linux-2.6.16-bcm43xx/net/Makefile
35622 --- linux-2.6.16/net/Makefile 2006-03-20 06:53:29.000000000 +0100
35623 +++ linux-2.6.16-bcm43xx/net/Makefile 2006-03-28 22:16:14.000000000 +0200
35624 @@ -44,6 +44,7 @@
35625 obj-$(CONFIG_VLAN_8021Q) += 8021q/
35626 obj-$(CONFIG_IP_DCCP) += dccp/
35627 obj-$(CONFIG_IP_SCTP) += sctp/
35628 +obj-$(CONFIG_D80211) += d80211/
35629 obj-$(CONFIG_IEEE80211) += ieee80211/
35630 obj-$(CONFIG_TIPC) += tipc/
35631
35632 diff -Nur linux-2.6.16/net/socket.c linux-2.6.16-bcm43xx/net/socket.c
35633 --- linux-2.6.16/net/socket.c 2006-03-20 06:53:29.000000000 +0100
35634 +++ linux-2.6.16-bcm43xx/net/socket.c 2006-03-28 22:16:14.000000000 +0200
35635 @@ -84,10 +84,7 @@
35636 #include <linux/compat.h>
35637 #include <linux/kmod.h>
35638 #include <linux/audit.h>
35639 -
35640 -#ifdef CONFIG_NET_RADIO
35641 -#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
35642 -#endif /* CONFIG_NET_RADIO */
35643 +#include <linux/wireless.h>
35644
35645 #include <asm/uaccess.h>
35646 #include <asm/unistd.h>
35647 @@ -840,11 +837,11 @@
35648 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
35649 err = dev_ioctl(cmd, argp);
35650 } else
35651 -#ifdef WIRELESS_EXT
35652 +#ifdef CONFIG_WIRELESS_EXT
35653 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
35654 err = dev_ioctl(cmd, argp);
35655 } else
35656 -#endif /* WIRELESS_EXT */
35657 +#endif /* CONFIG_WIRELESS_EXT */
35658 switch (cmd) {
35659 case FIOSETOWN:
35660 case SIOCSPGRP:
35661 diff -Nur linux-2.6.16/scripts/bcm43xx-d80211-sta_up.sh linux-2.6.16-bcm43xx/scripts/bcm43xx-d80211-sta_up.sh
35662 --- linux-2.6.16/scripts/bcm43xx-d80211-sta_up.sh 1970-01-01 01:00:00.000000000 +0100
35663 +++ linux-2.6.16-bcm43xx/scripts/bcm43xx-d80211-sta_up.sh 2006-03-28 22:16:14.000000000 +0200
35664 @@ -0,0 +1,80 @@
35665 +#!/bin/bash
35666 +
35667 +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
35668 + echo "$0, an ugly script to configure and bring up a STA (802.11 station)"
35669 + echo "device for the linux devicescape 802.11 stack."
35670 + echo
35671 + echo "Usage:"
35672 + echo "$0 [ wlan_device local_ip wpasupplicant_config ]"
35673 + echo
35674 + echo "Examples:"
35675 + echo "Run with default parameters: $0"
35676 + echo "Manually define parameters: $0 wlan0 192.168.1.1 ./wpasupp.conf"
35677 + echo
35678 + echo "Default parameters are: $0 wlan0 192.168.1.101 /etc/wpa_supplicant.conf"
35679 + exit 1
35680 +fi
35681 +
35682 +wlan_dev="$1"
35683 +ip_addr="$2"
35684 +wpasupp_conf="$3"
35685 +
35686 +if [ -z "$wlan_dev" ]; then
35687 + wlan_dev="wlan0"
35688 +fi
35689 +if [ -z "$sta_dev" ]; then
35690 + sta_dev="sta0"
35691 +fi
35692 +if [ -z "$ip_addr" ]; then
35693 + ip_addr="192.168.1.101"
35694 +fi
35695 +if [ -z "$wpasupp_conf" ]; then
35696 + wpasupp_conf="/etc/wpa_supplicant.conf"
35697 +fi
35698 +
35699 +idx=$(echo $wlan_dev | awk '{ gsub("[^0-9]", "", $0); printf($0); }')
35700 +if [ -z "$idx" ]; then
35701 + echo "Invalid wlan_device parameter \"$wlan_dev\". Example: wlan0"
35702 + exit 1
35703 +fi
35704 +sta_dev="sta$idx"
35705 +phy_dev="phy$idx"
35706 +
35707 +function run()
35708 +{
35709 + echo "$@"
35710 + $@
35711 + res=$?
35712 + if [ $res -ne 0 ]; then
35713 + echo "FAILED ($res)"
35714 + exit 1
35715 + fi
35716 +}
35717 +
35718 +if [ -z "$(grep -e bcm43xx /proc/modules)" ]; then
35719 + echo "ERROR: bcm43xx module not loaded."
35720 + exit 1
35721 +fi
35722 +
35723 +killall wpa_supplicant 2>/dev/null
35724 +echo -n "$sta_dev" > /sys/class/ieee80211/${phy_dev}/add_iface
35725 +if [ $? -ne 0 ]; then
35726 + echo "ERROR: Could not add STA device."
35727 + exit 1
35728 +fi
35729 +run iwconfig $wlan_dev.11 mode managed
35730 +run ifconfig $wlan_dev.11 up
35731 +
35732 +hwaddr="$(ifconfig | grep $wlan_dev.11 | awk '{print $NF}')"
35733 +run ifconfig $sta_dev hw ether $hwaddr
35734 +run ifconfig $sta_dev $ip_addr
35735 +run ifconfig $sta_dev up
35736 +run iwconfig $sta_dev mode managed
35737 +
35738 +run wpa_supplicant -B -Dwext -i$sta_dev -c$wpasupp_conf
35739 +
35740 +echo
35741 +echo "You may want to set the default route, now:"
35742 +echo " route add default gw GATEWAY_IP_ADDRESS"
35743 +
35744 +exit 0