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
7 + Broadcom BCM43xx wireless driver
9 + debugfs driver debugging code
11 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
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.
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.
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.
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>
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"
46 +#define REALLY_BIG_BUFFER_SIZE (1024*256)
48 +static struct bcm43xx_debugfs fs;
49 +static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
50 +static DECLARE_MUTEX(big_buffer_sem);
53 +static ssize_t write_file_dummy(struct file *file, const char __user *buf,
54 + size_t count, loff_t *ppos)
59 +static int open_file_generic(struct inode *inode, struct file *file)
61 + file->private_data = inode->u.generic_ip;
65 +#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
67 +static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
68 + size_t count, loff_t *ppos)
70 + const size_t len = REALLY_BIG_BUFFER_SIZE;
72 + struct bcm43xx_private *bcm = file->private_data;
73 + char *buf = really_big_buffer;
76 + struct net_device *net_dev;
77 + struct pci_dev *pci_dev;
78 + unsigned long flags;
82 + down(&big_buffer_sem);
84 + bcm43xx_lock_mmio(bcm, flags);
85 + if (!bcm->initialized) {
86 + fappend("Board not initialized.\n");
89 + net_dev = bcm->net_dev;
90 + pci_dev = bcm->pci_dev;
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,
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", \
112 + ? "available" : "nonavailable", \
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]);
121 + tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
123 + for (i = 0; i < BCM43xx_NR_LEDS; i++)
124 + fappend("%d ", !!(tmp16 & (1 << i)));
128 + bcm43xx_unlock_mmio(bcm, flags);
129 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
130 + up(&big_buffer_sem);
134 +static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
135 + size_t count, loff_t *ppos)
137 + const size_t len = REALLY_BIG_BUFFER_SIZE;
139 + char *buf = really_big_buffer;
143 + down(&big_buffer_sem);
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__);
149 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
150 + up(&big_buffer_sem);
154 +static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
155 + size_t count, loff_t *ppos)
157 + const size_t len = REALLY_BIG_BUFFER_SIZE;
159 + struct bcm43xx_private *bcm = file->private_data;
160 + char *buf = really_big_buffer;
163 + unsigned long flags;
165 + down(&big_buffer_sem);
166 + bcm43xx_lock_mmio(bcm, flags);
167 + if (!bcm->initialized) {
168 + fappend("Board not initialized.\n");
172 + /* This is where the information is written to the "sprom_dump" file */
173 + fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
176 + bcm43xx_unlock_mmio(bcm, flags);
177 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
178 + up(&big_buffer_sem);
182 +static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
183 + size_t count, loff_t *ppos)
185 + const size_t len = REALLY_BIG_BUFFER_SIZE;
187 + struct bcm43xx_private *bcm = file->private_data;
188 + char *buf = really_big_buffer;
191 + unsigned long flags;
194 + down(&big_buffer_sem);
195 + bcm43xx_lock_mmio(bcm, flags);
196 + if (!bcm->initialized) {
197 + fappend("Board not initialized.\n");
200 + bcm43xx_tsf_read(bcm, &tsf);
201 + fappend("0x%08x%08x\n",
202 + (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
203 + (unsigned int)(tsf & 0xFFFFFFFFULL));
206 + bcm43xx_unlock_mmio(bcm, flags);
207 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
208 + up(&big_buffer_sem);
212 +static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
213 + size_t count, loff_t *ppos)
215 + struct bcm43xx_private *bcm = file->private_data;
216 + char *buf = really_big_buffer;
219 + unsigned long flags;
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)) {
228 + bcm43xx_lock_mmio(bcm, flags);
229 + if (!bcm->initialized) {
230 + printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
234 + if (sscanf(buf, "%lli", &tsf) != 1) {
235 + printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
239 + bcm43xx_tsf_write(bcm, tsf);
243 + bcm43xx_unlock_mmio(bcm, flags);
245 + up(&big_buffer_sem);
249 +static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
250 + size_t count, loff_t *ppos)
252 + const size_t len = REALLY_BIG_BUFFER_SIZE;
254 + struct bcm43xx_private *bcm = file->private_data;
255 + char *buf = really_big_buffer;
258 + unsigned long flags;
259 + struct bcm43xx_dfsentry *e;
260 + struct bcm43xx_xmitstatus *status;
263 + down(&big_buffer_sem);
264 + bcm43xx_lock(bcm, flags);
266 + fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
267 + BCM43xx_NR_LOGGED_XMITSTATUS);
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.
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)));
281 + i = e->saved_xmitstatus_ptr - 1;
283 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
284 + cnt = e->saved_xmitstatus_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,
297 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
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;
307 + bcm43xx_unlock(bcm, flags);
308 + up(&big_buffer_sem);
315 +static struct file_operations devinfo_fops = {
316 + .read = devinfo_read_file,
317 + .write = write_file_dummy,
318 + .open = open_file_generic,
321 +static struct file_operations spromdump_fops = {
322 + .read = spromdump_read_file,
323 + .write = write_file_dummy,
324 + .open = open_file_generic,
327 +static struct file_operations drvinfo_fops = {
328 + .read = drvinfo_read_file,
329 + .write = write_file_dummy,
330 + .open = open_file_generic,
333 +static struct file_operations tsf_fops = {
334 + .read = tsf_read_file,
335 + .write = tsf_write_file,
336 + .open = open_file_generic,
339 +static struct file_operations txstat_fops = {
340 + .read = txstat_read_file,
341 + .write = write_file_dummy,
342 + .open = open_file_generic,
346 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
348 + struct bcm43xx_dfsentry *e;
349 + char devdir[IFNAMSIZ];
352 + e = kzalloc(sizeof(*e), GFP_KERNEL);
354 + printk(KERN_ERR PFX "out of memory\n");
358 + e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
359 + * sizeof(*(e->xmitstatus_buffer)),
361 + if (!e->xmitstatus_buffer) {
362 + printk(KERN_ERR PFX "out of memory\n");
366 + e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
367 + * sizeof(*(e->xmitstatus_buffer)),
369 + if (!e->xmitstatus_print_buffer) {
370 + printk(KERN_ERR PFX "out of memory\n");
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,
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);
398 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
400 + struct bcm43xx_dfsentry *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);
417 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
418 + struct bcm43xx_xmitstatus *status)
420 + struct bcm43xx_dfsentry *e;
421 + struct bcm43xx_xmitstatus *savedstatus;
423 + /* This is protected by bcm->_lock */
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++;
435 +void bcm43xx_debugfs_init(void)
437 + memset(&fs, 0, sizeof(fs));
438 + fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
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");
446 +void bcm43xx_debugfs_exit(void)
448 + debugfs_remove(fs.dentry_driverinfo);
449 + debugfs_remove(fs.root);
452 +void bcm43xx_printk_dump(const char *data,
454 + const char *description)
459 + printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
460 + description, size);
461 + for (i = 0; i < size; i++) {
464 + printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
466 + printk("0x%02x, ", c & 0xff);
471 +void bcm43xx_printk_bitdump(const unsigned char *data,
472 + size_t bytes, int msb_to_lsb,
473 + const char *description)
477 + const unsigned char *d;
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++) {
484 + printk("\n" KERN_INFO PFX "0x%08x: ", i);
486 + for (j = 7; j >= 0; j--) {
493 + for (j = 0; j < 8; j++) {
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
508 +#ifndef BCM43xx_DEBUGFS_H_
509 +#define BCM43xx_DEBUGFS_H_
511 +struct bcm43xx_private;
512 +struct bcm43xx_xmitstatus;
514 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
516 +#include <linux/list.h>
517 +#include <asm/semaphore.h>
521 +/* limited by the size of the "really_big_buffer" */
522 +#define BCM43xx_NR_LOGGED_XMITSTATUS 100
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;
531 + struct bcm43xx_private *bcm;
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).
541 + struct bcm43xx_xmitstatus *xmitstatus_print_buffer;
542 + int saved_xmitstatus_ptr;
543 + int saved_xmitstatus_cnt;
544 + int xmitstatus_printing;
547 +struct bcm43xx_debugfs {
548 + struct dentry *root;
549 + struct dentry *dentry_driverinfo;
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);
559 +/* Debug helper: Dump binary data through printk. */
560 +void bcm43xx_printk_dump(const char *data,
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) \
569 + bcm43xx_printk_bitdump((const unsigned char *)(pointer), \
570 + sizeof(*(pointer)), \
575 +#else /* CONFIG_BCM43XX_D80211_DEBUG*/
578 +void bcm43xx_debugfs_init(void) { }
580 +void bcm43xx_debugfs_exit(void) { }
582 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm) { }
584 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm) { }
586 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
587 + struct bcm43xx_xmitstatus *status) { }
590 +void bcm43xx_printk_dump(const char *data,
592 + const char *description)
596 +void bcm43xx_printk_bitdump(const unsigned char *data,
597 + size_t bytes, int msb_to_lsb,
598 + const char *description)
601 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) do { /* nothing */ } while (0)
603 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
605 +/* Ugly helper macros to make incomplete code more verbose on runtime */
611 + printk(KERN_INFO PFX "TODO: Incomplete code in %s() at %s:%d\n", \
612 + __FUNCTION__, __FILE__, __LINE__); \
620 + printk(KERN_INFO PFX "FIXME: Possibly broken code in %s() at %s:%d\n", \
621 + __FUNCTION__, __FILE__, __LINE__); \
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
631 + Broadcom BCM43xx wireless driver
633 + DMA ringbuffer and descriptor allocation/management
635 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
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
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.
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.
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.
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"
665 +#include <linux/dma-mapping.h>
666 +#include <linux/pci.h>
667 +#include <linux/delay.h>
668 +#include <linux/skbuff.h>
671 +static inline int free_slots(struct bcm43xx_dmaring *ring)
673 + return (ring->nr_slots - ring->used_slots);
676 +static inline int next_slot(struct bcm43xx_dmaring *ring, int slot)
678 + assert(slot >= -1 && slot <= ring->nr_slots - 1);
679 + if (slot == ring->nr_slots - 1)
684 +static inline int prev_slot(struct bcm43xx_dmaring *ring, int slot)
686 + assert(slot >= 0 && slot <= ring->nr_slots - 1);
688 + return ring->nr_slots - 1;
692 +/* Request a slot for usage. */
694 +int request_slot(struct bcm43xx_dmaring *ring)
699 + assert(!ring->suspended);
700 + assert(free_slots(ring) != 0);
702 + slot = next_slot(ring, ring->current_slot);
703 + ring->current_slot = slot;
704 + ring->used_slots++;
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*/
714 +/* Return a slot to the free slots. */
716 +void return_slot(struct bcm43xx_dmaring *ring, int slot)
720 + ring->used_slots--;
724 +dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
725 + unsigned char *buf,
729 + dma_addr_t dmaaddr;
732 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
736 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
745 +void unmap_descbuffer(struct bcm43xx_dmaring *ring,
751 + dma_unmap_single(&ring->bcm->pci_dev->dev,
755 + dma_unmap_single(&ring->bcm->pci_dev->dev,
762 +void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
768 + dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev,
769 + addr, len, DMA_FROM_DEVICE);
773 +void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
779 + dma_sync_single_for_device(&ring->bcm->pci_dev->dev,
780 + addr, len, DMA_FROM_DEVICE);
783 +/* Unmap and free a descriptor buffer. */
785 +void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
786 + struct bcm43xx_dmadesc *desc,
787 + struct bcm43xx_dmadesc_meta *meta,
792 + dev_kfree_skb_irq(meta->skb);
794 + dev_kfree_skb(meta->skb);
798 +static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
800 + struct device *dev = &(ring->bcm->pci_dev->dev);
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");
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);
816 + assert(!(ring->dmabase & 0x000003FF));
817 + memset(ring->vbase, 0, BCM43xx_DMA_RINGMEMSIZE);
822 +static void free_ringmemory(struct bcm43xx_dmaring *ring)
824 + struct device *dev = &(ring->bcm->pci_dev->dev);
826 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
827 + ring->vbase, ring->dmabase);
830 +/* Reset the RX DMA channel */
831 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
837 + bcm43xx_write32(bcm,
838 + mmio_base + BCM43xx_DMA_RX_CONTROL,
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) {
851 + printk(KERN_ERR PFX "Error: Wait on DMA RX status timed out.\n");
858 +/* Reset the RX DMA channel */
859 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
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)
875 + bcm43xx_write32(bcm,
876 + mmio_base + BCM43xx_DMA_TX_CONTROL,
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) {
889 + printk(KERN_ERR PFX "Error: Wait on DMA TX status timed out.\n");
892 + /* ensure the reset is completed. */
898 +static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
899 + struct bcm43xx_dmadesc *desc,
900 + struct bcm43xx_dmadesc_meta *meta,
903 + struct bcm43xx_rxhdr *rxhdr;
904 + dma_addr_t dmaaddr;
907 + const int slot = (int)(desc - ring->vbase);
908 + struct sk_buff *skb;
910 + assert(slot >= 0 && slot < ring->nr_slots);
913 + skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
914 + if (unlikely(!skb))
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);
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);
937 + rxhdr = (struct bcm43xx_rxhdr *)(skb->data);
938 + rxhdr->frame_length = 0;
944 +/* Allocate the initial descbuffers.
945 + * This is used for an RX ring only.
947 +static int alloc_initial_descbuffers(struct bcm43xx_dmaring *ring)
949 + int i, err = -ENOMEM;
950 + struct bcm43xx_dmadesc *desc;
951 + struct bcm43xx_dmadesc_meta *meta;
953 + for (i = 0; i < ring->nr_slots; i++) {
954 + desc = ring->vbase + i;
955 + meta = ring->meta + i;
957 + err = setup_rx_descbuffer(ring, desc, meta, GFP_KERNEL);
961 + ring->used_slots = ring->nr_slots;
967 + for (i--; i >= 0; i--) {
968 + desc = ring->vbase + i;
969 + meta = ring->meta + i;
971 + unmap_descbuffer(ring, meta->dmaaddr, ring->rx_buffersize, 0);
972 + dev_kfree_skb(meta->skb);
977 +/* Do initial setup of the DMA controller.
978 + * Reset the controller, write the ring busaddress
979 + * and switch the "enable" bit on.
981 +static int dmacontroller_setup(struct bcm43xx_dmaring *ring)
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);
994 + err = alloc_initial_descbuffers(ring);
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);
1012 +/* Shutdown the DMA controller. */
1013 +static void dmacontroller_cleanup(struct bcm43xx_dmaring *ring)
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);
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);
1026 +static void free_all_descbuffers(struct bcm43xx_dmaring *ring)
1028 + struct bcm43xx_dmadesc *desc;
1029 + struct bcm43xx_dmadesc_meta *meta;
1032 + if (!ring->used_slots)
1034 + for (i = 0; i < ring->nr_slots; i++) {
1035 + desc = ring->vbase + i;
1036 + meta = ring->meta + i;
1043 + unmap_descbuffer(ring, meta->dmaaddr,
1044 + meta->skb->len, 1);
1046 + unmap_descbuffer(ring, meta->dmaaddr,
1047 + ring->rx_buffersize, 0);
1049 + free_descriptor_buffer(ring, desc, meta, 0);
1053 +/* Main initialization function. */
1055 +struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
1056 + u16 dma_controller_base,
1057 + int nr_descriptor_slots,
1060 + struct bcm43xx_dmaring *ring;
1063 + ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1067 + ring->meta = kzalloc(sizeof(*ring->meta) * nr_descriptor_slots,
1070 + goto err_kfree_ring;
1072 + ring->memoffset = BCM43xx_DMA_DMABUSADDROFFSET;
1073 +#ifdef CONFIG_BCM947XX
1074 + if (bcm->pci_dev->bus->number == 0)
1075 + ring->memoffset = 0;
1079 + ring->nr_slots = nr_descriptor_slots;
1080 + ring->mmio_base = dma_controller_base;
1083 + ring->current_slot = -1;
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;
1090 + case BCM43xx_MMIO_DMA4_BASE:
1091 + ring->rx_buffersize = BCM43xx_DMA4_RXBUFFERSIZE;
1092 + ring->frameoffset = BCM43xx_DMA4_RX_FRAMEOFFSET;
1099 + err = alloc_ringmemory(ring);
1101 + goto err_kfree_meta;
1102 + err = dmacontroller_setup(ring);
1104 + goto err_free_ringmemory;
1109 +err_free_ringmemory:
1110 + free_ringmemory(ring);
1112 + kfree(ring->meta);
1119 +/* Main cleanup function. */
1120 +static void bcm43xx_destroy_dmaring(struct bcm43xx_dmaring *ring)
1125 + dprintk(KERN_INFO PFX "DMA 0x%04x (%s) max used slots: %d/%d\n",
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.
1132 + dmacontroller_cleanup(ring);
1133 + free_all_descbuffers(ring);
1134 + free_ringmemory(ring);
1136 + kfree(ring->meta);
1140 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1142 + struct bcm43xx_dma *dma;
1144 + if (bcm43xx_using_pio(bcm))
1146 + dma = bcm43xx_current_dma(bcm);
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;
1162 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1164 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1165 + struct bcm43xx_dmaring *ring;
1166 + int err = -ENOMEM;
1168 + /* setup TX DMA channels. */
1169 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1170 + BCM43xx_TXRING_SLOTS, 1);
1173 + dma->tx_ring0 = ring;
1175 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA2_BASE,
1176 + BCM43xx_TXRING_SLOTS, 1);
1178 + goto err_destroy_tx0;
1179 + dma->tx_ring1 = ring;
1181 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA3_BASE,
1182 + BCM43xx_TXRING_SLOTS, 1);
1184 + goto err_destroy_tx1;
1185 + dma->tx_ring2 = ring;
1187 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1188 + BCM43xx_TXRING_SLOTS, 1);
1190 + goto err_destroy_tx2;
1191 + dma->tx_ring3 = ring;
1193 + /* setup RX DMA channels. */
1194 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1195 + BCM43xx_RXRING_SLOTS, 0);
1197 + goto err_destroy_tx3;
1198 + dma->rx_ring0 = ring;
1200 + if (bcm->current_core->rev < 5) {
1201 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1202 + BCM43xx_RXRING_SLOTS, 0);
1204 + goto err_destroy_rx0;
1205 + dma->rx_ring1 = ring;
1208 + dprintk(KERN_INFO PFX "DMA initialized\n");
1214 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1215 + dma->rx_ring0 = NULL;
1217 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1218 + dma->tx_ring3 = NULL;
1220 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1221 + dma->tx_ring2 = NULL;
1223 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1224 + dma->tx_ring1 = NULL;
1226 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1227 + dma->tx_ring0 = NULL;
1231 +/* Generate a cookie for the TX header. */
1232 +static u16 generate_cookie(struct bcm43xx_dmaring *ring,
1235 + u16 cookie = 0x0000;
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
1241 + switch (ring->mmio_base) {
1244 + case BCM43xx_MMIO_DMA1_BASE:
1246 + case BCM43xx_MMIO_DMA2_BASE:
1249 + case BCM43xx_MMIO_DMA3_BASE:
1252 + case BCM43xx_MMIO_DMA4_BASE:
1256 + assert(((u16)slot & 0xF000) == 0x0000);
1257 + cookie |= (u16)slot;
1262 +/* Inspect a cookie and find out to which controller/slot it belongs. */
1264 +struct bcm43xx_dmaring * parse_cookie(struct bcm43xx_private *bcm,
1265 + u16 cookie, int *slot)
1267 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1268 + struct bcm43xx_dmaring *ring = NULL;
1270 + switch (cookie & 0xF000) {
1272 + ring = dma->tx_ring0;
1275 + ring = dma->tx_ring1;
1278 + ring = dma->tx_ring2;
1281 + ring = dma->tx_ring3;
1286 + *slot = (cookie & 0x0FFF);
1287 + assert(*slot >= 0 && *slot < ring->nr_slots);
1292 +static void dmacontroller_poke_tx(struct bcm43xx_dmaring *ring,
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.
1301 + slot = next_slot(ring, slot);
1302 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_INDEX,
1303 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1306 +static int dma_tx_fragment(struct bcm43xx_dmaring *ring,
1307 + struct sk_buff *skb,
1308 + struct ieee80211_tx_control *ctl)
1310 + struct sk_buff *hdr_skb;
1312 + struct bcm43xx_dmadesc *desc;
1313 + struct bcm43xx_dmadesc_meta *meta;
1317 + assert(skb_shinfo(skb)->nr_frags == 0);
1319 + hdr_skb = dev_alloc_skb(sizeof(struct bcm43xx_txhdr));
1320 + if (unlikely(!hdr_skb))
1322 + skb_put(hdr_skb, sizeof(struct bcm43xx_txhdr));
1324 + slot = request_slot(ring);
1325 + desc = ring->vbase + slot;
1326 + meta = ring->meta + slot;
1328 + bcm43xx_generate_txhdr(ring->bcm,
1329 + (struct bcm43xx_txhdr *)hdr_skb->data,
1330 + skb->data, skb->len,
1332 + generate_cookie(ring, slot),
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);
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);
1354 + slot = request_slot(ring);
1355 + desc = ring->vbase + slot;
1356 + meta = ring->meta + slot;
1358 + /* We inspect the txstatus on the FRAMESTART descriptor later
1359 + * on xmit-status IRQ.
1361 + meta->must_xmit_txstat = 1;
1362 + memset(&meta->txstat, 0, sizeof(meta->txstat));
1363 + memcpy(&meta->txstat.control, ctl, sizeof(*ctl));
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);
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;
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);
1391 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1392 + struct sk_buff *skb,
1393 + struct ieee80211_tx_control *ctl)
1395 + struct bcm43xx_dmaring *ring = bcm43xx_current_dma(bcm)->tx_ring1;
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.
1406 + printk(KERN_ERR PFX "DMA queue overflow\n");
1410 + err = dma_tx_fragment(ring, skb, ctl);
1412 + ring->nr_tx_packets++;
1417 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1418 + struct bcm43xx_xmitstatus *status)
1420 + struct bcm43xx_dmaring *ring;
1421 + struct bcm43xx_dmadesc *desc;
1422 + struct bcm43xx_dmadesc_meta *meta;
1423 + int is_last_fragment;
1426 + ring = parse_cookie(bcm, status->cookie, &slot);
1429 + assert(get_desc_ctl(ring->vbase + slot) & BCM43xx_DMADTOR_FRAMESTART);
1431 + assert(slot >= 0 && slot < ring->nr_slots);
1432 + desc = ring->vbase + slot;
1433 + meta = ring->meta + slot;
1435 + is_last_fragment = !!(get_desc_ctl(desc) & BCM43xx_DMADTOR_FRAMEEND);
1436 + unmap_descbuffer(ring, meta->dmaaddr, meta->skb->len, 1);
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().
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));
1450 + free_descriptor_buffer(ring, desc, meta, 1);
1451 + /* Everything belonging to the slot is unmapped
1452 + * and freed, so we can return it.
1454 + return_slot(ring, slot);
1456 + if (is_last_fragment)
1458 + slot = next_slot(ring, slot);
1460 + bcm->stats.last_tx = jiffies;
1463 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1464 + struct ieee80211_tx_queue_stats *stats)
1466 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1467 + struct bcm43xx_dmaring *ring;
1468 + struct ieee80211_tx_queue_stats_data *data;
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;
1477 +static void dma_rx(struct bcm43xx_dmaring *ring,
1480 + struct bcm43xx_dmadesc *desc;
1481 + struct bcm43xx_dmadesc_meta *meta;
1482 + struct bcm43xx_rxhdr *rxhdr;
1483 + struct sk_buff *skb;
1486 + dma_addr_t dmaaddr;
1488 + desc = ring->vbase + *slot;
1489 + meta = ring->meta + *slot;
1491 + sync_descbuffer_for_cpu(ring, meta->dmaaddr, ring->rx_buffersize);
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;
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);
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);
1513 + rxhdr = (struct bcm43xx_rxhdr *)skb->data;
1514 + len = le16_to_cpu(rxhdr->frame_length);
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);
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.
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);
1547 + tmp -= ring->rx_buffersize;
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);
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);
1566 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
1567 + skb_put(skb, len + ring->frameoffset);
1568 + skb_pull(skb, ring->frameoffset);
1570 + bcm43xx_rx(ring->bcm, skb, rxhdr);
1575 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1579 + int slot, current_slot;
1580 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1581 + int used_slots = 0;
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);
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;
1598 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX,
1599 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1600 + ring->current_slot = slot;
1603 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring)
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);
1612 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring)
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);
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
1624 +#ifndef BCM43xx_DMA_H_
1625 +#define BCM43xx_DMA_H_
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>
1633 +#include "bcm43xx.h"
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)
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
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
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)
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
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
1702 +#ifdef CONFIG_BCM43XX_D80211_DMA
1706 +struct bcm43xx_private;
1707 +struct bcm43xx_xmitstatus;
1710 +struct bcm43xx_dmadesc {
1713 +} __attribute__((__packed__));
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)
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;
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. */
1743 + /* Number of used descriptor slots. */
1745 + /* Currently used slot in the ring. */
1747 + /* Total number of packets sent. Statistics only. */
1748 + unsigned int nr_tx_packets;
1749 + /* Frameoffset in octets. */
1751 + /* Descriptor buffer size. */
1752 + u16 rx_buffersize;
1753 + /* The MMIO base register of the DMA controller, this
1754 + * ring is posted to.
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*/
1767 +u32 bcm43xx_dma_read(struct bcm43xx_dmaring *ring,
1770 + return bcm43xx_read32(ring->bcm, ring->mmio_base + offset);
1774 +void bcm43xx_dma_write(struct bcm43xx_dmaring *ring,
1775 + u16 offset, u32 value)
1777 + bcm43xx_write32(ring->bcm, ring->mmio_base + offset, value);
1781 +int bcm43xx_dma_init(struct bcm43xx_private *bcm);
1782 +void bcm43xx_dma_free(struct bcm43xx_private *bcm);
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);
1789 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring);
1790 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring);
1792 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1793 + struct ieee80211_tx_queue_stats *stats);
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);
1801 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring);
1804 +#else /* CONFIG_BCM43XX_D80211_DMA */
1808 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1813 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1817 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1818 + u16 dmacontroller_mmio_base)
1823 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1824 + u16 dmacontroller_mmio_base)
1829 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1830 + struct ieee80211_tx_queue_stats *stats)
1834 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1835 + struct sk_buff *skb,
1836 + struct ieee80211_tx_control *ctl)
1841 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1842 + struct bcm43xx_xmitstatus *status)
1846 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
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
1858 + Broadcom BCM43xx wireless driver
1862 + Copyright (c) 2006 Jason Lunz <lunz@falooley.org>
1864 + Some code in this file is derived from the 8139too.c driver
1865 + Copyright (C) 2002 Jeff Garzik
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.
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.
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.
1884 +#include "bcm43xx.h"
1885 +#include "bcm43xx_ethtool.h"
1887 +#include <linux/netdevice.h>
1888 +#include <linux/pci.h>
1889 +#include <linux/string.h>
1890 +#include <linux/version.h>
1893 +static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1895 + struct bcm43xx_private *bcm = bcm43xx_priv(dev);
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);
1902 +struct ethtool_ops bcm43xx_ethtool_ops = {
1903 + .get_drvinfo = bcm43xx_get_drvinfo,
1904 + .get_link = ethtool_op_get_link,
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
1910 +#ifndef BCM43xx_ETHTOOL_H_
1911 +#define BCM43xx_ETHTOOL_H_
1913 +#include <linux/ethtool.h>
1915 +extern struct ethtool_ops bcm43xx_ethtool_ops;
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
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>
1935 +#include <linux/wireless.h>
1936 +#include <net/d80211.h>
1937 +#include <net/d80211_mgmt.h>
1938 +#include <net/d80211_common.h>
1940 +#include "bcm43xx_debugfs.h"
1941 +#include "bcm43xx_leds.h"
1942 +#include "bcm43xx_sysfs.h"
1945 +#define PFX KBUILD_MODNAME ": "
1947 +#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
1948 +#define BCM43xx_IRQWAIT_MAX_RETRIES 50
1950 +#define BCM43xx_IO_SIZE 8192
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
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
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
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 */
2052 +/* GPIO register offset, in both ChipCommon and PCI core. */
2053 +#define BCM43xx_GPIO_CONTROL 0x6c
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
2062 +/* MacFilter offsets. */
2063 +#define BCM43xx_MACFILTER_SELF 0x0000
2064 +#define BCM43xx_MACFILTER_ASSOC 0x0003
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
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
2078 +/* SBTOPCI2 values. */
2079 +#define BCM43xx_SBTOPCI2_PREFETCH 0x4
2080 +#define BCM43xx_SBTOPCI2_BURST 0x8
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
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
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
2107 +#define BCM43xx_PCTL_FORCE_SLOW 0x0800
2108 +#define BCM43xx_PCTL_FORCE_PLL 0x1000
2109 +#define BCM43xx_PCTL_DYN_XTAL 0x2000
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
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)
2141 +/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
2142 +#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
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
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
2158 +/* sbtmstatehigh state flags */
2159 +#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
2160 +#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
2162 +/* sbimstate flags */
2163 +#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
2164 +#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
2166 +/* PHYVersioning */
2167 +#define BCM43xx_PHYTYPE_A 0x00
2168 +#define BCM43xx_PHYTYPE_B 0x01
2169 +#define BCM43xx_PHYTYPE_G 0x02
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
2187 +/* RadioRegisters */
2188 +#define BCM43xx_RADIOCTL_ID 0x01
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*/
2209 +/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
2210 +#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
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
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)
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)
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
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
2263 +#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
2264 +#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
2266 +/* Max size of a security key */
2267 +#define BCM43xx_SEC_KEYSIZE 16
2268 +/* Security algorithms. */
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,
2282 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2283 +#define assert(expr) \
2285 + if (unlikely(!(expr))) { \
2286 + printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
2287 + #expr, __FILE__, __LINE__, __FUNCTION__); \
2291 +#define assert(expr) do { /* nothing */ } while (0)
2294 +/* rate limited printk(). */
2298 +#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
2299 +/* rate limited printk() for debugging */
2303 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2304 +# define dprintkl printkl
2306 +# define dprintkl(f, x...) do { /* nothing */ } while (0)
2309 +/* debugging printk() */
2313 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2314 +# define dprintk(f, x...) do { printk(f ,##x); } while (0)
2316 +# define dprintk(f, x...) do { /* nothing */ } while (0)
2322 +struct bcm43xx_dmaring;
2323 +struct bcm43xx_pioqueue;
2325 +struct bcm43xx_initval {
2329 +} __attribute__((__packed__));
2331 +/* Values for bcm430x_sprominfo.locale */
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,
2347 +#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
2348 +struct bcm43xx_sprominfo {
2359 + u8 antennas_aphy:2;
2360 + u8 antennas_bgphy:2;
2369 + u8 maxpower_bgphy;
2373 + u8 idle_tssi_tgt_aphy;
2374 + u8 idle_tssi_tgt_bgphy;
2376 + u16 antennagain_aphy;
2377 + u16 antennagain_bgphy;
2380 +/* Value pair to measure the LocalOscillator. */
2381 +struct bcm43xx_lopair {
2386 +#define BCM43xx_LO_COUNT (14*4)
2388 +struct bcm43xx_phyinfo {
2389 + /* Hardware Data */
2393 + u16 antenna_diversity;
2396 + u16 minlowsigpos[2];
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.
2404 + struct bcm43xx_lopair *_lo_pairs;
2406 + /* TSSI to dBm table in use */
2407 + const s8 *tssi2dbm;
2408 + /* idle TSSI value */
2411 + /* Values from bcm43xx_calc_loopback_gain() */
2412 + u16 loopback_gain[2];
2414 + /* PHY lock for core.rev < 3
2415 + * This lock is only used by bcm43xx_phy_{un}lock()
2421 +struct bcm43xx_radioinfo {
2426 + /* Desired TX power level (in dBm).
2427 + * This is set by the user and adjusted in bcm43xx_phy_xmitpower(). */
2429 + /* TX Power control values. */
2433 + u16 baseband_atten;
2444 + /* Current Interference Mitigation mode */
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
2453 +#define BCM43xx_INTERFSTACK_SIZE 26
2454 + u32 interfstack[BCM43xx_INTERFSTACK_SIZE];
2456 + /* Saved values from the NRSSI Slope calculation */
2459 + /* In memory nrssi lookup table. */
2462 + /* current channel */
2464 + u8 initial_channel;
2471 + /* ACI (adjacent channel interference) flags. */
2473 + aci_wlan_automatic:1,
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 */
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;
2495 +#define BCM43xx_MAX_80211_CORES 2
2497 +#ifdef CONFIG_BCM947XX
2498 +#define core_offset(bcm) (bcm)->current_core_offset
2500 +#define core_offset(bcm) 0
2503 +/* Generic information about a core. */
2504 +struct bcm43xx_coreinfo {
2508 + /** core_id ID number */
2510 + /** core_rev revision number */
2512 + /** Index number for _switch_core() */
2516 +/* Additional information for each 80211 core. */
2517 +struct bcm43xx_coreinfo_80211 {
2519 + struct bcm43xx_phyinfo phy;
2520 + /* Radio device. */
2521 + struct bcm43xx_radioinfo radio;
2523 + /* DMA context. */
2524 + struct bcm43xx_dma dma;
2525 + /* PIO context. */
2526 + struct bcm43xx_pio pio;
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;
2539 +struct bcm43xx_stats {
2541 + /* Store the last TX/RX times here for updating the leds. */
2542 + unsigned long last_tx;
2543 + unsigned long last_rx;
2546 +struct bcm43xx_key {
2551 +struct bcm43xx_private {
2552 + struct bcm43xx_sysfs sysfs;
2554 + struct ieee80211_hw *ieee;
2555 + struct ieee80211_low_level_stats ieee_stats;
2558 + struct net_device *net_dev;
2559 + struct pci_dev *pci_dev;
2562 + void __iomem *mmio_addr;
2563 + unsigned int mmio_len;
2565 + /* Do not use the lock directly. Use the bcm43xx_lock* helper
2566 + * functions, to be MMIO-safe. */
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. */
2581 + struct bcm43xx_stats stats;
2583 + /* Bus type we are connected to.
2584 + * This is currently always BCM43xx_BUSTYPE_PCI
2590 + u16 board_revision;
2596 + struct bcm43xx_sprominfo sprom;
2597 +#define BCM43xx_NR_LEDS 4
2598 + struct bcm43xx_led leds[BCM43xx_NR_LEDS];
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;
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.
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.
2619 + int current_80211_core_idx;
2620 + /* Number of available 80211 cores. */
2621 + int nr_80211_available;
2623 + u32 chipcommon_capabilities;
2625 + /* Reason code of the last interrupt. */
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;
2633 + /* Interrupt Service Routine tasklet (bottom-half) */
2634 + struct tasklet_struct isr_tasklet;
2636 + /* Periodic tasks */
2637 + struct timer_list periodic_tasks;
2638 + unsigned int periodic_state;
2640 + struct work_struct restart_work;
2642 + /* Informational stuff. */
2643 + char nick[IW_ESSID_MAX_SIZE + 1];
2644 + u8 bssid[ETH_ALEN];
2646 + /* encryption/decryption */
2647 + u16 security_offset;
2648 + struct bcm43xx_key key[54];
2649 + u8 default_key_idx;
2652 + const struct firmware *ucode;
2653 + const struct firmware *pcm;
2654 + const struct firmware *initvals0;
2655 + const struct firmware *initvals1;
2657 + /* Cached beacon template while uploading the template. */
2658 + struct sk_buff *cached_beacon;
2660 + /* Debugging stuff follows. */
2661 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2662 + struct bcm43xx_dfsentry *dfsentry;
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.
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.
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)
2683 +struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
2685 + return ieee80211_dev_hw_data(dev);
2688 +/* Helper function, which returns a boolean.
2689 + * TRUE, if PIO is used; FALSE, if DMA is used.
2691 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
2693 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2695 + return bcm->__using_pio;
2697 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
2699 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2703 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
2705 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2710 +# error "Using neither DMA nor PIO? Confused..."
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.
2718 +struct bcm43xx_pio * bcm43xx_current_pio(struct bcm43xx_private *bcm)
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);
2726 +struct bcm43xx_dma * bcm43xx_current_dma(struct bcm43xx_private *bcm)
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);
2734 +struct bcm43xx_phyinfo * bcm43xx_current_phy(struct bcm43xx_private *bcm)
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);
2741 +struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
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);
2748 +/* Are we running in init_board() context? */
2750 +int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
2752 + if (bcm->initialized)
2754 + if (bcm->shutting_down)
2760 +struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
2761 + u16 radio_attenuation,
2762 + u16 baseband_attenuation)
2764 + return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
2769 +u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
2771 + return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
2775 +void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
2777 + iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
2781 +u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
2783 + return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
2787 +void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
2789 + iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
2793 +int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
2795 + return pci_read_config_word(bcm->pci_dev, offset, value);
2799 +int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
2801 + return pci_read_config_dword(bcm->pci_dev, offset, value);
2805 +int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
2807 + return pci_write_config_word(bcm->pci_dev, offset, value);
2811 +int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
2813 + return pci_write_config_dword(bcm->pci_dev, offset, value);
2816 +/** Limit a value between two limits */
2818 +# undef limit_value
2820 +#define limit_value(value, min, max) \
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; \
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]
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
2845 + Broadcom BCM43xx wireless driver
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>
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.
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.
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.
2870 +#include "bcm43xx.h"
2871 +#include "bcm43xx_ilt.h"
2872 +#include "bcm43xx_phy.h"
2875 +/**** Initial Internal Lookup Tables ****/
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,
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,
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,
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,
3071 +const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE] = {
3072 + 0x0001, 0x0001, 0x0001, 0xFFFE,
3073 + 0xFFFE, 0x3FFF, 0x1000, 0x0393,
3076 +const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE] = {
3077 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3078 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3081 +const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE] = {
3082 + 0x013C, 0x01F5, 0x031A, 0x0631,
3083 + 0x0001, 0x0001, 0x0001, 0x0001,
3086 +const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE] = {
3087 + 0x5484, 0x3C40, 0x0000, 0x0000,
3088 + 0x0000, 0x0000, 0x0000, 0x0000,
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,
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,
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,
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 */
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 */
3155 +/**** Helper functions to access the device Internal Lookup Tables ****/
3157 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
3159 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3160 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3162 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val);
3164 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3166 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val);
3170 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
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);
3176 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3177 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_G_DATA1);
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
3184 +#ifndef BCM43xx_ILT_H_
3185 +#define BCM43xx_ILT_H_
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];
3212 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
3213 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
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
3222 + Broadcom BCM43xx wireless driver
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>
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.
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.
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.
3247 +#include "bcm43xx_leds.h"
3248 +#include "bcm43xx.h"
3250 +#include <asm/bitops.h>
3253 +static void bcm43xx_led_changestate(struct bcm43xx_led *led)
3255 + struct bcm43xx_private *bcm = led->bcm;
3256 + const int index = bcm43xx_led_index(led);
3257 + const u16 mask = (1 << index);
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);
3267 +static void bcm43xx_led_blink(unsigned long d)
3269 + struct bcm43xx_led *led = (struct bcm43xx_led *)d;
3270 + struct bcm43xx_private *bcm = led->bcm;
3271 + unsigned long flags;
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);
3278 + bcm43xx_unlock_mmio(bcm, flags);
3281 +static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
3282 + unsigned long interval)
3284 + if (led->blink_interval)
3286 + led->blink_interval = interval;
3287 + bcm43xx_led_changestate(led);
3288 + led->blink_timer.expires = jiffies + interval;
3289 + add_timer(&led->blink_timer);
3292 +static void bcm43xx_led_blink_stop(struct bcm43xx_led *led, int sync)
3294 + struct bcm43xx_private *bcm = led->bcm;
3295 + const int index = bcm43xx_led_index(led);
3298 + if (!led->blink_interval)
3300 + if (unlikely(sync))
3301 + del_timer_sync(&led->blink_timer);
3303 + del_timer(&led->blink_timer);
3304 + led->blink_interval = 0;
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);
3312 + ledctl &= ~(1 << index);
3313 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3316 +static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
3317 + struct bcm43xx_led *led,
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.
3327 + switch (led_index) {
3329 + led->behaviour = BCM43xx_LED_ACTIVITY;
3330 + if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
3331 + led->behaviour = BCM43xx_LED_RADIO_ALL;
3334 + led->behaviour = BCM43xx_LED_RADIO_B;
3335 + if (bcm->board_vendor == PCI_VENDOR_ID_ASUSTEK)
3336 + led->behaviour = BCM43xx_LED_ASSOC;
3339 + led->behaviour = BCM43xx_LED_RADIO_A;
3342 + led->behaviour = BCM43xx_LED_OFF;
3349 +int bcm43xx_leds_init(struct bcm43xx_private *bcm)
3351 + struct bcm43xx_led *led;
3355 + sprom[0] = bcm->sprom.wl0gpio0;
3356 + sprom[1] = bcm->sprom.wl0gpio1;
3357 + sprom[2] = bcm->sprom.wl0gpio2;
3358 + sprom[3] = bcm->sprom.wl0gpio3;
3360 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3361 + led = &(bcm->leds[i]);
3363 + setup_timer(&led->blink_timer,
3364 + bcm43xx_led_blink,
3365 + (unsigned long)led);
3367 + if (sprom[i] == 0xFF) {
3368 + bcm43xx_led_init_hardcoded(bcm, led, i);
3370 + led->behaviour = sprom[i] & BCM43xx_LED_BEHAVIOUR;
3371 + led->activelow = !!(sprom[i] & BCM43xx_LED_ACTIVELOW);
3378 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm)
3380 + struct bcm43xx_led *led;
3383 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3384 + led = &(bcm->leds[i]);
3385 + bcm43xx_led_blink_stop(led, 1);
3387 + bcm43xx_leds_switch_all(bcm, 0);
3390 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
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;
3397 + unsigned long interval = 0;
3400 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3401 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3402 + led = &(bcm->leds[i]);
3405 + switch (led->behaviour) {
3406 + case BCM43xx_LED_INACTIVE:
3408 + case BCM43xx_LED_OFF:
3410 + case BCM43xx_LED_ON:
3413 + case BCM43xx_LED_ACTIVITY:
3414 + turn_on = activity;
3416 + case BCM43xx_LED_RADIO_ALL:
3417 + turn_on = radio->enabled;
3419 + case BCM43xx_LED_RADIO_A:
3420 + turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
3422 + case BCM43xx_LED_RADIO_B:
3423 + turn_on = (radio->enabled &&
3424 + (phy->type == BCM43xx_PHYTYPE_B ||
3425 + phy->type == BCM43xx_PHYTYPE_G));
3427 + case BCM43xx_LED_MODE_BG:
3428 + if (phy->type == BCM43xx_PHYTYPE_G &&
3429 + 1/*FIXME: using G rates.*/)
3432 + case BCM43xx_LED_TRANSFER:
3434 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3436 + bcm43xx_led_blink_stop(led, 0);
3438 + case BCM43xx_LED_APTRANSFER:
3439 + if (bcm->iw_mode == IW_MODE_MASTER) {
3440 + if (transferring) {
3441 + interval = BCM43xx_LEDBLINK_FAST;
3446 + if (0/*TODO: not assoc*/)
3447 + interval = BCM43xx_LEDBLINK_SLOW;
3448 + else if (transferring)
3449 + interval = BCM43xx_LEDBLINK_FAST;
3454 + bcm43xx_led_blink_start(led, interval);
3456 + bcm43xx_led_blink_stop(led, 0);
3458 + case BCM43xx_LED_WEIRD:
3461 + case BCM43xx_LED_ASSOC:
3462 + if (1/*bcm->softmac->associated*/)
3465 +#ifdef CONFIG_BCM43XX_DEBUG
3466 + case BCM43xx_LED_TEST_BLINKSLOW:
3467 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_SLOW);
3469 + case BCM43xx_LED_TEST_BLINKMEDIUM:
3470 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3472 + case BCM43xx_LED_TEST_BLINKFAST:
3473 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_FAST);
3475 +#endif /* CONFIG_BCM43XX_DEBUG */
3480 + if (led->activelow)
3481 + turn_on = !turn_on;
3483 + ledctl |= (1 << i);
3485 + ledctl &= ~(1 << i);
3487 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3490 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
3492 + struct bcm43xx_led *led;
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)
3503 + bit_on = led->activelow ? 0 : 1;
3505 + bit_on = led->activelow ? 1 : 0;
3507 + ledctl |= (1 << i);
3509 + ledctl &= ~(1 << i);
3511 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
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
3517 +#ifndef BCM43xx_LEDS_H_
3518 +#define BCM43xx_LEDS_H_
3520 +#include <linux/types.h>
3521 +#include <linux/timer.h>
3524 +struct bcm43xx_led {
3528 + struct bcm43xx_private *bcm;
3529 + struct timer_list blink_timer;
3530 + unsigned long blink_interval;
3532 +#define bcm43xx_led_index(led) ((int)((led) - (led)->bcm->leds))
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)
3539 +#define BCM43xx_LED_XFER_THRES (HZ / 100)
3541 +#define BCM43xx_LED_BEHAVIOUR 0x7F
3542 +#define BCM43xx_LED_ACTIVELOW 0x80
3543 +enum { /* LED behaviour values */
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,
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.
3562 + BCM43xx_LED_TEST_BLINKSLOW,
3563 + BCM43xx_LED_TEST_BLINKMEDIUM,
3564 + BCM43xx_LED_TEST_BLINKFAST,
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);
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
3579 + Broadcom BCM43xx wireless driver
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>
3587 + Some parts of the code in this file are derived from the ipw2200
3588 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
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>
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"
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");
3639 +#ifdef CONFIG_BCM947XX
3640 +extern char *nvram_get(char *name);
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
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");
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)");
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)");
3665 +static int modparam_noleds;
3666 +module_param_named(noleds, modparam_noleds, int, 0444);
3667 +MODULE_PARM_DESC(noleds, "Turn off all LED activity");
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.");
3674 +# define modparam_fwpostfix ""
3675 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
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.
3682 +//#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
3684 +/* If you want to enable printing of each MMIO access, enable this. */
3685 +//#define DEBUG_ENABLE_MMIO_PRINT
3687 +/* If you want to enable printing of MMIO access within
3688 + * ucode/pcm upload, initvals write, enable this.
3690 +//#define DEBUG_ENABLE_UCODE_MMIO_PRINT
3692 +/* If you want to enable printing of PCI Config Space access, enable this */
3693 +//#define DEBUG_ENABLE_PCILOG
3696 +/* Detailed list maintained at:
3697 + * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
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 },
3720 +MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
3723 +static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
3727 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3728 + if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
3729 + val = swab32(val);
3731 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
3733 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
3737 +void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
3738 + u16 routing, u16 offset)
3742 + /* "offset" is the WORD offset. */
3744 + control = routing;
3746 + control |= offset;
3747 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
3750 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
3751 + u16 routing, u16 offset)
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);
3761 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3762 + ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3768 + bcm43xx_shm_control_word(bcm, routing, offset);
3769 + ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
3774 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
3775 + u16 routing, u16 offset)
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);
3789 + bcm43xx_shm_control_word(bcm, routing, offset);
3790 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3795 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
3796 + u16 routing, u16 offset,
3799 + if (routing == BCM43xx_SHM_SHARED) {
3800 + if (offset & 0x0003) {
3801 + /* Unaligned access */
3802 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3804 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3805 + (value >> 16) & 0xffff);
3807 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3809 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
3815 + bcm43xx_shm_control_word(bcm, routing, offset);
3817 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
3820 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
3821 + u16 routing, u16 offset,
3824 + if (routing == BCM43xx_SHM_SHARED) {
3825 + if (offset & 0x0003) {
3826 + /* Unaligned access */
3827 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3829 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3835 + bcm43xx_shm_control_word(bcm, routing, offset);
3837 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
3840 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
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).
3848 + if (bcm->current_core->rev >= 3) {
3849 + u32 low, high, high2;
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));
3862 + u16 v0, v1, v2, v3;
3863 + u16 test1, test2, test3;
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);
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);
3888 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
3892 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3893 + status |= BCM43xx_SBF_TIME_UPDATE;
3894 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
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.
3901 + if (bcm->current_core->rev >= 3) {
3902 + u32 lo = (tsf & 0x00000000FFFFFFFFULL);
3903 + u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
3905 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
3907 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
3909 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
3911 + u16 v0 = (tsf & 0x000000000000FFFFULL);
3912 + u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
3913 + u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
3914 + u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
3916 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
3918 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
3920 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
3922 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
3924 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
3927 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3928 + status &= ~BCM43xx_SBF_TIME_UPDATE;
3929 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
3933 +void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
3940 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
3943 + data |= mac[1] << 8;
3944 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3946 + data |= mac[3] << 8;
3947 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3949 + data |= mac[5] << 8;
3950 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
3953 +static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
3956 + const u8 zero_addr[ETH_ALEN] = { 0 };
3958 + bcm43xx_macfilter_set(bcm, offset, zero_addr);
3961 +static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
3963 + const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
3964 + const u8 *bssid = bcm->bssid;
3965 + u8 mac_bssid[ETH_ALEN * 2];
3968 + memcpy(mac_bssid, mac, ETH_ALEN);
3969 + memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
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)));
3980 +static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
3982 + /* slot_time is in usec. */
3983 + if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
3985 + bcm43xx_write16(bcm, 0x684, 510 + slot_time);
3986 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
3989 +static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
3991 + bcm43xx_set_slot_time(bcm, 9);
3992 + bcm->short_slot = 1;
3995 +static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
3997 + bcm43xx_set_slot_time(bcm, 20);
3998 + bcm->short_slot = 0;
4001 +/* FIXME: To get the MAC-filter working, we need to implement the
4002 + * following functions (and rename them :)
4005 +static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
4007 + bcm43xx_mac_suspend(bcm);
4008 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
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);
4017 + if (bcm->current_core->rev < 3) {
4018 + bcm43xx_write16(bcm, 0x0610, 0x8000);
4019 + bcm43xx_write16(bcm, 0x060E, 0x0000);
4021 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
4023 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
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);
4031 + bcm43xx_mac_enable(bcm);
4034 +static void bcm43xx_associate(struct bcm43xx_private *bcm,
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);
4044 +/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
4045 + * Returns the _previously_ enabled IRQ mask.
4047 +static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
4051 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4052 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
4057 +/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
4058 + * Returns the _previously_ enabled IRQ mask.
4060 +static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
4064 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4065 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
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)
4074 + unsigned long flags;
4076 + bcm43xx_lock_mmio(bcm, flags);
4077 + if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
4078 + bcm43xx_unlock_mmio(bcm, flags);
4081 + old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4082 + tasklet_disable(&bcm->isr_tasklet);
4083 + bcm43xx_unlock_mmio(bcm, flags);
4090 +static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
4092 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4093 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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;
4106 + radio_id = 0x5205017F;
4108 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4109 + radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
4111 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4112 + radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
4115 + manufact = (radio_id & 0x00000FFF);
4116 + version = (radio_id & 0x0FFFF000) >> 12;
4117 + revision = (radio_id & 0xF0000000) >> 28;
4119 + dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
4120 + radio_id, manufact, version, revision);
4122 + switch (phy->type) {
4123 + case BCM43xx_PHYTYPE_A:
4124 + if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
4125 + goto err_unsupported_radio;
4127 + case BCM43xx_PHYTYPE_B:
4128 + if ((version & 0xFFF0) != 0x2050)
4129 + goto err_unsupported_radio;
4131 + case BCM43xx_PHYTYPE_G:
4132 + if (version != 0x2050)
4133 + goto err_unsupported_radio;
4137 + radio->manufact = manufact;
4138 + radio->version = version;
4139 + radio->revision = revision;
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;
4148 + /* Initialize the in-memory nrssi Lookup Table. */
4149 + for (i = 0; i < 64; i++)
4150 + radio->nrssi_lt[i] = i;
4154 +err_unsupported_radio:
4155 + printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
4159 +static inline u8 bcm43xx_crc8(u8 crc, u8 data)
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,
4195 + return t[crc ^ data];
4198 +static u8 bcm43xx_sprom_crc(const u16 *sprom)
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);
4207 + crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
4213 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
4216 + u8 crc, expected_crc;
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);
4233 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
4236 + u8 crc, expected_crc;
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");
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);
4251 + spromctl |= 0x10; /* SPROM WRITE enable. */
4252 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
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...
4258 + printk(KERN_INFO PFX "[ 0%%");
4260 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
4269 + bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
4273 + spromctl &= ~0x10; /* SPROM WRITE enable. */
4274 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4278 + printk("100%% ]\n");
4279 + printk(KERN_INFO PFX "SPROM written.\n");
4280 + bcm43xx_controller_restart(bcm, "SPROM update");
4284 + printk(KERN_ERR PFX "Could not access SPROM control register.\n");
4288 +static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
4292 +#ifdef CONFIG_BCM947XX
4296 + sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
4299 + printk(KERN_ERR PFX "sprom_extract OOM\n");
4302 +#ifdef CONFIG_BCM947XX
4303 + sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
4304 + sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
4306 + if ((c = nvram_get("il0macaddr")) != NULL)
4307 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
4309 + if ((c = nvram_get("et1macaddr")) != NULL)
4310 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
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"));
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"));
4320 + sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
4322 + bcm43xx_sprom_read(bcm, sprom);
4326 + value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
4327 + bcm->sprom.boardflags2 = value;
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);
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);
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);
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;
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;
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;
4376 + value = sprom[BCM43xx_SPROM_WL0GPIO0];
4377 + if (value == 0x0000)
4379 + bcm->sprom.wl0gpio0 = value & 0x00FF;
4380 + bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
4381 + value = sprom[BCM43xx_SPROM_WL0GPIO2];
4382 + if (value == 0x0000)
4384 + bcm->sprom.wl0gpio2 = value & 0x00FF;
4385 + bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
4388 + value = sprom[BCM43xx_SPROM_MAXPWR];
4389 + bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
4390 + bcm->sprom.maxpower_bgphy = value & 0x00FF;
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;
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;
4406 + value = sprom[BCM43xx_SPROM_BOARDFLAGS];
4407 + if (value == 0xFFFF)
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;
4420 + /* antenna gain */
4421 + value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
4422 + if (value == 0x0000 || value == 0xFFFF)
4424 + /* convert values to Q5.2 */
4425 + bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
4426 + bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
4433 +/* DummyTransmission function, as documented on
4434 + * http://bcm-specs.sipsolutions.net/DummyTransmission
4436 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
4438 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4439 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4440 + unsigned int i, max_loop;
4450 + switch (phy->type) {
4451 + case BCM43xx_PHYTYPE_A:
4453 + buffer[0] = 0xCC010200;
4455 + case BCM43xx_PHYTYPE_B:
4456 + case BCM43xx_PHYTYPE_G:
4458 + buffer[0] = 0x6E840B00;
4465 + for (i = 0; i < 5; i++)
4466 + bcm43xx_ram_write(bcm, i * 4, buffer[i]);
4468 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
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);
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)
4489 + for (i = 0x00; i < 0x0A; i++) {
4490 + value = bcm43xx_read16(bcm, 0x050E);
4491 + if (value & 0x0400)
4495 + for (i = 0x00; i < 0x0A; i++) {
4496 + value = bcm43xx_read16(bcm, 0x0690);
4497 + if (!(value & 0x0100))
4501 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4502 + bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
4505 +static void key_write(struct bcm43xx_private *bcm,
4506 + u8 index, u8 algorithm, const u16 *key)
4508 + unsigned int i, basic_wep = 0;
4512 + /* Write associated key information */
4513 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
4514 + ((index << 4) | (algorithm & 0x0F)));
4516 + /* The first 4 WEP keys need extra love */
4517 + if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
4518 + (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
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);
4531 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4532 + offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
4537 +static void keymac_write(struct bcm43xx_private *bcm,
4538 + u8 index, const u32 *addr)
4540 + /* for keys 0-3 there is no associated mac address */
4545 + if (bcm->current_core->rev >= 5) {
4546 + bcm43xx_shm_write32(bcm,
4547 + BCM43xx_SHM_HWMAC,
4549 + cpu_to_be32(*addr));
4550 + bcm43xx_shm_write16(bcm,
4551 + BCM43xx_SHM_HWMAC,
4553 + cpu_to_be16(*((u16 *)(addr + 1))));
4556 + TODO(); /* Put them in the macaddress filter */
4559 + /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
4560 + Keep in mind to update the count of keymacs in 0x003E as well! */
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)
4570 + u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
4572 + if (index >= ARRAY_SIZE(bcm->key))
4574 + if (key_len > ARRAY_SIZE(key))
4576 + if (algorithm < 1 || algorithm > 5)
4579 + memcpy(key, _key, key_len);
4580 + key_write(bcm, index, algorithm, (const u16 *)key);
4581 + keymac_write(bcm, index, (const u32 *)mac_addr);
4583 + bcm->key[index].algorithm = algorithm;
4588 +static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
4590 + static const u32 zero_mac[2] = { 0 };
4591 + unsigned int i,j, nr_keys = 54;
4594 + if (bcm->current_core->rev < 5)
4596 + assert(nr_keys <= ARRAY_SIZE(bcm->key));
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,
4610 + dprintk(KERN_INFO PFX "Keys cleared\n");
4613 +/* Lowlevel core-switch function. This is only to be used in
4614 + * bcm43xx_switch_core() and bcm43xx_probe_cores()
4616 +static int _switch_core(struct bcm43xx_private *bcm, int core)
4622 + assert(core >= 0);
4624 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4625 + (core * 0x1000) + 0x18000000);
4626 + if (unlikely(err))
4628 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4630 + if (unlikely(err))
4632 + current_core = (current_core - 0x18000000) / 0x1000;
4633 + if (current_core == core)
4636 + if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
4640 +#ifdef CONFIG_BCM947XX
4641 + if (bcm->pci_dev->bus->number == 0)
4642 + bcm->current_core_offset = 0x1000 * core;
4644 + bcm->current_core_offset = 0;
4649 + printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
4653 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
4657 + if (unlikely(!new_core))
4659 + if (!new_core->available)
4661 + if (bcm->current_core == new_core)
4663 + err = _switch_core(bcm, new_core->index);
4664 + if (unlikely(err))
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]));
4676 +static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
4680 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4681 + value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
4682 + | BCM43xx_SBTMSTATELOW_REJECT;
4684 + return (value == BCM43xx_SBTMSTATELOW_CLOCK);
4687 +/* disable current core */
4688 +static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
4691 + u32 sbtmstatehigh;
4694 + /* fetch sbtmstatelow from core information registers */
4695 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4697 + /* core is already in reset */
4698 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
4701 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
4702 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4703 + BCM43xx_SBTMSTATELOW_REJECT;
4704 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4706 + for (i = 0; i < 1000; i++) {
4707 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4708 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
4715 + printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
4719 + for (i = 0; i < 1000; i++) {
4720 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4721 + if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
4728 + printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
4732 + sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4733 + BCM43xx_SBTMSTATELOW_REJECT |
4734 + BCM43xx_SBTMSTATELOW_RESET |
4735 + BCM43xx_SBTMSTATELOW_CLOCK |
4737 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4741 + sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
4742 + BCM43xx_SBTMSTATELOW_REJECT |
4744 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4747 + bcm->current_core->enabled = 0;
4752 +/* enable (reset) current core */
4753 +static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
4756 + u32 sbtmstatehigh;
4760 + err = bcm43xx_core_disable(bcm, core_flags);
4764 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4765 + BCM43xx_SBTMSTATELOW_RESET |
4766 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4768 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
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);
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);
4783 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4784 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4786 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4789 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
4790 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4793 + bcm->current_core->enabled = 1;
4799 +/* http://bcm-specs.sipsolutions.net/80211CoreReset */
4800 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
4802 + u32 flags = 0x00040000;
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);
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));
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);
4834 +static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
4836 + bcm43xx_radio_turn_off(bcm);
4837 + bcm43xx_write16(bcm, 0x03E6, 0x00F4);
4838 + bcm43xx_core_disable(bcm, 0);
4841 +/* Mark the current 80211 core inactive.
4842 + * "active_80211_core" is the other 80211 core, which is used.
4844 +static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
4845 + struct bcm43xx_coreinfo *active_80211_core)
4848 + struct bcm43xx_coreinfo *old_core;
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);
4858 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4859 + sbtmstatelow &= ~0xa0000;
4860 + sbtmstatelow |= 0x80000;
4861 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
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);
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);
4880 +static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
4884 + struct bcm43xx_xmitstatus stat;
4887 + v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
4890 + v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
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);
4900 + bcm43xx_debugfs_log_txstat(bcm, &stat);
4902 + if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
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
4908 + if (bcm43xx_using_pio(bcm))
4909 + bcm43xx_pio_handle_xmitstatus(bcm, &stat);
4911 + bcm43xx_dma_handle_xmitstatus(bcm, &stat);
4915 +static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
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);
4925 +static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
4927 + /* Top half of Link Quality calculation. */
4929 + if (bcm->noisecalc.calculation_running)
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;
4936 + bcm43xx_generate_noise_sample(bcm);
4939 +static void handle_irq_noise(struct bcm43xx_private *bcm)
4941 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4947 + /* Bottom half of Link Quality calculation. */
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;
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. */
4978 + for (i = 0; i < 8; i++) {
4979 + for (j = 0; j < 4; j++)
4980 + average += bcm->noisecalc.samples[i][j];
4982 + average /= (8 * 4);
4986 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
4987 + tmp = (tmp / 128) & 0x1F;
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;
5004 + bcm->stats.link_quality = 3;
5005 +// dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
5007 + bcm->noisecalc.calculation_running = 0;
5011 + bcm43xx_generate_noise_sample(bcm);
5014 +static void handle_irq_ps(struct bcm43xx_private *bcm)
5016 + if (bcm->iw_mode == IW_MODE_MASTER) {
5019 + if (1/*FIXME: the last PSpoll frame was sent successfully */)
5020 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5022 + if (bcm->iw_mode == IW_MODE_ADHOC)
5023 + bcm->reg124_set_0x4 = 1;
5024 + //FIXME else set to false?
5027 +static void handle_irq_reg124(struct bcm43xx_private *bcm)
5029 + if (!bcm->reg124_set_0x4)
5031 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
5032 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
5034 + //FIXME: reset reg124_set_0x4 to false?
5037 +static void handle_irq_pmq(struct bcm43xx_private *bcm)
5044 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
5045 + if (!(tmp & 0x00000008))
5048 + /* 16bit write is odd, but correct. */
5049 + bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
5052 +static void bcm43xx_write_beacon_template(struct bcm43xx_private *bcm,
5054 + u16 shm_size_offset)
5060 + data = (const u8 *)(bcm->cached_beacon->data);
5061 + size = min(bcm->cached_beacon->len, (unsigned int)17);
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);
5070 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
5073 +static void handle_irq_beacon(struct bcm43xx_private *bcm)
5077 + bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
5078 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
5080 + if (!bcm->cached_beacon) {
5081 + struct ieee80211_tx_control control;
5083 + /* No cached template available, yet.
5084 + * Request the 80211 subsystem to generate a new beacon
5085 + * frame and use it as template.
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");
5094 + if ((status & 0x1) && (status & 0x2)) {
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;
5105 + if (!(status & 0x1)) {
5106 + bcm43xx_write_beacon_template(bcm, 0x68, 0x18);
5108 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5110 + if (!(status & 0x2)) {
5111 + bcm43xx_write_beacon_template(bcm, 0x468, 0x1A);
5113 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5117 +/* Interrupt handler bottom-half */
5118 +static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
5121 + u32 dma_reason[4];
5123 + unsigned long flags;
5125 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5126 + u32 _handled = 0x00000000;
5127 +# define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
5129 +# define bcmirq_handled(irq) do { /* nothing */ } while (0)
5130 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
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];
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.
5145 + printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
5146 + bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
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);
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]);
5170 + if (reason & BCM43xx_IRQ_PS) {
5171 + handle_irq_ps(bcm);
5172 + bcmirq_handled(BCM43xx_IRQ_PS);
5175 + if (reason & BCM43xx_IRQ_REG124) {
5176 + handle_irq_reg124(bcm);
5177 + bcmirq_handled(BCM43xx_IRQ_REG124);
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);
5186 + if (reason & BCM43xx_IRQ_PMQ) {
5187 + handle_irq_pmq(bcm);
5188 + bcmirq_handled(BCM43xx_IRQ_PMQ);
5191 + if (reason & BCM43xx_IRQ_SCAN) {
5193 + //bcmirq_handled(BCM43xx_IRQ_SCAN);
5196 + if (reason & BCM43xx_IRQ_NOISE) {
5197 + handle_irq_noise(bcm);
5198 + bcmirq_handled(BCM43xx_IRQ_NOISE);
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);
5208 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
5209 + /* We intentionally don't set "activity" to 1, here. */
5211 + if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
5212 + if (bcm43xx_using_pio(bcm))
5213 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
5215 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
5218 + bcmirq_handled(BCM43xx_IRQ_RX);
5220 + if (reason & BCM43xx_IRQ_XMIT_STATUS) {
5221 + handle_irq_transmit_status(bcm);
5223 + //TODO: In AP mode, this also causes sending of powersave responses.
5224 + bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
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]);
5239 +#undef bcmirq_handled
5241 + if (!modparam_noleds)
5242 + bcm43xx_leds_update(bcm, activity);
5243 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
5244 + bcm43xx_unlock_mmio(bcm, flags);
5247 +static void pio_irq_workaround(struct bcm43xx_private *bcm,
5248 + u16 base, int queueidx)
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;
5256 + bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
5259 +static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
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);
5271 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
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]);
5283 +/* Interrupt handler top-half */
5284 +static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
5286 + irqreturn_t ret = IRQ_HANDLED;
5287 + struct bcm43xx_private *bcm = dev_id;
5293 + spin_lock(&bcm->_lock);
5295 + reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5296 + if (reason == 0xffffffff) {
5297 + /* irq not for us (shared irq) */
5301 + reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
5305 + bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
5307 + bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
5309 + bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
5311 + bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
5314 + bcm43xx_interrupt_ack(bcm, reason);
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... .
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);
5332 + spin_unlock(&bcm->_lock);
5337 +static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
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);
5345 + release_firmware(bcm->initvals0);
5346 + bcm->initvals0 = NULL;
5347 + release_firmware(bcm->initvals1);
5348 + bcm->initvals1 = NULL;
5351 +static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
5353 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5354 + u8 rev = bcm->current_core->rev;
5357 + char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
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);
5365 + printk(KERN_ERR PFX
5366 + "Error: Microcode \"%s\" not available or load failed.\n",
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);
5379 + printk(KERN_ERR PFX
5380 + "Error: PCM \"%s\" not available or load failed.\n",
5386 + if (!bcm->initvals0) {
5387 + if (rev == 2 || rev == 4) {
5388 + switch (phy->type) {
5389 + case BCM43xx_PHYTYPE_A:
5392 + case BCM43xx_PHYTYPE_B:
5393 + case BCM43xx_PHYTYPE_G:
5397 + goto err_noinitval;
5400 + } else if (rev >= 5) {
5401 + switch (phy->type) {
5402 + case BCM43xx_PHYTYPE_A:
5405 + case BCM43xx_PHYTYPE_B:
5406 + case BCM43xx_PHYTYPE_G:
5410 + goto err_noinitval;
5413 + goto err_noinitval;
5414 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5415 + nr, modparam_fwpostfix);
5417 + err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
5419 + printk(KERN_ERR PFX
5420 + "Error: InitVals \"%s\" not available or load failed.\n",
5424 + if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
5425 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5430 + if (!bcm->initvals1) {
5432 + u32 sbtmstatehigh;
5434 + switch (phy->type) {
5435 + case BCM43xx_PHYTYPE_A:
5436 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
5437 + if (sbtmstatehigh & 0x00010000)
5442 + case BCM43xx_PHYTYPE_B:
5443 + case BCM43xx_PHYTYPE_G:
5447 + goto err_noinitval;
5449 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5450 + nr, modparam_fwpostfix);
5452 + err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
5454 + printk(KERN_ERR PFX
5455 + "Error: InitVals \"%s\" not available or load failed.\n",
5459 + if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
5460 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5469 + bcm43xx_release_firmware(bcm, 1);
5472 + printk(KERN_ERR PFX "Error: No InitVals available!\n");
5477 +static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
5480 + unsigned int i, len;
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]));
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]));
5505 +static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
5506 + const struct bcm43xx_initval *data,
5507 + const unsigned int len)
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);
5518 + if (unlikely(offset >= 0x1000))
5521 + if (unlikely(value & 0xFFFF0000))
5523 + bcm43xx_write16(bcm, offset, (u16)value);
5524 + } else if (size == 4) {
5525 + bcm43xx_write32(bcm, offset, value);
5533 + printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
5534 + "Please fix your bcm43xx firmware files.\n");
5538 +static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
5542 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
5543 + bcm->initvals0->size / sizeof(struct bcm43xx_initval));
5546 + if (bcm->initvals1) {
5547 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
5548 + bcm->initvals1->size / sizeof(struct bcm43xx_initval));
5556 +static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
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);
5569 + bcm->irq = d->irq;
5573 + res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
5574 + SA_SHIRQ, KBUILD_MODNAME, bcm);
5576 + printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
5579 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
5580 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
5583 + data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5584 + if (data == BCM43xx_IRQ_READY)
5587 + if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
5588 + printk(KERN_ERR PFX "Card IRQ register not responding. "
5590 + free_irq(bcm->irq, bcm);
5596 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5601 +/* Switch to the core used to write the GPIO register.
5602 + * This is either the ChipCommon, or the PCI core.
5604 +static int switch_to_gpio_core(struct bcm43xx_private *bcm)
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.
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");
5625 +/* Initialize the GPIOs
5626 + * http://bcm-specs.sipsolutions.net/GPIO
5628 +static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
5630 + struct bcm43xx_coreinfo *old_core;
5634 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5635 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5638 + bcm43xx_leds_switch_all(bcm, 0);
5639 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5640 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
5642 + mask = 0x0000001F;
5644 + if (bcm->chip_id == 0x4301) {
5648 + if (0 /* FIXME: conditional unknown */) {
5649 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5650 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5655 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
5656 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5657 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5662 + if (bcm->current_core->rev >= 2)
5663 + mask |= 0x0010; /* FIXME: This is redundant. */
5665 + old_core = bcm->current_core;
5666 + err = switch_to_gpio_core(bcm);
5669 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
5670 + (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
5671 + err = bcm43xx_switch_core(bcm, old_core);
5676 +/* Turn off all GPIO stuff. Call this on module unload, for example. */
5677 +static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
5679 + struct bcm43xx_coreinfo *old_core;
5682 + old_core = bcm->current_core;
5683 + err = switch_to_gpio_core(bcm);
5686 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
5687 + err = bcm43xx_switch_core(bcm, old_core);
5693 +/* http://bcm-specs.sipsolutions.net/EnableMac */
5694 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
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);
5705 +/* http://bcm-specs.sipsolutions.net/SuspendMAC */
5706 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
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)
5722 + printkl(KERN_ERR PFX "MAC suspend failed\n");
5725 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
5728 + struct net_device *net_dev = bcm->net_dev;
5732 + bcm->iw_mode = iw_mode;
5733 + if (iw_mode == IW_MODE_MONITOR)
5734 + net_dev->type = ARPHRD_IEEE80211;
5736 + net_dev->type = ARPHRD_ETHER;
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;
5744 +/* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
5745 +status |= BCM43xx_SBF_MODE_PROMISC;
5747 + switch (iw_mode) {
5748 + case IW_MODE_MONITOR:
5749 + status |= BCM43xx_SBF_MODE_MONITOR;
5750 + status |= BCM43xx_SBF_MODE_PROMISC;
5752 + case IW_MODE_ADHOC:
5753 + status &= ~BCM43xx_SBF_MODE_NOTADHOC;
5755 + case IW_MODE_MASTER:
5756 + status |= BCM43xx_SBF_MODE_AP;
5758 + case IW_MODE_SECOND:
5759 + case IW_MODE_REPEAT:
5760 + TODO(); /* TODO */
5762 + case IW_MODE_INFRA:
5763 + /* nothing to be done here... */
5766 + dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
5768 + if (net_dev->flags & IFF_PROMISC)
5769 + status |= BCM43xx_SBF_MODE_PROMISC;
5770 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
5773 + if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
5774 + if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
5779 + bcm43xx_write16(bcm, 0x0612, value);
5782 +/* This is the opposite of bcm43xx_chip_init() */
5783 +static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
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);
5793 +/* Initialize the chip
5794 + * http://bcm-specs.sipsolutions.net/ChipInit
5796 +static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
5798 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5799 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5805 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5806 + BCM43xx_SBF_CORE_READY
5807 + | BCM43xx_SBF_400);
5809 + err = bcm43xx_request_firmware(bcm);
5812 + bcm43xx_upload_microcode(bcm);
5813 + err = bcm43xx_initialize_irq(bcm);
5815 + goto err_release_fw;
5816 + err = bcm43xx_gpio_init(bcm);
5818 + goto err_free_irq;
5819 + err = bcm43xx_upload_initvals(bcm);
5821 + goto err_gpio_cleanup;
5822 + bcm43xx_radio_turn_on(bcm);
5824 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
5825 + err = bcm43xx_phy_init(bcm);
5827 + goto err_radio_off;
5829 + /* Select initial Interference Mitigation. */
5830 + tmp = radio->interfmode;
5831 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
5832 + bcm43xx_radio_set_interference_mitigation(bcm, tmp);
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);
5841 + bcm43xx_write32(bcm, 0x0100, 0x01000000);
5842 + if (bcm->current_core->rev < 5)
5843 + bcm43xx_write32(bcm, 0x010C, 0x01000000);
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);
5852 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5853 + value32 |= 0x100000;
5854 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
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);
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);
5868 + /* Initially set the wireless operation mode. */
5869 + bcm43xx_set_iwmode(bcm, bcm->iw_mode);
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);
5877 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
5878 + bcm43xx_write32(bcm, 0x018C, 0x02000000);
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);
5886 + value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
5887 + value32 |= 0x00100000;
5888 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
5890 + bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
5893 + dprintk(KERN_INFO PFX "Chip initialized\n");
5898 + bcm43xx_radio_turn_off(bcm);
5900 + bcm43xx_gpio_cleanup(bcm);
5902 + free_irq(bcm->irq, bcm);
5904 + bcm43xx_release_firmware(bcm, 1);
5908 +/* Validate chip access
5909 + * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
5910 +static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
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)
5919 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
5920 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
5922 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
5924 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5925 + if ((value | 0x80000000) != 0x80000400)
5928 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5929 + if (value != 0x00000000)
5934 + printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
5938 +static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
5940 + /* Initialize a "phyinfo" structure. The structure is already
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);
5950 +static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
5952 + /* Initialize a "radioinfo" structure. The structure is already
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;
5964 +static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
5968 + u32 core_vendor, core_id, core_rev;
5969 + u32 sb_id_hi, chip_id_32 = 0;
5970 + u16 pci_device, chip_id_16;
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;
5985 + err = _switch_core(bcm, 0);
5989 + /* fetch sb_id_hi from core information registers */
5990 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
5992 + core_id = (sb_id_hi & 0xFFF0) >> 4;
5993 + core_rev = (sb_id_hi & 0xF);
5994 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
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);
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;
6024 + printk(KERN_ERR PFX "Could not determine Chip ID\n");
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;
6034 + switch (chip_id_16) {
6057 + /* SOL if we get here */
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;
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");
6076 + if (bcm->core_chipcommon.available)
6080 + for ( ; current_core < core_count; current_core++) {
6081 + struct bcm43xx_coreinfo *core;
6082 + struct bcm43xx_coreinfo_80211 *ext_80211;
6084 + err = _switch_core(bcm, current_core);
6087 + /* Gather information */
6088 + /* fetch sb_id_hi from core information registers */
6089 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
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;
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" );
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");
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)
6118 + printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
6119 + BCM43xx_MAX_80211_CORES);
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.
6129 + if (bcm->pci_dev->device != 0x4324) {
6130 + dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
6134 + switch (core_rev) {
6143 + printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
6148 + bcm->nr_80211_available++;
6149 + bcm43xx_init_struct_phyinfo(&ext_80211->phy);
6150 + bcm43xx_init_struct_radioinfo(&ext_80211->radio);
6152 + case BCM43xx_COREID_CHIPCOMMON:
6153 + printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
6157 + core->available = 1;
6158 + core->id = core_id;
6159 + core->rev = core_rev;
6160 + core->index = current_core;
6164 + if (!bcm->core_80211[0].available) {
6165 + printk(KERN_ERR PFX "Error: No 80211 core found!\n");
6170 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
6177 +static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
6179 + const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
6180 + u8 *bssid = bcm->bssid;
6182 + switch (bcm->iw_mode) {
6183 + case IW_MODE_ADHOC:
6184 + random_ether_addr(bssid);
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);
6198 +static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
6206 + offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
6209 + offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
6211 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
6212 + bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
6215 +static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
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);
6238 +static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
6240 + bcm43xx_chip_cleanup(bcm);
6241 + bcm43xx_pio_free(bcm);
6242 + bcm43xx_dma_free(bcm);
6244 + bcm->current_core->initialized = 0;
6247 +/* http://bcm-specs.sipsolutions.net/80211Init */
6248 +static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
6250 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6251 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6254 + u32 sbimconfiglow;
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;
6267 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
6270 + bcm43xx_phy_calibrate(bcm);
6271 + err = bcm43xx_chip_init(bcm);
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);
6278 + if (0 /*FIXME: which condition has to be used here? */)
6279 + ucodeflags |= 0x00000010;
6281 + /* HW decryption needs to be set now. */
6282 + ucodeflags |= 0x40000000;
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;
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);
6302 + /* Short/Long Retry Limit.
6303 + * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
6304 + * the chip-internal counter.
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);
6311 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
6312 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
6314 + bcm43xx_rate_memory_init(bcm);
6316 + /* Minimum Contention Window */
6317 + if (phy->type == BCM43xx_PHYTYPE_B)
6318 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
6320 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
6321 + /* Maximum Contention Window */
6322 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
6324 + bcm43xx_gen_bssid(bcm);
6325 + bcm43xx_write_mac_bssid_templates(bcm);
6327 + if (bcm->current_core->rev >= 5)
6328 + bcm43xx_write16(bcm, 0x043C, 0x000C);
6330 + if (bcm43xx_using_pio(bcm))
6331 + err = bcm43xx_pio_init(bcm);
6333 + err = bcm43xx_dma_init(bcm);
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);
6340 + bcm43xx_mac_enable(bcm);
6341 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
6343 + bcm->current_core->initialized = 1;
6348 + bcm43xx_chip_cleanup(bcm);
6352 +static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
6357 + err = bcm43xx_pctl_set_crystal(bcm, 1);
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);
6367 +static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
6369 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
6370 + bcm43xx_pctl_set_crystal(bcm, 0);
6373 +static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
6377 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
6378 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
6381 +static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
6384 + struct bcm43xx_coreinfo *old_core;
6386 + old_core = bcm->current_core;
6387 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6391 + bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
6393 + bcm43xx_switch_core(bcm, old_core);
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
6402 +static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
6405 + u32 backplane_flag_nr;
6407 + struct bcm43xx_coreinfo *old_core;
6410 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
6411 + backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
6413 + old_core = bcm->current_core;
6414 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
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);
6423 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
6425 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6426 + goto out_switch_back;
6428 + value |= core_mask << 8;
6429 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
6431 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6432 + goto out_switch_back;
6436 + value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
6437 + value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
6438 + bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
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);
6452 + err = bcm43xx_switch_core(bcm, old_core);
6457 +static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
6459 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6461 + if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
6464 + bcm43xx_mac_suspend(bcm);
6465 + bcm43xx_phy_lo_g_measure(bcm);
6466 + bcm43xx_mac_enable(bcm);
6469 +static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
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);
6479 +static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
6481 + /* Update device statistics. */
6482 + bcm43xx_calculate_link_quality(bcm);
6485 +static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
6487 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6488 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
6499 + } else if (1/*TODO*/) {
6501 + if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
6502 + bcm43xx_radio_set_interference_mitigation(bcm,
6503 + BCM43xx_RADIO_INTERFMODE_NONE);
6507 + bcm43xx_mac_enable(bcm);
6508 + } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
6510 + //TODO: implement rev1 workaround
6513 + bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
6514 + //TODO for APHY (temperature?)
6517 +static void bcm43xx_periodic_task_handler(unsigned long d)
6519 + struct bcm43xx_private *bcm = (struct bcm43xx_private *)d;
6520 + unsigned long flags;
6521 + unsigned int state;
6523 + bcm43xx_lock_mmio(bcm, flags);
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;
6536 + mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15));
6538 + bcm43xx_unlock_mmio(bcm, flags);
6541 +static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
6543 + del_timer_sync(&bcm->periodic_tasks);
6546 +static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
6548 + struct timer_list *timer = &(bcm->periodic_tasks);
6550 + assert(bcm->initialized);
6551 + setup_timer(timer,
6552 + bcm43xx_periodic_task_handler,
6553 + (unsigned long)bcm);
6554 + timer->expires = jiffies;
6558 +static void bcm43xx_free_modes(struct bcm43xx_private *bcm)
6560 + struct ieee80211_hw *ieee = bcm->ieee;
6563 + for (i = 0; i < ieee->num_modes; i++) {
6564 + kfree(ieee->modes[i].channels);
6565 + kfree(ieee->modes[i].rates);
6567 + kfree(ieee->modes);
6568 + ieee->modes = NULL;
6569 + ieee->num_modes = 0;
6572 +static int bcm43xx_append_mode(struct ieee80211_hw *ieee,
6575 + const struct ieee80211_channel *channels,
6577 + const struct ieee80211_rate *rates)
6579 + struct ieee80211_hw_modes *mode;
6580 + int err = -ENOMEM;
6582 + mode = &(ieee->modes[ieee->num_modes]);
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)
6589 + memcpy(mode->channels, channels, sizeof(*channels) * nr_channels);
6591 + mode->num_rates = nr_rates;
6592 + mode->rates = kzalloc(sizeof(*rates) * nr_rates, GFP_KERNEL);
6594 + goto err_free_channels;
6595 + memcpy(mode->rates, rates, sizeof(*rates) * nr_rates);
6597 + ieee->num_modes++;
6603 + kfree(mode->channels);
6607 +static int bcm43xx_setup_modes_aphy(struct bcm43xx_private *bcm)
6611 + static const struct ieee80211_rate rates[] = {
6614 + .val = BCM43xx_OFDM_RATE_6MB,
6615 + .flags = IEEE80211_RATE_OFDM,
6616 + .val2 = BCM43xx_OFDM_RATE_6MB,
6619 + .val = BCM43xx_OFDM_RATE_9MB,
6620 + .flags = IEEE80211_RATE_OFDM,
6621 + .val2 = BCM43xx_OFDM_RATE_9MB,
6624 + .val = BCM43xx_OFDM_RATE_12MB,
6625 + .flags = IEEE80211_RATE_OFDM,
6626 + .val2 = BCM43xx_OFDM_RATE_12MB,
6629 + .val = BCM43xx_OFDM_RATE_18MB,
6630 + .flags = IEEE80211_RATE_OFDM,
6631 + .val2 = BCM43xx_OFDM_RATE_18MB,
6634 + .val = BCM43xx_OFDM_RATE_24MB,
6635 + .flags = IEEE80211_RATE_OFDM,
6636 + .val2 = BCM43xx_OFDM_RATE_24MB,
6639 + .val = BCM43xx_OFDM_RATE_36MB,
6640 + .flags = IEEE80211_RATE_OFDM,
6641 + .val2 = BCM43xx_OFDM_RATE_36MB,
6644 + .val = BCM43xx_OFDM_RATE_48MB,
6645 + .flags = IEEE80211_RATE_OFDM,
6646 + .val2 = BCM43xx_OFDM_RATE_48MB,
6649 + .val = BCM43xx_OFDM_RATE_54MB,
6650 + .flags = IEEE80211_RATE_OFDM,
6651 + .val2 = BCM43xx_OFDM_RATE_54MB,
6654 + static const struct ieee80211_channel channels[] = {
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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);
6784 +static int bcm43xx_setup_modes_bphy(struct bcm43xx_private *bcm)
6788 + static const struct ieee80211_rate rates[] = {
6791 + .val = BCM43xx_CCK_RATE_1MB,
6792 + .flags = IEEE80211_RATE_CCK,
6793 + .val2 = BCM43xx_CCK_RATE_1MB,
6796 + .val = BCM43xx_CCK_RATE_2MB,
6797 + .flags = IEEE80211_RATE_CCK_2,
6798 + .val2 = BCM43xx_CCK_RATE_2MB,
6801 + .val = BCM43xx_CCK_RATE_5MB,
6802 + .flags = IEEE80211_RATE_CCK_2,
6803 + .val2 = BCM43xx_CCK_RATE_5MB,
6806 + .val = BCM43xx_CCK_RATE_11MB,
6807 + .flags = IEEE80211_RATE_CCK_2,
6808 + .val2 = BCM43xx_CCK_RATE_11MB,
6811 + static const struct ieee80211_channel channels[] = {
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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);
6951 +static int bcm43xx_setup_modes_gphy(struct bcm43xx_private *bcm)
6955 + static const struct ieee80211_rate rates[] = {
6958 + .val = BCM43xx_CCK_RATE_1MB,
6959 + .flags = IEEE80211_RATE_CCK,
6960 + .val2 = BCM43xx_CCK_RATE_1MB,
6963 + .val = BCM43xx_CCK_RATE_2MB,
6964 + .flags = IEEE80211_RATE_CCK_2,
6965 + .val2 = BCM43xx_CCK_RATE_2MB,
6968 + .val = BCM43xx_CCK_RATE_5MB,
6969 + .flags = IEEE80211_RATE_CCK_2,
6970 + .val2 = BCM43xx_CCK_RATE_5MB,
6973 + .val = BCM43xx_OFDM_RATE_6MB,
6974 + .flags = IEEE80211_RATE_OFDM,
6975 + .val2 = BCM43xx_OFDM_RATE_6MB,
6978 + .val = BCM43xx_OFDM_RATE_9MB,
6979 + .flags = IEEE80211_RATE_OFDM,
6980 + .val2 = BCM43xx_OFDM_RATE_9MB,
6983 + .val = BCM43xx_CCK_RATE_11MB,
6984 + .flags = IEEE80211_RATE_CCK_2,
6985 + .val2 = BCM43xx_CCK_RATE_11MB,
6988 + .val = BCM43xx_OFDM_RATE_12MB,
6989 + .flags = IEEE80211_RATE_OFDM,
6990 + .val2 = BCM43xx_OFDM_RATE_12MB,
6993 + .val = BCM43xx_OFDM_RATE_18MB,
6994 + .flags = IEEE80211_RATE_OFDM,
6995 + .val2 = BCM43xx_OFDM_RATE_18MB,
6998 + .val = BCM43xx_OFDM_RATE_24MB,
6999 + .flags = IEEE80211_RATE_OFDM,
7000 + .val2 = BCM43xx_OFDM_RATE_24MB,
7003 + .val = BCM43xx_OFDM_RATE_36MB,
7004 + .flags = IEEE80211_RATE_OFDM,
7005 + .val2 = BCM43xx_OFDM_RATE_36MB,
7008 + .val = BCM43xx_OFDM_RATE_48MB,
7009 + .flags = IEEE80211_RATE_OFDM,
7010 + .val2 = BCM43xx_OFDM_RATE_48MB,
7013 + .val = BCM43xx_OFDM_RATE_54MB,
7014 + .flags = IEEE80211_RATE_OFDM,
7015 + .val2 = BCM43xx_OFDM_RATE_54MB,
7018 + static const struct ieee80211_channel channels[] = {
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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);
7157 +static int bcm43xx_setup_modes(struct bcm43xx_private *bcm)
7159 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7160 + int err = -ENOMEM;
7162 + struct ieee80211_hw *ieee = bcm->ieee;
7164 + if (phy->type == BCM43xx_PHYTYPE_A)
7166 + else if (phy->type == BCM43xx_PHYTYPE_B)
7170 + ieee->modes = kzalloc(sizeof(*(ieee->modes)) * nr, GFP_KERNEL);
7173 + ieee->num_modes = 0;
7175 + err = bcm43xx_setup_modes_aphy(bcm);
7178 + err = bcm43xx_setup_modes_gphy(bcm);
7181 + err = bcm43xx_setup_modes_bphy(bcm);
7185 + assert(ieee->num_modes == nr && nr > 0);
7190 + bcm43xx_free_modes(bcm);
7194 +static void bcm43xx_security_init(struct bcm43xx_private *bcm)
7196 + bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
7198 + bcm43xx_clear_keys(bcm);
7201 +/* This is the opposite of bcm43xx_init_board() */
7202 +static void bcm43xx_free_board(struct bcm43xx_private *bcm)
7205 + unsigned long flags;
7207 + bcm43xx_sysfs_unregister(bcm);
7209 + bcm43xx_periodic_tasks_delete(bcm);
7211 + bcm43xx_lock(bcm, flags);
7212 + bcm->initialized = 0;
7213 + bcm->shutting_down = 1;
7214 + bcm43xx_unlock(bcm, flags);
7216 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7217 + if (!bcm->core_80211[i].available)
7219 + if (!bcm->core_80211[i].initialized)
7222 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7224 + bcm43xx_wireless_core_cleanup(bcm);
7227 + bcm43xx_pctl_set_crystal(bcm, 0);
7228 + bcm43xx_free_modes(bcm);
7230 + bcm43xx_lock(bcm, flags);
7231 + bcm->shutting_down = 0;
7232 + bcm43xx_unlock(bcm, flags);
7235 +static int bcm43xx_init_board(struct bcm43xx_private *bcm)
7239 + unsigned long flags;
7243 + bcm43xx_lock(bcm, flags);
7244 + bcm->initialized = 0;
7245 + bcm->shutting_down = 0;
7246 + bcm43xx_unlock(bcm, flags);
7248 + err = bcm43xx_pctl_set_crystal(bcm, 1);
7251 + err = bcm43xx_pctl_init(bcm);
7253 + goto err_crystal_off;
7254 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
7256 + goto err_crystal_off;
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);
7263 + goto err_80211_unwind;
7265 + /* Enable the selected wireless core.
7266 + * Connect PHY only on the first core.
7268 + if (!bcm43xx_core_enabled(bcm)) {
7269 + if (bcm->nr_80211_available == 1) {
7270 + connect_phy = bcm43xx_current_phy(bcm)->connected;
7277 + bcm43xx_wireless_core_reset(bcm, connect_phy);
7281 + bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
7283 + err = bcm43xx_wireless_core_init(bcm);
7285 + goto err_80211_unwind;
7288 + bcm43xx_mac_suspend(bcm);
7289 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7290 + bcm43xx_radio_turn_off(bcm);
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);
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);
7308 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
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);
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);
7321 + bcm43xx_periodic_tasks_setup(bcm);
7322 + bcm43xx_sysfs_register(bcm);
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)
7334 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7335 + bcm43xx_wireless_core_cleanup(bcm);
7338 + bcm43xx_pctl_set_crystal(bcm, 0);
7342 +static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
7344 + struct pci_dev *pci_dev = bcm->pci_dev;
7347 + bcm43xx_chipset_detach(bcm);
7348 + /* Do _not_ access the chip, after it is detached. */
7349 + iounmap(bcm->mmio_addr);
7351 + pci_release_regions(pci_dev);
7352 + pci_disable_device(pci_dev);
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);
7362 +static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
7364 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7369 + int phy_rev_ok = 1;
7372 + value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
7374 + phy_version = (value & 0xF000) >> 12;
7375 + phy_type = (value & 0x0F00) >> 8;
7376 + phy_rev = (value & 0x000F);
7378 + dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
7379 + phy_version, phy_type, phy_rev);
7381 + switch (phy_type) {
7382 + case BCM43xx_PHYTYPE_A:
7386 + case BCM43xx_PHYTYPE_B:
7387 + if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
7390 + case BCM43xx_PHYTYPE_G:
7395 + printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
7399 + if (!phy_rev_ok) {
7400 + printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
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,
7412 + phy->_lo_pairs = p;
7418 +static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
7420 + struct pci_dev *pci_dev = bcm->pci_dev;
7421 + struct net_device *net_dev = bcm->net_dev;
7424 + unsigned long mmio_start, mmio_flags, mmio_len;
7427 + err = pci_enable_device(pci_dev);
7429 + printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
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));
7440 + goto err_pci_disable;
7442 + err = pci_request_regions(pci_dev, KBUILD_MODNAME);
7444 + printk(KERN_ERR PFX
7445 + "could not access PCI resources (%i)\n", err);
7446 + goto err_pci_disable;
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));
7455 + goto err_pci_release;
7457 + bcm->mmio_len = mmio_len;
7458 + net_dev->base_addr = (unsigned long)bcm->mmio_addr;
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);
7467 + err = bcm43xx_chipset_attach(bcm);
7470 + err = bcm43xx_pctl_init(bcm);
7472 + goto err_chipset_detach;
7473 + err = bcm43xx_probe_cores(bcm);
7475 + goto err_chipset_detach;
7477 + /* Attach all IO cores to the backplane. */
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);
7484 + printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
7485 + goto err_chipset_detach;
7488 + err = bcm43xx_sprom_extract(bcm);
7490 + goto err_chipset_detach;
7491 + err = bcm43xx_leds_init(bcm);
7493 + goto err_chipset_detach;
7495 + for (i = 0; i < bcm->nr_80211_available; i++) {
7496 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7497 + assert(err != -ENODEV);
7499 + goto err_80211_unwind;
7501 + /* Enable the selected wireless core.
7502 + * Connect PHY only on the first core.
7504 + bcm43xx_wireless_core_reset(bcm, (i == 0));
7506 + err = bcm43xx_read_phyinfo(bcm);
7507 + if (err && (i == 0))
7508 + goto err_80211_unwind;
7510 + err = bcm43xx_read_radioinfo(bcm);
7511 + if (err && (i == 0))
7512 + goto err_80211_unwind;
7514 + err = bcm43xx_validate_chip(bcm);
7515 + if (err && (i == 0))
7516 + goto err_80211_unwind;
7518 + bcm43xx_radio_turn_off(bcm);
7519 + err = bcm43xx_phy_init_tssi2dbm_table(bcm);
7521 + goto err_80211_unwind;
7522 + bcm43xx_wireless_core_disable(bcm);
7524 + bcm43xx_pctl_set_crystal(bcm, 0);
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);
7530 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
7532 + snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
7533 + "Broadcom %04X", bcm->chip_id);
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);
7545 +err_chipset_detach:
7546 + bcm43xx_chipset_detach(bcm);
7548 + iounmap(bcm->mmio_addr);
7550 + pci_release_regions(pci_dev);
7552 + pci_disable_device(pci_dev);
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)
7561 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7562 + int err = -ENODEV;
7563 + unsigned long flags;
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);
7570 + err = bcm43xx_dma_tx(bcm, skb, ctl);
7572 + bcm43xx_unlock_mmio(bcm, flags);
7577 +static int bcm43xx_net_reset(struct net_device *net_dev)
7579 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7580 + unsigned long flags;
7582 + bcm43xx_lock_mmio(bcm, flags);
7583 + bcm43xx_controller_restart(bcm, "IEEE reset");
7584 + bcm43xx_unlock_mmio(bcm, flags);
7589 +static int bcm43xx_net_config(struct net_device *net_dev,
7590 + struct ieee80211_conf *conf)
7592 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7593 + struct bcm43xx_radioinfo *radio;
7594 + struct bcm43xx_phyinfo *phy;
7595 + unsigned long flags;
7597 + bcm43xx_lock_mmio(bcm, flags);
7598 + if (!bcm->initialized) {
7599 + bcm43xx_unlock_mmio(bcm, flags);
7602 + radio = bcm43xx_current_radio(bcm);
7603 + phy = bcm43xx_current_phy(bcm);
7605 + if (conf->channel != radio->channel)
7606 + bcm43xx_radio_selectchannel(bcm, conf->channel, 0);
7608 + if (conf->mode != bcm->iw_mode)
7609 + bcm43xx_set_iwmode(bcm, conf->mode);
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);
7616 + bcm43xx_short_slot_timing_disable(bcm);
7619 + if (conf->power_level != 0) {
7620 + radio->power_level = conf->power_level;
7621 + bcm43xx_phy_xmitpower(bcm);
7623 +//FIXME: This does not seem to wake up:
7625 + if (conf->power_level == 0) {
7626 + if (radio->enabled)
7627 + bcm43xx_radio_turn_off(bcm);
7629 + if (!radio->enabled)
7630 + bcm43xx_radio_turn_on(bcm);
7637 + bcm43xx_unlock_mmio(bcm, flags);
7642 +static int bcm43xx_net_set_key(struct net_device *net_dev,
7645 + struct ieee80211_key_conf *key,
7648 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7649 + unsigned long flags;
7652 + int err = -EINVAL;
7654 + switch (key->alg) {
7658 + algorithm = BCM43xx_SEC_ALGO_NONE;
7661 + if (key->keylen == 5)
7662 + algorithm = BCM43xx_SEC_ALGO_WEP;
7664 + algorithm = BCM43xx_SEC_ALGO_WEP104;
7667 + algorithm = BCM43xx_SEC_ALGO_TKIP;
7670 + algorithm = BCM43xx_SEC_ALGO_AES;
7674 + index = (u8)(key->keyidx);
7675 + if (index >= ARRAY_SIZE(bcm->key))
7677 + bcm43xx_lock_mmio(bcm, flags);
7680 + err = bcm43xx_key_write(bcm, index, algorithm,
7681 + key->key, key->keylen,
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;
7692 + bcm->key[index].enabled = 0;
7695 + case REMOVE_ALL_KEYS:
7696 + bcm43xx_clear_keys(bcm);
7699 + case ENABLE_COMPRESSION:
7700 + case DISABLE_COMPRESSION:
7705 + bcm43xx_unlock_mmio(bcm, flags);
7710 +static int bcm43xx_net_conf_tx(struct net_device *net_dev,
7712 + const struct ieee80211_tx_queue_params *params)
7717 +static int bcm43xx_net_get_tx_stats(struct net_device *net_dev,
7718 + struct ieee80211_tx_queue_stats *stats)
7720 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7721 + unsigned long flags;
7723 + bcm43xx_lock(bcm, flags);
7724 + if (bcm43xx_using_pio(bcm))
7725 + bcm43xx_pio_get_tx_stats(bcm, stats);
7727 + bcm43xx_dma_get_tx_stats(bcm, stats);
7728 + bcm43xx_unlock(bcm, flags);
7733 +static int bcm43xx_net_get_stats(struct net_device *net_dev,
7734 + struct ieee80211_low_level_stats *stats)
7736 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7737 + unsigned long flags;
7739 + bcm43xx_lock(bcm, flags);
7740 + memcpy(stats, &bcm->ieee_stats, sizeof(*stats));
7741 + bcm43xx_unlock(bcm, flags);
7746 +#ifdef CONFIG_NET_POLL_CONTROLLER
7747 +static void bcm43xx_net_poll_controller(struct net_device *net_dev)
7749 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7750 + unsigned long flags;
7752 + local_irq_save(flags);
7753 + bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
7754 + local_irq_restore(flags);
7756 +#endif /* CONFIG_NET_POLL_CONTROLLER */
7758 +static int bcm43xx_net_open(struct net_device *net_dev)
7760 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7762 + return bcm43xx_init_board(bcm);
7765 +static int bcm43xx_net_stop(struct net_device *net_dev)
7767 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7769 + if (bcm->initialized) {
7770 + bcm43xx_disable_interrupts_sync(bcm, NULL);
7771 + bcm43xx_free_board(bcm);
7777 +/* Initialization of struct net_device, just after allocation. */
7778 +static void bcm43xx_netdev_setup(struct net_device *net_dev)
7780 +#ifdef CONFIG_NET_POLL_CONTROLLER
7781 + net_dev->poll_controller = bcm43xx_net_poll_controller;
7783 + SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
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)
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;
7806 + err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
7807 + err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
7809 +#ifdef CONFIG_BCM43XX_D80211_PIO
7810 + printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
7811 + bcm->__using_pio = 1;
7813 + printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
7814 + "Recompile the driver with PIO support, please.\n");
7816 +#endif /* CONFIG_BCM43XX_D80211_PIO */
7823 +static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
7824 + const struct pci_device_id *ent)
7826 + struct net_device *net_dev;
7827 + struct bcm43xx_private *bcm;
7828 + struct ieee80211_hw *ieee;
7829 + int err = -ENOMEM;
7831 +#ifdef CONFIG_BCM947XX
7832 + if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
7836 +#ifdef DEBUG_SINGLE_DEVICE_ONLY
7837 + if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
7841 + ieee = kzalloc(sizeof(*ieee), GFP_KERNEL);
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;
7856 + ieee->get_tx_stats = bcm43xx_net_get_tx_stats;
7857 + ieee->conf_tx = bcm43xx_net_conf_tx;
7858 + ieee->wep_include_iv = 1;
7860 + net_dev = ieee80211_alloc_hw(sizeof(*bcm), bcm43xx_netdev_setup);
7862 + printk(KERN_ERR PFX
7863 + "could not allocate ieee80211 device %s\n",
7865 + goto err_free_ieee;
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);
7872 + goto err_free_netdev;
7874 + pci_set_drvdata(pdev, net_dev);
7876 + err = bcm43xx_attach_board(bcm);
7878 + goto err_free_netdev;
7879 + err = ieee80211_register_hw(net_dev, ieee);
7881 + goto err_detach_board;
7883 + bcm43xx_debugfs_add_device(bcm);
7890 + bcm43xx_detach_board(bcm);
7892 + ieee80211_free_hw(net_dev);
7898 +static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
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;
7904 + bcm43xx_debugfs_remove_device(bcm);
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);
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);
7920 +/* Hard-reset the chip. Do not call this directly.
7921 + * Use bcm43xx_controller_restart()
7923 +static void bcm43xx_chip_reset(void *_bcm)
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;
7930 + int was_initialized = bcm->initialized;
7932 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
7933 + tasklet_disable(&bcm->isr_tasklet);
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);
7943 + err = bcm43xx_attach_board(bcm);
7946 + if (was_initialized) {
7947 + err = bcm43xx_init_board(bcm);
7951 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
7952 + printk(KERN_INFO PFX "Controller restarted\n");
7956 + printk(KERN_ERR PFX "Controller restart failed\n");
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.
7963 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
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);
7974 +static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
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;
7981 + dprintk(KERN_INFO PFX "Suspending...\n");
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);
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");
7996 + bcm->firmware_norelease = 1;
7997 + bcm43xx_free_board(bcm);
7998 + bcm->firmware_norelease = 0;
8000 + bcm43xx_chipset_detach(bcm);
8002 + pci_save_state(pdev);
8003 + pci_disable_device(pdev);
8004 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
8006 + dprintk(KERN_INFO PFX "Device suspended.\n");
8011 +static int bcm43xx_resume(struct pci_dev *pdev)
8013 + struct net_device *net_dev = pci_get_drvdata(pdev);
8014 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8017 + dprintk(KERN_INFO PFX "Resuming...\n");
8019 + pci_set_power_state(pdev, 0);
8020 + pci_enable_device(pdev);
8021 + pci_restore_state(pdev);
8023 + bcm43xx_chipset_attach(bcm);
8024 + if (bcm->was_initialized) {
8025 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
8026 + err = bcm43xx_init_board(bcm);
8029 + printk(KERN_ERR PFX "Resume failed!\n");
8033 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8035 + dprintk(KERN_INFO PFX "Device resumed.\n");
8040 +#endif /* CONFIG_PM */
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),
8048 + .suspend = bcm43xx_suspend,
8049 + .resume = bcm43xx_resume,
8050 +#endif /* CONFIG_PM */
8053 +static int __init bcm43xx_init(void)
8055 + printk(KERN_INFO KBUILD_MODNAME " driver\n");
8056 + bcm43xx_debugfs_init();
8057 + return pci_register_driver(&bcm43xx_pci_driver);
8060 +static void __exit bcm43xx_exit(void)
8062 + pci_unregister_driver(&bcm43xx_pci_driver);
8063 + bcm43xx_debugfs_exit();
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
8074 + Broadcom BCM43xx wireless driver
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>
8082 + Some parts of the code in this file are derived from the ipw2200
8083 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
8102 +#ifndef BCM43xx_MAIN_H_
8103 +#define BCM43xx_MAIN_H_
8105 +#include "bcm43xx.h"
8107 +#ifdef CONFIG_BCM947XX
8108 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
8110 +static inline void e_aton(char *str, char *dest)
8113 + u16 *d = (u16 *) dest;
8116 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
8118 + if (!*str++ || i == 6)
8121 + for (i = 0; i < 3; i++)
8122 + d[i] = cpu_to_be16(d[i]);
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))
8132 +/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
8134 +u8 bcm43xx_freq_to_channel_a(int freq)
8136 + return ((freq - 5000) / 5);
8139 +u8 bcm43xx_freq_to_channel_bg(int freq)
8146 + channel = (freq - 2407) / 5;
8151 +u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
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);
8159 +/* Lightweight function to convert a channel number to a frequency (in Mhz). */
8161 +int bcm43xx_channel_to_freq_a(u8 channel)
8163 + return (5000 + (5 * channel));
8166 +int bcm43xx_channel_to_freq_bg(u8 channel)
8170 + if (channel == 14)
8173 + freq = 2407 + (5 * channel);
8178 +int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
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);
8186 +/* Lightweight function to check if a channel number is valid.
8187 + * Note that this does _NOT_ check for geographical restrictions!
8190 +int bcm43xx_is_valid_channel_a(u8 channel)
8192 + return (channel <= 200);
8195 +int bcm43xx_is_valid_channel_bg(u8 channel)
8197 + return (channel >= 1 && channel <= 14);
8200 +int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
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);
8209 +int bcm43xx_is_cck_rate(int rate)
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);
8217 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
8218 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
8220 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
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,
8230 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
8231 + u16 routing, u16 offset,
8234 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
8236 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
8238 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
8240 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
8241 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
8243 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
8245 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
8246 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
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
8255 + Broadcom BCM43xx wireless driver
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>
8263 + Some parts of the code in this file are derived from the ipw2200
8264 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
8283 +#include <linux/delay.h>
8284 +#include <linux/pci.h>
8285 +#include <linux/types.h>
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"
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,
8314 +static const s8 bcm43xx_tssi2dbm_g_table[] = {
8329 + -20, -20, -20, -20,
8330 + -20, -20, -20, -20,
8333 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
8336 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
8338 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8340 + assert(irqs_disabled());
8341 + if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
8342 + phy->is_locked = 0;
8345 + if (bcm->current_core->rev < 3) {
8346 + bcm43xx_mac_suspend(bcm);
8347 + spin_lock(&phy->lock);
8349 + if (bcm->iw_mode != IW_MODE_MASTER)
8350 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
8352 + phy->is_locked = 1;
8355 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
8357 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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);
8366 + if (bcm->iw_mode != IW_MODE_MASTER)
8367 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
8369 + phy->is_locked = 0;
8372 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
8374 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8375 + return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
8378 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
8380 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8382 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
8385 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
8387 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8388 + unsigned long flags;
8390 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
8391 + if (phy->calibrated)
8393 + if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
8394 + /* We do not want to be preempted while calibrating
8397 + local_irq_save(flags);
8399 + bcm43xx_wireless_core_reset(bcm, 0);
8400 + bcm43xx_phy_initg(bcm);
8401 + bcm43xx_wireless_core_reset(bcm, 1);
8403 + local_irq_restore(flags);
8405 + phy->calibrated = 1;
8409 + * http://bcm-specs.sipsolutions.net/SetPHY
8411 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
8413 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8416 + if (bcm->current_core->rev < 5)
8419 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
8421 + if (!(flags & 0x00010000))
8423 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8424 + flags |= (0x800 << 18);
8425 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8427 + if (!(flags & 0x00020000))
8429 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8430 + flags &= ~(0x800 << 18);
8431 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8434 + phy->connected = connect;
8436 + dprintk(KERN_INFO PFX "PHY connected\n");
8438 + dprintk(KERN_INFO PFX "PHY disconnected\n");
8443 +/* intialize B PHY power control
8444 + * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
8446 +static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
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;
8453 + assert(phy->type != BCM43xx_PHYTYPE_A);
8454 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8455 + (bcm->board_type == 0x0416))
8458 + bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
8459 + bcm43xx_phy_write(bcm, 0x0028, 0x8018);
8461 + if (phy->type == BCM43xx_PHYTYPE_G) {
8462 + if (!phy->connected)
8464 + bcm43xx_phy_write(bcm, 0x047A, 0xC111);
8466 + if (phy->savedpctlreg != 0xFFFF)
8469 + if (phy->type == BCM43xx_PHYTYPE_B &&
8471 + radio->version == 0x2050) {
8472 + bcm43xx_radio_write16(bcm, 0x0076,
8473 + bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
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);
8482 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
8483 + must_reset_txpower = 1;
8485 + bcm43xx_dummy_transmission(bcm);
8487 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
8489 + if (must_reset_txpower)
8490 + bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
8492 + bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
8493 + bcm43xx_radio_clear_tssi(bcm);
8496 +static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
8498 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8499 + u16 offset = 0x0000;
8501 + if (phy->rev == 1)
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);
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);
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);
8522 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
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);
8529 + if (phy->rev == 1)
8530 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
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);
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);
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);
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);
8556 + bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
8557 + bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
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);
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);
8572 +static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
8574 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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);
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]);
8592 + /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
8593 + bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
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);
8603 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
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]);
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]);
8618 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8619 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
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]);
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);
8637 + bcm43xx_phy_agcsetup(bcm);
8639 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8640 + (bcm->board_type == 0x0416) &&
8641 + (bcm->board_revision == 0x0017))
8644 + bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
8645 + bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
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);
8655 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8656 + (bcm->board_type == 0x0416) &&
8657 + (bcm->board_revision == 0x0017))
8660 + bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
8661 + bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
8665 +/* Initialize the noisescaletable for APHY */
8666 +static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
8668 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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);
8676 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8678 + if (phy->rev == 2)
8679 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
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);
8686 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8688 + if (phy->rev == 2)
8689 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
8691 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
8694 +static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
8696 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8699 + assert(phy->type == BCM43xx_PHYTYPE_A);
8700 + switch (phy->rev) {
8702 + bcm43xx_phy_write(bcm, 0x008E, 0x3800);
8703 + bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
8704 + bcm43xx_phy_write(bcm, 0x0036, 0x0400);
8706 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
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);
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);
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);
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);
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);
8736 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8737 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8738 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8740 + for (i = 0; i < 16; i++)
8741 + bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
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);
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]);
8759 + for (i = 0; i < 64; i++)
8760 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8762 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
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);
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);
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]);
8781 + bcm43xx_phy_write(bcm, 0x0003, 0x1808);
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);
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);
8797 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8798 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8799 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8801 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8802 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8809 +/* Initialize APHY. This is also called for the GPHY in some cases. */
8810 +static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
8812 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8813 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8816 + if (phy->type == BCM43xx_PHYTYPE_A) {
8817 + bcm43xx_phy_setupa(bcm);
8819 + bcm43xx_phy_setupg(bcm);
8820 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
8821 + bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
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);
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);
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);
8840 + bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
8843 + bcm43xx_phy_write(bcm, 0x007A, 0xF111);
8845 + if (phy->savedpctlreg == 0xFFFF) {
8846 + bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
8847 + bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
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)
8855 + bcm43xx_ilt_write(bcm, 0x3001,
8856 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
8859 + bcm43xx_dummy_transmission(bcm);
8860 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
8861 + bcm43xx_ilt_write(bcm, 0x3001, tval);
8863 + bcm43xx_radio_set_txpower_a(bcm, 0x0018);
8865 + bcm43xx_radio_clear_tssi(bcm);
8868 +static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
8870 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
8879 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8880 + bcm43xx_phy_write(bcm, offset, val);
8883 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8884 + if (radio->channel == 0xFF)
8885 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
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);
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);
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);
8919 +static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
8921 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
8930 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8931 + bcm43xx_phy_write(bcm, offset, val);
8934 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8935 + if (radio->channel == 0xFF)
8936 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
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);
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);
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);
8960 + bcm43xx_phy_lo_b_measure(bcm);
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);
8974 + bcm43xx_phy_init_pctl(bcm);
8977 +static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
8979 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8980 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8983 + if (phy->version == 1 &&
8984 + radio->version == 0x2050) {
8985 + bcm43xx_radio_write16(bcm, 0x007A,
8986 + bcm43xx_radio_read16(bcm, 0x007A)
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)
8997 + bcm43xx_phy_write(bcm, 0x0035,
8998 + (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
9000 + if (radio->version == 0x2050)
9001 + bcm43xx_phy_write(bcm, 0x0038, 0x0667);
9003 + if (phy->connected) {
9004 + if (radio->version == 0x2050) {
9005 + bcm43xx_radio_write16(bcm, 0x007A,
9006 + bcm43xx_radio_read16(bcm, 0x007A)
9008 + bcm43xx_radio_write16(bcm, 0x0051,
9009 + bcm43xx_radio_read16(bcm, 0x0051)
9012 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
9014 + bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9015 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9017 + bcm43xx_phy_write(bcm, 0x001C, 0x186A);
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);
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));
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);
9036 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9037 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
9038 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
9040 + if (phy->version == 1 && radio->version == 0x2050)
9041 + bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
9043 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
9045 + if (phy->version == 0)
9046 + bcm43xx_write16(bcm, 0x03E4, 0x3000);
9048 + /* Force to channel 7, even if not supported. */
9049 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9051 + if (radio->version != 0x2050) {
9052 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
9053 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
9056 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9057 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9059 + if (radio->version == 0x2050) {
9060 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9061 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9064 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9065 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9067 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
9069 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9071 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9072 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9073 + bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
9075 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9077 + if (radio->version == 0x2050)
9078 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9080 + bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
9083 +static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
9085 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9086 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
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);
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);
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);
9154 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9155 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
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);
9163 + for (offset = 0x0088; offset < 0x0098; offset++) {
9164 + bcm43xx_phy_write(bcm, offset, val);
9168 + for (offset = 0x0098; offset < 0x00A8; offset++) {
9169 + bcm43xx_phy_write(bcm, offset, val);
9173 + for (offset = 0x00A8; offset < 0x00C8; offset++) {
9174 + bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
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);
9188 + /* Force to channel 7, even if not supported. */
9189 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9191 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9192 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
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);
9204 + bcm43xx_radio_write16(bcm, 0x007A,
9205 + (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
9207 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
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);
9216 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
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);
9229 + if (phy->rev == 4)
9230 + bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
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);
9244 + bcm43xx_phy_init_pctl(bcm);
9246 + bcm43xx_write16(bcm, 0x03E6, 0x0);
9249 +static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
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];
9257 + u16 loop1_cnt, loop1_done, loop1_omitted;
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);
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);
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);
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);
9319 + bcm43xx_phy_write(bcm, 0x000A,
9320 + bcm43xx_phy_read(bcm, 0x000A)
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);
9336 + } else if (radio->revision == 8) {
9337 + bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
9342 + bcm43xx_phy_set_baseband_attenuation(bcm, 11);
9344 + if (phy->rev >= 3)
9345 + bcm43xx_phy_write(bcm, 0x080F, 0xC020);
9347 + bcm43xx_phy_write(bcm, 0x080F, 0x8020);
9348 + bcm43xx_phy_write(bcm, 0x0810, 0x0000);
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)
9365 + bcm43xx_phy_write(bcm, 0x0812,
9366 + bcm43xx_phy_read(bcm, 0x0812)
9370 + bcm43xx_radio_write16(bcm, 0x007A,
9371 + bcm43xx_radio_read16(bcm, 0x007A)
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);
9386 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9390 + loop1_omitted = loop1_cnt - loop1_done;
9393 + if (loop1_done >= 8) {
9394 + bcm43xx_phy_write(bcm, 0x0812,
9395 + bcm43xx_phy_read(bcm, 0x0812)
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);
9408 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
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]);
9425 + bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
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]);
9431 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
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]);
9438 + phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
9439 + phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
9442 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
9444 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9445 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
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;
9466 + bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
9467 + bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
9469 + bcm43xx_phy_write(bcm, 0x04CC,
9470 + (bcm43xx_phy_read(bcm, 0x04CC)
9471 + & 0x00FF) | 0x1F00);
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);
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);
9488 + bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
9490 + if (radio->txctl2 == 0xFFFF) {
9491 + bcm43xx_phy_lo_g_measure(bcm);
9493 + if (radio->version == 0x2050 && radio->revision == 8) {
9496 + bcm43xx_radio_write16(bcm, 0x0052,
9497 + (bcm43xx_radio_read16(bcm, 0x0052)
9498 + & 0xFFF0) | radio->txctl1);
9500 + if (phy->rev >= 6) {
9502 + bcm43xx_phy_write(bcm, 0x0036,
9503 + (bcm43xx_phy_read(bcm, 0x0036)
9504 + & 0xF000) | (FIXME << 12));
9507 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
9508 + bcm43xx_phy_write(bcm, 0x002E, 0x8075);
9510 + bcm43xx_phy_write(bcm, 0x003E, 0x807F);
9512 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
9514 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
9516 + if (phy->connected) {
9517 + bcm43xx_phy_lo_adjust(bcm, 0);
9518 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
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())
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);
9535 + assert(radio->nrssi[1] != -1000);
9536 + bcm43xx_calc_nrssi_threshold(bcm);
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);
9550 +static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
9555 + for (i = 0; i < 10; i++){
9556 + bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
9558 + bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
9560 + bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
9562 + ret += bcm43xx_phy_read(bcm, 0x002C);
9568 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
9570 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9571 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9572 + u16 regstack[12] = { 0 };
9577 + regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
9578 + regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
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);
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;
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);
9598 + bcm43xx_phy_write(bcm, 0x0015, 0xB000);
9599 + bcm43xx_phy_write(bcm, 0x002B, 0x0004);
9601 + if (radio->version == 0x2053) {
9602 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
9603 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
9606 + phy->minlowsig[0] = 0xFFFF;
9608 + for (i = 0; i < 4; i++) {
9609 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9610 + bcm43xx_phy_lo_b_r15_loop(bcm);
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;
9620 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
9622 + phy->minlowsig[1] = 0xFFFF;
9624 + for (i = -4; i < 5; i += 2) {
9625 + for (j = -4; j < 5; j += 2) {
9627 + fval = (0x0100 * i) + j + 0x0100;
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;
9638 + phy->minlowsigpos[1] += 0x0101;
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]);
9649 + bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
9650 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
9652 + bcm43xx_radio_write16(bcm, 0x0052,
9653 + (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
9656 + bcm43xx_write16(bcm, 0x03EC, regstack[10]);
9658 + bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
9662 +u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
9664 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9666 + if (phy->connected) {
9667 + bcm43xx_phy_write(bcm, 0x15, 0xE300);
9669 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
9671 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
9673 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
9675 + bcm43xx_phy_write(bcm, 0x0015, 0xF300);
9678 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
9680 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
9682 + bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
9686 + return bcm43xx_phy_read(bcm, 0x002D);
9689 +static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
9694 + for (i = 0; i < 8; i++)
9695 + ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
9700 +/* Write the LocalOscillator CONTROL */
9702 +void bcm43xx_lo_write(struct bcm43xx_private *bcm,
9703 + struct bcm43xx_lopair *pair)
9707 + value = (u8)(pair->low);
9708 + value |= ((u8)(pair->high)) << 8;
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));
9723 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
9727 +struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
9728 + u16 baseband_attenuation,
9729 + u16 radio_attenuation,
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);
9735 + if (baseband_attenuation > 6)
9736 + baseband_attenuation = 6;
9737 + assert(radio_attenuation < 10);
9740 + return bcm43xx_get_lopair(phy,
9741 + radio_attenuation,
9742 + baseband_attenuation);
9744 + return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
9748 +struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
9750 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9752 + return bcm43xx_find_lopair(bcm,
9753 + radio->baseband_atten,
9754 + radio->radio_atten,
9758 +/* Adjust B/G LO */
9759 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
9761 + struct bcm43xx_lopair *pair;
9764 + /* Use fixed values. Only for initialization. */
9765 + pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
9767 + pair = bcm43xx_current_lopair(bcm);
9768 + bcm43xx_lo_write(bcm, pair);
9771 +static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
9773 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9774 + u16 txctl2 = 0, i;
9775 + u32 smallest, tmp;
9777 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9779 + smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9780 + for (i = 0; i < 16; i++) {
9781 + bcm43xx_radio_write16(bcm, 0x0052, i);
9783 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9784 + if (tmp < smallest) {
9789 + radio->txctl2 = txctl2;
9793 +void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
9794 + const struct bcm43xx_lopair *in_pair,
9795 + struct bcm43xx_lopair *out_pair,
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, },
9808 + struct bcm43xx_lopair lowest_transition = {
9809 + .high = in_pair->high,
9810 + .low = in_pair->low,
9812 + struct bcm43xx_lopair tmp_pair;
9813 + struct bcm43xx_lopair transition;
9817 + int j, begin, end;
9818 + u32 lowest_deviation;
9821 + /* Note that in_pair and out_pair can point to the same pair. Be careful. */
9823 + bcm43xx_lo_write(bcm, &lowest_transition);
9824 + lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9827 + assert(state >= 0 && state <= 8);
9831 + } else if (state % 2 == 0) {
9832 + begin = state - 1;
9835 + begin = state - 2;
9844 + tmp_pair.high = lowest_transition.high;
9845 + tmp_pair.low = lowest_transition.low;
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;
9858 + lowest_transition.high = transition.high;
9859 + lowest_transition.low = transition.low;
9869 + } while (i-- && found_lower);
9871 + out_pair->high = lowest_transition.high;
9872 + out_pair->low = lowest_transition.low;
9875 +/* Set the baseband attenuation value on chip. */
9876 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
9877 + u16 baseband_attenuation)
9879 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9882 + if (phy->version == 0) {
9883 + value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
9884 + value |= (baseband_attenuation & 0x000F);
9885 + bcm43xx_write16(bcm, 0x03E6, value);
9889 + if (phy->version > 1) {
9890 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
9891 + value |= (baseband_attenuation << 2) & 0x003C;
9893 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
9894 + value |= (baseband_attenuation << 3) & 0x0078;
9896 + bcm43xx_phy_write(bcm, 0x0060, value);
9899 +/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
9900 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
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;
9910 + u16 regstack[16] = { 0 };
9913 + //XXX: What are these?
9916 + oldchannel = radio->channel;
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);
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);
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);
9946 + bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
9948 + bcm43xx_phy_set_baseband_attenuation(bcm, 2);
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);
9963 + if (is_initializing)
9964 + bcm43xx_phy_lo_g_measure_txctl2(bcm);
9965 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
9970 + for (h = 0; h < 10; h++) {
9971 + /* Loop over each possible RadioAttenuation (0-9) */
9973 + if (is_initializing) {
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));
9982 + tmp_control = bcm43xx_get_lopair(phy, 3, 0);
9983 + memcpy(&control, tmp_control, sizeof(control));
9986 + /* Loop over each possible BasebandAttenuation/2 */
9987 + for (j = 0; j < 4; j++) {
9988 + if (is_initializing) {
10000 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10001 + if (!tmp_control->used)
10003 + memcpy(&control, tmp_control, sizeof(control));
10007 + bcm43xx_radio_write16(bcm, 0x43, i);
10008 + bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
10011 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10013 + tmp = (regstack[10] & 0xFFF0);
10016 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
10018 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10019 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
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.
10041 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10042 + if (!tmp_control->used)
10044 + memcpy(&control, tmp_control, sizeof(control));
10048 + bcm43xx_radio_write16(bcm, 0x43, i - 9);
10049 + bcm43xx_radio_write16(bcm, 0x52,
10051 + | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
10054 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10056 + tmp = (regstack[10] & 0xFFF0);
10059 + bcm43xx_radio_write16(bcm, 0x7A, tmp);
10061 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10062 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10066 + /* Restoration */
10067 + if (phy->connected) {
10068 + bcm43xx_phy_write(bcm, 0x0015, 0xE300);
10069 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
10071 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
10073 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
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);
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]);
10101 + bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
10103 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
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);
10116 +#endif /* CONFIG_BCM43XX_D80211_DEBUG */
10120 +void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
10122 + struct bcm43xx_lopair *pair;
10124 + pair = bcm43xx_current_lopair(bcm);
10128 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
10130 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10131 + struct bcm43xx_lopair *pair;
10134 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10135 + pair = phy->_lo_pairs + i;
10140 +/* http://bcm-specs.sipsolutions.net/EstimatePowerOut
10141 + * This function converts a TSSI value to dBm in Q5.2
10143 +static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
10145 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10149 + tmp = phy->idle_tssi;
10151 + tmp -= phy->savedpctlreg;
10153 + switch (phy->type) {
10154 + case BCM43xx_PHYTYPE_A:
10156 + tmp = limit_value(tmp, 0x00, 0xFF);
10157 + dbm = phy->tssi2dbm[tmp];
10158 + TODO(); //TODO: There's a FIXME on the specs
10160 + case BCM43xx_PHYTYPE_B:
10161 + case BCM43xx_PHYTYPE_G:
10162 + tmp = limit_value(tmp, 0x00, 0x3F);
10163 + dbm = phy->tssi2dbm[tmp];
10172 +/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
10173 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
10175 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10176 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10178 + if (phy->savedpctlreg == 0xFFFF)
10180 + if ((bcm->board_type == 0x0416) &&
10181 + (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
10184 + switch (phy->type) {
10185 + case BCM43xx_PHYTYPE_A: {
10187 + TODO(); //TODO: Nothing for A PHYs yet :-/
10191 + case BCM43xx_PHYTYPE_B:
10192 + case BCM43xx_PHYTYPE_G: {
10195 + s8 v0, v1, v2, v3;
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;
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);
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)
10220 + v0 = (v0 + 0x20) & 0x3F;
10221 + v1 = (v1 + 0x20) & 0x3F;
10222 + v2 = (v2 + 0x20) & 0x3F;
10223 + v3 = (v3 + 0x20) & 0x3F;
10226 + bcm43xx_radio_clear_tssi(bcm);
10228 + average = (v0 + v1 + v2 + v3 + 2) / 4;
10230 + if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
10233 + estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
10235 + max_pwr = bcm->sprom.maxpower_bgphy;
10237 + if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
10238 + (phy->type == BCM43xx_PHYTYPE_G))
10242 + max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
10243 + where REG is the max power as per the regulatory domain
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);
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);
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;
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.
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;
10275 + while (baseband_attenuation < 0 && radio_attenuation > 0) {
10276 + baseband_attenuation += 4;
10277 + radio_attenuation--;
10279 + while (baseband_attenuation > 11 && radio_attenuation < 9) {
10280 + baseband_attenuation -= 4;
10281 + radio_attenuation++;
10284 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10286 + txpower = radio->txctl1;
10287 + if ((radio->version == 0x2050) && (radio->revision == 2)) {
10288 + if (radio_attenuation <= 1) {
10289 + if (txpower == 0) {
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;
10297 + } else if (radio_attenuation > 4 && txpower != 0) {
10299 + if (baseband_attenuation < 3) {
10300 + radio_attenuation -= 3;
10301 + baseband_attenuation += 2;
10303 + radio_attenuation -= 2;
10304 + baseband_attenuation -= 2;
10308 + radio->txctl1 = txpower;
10309 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10310 + radio_attenuation = limit_value(radio_attenuation, 0, 9);
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);
10327 +s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
10332 + return (num+den/2)/den;
10336 +s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
10338 + s32 m1, m2, f = 256, q, delta;
10341 + m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
10342 + m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
10346 + q = bcm43xx_tssi2dbm_ad(f * 4096 -
10347 + bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
10348 + delta = abs(q - f);
10351 + } while (delta >= 2);
10352 + entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
10356 +/* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
10357 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
10359 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10360 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10361 + s16 pab0, pab1, pab2;
10363 + s8 *dyn_tssi2dbm;
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);
10370 + pab0 = (s16)(bcm->sprom.pa0b0);
10371 + pab1 = (s16)(bcm->sprom.pa0b1);
10372 + pab2 = (s16)(bcm->sprom.pa0b2);
10375 + if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
10376 + phy->idle_tssi = 0x34;
10377 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
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);
10389 + phy->idle_tssi = 62;
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);
10395 + phy->idle_tssi = 62;
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");
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");
10410 + phy->tssi2dbm = dyn_tssi2dbm;
10411 + phy->dyn_tssi_tbl = 1;
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");
10421 + case BCM43xx_PHYTYPE_B:
10422 + phy->idle_tssi = 0x34;
10423 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10425 + case BCM43xx_PHYTYPE_G:
10426 + phy->idle_tssi = 0x34;
10427 + phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
10435 +int bcm43xx_phy_init(struct bcm43xx_private *bcm)
10437 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10438 + int err = -ENODEV;
10439 + unsigned long flags;
10441 + /* We do not want to be preempted while calibrating
10444 + local_irq_save(flags);
10446 + switch (phy->type) {
10447 + case BCM43xx_PHYTYPE_A:
10448 + if (phy->rev == 2 || phy->rev == 3) {
10449 + bcm43xx_phy_inita(bcm);
10453 + case BCM43xx_PHYTYPE_B:
10454 + switch (phy->rev) {
10456 + bcm43xx_phy_initb2(bcm);
10460 + bcm43xx_phy_initb4(bcm);
10464 + bcm43xx_phy_initb5(bcm);
10468 + bcm43xx_phy_initb6(bcm);
10473 + case BCM43xx_PHYTYPE_G:
10474 + bcm43xx_phy_initg(bcm);
10478 + local_irq_restore(flags);
10480 + printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
10485 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
10487 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10493 + antennadiv = phy->antenna_diversity;
10495 + if (antennadiv == 0xFFFF)
10497 + assert(antennadiv <= 3);
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);
10505 + switch (phy->type) {
10506 + case BCM43xx_PHYTYPE_A:
10507 + case BCM43xx_PHYTYPE_G:
10508 + if (phy->type == BCM43xx_PHYTYPE_A)
10513 + if (antennadiv == 2)
10514 + value = (3/*automatic*/ << 7);
10516 + value = (antennadiv << 7);
10517 + bcm43xx_phy_write(bcm, offset + 1,
10518 + (bcm43xx_phy_read(bcm, offset + 1)
10519 + & 0x7E7F) | value);
10521 + if (antennadiv >= 2) {
10522 + if (antennadiv == 2)
10523 + value = (antennadiv << 7);
10525 + value = (0/*force0*/ << 7);
10526 + bcm43xx_phy_write(bcm, offset + 0x2B,
10527 + (bcm43xx_phy_read(bcm, offset + 0x2B)
10528 + & 0xFEFF) | value);
10531 + if (phy->type == BCM43xx_PHYTYPE_G) {
10532 + if (antennadiv >= 2)
10533 + bcm43xx_phy_write(bcm, 0x048C,
10534 + bcm43xx_phy_read(bcm, 0x048C)
10537 + bcm43xx_phy_write(bcm, 0x048C,
10538 + bcm43xx_phy_read(bcm, 0x048C)
10540 + if (phy->rev >= 2) {
10541 + bcm43xx_phy_write(bcm, 0x0461,
10542 + bcm43xx_phy_read(bcm, 0x0461)
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);
10550 + bcm43xx_phy_write(bcm, 0x0427,
10551 + (bcm43xx_phy_read(bcm, 0x0427)
10552 + & 0x00FF) | 0x0008);
10554 + else if (phy->rev >= 6)
10555 + bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
10557 + if (phy->rev < 3)
10558 + bcm43xx_phy_write(bcm, 0x002B,
10559 + (bcm43xx_phy_read(bcm, 0x002B)
10560 + & 0x00FF) | 0x0024);
10562 + bcm43xx_phy_write(bcm, 0x0061,
10563 + bcm43xx_phy_read(bcm, 0x0061)
10565 + if (phy->rev == 3) {
10566 + bcm43xx_phy_write(bcm, 0x0093, 0x001D);
10567 + bcm43xx_phy_write(bcm, 0x0027, 0x0008);
10569 + bcm43xx_phy_write(bcm, 0x0093, 0x003A);
10570 + bcm43xx_phy_write(bcm, 0x0027,
10571 + (bcm43xx_phy_read(bcm, 0x0027)
10572 + & 0x00FF) | 0x0008);
10577 + case BCM43xx_PHYTYPE_B:
10578 + if (bcm->current_core->rev == 2)
10579 + value = (3/*automatic*/ << 7);
10581 + value = (antennadiv << 7);
10582 + bcm43xx_phy_write(bcm, 0x03E2,
10583 + (bcm43xx_phy_read(bcm, 0x03E2)
10584 + & 0xFE7F) | value);
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);
10598 + phy->antenna_diversity = antennadiv;
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
10606 + Broadcom BCM43xx wireless driver
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>
10614 + Some parts of the code in this file are derived from the ipw2200
10615 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
10634 +#ifndef BCM43xx_PHY_H_
10635 +#define BCM43xx_PHY_H_
10637 +#include <linux/types.h>
10639 +struct bcm43xx_private;
10641 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm);
10642 +#define bcm43xx_phy_lock(bcm, flags) \
10644 + local_irq_save(flags); \
10645 + bcm43xx_raw_phy_lock(bcm); \
10647 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm);
10648 +#define bcm43xx_phy_unlock(bcm, flags) \
10650 + bcm43xx_raw_phy_unlock(bcm); \
10651 + local_irq_restore(flags); \
10654 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset);
10655 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
10657 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm);
10658 +int bcm43xx_phy_init(struct bcm43xx_private *bcm);
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);
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);
10668 +/* Adjust the LocalOscillator to the saved values.
10669 + * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
10671 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed);
10672 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm);
10674 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
10675 + u16 baseband_attenuation);
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
10684 + Broadcom BCM43xx wireless driver
10688 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
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.
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.
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.
10707 +#include "bcm43xx.h"
10708 +#include "bcm43xx_pio.h"
10709 +#include "bcm43xx_main.h"
10710 +#include "bcm43xx_xmit.h"
10712 +#include <linux/delay.h>
10715 +static void tx_start(struct bcm43xx_pioqueue *queue)
10717 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10718 + BCM43xx_PIO_TXCTL_INIT);
10721 +static void tx_octet(struct bcm43xx_pioqueue *queue,
10724 + if (queue->need_workarounds) {
10725 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10727 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10728 + BCM43xx_PIO_TXCTL_WRITEHI);
10730 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10731 + BCM43xx_PIO_TXCTL_WRITEHI);
10732 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10737 +static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr,
10738 + const u8 *packet,
10739 + unsigned int *pos)
10741 + const u8 *source;
10742 + unsigned int i = *pos;
10745 + if (i < sizeof(*txhdr)) {
10746 + source = (const u8 *)txhdr;
10749 + i -= sizeof(*txhdr);
10751 + ret = le16_to_cpu( *((u16 *)(source + i)) );
10757 +static void tx_data(struct bcm43xx_pioqueue *queue,
10758 + struct bcm43xx_txhdr *txhdr,
10759 + const u8 *packet,
10760 + unsigned int octets)
10763 + unsigned int i = 0;
10765 + if (queue->need_workarounds) {
10766 + data = tx_get_next_word(txhdr, packet, &i);
10767 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
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);
10777 + tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]);
10780 +static void tx_complete(struct bcm43xx_pioqueue *queue,
10781 + struct sk_buff *skb)
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);
10790 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10791 + BCM43xx_PIO_TXCTL_COMPLETE);
10795 +static u16 generate_cookie(struct bcm43xx_pioqueue *queue,
10798 + u16 cookie = 0x0000;
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).
10804 + switch (queue->mmio_base) {
10805 + case BCM43xx_MMIO_PIO1_BASE:
10807 + case BCM43xx_MMIO_PIO2_BASE:
10810 + case BCM43xx_MMIO_PIO3_BASE:
10813 + case BCM43xx_MMIO_PIO4_BASE:
10819 + assert(((u16)packetindex & 0xF000) == 0x0000);
10820 + cookie |= (u16)packetindex;
10826 +struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm,
10828 + struct bcm43xx_pio_txpacket **packet)
10830 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
10831 + struct bcm43xx_pioqueue *queue = NULL;
10834 + switch (cookie & 0xF000) {
10836 + queue = pio->queue0;
10839 + queue = pio->queue1;
10842 + queue = pio->queue2;
10845 + queue = pio->queue3;
10850 + packetindex = (cookie & 0x0FFF);
10851 + assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS);
10852 + *packet = &(queue->tx_packets_cache[packetindex]);
10857 +static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue,
10858 + struct sk_buff *skb,
10859 + struct bcm43xx_pio_txpacket *packet)
10861 + struct bcm43xx_txhdr txhdr;
10862 + unsigned int octets;
10864 + assert(skb_shinfo(skb)->nr_frags == 0);
10865 + bcm43xx_generate_txhdr(queue->bcm,
10866 + &txhdr, skb->data, skb->len,
10868 + generate_cookie(queue, pio_txpacket_getindex(packet)),
10872 + octets = skb->len + sizeof(txhdr);
10873 + if (queue->need_workarounds)
10875 + tx_data(queue, &txhdr, (u8 *)skb->data, octets);
10876 + tx_complete(queue, skb);
10879 +static void free_txpacket(struct bcm43xx_pio_txpacket *packet,
10882 + struct bcm43xx_pioqueue *queue = packet->queue;
10885 + dev_kfree_skb_irq(packet->skb);
10887 + dev_kfree_skb(packet->skb);
10888 + list_move(&packet->list, &queue->txfree);
10889 + queue->nr_txfree++;
10892 +static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet)
10894 + struct bcm43xx_pioqueue *queue = packet->queue;
10895 + struct sk_buff *skb = packet->skb;
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);
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
10912 + if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS)
10914 + if (queue->tx_devq_used + octets > queue->tx_devq_size)
10916 + /* Now poke the device. */
10917 + pio_tx_write_fragment(queue, skb, packet);
10919 + /* Account for the packet size.
10920 + * (We must not overflow the device TX queue)
10922 + queue->tx_devq_packets++;
10923 + queue->tx_devq_used += octets;
10925 + /* Transmission started, everything ok, move the
10926 + * packet to the txrunning list.
10928 + list_move_tail(&packet->list, &queue->txrunning);
10933 +static void tx_tasklet(unsigned long d)
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;
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
10950 + err = pio_tx_packet(packet);
10954 + bcm43xx_unlock_mmio(bcm, flags);
10957 +static void setup_txqueues(struct bcm43xx_pioqueue *queue)
10959 + struct bcm43xx_pio_txpacket *packet;
10962 + queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS;
10963 + for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) {
10964 + packet = &(queue->tx_packets_cache[i]);
10966 + packet->queue = queue;
10967 + INIT_LIST_HEAD(&packet->list);
10969 + list_add(&packet->list, &queue->txfree);
10974 +struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm,
10975 + u16 pio_mmio_base)
10977 + struct bcm43xx_pioqueue *queue;
10981 + queue = kzalloc(sizeof(*queue), GFP_KERNEL);
10985 + queue->bcm = bcm;
10986 + queue->mmio_base = pio_mmio_base;
10987 + queue->need_workarounds = (bcm->current_core->rev < 3);
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);
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);
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;
11004 + qsize -= BCM43xx_PIO_TXQADJUST;
11005 + queue->tx_devq_size = qsize;
11007 + setup_txqueues(queue);
11018 +static void cancel_transfers(struct bcm43xx_pioqueue *queue)
11020 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
11022 + ieee80211_netif_oper(queue->bcm->net_dev, NETIF_DETACH);
11023 + assert(queue->bcm->shutting_down);
11024 + tasklet_disable(&queue->txtask);
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);
11032 +static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue)
11037 + cancel_transfers(queue);
11041 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11043 + struct bcm43xx_pio *pio;
11045 + if (!bcm43xx_using_pio(bcm))
11047 + pio = bcm43xx_current_pio(bcm);
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;
11059 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11061 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11062 + struct bcm43xx_pioqueue *queue;
11063 + int err = -ENOMEM;
11065 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE);
11068 + pio->queue0 = queue;
11070 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE);
11072 + goto err_destroy0;
11073 + pio->queue1 = queue;
11075 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE);
11077 + goto err_destroy1;
11078 + pio->queue2 = queue;
11080 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE);
11082 + goto err_destroy2;
11083 + pio->queue3 = queue;
11085 + if (bcm->current_core->rev < 3)
11086 + bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND;
11088 + dprintk(KERN_INFO PFX "PIO initialized\n");
11094 + bcm43xx_destroy_pioqueue(pio->queue2);
11095 + pio->queue2 = NULL;
11097 + bcm43xx_destroy_pioqueue(pio->queue1);
11098 + pio->queue1 = NULL;
11100 + bcm43xx_destroy_pioqueue(pio->queue0);
11101 + pio->queue0 = NULL;
11105 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11106 + struct sk_buff *skb,
11107 + struct ieee80211_tx_control *ctl)
11109 + struct bcm43xx_pioqueue *queue = bcm43xx_current_pio(bcm)->queue1;
11110 + struct bcm43xx_pio_txpacket *packet;
11113 + assert(!queue->tx_suspended);
11114 + assert(!list_empty(&queue->txfree));
11116 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
11117 + if (tmp & BCM43xx_PIO_TXCTL_SUSPEND)
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);
11127 + tasklet_schedule(&queue->txtask);
11132 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11133 + struct bcm43xx_xmitstatus *status)
11135 + struct bcm43xx_pioqueue *queue;
11136 + struct bcm43xx_pio_txpacket *packet;
11138 + queue = parse_cookie(bcm, status->cookie, &packet);
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);
11149 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11150 + struct ieee80211_tx_queue_stats *stats)
11152 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11153 + struct bcm43xx_pioqueue *queue;
11154 + struct ieee80211_tx_queue_stats_data *data;
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;
11163 +static void pio_rx_error(struct bcm43xx_pioqueue *queue,
11164 + int clear_buffers,
11165 + const char *error)
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);
11181 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
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;
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.
11195 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11196 + BCM43xx_PIO_RXCTL_DATAAVAILABLE);
11198 + for (i = 0; i < 10; i++) {
11199 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11200 + if (tmp & BCM43xx_PIO_RXCTL_READY)
11204 + dprintkl(KERN_ERR PFX "PIO RX timed out\n");
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");
11214 + if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) {
11215 + pio_rx_error(queue, 0, "len == 0");
11218 + preamble[0] = cpu_to_le16(len);
11219 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE)
11220 + preamble_readwords = 14 / sizeof(u16);
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?
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");
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;
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);
11248 + bcm43xx_debugfs_log_txstat(queue->bcm, &stat);
11249 + bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat);
11254 + skb = dev_alloc_skb(len);
11255 + if (unlikely(!skb)) {
11256 + pio_rx_error(queue, 1, "OOM");
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;
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;
11270 + skb->data[0x1E] = (tmp & 0xFF00) >> 8;
11272 + bcm43xx_rx(queue->bcm, skb, rxhdr);
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
11278 +#ifndef BCM43xx_PIO_H_
11279 +#define BCM43xx_PIO_H_
11281 +#include "bcm43xx.h"
11283 +#include <linux/interrupt.h>
11284 +#include <linux/list.h>
11285 +#include <linux/skbuff.h>
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
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)
11300 +#define BCM43xx_PIO_RXCTL_DATAAVAILABLE (1 << 0)
11301 +#define BCM43xx_PIO_RXCTL_READY (1 << 1)
11303 +/* PIO constants */
11304 +#define BCM43xx_PIO_MAXTXDEVQPACKETS 31
11305 +#define BCM43xx_PIO_TXQADJUST 80
11307 +/* PIO tuning knobs */
11308 +#define BCM43xx_PIO_MAXTXPACKETS 256
11312 +#ifdef CONFIG_BCM43XX_D80211_PIO
11315 +struct bcm43xx_pioqueue;
11316 +struct bcm43xx_xmitstatus;
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;
11325 +#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
11327 +struct bcm43xx_pioqueue {
11328 + struct bcm43xx_private *bcm;
11331 + u8 tx_suspended:1,
11332 + need_workarounds:1; /* Workarounds needed for core.rev < 3 */
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.
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.
11348 + struct list_head txqueue;
11349 + /* Packets on the txrunning queue are completely
11350 + * posted to the device. We are waiting for the txstatus.
11352 + struct list_head txrunning;
11353 + /* Total number or packets sent.
11354 + * (This counter can obviously wrap).
11356 + unsigned int nr_tx_packets;
11357 + struct tasklet_struct txtask;
11358 + struct bcm43xx_pio_txpacket tx_packets_cache[BCM43xx_PIO_MAXTXPACKETS];
11362 +u16 bcm43xx_pio_read(struct bcm43xx_pioqueue *queue,
11365 + return bcm43xx_read16(queue->bcm, queue->mmio_base + offset);
11369 +void bcm43xx_pio_write(struct bcm43xx_pioqueue *queue,
11370 + u16 offset, u16 value)
11372 + bcm43xx_write16(queue->bcm, queue->mmio_base + offset, value);
11376 +int bcm43xx_pio_init(struct bcm43xx_private *bcm);
11377 +void bcm43xx_pio_free(struct bcm43xx_private *bcm);
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);
11387 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue);
11389 +#else /* CONFIG_BCM43XX_D80211_PIO */
11392 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11397 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11401 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11402 + struct sk_buff *skb,
11403 + struct ieee80211_tx_control *ctl)
11408 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11409 + struct bcm43xx_xmitstatus *status)
11413 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11414 + struct ieee80211_tx_queue_stats *stats)
11418 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
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
11430 + Broadcom BCM43xx wireless driver
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>
11438 + Some parts of the code in this file are derived from the ipw2200
11439 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
11458 +#include <linux/delay.h>
11460 +#include "bcm43xx.h"
11461 +#include "bcm43xx_power.h"
11462 +#include "bcm43xx_main.h"
11465 +/* Get max/min slowclock frequency
11466 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11468 +static int bcm43xx_pctl_clockfreqlimit(struct bcm43xx_private *bcm,
11476 + struct bcm43xx_coreinfo *old_core;
11478 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11480 + old_core = bcm->current_core;
11481 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11485 + if (bcm->current_core->rev < 6) {
11486 + if ((bcm->bustype == BCM43xx_BUSTYPE_PCMCIA) ||
11487 + (bcm->bustype == BCM43xx_BUSTYPE_SB)) {
11491 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &tmp);
11493 + printk(KERN_ERR PFX "clockfreqlimit pcicfg read failure\n");
11494 + goto out_switchback;
11496 + if (tmp & 0x10) {
11506 + } else if (bcm->current_core->rev < 10) {
11507 + selection = (tmp & 0x07);
11509 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11510 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11514 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SYSCLKCTL);
11515 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11519 + switch (selection) {
11530 + limit = 20200000;
11532 + limit = 19800000;
11537 + limit = 34000000;
11539 + limit = 25000000;
11544 + limit /= divisor;
11547 + err = bcm43xx_switch_core(bcm, old_core);
11548 + assert(err == 0);
11554 +/* init power control
11555 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11557 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm)
11559 + int err, maxfreq;
11560 + struct bcm43xx_coreinfo *old_core;
11562 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11564 + old_core = bcm->current_core;
11565 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11566 + if (err == -ENODEV)
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);
11577 + err = bcm43xx_switch_core(bcm, old_core);
11578 + assert(err == 0);
11584 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm)
11588 + u32 pll_on_delay;
11589 + struct bcm43xx_coreinfo *old_core;
11592 + if (bcm->bustype != BCM43xx_BUSTYPE_PCI)
11594 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11596 + old_core = bcm->current_core;
11597 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11598 + if (err == -ENODEV)
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;
11605 + err = bcm43xx_switch_core(bcm, old_core);
11606 + assert(err == 0);
11612 +/* set the powercontrol clock
11613 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11615 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode)
11618 + struct bcm43xx_coreinfo *old_core;
11621 + old_core = bcm->current_core;
11622 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11623 + if (err == -ENODEV)
11628 + if (bcm->core_chipcommon.rev < 6) {
11629 + if (mode == BCM43xx_PCTL_CLK_FAST) {
11630 + err = bcm43xx_pctl_set_crystal(bcm, 1);
11635 + if ((bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL) &&
11636 + (bcm->core_chipcommon.rev < 10)) {
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);
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);
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);
11658 + err = bcm43xx_switch_core(bcm, old_core);
11659 + assert(err == 0);
11665 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on)
11668 + u32 in, out, outenable;
11670 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_IN, &in);
11673 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &out);
11676 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUTENABLE, &outenable);
11680 + outenable |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11686 + out |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11688 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11691 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11696 + out &= ~BCM43xx_PCTL_PLL_POWERDOWN;
11697 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11702 + if (bcm->current_core->rev < 5)
11704 + if (bcm->sprom.boardflags & BCM43xx_BFL_XTAL_NOSLOW)
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);
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))))
11716 + * err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11721 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
11724 + out &= ~BCM43xx_PCTL_XTAL_POWERUP;
11725 + out |= BCM43xx_PCTL_PLL_POWERDOWN;
11726 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11729 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11738 + printk(KERN_ERR PFX "Error: pctl_set_clock() could not access PCI config space!\n");
11743 +/* Set the PowerSavingControlBits.
11745 + * 0 => unset the bit
11746 + * 1 => set the bit
11747 + * -1 => calculate the bit
11749 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11750 + int bit25, int bit26)
11755 +//FIXME: Force 25 to off and 26 to on for now:
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
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
11768 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11770 + status |= BCM43xx_SBF_PS1;
11772 + status &= ~BCM43xx_SBF_PS1;
11774 + status |= BCM43xx_SBF_PS2;
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)
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
11792 + Broadcom BCM43xx wireless driver
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>
11800 + Some parts of the code in this file are derived from the ipw2200
11801 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
11820 +#ifndef BCM43xx_POWER_H_
11821 +#define BCM43xx_POWER_H_
11823 +#include <linux/types.h>
11826 +struct bcm43xx_private;
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);
11833 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11834 + int bit25, int bit26);
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
11843 + Broadcom BCM43xx wireless driver
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>
11851 + Some parts of the code in this file are derived from the ipw2200
11852 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
11871 +#include <linux/delay.h>
11873 +#include "bcm43xx.h"
11874 +#include "bcm43xx_main.h"
11875 +#include "bcm43xx_phy.h"
11876 +#include "bcm43xx_radio.h"
11877 +#include "bcm43xx_ilt.h"
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,
11888 +/* Reverse the bits of a 4bit value.
11889 + * Example: 1101 is flipped 1011
11891 +static u16 flip_4bit(u16 value)
11893 + u16 flipped = 0x0000;
11895 + assert((value & ~0x000F) == 0x0000);
11897 + flipped |= (value & 0x0001) << 3;
11898 + flipped |= (value & 0x0002) << 1;
11899 + flipped |= (value & 0x0004) >> 1;
11900 + flipped |= (value & 0x0008) >> 3;
11905 +/* Get the freq, as it has to be written to the device. */
11907 +u16 channel2freq_bg(u8 channel)
11909 + /* Frequencies are given as frequencies_bg[index] + 2.4GHz
11910 + * Starting with channel 1
11912 + static const u16 frequencies_bg[14] = {
11919 + assert(channel >= 1 && channel <= 14);
11921 + return frequencies_bg[channel - 1];
11924 +/* Get the freq, as it has to be written to the device. */
11926 +u16 channel2freq_a(u8 channel)
11928 + assert(channel <= 200);
11930 + return (5000 + 5 * channel);
11933 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm)
11937 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11938 + status |= BCM43xx_SBF_RADIOREG_LOCK;
11939 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
11944 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm)
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);
11955 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset)
11957 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
11958 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
11960 + switch (phy->type) {
11961 + case BCM43xx_PHYTYPE_A:
11962 + offset |= 0x0040;
11964 + case BCM43xx_PHYTYPE_B:
11965 + if (radio->version == 0x2053) {
11966 + if (offset < 0x70)
11968 + else if (offset < 0x80)
11970 + } else if (radio->version == 0x2050) {
11975 + case BCM43xx_PHYTYPE_G:
11980 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
11981 + return bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
11984 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val)
11986 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
11988 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW, val);
11991 +static void bcm43xx_set_all_gains(struct bcm43xx_private *bcm,
11992 + s16 first, s16 second, s16 third)
11994 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
11996 + u16 start = 0x08, end = 0x18;
11997 + u16 offset = 0x0400;
12000 + if (phy->rev <= 1) {
12006 + for (i = 0; i < 4; i++)
12007 + bcm43xx_ilt_write(bcm, offset + i, first);
12009 + for (i = start; i < end; i++)
12010 + bcm43xx_ilt_write(bcm, offset + i, second);
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);
12021 + bcm43xx_dummy_transmission(bcm);
12024 +static void bcm43xx_set_original_gains(struct bcm43xx_private *bcm)
12026 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12028 + u16 offset = 0x0400;
12029 + u16 start = 0x0008, end = 0x0018;
12031 + if (phy->rev <= 1) {
12037 + for (i = 0; i < 4; i++) {
12038 + tmp = (i & 0xFFFC);
12039 + tmp |= (i & 0x0001) << 1;
12040 + tmp |= (i & 0x0002) >> 1;
12042 + bcm43xx_ilt_write(bcm, offset + i, tmp);
12045 + for (i = start; i < end; i++)
12046 + bcm43xx_ilt_write(bcm, offset + i, i - start);
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);
12057 +/* Synthetic PU workaround */
12058 +static void bcm43xx_synth_pu_workaround(struct bcm43xx_private *bcm, u8 channel)
12060 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12062 + if (radio->version != 0x2050 || radio->revision >= 6) {
12063 + /* We do not need the workaround. */
12067 + if (channel <= 10) {
12068 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12069 + channel2freq_bg(channel + 4));
12071 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12072 + channel2freq_bg(1));
12075 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12076 + channel2freq_bg(channel));
12079 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel)
12081 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12083 + u16 saved, rssi, temp;
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;
12092 + rssi = saved & 0x3F;
12093 + /* clamp temp to signed 5bit */
12096 + for (i = 0;i < 100; i++) {
12097 + temp = (bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x3F;
12105 + bcm43xx_phy_write(bcm, 0x0403, saved);
12110 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm)
12112 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12113 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12115 + unsigned int channel = radio->channel;
12116 + unsigned int i, j, start, end;
12117 + unsigned long phylock_flags;
12119 + if (!((phy->type == BCM43xx_PHYTYPE_G) && (phy->rev > 0)))
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);
12130 + start = (channel - 5 > 0) ? channel - 5 : 1;
12131 + end = (channel + 5 < 14) ? channel + 5 : 13;
12133 + for (i = start; i <= end; i++) {
12134 + if (abs(channel - i) > 2)
12135 + ret[i-1] = bcm43xx_radio_aci_detect(bcm, i);
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++) {
12148 + end = (i + 5 < 13) ? i + 5 : 13;
12149 + for (j = i; j < end; j++)
12152 + bcm43xx_radio_unlock(bcm);
12153 + bcm43xx_phy_unlock(bcm, phylock_flags);
12155 + return ret[channel - 1];
12158 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12159 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val)
12161 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12163 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_DATA, (u16)val);
12166 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12167 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset)
12171 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12172 + val = bcm43xx_phy_read(bcm, BCM43xx_PHY_NRSSILT_DATA);
12177 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12178 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val)
12183 + for (i = 0; i < 64; i++) {
12184 + tmp = bcm43xx_nrssi_hw_read(bcm, i);
12186 + tmp = limit_value(tmp, -32, 31);
12187 + bcm43xx_nrssi_hw_write(bcm, i, tmp);
12191 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12192 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm)
12194 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12198 + delta = 0x1F - radio->nrssi[0];
12199 + for (i = 0; i < 64; i++) {
12200 + tmp = (i - delta) * radio->nrssislope;
12203 + tmp = limit_value(tmp, 0, 0x3F);
12204 + radio->nrssi_lt[i] = tmp;
12208 +static void bcm43xx_calc_nrssi_offset(struct bcm43xx_private *bcm)
12210 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12211 + u16 backup[20] = { 0 };
12214 + u16 saved = 0xFFFF;
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);
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);
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);
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);
12268 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12269 + if (v47F >= 0x20)
12271 + if (v47F == 31) {
12272 + for (i = 7; i >= 4; i--) {
12273 + bcm43xx_radio_write16(bcm, 0x007B, i);
12275 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12276 + if (v47F >= 0x20)
12278 + if (v47F < 31 && saved == 0xFFFF)
12281 + if (saved == 0xFFFF)
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);
12304 + bcm43xx_phy_write(bcm, 0x000A,
12305 + bcm43xx_phy_read(bcm, 0x000A)
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)
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);
12322 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12323 + if (v47F >= 0x20)
12325 + if (v47F == -32) {
12326 + for (i = 0; i < 4; i++) {
12327 + bcm43xx_radio_write16(bcm, 0x007B, i);
12329 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12330 + if (v47F >= 0x20)
12332 + if (v47F > -31 && saved == 0xFFFF)
12335 + if (saved == 0xFFFF)
12340 + bcm43xx_radio_write16(bcm, 0x007B, saved);
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]);
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]);
12368 + bcm43xx_phy_write(bcm, 0x0001, backup[0]);
12369 + bcm43xx_phy_write(bcm, 0x0812, backup[2]);
12370 + bcm43xx_phy_write(bcm, 0x0811, backup[1]);
12373 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm)
12375 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12376 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12377 + u16 backup[18] = { 0 };
12379 + s16 nrssi0, nrssi1;
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);
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);
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);
12418 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12419 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) & 0x2000);
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);
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]);
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]);
12449 + if (nrssi0 == nrssi1)
12450 + radio->nrssislope = 0x00010000;
12452 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12454 + if (nrssi0 <= -4) {
12455 + radio->nrssi[0] = nrssi0;
12456 + radio->nrssi[1] = nrssi1;
12459 + case BCM43xx_PHYTYPE_G:
12460 + if (radio->revision >= 9)
12462 + if (radio->revision == 8)
12463 + bcm43xx_calc_nrssi_offset(bcm);
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)
12497 + bcm43xx_phy_write(bcm, 0x0801,
12498 + bcm43xx_phy_read(bcm, 0x0801)
12502 + bcm43xx_phy_write(bcm, 0x0801,
12503 + bcm43xx_phy_read(bcm, 0x0801)
12507 + bcm43xx_phy_write(bcm, 0x0060,
12508 + bcm43xx_phy_read(bcm, 0x0060)
12510 + bcm43xx_phy_write(bcm, 0x0014,
12511 + bcm43xx_phy_read(bcm, 0x0014)
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);
12525 + bcm43xx_radio_write16(bcm, 0x007A,
12526 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12529 + nrssi0 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12530 + if (nrssi0 >= 0x0020)
12531 + nrssi0 -= 0x0040;
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);
12541 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12542 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
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);
12554 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12555 + if (radio->revision == 8) {
12556 + bcm43xx_radio_write16(bcm, 0x0043, 0x001F);
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);
12563 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12564 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12565 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
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;
12573 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12574 + if (nrssi0 >= -4) {
12575 + radio->nrssi[0] = nrssi1;
12576 + radio->nrssi[1] = nrssi0;
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]);
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);
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]);
12613 + bcm43xx_nrssi_mem_update(bcm);
12614 + bcm43xx_calc_nrssi_threshold(bcm);
12621 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm)
12623 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12624 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12630 + switch (phy->type) {
12631 + case BCM43xx_PHYTYPE_B: {
12632 + if (radio->version != 0x2050)
12634 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI))
12637 + if (radio->revision >= 6) {
12638 + threshold = (radio->nrssi[1] - radio->nrssi[0]) * 32;
12639 + threshold += 20 * (radio->nrssi[0] + 1);
12642 + threshold = radio->nrssi[1] - 5;
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);
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);
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)
12667 + bcm43xx_phy_write(bcm, 0x048A,
12668 + (bcm43xx_phy_read(bcm, 0x048A)
12669 + & 0xF000) | 0x09EB);
12671 + bcm43xx_phy_write(bcm, 0x048A,
12672 + (bcm43xx_phy_read(bcm, 0x048A)
12673 + & 0xF000) | 0x0AED);
12676 + if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
12679 + } else if (!radio->aci_wlan_automatic && radio->aci_enable) {
12687 + a = a * (radio->nrssi[1] - radio->nrssi[0]);
12688 + a += (radio->nrssi[0] << 6);
12694 + a = limit_value(a, -31, 31);
12696 + b = b * (radio->nrssi[1] - radio->nrssi[0]);
12697 + b += (radio->nrssi[0] << 6);
12703 + b = limit_value(b, -31, 31);
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);
12716 +/* Stack implementation to save/restore values from the
12717 + * interference mitigation code.
12718 + * It is save to restore values in random order.
12720 +static void _stack_save(u32 *_stackptr, size_t *stackidx,
12721 + u8 id, u16 offset, u16 value)
12723 + u32 *stackptr = &(_stackptr[*stackidx]);
12725 + assert((offset & 0xF000) == 0x0000);
12726 + assert((id & 0xF0) == 0x00);
12727 + *stackptr = offset;
12728 + *stackptr |= ((u32)id) << 12;
12729 + *stackptr |= ((u32)value) << 16;
12731 + assert(*stackidx < BCM43xx_INTERFSTACK_SIZE);
12734 +static u16 _stack_restore(u32 *stackptr,
12735 + u8 id, u16 offset)
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)
12744 + if (((*stackptr & 0x0000F000) >> 12) != id)
12746 + return ((*stackptr & 0xFFFF0000) >> 16);
12753 +#define phy_stacksave(offset) \
12755 + _stack_save(stack, &stackidx, 0x1, (offset), \
12756 + bcm43xx_phy_read(bcm, (offset))); \
12758 +#define phy_stackrestore(offset) \
12760 + bcm43xx_phy_write(bcm, (offset), \
12761 + _stack_restore(stack, 0x1, \
12764 +#define radio_stacksave(offset) \
12766 + _stack_save(stack, &stackidx, 0x2, (offset), \
12767 + bcm43xx_radio_read16(bcm, (offset))); \
12769 +#define radio_stackrestore(offset) \
12771 + bcm43xx_radio_write16(bcm, (offset), \
12772 + _stack_restore(stack, 0x2, \
12775 +#define ilt_stacksave(offset) \
12777 + _stack_save(stack, &stackidx, 0x3, (offset), \
12778 + bcm43xx_ilt_read(bcm, (offset))); \
12780 +#define ilt_stackrestore(offset) \
12782 + bcm43xx_ilt_write(bcm, (offset), \
12783 + _stack_restore(stack, 0x3, \
12788 +bcm43xx_radio_interference_mitigation_enable(struct bcm43xx_private *bcm,
12791 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12792 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12793 + u16 tmp, flipped;
12795 + size_t stackidx = 0;
12796 + u32 *stack = radio->interfstack;
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);
12807 + radio_stacksave(0x0078);
12808 + tmp = (bcm43xx_radio_read16(bcm, 0x0078) & 0x001E);
12809 + flipped = flip_4bit(tmp);
12810 + if (flipped < 10 && flipped >= 8)
12812 + else if (flipped >= 10)
12814 + flipped = flip_4bit(flipped);
12815 + flipped = (flipped << 1) | 0x0020;
12816 + bcm43xx_radio_write16(bcm, 0x0078, flipped);
12818 + bcm43xx_calc_nrssi_threshold(bcm);
12820 + phy_stacksave(0x0406);
12821 + bcm43xx_phy_write(bcm, 0x0406, 0x7E28);
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);
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);
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);
12857 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
12858 + if (bcm43xx_phy_read(bcm, 0x0033) & 0x0800)
12861 + radio->aci_enable = 1;
12863 + phy_stacksave(BCM43xx_PHY_RADIO_BITFIELD);
12864 + phy_stacksave(BCM43xx_PHY_G_CRS);
12865 + if (phy->rev < 2) {
12866 + phy_stacksave(0x0406);
12868 + phy_stacksave(0x04C0);
12869 + phy_stacksave(0x04C1);
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);
12895 + phy_stacksave(0x042B);
12896 + phy_stacksave(0x048C);
12898 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
12899 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
12901 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12902 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS)
12903 + & 0xFFFC) | 0x0002);
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);
12912 + bcm43xx_phy_write(bcm, 0x04A0,
12913 + (bcm43xx_phy_read(bcm, 0x04A0)
12914 + & 0xFFC0) | 0x001A);
12915 + bcm43xx_phy_write(bcm, 0x04A7, 0x000D);
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);
12923 + bcm43xx_phy_write(bcm, 0x04C0, 0x00C1);
12924 + bcm43xx_phy_write(bcm, 0x04C1, 0x0059);
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);
12967 + if (phy->rev >= 3) {
12968 + bcm43xx_phy_write(bcm, 0x048A,
12969 + bcm43xx_phy_read(bcm, 0x048A)
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);
12981 + bcm43xx_phy_write(bcm, 0x048A,
12982 + bcm43xx_phy_read(bcm, 0x048A)
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)) {
12991 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
12992 + BCM43xx_UCODEFLAGS_OFFSET,
12996 + if (phy->rev >= 2) {
12997 + bcm43xx_phy_write(bcm, 0x042B,
12998 + bcm43xx_phy_read(bcm, 0x042B)
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)
13018 + bcm43xx_calc_nrssi_slope(bcm);
13026 +bcm43xx_radio_interference_mitigation_disable(struct bcm43xx_private *bcm,
13029 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13030 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13032 + u32 *stack = radio->interfstack;
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);
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)
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);
13067 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13068 + if (!(bcm43xx_phy_read(bcm, 0x0033) & 0x0800))
13071 + radio->aci_enable = 0;
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);
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);
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) {
13110 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13111 + BCM43xx_UCODEFLAGS_OFFSET,
13114 + bcm43xx_calc_nrssi_slope(bcm);
13121 +#undef phy_stacksave
13122 +#undef phy_stackrestore
13123 +#undef radio_stacksave
13124 +#undef radio_stackrestore
13125 +#undef ilt_stacksave
13126 +#undef ilt_stackrestore
13128 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm,
13131 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13132 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13135 + if ((phy->type != BCM43xx_PHYTYPE_G) ||
13136 + (phy->rev == 0) ||
13137 + (!phy->connected))
13140 + radio->aci_wlan_automatic = 0;
13142 + case BCM43xx_RADIO_INTERFMODE_AUTOWLAN:
13143 + radio->aci_wlan_automatic = 1;
13144 + if (radio->aci_enable)
13145 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
13147 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
13149 + case BCM43xx_RADIO_INTERFMODE_NONE:
13150 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13151 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13157 + currentmode = radio->interfmode;
13158 + if (currentmode == mode)
13160 + if (currentmode != BCM43xx_RADIO_INTERFMODE_NONE)
13161 + bcm43xx_radio_interference_mitigation_disable(bcm, currentmode);
13163 + if (mode == BCM43xx_RADIO_INTERFMODE_NONE) {
13164 + radio->aci_enable = 0;
13165 + radio->aci_hw_rssi = 0;
13167 + bcm43xx_radio_interference_mitigation_enable(bcm, mode);
13168 + radio->interfmode = mode;
13173 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm)
13175 + u16 reg, index, ret;
13177 + reg = bcm43xx_radio_read16(bcm, 0x0060);
13178 + index = (reg & 0x001E) >> 1;
13179 + ret = rcc_table[index] << 1;
13180 + ret |= (reg & 0x0001);
13186 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
13188 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13189 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13190 + u16 backup[19] = { 0 };
13193 + u32 tmp1 = 0, tmp2 = 0;
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);
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);
13226 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13227 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) | 0x8000));
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);
13235 + // Initialization
13236 + if (phy->version == 0) {
13237 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
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));
13245 + ret = bcm43xx_radio_calibrationvalue(bcm);
13247 + if (phy->type == BCM43xx_PHYTYPE_B)
13248 + bcm43xx_radio_write16(bcm, 0x0078, 0x0003);
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);
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);
13270 + if (phy->connected)
13271 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13272 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13274 + if (phy->connected)
13275 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13276 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
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);
13288 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
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);
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);
13302 + if (phy->connected)
13303 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13304 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13306 + if (phy->connected)
13307 + bcm43xx_phy_write(bcm, 0x0812, 0x30B3); /* 0x30B3 is not a typo */
13308 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
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);
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]);
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]);
13351 + ret = backup[13];
13356 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm)
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);
13377 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020) | 0x0010);
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);
13390 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_A, 0);
13391 + assert(err == 0);
13396 +u16 freq_r3A_value(u16 frequency)
13400 + if (frequency < 5091)
13402 + else if (frequency < 5321)
13404 + else if (frequency < 5806)
13412 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm)
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);
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);
13429 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
13431 + int synthetic_pu_workaround)
13433 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13437 + if ((radio->manufact == 0x17F) &&
13438 + (radio->version == 0x2060) &&
13439 + (radio->revision == 1)) {
13440 + if (channel > 200)
13442 + freq = channel2freq_a(channel);
13444 + r8 = bcm43xx_radio_read16(bcm, 0x0008);
13445 + bcm43xx_write16(bcm, 0x03F0, freq);
13446 + bcm43xx_radio_write16(bcm, 0x0008, r8);
13448 + TODO();//TODO: write max channel TX power? to Radio 0x2D
13449 + tmp = bcm43xx_radio_read16(bcm, 0x002E);
13451 + TODO();//TODO: OR tmp with the Power out estimation for this channel?
13452 + bcm43xx_radio_write16(bcm, 0x002E, tmp);
13454 + if (freq >= 4920 && freq <= 5500) {
13456 + * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
13457 + * = (freq * 0.025862069
13459 + r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
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?
13494 + if ((channel < 1) || (channel > 14))
13497 + if (synthetic_pu_workaround)
13498 + bcm43xx_synth_pu_workaround(bcm, channel);
13500 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
13501 + channel2freq_bg(channel));
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)
13511 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13512 + BCM43xx_UCODEFLAGS_OFFSET,
13513 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13514 + BCM43xx_UCODEFLAGS_OFFSET)
13517 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13518 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13521 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13522 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13527 + radio->channel = channel;
13528 + //XXX: Using the longer of 2 timeouts (8000 vs 2000 usecs). Specs states
13529 + // that 2000 usecs might suffice.
13535 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val)
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);
13548 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
13549 +static u16 bcm43xx_get_txgain_base_band(u16 txpower)
13553 + assert(txpower <= 63);
13555 + if (txpower >= 54)
13557 + else if (txpower >= 49)
13559 + else if (txpower >= 44)
13567 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
13568 +static u16 bcm43xx_get_txgain_freq_power_amp(u16 txpower)
13572 + assert(txpower <= 63);
13574 + if (txpower >= 32)
13576 + else if (txpower >= 25)
13578 + else if (txpower >= 20)
13580 + else if (txpower >= 12)
13588 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
13589 +static u16 bcm43xx_get_txgain_dac(u16 txpower)
13593 + assert(txpower <= 63);
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;
13615 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower)
13617 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13618 + u16 pamp, base, dac, ilt;
13620 + txpower = limit_value(txpower, 0, 63);
13622 + pamp = bcm43xx_get_txgain_freq_power_amp(txpower);
13625 + bcm43xx_phy_write(bcm, 0x0019, pamp);
13627 + base = bcm43xx_get_txgain_base_band(txpower);
13629 + bcm43xx_phy_write(bcm, 0x0017, base | 0x0020);
13631 + ilt = bcm43xx_ilt_read(bcm, 0x3001);
13634 + dac = bcm43xx_get_txgain_dac(txpower);
13638 + bcm43xx_ilt_write(bcm, 0x3001, dac);
13640 + radio->txpwr_offset = txpower;
13643 + //TODO: FuncPlaceholder (Adjust BB loft cancel)
13646 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
13647 + u16 baseband_attenuation, u16 radio_attenuation,
13650 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13651 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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;
13663 + assert(/*baseband_attenuation >= 0 &&*/ baseband_attenuation <= 11);
13664 + if (radio->revision < 6)
13665 + assert(/*radio_attenuation >= 0 &&*/ radio_attenuation <= 9);
13667 + assert(/* radio_attenuation >= 0 &&*/ radio_attenuation <= 31);
13668 + assert(/*txpower >= 0 &&*/ txpower <= 7);
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));
13678 + //FIXME: The spec is very weird and unclear here.
13679 + if (phy->type == BCM43xx_PHYTYPE_G)
13680 + bcm43xx_phy_lo_adjust(bcm, 0);
13683 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm)
13685 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13687 + if (radio->version == 0x2050 && radio->revision < 6)
13692 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm)
13694 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13695 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13696 + u16 att = 0xFFFF;
13698 + if (phy->type == BCM43xx_PHYTYPE_A)
13701 + switch (radio->version) {
13703 + switch (radio->revision) {
13710 + switch (radio->revision) {
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)
13720 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13721 + bcm->board_type == 0x416)
13726 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13727 + bcm->board_type == 0x421 &&
13728 + bcm->board_revision >= 30)
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)
13740 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13741 + bcm->board_type == 0x416)
13743 + else if (bcm->chip_id == 0x4320)
13769 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13770 + bcm->board_type == 0x421) {
13771 + if (bcm->board_revision < 0x43)
13773 + else if (bcm->board_revision < 0x51)
13776 + if (att == 0xFFFF)
13782 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm)
13784 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13786 + if (radio->version != 0x2050)
13788 + if (radio->revision == 1)
13790 + if (radio->revision < 6)
13792 + if (radio->revision == 8)
13797 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
13799 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13800 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13803 + if (radio->enabled)
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);
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);
13825 + radio->enabled = 1;
13826 + dprintk(KERN_INFO PFX "Radio turned on\n");
13829 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
13831 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13832 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
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);
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);
13844 + bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
13845 + radio->enabled = 0;
13846 + dprintk(KERN_INFO PFX "Radio turned off\n");
13849 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
13851 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
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);
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);
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
13873 + Broadcom BCM43xx wireless driver
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>
13881 + Some parts of the code in this file are derived from the ipw2200
13882 + driver Copyright(c) 2003 - 2004 Intel Corporation.
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.
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.
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.
13901 +#ifndef BCM43xx_RADIO_H_
13902 +#define BCM43xx_RADIO_H_
13904 +#include "bcm43xx.h"
13907 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_A 36
13908 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_BG 6
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.
13917 +#define BCM43xx_RADIO_TXANTENNA_LASTPLCP 3
13918 +#define BCM43xx_RADIO_TXANTENNA_DEFAULT BCM43xx_RADIO_TXANTENNA_LASTPLCP
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
13926 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm);
13927 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm);
13929 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset);
13930 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val);
13932 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm);
13933 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
13935 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
13936 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
13938 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
13939 + int synthetic_pu_workaround);
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,
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);
13950 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val);
13952 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm);
13954 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel);
13955 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm);
13957 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm, int mode);
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);
13966 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm);
13967 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm);
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
13976 + Broadcom BCM43xx wireless driver
13978 + SYSFS support routines
13980 + Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
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.
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.
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.
13999 +#include "bcm43xx_sysfs.h"
14000 +#include "bcm43xx.h"
14001 +#include "bcm43xx_main.h"
14002 +#include "bcm43xx_radio.h"
14004 +#include <linux/capability.h>
14007 +#define GENERIC_FILESIZE 64
14010 +static int get_integer(const char *buf, size_t count)
14012 + char tmp[10 + 1] = { 0 };
14013 + int ret = -EINVAL;
14017 + count = min(count, (size_t)10);
14018 + memcpy(tmp, buf, count);
14019 + ret = simple_strtol(tmp, NULL, 10);
14024 +static int get_boolean(const char *buf, size_t count)
14026 + if (count != 0) {
14027 + if (buf[0] == '1')
14029 + if (buf[0] == '0')
14031 + if (count >= 4 && memcmp(buf, "true", 4) == 0)
14033 + if (count >= 5 && memcmp(buf, "false", 5) == 0)
14035 + if (count >= 3 && memcmp(buf, "yes", 3) == 0)
14037 + if (count >= 2 && memcmp(buf, "no", 2) == 0)
14039 + if (count >= 2 && memcmp(buf, "on", 2) == 0)
14041 + if (count >= 3 && memcmp(buf, "off", 3) == 0)
14047 +static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
14048 + struct device_attribute *attr,
14051 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14053 + unsigned long flags;
14056 + if (!capable(CAP_NET_ADMIN))
14059 + assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
14060 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14064 + bcm43xx_lock_mmio(bcm, flags);
14065 + assert(bcm->initialized);
14066 + err = bcm43xx_sprom_read(bcm, sprom);
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;
14073 + bcm43xx_unlock_mmio(bcm, flags);
14076 + return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
14079 +static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
14080 + struct device_attribute *attr,
14081 + const char *buf, size_t count)
14083 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14085 + unsigned long flags;
14088 + if (!capable(CAP_NET_ADMIN))
14091 + if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
14093 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
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;
14101 + bcm43xx_lock_mmio(bcm, flags);
14102 + assert(bcm->initialized);
14103 + err = bcm43xx_sprom_write(bcm, sprom);
14104 + bcm43xx_unlock_mmio(bcm, flags);
14107 + return err ? err : count;
14111 +static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
14112 + struct device_attribute *attr,
14115 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14116 + unsigned long flags;
14118 + ssize_t count = 0;
14120 + if (!capable(CAP_NET_ADMIN))
14123 + bcm43xx_lock(bcm, flags);
14124 + assert(bcm->initialized);
14126 + switch (bcm43xx_current_radio(bcm)->interfmode) {
14127 + case BCM43xx_RADIO_INTERFMODE_NONE:
14128 + count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
14130 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
14131 + count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
14133 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
14134 + count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
14141 + bcm43xx_unlock(bcm, flags);
14143 + return err ? err : count;
14147 +static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
14148 + struct device_attribute *attr,
14149 + const char *buf, size_t count)
14151 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14152 + unsigned long flags;
14156 + if (!capable(CAP_NET_ADMIN))
14159 + mode = get_integer(buf, count);
14162 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
14165 + mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
14168 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
14171 + mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
14177 + bcm43xx_lock_mmio(bcm, flags);
14178 + assert(bcm->initialized);
14180 + err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
14182 + printk(KERN_ERR PFX "Interference Mitigation not "
14183 + "supported by device\n");
14186 + bcm43xx_unlock_mmio(bcm, flags);
14188 + return err ? err : count;
14191 +static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
14192 + struct device_attribute *attr,
14195 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14196 + unsigned long flags;
14200 + if (!capable(CAP_NET_ADMIN))
14203 + bcm43xx_lock(bcm, flags);
14204 + assert(bcm->initialized);
14206 + if (bcm->short_preamble)
14207 + count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
14209 + count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
14212 + bcm43xx_unlock(bcm, flags);
14214 + return err ? err : count;
14217 +static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
14218 + struct device_attribute *attr,
14219 + const char *buf, size_t count)
14221 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14222 + unsigned long flags;
14226 + if (!capable(CAP_NET_ADMIN))
14229 + value = get_boolean(buf, count);
14232 + bcm43xx_lock(bcm, flags);
14233 + assert(bcm->initialized);
14235 + bcm->short_preamble = !!value;
14238 + bcm43xx_unlock(bcm, flags);
14240 + return err ? err : count;
14243 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
14245 + struct device *dev = &bcm->pci_dev->dev;
14246 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14249 + assert(bcm->initialized);
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);
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);
14267 + goto err_remove_sprom;
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);
14276 + goto err_remove_interfmode;
14280 +err_remove_interfmode:
14281 + device_remove_file(dev, &sysfs->attr_interfmode);
14283 + device_remove_file(dev, &sysfs->attr_sprom);
14287 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
14289 + struct device *dev = &bcm->pci_dev->dev;
14290 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14292 + device_remove_file(dev, &sysfs->attr_preamble);
14293 + device_remove_file(dev, &sysfs->attr_interfmode);
14294 + device_remove_file(dev, &sysfs->attr_sprom);
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
14300 +#ifndef BCM43xx_SYSFS_H_
14301 +#define BCM43xx_SYSFS_H_
14303 +#include <linux/device.h>
14306 +struct bcm43xx_sysfs {
14307 + struct device_attribute attr_sprom;
14308 + struct device_attribute attr_interfmode;
14309 + struct device_attribute attr_preamble;
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); \
14319 +struct bcm43xx_private;
14321 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
14322 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
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
14331 + Broadcom BCM43xx wireless driver
14333 + Transmission (TX/RX) related functions.
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>
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.
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.
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.
14358 +#include "bcm43xx_xmit.h"
14361 +/* Extract the bitrate out of a CCK PLCP header. */
14362 +static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr4 *plcp)
14364 + switch (plcp->raw[0]) {
14366 + return BCM43xx_CCK_RATE_1MB;
14368 + return BCM43xx_CCK_RATE_2MB;
14370 + return BCM43xx_CCK_RATE_5MB;
14372 + return BCM43xx_CCK_RATE_11MB;
14378 +/* Extract the bitrate out of an OFDM PLCP header. */
14379 +static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr4 *plcp)
14381 + switch (plcp->raw[0] & 0xF) {
14383 + return BCM43xx_OFDM_RATE_6MB;
14385 + return BCM43xx_OFDM_RATE_9MB;
14387 + return BCM43xx_OFDM_RATE_12MB;
14389 + return BCM43xx_OFDM_RATE_18MB;
14391 + return BCM43xx_OFDM_RATE_24MB;
14393 + return BCM43xx_OFDM_RATE_36MB;
14395 + return BCM43xx_OFDM_RATE_48MB;
14397 + return BCM43xx_OFDM_RATE_54MB;
14403 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
14405 + switch (bitrate) {
14406 + case BCM43xx_CCK_RATE_1MB:
14408 + case BCM43xx_CCK_RATE_2MB:
14410 + case BCM43xx_CCK_RATE_5MB:
14412 + case BCM43xx_CCK_RATE_11MB:
14419 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
14421 + switch (bitrate) {
14422 + case BCM43xx_OFDM_RATE_6MB:
14424 + case BCM43xx_OFDM_RATE_9MB:
14426 + case BCM43xx_OFDM_RATE_12MB:
14428 + case BCM43xx_OFDM_RATE_18MB:
14430 + case BCM43xx_OFDM_RATE_24MB:
14432 + case BCM43xx_OFDM_RATE_36MB:
14434 + case BCM43xx_OFDM_RATE_48MB:
14436 + case BCM43xx_OFDM_RATE_54MB:
14443 +static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
14444 + const u16 octets, const u8 bitrate,
14445 + const int ofdm_modulation)
14447 + __le32 *data = &(plcp->data);
14448 + __u8 *raw = plcp->raw;
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);
14458 + plen = octets * 16 / bitrate;
14459 + if ((octets * 16 % bitrate) > 0) {
14461 + if ((bitrate == BCM43xx_CCK_RATE_11MB)
14462 + && ((octets * 8 % 11) < 4)) {
14468 + *data |= cpu_to_le32(plen << 16);
14469 + raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
14473 +static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
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;
14506 +__le16 bcm43xx_calc_duration_id(const struct ieee80211_hdr *wireless_header,
14509 + const u16 frame_ctl = le16_to_cpu(wireless_header->frame_control);
14510 + __le16 duration_id = wireless_header->duration_id;
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.
14517 + case WLAN_FC_TYPE_CTRL:
14518 + /* Use the original duration/id. */
14524 + return duration_id;
14528 +u16 ceiling_div(u16 dividend, u16 divisor)
14530 + return ((dividend + divisor - 1) / divisor);
14533 +static void bcm43xx_generate_rts(const struct bcm43xx_phyinfo *phy,
14534 + struct bcm43xx_txhdr *txhdr,
14537 + const struct ieee80211_hdr *wlhdr)
14541 + u8 fallback_bitrate;
14542 + int ofdm_modulation;
14543 + int fallback_ofdm_modulation;
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));
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),
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...
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.
14571 + if (phy->type == BCM43xx_PHYTYPE_A) {
14572 + /* Three times SIFS */
14574 + /* Add ACK duration. */
14575 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14577 + /* Add CTS duration. */
14578 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14581 + /* Three times SIFS */
14583 + /* Add ACK duration. */
14584 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14586 + /* Add CTS duration. */
14587 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
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);
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;
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)
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);
14618 + u8 fallback_bitrate;
14619 + int ofdm_modulation;
14620 + int fallback_ofdm_modulation;
14621 + u16 plcp_fragment_len = fragment_len;
14624 + u16 wsec_rate = 0;
14626 + /* Now construct the TX header. */
14627 + memset(txhdr, 0, sizeof(*txhdr));
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));
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);
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]);
14651 + if (key->enabled) {
14652 + /* Hardware appends ICV. */
14653 + plcp_fragment_len += txctl->icv_len;
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);
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);
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;
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;
14686 + /* Set WSEC/RATE field */
14687 + wsec_rate |= (txhdr->plcp.raw[0] << BCM43xx_TXHDR_RATE_SHIFT)
14688 + & BCM43xx_TXHDR_RATE_MASK;
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.
14695 + if (txctl->use_rts_cts) {
14696 + bcm43xx_generate_rts(phy, txhdr, &flags,
14697 + txctl->rts_cts_rate,
14698 + wireless_header);
14701 + txhdr->flags = cpu_to_le16(flags);
14702 + txhdr->control = cpu_to_le16(control);
14703 + txhdr->wsec_rate = cpu_to_le16(wsec_rate);
14706 +static s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm,
14707 + u8 in_rssi, int ofdm,
14708 + int adjust_2053, int adjust_2050)
14710 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14711 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14714 + switch (radio->version) {
14727 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
14728 + if (in_rssi > 63)
14730 + tmp = radio->nrssi_lt[in_rssi];
14742 + if (phy->type == BCM43xx_PHYTYPE_G &&
14748 + if (in_rssi > 127)
14749 + tmp = in_rssi - 256;
14769 +static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm,
14772 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14775 + if (phy->type == BCM43xx_PHYTYPE_A) {
14776 + //TODO: Incomplete specs.
14779 + ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
14785 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14786 + struct sk_buff *skb,
14787 + struct bcm43xx_rxhdr *rxhdr)
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);
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));
14802 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
14803 + /* Skip the PLCP header. */
14804 + skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
14806 + /* The SKB contains the PAYLOAD (wireless header + data)
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));
14815 + status.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
14817 + status.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
14818 + status.channel = radio->channel;
14820 + bcm->stats.last_rx = jiffies;
14821 + ieee80211_rx_irqsafe(bcm->net_dev, skb, &status);
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
14827 +#ifndef BCM43xx_XMIT_H_
14828 +#define BCM43xx_XMIT_H_
14830 +#include "bcm43xx_main.h"
14833 +#define _bcm43xx_declare_plcp_hdr(size) \
14834 + struct bcm43xx_plcp_hdr##size { \
14837 + __u8 raw[size]; \
14838 + } __attribute__((__packed__)); \
14839 + } __attribute__((__packed__))
14841 +/* struct bcm43xx_plcp_hdr4 */
14842 +_bcm43xx_declare_plcp_hdr(4);
14843 +/* struct bcm43xx_plcp_hdr6 */
14844 +_bcm43xx_declare_plcp_hdr(6);
14846 +#undef _bcm43xx_declare_plcp_hdr
14848 +/* Device specific TX header. To be prepended to TX frames. */
14849 +struct bcm43xx_txhdr {
14853 + __le16 wsec_rate;
14854 + __le16 frame_control;
14855 + u16 unknown_zeroed_0;
14858 + u8 unknown_wsec_tkip_data[3]; //FIXME
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;
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];
14875 + struct bcm43xx_plcp_hdr6 plcp;
14876 + } __attribute__((__packed__));
14878 + } __attribute__((__packed__));
14879 +} __attribute__((__packed__));
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
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
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
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);
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;
14920 + /* Flags field 1 */
14923 + u8 signal_quality;
14925 + /* Flags field 3 */
14927 + /* Flags field 2 */
14929 + /* Lower 16bits of the TSF at the time the frame started. */
14932 +} __attribute__((__packed__));
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)
14939 +#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
14940 +#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
14941 +/*FIXME: WEP related flags */
14943 +#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
14945 +/* Transmit Status as received from the hardware. */
14946 +struct bcm43xx_hwxmitstatus {
14954 + __le16 unknown; //FIXME
14955 +} __attribute__((__packed__));
14957 +/* Transmit Status in CPU byteorder. */
14958 +struct bcm43xx_xmitstatus {
14964 + u16 unknown; //FIXME
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
14976 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
14977 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
14979 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14980 + struct sk_buff *skb,
14981 + struct bcm43xx_rxhdr *rxhdr);
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
14988 +config BCM43XX_D80211
14989 + tristate "Broadcom BCM43xx wireless support (DeviceScape stack)"
14990 + depends on PCI && D80211 && NET_RADIO && EXPERIMENTAL
14993 + This is an experimental driver for the Broadcom 43xx wireless chip,
14994 + found in the Apple Airport Extreme and various other devices.
14996 +config BCM43XX_D80211_DEBUG
14997 + bool "Broadcom BCM43xx debugging (RECOMMENDED)"
14998 + depends on BCM43XX_D80211
15001 + Broadcom 43xx debugging messages.
15002 + Say Y, because the driver is still very experimental and
15003 + this will help you get it running.
15005 +config BCM43XX_D80211_DMA
15007 +config BCM43XX_D80211_PIO
15011 + prompt "BCM43xx data transfer mode"
15012 + depends on BCM43XX_D80211
15013 + default BCM43XX_D80211_DMA_AND_PIO_MODE
15015 +config BCM43XX_D80211_DMA_AND_PIO_MODE
15017 + select BCM43XX_D80211_DMA
15018 + select BCM43XX_D80211_PIO
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.
15026 + If unsure, choose this option.
15028 +config BCM43XX_D80211_DMA_MODE
15029 + bool "DMA (Direct Memory Access) only"
15030 + select BCM43XX_D80211_DMA
15032 + Only include Direct Memory Access (DMA).
15033 + This reduces the size of the driver module, by omitting the PIO code.
15035 +config BCM43XX_D80211_PIO_MODE
15036 + bool "PIO (Programmed I/O) only"
15037 + select BCM43XX_D80211_PIO
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).
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.
15047 + Only use PIO, if DMA does not work for you.
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
15054 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211.o
15055 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DEBUG) += bcm43xx_debugfs.o
15057 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DMA) += bcm43xx_dma.o
15058 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_PIO) += bcm43xx_pio.o
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 \
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.
15072 source "drivers/net/wireless/hostap/Kconfig"
15073 +source "drivers/net/wireless/bcm43xx-d80211/Kconfig"
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
15081 obj-$(CONFIG_PRISM54) += prism54/
15083 obj-$(CONFIG_HOSTAP) += hostap/
15084 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211/
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
15093 + * IEEE 802.11 driver (80211.o) -- hostapd interface
15094 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
15101 +#ifndef D80211_COMMON_H
15102 +#define D80211_COMMON_H
15104 +#include <linux/types.h>
15107 + * This is common header information with user space. It is used on all
15108 + * frames sent to wlan#ap interface.
15111 +#define IEEE80211_FI_VERSION 0x80211001
15113 +struct ieee80211_frame_info {
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. */
15134 +} __attribute__ ((packed));
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,
15151 +struct ieee80211_msg_set_aid_for_sta {
15152 + char sta_address[ETH_ALEN];
15156 +struct ieee80211_msg_key_notification {
15158 + char ifname[IFNAMSIZ];
15159 + u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
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,
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 */
15183 +struct ieee80211_radar_info {
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
15195 + * Low-level hardware driver -- IEEE 802.11 driver (80211.o) interface
15196 + * Copyright 2002-2005, Devicescape Software, Inc.
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.
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"
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).
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.
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
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.
15238 +/* Interface version (used for compatibility verification) */
15239 +#define IEEE80211_VERSION 2
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;
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;
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 */
15272 +struct ieee80211_hw_modes {
15274 + int num_channels;
15275 + struct ieee80211_channel *channels;
15277 + struct ieee80211_rate *rates;
15278 + int xr_end; /* only used with Atheros XR */
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 */
15289 +#define NUM_TX_DATA_QUEUES 6
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 */
15297 +struct ieee80211_tx_queue_stats {
15298 + struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES];
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
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
15316 +#endif /* IEEE80211_TX_QUEUE_NUMS */
15319 +struct ieee80211_low_level_stats {
15320 + unsigned int dot11ACKFailureCount;
15321 + unsigned int dot11RTSFailureCount;
15322 + unsigned int dot11FCSErrorCount;
15323 + unsigned int dot11RTSSuccessCount;
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
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
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;
15360 + unsigned int atheros_xr:1; /* only used with Atheros XR */
15362 + unsigned int power_level:8; /* per-packet transmit power level, in dBm
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()
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) */
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 */
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;
15395 +#define RX_FLAG_MMIC_ERROR 0x1
15396 +#define RX_FLAG_DECRYPTED 0x2
15397 +#define RX_FLAG_XR_DOUBLE_CHIRP 0x4
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
15402 +struct ieee80211_rx_status {
15405 + int freq; /* receive frequency in Mhz */
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
15417 +struct ieee80211_tx_status {
15418 + /* copied ieee80211_tx_control structure */
15419 + struct ieee80211_tx_control control;
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;
15427 + /* following two fields are only used with Atheros Super A/G */
15428 + int queue_length; /* information about TX queue */
15429 + int queue_number;
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 */
15438 + int mode; /* IW_MODE_ */
15440 + int phymode; /* MODE_IEEE80211A, .. */
15441 + unsigned int regulatory_domain;
15446 + /* Bitfields, grouped together */
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 */
15453 + /* these fields are used by low level drivers for hardware
15454 + * that generate beacons independently */
15457 + u8 *generic_elem;
15458 + size_t generic_elem_len;
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 */
15465 + int antenna_sel; /* default antenna conf:
15466 + * 0 = default/diversity,
15470 + int calib_int; /* hw/radio calibration interval in
15473 + int antenna_mode;
15475 + u8 bssid_mask[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff = 1 BSSID */
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;
15487 + u8 client_bssid[ETH_ALEN];
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
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;
15504 +typedef enum { ALG_NONE, ALG_WEP, ALG_TKIP, ALG_CCMP, ALG_NULL }
15505 +ieee80211_key_alg;
15508 +struct ieee80211_key_conf {
15510 + int hw_key_idx; /* filled + used by low-level driver */
15511 + ieee80211_key_alg alg;
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 */
15524 +#define IEEE80211_SCAN_START 1
15525 +#define IEEE80211_SCAN_END 2
15527 +struct ieee80211_scan_conf {
15528 + int scan_channel; /* IEEE 802.11 channel number to do passive scan
15530 + int scan_freq; /* new freq in MHz to switch to for passive scan
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;
15538 + int running_channel; /* IEEE 802.11 channel number we operate on
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;
15546 + int scan_time; /* time a scan will take in us */
15549 + struct sk_buff *skb; /* skb to transmit before changing channels, maybe
15550 + * NULL for none */
15551 + struct ieee80211_tx_control *tx_control;
15555 +#ifndef IW_MODE_ADHOC
15556 +#define IW_MODE_ADHOC 1
15559 +#ifndef IW_MODE_INFRA
15560 +#define IW_MODE_INFRA 2
15563 +#ifndef IW_MODE_MASTER
15564 +#define IW_MODE_MASTER 3
15567 +#ifndef IW_MODE_MONITOR
15568 +#define IW_MODE_MONITOR 6
15571 +#define IEEE80211_SEQ_COUNTER_RX 0
15572 +#define IEEE80211_SEQ_COUNTER_TX 1
15575 + SET_KEY, DISABLE_KEY, REMOVE_ALL_KEYS,
15576 + ENABLE_COMPRESSION, DISABLE_COMPRESSION
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
15582 +struct ieee80211_hw {
15583 + int version; /* IEEE80211_VERSION */
15585 + /* Driver name */
15588 + /* TODO: frame_type 802.11/802.3, sw_encryption requirements */
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;
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
15602 + int device_hides_wep:1;
15604 + /* Whether RX frames passed to ieee80211_rx() include FCS in the end
15606 + int rx_includes_fcs:1;
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;
15616 + int wep_include_iv:1;
15617 + int data_nullfunc_ack:1; /* will data nullfunc frames get proper
15618 + * TX status callback */
15620 + /* Force sw version of encryption for TKIP packets if WMM is enabled.
15622 + int no_tkip_wmm_hwaccel:1;
15624 + /* 1 if the payload needs to be padded at even boundaries after the
15626 + unsigned int extra_hdr_room:1;
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.
15633 + unsigned int device_strips_mic:1;
15635 + /* 1 = low-level driver supports skb fraglist (NETIF_F_FRAGLIST), i.e.,
15636 + * more than one skb per frame */
15637 + unsigned int fraglist;
15639 + /* This is the time in us to change channels
15641 + int channel_change_time;
15644 + struct ieee80211_hw_modes *modes;
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);
15653 + /* Handler for performing hardware reset. */
15654 + int (*reset)(struct net_device *dev);
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);
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);
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);
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);
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);
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
15691 + int (*set_key_idx)(struct net_device *dev, int idx);
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);
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);
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);
15713 + /* return low-level statistics */
15714 + int (*get_stats)(struct net_device *dev,
15715 + struct ieee80211_low_level_stats *stats);
15717 + /* Enable/disable test modes; mode = IEEE80211_TEST_* */
15718 + int (*test_mode)(struct net_device *dev, int mode);
15720 + /* Configuration of test parameters */
15721 + int (*test_param)(struct net_device *dev, int param, int value);
15723 + /* Change MAC address. addr is pointer to struct sockaddr. */
15724 + int (*set_mac_address)(struct net_device *dev, void *addr);
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 */
15730 + int (*set_privacy_invoked)(struct net_device *dev,
15731 + int privacy_invoked);
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);
15739 + /* Configuration of RTS threshold (if device needs it) */
15740 + int (*set_rts_threshold)(struct net_device *dev, u32 value);
15742 + /* Configuration of fragmentation threshold (if device needs it) */
15743 + int (*set_frag_threshold)(struct net_device *dev, u32 value);
15745 + /* Configuration of retry limits (if device needs it) */
15746 + int (*set_retry_limit)(struct net_device *dev, u32 short_retry,
15749 + /* Number of STAs in STA table notification (NULL = disabled) */
15750 + void (*sta_table_notification)(struct net_device *dev, int num_sta);
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);
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);
15767 + /* Number of available hardware TX queues for data packets.
15768 + * WMM requires at least four queues. */
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);
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);
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);
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);
15793 + /* Optional handler for XR-in-use notification. */
15794 + int (*atheros_xr_in_use)(struct net_device *dev, int in_use);
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.
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 *));
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
15814 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw);
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);
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);
15824 +/* Free allocated net_device including private data of a driver. */
15825 +void ieee80211_free_hw(struct net_device *dev);
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);
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
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);
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);
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.
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. */
15871 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
15872 + struct ieee80211_tx_control *control);
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,
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.
15885 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb);
15887 +/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */
15888 +int ieee80211_get_hdrlen(u16 fc);
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. */
15895 + NETIF_ATTACH, NETIF_DETACH, NETIF_START, NETIF_STOP, NETIF_WAKE,
15896 + NETIF_IS_STOPPED, NETIF_UPDATE_TX_START
15898 +int ieee80211_netif_oper(struct net_device *dev, Netif_Oper op);
15902 + * Function to get hardware configuration information
15903 + * by the low level driver should it need it.
15905 +struct ieee80211_conf *
15906 +ieee80211_get_hw_conf(struct net_device *dev);
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);
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,
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,
15927 +/* Test parameters */
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,
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
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
15949 +void ieee80211_rx_led(int state, struct net_device *dev);
15952 +/* IEEE 802.11 defines */
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
15966 +#define WLAN_FC_GET_TYPE(fc) (((fc) & 0x000c) >> 2)
15967 +#define WLAN_FC_GET_STYPE(fc) (((fc) & 0x00f0) >> 4)
15969 +#define WLAN_GET_SEQ_FRAG(seq) ((seq) & 0x000f)
15970 +#define WLAN_GET_SEQ_SEQ(seq) ((seq) >> 4)
15972 +#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
15974 +#define WLAN_FC_TYPE_MGMT 0
15975 +#define WLAN_FC_TYPE_CTRL 1
15976 +#define WLAN_FC_TYPE_DATA 2
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
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
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
16019 +#define IEEE80211_MAX_FRAG_THRESHOLD 2346
16020 +#define IEEE80211_MAX_RTS_THRESHOLD 2347
16022 +struct ieee80211_hdr {
16023 + u16 frame_control;
16030 +} __attribute__ ((packed));
16032 +/* return a pointer to the source address (SA) */
16033 +static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
16035 + u8 *raw = (u8 *) hdr;
16036 + u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
16038 + switch (tofrom) {
16040 + return hdr->addr3;
16042 + return hdr->addr4;
16044 + return hdr->addr2;
16047 +/* return a pointer to the destination address (DA) */
16048 +static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
16050 + u8 *raw = (u8 *) hdr;
16051 + u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
16054 + return hdr->addr3;
16055 + return hdr->addr1;
16058 +static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
16060 + return (le16_to_cpu(hdr->frame_control) & WLAN_FC_MOREFRAG) != 0;
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
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.
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.
16079 +#ifndef D802_11_MGMT_H
16080 +#define D802_11_MGMT_H
16082 +#include <linux/types.h>
16084 +struct ieee80211_mgmt {
16085 + u16 frame_control;
16094 + u16 auth_transaction;
16096 + /* possibly followed by Challenge text */
16098 + } __attribute__ ((packed)) auth;
16101 + } __attribute__ ((packed)) deauth;
16104 + u16 listen_interval;
16105 + /* followed by SSID and Supported rates */
16107 + } __attribute__ ((packed)) assoc_req;
16112 + /* followed by Supported rates */
16114 + } __attribute__ ((packed)) assoc_resp, reassoc_resp;
16117 + u16 listen_interval;
16118 + u8 current_ap[6];
16119 + /* followed by SSID and Supported rates */
16121 + } __attribute__ ((packed)) reassoc_req;
16124 + } __attribute__ ((packed)) disassoc;
16129 + /* followed by some of SSID, Supported rates,
16130 + * FH Params, DS Params, CF Params, IBSS Params, TIM */
16132 + } __attribute__ ((packed)) beacon;
16134 + /* only variable items: SSID, Supported rates */
16136 + } __attribute__ ((packed)) probe_req;
16141 + /* followed by some of SSID, Supported rates,
16142 + * FH Params, DS Params, CF Params, IBSS Params */
16144 + } __attribute__ ((packed)) probe_resp;
16153 + } __attribute__ ((packed)) wme_action;
16161 + } __attribute__((packed)) chan_switch;
16163 + } __attribute__ ((packed)) action;
16165 +} __attribute__ ((packed));
16168 +/* Authentication algorithms */
16169 +#define WLAN_AUTH_OPEN 0
16170 +#define WLAN_AUTH_SHARED_KEY 1
16171 +#define WLAN_AUTH_LEAP 128
16173 +#define WLAN_AUTH_CHALLENGE_LEN 128
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)
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)
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
16201 +#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
16202 +#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
16203 +#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
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
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
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
16225 +#define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10
16226 +#define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
16228 +#define WLAN_REASON_MIC_FAILURE 14
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
16262 +#define ATHEROS_INFO_USEXR BIT(3)
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
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.
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.
16279 +#ifndef D80211_SHARED_H
16280 +#define D80211_SHARED_H
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. */
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
16296 +#define IEEE80211_CHAN_W_SCAN 0x00000001
16297 +#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
16298 +#define IEEE80211_CHAN_W_IBSS 0x00000004
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
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))
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
16323 /* deinitialize crypto context and free allocated private data */
16324 void (*deinit) (void *priv);
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);
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
16341 #define WLAN_AUTH_CHALLENGE_LEN 128
16343 @@ -299,6 +300,23 @@
16344 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
16347 +/* Action categories - 802.11h */
16348 +enum ieee80211_actioncategories {
16349 + WLAN_ACTION_SPECTRUM_MGMT = 0,
16350 + /* Reserved 1-127 */
16351 + /* Error 128-255 */
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 */
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 @@
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));
16380 +struct ieee80211_channel_switch {
16386 +} __attribute__ ((packed));
16388 +struct ieee80211_action {
16389 + struct ieee80211_hdr_3addr header;
16393 + struct ieee80211_action_exchange {
16395 + struct ieee80211_info_element info_element[0];
16397 + struct ieee80211_channel_switch channel_switch;
16400 +} __attribute__ ((packed));
16402 struct ieee80211_disassoc {
16403 struct ieee80211_hdr_3addr header;
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)
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)
16420 #define QOS_QUEUE_NUM 4
16421 #define QOS_OUI_LEN 3
16422 @@ -748,6 +798,91 @@
16424 /*******************************************************/
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 */
16435 +struct ieee80211_basic_report {
16437 + __le64 start_time;
16440 +} __attribute__ ((packed));
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 */
16451 + IEEE80211_REPORT_BASIC = 0, /* required */
16452 + IEEE80211_REPORT_CCA = 1, /* optional */
16453 + IEEE80211_REPORT_RPI = 2, /* optional */
16454 + /* 3-255 reserved */
16457 +struct ieee80211_measurement_params {
16459 + __le64 start_time;
16461 +} __attribute__ ((packed));
16463 +struct ieee80211_measurement_request {
16464 + struct ieee80211_info_element ie;
16468 + struct ieee80211_measurement_params params[0];
16469 +} __attribute__ ((packed));
16471 +struct ieee80211_measurement_report {
16472 + struct ieee80211_info_element ie;
16477 + struct ieee80211_basic_report basic[0];
16479 +} __attribute__ ((packed));
16481 +struct ieee80211_tpc_report {
16482 + u8 transmit_power;
16484 +} __attribute__ ((packed));
16486 +struct ieee80211_channel_map {
16489 +} __attribute__ ((packed));
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];
16498 +struct ieee80211_csa {
16502 +} __attribute__ ((packed));
16504 +struct ieee80211_quiet {
16509 +} __attribute__ ((packed));
16511 struct ieee80211_network {
16512 /* These entries are used to identify a unique network */
16513 u8 bssid[ETH_ALEN];
16514 @@ -767,7 +902,7 @@
16516 unsigned long last_scanned;
16520 u32 last_associate;
16522 u16 beacon_interval;
16523 @@ -779,6 +914,25 @@
16524 u8 rsn_ie[MAX_WPA_IE_LEN];
16526 struct ieee80211_tim_parameters tim;
16528 + /* 802.11h info */
16530 + /* Power Constraint - mandatory if spctrm mgmt required */
16531 + u8 power_constraint;
16533 + /* TPC Report - mandatory if spctrm mgmt required */
16534 + struct ieee80211_tpc_report tpc_report;
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;
16540 + /* Channel Switch Announcement - optional if spctrm mgmt required */
16541 + struct ieee80211_csa csa;
16543 + /* Quiet - optional if spctrm mgmt required */
16544 + struct ieee80211_quiet quiet;
16546 struct list_head list;
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);
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,
16572 extern u8 ieee80211_freq_to_channel(struct ieee80211_device *ieee, u32 freq);
16573 +extern u8 ieee80211_get_channel_flags(struct ieee80211_device *ieee,
16575 +extern const struct ieee80211_channel *ieee80211_get_channel(struct
16577 + *ieee, u8 channel);
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,
16589 +extern int ieee80211_wx_get_auth(struct net_device *dev,
16590 + struct iw_request_info *info,
16591 + union iwreq_data *wrqu,
16594 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
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; \
16602 *(__timeo) = schedule_timeout(*(__timeo)); \
16603 + rc = __condition; \
16606 - rc = __condition; \
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>
16625 @@ -1448,8 +1446,29 @@
16627 struct net_device *dev = skb->dev;
16630 + if (dev->master) {
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.
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)
16643 + if (dev->master->priv_flags & IFF_MASTER_8023AD &&
16644 + skb->protocol == __constant_htons(ETH_P_SLOW))
16651 skb->dev = dev->master;
16656 @@ -1593,6 +1612,9 @@
16658 orig_dev = skb_bond(skb);
16661 + return NET_RX_DROP;
16663 __get_cpu_var(netdev_rx_stat).total++;
16665 skb->h.raw = skb->nh.raw = skb->data;
16666 @@ -2028,7 +2050,7 @@
16667 .release = seq_release,
16670 -#ifdef WIRELESS_EXT
16671 +#ifdef CONFIG_WIRELESS_EXT
16672 extern int wireless_proc_init(void);
16674 #define wireless_proc_init() 0
16675 @@ -2582,7 +2604,7 @@
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 @@
16688 -#endif /* WIRELESS_EXT */
16689 +#endif /* CONFIG_WIRELESS_EXT */
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
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
16707 +/* Based on Rijndael implementation that has been placed in the public domain,
16708 + * although heavily modified.
16710 + * Modifications Copyright 2003, Instant802 Networks, Inc.
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.
16716 + * Optimized both speed and size by removing not used key lengths (only
16717 + * 128-bit is used in IEEE 802.11i).
16720 +/* Use 256-byte Te4 table instead of larger 1024-byte */
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 */
16730 +/* --- start of code that is based on public domain AES implementation --- */
16733 + * rijndael-alg-fst.c
16735 + * @version 3.0 (December 2000)
16737 + * Optimised ANSI C code for the Rijndael cipher (now AES)
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>
16743 + * This code is hereby placed in the public domain.
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.
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];
16766 +static const u32 Te0[256] =
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,
16834 +#ifndef ONLY_ONE_TABLE
16835 +static const u32 Te1[256] =
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,
16903 +static const u32 Te2[256] =
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,
16971 +static const u32 Te3[256] =
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,
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])
17044 +#else /* ONLY_ONE_TABLE */
17047 +static inline u32 ROR8(u32 v)
17049 + return (v >> 8) | (v << 24);
17052 +static inline u32 ROR16(u32 v)
17054 + return (v >> 16) | (v << 16);
17057 +static inline u32 ROR24(u32 v)
17059 + return (v >> 24) | (v << 8);
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]))
17067 +#endif /* ONLY_ONE_TABLE */
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,
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])
17112 +#else /* SMALL_TE4 */
17114 +static const u32 Te4[256] =
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,
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)
17187 +#endif /* SMALL_TE4 */
17190 +static const u32 rcon[] = {
17191 + 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
17192 + 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
17195 +#define GETU32(pt) \
17196 +(((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ \
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); }
17203 +/* Expand the cipher key into the encryption key schedule. */
17204 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[])
17209 + rk[0] = GETU32(key );
17210 + rk[1] = GETU32(key + 4);
17211 + rk[2] = GETU32(key + 8);
17212 + rk[3] = GETU32(key + 12);
17214 + for (i = 0; i < 10; i++) {
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];
17226 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
17228 + const int Nr = 10;
17229 + u32 s0, s1, s2, s3, t0, t1, t2, t3;
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];
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]
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) ^
17259 + s0 = TE4_1(t1 >> 24) ^ TE4_2(t2 >> 16) ^ TE4_3(t3 >> 8) ^ TE4_4(t0) ^
17261 + PUTU32(ct + 4, s0);
17262 + s0 = TE4_1(t2 >> 24) ^ TE4_2(t3 >> 16) ^ TE4_3(t0 >> 8) ^ TE4_4(t1) ^
17264 + PUTU32(ct + 8, s0);
17265 + s0 = TE4_1(t3 >> 24) ^ TE4_2(t0 >> 16) ^ TE4_3(t1 >> 8) ^ TE4_4(t2) ^
17267 + PUTU32(ct + 12, s0);
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
17276 + * Copyright 2003-2004, Instant802 Networks, Inc.
17277 + * Copyright 2005, Devicescape Software, Inc.
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.
17284 +#include <linux/types.h>
17285 +#include <linux/netdevice.h>
17287 +#include <net/d80211.h>
17288 +#include "ieee80211_key.h"
17289 +#include "aes_ccm.h"
17293 +static inline void aes_ccm_prepare(u32 *rk, u8 *b_0, u8 *aad, u8 *b,
17298 + ieee80211_aes_encrypt(rk, b_0, b);
17300 + /* Extra Authenticate-only data (always two AES blocks) */
17301 + for (i = 0; i < AES_BLOCK_LEN; i++)
17303 + ieee80211_aes_encrypt(rk, aad, b);
17305 + aad += AES_BLOCK_LEN;
17307 + for (i = 0; i < AES_BLOCK_LEN; i++)
17309 + ieee80211_aes_encrypt(rk, aad, a);
17311 + /* Mask out bits from auth-only-b_0 */
17314 + /* S_0 is used to encrypt T (= MIC) */
17317 + ieee80211_aes_encrypt(rk, b_0, s_0);
17321 +void ieee80211_aes_ccm_encrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *data,
17322 + size_t data_len, u8 *cdata, u8 *mic)
17324 + int i, j, last_len, num_blocks;
17326 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], e[AES_BLOCK_LEN];
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);
17332 + /* Process payload blocks */
17335 + for (j = 1; j <= num_blocks; j++) {
17336 + int blen = (j == num_blocks && last_len) ?
17337 + last_len : AES_BLOCK_LEN;
17339 + /* Authentication followed by encryption */
17340 + for (i = 0; i < blen; i++)
17342 + ieee80211_aes_encrypt(rk, b, b);
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];
17351 + for (i = 0; i < CCMP_MIC_LEN; i++)
17352 + mic[i] = b[i] ^ s_0[i];
17356 +int ieee80211_aes_ccm_decrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *cdata,
17357 + size_t data_len, u8 *mic, u8 *data)
17359 + int i, j, last_len, num_blocks;
17361 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], a[AES_BLOCK_LEN];
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);
17367 + /* Process payload blocks */
17370 + for (j = 1; j <= num_blocks; j++) {
17371 + int blen = (j == num_blocks && last_len) ?
17372 + last_len : AES_BLOCK_LEN;
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];
17383 + ieee80211_aes_encrypt(rk, a, a);
17386 + for (i = 0; i < CCMP_MIC_LEN; i++) {
17387 + if ((mic[i] ^ s_0[i]) != a[i])
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
17399 + * Copyright 2003-2004, Instant802 Networks, Inc.
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.
17409 +#include <linux/types.h>
17411 +#define AES_BLOCK_LEN 16
17412 +#define AES_STATE_LEN 44
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);
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
17427 + * Copyright 2005, Devicescape Software, Inc.
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.
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.
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"
17445 +static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* qd)
17447 + struct sk_buff_head *q = qdisc_priv(qd);
17449 + if (skb_queue_len(q) > qd->dev->tx_queue_len) {
17450 + qd->qstats.drops++;
17452 + return NET_XMIT_DROP;
17455 + skb_queue_tail(q, skb);
17457 + qd->bstats.bytes += skb->len;
17458 + qd->bstats.packets++;
17460 + return NET_XMIT_SUCCESS;
17464 +static int pfifo_requeue(struct sk_buff *skb, struct Qdisc* qd)
17466 + struct sk_buff_head *q = qdisc_priv(qd);
17468 + skb_queue_head(q, skb);
17470 + qd->bstats.bytes += skb->len;
17471 + qd->bstats.packets++;
17473 + return NET_XMIT_SUCCESS;
17477 +static struct sk_buff *pfifo_dequeue(struct Qdisc* qd)
17479 + struct sk_buff_head *q = qdisc_priv(qd);
17481 + return skb_dequeue(q);
17485 +static int pfifo_init(struct Qdisc* qd, struct rtattr *opt)
17487 + struct sk_buff_head *q = qdisc_priv(qd);
17489 + skb_queue_head_init(q);
17494 +static void pfifo_reset(struct Qdisc* qd)
17496 + struct sk_buff_head *q = qdisc_priv(qd);
17498 + skb_queue_purge(q);
17503 +static int pfifo_dump(struct Qdisc *qd, struct sk_buff *skb)
17509 +struct Qdisc_ops pfifo_qdisc_ops =
17513 + .id = "ieee80211_pfifo",
17514 + .priv_size = sizeof(struct sk_buff_head),
17516 + .enqueue = pfifo_enqueue,
17517 + .dequeue = pfifo_dequeue,
17518 + .requeue = pfifo_requeue,
17521 + .init = pfifo_init,
17522 + .reset = pfifo_reset,
17526 + .dump = pfifo_dump,
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
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.
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.
17545 +#ifndef HOSTAPD_IOCTL_H
17546 +#define HOSTAPD_IOCTL_H
17548 +#include <linux/types.h>
17550 +#ifndef __KERNEL__
17551 +#include "ieee80211_shared.h"
17552 +#endif /* __KERNEL__ */
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)
17559 +/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
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,
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. */
17636 +/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
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,
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. */
17683 + /* these definitions mirror the ieee80211_i.h
17684 + * IEEE80211_DISABLED, ... IEEE80211_ASSOCIATED enumeration */
17686 + PRISM2_PARAM_STA_DISABLED,
17687 + PRISM2_PARAM_STA_AUTHENTICATE,
17688 + PRISM2_PARAM_STA_ASSOCIATE,
17689 + PRISM2_PARAM_STA_ASSOCIATED,
17692 +#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
17693 +#define HOSTAP_CRYPT_ALG_NAME_LEN 16
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.
17701 +#define ALIGNED __attribute__ ((aligned))
17703 +/* Check if it has been defined elsewhere */
17705 +#error "Must define ALIGNED to generate aligned structure elements"
17709 +struct prism2_hostapd_param {
17711 + u8 sta_addr[ETH_ALEN];
17717 + u8 supp_rates[32];
17718 + /* atheros_super_ag and enc_flags are only used with
17719 + * IEEE80211_ATHEROS_SUPER_AG
17721 + u8 atheros_super_ag;
17722 + u8 atheros_xr_mode;
17724 +#define IEEE80211_STA_DYNAMIC_ENC BIT(0)
17728 + u32 inactive_msec;
17733 + u32 current_tx_rate; /* in 100 kbps */
17736 + u32 num_ps_buf_frames;
17737 + u32 tx_retry_failed;
17738 + u32 tx_retry_count;
17740 + u32 last_ack_rssi;
17743 + u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
17747 +#define HOSTAP_SEQ_COUNTER_SIZE 8
17748 + u8 seq_counter[HOSTAP_SEQ_COUNTER_SIZE];
17750 + u8 key[0] ALIGNED;
17759 + u8 data[0] ALIGNED;
17764 + u8 data[0] ALIGNED; /* head_len + tail_len bytes */
17769 + u8 data[0] ALIGNED; /* num_modes * feature data */
17773 + s8 our_mode_only;
17776 + s16 interval; /* seconds */
17777 + s32 listen; /* microseconds */
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)
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 */
17797 + u8 type; /* WDS, VLAN, etc */
17798 + u8 name[IFNAMSIZ];
17799 + u8 data[0] ALIGNED;
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;
17815 +#define LOAD_STATS_CLEAR BIT(1)
17818 + } get_load_stats;
17820 + char vlan_name[IFNAMSIZ];
17825 + u8 data[0] ALIGNED;
17826 + } set_generic_info_elem;
17828 + u16 mode; /* MODE_* */
17831 + u8 power_level; /* regulatory limit in dBm */
17833 + } set_channel_flag;
17836 + } set_regulatory_domain;
17842 + u32 burst_time; /* maximum burst time in 0.1 ms, i.e.,
17844 + } tx_queue_params;
17847 + u8 bssid_mask[ETH_ALEN];
17849 + struct ieee80211_tx_stats {
17851 + unsigned int len; /* num packets in queue */
17852 + unsigned int limit; /* queue len (soft) limit
17854 + unsigned int count; /* total num frames sent */
17859 + u8 ssid[0] ALIGNED;
17865 +#define MLME_STA_DEAUTH 0
17866 +#define MLME_STA_DISASSOC 1
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;
17878 + unsigned int period;
17879 + unsigned int offset;
17880 + unsigned int duration;
17883 + unsigned int tx_power_min;
17884 + unsigned int tx_power_max;
17887 + u8 dummy[80]; /* Make sizeof() this struct large enough
17888 + * with some compiler versions. */
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 */
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
17908 +#endif /* IEEE80211_TX_QUEUE_NUMS */
17911 +#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
17912 +#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
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
17921 +#define HOSTAP_HW_FLAG_NULLFUNC_OK BIT(0)
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,
17931 +/* Data structures used for get_hw_features ioctl */
17932 +struct hostapd_ioctl_hw_modes_hdr {
17934 + int num_channels;
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_*) */
17944 +struct ieee80211_rate_data {
17945 + int rate; /* rate in 100 kbps */
17946 + int flags; /* IEEE80211_RATE_ flags */
17950 +/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
17952 + HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
17953 + HOSTAP_IF_STA = 4
17956 +struct hostapd_if_wds {
17957 + u8 remote_addr[ETH_ALEN];
17960 +struct hostapd_if_vlan {
17964 +struct hostapd_if_bss {
17965 + u8 bssid[ETH_ALEN];
17968 +struct hostapd_if_sta {
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
17977 + * Copyright 2002-2005, Instant802 Networks, Inc.
17978 + * Copyright 2005-2006, Devicescape Software, Inc.
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.
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>
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"
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) */
18020 +static unsigned char eapol_header[] =
18021 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
18024 +struct rate_control_algs {
18025 + struct rate_control_algs *next;
18026 + struct rate_control_ops *ops;
18029 +static struct rate_control_algs *ieee80211_rate_ctrl_algs;
18031 +static int rate_control_initialize(struct ieee80211_local *local);
18034 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
18037 +struct ieee80211_key_conf *
18038 +ieee80211_key_data2conf(struct ieee80211_local *local,
18039 + struct ieee80211_key *data)
18041 + struct ieee80211_key_conf *conf;
18043 + conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
18044 + if (conf == NULL)
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);
18060 +static int rate_list_match(int *rate_list, int rate)
18064 + if (rate_list == NULL)
18067 + for (i = 0; rate_list[i] >= 0; i++)
18068 + if (rate_list[i] == rate)
18075 +void ieee80211_prepare_rates(struct net_device *dev)
18077 + struct ieee80211_local *local = dev->priv;
18080 + for (i = 0; i < local->num_curr_rates; i++) {
18081 + struct ieee80211_rate *rate = &local->curr_rates[i];
18083 + rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
18084 + IEEE80211_RATE_BASIC);
18086 + if (local->supp_rates[local->conf.phymode]) {
18087 + if (!rate_list_match(local->supp_rates
18088 + [local->conf.phymode],
18093 + rate->flags |= IEEE80211_RATE_SUPPORTED;
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],
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;
18108 + case MODE_IEEE80211B:
18109 + if (rate->rate == 10 || rate->rate == 20)
18110 + rate->flags |= IEEE80211_RATE_BASIC;
18112 + case MODE_ATHEROS_TURBO:
18113 + if (rate->rate == 120 || rate->rate == 240 ||
18114 + rate->rate == 480)
18115 + rate->flags |= IEEE80211_RATE_BASIC;
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;
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;
18131 + case MODE_IEEE80211B:
18132 + if (rate->rate == 10)
18133 + rate->flags |= IEEE80211_RATE_MANDATORY;
18135 + case MODE_ATHEROS_TURBO:
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;
18152 +static void ieee80211_key_threshold_notify(struct net_device *dev,
18153 + struct ieee80211_key *key,
18154 + struct sta_info *sta)
18156 + struct sk_buff *skb;
18157 + struct ieee80211_msg_key_notification *msg;
18159 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
18160 + sizeof(struct ieee80211_msg_key_notification));
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);
18170 + memcpy(msg->addr, sta->addr, ETH_ALEN);
18172 + memset(msg->addr, 0xff, ETH_ALEN);
18174 + key->tx_rx_count = 0;
18176 + ieee80211_rx_mgmt(dev, skb, 0,
18177 + ieee80211_msg_key_threshold_notification);
18181 +int ieee80211_get_hdrlen(u16 fc)
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 */
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:
18209 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb)
18211 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18214 + if (unlikely(skb->len < 10))
18216 + hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
18217 + if (unlikely(hdrlen > skb->len))
18223 +#ifdef IEEE80211_VERBOSE_DEBUG_FRAME_DUMP
18224 +static void ieee80211_dump_frame(const char *ifname, const char *title,
18225 + struct sk_buff *skb)
18227 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18231 + printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
18232 + if (skb->len < 4) {
18237 + fc = le16_to_cpu(hdr->frame_control);
18238 + hdrlen = ieee80211_get_hdrlen(fc);
18239 + if (hdrlen > skb->len)
18240 + hdrlen = skb->len;
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));
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)
18259 +#endif /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18262 +static int ieee80211_is_eapol(struct sk_buff *skb)
18264 + struct ieee80211_hdr *hdr;
18268 + if (unlikely(skb->len < 10))
18271 + hdr = (struct ieee80211_hdr *) skb->data;
18272 + fc = le16_to_cpu(hdr->frame_control);
18274 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
18277 + hdrlen = ieee80211_get_hdrlen(fc);
18279 + if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
18280 + memcmp(skb->data + hdrlen, eapol_header,
18281 + sizeof(eapol_header)) == 0))
18288 +static ieee80211_txrx_result
18289 +ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
18291 + struct rate_control_extra extra;
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;
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;
18307 + tx->u.tx.control->alt_retry_rate = -1;
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 &&
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;
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;
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;
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;
18334 + return TXRX_CONTINUE;
18338 +static ieee80211_txrx_result
18339 +ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
18342 + tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
18344 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
18346 + if (unlikely(tx->u.tx.control->do_not_encrypt))
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;
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,
18369 + return TXRX_CONTINUE;
18373 +static ieee80211_txrx_result
18374 +ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
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;
18381 + int frag_threshold = tx->local->fragmentation_threshold;
18383 + if (!tx->fragmented)
18384 + return TXRX_CONTINUE;
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;
18393 + frags = (struct sk_buff **)
18394 + kmalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
18395 + if (frags == NULL)
18397 + memset(frags, 0, num_fragm * sizeof(struct sk_buff *));
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;
18409 + /* reserve enough extra head and tail room for possible
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);
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);
18434 + skb_trim(first, hdrlen + per_fragm);
18436 + tx->u.tx.num_extra_frag = num_fragm - 1;
18437 + tx->u.tx.extra_frag = frags;
18439 + return TXRX_CONTINUE;
18442 + printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
18444 + for (i = 0; i < num_fragm - 1; i++)
18446 + dev_kfree_skb(frags[i]);
18449 + I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
18450 + return TXRX_DROP;
18454 +static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
18456 + if (tx->key->force_sw_encrypt || tx->local->conf.sw_encrypt) {
18457 + if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
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) ==
18471 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
18473 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18475 + hdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18476 + if (tx->u.tx.extra_frag) {
18477 + struct ieee80211_hdr *fhdr;
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);
18488 +static ieee80211_txrx_result
18489 +ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
18491 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18494 + fc = le16_to_cpu(hdr->frame_control);
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;
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);
18506 + if (wep_encrypt_skb(tx, tx->skb) < 0) {
18507 + I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
18508 + return TXRX_DROP;
18511 + if (tx->u.tx.extra_frag) {
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;
18522 + return TXRX_CONTINUE;
18526 +static inline int ceiling_div(int dividend, int divisor)
18528 + return ((dividend + divisor - 1) / divisor);
18532 +static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
18533 + int rate, int erp, int short_preamble)
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.
18542 + * rate is in 100 kbps, so divident is multiplied by 10 in the
18543 + * ceiling_div() operations.
18546 + if (local->conf.phymode == MODE_IEEE80211A || erp ||
18547 + local->conf.phymode == MODE_ATHEROS_TURBO) {
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
18557 + * 802.11a - 17.5.2: aSIFSTime = 16 usec
18558 + * 802.11g - 19.8.4: aSIFSTime = 10 usec +
18559 + * signal ext = 6 usec
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 */
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.
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
18578 + dur = 10; /* aSIFSTime = 10 usec */
18579 + dur += short_preamble ? (72 + 24) : (144 + 48);
18581 + dur += ceiling_div(8 * (len + 4) * 10, rate);
18588 +static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
18589 + int next_frag_len)
18591 + int rate, mrate, erp, dur, i;
18592 + struct ieee80211_rate *txrate = tx->u.tx.rate;
18593 + struct ieee80211_local *local = tx->local;
18595 + erp = txrate->flags & IEEE80211_RATE_ERP;
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
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
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.
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
18628 + * PS Poll: BIT(15) | BIT(14) | aid
18634 + if (0 /* FIX: data/mgmt during CFP */)
18637 + if (group_addr) /* Group address as the destination - no ACK */
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
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)
18657 + if (IEEE80211_RATE_MODULATION(txrate->flags) !=
18658 + IEEE80211_RATE_MODULATION(r->flags))
18661 + if (r->flags & IEEE80211_RATE_BASIC)
18663 + else if (r->flags & IEEE80211_RATE_MANDATORY)
18666 + if (rate == -1) {
18667 + /* No matching basic rate found; use highest suitable mandatory
18672 + /* Time needed to transmit ACK
18673 + * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
18674 + * to closest integer */
18676 + dur = ieee80211_frame_duration(local, 10, rate, erp,
18677 + local->short_preamble);
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);
18693 +static ieee80211_txrx_result
18694 +ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
18696 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18698 + struct ieee80211_tx_control *control = tx->u.tx.control;
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;
18707 + control->retry_limit =
18708 + tx->local->short_retry_limit;
18711 + control->retry_limit = 1;
18714 + if (tx->fragmented) {
18715 + /* Do not use multiple retry rates when sending fragmented
18717 + * TODO: The last fragment could still use multiple retry
18719 + control->alt_retry_rate = -1;
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;
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 :
18738 + hdr->duration_id = cpu_to_le16(dur);
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;
18744 + /* Do not use multiple retry rates when using RTS/CTS */
18745 + control->alt_retry_rate = -1;
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))
18753 + if (control->use_rts_cts)
18754 + dur += ieee80211_frame_duration(tx->local, 10,
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;
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) {
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;
18778 + tx->local->scan.txrx_count++;
18780 + return TXRX_CONTINUE;
18784 +static void ieee80211_rate_limit(unsigned long data)
18786 + struct ieee80211_local *local = (struct ieee80211_local *) data;
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);
18798 +static ieee80211_txrx_result
18799 +ieee80211_tx_h_rate_limit(struct ieee80211_txrx_data *tx)
18802 + if (likely(!tx->local->rate_limit || tx->u.tx.unicast))
18803 + return TXRX_CONTINUE;
18806 + if (tx->local->rate_limit_bucket) {
18807 + tx->local->rate_limit_bucket--;
18808 + return TXRX_CONTINUE;
18811 + I802_DEBUG_INC(tx->local->tx_handlers_drop_rate_limit);
18812 + return TXRX_DROP;
18816 +static ieee80211_txrx_result
18817 +ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
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 */
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;
18830 + if (tx->u.tx.ps_buffered)
18831 + return TXRX_CONTINUE;
18833 + sta_flags = tx->sta ? tx->sta->flags : 0;
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;
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)) {
18853 + * No associated STAs - no need to send multicast
18856 + return TXRX_DROP;
18858 + return TXRX_CONTINUE;
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));
18870 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
18871 + return TXRX_DROP;
18874 + return TXRX_CONTINUE;
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)
18884 + int total = 0, purged = 0;
18885 + struct sk_buff *skb;
18886 + struct list_head *ptr;
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)
18896 + ap = &sdata->u.ap;
18897 + skb = skb_dequeue(&ap->ps_bc_buf);
18900 + dev_kfree_skb(skb);
18902 + total += skb_queue_len(&ap->ps_bc_buf);
18904 + spin_unlock_bh(&local->sub_if_lock);
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);
18913 + dev_kfree_skb(skb);
18915 + total += skb_queue_len(&sta->ps_tx_buf);
18917 + spin_unlock_bh(&local->sta_lock);
18919 + local->total_ps_buffered = total;
18920 + printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
18921 + local->mdev->name, purged);
18925 +static inline ieee80211_txrx_result
18926 +ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
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",
18944 + dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
18946 + tx->local->total_ps_buffered++;
18947 + skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
18948 + return TXRX_QUEUED;
18951 + return TXRX_CONTINUE;
18955 +static inline ieee80211_txrx_result
18956 +ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
18958 + struct sta_info *sta = tx->sta;
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;
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 "
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));
18983 + dev_kfree_skb(old);
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;
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));
19000 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
19003 + return TXRX_CONTINUE;
19007 +static ieee80211_txrx_result
19008 +ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
19010 + if (unlikely(tx->u.tx.ps_buffered))
19011 + return TXRX_CONTINUE;
19013 + if (tx->u.tx.unicast)
19014 + return ieee80211_tx_h_unicast_ps_buf(tx);
19016 + return ieee80211_tx_h_multicast_ps_buf(tx);
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)
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;
19030 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19032 + memset(tx, 0, sizeof(*tx));
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;
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];
19065 +static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
19066 + struct ieee80211_tx_control *control, int mgmt)
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;
19075 + if (unlikely(skb->len < 10)) {
19076 + dev_kfree_skb(skb);
19080 + ieee80211_tx_prepare(&tx, skb, dev, control);
19082 + tx.u.tx.mgmt_interface = mgmt;
19084 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19085 + res = (*handler)(&tx);
19086 + if (res != TXRX_CONTINUE)
19090 + skb = tx.skb; /* handlers are allowed to change skb */
19093 + sta_info_release(local, sta);
19095 + if (unlikely(res == TXRX_DROP)) {
19096 + I802_DEBUG_INC(local->tx_handlers_drop);
19100 + if (unlikely(res == TXRX_QUEUED)) {
19101 + I802_DEBUG_INC(local->tx_handlers_queued);
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);
19111 +#endif /* IEEE80211_LEDS */
19112 + if (tx.u.tx.extra_frag) {
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
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;
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;
19143 + dur = ieee80211_duration(&tx, 0, next_len);
19144 + hdr->duration_id = cpu_to_le16(dur);
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],
19152 +#ifdef IEEE80211_LEDS
19153 + if (local->tx_led_counter++ == 0) {
19154 + ieee80211_tx_led(1, dev);
19156 +#endif /* IEEE80211_LEDS */
19157 + tx.u.tx.extra_frag[i] = NULL;
19159 + kfree(tx.u.tx.extra_frag);
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);
19176 +static int ieee80211_master_start_xmit(struct sk_buff *skb,
19177 + struct net_device *dev)
19179 + struct ieee80211_tx_control control;
19180 + struct ieee80211_tx_packet_data *pkt_data;
19181 + struct ieee80211_sub_if_data *sdata;
19184 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19187 + * copy control out of the skb so other people can use skb->cb
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;
19199 + ret = ieee80211_tx(dev, skb, &control,
19200 + control.sdata->type == IEEE80211_SUB_IF_TYPE_MGMT);
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
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
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).
19221 +static int ieee80211_subif_start_xmit(struct sk_buff *skb,
19222 + struct net_device *dev)
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;
19231 + int encaps_len, skip_header_bytes;
19232 + int nh_pos, h_pos, no_encrypt = 0;
19233 + struct sta_info *sta;
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);
19243 + nh_pos = skb->nh.raw - skb->data;
19244 + h_pos = skb->h.raw - skb->data;
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);
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);
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);
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);
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);
19300 + /* receiver is QoS enabled, use a QoS type frame */
19301 + sta = sta_info_get(local, hdr.addr1);
19303 + if (sta->flags & WLAN_STA_WME) {
19304 + fc |= WLAN_FC_STYPE_QOS_DATA << 4;
19307 + sta_info_release(local, sta);
19310 + hdr.frame_control = cpu_to_le16(fc);
19311 + hdr.duration_id = 0;
19312 + hdr.seq_ctrl = 0;
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;
19324 + encaps_data = NULL;
19328 + skb_pull(skb, skip_header_bytes);
19329 + nh_pos -= skip_header_bytes;
19330 + h_pos -= skip_header_bytes;
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
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)
19345 + head_need = hdrlen + encaps_len + (local->hw->extra_hdr_room ? 2 : 0);
19346 + head_need -= skb_headroom(skb);
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. */
19352 + if (head_need > 0 || skb_cloned(skb)) {
19354 + printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
19355 + "of headroom\n", dev->name, head_need);
19358 + if (skb_cloned(skb))
19359 + I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
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);
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;
19378 + memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
19379 + nh_pos += hdrlen;
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;
19387 + skb->dev = sdata->master;
19388 + sdata->stats.tx_packets++;
19389 + sdata->stats.tx_bytes += skb->len;
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;
19398 + dev_queue_xmit(skb);
19404 + dev_kfree_skb(skb);
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
19416 +ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
19418 + struct ieee80211_sub_if_data *sdata;
19419 + struct ieee80211_tx_packet_data *pkt_data;
19420 + struct ieee80211_hdr *hdr;
19423 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19425 + if (skb->len < 10) {
19426 + dev_kfree_skb(skb);
19430 + hdr = (struct ieee80211_hdr *) skb->data;
19431 + fc = le16_to_cpu(hdr->frame_control);
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;
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;
19441 + skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
19442 + skb->dev = sdata->master;
19445 + * We're using the protocol field of the the frame control header
19446 + * to request TX callback for hostapd. BIT(1) is checked.
19448 + if ((fc & BIT(1)) == BIT(1)) {
19449 + pkt_data->req_tx_status = 1;
19451 + hdr->frame_control = cpu_to_le16(fc);
19454 + pkt_data->do_not_encrypt = !(fc & WLAN_FC_ISWEP);
19456 + sdata->stats.tx_packets++;
19457 + sdata->stats.tx_bytes += skb->len;
19459 + dev_queue_xmit(skb);
19465 +static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
19466 + struct ieee80211_if_ap *bss,
19467 + struct sk_buff *skb)
19471 + int i, num_bits = 0, n1, n2;
19474 + /* Generate bitmap for TIM only if there are any STAs in power save
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)))
19484 + bitmap[(i + 1) / 8] |= 1 << (i + 1) % 8;
19488 + spin_unlock_bh(&local->sta_lock);
19491 + if (bss->dtim_count == 0)
19492 + bss->dtim_count = bss->dtim_period - 1;
19494 + bss->dtim_count--;
19496 + tim = pos = (u8 *) skb_put(skb, 6);
19497 + *pos++ = WLAN_EID_TIM;
19499 + *pos++ = bss->dtim_count;
19500 + *pos++ = bss->dtim_period;
19502 + if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) {
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. */
19511 + for (i = 0; i < sizeof(bitmap); i++) {
19518 + for (i = sizeof(bitmap) - 1; i >= n1; i--) {
19525 + /* Bitmap control */
19526 + *pos++ = n1 | (aid0 ? 1 : 0);
19527 + /* Part Virt Bitmap */
19528 + memcpy(pos, bitmap + n1, n2 - n1 + 1);
19530 + tim[1] = n2 - n1 + 4;
19531 + skb_put(skb, n2 - n1);
19533 + *pos++ = aid0 ? 1 : 0; /* Bitmap control */
19534 + *pos++ = 0; /* Part Virt Bitmap */
19539 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
19540 + struct ieee80211_tx_control *control)
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;
19552 + spin_lock_bh(&local->sub_if_lock);
19553 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count)
19556 + bdev = local->bss_devs[bss_idx];
19557 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19558 + ap = &sdata->u.ap;
19560 + spin_unlock_bh(&local->sub_if_lock);
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 */
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;
19577 + skb = dev_alloc_skb(bh_len + bt_len + 256 /* maximum TIM len */);
19581 + memcpy(skb_put(skb, bh_len), b_head, bh_len);
19583 + ieee80211_beacon_add_tim(local, ap, skb);
19586 + memcpy(skb_put(skb, bt_len), b_tail, bt_len);
19589 + memset(&extra, 0, sizeof(extra));
19590 + extra.endidx = local->num_curr_rates;
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);
19598 + dev_kfree_skb(skb);
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;
19612 + ap->num_beacons++;
19618 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
19619 + struct ieee80211_tx_control *control)
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;
19631 + spin_lock_bh(&local->sub_if_lock);
19632 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count) {
19636 + bdev = local->bss_devs[bss_idx];
19637 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19638 + bss = &sdata->u.ap;
19640 + spin_unlock_bh(&local->sub_if_lock);
19641 + if (bdev == NULL || bss == NULL || bss->beacon_head == NULL)
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));
19650 + local->total_ps_buffered--;
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);
19659 + ieee80211_tx_prepare(&tx, skb, dev, control);
19661 + tx.u.tx.ps_buffered = 1;
19663 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19664 + res = (*handler)(&tx);
19665 + if (res == TXRX_DROP || res == TXRX_QUEUED)
19669 + if (res == TXRX_DROP) {
19670 + I802_DEBUG_INC(local->tx_handlers_drop);
19671 + dev_kfree_skb(skb);
19673 + } else if (res == TXRX_QUEUED) {
19674 + I802_DEBUG_INC(local->tx_handlers_queued);
19679 + sta_info_release(local, sta);
19685 +int ieee80211_hw_config(struct net_device *dev)
19687 + struct ieee80211_local *local = dev->priv;
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 */
19696 + if (local->hw->config)
19697 + ret = local->hw->config(dev, &local->conf);
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);
19705 + local->curr_rates = mode->rates;
19706 + local->num_curr_rates = mode->num_rates;
19707 + ieee80211_prepare_rates(dev);
19716 +struct ieee80211_conf *ieee80211_get_hw_conf(struct net_device *dev)
19718 + struct ieee80211_local *local = dev->priv;
19719 + return &local->conf;
19723 +static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
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);
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;
19741 +static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
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);
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;
19759 +static void ieee80211_tx_timeout(struct net_device *dev)
19761 + struct ieee80211_local *local = dev->priv;
19763 + printk(KERN_WARNING "%s: resetting interface.\n", dev->name);
19765 + if (local->hw->reset(dev))
19766 + printk(KERN_ERR "%s: failed to reset interface.\n", dev->name);
19768 + netif_wake_queue(dev);
19772 +static int ieee80211_set_mac_address(struct net_device *dev, void *addr)
19774 + struct ieee80211_local *local = dev->priv;
19775 + struct sockaddr *a = addr;
19776 + struct list_head *ptr;
19779 + if (!local->hw->set_mac_address)
19780 + return -EOPNOTSUPP;
19782 + res = local->hw->set_mac_address(dev, addr);
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);
19796 +static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
19798 + struct ieee80211_sub_if_data *sdata;
19799 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19800 + return &(sdata->stats);
19804 +static int ieee80211_open(struct net_device *dev)
19806 + struct ieee80211_sub_if_data *sdata;
19807 + struct ieee80211_local *local = dev->priv;
19810 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19812 + if (local->open_count == 0) {
19813 + res = local->hw->open(sdata->master);
19816 + ieee80211_init_scan(sdata->master);
19818 + local->open_count++;
19820 + netif_start_queue(dev);
19825 +static int ieee80211_stop(struct net_device *dev)
19827 + struct ieee80211_sub_if_data *sdata;
19828 + struct ieee80211_local *local = dev->priv;
19831 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19833 + netif_stop_queue(dev);
19835 + local->open_count--;
19836 + if (local->open_count == 0) {
19837 + ieee80211_stop_scan(sdata->master);
19838 + res = local->hw->stop(sdata->master);
19847 +static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
19849 + memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
19854 +static struct net_device *
19855 +ieee80211_get_wds_dev(struct ieee80211_local *local, u8 *addr)
19857 + struct list_head *ptr;
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;
19871 +static struct net_device * ieee80211_own_bssid(struct ieee80211_local *local,
19875 + struct net_device *dev = NULL;
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)
19881 + dev = local->bss_devs[i];
19885 + spin_unlock_bh(&local->sub_if_lock);
19891 +static struct net_device * ieee80211_sta_bssid(struct ieee80211_local *local,
19892 + u8 *addr, u8 *a1,
19893 + int *sta_multicast)
19895 + struct list_head *ptr;
19897 + u8 *own_addr = local->mdev->dev_addr;
19899 + multicast = a1[0] & 0x01;
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;
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)
19928 + if (!multicast &&
19929 + memcmp(a1, sdata->dev->dev_addr, ETH_ALEN) != 0)
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;
19944 +static int ieee80211_own_addr(struct net_device *dev, u8 *addr)
19946 + struct ieee80211_local *local = dev->priv;
19947 + u8 *own = dev->dev_addr;
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])
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])
19965 +static ieee80211_txrx_result
19966 +ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
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;
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;
19979 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA))
19980 + return TXRX_CONTINUE;
19982 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
19983 + return TXRX_DROP;
19985 + hdrlen = ieee80211_get_hdrlen(fc);
19987 + /* convert IEEE 802.11 header + possible LLC headers into Ethernet
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
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);
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;
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);
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="
20022 + rx->dev->name, MAC2STR(hdr->addr1),
20023 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3),
20024 + MAC2STR(hdr->addr4));
20025 + return TXRX_DROP;
20028 + case WLAN_FC_FROMDS:
20029 + /* DA BSSID SA */
20030 + memcpy(dst, hdr->addr1, ETH_ALEN);
20031 + memcpy(src, hdr->addr3, ETH_ALEN);
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;
20041 + /* DA SA BSSID */
20042 + memcpy(dst, hdr->addr1, ETH_ALEN);
20043 + memcpy(src, hdr->addr2, ETH_ALEN);
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
20051 + dev->name, MAC2STR(hdr->addr1),
20052 + MAC2STR(hdr->addr2),
20053 + MAC2STR(hdr->addr3));
20055 + return TXRX_DROP;
20060 + payload = skb->data + hdrlen;
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);
20067 + return TXRX_DROP;
20070 + ethertype = (payload[6] << 8) | payload[7];
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);
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;
20091 + if (rx->sta && !rx->sta->assoc_ap &&
20092 + !(rx->sta && (rx->sta->flags & WLAN_STA_WDS)))
20093 + skb->dev = rx->sta->dev;
20098 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20101 + * don't count the master since the low level code
20102 + * counts it already for us.
20104 + if (skb->dev != sdata->master) {
20105 + sdata->stats.rx_packets++;
20106 + sdata->stats.rx_bytes += skb->len;
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);
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 "
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.
20133 + sta_info_release(local, dsta);
20138 + /* deliver to local stack */
20139 + skb->protocol = eth_type_trans(skb, dev);
20140 + memset(skb->cb, 0, sizeof(skb->cb));
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);
20151 + return TXRX_QUEUED;
20155 +static struct ieee80211_rate *
20156 +ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
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)
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))
20178 +ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
20179 + struct ieee80211_rx_status *status, u32 msg_type)
20181 + struct ieee80211_local *local = dev->priv;
20182 + struct ieee80211_frame_info *fi;
20184 + struct ieee80211_sub_if_data *sdata;
20186 + dev = local->apdev;
20189 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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);
20200 + hlen = sizeof(struct ieee80211_frame_info);
20201 + if (msg_type == ieee80211_msg_monitor)
20202 + hlen -= sizeof(fi->msg_type);
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);
20211 + struct timespec ts;
20212 + struct ieee80211_rate *rate;
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);
20222 + case MODE_IEEE80211B:
20223 + fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
20225 + case MODE_IEEE80211G:
20226 + fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
20228 + case MODE_ATHEROS_TURBO:
20230 + htonl(ieee80211_phytype_dsss_dot11_turbo);
20233 + fi->phytype = 0xAAAAAAAA;
20236 + fi->channel = htonl(status->channel);
20237 + rate = ieee80211_get_rate(local, status->phymode,
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 */
20247 + fi->preamble = htonl(0);
20249 + fi->datarate = htonl(0);
20250 + fi->preamble = htonl(0);
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;
20260 + fi->ssi_type = htonl(ieee80211_ssi_none);
20263 + sdata->stats.rx_packets++;
20264 + sdata->stats.rx_bytes += skb->len;
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));
20275 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
20278 + struct sk_buff *skb;
20279 + struct ieee80211_radar_info *msg;
20281 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20282 + sizeof(struct ieee80211_radar_info));
20286 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
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;
20294 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_radar);
20299 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
20302 + struct sk_buff *skb;
20303 + struct ieee80211_msg_set_aid_for_sta *msg;
20305 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20306 + sizeof(struct ieee80211_msg_set_aid_for_sta));
20310 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
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);
20317 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_set_aid_for_sta);
20322 +static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
20324 + struct ieee80211_sub_if_data *sdata;
20325 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20328 + atomic_inc(&sdata->bss->num_sta_ps);
20329 + sta->flags |= WLAN_STA_PS;
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 */
20338 +static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
20340 + struct ieee80211_local *local = dev->priv;
20341 + struct sk_buff *skb;
20343 + struct ieee80211_sub_if_data *sdata;
20344 + struct ieee80211_tx_packet_data *pkt_data;
20346 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20348 + atomic_dec(&sdata->bss->num_sta_ps);
20349 + sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
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;
20361 + pkt_data->requeue = 1;
20362 + dev_queue_xmit(skb);
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--;
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);
20381 +static ieee80211_txrx_result
20382 +ieee80211_rx_h_ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
20384 + struct sk_buff *skb;
20385 + int no_pending_pkts;
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;
20391 + skb = skb_dequeue(&rx->sta->tx_filtered);
20392 + if (skb == NULL) {
20393 + skb = skb_dequeue(&rx->sta->ps_tx_buf);
20395 + rx->local->total_ps_buffered--;
20397 + no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
20398 + skb_queue_empty(&rx->sta->ps_tx_buf);
20401 + struct ieee80211_hdr *hdr =
20402 + (struct ieee80211_hdr *) skb->data;
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;
20408 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20409 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS Poll (entries "
20411 + MAC2STR(rx->sta->addr), rx->sta->aid,
20412 + skb_queue_len(&rx->sta->ps_tx_buf));
20413 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
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;
20421 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
20423 + dev_queue_xmit(skb);
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 */
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);
20440 + return TXRX_QUEUED;
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)
20449 + struct ieee80211_fragment_entry *entry;
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;
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);
20472 + entry->skb = *skb;
20474 + entry->first_frag_time = jiffies;
20475 + entry->seq = seq;
20476 + entry->rx_queue = rx_queue;
20477 + entry->last_frag = frag;
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)
20489 + struct ieee80211_fragment_entry *entry;
20492 + idx = local->fragment_next;
20493 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
20494 + struct ieee80211_hdr *f_hdr;
20499 + idx = IEEE80211_FRAGMENT_MAX - 1;
20501 + entry = &local->fragments[idx];
20502 + if (!entry->skb || entry->seq != seq ||
20503 + entry->rx_queue != rx_queue ||
20504 + entry->last_frag + 1 != frag)
20507 + f_hdr = (struct ieee80211_hdr *) entry->skb->data;
20508 + f_fc = le16_to_cpu(f_hdr->frame_control);
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)
20515 + if (entry->first_frag_time + 2 * HZ < jiffies) {
20516 + dev_kfree_skb(entry->skb);
20517 + entry->skb = NULL;
20527 +static ieee80211_txrx_result
20528 +ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
20530 + struct ieee80211_hdr *hdr;
20532 + unsigned int frag, seq;
20533 + struct ieee80211_fragment_entry *entry;
20535 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20536 + sc = le16_to_cpu(hdr->seq_ctrl);
20537 + frag = WLAN_GET_SEQ_FRAG(sc);
20539 + if (likely((!(rx->fc & WLAN_FC_MOREFRAG) && frag == 0) ||
20540 + (rx->skb)->len < 24 || MULTICAST_ADDR(hdr->addr1))) {
20541 + /* not fragmented */
20544 + I802_DEBUG_INC(rx->local->rx_handlers_fragments);
20546 + seq = WLAN_GET_SEQ_SEQ(sc);
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. */
20557 + memcpy(entry->last_pn,
20558 + rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
20561 + return TXRX_QUEUED;
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.
20567 + entry = ieee80211_reassemble_find(rx->local, rx->fc, frag, seq,
20568 + rx->u.rx.queue, hdr);
20570 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20571 + return TXRX_DROP;
20574 + /* Verify that MPDUs within one MSDU have sequential PN values.
20575 + * (IEEE 802.11i, 8.3.3.4.5) */
20576 + if (entry->ccmp) {
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--) {
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;
20597 + memcpy(entry->last_pn, pn, CCMP_PN_LEN);
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,
20607 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20608 + return TXRX_DROP;
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);
20615 + if (rx->fc & WLAN_FC_MOREFRAG) {
20617 + return TXRX_QUEUED;
20620 + /* Complete frame has been reassembled - process it now */
20621 + rx->skb = entry->skb;
20622 + rx->fragmented = 1;
20623 + entry->skb = NULL;
20627 + rx->sta->rx_packets++;
20628 + if (MULTICAST_ADDR(hdr->addr1))
20629 + rx->local->dot11MulticastReceivedFrameCount++;
20630 +#ifdef IEEE80211_LEDS
20632 + ieee80211_rx_led(2, rx->dev);
20633 +#endif /* IEEE80211_LEDS */
20634 + return TXRX_CONTINUE;
20638 +static ieee80211_txrx_result
20639 +ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
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;
20647 + return TXRX_CONTINUE;
20651 +static ieee80211_txrx_result
20652 +ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
20654 + struct ieee80211_hdr *hdr;
20655 + int always_sta_key;
20656 + hdr = (struct ieee80211_hdr *) rx->skb->data;
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;
20667 + rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
20670 + if (rx->local->hw->rx_includes_fcs && rx->skb->len > FCS_LEN)
20671 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
20673 + if (unlikely(rx->skb->len < 16)) {
20674 + I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
20675 + return TXRX_DROP;
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;
20685 + /* Drop disallowed frame classes based on STA auth/assoc state;
20686 + * IEEE 802.11, Chap 5.5.
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.
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;
20703 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20704 + ieee80211_msg_sta_not_assoc);
20705 + return TXRX_QUEUED;
20708 + if (rx->local->conf.mode == IW_MODE_INFRA)
20709 + always_sta_key = 0;
20711 + always_sta_key = 1;
20713 + if (rx->sta && rx->sta->key && always_sta_key) {
20714 + rx->key = rx->sta->key;
20716 + if (!rx->sdata) {
20717 + printk(KERN_DEBUG "%s: sdata was null in packet!!\n",
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;
20727 + if (rx->sta && rx->sta->key)
20728 + rx->key = rx->sta->key;
20730 + rx->key = rx->sdata->default_key;
20732 + if (rx->local->hw->wep_include_iv &&
20733 + rx->fc & WLAN_FC_ISWEP) {
20734 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
20736 + if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
20737 + (rx->sta == NULL || rx->sta->key == NULL ||
20739 + rx->key = rx->sdata->keys[keyidx];
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;
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,
20767 + return TXRX_CONTINUE;
20771 +static ieee80211_txrx_result
20772 +ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
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;
20779 + return TXRX_CONTINUE;
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;
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.
20795 + sta->last_rx = jiffies;
20797 + sta->rx_fragments++;
20798 + sta->rx_bytes += rx->skb->len;
20799 + sta->last_rssi = rx->u.rx.status->ssi;
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);
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;
20823 + return TXRX_CONTINUE;
20827 +static ieee80211_txrx_result
20828 +ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
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;
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);
20840 + rx->sta->wep_weak_iv_count++;
20844 + return TXRX_CONTINUE;
20848 +static ieee80211_txrx_result
20849 +ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
20851 + /* If the device handles decryption totally, skip this test */
20852 + if (rx->local->hw->device_hides_wep)
20853 + return TXRX_CONTINUE;
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;
20863 + printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
20865 + return TXRX_DROP;
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;
20875 + } else if (rx->local->hw->wep_include_iv) {
20876 + ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
20878 + skb_trim(rx->skb, rx->skb->len - 4);
20881 + return TXRX_CONTINUE;
20885 +static ieee80211_txrx_result
20886 +ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
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;
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;
20912 + return TXRX_CONTINUE;
20916 +static ieee80211_txrx_result
20917 +ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
20919 + /* If the device handles decryption totally, skip this test */
20920 + if (rx->local->hw->device_hides_wep)
20921 + return TXRX_CONTINUE;
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;
20934 + return TXRX_CONTINUE;
20938 +static ieee80211_txrx_result
20939 +ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
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);
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);
20950 + return TXRX_QUEUED;
20954 +static ieee80211_txrx_result
20955 +ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
20957 + struct ieee80211_local *local = rx->local;
20958 + struct sk_buff *skb = rx->skb;
20960 + if (unlikely(local->sta_scanning != 0)) {
20961 + ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
20962 + return TXRX_QUEUED;
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;
20972 + local->scan.rx_packets++;
20974 + hdr = (struct ieee80211_hdr *) skb->data;
20975 + fc = le16_to_cpu(hdr->frame_control);
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);
20986 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20987 + ieee80211_msg_passive_scan);
20988 + return TXRX_QUEUED;
20990 + I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
20991 + return TXRX_DROP;
20995 + return TXRX_CONTINUE;
20999 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
21006 + fc = le16_to_cpu(hdr->frame_control);
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):
21015 + case WLAN_FC_FROMDS:
21016 + return hdr->addr2;
21018 + return hdr->addr3;
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;
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)
21039 + struct net_device *dev;
21042 + bssid = ieee80211_get_bssid(hdr, len);
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,
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);
21064 + /* Default to default device if nothing else matches */
21065 + return local->wdev;
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)
21074 + int keyidx, hdrlen;
21076 + hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
21077 + if (rx->skb->len >= hdrlen + 4)
21078 + keyidx = rx->skb->data[hdrlen + 3] >> 6;
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);
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));
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));
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. */
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));
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));
21131 + union iwreq_data wrqu;
21132 + char *buf = kmalloc(128, GFP_ATOMIC);
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);
21147 + /* TODO: consider verifying the MIC error report with software
21148 + * implementation if we get too many spurious reports from the
21150 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21151 + ieee80211_msg_michael_mic_failure);
21155 + dev_kfree_skb(rx->skb);
21160 +static void ieee80211_sta_rx_broadcast(struct ieee80211_txrx_data *rx)
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;
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);
21176 + memcpy(bssid, _bssid, ETH_ALEN);
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)))
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);
21196 + hdr = (struct ieee80211_hdr *) skb->data;
21198 + rx->dev = sdata->dev;
21199 + rx->sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
21202 + for (handler = local->rx_handlers; *handler != NULL; handler++)
21204 + res = (*handler)(rx);
21205 + if (res == TXRX_DROP || res == TXRX_QUEUED)
21209 + if (res == TXRX_DROP || *handler == NULL)
21210 + dev_kfree_skb(skb);
21213 + dev_kfree_skb(orig_skb);
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.
21221 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
21222 + struct ieee80211_rx_status *status)
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;
21231 + int sta_broadcast = 0;
21233 + hdr = (struct ieee80211_hdr *) skb->data;
21234 + memset(&rx, 0, sizeof(rx));
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);
21243 + memcmp(bssid, local->bssid, ETH_ALEN) == 0)
21245 + ieee80211_ibss_add_sta(dev, skb, bssid,
21249 + sta = rx.sta = NULL;
21250 + if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS))
21251 + rx.dev = sta->dev;
21253 + rx.dev = ieee80211_get_rx_dev(local, hdr, skb->len,
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);
21267 + if ((status->flag & RX_FLAG_MMIC_ERROR)) {
21268 + ieee80211_rx_michael_mic_report(dev, hdr, sta, &rx);
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);
21278 + sta->rx_dropped++;
21280 + if (res == TXRX_QUEUED)
21281 + I802_DEBUG_INC(local->rx_handlers_queued);
21285 + skb = rx.skb; /* handlers are allowed to change skb */
21287 + if (res == TXRX_DROP || *handler == NULL)
21288 + dev_kfree_skb(skb);
21292 + sta_info_release(local, sta);
21296 +static ieee80211_txrx_result
21297 +ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
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;
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 */
21308 + /* Estimate total channel use caused by this frame */
21310 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21311 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
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;
21320 + hdrtime = CHAN_UTIL_HDR_LONG;
21323 + if (!MULTICAST_ADDR(hdr->addr1))
21326 + if (tx->u.tx.control->use_rts_cts)
21327 + load += 2 * hdrtime;
21328 + else if (tx->u.tx.control->use_cts_protect)
21331 + load += skb->len * tx->u.tx.rate->rate_inv;
21333 + if (tx->u.tx.extra_frag) {
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;
21342 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21343 + load >>= CHAN_UTIL_SHIFT;
21344 + local->channel_use_raw += load;
21346 + tx->sta->channel_use_raw += load;
21347 + tx->sdata->channel_use_raw += load;
21349 + return TXRX_CONTINUE;
21353 +static ieee80211_txrx_result
21354 +ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
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;
21363 + /* Estimate total channel use caused by this frame */
21365 + if (unlikely(local->num_curr_rates < 0))
21366 + return TXRX_CONTINUE;
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];
21376 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21377 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
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;
21386 + hdrtime = CHAN_UTIL_HDR_LONG;
21389 + if (!MULTICAST_ADDR(hdr->addr1))
21392 + load += skb->len * rate->rate_inv;
21394 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21395 + load >>= CHAN_UTIL_SHIFT;
21396 + local->channel_use_raw += load;
21398 + rx->sta->channel_use_raw += load;
21399 + rx->sdata->channel_use_raw += load;
21401 + return TXRX_CONTINUE;
21405 +static void ieee80211_stat_refresh(unsigned long data)
21407 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21408 + struct list_head *ptr, *n;
21410 + if (!local->stat_time)
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;
21422 + spin_unlock_bh(&local->sta_lock);
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;
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;
21439 + local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
21440 + add_timer(&local->stat_timer);
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)
21449 + struct ieee80211_local *local = dev->priv;
21450 + struct ieee80211_rx_status *saved;
21453 + saved = kmalloc(sizeof(struct ieee80211_rx_status), GFP_ATOMIC);
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);
21463 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
21464 + struct ieee80211_tx_status *status)
21466 + struct ieee80211_local *local = dev->priv;
21467 + struct ieee80211_tx_status *saved;
21471 + saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
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));
21484 + dev_kfree_skb_irq(skb);
21486 + I802_DEBUG_INC(local->tx_status_drop);
21488 + tasklet_schedule(&local->tasklet);
21492 +static void ieee80211_tasklet_handler(unsigned long data)
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;
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",
21509 + dev_kfree_skb(skb);
21512 + /* Clear skb->type in order to not confuse kernel
21514 + skb->pkt_type = 0;
21515 + __ieee80211_rx(skb->dev, skb, rx_status);
21516 + kfree(rx_status);
21518 + case ieee80211_tx_status_msg:
21519 + memcpy(&tx_status, skb->cb, sizeof(tx_status));
21520 + if (!tx_status) {
21521 + dev_kfree_skb(skb);
21524 + skb->pkt_type = 0;
21525 + ieee80211_tx_status(skb->dev, skb, tx_status);
21526 + kfree(tx_status);
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);
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)
21547 + int hdrlen, iv_len, mic_len;
21548 + struct ieee80211_tx_packet_data *pkt_data;
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;
21561 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
21563 + switch (key->alg) {
21565 + iv_len = WEP_IV_LEN;
21566 + mic_len = WEP_ICV_LEN;
21569 + iv_len = TKIP_IV_LEN;
21570 + mic_len = TKIP_ICV_LEN;
21573 + iv_len = CCMP_HDR_LEN;
21574 + mic_len = CCMP_MIC_LEN;
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);
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);
21600 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
21601 + struct ieee80211_tx_status *status)
21603 + struct sk_buff *skb2;
21604 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21605 + struct ieee80211_local *local = dev->priv;
21611 + "%s: ieee80211_tx_status called with NULL status\n",
21613 + dev_kfree_skb(skb);
21617 + if (status->excessive_retries) {
21618 + struct sta_info *sta;
21619 + sta = sta_info_get(local, hdr->addr1);
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.
21625 + status->excessive_retries = 0;
21626 + status->tx_filtered = 1;
21628 + sta_info_release(local, sta);
21632 + if (status->tx_filtered) {
21633 + struct sta_info *sta;
21634 + sta = sta_info_get(local, hdr->addr1);
21636 + sta->tx_filtered_count++;
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
21642 + sta->clear_dst_mask = 1;
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,
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,
21662 + &status->control);
21663 + dev_queue_xmit(skb);
21665 + if (net_ratelimit()) {
21666 + printk(KERN_DEBUG "%s: dropped TX "
21667 + "filtered frame queue_len=%d "
21671 + &sta->tx_filtered),
21672 + !!(sta->flags & WLAN_STA_PS),
21675 + dev_kfree_skb(skb);
21677 + sta_info_release(local, sta);
21681 + rate_control_tx_status(dev, skb, status);
21684 +#ifdef IEEE80211_LEDS
21685 + if (local->tx_led_counter && (local->tx_led_counter-- == 1)) {
21686 + ieee80211_tx_led(0, dev);
21688 +#endif /* IEEE80211_LEDS */
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. */
21694 + frag = WLAN_GET_SEQ_FRAG(le16_to_cpu(hdr->seq_ctrl));
21695 + type = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_control));
21697 + if (status->ack) {
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++;
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++;
21717 + local->dot11FailedCount++;
21720 + if (!status->control.req_tx_status) {
21721 + dev_kfree_skb(skb);
21725 + msg_type = status->ack ? ieee80211_msg_tx_callback_ack :
21726 + ieee80211_msg_tx_callback_fail;
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);
21732 + dev_kfree_skb(skb);
21735 + dev_kfree_skb(skb);
21738 + /* Send frame to hostapd */
21739 + ieee80211_rx_mgmt(dev, skb, NULL, msg_type);
21743 +/* TODO: implement register/unregister functions for adding TX/RX handlers
21744 + * into ordered list */
21746 +static ieee80211_rx_handler ieee80211_rx_handlers[] =
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
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,
21773 +static ieee80211_tx_handler ieee80211_tx_handlers[] =
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,
21791 +static void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
21793 + /* Default values for sub-interface parameters */
21794 + sdata->drop_unencrypted = 0;
21795 + sdata->eapol = 1;
21799 +static struct net_device *ieee80211_if_add(struct net_device *dev,
21800 + const char *name, int locked)
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;
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;
21813 + wds_dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
21814 + if (wds_dev == NULL)
21817 + memset(wds_dev, 0, alloc_size);
21818 + wds_dev->priv = local;
21819 + ether_setup(wds_dev);
21820 + if (strlen(name) == 0) {
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)
21827 + dev_put(tmp_dev);
21828 + } while (i < 10000);
21830 + snprintf(wds_dev->name, IFNAMSIZ, "%s", name);
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;
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;
21859 + printk(KERN_DEBUG "%s: could not set BSS pointer for new "
21860 + "interface %s\n", dev->name, wds_dev->name);
21862 + ieee80211_if_sdata_init(sdata);
21865 + ret = register_netdevice(wds_dev);
21867 + ret = register_netdev(wds_dev);
21873 + list_add(&sdata->list, &local->sub_if_list);
21879 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
21880 + struct ieee80211_if_wds *wds, int locked)
21882 + struct net_device *wds_dev = NULL;
21883 + struct ieee80211_sub_if_data *sdata = NULL;
21885 + if (strlen(name) != 0) {
21886 + wds_dev = dev_get_by_name(name);
21888 + dev_put(wds_dev);
21893 + wds_dev = ieee80211_if_add(dev, name, locked);
21894 + if (wds_dev == NULL)
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));
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 */
21907 + ieee80211_proc_init_virtual(wds_dev);
21913 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
21914 + struct ieee80211_if_wds *wds, int locked)
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;
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;
21930 + if (wds_dev == NULL || sdata->type != IEEE80211_SUB_IF_TYPE_WDS)
21933 + /* Remove STA entry for the old peer */
21934 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
21936 + sta_info_release(local, sta);
21937 + sta_info_free(local, sta, 0);
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));
21945 + /* Update WDS link data */
21946 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
21952 +static void ieee80211_if_init(struct net_device *dev)
21954 + struct ieee80211_local *local = dev->priv;
21956 + spin_lock_init(&local->sub_if_lock);
21957 + INIT_LIST_HEAD(&local->sub_if_list);
21961 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
21962 + struct ieee80211_if_vlan *vlan, int locked)
21964 + struct net_device *vlan_dev = NULL;
21965 + struct ieee80211_sub_if_data *sdata = NULL;
21967 + if (strlen(name) != 0) {
21968 + vlan_dev = dev_get_by_name(name);
21970 + dev_put(vlan_dev);
21975 + vlan_dev = ieee80211_if_add(dev, name, locked);
21976 + if (vlan_dev == NULL)
21979 + sdata = IEEE80211_DEV_TO_SUB_IF(vlan_dev);
21980 + sdata->type = IEEE80211_SUB_IF_TYPE_VLAN;
21981 + ieee80211_proc_init_virtual(vlan_dev);
21986 +static void ieee80211_if_ap_init(struct ieee80211_sub_if_data *sdata)
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;
21997 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
22000 + struct ieee80211_local *local = dev->priv;
22001 + struct net_device *ap_dev = NULL;
22002 + struct ieee80211_sub_if_data *sdata = NULL;
22004 + if (local->bss_dev_count >= local->conf.bss_count)
22007 + if (strlen(name) != 0) {
22008 + ap_dev = dev_get_by_name(name);
22015 + ap_dev = ieee80211_if_add(dev, name, locked);
22016 + if (ap_dev == NULL)
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);
22032 +static void ieee80211_addr_inc(u8 *addr)
22035 + while (pos >= 0) {
22037 + if (addr[pos] != 0)
22044 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked)
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;
22052 + if (local->sta_dev_count >= local->conf.bss_count)
22055 + if (strlen(name) != 0) {
22056 + sta_dev = dev_get_by_name(name);
22058 + dev_put(sta_dev);
22063 + sta_dev = ieee80211_if_add(dev, name, locked);
22064 + if (sta_dev == NULL)
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);
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);
22080 + ieee80211_addr_inc(sta_dev->dev_addr);
22083 + printk(KERN_DEBUG "%s: MAC address " MACSTR "\n",
22084 + sta_dev->name, MAC2STR(sta_dev->dev_addr));
22088 + spin_unlock_bh(&local->sub_if_lock);
22090 + init_timer(&ifsta->timer);
22091 + ifsta->timer.data = (unsigned long) sta_dev;
22092 + ifsta->timer.function = ieee80211_sta_timer;
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;
22104 +static void ieee80211_if_del(struct ieee80211_local *local,
22105 + struct ieee80211_sub_if_data *sdata, int locked)
22107 + struct sta_info *sta;
22108 + u8 addr[ETH_ALEN];
22110 + struct list_head *ptr, *n;
22112 + memset(addr, 0xff, ETH_ALEN);
22113 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
22114 + if (!sdata->keys[i])
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);
22124 + kfree(sdata->keys[i]);
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,
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);
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 -
22158 + local->bss_devs[j] = NULL;
22159 + local->bss_dev_count--;
22163 + spin_unlock_bh(&local->sub_if_lock);
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);
22174 + case IEEE80211_SUB_IF_TYPE_WDS:
22175 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22177 + sta_info_release(local, sta);
22178 + sta_info_free(local, sta, 0);
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 */
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;
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--;
22211 + /* remove all STAs that are bound to this virtual interface */
22212 + sta_info_flush(local, sdata->dev);
22214 + list_del(&sdata->list);
22215 + ieee80211_proc_deinit_virtual(sdata->dev);
22217 + unregister_netdevice(sdata->dev);
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);
22229 +static int ieee80211_if_remove(struct net_device *dev, const char *name,
22230 + int id, int locked)
22232 + struct ieee80211_local *local = dev->priv;
22233 + struct list_head *ptr, *n;
22235 + /* Make sure not to touch sdata->master since it may
22236 + * have already been deleted, etc. */
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);
22242 + if (sdata->type == id && strcmp(name, sdata->dev->name) == 0) {
22243 + ieee80211_if_del(local, sdata, locked);
22252 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name,
22255 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_WDS,
22260 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name,
22263 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_VLAN,
22268 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name,
22271 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_AP,
22276 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name,
22279 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_STA,
22284 +int ieee80211_if_flush(struct net_device *dev, int locked)
22286 + struct ieee80211_local *local = dev->priv;
22287 + struct list_head *ptr, *n;
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);
22293 + if (sdata->dev != local->mdev &&
22294 + sdata->dev != local->wdev &&
22295 + sdata->dev != local->apdev)
22296 + ieee80211_if_del(local, sdata, locked);
22303 +static void ieee80211_precalc_rates(struct ieee80211_hw *hw)
22305 + struct ieee80211_hw_modes *mode;
22306 + struct ieee80211_rate *rate;
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;
22319 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
22320 + void (*setup)(struct net_device *))
22322 + struct net_device *dev, *apdev, *mdev;
22323 + struct ieee80211_local *local;
22324 + struct ieee80211_sub_if_data *sdata;
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.
22331 + * Sample memory map looks something like:
22333 + * 0000 *****************
22335 + * 015c *****************
22337 + * 017c *****************
22339 + * 0b84 *****************
22341 + * 1664 *****************
22343 + * 17c0 *****************
22345 + * *****************
22346 + * * master net_dev*
22347 + * *****************
22349 + * *****************
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 +
22360 + mdev = (struct net_device *) kzalloc(alloc_size, GFP_KERNEL);
22361 + if (mdev == NULL)
22364 + mdev->priv = (struct net_device *)
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;
22379 + ether_setup(dev);
22380 + memcpy(dev->name, "wlan%d", 7);
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;
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;
22400 + local->bridge_packets = 1;
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)
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)
22419 + local->sta_devs[0] = NULL;
22421 + local->scan.in_scan = 0;
22422 + local->hw_modes = (unsigned int) -1;
22424 + init_timer(&local->scan.timer); /* clear it out */
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);
22435 + sta_info_init(local);
22437 + ieee80211_if_init(dev);
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);
22447 + if (strlen(dev->name) + 2 >= sizeof(dev->name))
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);
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);
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);
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);
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);
22505 + ieee80211_free_hw(mdev);
22510 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw)
22512 + struct ieee80211_local *local = dev->priv;
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);
22525 + result = ieee80211_dev_alloc_index(local);
22529 + local->class_dev.dev = dev->class_dev.dev;
22530 + result = ieee80211_register_sysfs(local);
22534 + local->conf.mode = IW_MODE_MASTER;
22535 + local->conf.beacon_int = 1000;
22537 + ieee80211_update_hw(dev, hw); /* Don't care about the result. */
22539 + sta_info_start(local);
22541 + result = register_netdev(local->wdev);
22543 + goto fail_1st_dev;
22545 + result = register_netdev(local->apdev);
22547 + goto fail_2nd_dev;
22549 + if (hw->fraglist)
22550 + dev->features |= NETIF_F_FRAGLIST;
22551 + result = register_netdev(dev);
22553 + goto fail_3rd_dev;
22555 + if (rate_control_initialize(local) < 0) {
22556 + printk(KERN_DEBUG "%s: Failed to initialize rate control "
22557 + "algorithm\n", dev->name);
22561 + /* TODO: add rtnl locking around device creation and qdisc install */
22562 + ieee80211_install_qdisc(dev);
22564 + ieee80211_wep_init(local);
22565 + ieee80211_proc_init_interface(local);
22569 + unregister_netdev(dev);
22571 + unregister_netdev(local->apdev);
22573 + unregister_netdev(local->wdev);
22575 + sta_info_stop(local);
22576 + ieee80211_unregister_sysfs(local);
22578 + ieee80211_dev_free_index(local);
22582 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw)
22584 + struct ieee80211_local *local = dev->priv;
22588 + /* Backwards compatibility for low-level drivers that do not set number
22589 + * of TX queues. */
22590 + if (hw->queues == 0)
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;
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;
22605 + if (!hw->modes || !hw->modes->channels || !hw->modes->rates ||
22606 + !hw->modes->num_channels || !hw->modes->num_rates)
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);
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. */
22624 +void ieee80211_unregister_hw(struct net_device *dev)
22626 + struct ieee80211_local *local = dev->priv;
22627 + struct list_head *ptr, *n;
22630 + tasklet_disable(&local->tasklet);
22631 + /* TODO: skb_queue should be empty here, no need to do anything? */
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);
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);
22647 + sta_info_stop(local);
22648 + ieee80211_unregister_sysfs(local);
22650 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
22651 + if (local->fragments[i].skb)
22652 + dev_kfree_skb(local->fragments[i].skb);
22654 + for (i = 0; i < NUM_IEEE80211_MODES; i++) {
22655 + kfree(local->supp_rates[i]);
22656 + kfree(local->basic_rates[i]);
22659 + kfree(local->conf.ssid);
22660 + kfree(local->conf.generic_elem);
22662 + ieee80211_proc_deinit_interface(local);
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);
22670 + rate_control_free(local);
22671 + ieee80211_dev_free_index(local);
22674 +void ieee80211_free_hw(struct net_device *dev)
22676 + struct ieee80211_local *local = dev->priv;
22678 + kfree(local->sta_devs);
22679 + kfree(local->bss_devs);
22684 +/* Perform netif operations on all configured interfaces */
22685 +int ieee80211_netif_oper(struct net_device *sdev, Netif_Oper op)
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;
22692 + case NETIF_ATTACH:
22693 + netif_device_attach(dev);
22695 + case NETIF_DETACH:
22696 + netif_device_detach(dev);
22698 + case NETIF_START:
22699 + netif_start_queue(dev);
22704 + if (local->scan.in_scan == 0) {
22705 + netif_wake_queue(dev);
22707 + if (/* FIX: 802.11 qdisc in use */ 1)
22708 + __netif_schedule(dev);
22712 + case NETIF_IS_STOPPED:
22713 + if (netif_queue_stopped(dev))
22716 + case NETIF_UPDATE_TX_START:
22717 + dev->trans_start = jiffies;
22725 +void * ieee80211_dev_hw_data(struct net_device *dev)
22727 + struct ieee80211_local *local = dev->priv;
22728 + return local->hw_priv;
22732 +void * ieee80211_dev_stats(struct net_device *dev)
22734 + struct ieee80211_sub_if_data *sdata;
22735 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22736 + return &(sdata->stats);
22740 +int ieee80211_rate_control_register(struct rate_control_ops *ops)
22742 + struct rate_control_algs *alg;
22744 + alg = kmalloc(sizeof(*alg), GFP_KERNEL);
22745 + if (alg == NULL) {
22748 + memset(alg, 0, sizeof(*alg));
22749 + alg->next = ieee80211_rate_ctrl_algs;
22751 + ieee80211_rate_ctrl_algs = alg;
22757 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops)
22759 + struct rate_control_algs *alg, *prev;
22762 + alg = ieee80211_rate_ctrl_algs;
22764 + if (alg->ops == ops) {
22766 + prev->next = alg->next;
22768 + ieee80211_rate_ctrl_algs = alg->next;
22778 +static int rate_control_initialize(struct ieee80211_local *local)
22780 + struct rate_control_algs *algs;
22782 + if (!ieee80211_rate_ctrl_algs)
22783 + request_module("ieee80211_rate_control");
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);
22796 + printk(KERN_WARNING "%s: Failed to select rate control algorithm\n",
22797 + local->wdev->name);
22802 +static int __init ieee80211_init(void)
22804 + struct sk_buff *skb;
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));
22814 + if ((ret = ieee80211_sysfs_init())) {
22815 + printk(KERN_WARNING "ieee80211_init: sysfs initialization "
22820 + ieee80211_proc_init();
22822 + ret = ieee80211_wme_register();
22824 + printk(KERN_DEBUG "ieee80211_init: failed to "
22825 + "initialize WME (err=%d)\n", ret);
22826 + ieee80211_proc_deinit();
22835 +static void __exit ieee80211_exit(void)
22837 + ieee80211_wme_unregister();
22838 + ieee80211_proc_deinit();
22839 + ieee80211_sysfs_deinit();
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);
22867 +module_init(ieee80211_init);
22868 +module_exit(ieee80211_exit);
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
22877 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
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.
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"
22892 +struct ieee80211_dev_list {
22893 + struct list_head list;
22895 + struct ieee80211_local *local;
22898 +static LIST_HEAD(dev_list);
22899 +static DEFINE_SPINLOCK(dev_list_lock);
22902 +/* Caller must hold dev_list_lock */
22903 +static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
22905 + struct ieee80211_dev_list *dev_item;
22907 + list_for_each_entry(dev_item, &dev_list, list) {
22908 + if (dev_item->dev_index == index)
22914 +int ieee80211_dev_alloc_index(struct ieee80211_local *local)
22916 + struct list_head *i;
22917 + struct ieee80211_dev_list *dev_item, *new;
22920 + new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
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)
22931 + new->dev_index = index;
22932 + list_add_tail(&new->list, i);
22933 + spin_unlock(&dev_list_lock);
22934 + local->dev_index = index;
22938 +void ieee80211_dev_free_index(struct ieee80211_local *local)
22940 + struct ieee80211_dev_list *dev_item;
22942 + spin_lock(&dev_list_lock);
22943 + dev_item = __ieee80211_dev_find(local->dev_index);
22945 + list_del(&dev_item->list);
22946 + spin_unlock(&dev_list_lock);
22949 + local->dev_index = -1;
22952 +struct ieee80211_local *ieee80211_dev_find(int index)
22954 + struct ieee80211_dev_list *dev_item;
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;
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
22966 + * Copyright 2002-2005, Instant802 Networks, Inc.
22967 + * Copyright 2005, Devicescape Software, Inc.
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.
22974 +#ifndef IEEE80211_I_H
22975 +#define IEEE80211_I_H
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"
22987 +/* ieee80211.o internal definitions, etc. These are not included into
22988 + * low-level drivers. */
22991 +#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
22992 +#endif /* ETH_P_PAE */
22994 +#define IEEE80211_MAX_SSID_LEN 32
22996 +struct ieee80211_local;
22998 +#define BIT(x) (1 << (x))
23000 +#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
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
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
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"
23017 +#define MULTICAST_ADDR(a) ((a)[0] & 0x01)
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
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 */
23037 +struct ieee80211_sta_bss {
23038 + struct list_head list;
23039 + struct ieee80211_sta_bss *hnext;
23042 + u8 bssid[ETH_ALEN];
23043 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23045 + u16 capability; /* host byte order */
23051 + size_t wpa_ie_len;
23053 + size_t rsn_ie_len;
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;
23063 + unsigned long last_update;
23069 + TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
23070 +} ieee80211_txrx_result;
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 */
23083 + struct ieee80211_tx_control *control;
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;
23096 + /* Extra fragments (in addition to the first fragment
23098 + int num_extra_frag;
23099 + struct sk_buff **extra_frag;
23102 + struct ieee80211_rx_status *status;
23103 + int sent_ps_buffered;
23107 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23109 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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
23117 + int interval; /* time in seconds between scans */
23118 + int time; /* time in microseconds to scan for */
23119 + int channel; /* channel to be scanned */
23130 + struct timer_list timer;
23132 + struct sk_buff *skb; /* skb to transmit before changing channels,
23133 + * maybe null for none */
23134 + struct ieee80211_tx_control tx_control;
23136 + unsigned int num_scans;
23139 +typedef ieee80211_txrx_result (*ieee80211_tx_handler)
23140 +(struct ieee80211_txrx_data *tx);
23142 +typedef ieee80211_txrx_result (*ieee80211_rx_handler)
23143 +(struct ieee80211_txrx_data *rx);
23145 +struct ieee80211_if_ap {
23146 + u8 *beacon_head, *beacon_tail;
23147 + int beacon_head_len, beacon_tail_len;
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 */
23164 +struct ieee80211_if_wds {
23165 + u8 remote_addr[ETH_ALEN];
23166 + struct sta_info *sta;
23169 +struct ieee80211_if_vlan {
23173 +struct ieee80211_if_sta {
23175 + IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
23176 + IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
23177 + IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
23179 + struct timer_list timer;
23180 + u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
23181 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23184 + u16 ap_capab, capab;
23185 + u8 *extra_ie; /* to be added to the end of AssocReq */
23186 + size_t extra_ie_len;
23188 + /* The last AssocReq/Resp IEs */
23189 + u8 *assocreq_ies, *assocresp_ies;
23190 + size_t assocreq_ies_len, assocresp_ies_len;
23192 + int auth_tries, assoc_tries;
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;
23206 + unsigned long last_probe;
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;
23215 + unsigned long ibss_join_req;
23216 + struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
23217 + u32 supp_rates_bits;
23219 + int wmm_last_param_set;
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
23229 +struct ieee80211_sub_if_data {
23230 + struct list_head list;
23231 + unsigned int type;
23233 + struct net_device *dev;
23234 + struct net_device *master;
23235 + struct ieee80211_local *local;
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
23242 + int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
23245 +#define NUM_DEFAULT_KEYS 4
23246 + struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
23247 + struct ieee80211_key *default_key;
23249 + struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
23252 + struct ieee80211_if_ap ap;
23253 + struct ieee80211_if_wds wds;
23254 + struct ieee80211_if_vlan vlan;
23255 + struct ieee80211_if_sta sta;
23258 + int channel_use_raw;
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)))
23267 +struct ieee80211_local {
23268 + struct ieee80211_hw *hw;
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) */
23274 + struct ieee80211_conf conf;
23277 + struct class_device class_dev;
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;
23288 + ieee80211_rx_msg = 1,
23289 + ieee80211_tx_status_msg = 2
23290 + } ieee80211_msg_enum;
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;
23300 + /* Current rate table. This is a pointer to hw->modes structure. */
23301 + struct ieee80211_rate *curr_rates;
23302 + int num_curr_rates;
23304 + void *rate_ctrl_priv;
23305 + struct rate_control_ops *rate_ctrl;
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. */
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];
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 */
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. */
23329 + /* Fragment table for host-based reassembly */
23330 + struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
23331 + unsigned int fragment_next;
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 */
23337 + struct ieee80211_passive_scan scan;
23340 + ieee80211_rx_handler *rx_handlers;
23341 + ieee80211_tx_handler *tx_handlers;
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)
23375 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
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;
23391 + int tx_led_counter;
23394 + u32 channel_use_raw;
23396 + struct timer_list stat_timer;
23398 + u8 bssid[ETH_ALEN]; /* BSSID for STA modes (Adhoc/Managed) */
23399 + struct timer_list rate_limit_timer;
23401 + u32 rate_limit_burst;
23402 + u32 rate_limit_bucket;
23403 + struct proc_dir_entry *proc, *proc_sta, *proc_iface;
23405 + struct work_struct sta_proc_add;
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;
23413 + int rate_ctrl_num_up, rate_ctrl_num_down;
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 */
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
23451 + int allow_broadcast_always; /* whether to allow TX of broadcast frames
23452 + * even when there are no associated STAs
23455 + int wifi_wme_noack_test;
23456 + unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
23458 + unsigned int hw_modes; /* bitfield of allowed hardware modes;
23459 + * (1 << MODE_*) */
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,
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);
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;
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);
23495 +/* ieee80211_scan.c */
23496 +void ieee80211_init_scan(struct net_device *dev);
23497 +void ieee80211_stop_scan(struct net_device *dev);
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)
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,
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,
23546 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
23547 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
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);
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);
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
23566 + * Copyright 2002-2005, Instant802 Networks, Inc.
23567 + * Copyright 2005-2006, Devicescape Software, Inc.
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.
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>
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"
23593 +#include "aes_ccm.h"
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");
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
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");
23611 +static int ieee80211_ioctl_set_beacon(struct net_device *dev,
23612 + struct prism2_hostapd_param *param,
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;
23622 + len = ((char *) param->u.beacon.data - (char *) param) +
23623 + param->u.beacon.head_len + param->u.beacon.tail_len;
23625 + if (param_len > len)
23627 + else if (param_len != len)
23630 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23631 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
23633 + ap = &sdata->u.ap;
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;
23643 + printk(KERN_DEBUG "%s: unknown beacon flag %d\n",
23644 + dev->name, flag);
23653 + *b_head_len = param->u.beacon.head_len;
23654 + *b_tail_len = param->u.beacon.tail_len;
23656 + *b_head = kmalloc(*b_head_len, GFP_KERNEL);
23658 + memcpy(*b_head, param->u.beacon.data, *b_head_len);
23660 + printk(KERN_DEBUG "%s: failed to allocate beacon_head\n",
23665 + if (*b_tail_len > 0) {
23666 + *b_tail = kmalloc(*b_tail_len, GFP_KERNEL);
23668 + memcpy(*b_tail, param->u.beacon.data + (*b_head_len),
23671 + printk(KERN_DEBUG "%s: failed to allocate "
23672 + "beacon_tail\n", dev->name);
23681 +static int ieee80211_ioctl_get_hw_features(struct net_device *dev,
23682 + struct prism2_hostapd_param *param,
23685 + struct ieee80211_local *local = dev->priv;
23686 + u8 *pos = param->u.hw_features.data;
23687 + int left = param_len - (pos - (u8 *) param);
23689 + struct hostapd_ioctl_hw_modes_hdr *hdr;
23690 + struct ieee80211_rate_data *rate;
23691 + struct ieee80211_channel_data *chan;
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;
23697 + param->u.hw_features.num_modes = local->hw->num_modes;
23698 + for (mode = 0; mode < local->hw->num_modes; mode++) {
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)
23705 + left -= sizeof(*hdr) + clen + rlen;
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;
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;
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;
23733 +static int ieee80211_ioctl_scan(struct net_device *dev,
23734 + struct prism2_hostapd_param *param)
23736 + struct ieee80211_local *local = dev->priv;
23738 + if (local->hw->passive_scan == NULL)
23739 + return -EOPNOTSUPP;
23741 + if ((param->u.scan.now == 1) && (local->scan.in_scan == 1))
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);
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;
23763 + param->u.scan.last_rx = local->scan.rx_packets;
23764 + local->scan.rx_packets = -1;
23766 + param->u.scan.channel = local->hw->modes[local->scan.mode_idx].
23767 + channels[local->scan.chan_idx].chan;
23773 +static int ieee80211_ioctl_flush(struct net_device *dev,
23774 + struct prism2_hostapd_param *param)
23776 + struct ieee80211_local *local = dev->priv;
23777 + sta_info_flush(local, NULL);
23782 +static int ieee80211_ioctl_add_sta(struct net_device *dev,
23783 + struct prism2_hostapd_param *param)
23785 + struct ieee80211_local *local = dev->priv;
23786 + struct sta_info *sta;
23789 + struct ieee80211_sub_if_data *sdata;
23790 + int add_key_entry = 1;
23792 + sta = sta_info_get(local, param->sta_addr);
23794 + if (sta == NULL) {
23795 + sta = sta_info_add(local, dev, param->sta_addr);
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);
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
23812 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
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)
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;
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)
23829 + for (j = 0; j < local->num_curr_rates; j++) {
23830 + if (local->curr_rates[j].rate == rate)
23835 + sta->supp_rates = rates;
23837 + rate_control_rate_init(local, sta);
23839 + if (param->u.add_sta.wds_flags & 0x01)
23840 + sta->flags |= WLAN_STA_WDS;
23842 + sta->flags &= ~WLAN_STA_WDS;
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,
23855 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
23857 + sta->key_idx_compression = conf.hw_key_idx;
23861 + sta_info_release(local, sta);
23867 +static int ieee80211_ioctl_remove_sta(struct net_device *dev,
23868 + struct prism2_hostapd_param *param)
23870 + struct ieee80211_local *local = dev->priv;
23871 + struct sta_info *sta;
23873 + sta = sta_info_get(local, param->sta_addr);
23875 + sta_info_release(local, sta);
23876 + sta_info_free(local, sta, 1);
23879 + return sta ? 0 : -ENOENT;
23883 +static int ieee80211_ioctl_get_dot11counterstable(struct net_device *dev,
23884 + struct prism2_hostapd_param *param)
23886 + struct ieee80211_local *local = dev->priv;
23887 + struct ieee80211_low_level_stats stats;
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;
23915 +static int ieee80211_ioctl_get_info_sta(struct net_device *dev,
23916 + struct prism2_hostapd_param *param)
23918 + struct ieee80211_local *local = dev->priv;
23919 + struct sta_info *sta;
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;
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;
23937 + sta = sta_info_get(local, param->sta_addr);
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];
23960 + sta_info_release(local, sta);
23966 +static int ieee80211_ioctl_set_flags_sta(struct net_device *dev,
23967 + struct prism2_hostapd_param *param)
23969 + struct ieee80211_local *local = dev->priv;
23970 + struct sta_info *sta;
23972 + sta = sta_info_get(local, param->sta_addr);
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);
23991 + return sta ? 0 : -ENOENT;
23995 +int ieee80211_set_hw_encryption(struct net_device *dev,
23996 + struct sta_info *sta, u8 addr[ETH_ALEN],
23997 + struct ieee80211_key *key)
23999 + struct ieee80211_key_conf *keyconf = NULL;
24000 + struct ieee80211_local *local = dev->priv;
24003 + /* default to sw encryption; this will be cleared by low-level
24004 + * driver if the hw supports requested encryption */
24006 + key->force_sw_encrypt = 1;
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;
24017 + key->force_sw_encrypt =
24018 + keyconf->force_sw_encrypt;
24019 + key->hw_key_idx =
24020 + keyconf->hw_key_idx;
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)
24034 + struct ieee80211_local *local = dev->priv;
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;
24042 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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) {
24048 + if (idx >= NUM_DEFAULT_KEYS) {
24049 + printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
24053 + key = &sdata->keys[idx];
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 */)
24070 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP ||
24071 + dev != local->wdev)
24076 + printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
24077 + "individual key\n", dev->name);
24081 + sta = sta_info_get(local, sta_addr);
24082 + if (sta == NULL) {
24084 + *err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24085 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
24086 + printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
24088 + dev->name, MAC2STR(sta_addr));
24089 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
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
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).
24107 + if (!sta && alg == ALG_WEP && !local->default_wep_only &&
24108 + local->conf.mode != IW_MODE_ADHOC &&
24109 + local->conf.mode != IW_MODE_INFRA) {
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. */
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.
24126 + else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24127 + sta = sta_info_get(local, sdata->u.sta.bssid);
24129 + if (sta->flags & WLAN_STA_WME) {
24132 + sta_info_release(local, sta);
24138 + if (alg == ALG_NONE) {
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)) {
24145 + *err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24146 + printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
24147 + " failed\n", dev->name);
24152 + if (sdata->default_key == *key)
24153 + sdata->default_key = NULL;
24157 + if (*key == NULL || (*key)->keylen < key_len) {
24159 + *key = kmalloc(sizeof(struct ieee80211_key) +
24160 + key_len, GFP_ATOMIC);
24161 + if (*key == NULL) {
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;
24172 + (*key)->alg = alg;
24173 + (*key)->keyidx = idx;
24174 + (*key)->keylen = key_len;
24175 + memcpy((*key)->key, _key, key_len);
24177 + (*key)->default_tx_key = 1;
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
24183 + ieee80211_aes_key_setup_encrypt(
24184 + (*key)->u.ccmp.aes_state, (*key)->key);
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,
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);
24206 + sta_info_release(local, sta);
24212 +static int ieee80211_ioctl_set_encryption(struct net_device *dev,
24213 + struct prism2_hostapd_param *param,
24218 + param->u.crypt.err = 0;
24219 + param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
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",
24229 + if (strcmp(param->u.crypt.alg, "none") == 0)
24231 + else if (strcmp(param->u.crypt.alg, "WEP") == 0)
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);
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);
24250 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
24251 + printk(KERN_DEBUG "%s: set_encrypt - unknown alg\n",
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 + ¶m->u.crypt.err, param->u.crypt.key,
24261 + param->u.crypt.key_len);
24265 +static int ieee80211_ioctl_get_encryption(struct net_device *dev,
24266 + struct prism2_hostapd_param *param,
24269 + struct ieee80211_local *local = dev->priv;
24271 + struct sta_info *sta;
24272 + struct ieee80211_key **key;
24274 + struct ieee80211_sub_if_data *sdata;
24277 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24279 + param->u.crypt.err = 0;
24281 + max_key_len = param_len -
24282 + (int) ((char *) param->u.crypt.key - (char *) param);
24283 + if (max_key_len < 0)
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) {
24290 + if (param->u.crypt.idx > NUM_DEFAULT_KEYS) {
24291 + param->u.crypt.idx = sdata->default_key ?
24292 + sdata->default_key->keyidx : 0;
24295 + key = &sdata->keys[param->u.crypt.idx];
24297 + sta = sta_info_get(local, param->sta_addr);
24298 + if (sta == NULL) {
24299 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
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;
24312 + switch ((*key)->alg) {
24314 + memcpy(param->u.crypt.alg, "WEP", 4);
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,
24327 + IEEE80211_SEQ_COUNTER_TX,
24330 + /* Error getting value from device */
24334 + /* Get it from our own local data */
24335 + iv32 = (*key)->u.tkip.iv32;
24336 + iv16 = (*key)->u.tkip.iv16;
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;
24350 + memcpy(param->u.crypt.alg, "CCMP", 5);
24351 + pos = param->u.crypt.seq_counter;
24352 + pn = (*key)->u.ccmp.tx_pn;
24362 + memcpy(param->u.crypt.alg, "unknown", 8);
24366 + if (max_key_len < (*key)->keylen)
24369 + param->u.crypt.key_len = (*key)->keylen;
24370 + memcpy(param->u.crypt.key, (*key)->key,
24376 + sta_info_release(local, sta);
24382 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24383 +static int ieee80211_ioctl_wpa_trigger(struct net_device *dev,
24384 + struct prism2_hostapd_param *param)
24386 + struct ieee80211_local *local = dev->priv;
24387 + struct sta_info *sta;
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;
24396 + sta = sta_info_get(local, param->sta_addr);
24397 + if (sta == NULL) {
24398 + printk(KERN_DEBUG "%s: wpa_trigger - unknown addr\n",
24403 + sta->wpa_trigger = param->u.wpa_trigger.trigger;
24405 + sta_info_release(local, sta);
24408 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24411 +static int ieee80211_ioctl_set_rate_sets(struct net_device *dev,
24412 + struct prism2_hostapd_param *param,
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;
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;
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);
24431 + supp = (int *) kmalloc((num_supp + 1) * sizeof(int), GFP_KERNEL);
24432 + basic = (int *) kmalloc((num_basic + 1) * sizeof(int), GFP_KERNEL);
24434 + if (!supp || !basic) {
24440 + for (i = 0; i < num_supp; i++)
24441 + supp[i] = *pos++;
24444 + for (i = 0; i < num_basic; i++)
24445 + basic[i] = *pos++;
24448 + if (num_supp == 0) {
24453 + if (num_basic == 0) {
24458 + prev = local->supp_rates[mode];
24459 + local->supp_rates[mode] = supp;
24462 + prev = local->basic_rates[mode];
24463 + local->basic_rates[mode] = basic;
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
24470 + ieee80211_prepare_rates(dev);
24477 +static int ieee80211_ioctl_add_if(struct net_device *dev,
24478 + struct prism2_hostapd_param *param,
24481 + u8 *pos = param->u.if_info.data;
24482 + int left = param_len - ((u8 *) pos - (u8 *) param);
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;
24489 + if (left < sizeof(struct ieee80211_if_wds))
24492 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24494 + return ieee80211_if_add_wds(dev, param->u.if_info.name,
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;
24500 + if (left < sizeof(struct hostapd_if_vlan))
24503 + ivlan.id = vlan->id;
24505 + return ieee80211_if_add_vlan(dev, param->u.if_info.name,
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;
24511 + if (left < sizeof(struct hostapd_if_bss))
24514 + return ieee80211_if_add_ap(dev, param->u.if_info.name,
24516 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24518 + struct hostapd_if_sta *sta =
24519 + (struct hostapd_if_sta *) param->u.if_info.data;
24522 + if (left < sizeof(struct hostapd_if_sta))
24525 + return ieee80211_if_add_sta(dev, param->u.if_info.name, 1);
24533 +static int ieee80211_ioctl_remove_if(struct net_device *dev,
24534 + struct prism2_hostapd_param *param)
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);
24550 +static int ieee80211_ioctl_update_if(struct net_device *dev,
24551 + struct prism2_hostapd_param *param,
24554 + u8 *pos = param->u.if_info.data;
24555 + int left = param_len - ((u8 *) pos - (u8 *) param);
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;
24562 + if (left < sizeof(struct ieee80211_if_wds))
24565 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24567 + return ieee80211_if_update_wds(dev, param->u.if_info.name,
24570 + return -EOPNOTSUPP;
24575 +static int ieee80211_ioctl_flush_ifs(struct net_device *dev,
24576 + struct prism2_hostapd_param *param)
24578 + return ieee80211_if_flush(dev, 1);
24582 +static int ieee80211_ioctl_scan_req(struct net_device *dev,
24583 + struct prism2_hostapd_param *param,
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;
24590 + if (left < len || len > IEEE80211_MAX_SSID_LEN)
24593 + return ieee80211_sta_req_scan(dev, pos, len);
24597 +static int ieee80211_ioctl_sta_get_state(struct net_device *dev,
24598 + struct prism2_hostapd_param *param)
24600 + struct ieee80211_sub_if_data *sdata;
24602 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24603 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24605 + param->u.sta_get_state.state = sdata->u.sta.state;
24610 +static int ieee80211_ioctl_mlme(struct net_device *dev,
24611 + struct prism2_hostapd_param *param)
24613 + struct ieee80211_sub_if_data *sdata;
24615 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24616 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24618 + switch (param->u.mlme.cmd) {
24619 + case MLME_STA_DEAUTH:
24620 + ieee80211_sta_deauthenticate(dev, param->u.mlme.reason_code);
24622 + case MLME_STA_DISASSOC:
24623 + ieee80211_sta_disassociate(dev, param->u.mlme.reason_code);
24630 +static int ieee80211_ioctl_get_load_stats(struct net_device *dev,
24631 + struct prism2_hostapd_param *param)
24633 + struct ieee80211_local *local = dev->priv;
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 */
24643 +static int ieee80211_ioctl_set_sta_vlan(struct net_device *dev,
24644 + struct prism2_hostapd_param *param)
24646 + struct ieee80211_local *local = dev->priv;
24647 + struct sta_info *sta;
24649 + sta = sta_info_get(local, param->sta_addr);
24651 + struct net_device *new_vlan_dev;
24653 + dev_get_by_name(param->u.set_sta_vlan.vlan_name);
24654 + if (new_vlan_dev) {
24656 + printk("%s: Station " MACSTR " moved to vlan: %s\n",
24657 + dev->name, MAC2STR(param->sta_addr),
24658 + new_vlan_dev->name);
24660 + sta->dev = new_vlan_dev;
24661 + sta->vlan_id = param->u.set_sta_vlan.vlan_id;
24662 + dev_put(new_vlan_dev);
24664 + sta_info_release(local, sta);
24667 + return sta ? 0 : -ENOENT;
24671 +static int ieee80211_set_gen_ie(struct net_device *dev, u8 *ie, size_t len)
24673 + struct ieee80211_local *local = dev->priv;
24674 + struct ieee80211_sub_if_data *sdata;
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);
24680 + kfree(local->conf.generic_elem);
24681 + local->conf.generic_elem = kmalloc(len, GFP_KERNEL);
24682 + if (local->conf.generic_elem == NULL)
24684 + memcpy(local->conf.generic_elem, ie, len);
24685 + local->conf.generic_elem_len = len;
24687 + return ieee80211_hw_config(dev);
24692 +ieee80211_ioctl_set_generic_info_elem(struct net_device *dev,
24693 + struct prism2_hostapd_param *param,
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;
24703 + return ieee80211_set_gen_ie(dev, pos, len);
24707 +static int ieee80211_ioctl_set_regulatory_domain(struct net_device *dev,
24708 + struct prism2_hostapd_param *param)
24710 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24711 + conf->regulatory_domain = param->u.set_regulatory_domain.rd;
24716 +static int ieee80211_ioctl_set_adm_status(struct net_device *dev,
24719 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24720 + conf->adm_status = val;
24721 + return ieee80211_hw_config(dev);
24725 +ieee80211_ioctl_set_tx_queue_params(struct net_device *dev,
24726 + struct prism2_hostapd_param *param)
24728 + struct ieee80211_local *local = dev->priv;
24729 + struct ieee80211_tx_queue_params qparam;
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;
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;
24743 + return local->hw->conf_tx(dev, param->u.tx_queue_params.queue,
24748 +static int ieee80211_ioctl_get_tx_stats(struct net_device *dev,
24749 + struct prism2_hostapd_param *param)
24751 + struct ieee80211_local *local = dev->priv;
24752 + struct ieee80211_tx_queue_stats stats;
24755 + if (!local->hw->get_tx_stats)
24756 + return -EOPNOTSUPP;
24758 + memset(&stats, 0, sizeof(stats));
24759 + ret = local->hw->get_tx_stats(dev, &stats);
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;
24773 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
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;
24783 + for (i = 0; i < conf->bss_count; i++) {
24784 + if (local->bss_devs[i])
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);
24794 + bss_devs = kmalloc(new_count * sizeof(struct net_device *),
24796 + if (bss_devs == NULL)
24798 + sta_devs = kmalloc(new_count * sizeof(struct net_device *),
24800 + if (sta_devs == NULL) {
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 *));
24812 + memcpy(conf->bssid_mask, bssid_mask, ETH_ALEN);
24814 + prev = local->bss_devs;
24815 + local->bss_devs = bss_devs;
24816 + conf->bss_count = new_count;
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;
24825 + spin_unlock_bh(&local->sub_if_lock);
24827 + kfree(prev_sta_devs);
24829 + return ieee80211_hw_config(dev);
24832 +static int ieee80211_ioctl_set_bss(struct net_device *dev,
24833 + struct prism2_hostapd_param *param)
24835 + return ieee80211_set_bss_count(dev, param->u.set_bss.bss_count,
24836 + param->u.set_bss.bssid_mask);
24840 +static int ieee80211_ioctl_set_channel_flag(struct net_device *dev,
24841 + struct prism2_hostapd_param *param)
24843 + struct ieee80211_local *local = dev->priv;
24844 + struct ieee80211_hw_modes *mode = NULL;
24845 + struct ieee80211_channel *chan = NULL;
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)
24858 + for (i = 0; i < mode->num_channels; i++) {
24859 + chan = &mode->channels[i];
24860 + if (chan->chan == param->u.set_channel_flag.chan)
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;
24876 +static int ieee80211_ioctl_set_quiet_params(struct net_device *dev,
24877 + struct prism2_hostapd_param *param)
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;
24887 +static int ieee80211_ioctl_set_radar_params(struct net_device *dev,
24888 + struct prism2_hostapd_param *param)
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;
24900 +static int ieee80211_ioctl_priv_hostapd(struct net_device *dev,
24901 + struct iw_point *p)
24903 + struct prism2_hostapd_param *param;
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);
24915 + param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
24916 + if (param == NULL)
24919 + if (copy_from_user(param, p->pointer, p->length)) {
24924 + switch (param->cmd) {
24925 + case PRISM2_HOSTAPD_FLUSH:
24926 + ret = ieee80211_ioctl_flush(dev, param);
24928 + case PRISM2_HOSTAPD_ADD_STA:
24929 + ret = ieee80211_ioctl_add_sta(dev, param);
24931 + case PRISM2_HOSTAPD_REMOVE_STA:
24932 + ret = ieee80211_ioctl_remove_sta(dev, param);
24934 + case PRISM2_HOSTAPD_GET_INFO_STA:
24935 + ret = ieee80211_ioctl_get_info_sta(dev, param);
24937 + case PRISM2_SET_ENCRYPTION:
24938 + ret = ieee80211_ioctl_set_encryption(dev, param, p->length);
24940 + case PRISM2_GET_ENCRYPTION:
24941 + ret = ieee80211_ioctl_get_encryption(dev, param, p->length);
24943 + case PRISM2_HOSTAPD_SET_FLAGS_STA:
24944 + ret = ieee80211_ioctl_set_flags_sta(dev, param);
24946 + case PRISM2_HOSTAPD_SET_BEACON:
24947 + ret = ieee80211_ioctl_set_beacon(dev, param, p->length, 0);
24949 + case PRISM2_HOSTAPD_GET_HW_FEATURES:
24950 + ret = ieee80211_ioctl_get_hw_features(dev, param, p->length);
24952 + case PRISM2_HOSTAPD_SCAN:
24953 + ret = ieee80211_ioctl_scan(dev, param);
24955 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24956 + case PRISM2_HOSTAPD_WPA_TRIGGER:
24957 + ret = ieee80211_ioctl_wpa_trigger(dev, param);
24959 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24960 + case PRISM2_HOSTAPD_SET_RATE_SETS:
24961 + ret = ieee80211_ioctl_set_rate_sets(dev, param, p->length);
24963 + case PRISM2_HOSTAPD_ADD_IF:
24964 + ret = ieee80211_ioctl_add_if(dev, param, p->length);
24966 + case PRISM2_HOSTAPD_REMOVE_IF:
24967 + ret = ieee80211_ioctl_remove_if(dev, param);
24969 + case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE:
24970 + ret = ieee80211_ioctl_get_dot11counterstable(dev, param);
24972 + case PRISM2_HOSTAPD_GET_LOAD_STATS:
24973 + ret = ieee80211_ioctl_get_load_stats(dev, param);
24975 + case PRISM2_HOSTAPD_SET_STA_VLAN:
24976 + ret = ieee80211_ioctl_set_sta_vlan(dev, param);
24978 + case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM:
24979 + ret = ieee80211_ioctl_set_generic_info_elem(dev, param,
24982 + case PRISM2_HOSTAPD_SET_CHANNEL_FLAG:
24983 + ret = ieee80211_ioctl_set_channel_flag(dev, param);
24985 + case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN:
24986 + ret = ieee80211_ioctl_set_regulatory_domain(dev, param);
24988 + case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS:
24989 + ret = ieee80211_ioctl_set_tx_queue_params(dev, param);
24991 + case PRISM2_HOSTAPD_SET_BSS:
24992 + ret = ieee80211_ioctl_set_bss(dev, param);
24994 + case PRISM2_HOSTAPD_GET_TX_STATS:
24995 + ret = ieee80211_ioctl_get_tx_stats(dev, param);
24997 + case PRISM2_HOSTAPD_UPDATE_IF:
24998 + ret = ieee80211_ioctl_update_if(dev, param, p->length);
25000 + case PRISM2_HOSTAPD_SCAN_REQ:
25001 + ret = ieee80211_ioctl_scan_req(dev, param, p->length);
25003 + case PRISM2_STA_GET_STATE:
25004 + ret = ieee80211_ioctl_sta_get_state(dev, param);
25006 + case PRISM2_HOSTAPD_MLME:
25007 + ret = ieee80211_ioctl_mlme(dev, param);
25009 + case PRISM2_HOSTAPD_FLUSH_IFS:
25010 + ret = ieee80211_ioctl_flush_ifs(dev, param);
25012 + case PRISM2_HOSTAPD_SET_RADAR_PARAMS:
25013 + ret = ieee80211_ioctl_set_radar_params(dev, param);
25015 + case PRISM2_HOSTAPD_SET_QUIET_PARAMS:
25016 + ret = ieee80211_ioctl_set_quiet_params(dev, param);
25019 + ret = -EOPNOTSUPP;
25023 + if (copy_to_user(p->pointer, param, p->length))
25033 +static int ieee80211_ioctl_giwname(struct net_device *dev,
25034 + struct iw_request_info *info,
25035 + char *name, char *extra)
25037 + struct ieee80211_local *local = dev->priv;
25039 + switch (local->conf.phymode) {
25040 + case MODE_IEEE80211A:
25041 + strcpy(name, "IEEE 802.11a");
25043 + case MODE_IEEE80211B:
25044 + strcpy(name, "IEEE 802.11b");
25046 + case MODE_IEEE80211G:
25047 + strcpy(name, "IEEE 802.11g");
25049 + case MODE_ATHEROS_TURBO:
25050 + strcpy(name, "5GHz Turbo");
25053 + strcpy(name, "IEEE 802.11");
25061 +static int ieee80211_ioctl_giwrange(struct net_device *dev,
25062 + struct iw_request_info *info,
25063 + struct iw_point *data, char *extra)
25065 + struct iw_range *range = (struct iw_range *) extra;
25067 + data->length = sizeof(struct iw_range);
25068 + memset(range, 0, sizeof(struct iw_range));
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;
25085 +struct ieee80211_channel_range {
25086 + short start_freq;
25088 + unsigned char power_level;
25089 + unsigned char antenna_max;
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 */,
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 */,
25108 +static const struct ieee80211_channel_range *channel_range =
25109 + ieee80211_fcc_channels;
25112 +static void ieee80211_unmask_channel(struct net_device *dev, int mode,
25113 + struct ieee80211_channel *chan)
25119 + if (ieee80211_regdom == 64 &&
25120 + (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
25121 + /* Do not allow Turbo modes in Japan. */
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) {
25131 + * Skip new channels in Japan since the
25132 + * firmware was not marked having been upgraded
25138 + if (ieee80211_regdom == 0x10 &&
25139 + (chan->freq == 5190 || chan->freq == 5210 ||
25140 + chan->freq == 5230)) {
25141 + /* Skip MKK channels when in FCC domain. */
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;
25151 + if (ieee80211_regdom == 64 &&
25152 + (chan->freq == 5170 || chan->freq == 5190 ||
25153 + chan->freq == 5210 || chan->freq == 5230)) {
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.
25160 + chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
25163 + if (ieee80211_regdom == 64 &&
25164 + (chan->freq == 5260 || chan->freq == 5280 ||
25165 + chan->freq == 5300 || chan->freq == 5320)) {
25167 + * IBSS is not allowed on 5.25-5.35 GHz band
25168 + * due to radar detection requirements.
25170 + chan->flag &= ~IEEE80211_CHAN_W_IBSS;
25179 +static int ieee80211_unmask_channels(struct net_device *dev)
25181 + struct ieee80211_local *local = dev->priv;
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]);
25195 +static int ieee80211_init_client(struct net_device *dev)
25197 + if (ieee80211_regdom == 0x40)
25198 + channel_range = ieee80211_mkk_channels;
25199 + ieee80211_unmask_channels(dev);
25200 + ieee80211_ioctl_set_adm_status(dev, 1);
25205 +static int ieee80211_is_client_mode(int iw_mode)
25207 + return (iw_mode == IW_MODE_INFRA || iw_mode == IW_MODE_ADHOC);
25211 +static int ieee80211_ioctl_siwmode(struct net_device *dev,
25212 + struct iw_request_info *info,
25213 + __u32 *mode, char *extra)
25215 + struct ieee80211_local *local = dev->priv;
25217 + if (!ieee80211_is_client_mode(local->conf.mode) &&
25218 + ieee80211_is_client_mode(*mode)) {
25219 + ieee80211_init_client(dev);
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
25230 + sdata->drop_unencrypted = 0;
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;
25238 + local->conf.mode = *mode;
25239 + return ieee80211_hw_config(dev);
25243 +static int ieee80211_ioctl_giwmode(struct net_device *dev,
25244 + struct iw_request_info *info,
25245 + __u32 *mode, char *extra)
25247 + struct ieee80211_local *local = dev->priv;
25248 + struct ieee80211_sub_if_data *sdata;
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;
25255 + *mode = IW_MODE_INFRA;
25257 + *mode = local->conf.mode;
25262 +int ieee80211_ioctl_siwfreq(struct net_device *dev,
25263 + struct iw_request_info *info,
25264 + struct iw_freq *freq, char *extra)
25266 + struct ieee80211_local *local = dev->priv;
25267 + int m, c, nfreq, set = 0;
25269 + /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
25270 + if (freq->e == 0)
25273 + int i, div = 1000000;
25274 + for (i = 0; i < freq->e; i++)
25277 + nfreq = freq->m / div;
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)
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;
25307 + local->sta_scanning = 0; /* Abort possible scan */
25308 + return ieee80211_hw_config(dev);
25315 +static int ieee80211_ioctl_giwfreq(struct net_device *dev,
25316 + struct iw_request_info *info,
25317 + struct iw_freq *freq, char *extra)
25319 + struct ieee80211_local *local = dev->priv;
25321 + /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
25322 + * driver for the current channel with firmware-based management */
25324 + freq->m = local->conf.freq;
25331 +static int ieee80211_ioctl_siwessid(struct net_device *dev,
25332 + struct iw_request_info *info,
25333 + struct iw_point *data, char *ssid)
25335 + struct ieee80211_local *local = dev->priv;
25336 + struct ieee80211_sub_if_data *sdata;
25337 + size_t len = data->length;
25339 + /* iwconfig uses nul termination in SSID.. */
25340 + if (len > 0 && ssid[len - 1] == '\0')
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);
25347 + kfree(local->conf.ssid);
25348 + local->conf.ssid = kmalloc(len + 1, GFP_KERNEL);
25349 + if (local->conf.ssid == NULL)
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);
25358 +static int ieee80211_ioctl_giwessid(struct net_device *dev,
25359 + struct iw_request_info *info,
25360 + struct iw_point *data, char *ssid)
25362 + struct ieee80211_local *local = dev->priv;
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);
25370 + data->length = len;
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;
25383 +static int ieee80211_ioctl_siwap(struct net_device *dev,
25384 + struct iw_request_info *info,
25385 + struct sockaddr *ap_addr, char *extra)
25387 + struct ieee80211_local *local = dev->priv;
25388 + struct ieee80211_sub_if_data *sdata;
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,
25395 + changed_bssid = 1;
25396 + memcpy(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
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);
25402 + return ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
25405 + return -EOPNOTSUPP;
25409 +static int ieee80211_ioctl_giwap(struct net_device *dev,
25410 + struct iw_request_info *info,
25411 + struct sockaddr *ap_addr, char *extra)
25413 + struct ieee80211_sub_if_data *sdata;
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);
25422 + return -EOPNOTSUPP;
25426 +static int ieee80211_ioctl_siwscan(struct net_device *dev,
25427 + struct iw_request_info *info,
25428 + struct iw_point *data, char *extra)
25430 + struct ieee80211_local *local = dev->priv;
25432 + size_t ssid_len = 0;
25434 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
25435 + ssid = local->conf.ssid;
25436 + ssid_len = local->conf.ssid_len;
25438 + return ieee80211_sta_req_scan(dev, ssid, ssid_len);
25442 +static int ieee80211_ioctl_giwscan(struct net_device *dev,
25443 + struct iw_request_info *info,
25444 + struct iw_point *data, char *extra)
25447 + struct ieee80211_local *local = dev->priv;
25448 + if (local->sta_scanning)
25450 + res = ieee80211_sta_scan_results(dev, extra, IW_SCAN_MAX_DATA);
25452 + data->length = res;
25455 + data->length = 0;
25460 +static int ieee80211_ioctl_siwrts(struct net_device *dev,
25461 + struct iw_request_info *info,
25462 + struct iw_param *rts, char *extra)
25464 + struct ieee80211_local *local = dev->priv;
25466 + if (rts->disabled)
25467 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
25468 + else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
25471 + local->rts_threshold = rts->value;
25473 + /* If the wlan card performs RTS/CTS in hardware/firmware,
25474 + * configure it here */
25476 + if (local->hw->set_rts_threshold) {
25477 + local->hw->set_rts_threshold(dev, local->rts_threshold);
25483 +static int ieee80211_ioctl_giwrts(struct net_device *dev,
25484 + struct iw_request_info *info,
25485 + struct iw_param *rts, char *extra)
25487 + struct ieee80211_local *local = dev->priv;
25489 + rts->value = local->rts_threshold;
25490 + rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
25497 +static int ieee80211_ioctl_siwfrag(struct net_device *dev,
25498 + struct iw_request_info *info,
25499 + struct iw_param *frag, char *extra)
25501 + struct ieee80211_local *local = dev->priv;
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)
25509 + /* Fragment length must be even, so strip LSB. */
25510 + local->fragmentation_threshold = frag->value & ~0x1;
25513 + /* If the wlan card performs fragmentation in hardware/firmware,
25514 + * configure it here */
25516 + if (local->hw->set_frag_threshold) {
25517 + local->hw->set_frag_threshold(
25518 + dev, local->fragmentation_threshold);
25524 +static int ieee80211_ioctl_giwfrag(struct net_device *dev,
25525 + struct iw_request_info *info,
25526 + struct iw_param *frag, char *extra)
25528 + struct ieee80211_local *local = dev->priv;
25530 + frag->value = local->fragmentation_threshold;
25531 + frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
25538 +static int ieee80211_ioctl_siwretry(struct net_device *dev,
25539 + struct iw_request_info *info,
25540 + struct iw_param *retry, char *extra)
25542 + struct ieee80211_local *local = dev->priv;
25544 + if (retry->disabled ||
25545 + (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
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;
25553 + local->long_retry_limit = retry->value;
25554 + local->short_retry_limit = retry->value;
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);
25567 +static int ieee80211_ioctl_giwretry(struct net_device *dev,
25568 + struct iw_request_info *info,
25569 + struct iw_param *retry, char *extra)
25571 + struct ieee80211_local *local = dev->priv;
25573 + retry->disabled = 0;
25574 + if ((retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25576 + if (retry->flags & IW_RETRY_MAX) {
25577 + retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
25578 + retry->value = local->long_retry_limit;
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;
25590 +static void ieee80211_ioctl_unmask_channels(struct ieee80211_local *local)
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;
25604 +static int ieee80211_ioctl_test_mode(struct net_device *dev, int mode)
25606 + struct ieee80211_local *local = dev->priv;
25607 + int ret = -EOPNOTSUPP;
25609 + if (mode == IEEE80211_TEST_UNMASK_CHANNELS) {
25610 + ieee80211_ioctl_unmask_channels(local);
25614 + if (local->hw->test_mode)
25615 + ret = local->hw->test_mode(dev, mode);
25621 +static int ieee80211_ioctl_clear_keys(struct net_device *dev)
25623 + struct ieee80211_local *local = dev->priv;
25624 + struct ieee80211_key_conf key;
25625 + struct list_head *ptr;
25627 + u8 addr[ETH_ALEN];
25628 + struct ieee80211_key_conf *keyconf;
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++) {
25636 + if (sdata->keys[i] &&
25637 + !sdata->keys[i]->force_sw_encrypt &&
25638 + local->hw->set_key &&
25639 + (keyconf = ieee80211_key_data2conf(local,
25642 + local->hw->set_key(dev, DISABLE_KEY, addr,
25645 + kfree(sdata->keys[i]);
25646 + sdata->keys[i] = NULL;
25648 + sdata->default_key = NULL;
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);
25656 + if (sta->key && !sta->key->force_sw_encrypt &&
25657 + local->hw->set_key &&
25658 + (keyconf = ieee80211_key_data2conf(local, sta->key))
25660 + local->hw->set_key(dev, DISABLE_KEY, sta->addr,
25661 + keyconf, sta->aid);
25666 + spin_unlock_bh(&local->sta_lock);
25668 + memset(&key, 0, sizeof(key));
25669 + if (local->hw->set_key &&
25670 + local->hw->set_key(dev, REMOVE_ALL_KEYS, NULL,
25672 + printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
25680 +ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
25681 + struct ieee80211_sub_if_data *sdata,
25684 + struct ieee80211_local *local = dev->priv;
25687 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25691 + sdata->u.ap.force_unicast_rateidx = -1;
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;
25706 +ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
25707 + struct ieee80211_sub_if_data *sdata,
25710 + struct ieee80211_local *local = dev->priv;
25713 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25717 + sdata->u.ap.max_ratectrl_rateidx = -1;
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;
25731 +static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
25732 + struct ieee80211_key *key)
25734 + struct ieee80211_key_conf *keyconf;
25735 + u8 addr[ETH_ALEN];
25737 + if (key == NULL || key->alg != ALG_WEP || !key->force_sw_encrypt ||
25738 + local->hw->device_hides_wep)
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;
25752 +static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
25753 + struct ieee80211_key *key)
25755 + struct ieee80211_key_conf *keyconf;
25756 + u8 addr[ETH_ALEN];
25758 + if (key == NULL || key->alg != ALG_WEP || key->force_sw_encrypt ||
25759 + local->hw->device_hides_wep)
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);
25767 + key->force_sw_encrypt = 1;
25771 +static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
25775 + struct list_head *ptr;
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++) {
25783 + ieee80211_key_enable_hwaccel(local,
25786 + ieee80211_key_disable_hwaccel(local,
25796 +static int ieee80211_ioctl_prism2_param(struct net_device *dev,
25797 + struct iw_request_info *info,
25798 + void *wrqu, char *extra)
25800 + struct ieee80211_local *local = dev->priv;
25801 + struct ieee80211_sub_if_data *sdata;
25802 + int *i = (int *) extra;
25804 + int value = *(i + 1);
25807 + if (!capable(CAP_NET_ADMIN))
25810 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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 */
25819 + case PRISM2_PARAM_BEACON_INT:
25820 + local->conf.beacon_int = value;
25821 + if (ieee80211_hw_config(dev))
25825 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
25826 + local->bridge_packets = value;
25829 + case PRISM2_PARAM_AP_AUTH_ALGS:
25830 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25831 + sdata->u.sta.auth_algs = value;
25833 + ret = -EOPNOTSUPP;
25836 + case PRISM2_PARAM_DTIM_PERIOD:
25839 + else if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25842 + sdata->u.ap.dtim_period = value;
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);
25853 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
25854 + local->cts_protect_erp_frames = value;
25857 + case PRISM2_PARAM_DROP_UNENCRYPTED:
25858 + sdata->drop_unencrypted = value;
25861 + case PRISM2_PARAM_PREAMBLE:
25862 + local->short_preamble = value;
25865 + case PRISM2_PARAM_RATE_LIMIT_BURST:
25866 + local->rate_limit_burst = value;
25867 + local->rate_limit_bucket = value;
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 =
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);
25881 + local->rate_limit = value;
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);
25891 + local->stat_time = value;
25893 + case PRISM2_PARAM_SHORT_SLOT_TIME:
25894 + local->conf.short_slot_time = value;
25895 + if (ieee80211_hw_config(dev))
25899 + case PRISM2_PARAM_PRIVACY_INVOKED:
25900 + if (local->hw->set_privacy_invoked)
25901 + ret = local->hw->set_privacy_invoked(dev, value);
25904 + case PRISM2_PARAM_TEST_MODE:
25905 + ret = ieee80211_ioctl_test_mode(dev, value);
25908 + case PRISM2_PARAM_NEXT_MODE:
25909 + local->next_mode = value;
25912 + case PRISM2_PARAM_CLEAR_KEYS:
25913 + ret = ieee80211_ioctl_clear_keys(dev);
25916 + case PRISM2_PARAM_ADM_STATUS:
25917 + ret = ieee80211_ioctl_set_adm_status(dev, value);
25920 + case PRISM2_PARAM_ANTENNA_SEL:
25921 + local->conf.antenna_sel = value;
25922 + if (ieee80211_hw_config(dev))
25926 + case PRISM2_PARAM_CALIB_INT:
25927 + local->conf.calib_int = value;
25928 + if (ieee80211_hw_config(dev))
25932 + case PRISM2_PARAM_ANTENNA_MODE:
25933 + local->conf.antenna_mode = value;
25934 + if (ieee80211_hw_config(dev))
25938 + case PRISM2_PARAM_BROADCAST_SSID:
25939 + if ((value < 0) || (value > 1))
25942 + local->conf.ssid_hidden = value;
25945 + case PRISM2_PARAM_STA_ANTENNA_SEL:
25946 + local->sta_antenna_sel = value;
25949 + case PRISM2_PARAM_FORCE_UNICAST_RATE:
25950 + ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
25953 + case PRISM2_PARAM_MAX_RATECTRL_RATE:
25954 + ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
25957 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
25958 + local->rate_ctrl_num_up = value;
25961 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
25962 + local->rate_ctrl_num_down = value;
25965 + case PRISM2_PARAM_TX_POWER_REDUCTION:
25969 + local->conf.tx_power_reduction = value;
25972 + case PRISM2_PARAM_EAPOL:
25973 + sdata->eapol = value;
25976 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
25977 + local->key_tx_rx_threshold = value;
25980 + case PRISM2_PARAM_KEY_INDEX:
25981 + if (value < 0 || value >= NUM_DEFAULT_KEYS)
25983 + else if (sdata->keys[value] == NULL)
25986 + sdata->default_key = sdata->keys[value];
25989 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
25990 + ret = ieee80211_ioctl_default_wep_only(local, value);
25993 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
25994 + local->wifi_wme_noack_test = value;
25997 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
25998 + local->allow_broadcast_always = value;
26001 + case PRISM2_PARAM_SCAN_FLAGS:
26002 + local->scan_flags = value;
26005 + case PRISM2_PARAM_MIXED_CELL:
26006 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26009 + sdata->u.sta.mixed_cell = !!value;
26012 + case PRISM2_PARAM_KEY_MGMT:
26013 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26016 + sdata->u.sta.key_mgmt = value;
26019 + case PRISM2_PARAM_HW_MODES:
26020 + local->hw_modes = value;
26023 + case PRISM2_PARAM_CREATE_IBSS:
26024 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26027 + sdata->u.sta.create_ibss = !!value;
26029 + case PRISM2_PARAM_WMM_ENABLED:
26030 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26033 + sdata->u.sta.wmm_enabled = !!value;
26035 + case PRISM2_PARAM_RADAR_DETECT:
26036 + local->conf.radar_detect = value;
26038 + case PRISM2_PARAM_SPECTRUM_MGMT:
26039 + local->conf.spect_mgmt = value;
26042 + ret = -EOPNOTSUPP;
26050 +static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
26051 + struct iw_request_info *info,
26052 + void *wrqu, char *extra)
26054 + struct ieee80211_local *local = dev->priv;
26055 + struct ieee80211_sub_if_data *sdata;
26056 + int *param = (int *) extra;
26059 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26061 + switch (*param) {
26062 + case PRISM2_PARAM_BEACON_INT:
26063 + *param = local->conf.beacon_int;
26066 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
26067 + *param = local->bridge_packets;
26070 + case PRISM2_PARAM_AP_AUTH_ALGS:
26071 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
26072 + *param = sdata->u.sta.auth_algs;
26074 + ret = -EOPNOTSUPP;
26077 + case PRISM2_PARAM_DTIM_PERIOD:
26078 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
26081 + *param = sdata->u.ap.dtim_period;
26084 + case PRISM2_PARAM_IEEE_802_1X:
26085 + *param = sdata->ieee802_1x;
26088 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
26089 + *param = local->cts_protect_erp_frames;
26092 + case PRISM2_PARAM_DROP_UNENCRYPTED:
26093 + *param = sdata->drop_unencrypted;
26096 + case PRISM2_PARAM_PREAMBLE:
26097 + *param = local->short_preamble;
26100 + case PRISM2_PARAM_RATE_LIMIT_BURST:
26101 + *param = local->rate_limit_burst;
26104 + case PRISM2_PARAM_RATE_LIMIT:
26105 + *param = local->rate_limit;
26108 + case PRISM2_PARAM_STAT_TIME:
26109 + *param = local->stat_time;
26111 + case PRISM2_PARAM_SHORT_SLOT_TIME:
26112 + *param = local->conf.short_slot_time;
26115 + case PRISM2_PARAM_NEXT_MODE:
26116 + *param = local->next_mode;
26119 + case PRISM2_PARAM_ANTENNA_SEL:
26120 + *param = local->conf.antenna_sel;
26123 + case PRISM2_PARAM_CALIB_INT:
26124 + *param = local->conf.calib_int;
26127 + case PRISM2_PARAM_ANTENNA_MODE:
26128 + *param = local->conf.antenna_mode;
26131 + case PRISM2_PARAM_BROADCAST_SSID:
26132 + *param = local->conf.ssid_hidden;
26135 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26136 + *param = local->sta_antenna_sel;
26139 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26140 + *param = local->rate_ctrl_num_up;
26143 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26144 + *param = local->rate_ctrl_num_down;
26147 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26148 + *param = local->conf.tx_power_reduction;
26151 + case PRISM2_PARAM_EAPOL:
26152 + *param = sdata->eapol;
26155 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26156 + *param = local->key_tx_rx_threshold;
26159 + case PRISM2_PARAM_KEY_INDEX:
26160 + if (sdata->default_key == NULL)
26162 + else if (sdata->default_key == sdata->keys[0])
26164 + else if (sdata->default_key == sdata->keys[1])
26166 + else if (sdata->default_key == sdata->keys[2])
26168 + else if (sdata->default_key == sdata->keys[3])
26174 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26175 + *param = local->default_wep_only;
26178 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26179 + *param = local->wifi_wme_noack_test;
26182 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26183 + *param = local->allow_broadcast_always;
26186 + case PRISM2_PARAM_SCAN_FLAGS:
26187 + *param = local->scan_flags;
26190 + case PRISM2_PARAM_HW_MODES:
26191 + *param = local->hw_modes;
26194 + case PRISM2_PARAM_CREATE_IBSS:
26195 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26198 + *param = !!sdata->u.sta.create_ibss;
26201 + case PRISM2_PARAM_MIXED_CELL:
26202 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26205 + *param = !!sdata->u.sta.mixed_cell;
26208 + case PRISM2_PARAM_KEY_MGMT:
26209 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26212 + *param = sdata->u.sta.key_mgmt;
26214 + case PRISM2_PARAM_WMM_ENABLED:
26215 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26218 + *param = !!sdata->u.sta.wmm_enabled;
26222 + ret = -EOPNOTSUPP;
26230 +static int ieee80211_ioctl_test_param(struct net_device *dev,
26231 + struct iw_request_info *info,
26232 + void *wrqu, char *extra)
26234 + struct ieee80211_local *local = dev->priv;
26235 + int *i = (int *) extra;
26237 + int value = *(i + 1);
26239 + if (!capable(CAP_NET_ADMIN))
26242 + if (local->hw->test_param)
26243 + return local->hw->test_param(local->mdev, param, value);
26245 + return -EOPNOTSUPP;
26249 +static int ieee80211_ioctl_siwmlme(struct net_device *dev,
26250 + struct iw_request_info *info,
26251 + struct iw_point *data, char *extra)
26253 + struct ieee80211_sub_if_data *sdata;
26254 + struct iw_mlme *mlme = (struct iw_mlme *) extra;
26256 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26257 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
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);
26268 + return -EOPNOTSUPP;
26273 +static int ieee80211_ioctl_siwencode(struct net_device *dev,
26274 + struct iw_request_info *info,
26275 + struct iw_point *erq, char *keybuf)
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 };
26281 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26283 + idx = erq->flags & IW_ENCODE_INDEX;
26284 + if (idx < 1 || idx > 4) {
26286 + if (sdata->default_key == NULL)
26288 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26289 + if (sdata->default_key == sdata->keys[i])
26298 + if (erq->flags & IW_ENCODE_DISABLED)
26300 + else if (erq->length == 0) {
26301 + /* No key data - just set the default TX key index */
26302 + sdata->default_key = sdata->keys[idx];
26305 + return ieee80211_set_encryption(
26307 + idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
26308 + sdata->default_key == NULL,
26309 + NULL, keybuf, erq->length);
26315 +static int ieee80211_ioctl_giwencode(struct net_device *dev,
26316 + struct iw_request_info *info,
26317 + struct iw_point *erq, char *key)
26319 + struct ieee80211_sub_if_data *sdata;
26322 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26324 + idx = erq->flags & IW_ENCODE_INDEX;
26325 + if (idx < 1 || idx > 4) {
26327 + if (sdata->default_key == NULL)
26329 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26330 + if (sdata->default_key == sdata->keys[i])
26339 + erq->flags = idx + 1;
26341 + if (sdata->keys[idx] == NULL) {
26343 + erq->flags |= IW_ENCODE_DISABLED;
26348 + erq->flags |= IW_ENCODE_ENABLED;
26354 +static int ieee80211_ioctl_siwgenie(struct net_device *dev,
26355 + struct iw_request_info *info,
26356 + struct iw_point *data, char *extra)
26358 + return ieee80211_set_gen_ie(dev, extra, data->length);
26362 +static int ieee80211_ioctl_siwauth(struct net_device *dev,
26363 + struct iw_request_info *info,
26364 + struct iw_param *data, char *extra)
26366 + struct ieee80211_local *local = dev->priv;
26367 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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:
26377 + case IW_AUTH_KEY_MGMT:
26378 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
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.
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;
26395 + sdata->u.sta.key_mgmt =
26396 + IEEE80211_KEY_MGMT_NONE;
26400 + case IW_AUTH_80211_AUTH_ALG:
26401 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26402 + sdata->u.sta.auth_algs = data->value;
26404 + ret = -EOPNOTSUPP;
26406 + case IW_AUTH_PRIVACY_INVOKED:
26407 + if (local->hw->set_privacy_invoked)
26408 + ret = local->hw->set_privacy_invoked(dev, data->value);
26411 + ret = -EOPNOTSUPP;
26418 +static int ieee80211_ioctl_giwauth(struct net_device *dev,
26419 + struct iw_request_info *info,
26420 + struct iw_param *data, char *extra)
26422 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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;
26430 + ret = -EOPNOTSUPP;
26433 + ret = -EOPNOTSUPP;
26440 +static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
26441 + struct iw_request_info *info,
26442 + struct iw_point *erq, char *extra)
26444 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26445 + struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
26448 + switch (ext->alg) {
26449 + case IW_ENCODE_ALG_NONE:
26452 + case IW_ENCODE_ALG_WEP:
26455 + case IW_ENCODE_ALG_TKIP:
26458 + case IW_ENCODE_ALG_CCMP:
26462 + return -EOPNOTSUPP;
26465 + if (erq->flags & IW_ENCODE_DISABLED)
26468 + idx = erq->flags & IW_ENCODE_INDEX;
26469 + if (idx < 1 || idx > 4) {
26471 + if (sdata->default_key == NULL)
26473 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26474 + if (sdata->default_key == sdata->keys[i])
26483 + return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
26485 + IW_ENCODE_EXT_SET_TX_KEY,
26486 + NULL, ext->key, ext->key_len);
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" },
26501 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
26503 + struct iwreq *wrq = (struct iwreq *) rq;
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);
26513 + case PRISM2_IOCTL_HOSTAPD:
26514 + if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
26515 + else ret = ieee80211_ioctl_priv_hostapd(dev, &wrq->u.data);
26518 + ret = -EOPNOTSUPP;
26526 +/* Structures to export the Wireless Handlers */
26528 +static const iw_handler ieee80211_handler[] =
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 -- */
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 */
26594 +const struct iw_handler_def ieee80211_iw_handler_def =
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,
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
26610 + * Copyright 2002-2004, Instant802 Networks, Inc.
26611 + * Copyright 2005, Devicescape Software, Inc.
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.
26618 +#ifndef IEEE80211_KEY_H
26619 +#define IEEE80211_KEY_H
26621 +#include <linux/types.h>
26622 +#include <net/d80211.h>
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)
26631 +#define WEP_IV_LEN 4
26632 +#define WEP_ICV_LEN 4
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
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
26648 +#define NUM_RX_DATA_QUEUES 17
26650 +struct ieee80211_key {
26651 + int hw_key_idx; /* filled and used by low-level driver */
26652 + ieee80211_key_alg alg;
26655 + /* last used TSC */
26659 + int tx_initialized;
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];
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
26674 + u32 aes_state[AES_STATE_LEN];
26675 + u32 replays; /* dot11RSNAStatsCCMPReplays */
26678 + int tx_rx_count; /* number of times this key has been used */
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). */
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
26697 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
26704 +#include <linux/config.h>
26705 +#include <linux/netdevice.h>
26706 +#include <linux/types.h>
26708 +#ifdef CONFIG_OAP_LEDS_WLAN
26709 +extern void leds_wlan_set(int unit, int tx, int state);
26712 +void ieee80211_rx_led(int state, struct net_device *dev) {
26713 +#ifdef CONFIG_OAP_LEDS_WLAN
26714 + static unsigned int count = 0;
26716 + if (state == 2) {
26717 + leds_wlan_set(0, 0, (++count) & 1);
26722 +void ieee80211_tx_led(int state, struct net_device *dev) {
26723 +#ifdef CONFIG_OAP_LEDS_WLAN
26724 + leds_wlan_set(0, 1, state);
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
26733 + * Copyright 2003-2005, Devicescape Software, Inc.
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.
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>
26747 +#ifdef CONFIG_PROC_FS
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"
26758 +static struct proc_dir_entry *ieee80211_proc;
26760 +#define PROC_LIMIT (PAGE_SIZE - 80)
26763 +static char * ieee80211_proc_key(char *p, struct ieee80211_key *key,
26764 + int idx, int def_key)
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) {
26779 + p += sprintf(p, " alg=WEP");
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)
26788 + p += sprintf(p, " iv(rx %d)=%08x %04x", i,
26789 + key->u.tkip.iv32_rx[i],
26790 + key->u.tkip.iv16_rx[i]);
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)
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],
26805 + p += sprintf(p, " replays=%u", key->u.ccmp.replays);
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");
26819 +static char * ieee80211_proc_sub_if_ap(char *p,
26820 + struct ieee80211_if_ap *ap)
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);
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);
26844 +static char * ieee80211_proc_sub_if_sta(char *p,
26845 + struct ieee80211_if_sta *ifsta)
26847 + p += sprintf(p, "type=sta\n");
26850 + "bssid=" MACSTR "\n"
26851 + "prev_bssid=" MACSTR "\n"
26854 + "ap_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"
26862 + "auth_transaction=%d\n",
26864 + MAC2STR(ifsta->bssid),
26865 + MAC2STR(ifsta->prev_bssid),
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,
26882 + ifsta->auth_transaction);
26887 +static char * ieee80211_proc_sub_if(char *p,
26888 + struct ieee80211_sub_if_data *sdata)
26890 + if (sdata == NULL)
26894 + p += sprintf(p, "bss=%p\n", sdata->bss);
26896 + switch (sdata->type) {
26897 + case IEEE80211_SUB_IF_TYPE_AP:
26898 + p = ieee80211_proc_sub_if_ap(p, &sdata->u.ap);
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));
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);
26909 + case IEEE80211_SUB_IF_TYPE_STA:
26910 + p = ieee80211_proc_sub_if_sta(p, &sdata->u.sta);
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);
26922 +static int ieee80211_proc_iface_read(char *page, char **start, off_t off,
26923 + int count, int *eof, void *data)
26926 + struct net_device *dev = (struct net_device *) data;
26927 + struct ieee80211_sub_if_data *sdata;
26935 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26939 + p = ieee80211_proc_sub_if(p, sdata);
26941 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26942 + if (sdata->keys[i] == NULL)
26945 + p = ieee80211_proc_key(p, sdata->keys[i], i,
26946 + sdata->keys[i] == sdata->default_key);
26949 + return (p - page);
26953 +static int ieee80211_proc_sta_read(char *page, char **start, off_t off,
26954 + int count, int *eof, void *data)
26957 + struct sta_info *sta = (struct sta_info *) data;
26958 + struct ieee80211_local *local;
26966 + if (!sta || !sta->dev)
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);
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);
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);
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");
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]);
27037 + p += sprintf(p, "\n");
27039 + p += rate_control_status_sta(local, sta, p);
27041 + return (p - page);
27045 +static int ieee80211_proc_counters_read(char *page, char **start, off_t off,
27046 + int count, int *eof, void *data)
27049 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27050 + struct ieee80211_low_level_stats stats;
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);
27079 + memset(&stats, 0, sizeof(stats));
27080 + if (local->hw->get_stats &&
27081 + local->hw->get_stats(local->mdev, &stats) == 0) {
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);
27093 + return (p - page);
27097 +static int ieee80211_proc_debug_read(char *page, char **start, off_t off,
27098 + int count, int *eof, void *data)
27101 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27109 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
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);
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");
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");
27163 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27165 + p += sprintf(p, "num_scans=%u\n", local->scan.num_scans);
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");
27178 + return (p - page);
27182 +static const char * ieee80211_mode_str_short(int 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";
27194 + return "UNKNOWN";
27199 +static const char * ieee80211_mode_str(int 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)";
27211 + return "UNKNOWN";
27216 +static int ieee80211_proc_info_read(char *page, char **start, off_t off,
27217 + int count, int *eof, void *data)
27220 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27222 + struct ieee80211_hw_modes *mode;
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));
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);
27242 +static int ieee80211_proc_config_read(char *page, char **start, off_t off,
27243 + int count, int *eof, void *data)
27246 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27254 + "low_level_driver=%s\n"
27259 + "wep_iv=0x%06x\n"
27260 + "antenna_sel=%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);
27288 + return (p - page);
27292 +static int ieee80211_proc_channels_read(char *page, char **start, off_t off,
27293 + int count, int *eof, void *data)
27296 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27298 + struct ieee80211_hw_modes *mode;
27299 + struct ieee80211_channel *chan;
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 ?
27316 + chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN
27317 + ? "[W_ACTIVE_SCAN]" : "",
27318 + chan->flag & IEEE80211_CHAN_W_IBSS ?
27319 + "[W_IBSS]" : "");
27322 + return (p - page);
27326 +static int ieee80211_proc_rates_read(char *page, char **start, off_t off,
27327 + int count, int *eof, void *data)
27330 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27332 + struct ieee80211_rate *rate;
27339 + p += sprintf(p, "RATE VAL VAL2 MIN_RSSI_ACK MIN_RSSI_ACK_DELTA "
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,
27347 + rate->flags & IEEE80211_RATE_ERP ? "[ERP]" : "",
27348 + rate->flags & IEEE80211_RATE_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 ?
27358 + rate->flags & IEEE80211_RATE_MANDATORY ?
27359 + "[MANDATORY]" : "");
27361 + return (p - page);
27365 +static int ieee80211_proc_multicast_read(char *page, char **start, off_t off,
27366 + int count, int *eof, void *data)
27369 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27376 + return rate_control_status_global(local, p);
27381 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27382 + struct sta_info *sta)
27385 + struct proc_dir_entry *entry;
27387 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27389 + if (!local->proc_sta)
27392 + entry = create_proc_read_entry(buf, 0, local->proc_sta,
27393 + ieee80211_proc_sta_read, sta);
27395 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27396 + sta->proc_entry_added = 1;
27401 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27402 + struct sta_info *sta)
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;
27413 +void ieee80211_proc_init_virtual(struct net_device *dev)
27415 + struct proc_dir_entry *entry;
27416 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27418 + if (!local->proc_iface)
27421 + entry = create_proc_read_entry(dev->name, 0, local->proc_iface,
27422 + ieee80211_proc_iface_read, dev);
27424 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27428 +void ieee80211_proc_deinit_virtual(struct net_device *dev)
27430 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27432 + if (local->proc_iface)
27433 + remove_proc_entry(dev->name, local->proc_iface);
27437 +void ieee80211_proc_init_interface(struct ieee80211_local *local)
27439 + if (!ieee80211_proc)
27442 + local->proc = proc_mkdir(local->wdev->name, ieee80211_proc);
27443 + if (!local->proc)
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);
27466 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local)
27468 + if (!local->proc)
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);
27486 +void ieee80211_proc_init(void)
27488 + if (proc_net == NULL) {
27489 + ieee80211_proc = NULL;
27493 + ieee80211_proc = proc_mkdir("ieee80211", proc_net);
27494 + if (!ieee80211_proc)
27495 + printk(KERN_WARNING "Failed to mkdir /proc/net/ieee80211\n");
27499 +void ieee80211_proc_deinit(void)
27501 + if (!ieee80211_proc)
27504 + ieee80211_proc = NULL;
27505 + remove_proc_entry("ieee80211", proc_net);
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
27514 + * Copyright 2003-2004, Instant802 Networks, Inc.
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.
27521 +#ifndef IEEE80211_PROC_H
27522 +#define IEEE80211_PROC_H
27524 +#include <linux/netdevice.h>
27525 +#include "ieee80211_i.h"
27526 +#include "sta_info.h"
27528 +#ifdef CONFIG_PROC_FS
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);
27541 +#else /* CONFIG_PROC_FS */
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 */
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
27563 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
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>
27578 +#include <net/d80211.h>
27579 +#include "ieee80211_i.h"
27580 +#include "rate_control.h"
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
27589 +static void get_channel_params(struct ieee80211_local *local, int channel,
27590 + struct ieee80211_hw_modes **mode,
27591 + struct ieee80211_channel **chan)
27595 + for (m = 0; m < local->hw->num_modes; m++) {
27596 + *mode = &local->hw->modes[m];
27597 + if ((*mode)->mode == local->conf.phymode)
27600 + local->scan.mode_idx = m;
27601 + local->scan.chan_idx = 0;
27603 + *chan = &(*mode)->channels[local->scan.chan_idx];
27604 + if ((*chan)->chan == channel) {
27607 + local->scan.chan_idx++;
27608 + } while (local->scan.chan_idx < (*mode)->num_channels);
27613 +static void next_chan_same_mode(struct ieee80211_local *local,
27614 + struct ieee80211_hw_modes **mode,
27615 + struct ieee80211_channel **chan)
27619 + for (m = 0; m < local->hw->num_modes; m++) {
27620 + *mode = &local->hw->modes[m];
27621 + if ((*mode)->mode == local->conf.phymode)
27624 + local->scan.mode_idx = m;
27626 + /* Select next channel - scan only channels marked with W_SCAN flag */
27627 + prev = local->scan.chan_idx;
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)
27635 + } while (local->scan.chan_idx != prev);
27639 +static void next_chan_all_modes(struct ieee80211_local *local,
27640 + struct ieee80211_hw_modes **mode,
27641 + struct ieee80211_channel **chan)
27643 + int prev, prev_m;
27645 + if (local->scan.mode_idx >= local->hw->num_modes) {
27646 + local->scan.mode_idx = 0;
27647 + local->scan.chan_idx = 0;
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;
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];
27663 + *chan = &(*mode)->channels[local->scan.chan_idx];
27664 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27666 + } while (local->scan.chan_idx != prev ||
27667 + local->scan.mode_idx != prev_m);
27671 +static void ieee80211_scan_start(struct net_device *dev,
27672 + struct ieee80211_scan_conf *conf)
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;
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",
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
27694 + local->scan.txrx_count = 0;
27695 + local->scan.timer.expires = jiffies + HZ;
27696 + add_timer(&local->scan.timer);
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);
27705 + if (local->scan.our_mode_only) {
27706 + if (local->scan.channel > 0) {
27707 + get_channel_params(local, local->scan.channel, &mode,
27710 + next_chan_same_mode(local, &mode, &chan);
27713 + next_chan_all_modes(local, &mode, &chan);
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;
27727 + printk(KERN_DEBUG "%s: Doing scan on mode: %d freq: %d chan: %d "
27729 + dev->name, conf->scan_phymode, conf->scan_freq,
27730 + conf->scan_channel, conf->scan_time);
27732 + local->scan.rx_packets = 0;
27733 + local->scan.rx_beacon = 0;
27734 + local->scan.freq = chan->freq;
27735 + local->scan.in_scan = 1;
27737 + ieee80211_netif_oper(dev, NETIF_STOP);
27739 + ret = local->hw->passive_scan(dev, IEEE80211_SCAN_START, conf);
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;
27748 + local->scan.in_scan = 0;
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;
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);
27763 + local->scan.in_scan = 0;
27766 + add_timer(&local->scan.timer);
27770 +static void ieee80211_scan_stop(struct net_device *dev,
27771 + struct ieee80211_scan_conf *conf)
27773 + struct ieee80211_local *local = dev->priv;
27774 + struct ieee80211_hw_modes *mode;
27775 + struct ieee80211_channel *chan;
27778 + if (local->hw->passive_scan == NULL)
27781 + if (local->scan.mode_idx >= local->hw->num_modes) {
27782 + local->scan.mode_idx = 0;
27783 + local->scan.chan_idx = 0;
27786 + mode = &local->hw->modes[local->scan.mode_idx];
27788 + if (local->scan.chan_idx >= mode->num_channels) {
27789 + local->scan.chan_idx = 0;
27792 + chan = &mode->channels[local->scan.chan_idx];
27794 + local->hw->passive_scan(dev, IEEE80211_SCAN_END, conf);
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",
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++;
27806 + local->scan.in_scan = 0;
27807 + ieee80211_netif_oper(dev, NETIF_WAKE);
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)) /
27813 + local->scan.timer.expires = jiffies + wait;
27815 + add_timer(&local->scan.timer);
27819 +static void ieee80211_scan_handler(unsigned long uldev)
27821 + struct net_device *dev = (struct net_device *) uldev;
27822 + struct ieee80211_local *local = dev->priv;
27823 + struct ieee80211_scan_conf conf;
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);
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;
27841 + if (local->scan.in_scan == 0)
27842 + ieee80211_scan_start(dev, &conf);
27844 + ieee80211_scan_stop(dev, &conf);
27848 +void ieee80211_init_scan(struct net_device *dev)
27850 + struct ieee80211_local *local = dev->priv;
27851 + struct ieee80211_hdr hdr;
27854 + struct rate_control_extra extra;
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);
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);
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);
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;
27891 + memcpy(skb_put(local->scan.skb, len), &hdr, len);
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;
27904 +void ieee80211_stop_scan(struct net_device *dev)
27906 + struct ieee80211_local *local = dev->priv;
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;
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
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.
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.
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,
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>
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"
27953 +/* #define IEEE80211_IBSS_DEBUG */
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)
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)
27973 +#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
27976 +#define IEEE80211_FC(type, stype) cpu_to_le16((type << 2) | (stype << 4))
27978 +#define ERP_INFO_USE_PROTECTION BIT(1)
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);
27991 +/* Parsed Information Elements */
27992 +struct ieee802_11_elems {
27996 + u8 supp_rates_len;
27998 + u8 fh_params_len;
28000 + u8 ds_params_len;
28002 + u8 cf_params_len;
28006 + u8 ibss_params_len;
28008 + u8 challenge_len;
28015 + u8 *ext_supp_rates;
28016 + u8 ext_supp_rates_len;
28020 + u8 wmm_param_len;
28023 +typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
28026 +static ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
28027 + struct ieee802_11_elems *elems)
28029 + size_t left = len;
28033 + memset(elems, 0, sizeof(*elems));
28035 + while (left >= 2) {
28042 + if (elen > left) {
28044 + if (net_ratelimit())
28045 + printk(KERN_DEBUG "IEEE 802.11 element parse "
28046 + "failed (id=%d elen=%d left=%d)\n",
28049 + return ParseFailed;
28053 + case WLAN_EID_SSID:
28054 + elems->ssid = pos;
28055 + elems->ssid_len = elen;
28057 + case WLAN_EID_SUPP_RATES:
28058 + elems->supp_rates = pos;
28059 + elems->supp_rates_len = elen;
28061 + case WLAN_EID_FH_PARAMS:
28062 + elems->fh_params = pos;
28063 + elems->fh_params_len = elen;
28065 + case WLAN_EID_DS_PARAMS:
28066 + elems->ds_params = pos;
28067 + elems->ds_params_len = elen;
28069 + case WLAN_EID_CF_PARAMS:
28070 + elems->cf_params = pos;
28071 + elems->cf_params_len = elen;
28073 + case WLAN_EID_TIM:
28074 + elems->tim = pos;
28075 + elems->tim_len = elen;
28077 + case WLAN_EID_IBSS_PARAMS:
28078 + elems->ibss_params = pos;
28079 + elems->ibss_params_len = elen;
28081 + case WLAN_EID_CHALLENGE:
28082 + elems->challenge = pos;
28083 + elems->challenge_len = elen;
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;
28104 + case WLAN_EID_RSN:
28105 + elems->rsn = pos;
28106 + elems->rsn_len = elen;
28108 + case WLAN_EID_ERP_INFO:
28109 + elems->erp_info = pos;
28110 + elems->erp_info_len = elen;
28112 + case WLAN_EID_EXT_SUPP_RATES:
28113 + elems->ext_supp_rates = pos;
28114 + elems->ext_supp_rates_len = elen;
28118 + printk(KERN_DEBUG "IEEE 802.11 element parse ignored "
28119 + "unknown element (id=%d elen=%d)\n",
28130 + /* Do not trigger error if left == 1 as Apple Airport base stations
28131 + * send AssocResps that are one spurious byte too long. */
28133 + return unknown ? ParseUnknown : ParseOK;
28139 +static int ecw2cw(int ecw)
28142 + while (ecw > 0) {
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)
28154 + struct ieee80211_local *local = dev->priv;
28155 + struct ieee80211_tx_queue_params params;
28160 + if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
28162 + count = wmm_param[6] & 0x0f;
28163 + if (count == ifsta->wmm_last_param_set)
28165 + ifsta->wmm_last_param_set = count;
28167 + pos = wmm_param + 8;
28168 + left = wmm_param_len - 8;
28170 + memset(¶ms, 0, sizeof(params));
28172 + if (local->hw->conf_tx == NULL)
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;
28183 + queue = IEEE80211_TX_QUEUE_DATA3;
28185 + local->wmm_acm |= BIT(1) | BIT(2);
28189 + queue = IEEE80211_TX_QUEUE_DATA1;
28191 + local->wmm_acm |= BIT(4) | BIT(5);
28195 + queue = IEEE80211_TX_QUEUE_DATA0;
28197 + local->wmm_acm |= BIT(6) | BIT(7);
28202 + queue = IEEE80211_TX_QUEUE_DATA2;
28204 + local->wmm_acm |= BIT(0) | BIT(3);
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
28220 + if (local->hw->conf_tx(local->mdev, queue, ¶ms)) {
28221 + printk(KERN_DEBUG "%s: failed to set TX queue "
28222 + "parameters for queue %d\n", dev->name, queue);
28228 +static void ieee80211_sta_send_associnfo(struct net_device *dev,
28229 + struct ieee80211_if_sta *ifsta)
28234 + union iwreq_data wrqu;
28236 + if (ifsta->assocreq_ies == NULL && ifsta->assocresp_ies == NULL)
28239 + buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
28240 + ifsta->assocresp_ies_len), GFP_ATOMIC);
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]);
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]);
28261 + len += sprintf(buf + len, ")");
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]);
28271 + memset(&wrqu, 0, sizeof(wrqu));
28272 + wrqu.data.length = len;
28273 + wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
28279 +static void ieee80211_set_associated(struct net_device *dev,
28280 + struct ieee80211_if_sta *ifsta, int assoc)
28282 + union iwreq_data wrqu;
28284 + if (ifsta->associated == assoc)
28287 + ifsta->associated = 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)
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);
28299 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28301 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28302 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28303 + ifsta->last_probe = jiffies;
28307 +static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
28308 + int encrypt, int probe_resp)
28310 + struct ieee80211_sub_if_data *sdata;
28311 + struct ieee80211_tx_packet_data *pkt_data;
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;
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;
28322 + pkt_data->pkt_probe_resp = 1;
28324 + dev_queue_xmit(skb);
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,
28333 + struct sk_buff *skb;
28334 + struct ieee80211_mgmt *mgmt;
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);
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);
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);
28357 + memcpy(skb_put(skb, extra_len), extra, extra_len);
28359 + ieee80211_sta_tx(dev, skb, encrypt, 0);
28363 +static void ieee80211_authenticate(struct net_device *dev,
28364 + struct ieee80211_if_sta *ifsta)
28366 + ifsta->auth_tries++;
28367 + if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
28368 + printk(KERN_DEBUG "%s: authentication with AP " MACSTR
28370 + dev->name, MAC2STR(ifsta->bssid));
28374 + ifsta->state = IEEE80211_AUTHENTICATE;
28375 + printk(KERN_DEBUG "%s: authenticate with AP " MACSTR "\n",
28376 + dev->name, MAC2STR(ifsta->bssid));
28378 + ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
28380 + mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
28384 +static void ieee80211_send_assoc(struct net_device *dev,
28385 + struct ieee80211_if_sta *ifsta)
28387 + struct ieee80211_local *local = dev->priv;
28388 + struct sk_buff *skb;
28389 + struct ieee80211_mgmt *mgmt;
28393 + struct ieee80211_sta_bss *bss;
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);
28404 + capab = ifsta->capab;
28405 + if (local->conf.phymode == MODE_IEEE80211G) {
28406 + capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
28407 + WLAN_CAPABILITY_SHORT_PREAMBLE;
28409 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28411 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
28412 + capab |= WLAN_CAPABILITY_PRIVACY;
28413 + if (bss->wmm_ie) {
28416 + ieee80211_rx_bss_put(dev, bss);
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);
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,
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);
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);
28447 + len = local->num_curr_rates;
28450 + pos = skb_put(skb, len + 2);
28451 + *pos++ = WLAN_EID_SUPP_RATES;
28453 + for (i = 0; i < len; i++) {
28454 + int rate = local->curr_rates[i].rate;
28455 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28457 + *pos++ = (u8) (rate / 5);
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)
28468 + *pos++ = (u8) (rate / 5);
28472 + if (ifsta->extra_ie) {
28473 + pos = skb_put(skb, ifsta->extra_ie_len);
28474 + memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
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 */
28484 + *pos++ = 2; /* WME */
28485 + *pos++ = 0; /* WME info */
28486 + *pos++ = 1; /* WME ver */
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);
28496 + ieee80211_sta_tx(dev, skb, 0, 0);
28500 +static void ieee80211_send_deauth(struct net_device *dev,
28501 + struct ieee80211_if_sta *ifsta, u16 reason)
28503 + struct sk_buff *skb;
28504 + struct ieee80211_mgmt *mgmt;
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);
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);
28521 + mgmt->u.deauth.reason_code = cpu_to_le16(reason);
28523 + ieee80211_sta_tx(dev, skb, 0, 0);
28527 +static void ieee80211_send_disassoc(struct net_device *dev,
28528 + struct ieee80211_if_sta *ifsta, u16 reason)
28530 + struct sk_buff *skb;
28531 + struct ieee80211_mgmt *mgmt;
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);
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);
28548 + mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
28550 + ieee80211_sta_tx(dev, skb, 0, 0);
28554 +static int ieee80211_privacy_mismatch(struct net_device *dev,
28555 + struct ieee80211_if_sta *ifsta)
28557 + struct ieee80211_sta_bss *bss;
28560 + if (ifsta == NULL || ifsta->mixed_cell ||
28561 + ifsta->key_mgmt != IEEE80211_KEY_MGMT_NONE)
28564 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28568 + if (ieee80211_sta_wep_configured(dev) !=
28569 + !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
28572 + ieee80211_rx_bss_put(dev, bss);
28578 +static void ieee80211_associate(struct net_device *dev,
28579 + struct ieee80211_if_sta *ifsta)
28581 + ifsta->assoc_tries++;
28582 + if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
28583 + printk(KERN_DEBUG "%s: association with AP " MACSTR
28585 + dev->name, MAC2STR(ifsta->bssid));
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);
28598 + ieee80211_send_assoc(dev, ifsta);
28600 + mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
28604 +static void ieee80211_associated(struct net_device *dev,
28605 + struct ieee80211_if_sta *ifsta)
28607 + struct ieee80211_local *local = dev->priv;
28608 + struct sta_info *sta;
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 */
28616 + ifsta->state = IEEE80211_ASSOCIATED;
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));
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 "
28631 + dev->name, MAC2STR(ifsta->bssid));
28634 + ieee80211_send_probe_req(dev, ifsta->bssid,
28635 + local->scan_ssid,
28636 + local->scan_ssid_len);
28637 + ifsta->probereq_poll = 1;
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,
28646 + ifsta->ssid_len);
28649 + sta_info_release(local, sta);
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);
28659 + mod_timer(&ifsta->timer,
28660 + jiffies + IEEE80211_MONITORING_INTERVAL);
28665 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
28666 + u8 *ssid, size_t ssid_len)
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;
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);
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);
28687 + memcpy(mgmt->da, dst, ETH_ALEN);
28688 + memcpy(mgmt->bssid, dst, ETH_ALEN);
28690 + memset(mgmt->da, 0xff, ETH_ALEN);
28691 + memset(mgmt->bssid, 0xff, ETH_ALEN);
28693 + pos = skb_put(skb, 2 + ssid_len);
28694 + *pos++ = WLAN_EID_SSID;
28695 + *pos++ = ssid_len;
28696 + memcpy(pos, ssid, ssid_len);
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))
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];
28714 + pos = skb_put(skb, 1);
28717 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28718 + *pos = rate->rate / 10;
28720 + *pos = rate->rate / 5;
28723 + ieee80211_sta_tx(dev, skb, 0, 0);
28727 +static int ieee80211_sta_wep_configured(struct net_device *dev)
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)
28737 +static void ieee80211_auth_completed(struct net_device *dev,
28738 + struct ieee80211_if_sta *ifsta)
28740 + printk(KERN_DEBUG "%s: authenticated\n", dev->name);
28741 + ifsta->authenticated = 1;
28742 + ieee80211_associate(dev, ifsta);
28746 +static void ieee80211_auth_challenge(struct net_device *dev,
28747 + struct ieee80211_if_sta *ifsta,
28748 + struct ieee80211_mgmt *mgmt,
28750 + struct ieee80211_rx_status *rx_status)
28753 + struct ieee802_11_elems elems;
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",
28763 + if (elems.challenge == NULL) {
28764 + printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
28765 + "frame\n", dev->name);
28768 + ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
28769 + elems.challenge_len + 2, 1);
28773 +static void ieee80211_rx_mgmt_auth(struct net_device *dev,
28774 + struct ieee80211_if_sta *ifsta,
28775 + struct ieee80211_mgmt *mgmt,
28777 + struct ieee80211_rx_status *rx_status)
28779 + struct ieee80211_local *local = dev->priv;
28780 + u16 auth_alg, auth_transaction, status_code;
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));
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));
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));
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));
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);
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);
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);
28836 + ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
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);
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];
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)
28863 + else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
28867 + for (i = 0; i < num_algs; i++) {
28869 + if (pos >= num_algs)
28871 + if (algs[pos] == ifsta->auth_alg ||
28872 + algs[pos] == 0xff)
28874 + if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
28875 + !ieee80211_sta_wep_configured(dev))
28877 + ifsta->auth_alg = algs[pos];
28878 + printk(KERN_DEBUG "%s: set auth_alg=%d for "
28880 + dev->name, ifsta->auth_alg);
28887 + switch (ifsta->auth_alg) {
28888 + case WLAN_AUTH_OPEN:
28889 + case WLAN_AUTH_LEAP:
28890 + ieee80211_auth_completed(dev, ifsta);
28892 + case WLAN_AUTH_SHARED_KEY:
28893 + if (ifsta->auth_transaction == 4)
28894 + ieee80211_auth_completed(dev, ifsta);
28896 + ieee80211_auth_challenge(dev, ifsta, mgmt, len,
28903 +static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
28904 + struct ieee80211_if_sta *ifsta,
28905 + struct ieee80211_mgmt *mgmt,
28907 + struct ieee80211_rx_status *rx_status)
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));
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));
28926 + reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
28928 + printk(KERN_DEBUG "%s: RX deauthentication from " MACSTR
28929 + " (reason=%d)\n",
28930 + dev->name, MAC2STR(mgmt->sa), reason_code);
28932 + if (ifsta->authenticated) {
28933 + printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
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);
28944 + ieee80211_set_associated(dev, ifsta, 0);
28945 + ifsta->authenticated = 0;
28949 +static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
28950 + struct ieee80211_if_sta *ifsta,
28951 + struct ieee80211_mgmt *mgmt,
28953 + struct ieee80211_rx_status *rx_status)
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));
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));
28972 + reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
28974 + printk(KERN_DEBUG "%s: RX disassociation from " MACSTR
28975 + " (reason=%d)\n",
28976 + dev->name, MAC2STR(mgmt->sa), reason_code);
28978 + if (ifsta->associated)
28979 + printk(KERN_DEBUG "%s: disassociated\n", dev->name);
28981 + if (ifsta->state == IEEE80211_ASSOCIATED) {
28982 + ifsta->state = IEEE80211_ASSOCIATE;
28983 + mod_timer(&ifsta->timer,
28984 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
28987 + ieee80211_set_associated(dev, ifsta, 0);
28991 +static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
28992 + struct ieee80211_if_sta *ifsta,
28993 + struct ieee80211_mgmt *mgmt,
28995 + struct ieee80211_rx_status *rx_status,
28998 + struct ieee80211_local *local = dev->priv;
28999 + struct sta_info *sta;
29001 + u16 capab_info, status_code, aid;
29002 + struct ieee802_11_elems elems;
29006 + /* AssocResp and ReassocResp have identical structure, so process both
29007 + * of them in this function. */
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));
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));
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));
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));
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);
29044 + if (status_code != WLAN_STATUS_SUCCESS) {
29045 + printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
29046 + dev->name, status_code);
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",
29058 + if (elems.supp_rates == NULL) {
29059 + printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
29064 + printk(KERN_DEBUG "%s: associated\n", dev->name);
29065 + ifsta->aid = aid;
29066 + ifsta->ap_capab = capab_info;
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);
29074 + ieee80211_set_associated(dev, ifsta, 1);
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);
29088 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
29089 + sta->assoc_ap = 1;
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)
29096 + for (j = 0; j < local->num_curr_rates; j++)
29097 + if (local->curr_rates[j].rate == rate)
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)
29104 + for (j = 0; j < local->num_curr_rates; j++)
29105 + if (local->curr_rates[j].rate == rate)
29108 + sta->supp_rates = rates;
29110 + rate_control_rate_init(local, sta);
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);
29119 + sta_info_release(local, sta);
29121 + ieee80211_associated(dev, ifsta);
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)
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;
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)
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)];
29144 + if (prev == NULL) {
29145 + local->sta_bss_hash[STA_HASH(bss->bssid)] =
29148 + prev->hnext = bss->hnext;
29158 +static struct ieee80211_sta_bss *
29159 +ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid)
29161 + struct ieee80211_local *local = dev->priv;
29162 + struct ieee80211_sta_bss *bss;
29164 + bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
29167 + memset(bss, 0, sizeof(*bss));
29168 + atomic_inc(&bss->users);
29169 + atomic_inc(&bss->users);
29170 + memcpy(bss->bssid, bssid, ETH_ALEN);
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);
29181 +static struct ieee80211_sta_bss *
29182 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid)
29184 + struct ieee80211_local *local = dev->priv;
29185 + struct ieee80211_sta_bss *bss;
29187 + spin_lock_bh(&local->sta_bss_lock);
29188 + bss = local->sta_bss_hash[STA_HASH(bssid)];
29190 + if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
29191 + atomic_inc(&bss->users);
29194 + bss = bss->hnext;
29196 + spin_unlock_bh(&local->sta_bss_lock);
29201 +static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
29203 + kfree(bss->wpa_ie);
29204 + kfree(bss->rsn_ie);
29205 + kfree(bss->wmm_ie);
29210 +static void ieee80211_rx_bss_put(struct net_device *dev,
29211 + struct ieee80211_sta_bss *bss)
29213 + struct ieee80211_local *local = dev->priv;
29214 + if (!atomic_dec_and_test(&bss->users))
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);
29225 +void ieee80211_rx_bss_list_init(struct net_device *dev)
29227 + struct ieee80211_local *local = dev->priv;
29228 + spin_lock_init(&local->sta_bss_lock);
29229 + INIT_LIST_HEAD(&local->sta_bss_list);
29233 +void ieee80211_rx_bss_list_deinit(struct net_device *dev)
29235 + struct ieee80211_local *local = dev->priv;
29236 + struct ieee80211_sta_bss *bss;
29237 + struct list_head *ptr;
29240 + ptr = local->sta_bss_list.next;
29241 + if (!ptr || ptr == &local->sta_bss_list)
29243 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
29244 + ieee80211_rx_bss_put(dev, bss);
29249 +static void ieee80211_rx_bss_info(struct net_device *dev,
29250 + struct ieee80211_mgmt *mgmt,
29252 + struct ieee80211_rx_status *rx_status,
29255 + struct ieee80211_local *local = dev->priv;
29256 + struct ieee802_11_elems elems;
29258 + int channel, invalid = 0, clen;
29259 + struct ieee80211_sta_bss *bss;
29260 + struct sta_info *sta;
29261 + struct ieee80211_sub_if_data *sdata;
29265 + if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
29266 + return; /* ignore ProbeResp to foreign address */
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));
29274 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29275 + if (baselen > len)
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]);
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;
29289 + if (local->hw->get_tsf)
29290 + tsf = local->hw->get_tsf(local->mdev);
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 "
29297 + MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
29298 + tsf, timestamp, tsf - timestamp, jiffies);
29299 + last_tsf_debug = jiffies;
29301 +#endif /* IEEE80211_IBSS_DEBUG */
29304 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29305 + &elems) == ParseFailed)
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;
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;
29332 + for (i = 0; i < elems.supp_rates_len +
29333 + elems.ext_supp_rates_len; i++) {
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)
29344 + for (j = 0; j < num_rates; j++)
29345 + if (rates[j].rate == own_rate)
29346 + supp_rates |= BIT(j);
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;
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 -> "
29361 + dev->name, MAC2STR(sta->addr), prev_rates,
29362 + supp_rates, sta->supp_rates);
29364 + sta_info_release(local, sta);
29367 + if (elems.ssid == NULL)
29370 + if (elems.ds_params && elems.ds_params_len == 1)
29371 + channel = elems.ds_params[0];
29373 + channel = rx_status->channel;
29375 + bss = ieee80211_rx_bss_get(dev, mgmt->bssid);
29376 + if (bss == NULL) {
29377 + bss = ieee80211_rx_bss_add(dev, mgmt->bssid);
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);
29389 + if (bss->probe_resp && beacon) {
29390 + /* Do not allow beacon to override data from Probe Response. */
29391 + ieee80211_rx_bss_put(dev, bss);
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;
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,
29409 + bss->supp_rates_len += clen;
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;
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;
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;
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;
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;
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;
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;
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
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];
29485 + bss->timestamp = timestamp;
29486 + bss->last_update = jiffies;
29487 + bss->rssi = rx_status->ssi;
29489 + bss->probe_resp++;
29490 + ieee80211_rx_bss_put(dev, bss);
29494 +static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
29495 + struct ieee80211_mgmt *mgmt,
29497 + struct ieee80211_rx_status *rx_status)
29499 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
29503 +static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
29504 + struct ieee80211_mgmt *mgmt,
29506 + struct ieee80211_rx_status *rx_status)
29508 + struct ieee80211_local *local = dev->priv;
29509 + struct ieee80211_sub_if_data *sdata;
29510 + struct ieee80211_if_sta *ifsta;
29511 + int use_protection;
29513 + struct ieee802_11_elems elems;
29515 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
29517 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29518 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
29520 + ifsta = &sdata->u.sta;
29522 + if (!ifsta->associated ||
29523 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
29526 + /* Process beacon from the current BSS */
29527 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29528 + if (baselen > len)
29531 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29532 + &elems) == ParseFailed)
29535 + use_protection = 0;
29536 + if (elems.erp_info && elems.erp_info_len >= 1) {
29538 + (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
29541 + if (use_protection != !!ifsta->use_protection) {
29542 + if (net_ratelimit()) {
29543 + printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
29546 + use_protection ? "enabled" : "disabled",
29547 + MAC2STR(ifsta->bssid));
29549 + ifsta->use_protection = use_protection ? 1 : 0;
29550 + local->cts_protect_erp_frames = use_protection;
29553 + if (elems.wmm_param && ifsta->wmm_enabled) {
29554 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29555 + elems.wmm_param_len);
29560 +static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
29561 + struct ieee80211_if_sta *ifsta,
29562 + struct ieee80211_mgmt *mgmt,
29564 + struct ieee80211_rx_status *rx_status)
29566 + struct ieee80211_local *local = dev->priv;
29567 + int tx_last_beacon;
29568 + struct sk_buff *skb;
29569 + struct ieee80211_mgmt *resp;
29572 + if (local->conf.mode != IW_MODE_ADHOC ||
29573 + ifsta->state != IEEE80211_IBSS_JOINED ||
29574 + len < 24 + 2 || ifsta->probe_resp == NULL)
29577 + if (local->hw->tx_last_beacon)
29578 + tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
29580 + tx_last_beacon = 1;
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 */
29589 + if (!tx_last_beacon)
29592 + if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
29593 + memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
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));
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 */
29614 + /* Reply with ProbeResp */
29615 + skb = skb_copy(ifsta->probe_resp, GFP_ATOMIC);
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);
29629 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
29630 + struct ieee80211_rx_status *rx_status)
29632 + struct ieee80211_sub_if_data *sdata;
29633 + struct ieee80211_if_sta *ifsta;
29634 + struct ieee80211_mgmt *mgmt;
29637 + if (skb->len < 24)
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);
29646 + ifsta = &sdata->u.sta;
29648 + mgmt = (struct ieee80211_mgmt *) skb->data;
29649 + fc = le16_to_cpu(mgmt->frame_control);
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,
29656 + case WLAN_FC_STYPE_PROBE_RESP:
29657 + ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
29659 + case WLAN_FC_STYPE_BEACON:
29660 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
29662 + case WLAN_FC_STYPE_AUTH:
29663 + ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len, rx_status);
29665 + case WLAN_FC_STYPE_ASSOC_RESP:
29666 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29669 + case WLAN_FC_STYPE_REASSOC_RESP:
29670 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29673 + case WLAN_FC_STYPE_DEAUTH:
29674 + ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len,
29677 + case WLAN_FC_STYPE_DISASSOC:
29678 + ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len,
29682 + printk(KERN_DEBUG "%s: received unknown management frame - "
29683 + "stype=%d\n", dev->name, WLAN_FC_GET_STYPE(fc));
29688 + dev_kfree_skb(skb);
29692 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
29693 + struct ieee80211_rx_status *rx_status)
29695 + struct ieee80211_mgmt *mgmt;
29698 + if (skb->len < 24) {
29699 + dev_kfree_skb(skb);
29703 + mgmt = (struct ieee80211_mgmt *) skb->data;
29704 + fc = le16_to_cpu(mgmt->frame_control);
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,
29716 + dev_kfree_skb(skb);
29720 +static int ieee80211_sta_active_ibss(struct net_device *dev)
29722 + struct ieee80211_local *local = dev->priv;
29723 + struct list_head *ptr;
29725 + struct sta_info *sta;
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,
29737 + spin_unlock_bh(&local->sta_lock);
29743 +static void ieee80211_sta_expire(struct net_device *dev)
29745 + struct ieee80211_local *local = dev->priv;
29746 + struct list_head *ptr, *n;
29747 + struct sta_info *sta;
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);
29759 + spin_unlock_bh(&local->sta_lock);
29763 +static void ieee80211_sta_merge_ibss(struct net_device *dev,
29764 + struct ieee80211_if_sta *ifsta)
29766 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
29768 + ieee80211_sta_expire(dev);
29769 + if (ieee80211_sta_active_ibss(dev))
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);
29778 +void ieee80211_sta_timer(unsigned long ptr)
29780 + struct net_device *dev;
29781 + struct ieee80211_sub_if_data *sdata;
29782 + struct ieee80211_if_sta *ifsta;
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);
29791 + ifsta = &sdata->u.sta;
29793 + switch (ifsta->state) {
29794 + case IEEE80211_DISABLED:
29796 + case IEEE80211_AUTHENTICATE:
29797 + ieee80211_authenticate(dev, ifsta);
29799 + case IEEE80211_ASSOCIATE:
29800 + ieee80211_associate(dev, ifsta);
29802 + case IEEE80211_ASSOCIATED:
29803 + ieee80211_associated(dev, ifsta);
29805 + case IEEE80211_IBSS_SEARCH:
29806 + ieee80211_sta_find_ibss(dev, ifsta);
29808 + case IEEE80211_IBSS_JOINED:
29809 + ieee80211_sta_merge_ibss(dev, ifsta);
29812 + printk(KERN_DEBUG "ieee80211_sta_timer: Unknown state %d\n",
29817 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
29818 + printk(KERN_DEBUG "%s: privacy configuration mismatch and "
29819 + "mixed-cell disabled - disassociate\n", dev->name);
29821 + ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
29822 + ieee80211_set_associated(dev, ifsta, 0);
29827 +static void ieee80211_sta_new_auth(struct net_device *dev,
29828 + struct ieee80211_if_sta *ifsta)
29830 + struct ieee80211_local *local = dev->priv;
29832 + if (local->conf.mode != IW_MODE_INFRA)
29835 + if (local->hw->reset_tsf) {
29836 + /* Reset own TSF to allow time synchronization work. */
29837 + local->hw->reset_tsf(local->mdev);
29840 + ifsta->wmm_last_param_set = -1; /* allow any WMM update */
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;
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);
29859 +static int ieee80211_ibss_allowed(struct ieee80211_local *local)
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)
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)
29882 +extern int ieee80211_ioctl_siwfreq(struct net_device *dev,
29883 + struct iw_request_info *info,
29884 + struct iw_freq *freq, char *extra);
29886 +static int ieee80211_sta_join_ibss(struct net_device *dev,
29887 + struct ieee80211_if_sta *ifsta,
29888 + struct ieee80211_sta_bss *bss)
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;
29899 + struct ieee80211_sub_if_data *sdata;
29901 + /* Remove possible STA entries from other IBSS networks. */
29902 + sta_info_flush(local, NULL);
29904 + if (local->hw->reset_tsf) {
29905 + /* Reset own TSF to allow time synchronization work. */
29906 + local->hw->reset_tsf(local->mdev);
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);
29912 + local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
29914 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29915 + sdata->drop_unencrypted = bss->capability &
29916 + cpu_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
29918 + memset(&rq, 0, sizeof(rq));
29919 + rq.m = bss->freq * 100000;
29921 + res = ieee80211_ioctl_siwfreq(dev, NULL, &rq, NULL);
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);
29930 + /* Set beacon template based on scan results */
29931 + skb = dev_alloc_skb(400);
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);
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);
29953 + rates = bss->supp_rates_len;
29956 + pos = skb_put(skb, 2 + rates);
29957 + *pos++ = WLAN_EID_SUPP_RATES;
29959 + memcpy(pos, bss->supp_rates, rates);
29961 + pos = skb_put(skb, 2 + 1);
29962 + *pos++ = WLAN_EID_DS_PARAMS;
29964 + *pos++ = bss->channel;
29966 + pos = skb_put(skb, 2 + 2);
29967 + *pos++ = WLAN_EID_IBSS_PARAMS;
29969 + /* FIX: set ATIM window based on scan results */
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;
29978 + memcpy(pos, &bss->supp_rates[8], rates);
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);
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;
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);
30008 + printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
30009 + "template for IBSS\n", dev->name);
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);
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)
30024 + for (j = 0; j < local->num_curr_rates; j++)
30025 + if (local->curr_rates[j].rate == rate)
30028 + ifsta->supp_rates_bits = rates;
30032 + printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
30033 + "template\n", dev->name);
30034 + dev_kfree_skb(skb);
30037 + ifsta->state = IEEE80211_IBSS_JOINED;
30038 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30040 + ieee80211_rx_bss_put(dev, bss);
30046 +static int ieee80211_sta_create_ibss(struct net_device *dev,
30047 + struct ieee80211_if_sta *ifsta)
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;
30056 + /* Easier testing, use fixed BSSID. */
30057 + memset(bssid, 0xfe, ETH_ALEN);
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;
30069 + printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID " MACSTR "\n",
30070 + dev->name, MAC2STR(bssid));
30072 + bss = ieee80211_rx_bss_add(dev, bssid);
30076 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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);
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)
30096 + *pos++ = (u8) (rate / 5);
30099 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30103 +static int ieee80211_sta_find_ibss(struct net_device *dev,
30104 + struct ieee80211_if_sta *ifsta)
30106 + struct ieee80211_local *local = dev->priv;
30107 + struct ieee80211_sta_bss *bss;
30109 + u8 bssid[ETH_ALEN];
30110 + struct list_head *ptr;
30113 + if (ifsta->ssid_len == 0)
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))
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);
30134 + if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
30137 + spin_unlock_bh(&local->sta_bss_lock);
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);
30150 +#ifdef IEEE80211_IBSS_DEBUG
30151 + printk(KERN_DEBUG " did not try to join ibss\n");
30152 +#endif /* IEEE80211_IBSS_DEBUG */
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;
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);
30180 + /* No IBSS found - decrease scan interval and continue
30182 + interval = IEEE80211_SCAN_INTERVAL_SLOW;
30185 + ifsta->state = IEEE80211_IBSS_SEARCH;
30186 + mod_timer(&ifsta->timer, jiffies + interval);
30194 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
30196 + struct ieee80211_sub_if_data *sdata;
30197 + struct ieee80211_if_sta *ifsta;
30198 + struct ieee80211_local *local = dev->priv;
30200 + if (len > IEEE80211_MAX_SSID_LEN)
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;
30209 + memset(&qparam, 0, sizeof(qparam));
30210 + /* TODO: are these ok defaults for all hw_modes? */
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++)
30218 + local->hw->conf_tx(dev, i + IEEE80211_TX_QUEUE_DATA0,
30221 + /* IBSS uses different parameters for Beacon sending */
30223 + qparam.cw_min *= 2;
30225 + local->hw->conf_tx(dev, IEEE80211_TX_QUEUE_BEACON, &qparam);
30228 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30229 + ifsta = &sdata->u.sta;
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;
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);
30244 + if (ifsta->bssid_set && ifsta->state != IEEE80211_AUTHENTICATE)
30245 + ieee80211_sta_new_auth(dev, ifsta);
30251 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
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;
30261 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
30263 + struct ieee80211_local *local = dev->priv;
30264 + struct ieee80211_sub_if_data *sdata;
30265 + struct ieee80211_if_sta *ifsta;
30267 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30268 + ifsta = &sdata->u.sta;
30270 + memcpy(ifsta->bssid, bssid, ETH_ALEN);
30271 + if (local->conf.mode == IW_MODE_ADHOC)
30272 + memcpy(local->bssid, bssid, ETH_ALEN);
30274 + if (memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
30275 + ifsta->bssid_set = 0;
30277 + ifsta->bssid_set = 1;
30278 + if (ifsta->ssid_set)
30279 + ieee80211_sta_new_auth(dev, ifsta);
30285 +static void ieee80211_sta_save_oper_chan(struct net_device *dev)
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;
30297 +static int ieee80211_sta_restore_oper_chan(struct net_device *dev)
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);
30310 +static int ieee80211_active_scan(struct ieee80211_local *local)
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)
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)
30333 +static void ieee80211_sta_scan_timer(unsigned long ptr)
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;
30340 + union iwreq_data wrqu;
30342 + if (!local->sta_scanning)
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",
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);
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))
30383 + printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
30384 + dev->name, chan->chan, chan->freq);
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);
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;
30409 + local->scan_timer.expires = jiffies;
30413 + local->scan_timer.expires = jiffies + IEEE80211_PROBE_DELAY;
30414 + local->scan_state = SCAN_SEND_PROBE;
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;
30423 + local->scan_timer.expires =
30424 + jiffies + IEEE80211_PASSIVE_CHANNEL_TIME;
30426 + local->scan_state = SCAN_SET_CHANNEL;
30430 + add_timer(&local->scan_timer);
30434 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
30436 + struct ieee80211_local *local = dev->priv;
30438 + if (ssid_len > IEEE80211_MAX_SSID_LEN)
30441 + /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
30442 + * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
30443 + * BSSID: MACAddress
30445 + * ScanType: ACTIVE, PASSIVE
30446 + * ProbeDelay: delay (in microseconds) to be used prior to transmitting
30447 + * a Probe frame during active scanning
30449 + * MinChannelTime (>= ProbeDelay), in TU
30450 + * MaxChannelTime: (>= MinChannelTime), in TU
30453 + /* MLME-SCAN.confirm
30454 + * BSSDescriptionSet
30455 + * ResultCode: SUCCESS, INVALID_PARAMETERS
30458 + /* TODO: if assoc, move to power save mode for the duration of the
30461 + if (local->sta_scanning)
30464 + printk(KERN_DEBUG "%s: starting scan\n", dev->name);
30466 + ieee80211_sta_save_oper_chan(dev);
30468 + local->sta_scanning = 1;
30469 + /* TODO: stop TX queue? */
30472 + local->scan_ssid_len = ssid_len;
30473 + memcpy(local->scan_ssid, ssid, ssid_len);
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);
30491 +ieee80211_sta_scan_result(struct net_device *dev,
30492 + struct ieee80211_sta_bss *bss,
30493 + char *current_ev, char *end_buf)
30495 + struct ieee80211_local *local = dev->priv;
30496 + struct iw_event iwe;
30498 + if (time_after(jiffies,
30499 + bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
30500 + return current_ev;
30502 + if (!(local->hw_modes & (1 << bss->hw_mode)))
30503 + return current_ev;
30505 + if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY &&
30506 + bss->wpa_ie == NULL && bss->rsn_ie == NULL)
30507 + return current_ev;
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;
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,
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,
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;
30534 + iwe.u.mode = IW_MODE_ADHOC;
30535 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
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,
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;
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, "");
30555 + if (bss && bss->wpa_ie) {
30558 + buf = kmalloc(30 + bss->wpa_ie_len * 2, GFP_ATOMIC);
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,
30573 + if (bss && bss->rsn_ie) {
30576 + buf = kmalloc(30 + bss->rsn_ie_len * 2, GFP_ATOMIC);
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,
30593 + buf = kmalloc(30, GFP_ATOMIC);
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,
30609 + if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO))
30612 + buf = kmalloc(100, GFP_ATOMIC);
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,
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,
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,
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,
30651 + return current_ev;
30655 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
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;
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,
30669 + spin_unlock_bh(&local->sta_bss_lock);
30670 + return current_ev - buf;
30674 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
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);
30680 + ifsta->extra_ie = NULL;
30681 + ifsta->extra_ie_len = 0;
30684 + ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
30685 + if (ifsta->extra_ie == NULL) {
30686 + ifsta->extra_ie_len = 0;
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);
30698 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
30699 + struct sk_buff *skb, u8 *bssid,
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;
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));
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;
30727 + spin_unlock_bh(&local->sub_if_lock);
30729 + if (sta_dev == NULL)
30732 + printk(KERN_DEBUG "%s: Adding new IBSS station " MACSTR " (dev=%s)\n",
30733 + dev->name, MAC2STR(addr), sta_dev->name);
30735 + sta = sta_info_add(local, dev, addr);
30736 + if (sta == NULL) {
30740 + sta->dev = sta_dev;
30741 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
30743 + rate_control_rate_init(local, sta);
30745 + return sta; /* caller will call sta_info_release() */
30749 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
30751 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30752 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30754 + printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
30755 + dev->name, reason);
30757 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30760 + ieee80211_send_deauth(dev, ifsta, reason);
30761 + ieee80211_set_associated(dev, ifsta, 0);
30766 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
30768 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30769 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30771 + printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
30772 + dev->name, reason);
30774 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30777 + if (!ifsta->associated)
30780 + ieee80211_send_disassoc(dev, ifsta, reason);
30781 + ieee80211_set_associated(dev, ifsta, 0);
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
30789 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
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.
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"
30804 +#define to_ieee80211_local(class) container_of(class, struct ieee80211_local, class_dev)
30807 +static ssize_t store_add_iface(struct class_device *dev,
30808 + const char *buf, size_t len)
30810 + struct ieee80211_local *local = to_ieee80211_local(dev);
30813 + if (!capable(CAP_NET_ADMIN))
30815 + if (len > IFNAMSIZ)
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. */
30821 + res = ieee80211_if_add_sta(local->mdev, buf, 1);
30823 + return res < 0 ? res : len;
30826 +static ssize_t store_remove_iface(struct class_device *dev,
30827 + const char *buf, size_t len)
30829 + struct ieee80211_local *local = to_ieee80211_local(dev);
30832 + if (!capable(CAP_NET_ADMIN))
30834 + if (len > IFNAMSIZ)
30836 + res = ieee80211_if_remove_sta(local->mdev, buf, 0);
30837 + return res < 0 ? res : len;
30840 +static ssize_t show_max_iface_count(struct class_device *dev,
30843 + struct ieee80211_local *local = to_ieee80211_local(dev);
30845 + return sprintf(buf, "%d\n", local->conf.bss_count);
30848 +static ssize_t store_max_iface_count(struct class_device *dev,
30849 + const char *buf, size_t len)
30851 + struct ieee80211_local *local = to_ieee80211_local(dev);
30852 + unsigned long new_count;
30856 + if (!capable(CAP_NET_ADMIN))
30858 + new_count = simple_strtoul(buf, &endp, 0);
30862 + res = ieee80211_set_bss_count(local->mdev, new_count, NULL);
30864 + return res < 0 ? res : len;
30867 +#ifdef CONFIG_HOTPLUG
30868 +static int ieee80211_uevent(struct class_device *cd, char **envp,
30869 + int num_envp, char *buf, int size)
30871 + struct ieee80211_local *local = to_ieee80211_local(cd);
30873 + if (num_envp < 2)
30876 + if (snprintf(buf, size, "IEEE80211_DEV=phy%d",
30877 + local->dev_index) + 1 >= size)
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),
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,
30900 +int ieee80211_register_sysfs(struct ieee80211_local *local)
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);
30909 +void ieee80211_unregister_sysfs(struct ieee80211_local *local)
30911 + class_device_del(&local->class_dev);
30914 +int ieee80211_sysfs_init(void)
30916 + return class_register(&ieee80211_class);
30919 +void ieee80211_sysfs_deinit(void)
30921 + class_unregister(&ieee80211_class);
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
30928 + tristate "Generic IEEE 802.11 Networking Stack (dscape)"
30930 + This option enables the hardware independent IEEE 802.11
30931 + networking stack.
30933 +config D80211_DEBUG
30934 + bool "Enable debugging output"
30935 + depends on D80211
30937 + This option will enable debug tracing output for the
30938 + ieee80211 network stack.
30940 + If you are not trying to debug or develop the ieee80211
30941 + subsystem, you most likely want to say N here.
30943 +config D80211_VERBOSE_DEBUG
30944 + bool "Verbose debugging output"
30945 + depends on D80211_DEBUG
30948 + bool "TKIP debugging"
30949 + depends on D80211_DEBUG
30951 +config D80211_DEBUG_COUNTERS
30952 + bool "Extra statistics for TX/RX debugging"
30953 + depends on D80211_DEBUG
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
30962 +obj-$(CONFIG_D80211) += 80211.o rate_control.o
30966 + ieee80211_ioctl.o \
30970 + ieee80211_proc.o \
30971 + ieee80211_scan.o \
30972 + ieee80211_sta.o \
30973 + ieee80211_dev.o \
30974 + ieee80211_sysfs.o \
30980 +ifeq ($(CONFIG_NET_SCHED),)
30981 + 80211-objs += fifo_qdisc.o
30984 +ifeq ($(CONFIG_D80211_LEDS),y)
30985 + 80211-objs += ieee80211_led.o
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
30993 + * Michael MIC implementation - optimized for TKIP MIC operations
30994 + * Copyright 2002-2003, Instant802 Networks, Inc.
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.
31001 +#include <linux/types.h>
31003 +#include "michael.h"
31005 +static inline u32 rotr(u32 val, int bits)
31007 + return (val >> bits) | (val << (32 - bits));
31011 +static inline u32 rotl(u32 val, int bits)
31013 + return (val << bits) | (val >> (32 - bits));
31017 +static inline u32 xswap(u32 val)
31019 + return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
31023 +#define michael_block(l, r) \
31025 + r ^= rotl(l, 17); \
31029 + r ^= rotl(l, 3); \
31031 + r ^= rotr(l, 2); \
31036 +static inline u32 michael_get32(u8 *data)
31038 + return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
31042 +static inline void michael_put32(u32 val, u8 *data)
31044 + data[0] = val & 0xff;
31045 + data[1] = (val >> 8) & 0xff;
31046 + data[2] = (val >> 16) & 0xff;
31047 + data[3] = (val >> 24) & 0xff;
31051 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31052 + u8 *data, size_t data_len, u8 *mic)
31055 + size_t block, blocks, left;
31057 + l = michael_get32(key);
31058 + r = michael_get32(key + 4);
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);
31069 + michael_block(l, r);
31072 + blocks = data_len / 4;
31073 + left = data_len % 4;
31075 + for (block = 0; block < blocks; block++) {
31076 + l ^= michael_get32(&data[block * 4]);
31077 + michael_block(l, r);
31080 + /* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
31081 + * total length a multiple of 4. */
31083 + while (left > 0) {
31086 + val |= data[blocks * 4 + left];
31089 + michael_block(l, r);
31090 + /* last block is zero, so l ^ 0 = l */
31091 + michael_block(l, r);
31093 + michael_put32(l, mic);
31094 + michael_put32(r, mic + 4);
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
31101 + * Michael MIC implementation - optimized for TKIP MIC operations
31102 + * Copyright 2002-2003, Instant802 Networks, Inc.
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.
31112 +#include <linux/types.h>
31114 +#define MICHAEL_MIC_LEN 8
31116 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31117 + u8 *data, size_t data_len, u8 *mic);
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
31125 + * Copyright 2002-2005, Instant802 Networks, Inc.
31126 + * Copyright 2005, Devicescape Software, Inc.
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.
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>
31143 +#include <net/d80211.h>
31144 +#include "ieee80211_i.h"
31145 +#include "rate_control.h"
31148 +/* This is a minimal implementation of TX rate controlling that can be used
31149 + * as the default when no improved mechanisms are available. */
31152 +#define RATE_CONTROL_EMERG_DEC 2
31153 +#define RATE_CONTROL_INTERVAL (HZ / 20)
31154 +#define RATE_CONTROL_MIN_TX 10
31156 +MODULE_ALIAS("ieee80211_rate_control");
31158 +static void rate_control_rate_inc(struct ieee80211_local *local,
31159 + struct sta_info *sta)
31161 + struct ieee80211_sub_if_data *sdata;
31162 + int i = sta->txrate;
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 */
31171 + maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
31173 + if (i > local->num_curr_rates)
31174 + i = local->num_curr_rates - 2;
31176 + while (i + 1 < local->num_curr_rates) {
31178 + if (sta->supp_rates & BIT(i) &&
31179 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED &&
31180 + (maxrate < 0 || i <= maxrate)) {
31188 +static void rate_control_rate_dec(struct ieee80211_local *local,
31189 + struct sta_info *sta)
31191 + struct ieee80211_sub_if_data *sdata;
31192 + int i = sta->txrate;
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 */
31200 + if (i > local->num_curr_rates)
31201 + i = local->num_curr_rates;
31205 + if (sta->supp_rates & BIT(i) &&
31206 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED) {
31214 +static struct ieee80211_rate *
31215 +rate_control_lowest_rate(struct ieee80211_local *local)
31219 + for (i = 0; i < local->num_curr_rates; i++) {
31220 + struct ieee80211_rate *rate = &local->curr_rates[i];
31222 + if (rate->flags & IEEE80211_RATE_SUPPORTED
31227 + printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
31229 + return &local->curr_rates[0];
31233 +struct global_rate_control {
31237 +struct sta_rate_control {
31238 + unsigned long last_rate_change;
31239 + u32 tx_num_failures;
31242 + unsigned long avg_rate_update;
31243 + u32 tx_avg_rate_sum;
31244 + u32 tx_avg_rate_num;
31248 +static void rate_control_simple_tx_status(struct net_device *dev,
31249 + struct sk_buff *skb,
31250 + struct ieee80211_tx_status *status)
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;
31257 + sta = sta_info_get(local, hdr->addr1);
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 "
31269 + dev->name, MAC2STR(hdr->addr1),
31270 + sta->antenna_sel, jiffies);
31272 + srctrl->tx_num_failures++;
31273 + sta->tx_retry_failed++;
31274 + sta->tx_num_consecutive_failures++;
31275 + sta->tx_num_mpdu_fail++;
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++;
31283 + sta->tx_retry_count += status->retry_count;
31284 + sta->tx_num_mpdu_fail += status->retry_count;
31286 + if (time_after(jiffies,
31287 + srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
31288 + srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
31290 + srctrl->last_rate_change = jiffies;
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 */
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,
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);
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);
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: "
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;
31335 + sta_info_release(local, sta);
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)
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;
31350 + memset(extra, 0, sizeof(*extra));
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);
31361 + sta = sta_info_get(local, hdr->addr1);
31364 + return rate_control_lowest_rate(local);
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;
31370 + rateidx = sta->txrate;
31372 + if (rateidx >= local->num_curr_rates)
31373 + rateidx = local->num_curr_rates - 1;
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))))
31383 + extra->nonerp_idx = nonerp_idx;
31384 + extra->nonerp = &local->curr_rates[extra->nonerp_idx];
31386 + sta_info_release(local, sta);
31388 + return &local->curr_rates[rateidx];
31392 +static void rate_control_simple_rate_init(struct ieee80211_local *local,
31393 + struct sta_info *sta)
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))
31409 +static void * rate_control_simple_alloc(struct ieee80211_local *local)
31411 + struct global_rate_control *rctrl;
31413 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31414 + if (rctrl == NULL) {
31417 + memset(rctrl, 0, sizeof(*rctrl));
31422 +static void rate_control_simple_free(void *priv)
31424 + struct global_rate_control *rctrl = priv;
31429 +static void rate_control_simple_clear(void *priv)
31434 +static void * rate_control_simple_alloc_sta(void)
31436 + struct sta_rate_control *rctrl;
31438 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31439 + if (rctrl == NULL) {
31442 + memset(rctrl, 0, sizeof(*rctrl));
31447 +static void rate_control_simple_free_sta(void *priv)
31449 + struct sta_rate_control *rctrl = priv;
31454 +static int rate_control_simple_status_sta(struct ieee80211_local *local,
31455 + struct sta_info *sta, char *buf)
31458 + struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
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);
31470 +static int rate_control_simple_status_global(struct ieee80211_local *local,
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,
31492 +int __init rate_control_simple_init(void)
31494 + return ieee80211_rate_control_register(&rate_control_simple);
31498 +static void __exit rate_control_simple_exit(void)
31500 + ieee80211_rate_control_unregister(&rate_control_simple);
31504 +module_init(rate_control_simple_init);
31505 +module_exit(rate_control_simple_exit);
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
31514 + * Copyright 2002-2005, Instant802 Networks, Inc.
31515 + * Copyright 2005, Devicescape Software, Inc.
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.
31522 +#ifndef RATE_CONTROL
31523 +#define RATE_CONTROL
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"
31532 +#define RATE_CONTROL_NUM_DOWN 20
31533 +#define RATE_CONTROL_NUM_UP 15
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
31540 + int startidx, endidx, rateidx;
31541 + struct ieee80211_rate *nonerp;
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) */
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);
31564 + void * (*alloc)(struct ieee80211_local *local);
31565 + void (*free)(void *priv);
31566 + void * (*alloc_sta)(void);
31567 + void (*free_sta)(void *priv);
31571 +int ieee80211_rate_control_register(struct rate_control_ops *ops);
31572 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
31575 +static inline void rate_control_tx_status(struct net_device *dev,
31576 + struct sk_buff *skb,
31577 + struct ieee80211_tx_status *status)
31579 + struct ieee80211_local *local = dev->priv;
31580 + local->rate_ctrl->tx_status(dev, skb, status);
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)
31588 + struct ieee80211_local *local = dev->priv;
31589 + return local->rate_ctrl->get_rate(dev, skb, extra);
31593 +static inline void rate_control_rate_init(struct ieee80211_local *local,
31594 + struct sta_info *sta)
31596 + local->rate_ctrl->rate_init(local, sta);
31600 +static inline void rate_control_clear(struct ieee80211_local *local)
31602 + local->rate_ctrl->clear(local->rate_ctrl_priv);
31606 +static inline int rate_control_status_sta(struct ieee80211_local *local,
31607 + struct sta_info *sta, char *buf)
31609 + return local->rate_ctrl->status_sta(local, sta, buf);
31613 +static inline int rate_control_status_global(struct ieee80211_local *local,
31616 + return local->rate_ctrl->status_global(local, buf);
31620 +static inline void * rate_control_alloc(struct ieee80211_local *local)
31622 + return local->rate_ctrl->alloc(local);
31626 +static inline void rate_control_free(struct ieee80211_local *local)
31628 + if (local->rate_ctrl == NULL || local->rate_ctrl_priv == NULL)
31630 + local->rate_ctrl->free(local->rate_ctrl_priv);
31631 + local->rate_ctrl_priv = NULL;
31635 +static inline void * rate_control_alloc_sta(struct ieee80211_local *local)
31637 + return local->rate_ctrl->alloc_sta();
31641 +static inline void rate_control_free_sta(struct ieee80211_local *local,
31644 + local->rate_ctrl->free_sta(priv);
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
31653 + * Copyright 2002-2005, Instant802 Networks, Inc.
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.
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>
31670 +#include <net/d80211.h>
31671 +#include "ieee80211_i.h"
31672 +#include "ieee80211_proc.h"
31673 +#include "rate_control.h"
31676 +/* Caller must hold local->sta_lock */
31677 +static void sta_info_hash_add(struct ieee80211_local *local,
31678 + struct sta_info *sta)
31680 + sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
31681 + local->sta_hash[STA_HASH(sta->addr)] = sta;
31685 +/* Caller must hold local->sta_lock */
31686 +static void sta_info_hash_del(struct ieee80211_local *local,
31687 + struct sta_info *sta)
31689 + struct sta_info *s;
31691 + s = local->sta_hash[STA_HASH(sta->addr)];
31694 + if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
31695 + local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
31699 + while (s->hnext != NULL &&
31700 + memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
31702 + if (s->hnext != NULL)
31703 + s->hnext = s->hnext->hnext;
31705 + printk(KERN_ERR "%s: could not remove STA " MACSTR " from "
31706 + "hash table\n", local->mdev->name, MAC2STR(sta->addr));
31710 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr)
31712 + struct sta_info *sta;
31714 + spin_lock_bh(&local->sta_lock);
31715 + sta = local->sta_hash[STA_HASH(addr)];
31717 + if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
31718 + atomic_inc(&sta->users);
31721 + sta = sta->hnext;
31723 + spin_unlock_bh(&local->sta_lock);
31729 +int sta_info_min_txrate_get(struct ieee80211_local *local)
31731 + struct sta_info *sta;
31732 + int min_txrate = 9999999;
31735 + spin_lock_bh(&local->sta_lock);
31736 + for (i = 0; i < STA_HASH_SIZE; i++) {
31737 + sta = local->sta_hash[i];
31739 + if (sta->txrate < min_txrate)
31740 + min_txrate = sta->txrate;
31741 + sta = sta->hnext;
31744 + spin_unlock_bh(&local->sta_lock);
31745 + if (min_txrate == 9999999)
31748 + return min_txrate;
31752 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta)
31754 + struct sk_buff *skb;
31756 + if (!atomic_dec_and_test(&sta->users))
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);
31767 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31768 + dev_kfree_skb_any(skb);
31770 + rate_control_free_sta(local, sta->rate_ctrl_priv);
31775 +struct sta_info * sta_info_add(struct ieee80211_local *local,
31776 + struct net_device *dev, u8 *addr)
31778 + struct sta_info *sta;
31780 + sta = kmalloc(sizeof(*sta), GFP_ATOMIC);
31784 + memset(sta, 0, sizeof(*sta));
31786 + sta->rate_ctrl_priv = rate_control_alloc_sta(local);
31787 + if (sta->rate_ctrl_priv == NULL) {
31792 + memcpy(sta->addr, addr, ETH_ALEN);
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;
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 */
31814 + if (!in_interrupt()) {
31815 + ieee80211_proc_init_sta(local, sta);
31817 + /* procfs entry adding might sleep, so schedule process context
31818 + * task for adding proc entry for STAs that do not yet have
31820 + schedule_work(&local->sta_proc_add);
31827 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
31830 + struct sk_buff *skb;
31831 + struct ieee80211_sub_if_data *sdata;
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;
31841 + atomic_dec(&sdata->bss->num_sta_ps);
31843 + local->num_sta--;
31844 + sta_info_remove_aid_ptr(sta);
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);
31850 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31851 + local->total_ps_buffered--;
31852 + dev_kfree_skb_any(skb);
31854 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31855 + dev_kfree_skb_any(skb);
31859 + if (local->hw->set_key) {
31860 + struct ieee80211_key_conf *key;
31861 + key = ieee80211_key_data2conf(local, sta->key);
31863 + local->hw->set_key(local->mdev, DISABLE_KEY,
31864 + sta->addr, key, sta->aid);
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,
31878 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
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 */
31886 + ieee80211_proc_deinit_sta(local, sta);
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));
31897 + sta_info_release(local, sta);
31901 +static inline int sta_info_buffer_expired(struct sk_buff *skb)
31903 + struct ieee80211_tx_packet_data *pkt_data;
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 */
31911 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
31912 + return time_after(jiffies, pkt_data->jiffies + STA_TX_BUFFER_EXPIRE);
31916 +static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
31917 + struct sta_info *sta)
31919 + unsigned long flags;
31920 + struct sk_buff *skb;
31922 + if (skb_queue_empty(&sta->ps_tx_buf))
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);
31932 + spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
31935 + local->total_ps_buffered--;
31936 + printk(KERN_DEBUG "Buffered frame expired (STA "
31937 + MACSTR ")\n", MAC2STR(sta->addr));
31938 + dev_kfree_skb(skb);
31945 +static void sta_info_cleanup(unsigned long data)
31947 + struct ieee80211_local *local = (struct ieee80211_local *) data;
31948 + struct list_head *ptr;
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);
31959 + spin_unlock_bh(&local->sta_lock);
31961 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
31962 + add_timer(&local->sta_cleanup);
31966 +static void sta_info_proc_add_task(void *data)
31968 + struct ieee80211_local *local = data;
31969 + struct list_head *ptr;
31970 + struct sta_info *sta;
31971 + int max_adds = 100;
31973 + while (max_adds > 0) {
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);
31984 + spin_unlock_bh(&local->sta_lock);
31989 + ieee80211_proc_init_sta(local, sta);
31990 + atomic_dec(&sta->users);
31997 +void sta_info_init(struct ieee80211_local *local)
31999 + spin_lock_init(&local->sta_lock);
32000 + INIT_LIST_HEAD(&local->sta_list);
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;
32007 + INIT_WORK(&local->sta_proc_add, sta_info_proc_add_task, local);
32010 +void sta_info_start(struct ieee80211_local *local)
32012 + add_timer(&local->sta_cleanup);
32015 +void sta_info_stop(struct ieee80211_local *local)
32017 + struct list_head *ptr;
32019 + del_timer(&local->sta_cleanup);
32021 + ptr = local->sta_list.next;
32022 + while (ptr && ptr != &local->sta_list) {
32023 + struct sta_info *sta = (struct sta_info *) ptr;
32025 + sta_info_free(local, sta, 0);
32030 +void sta_info_remove_aid_ptr(struct sta_info *sta)
32032 + struct ieee80211_sub_if_data *sdata;
32034 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
32035 + if (sta->aid <= 0 || !sdata->bss)
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--;
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
32052 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
32054 + struct list_head *ptr, *n;
32056 + spin_lock_bh(&local->sta_lock);
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);
32063 + spin_unlock_bh(&local->sta_lock);
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
32070 + * Copyright 2002-2005, Devicescape Software, Inc.
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.
32077 +#ifndef STA_INFO_H
32078 +#define STA_INFO_H
32080 +#include <linux/if_ether.h>
32081 +#include <linux/types.h>
32082 +#include "ieee80211_i.h"
32083 +#include "ieee80211_key.h"
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
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)
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) */
32106 + u8 addr[ETH_ALEN];
32107 + u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
32108 + u32 flags; /* WLAN_STA_ */
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;
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;
32123 + unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
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;
32131 + struct net_device *dev; /* which net device is this station associated
32134 + struct ieee80211_key *key;
32136 + u32 tx_num_consecutive_failures;
32137 + u32 tx_num_mpdu_ok;
32138 + u32 tx_num_mpdu_fail;
32140 + void *rate_ctrl_priv;
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 */
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;
32154 + int channel_use_raw;
32159 + int key_idx_compression; /* key table index for compression and TX
32160 + * filtering; used only if sta->key is not
32163 + int proc_entry_added:1;
32164 + int assoc_ap:1; /* whether this is an AP that we are associated with
32167 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
32169 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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 */
32180 +/* Maximum number of concurrently registered stations */
32181 +#define MAX_STA_COUNT 2007
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
32187 +#define STA_HASH_SIZE 256
32188 +#define STA_HASH(sta) (sta[5])
32191 +/* Maximum number of frames to buffer per power saving station */
32192 +#define STA_MAX_TX_BUFFER 128
32194 +/* Buffered frame expiry time */
32195 +#define STA_TX_BUFFER_EXPIRE (10 * HZ)
32197 +/* How often station data is cleaned up (e.g., expiration of buffered frames)
32199 +#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
32201 +struct ieee80211_local;
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,
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);
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
32222 + * Copyright 2002-2004, Instant802 Networks, Inc.
32223 + * Copyright 2005, Devicescape Software, Inc.
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.
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 */
32238 +#include <linux/types.h>
32239 +#include <linux/netdevice.h>
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 */
32248 +/* Dummy prototypes for structures used in wep.h, but not really needed for
32250 +struct ieee80211_local;
32255 +/* TKIP key mixing functions */
32258 +#define PHASE1_LOOP_COUNT 8
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] =
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,
32300 +static inline u16 Mk16(u8 x, u8 y)
32302 + return ((u16) x << 8) | (u16) y;
32306 +static inline u8 Hi8(u16 v)
32312 +static inline u8 Lo8(u16 v)
32318 +static inline u16 Hi16(u32 v)
32324 +static inline u16 Lo16(u32 v)
32326 + return v & 0xffff;
32330 +static inline u16 RotR1(u16 v)
32332 + return (v >> 1) | ((v & 0x0001) << 15);
32336 +static inline u16 tkip_S(u16 val)
32338 + u16 a = tkip_sbox[Hi8(val)];
32340 + return tkip_sbox[Lo8(val)] ^ Hi8(a) ^ (Lo8(a) << 8);
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)
32351 +static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
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]);
32362 + for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
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;
32373 +static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
32384 + ppk[5] = p1k[4] + tsc_IV16;
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]);
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);
32404 + for (i = 0; i < 6; i++) {
32405 + rc4key[4 + 2 * i] = Lo8(ppk[i]);
32406 + rc4key[5 + 2 * i] = Hi8(ppk[i]);
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)
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;
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)
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;
32447 + tkip_mixing_phase2(key->u.tkip.p1k, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32448 + key->u.tkip.iv16, rc4key);
32450 + pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]);
32451 + ieee80211_wep_encrypt_data(rc4key, 16, pos, payload_len);
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,
32465 + u8 rc4key[16], keyid, *pos = payload;
32468 + if (payload_len < 12)
32471 + iv16 = (pos[0] << 8) | pos[2];
32473 + iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
32475 +#ifdef CONFIG_TKIP_DEBUG
32478 + printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len);
32479 + for (i = 0; i < payload_len; i++)
32480 + printk(" %02x", payload[i]);
32482 + printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n",
32485 +#endif /* CONFIG_TKIP_DEBUG */
32487 + if (!(keyid & (1 << 5)))
32488 + return TKIP_DECRYPT_NO_EXT_IV;
32490 + if ((keyid >> 6) != key->keyidx)
32491 + return TKIP_DECRYPT_INVALID_KEYIDX;
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",
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;
32508 + res = TKIP_DECRYPT_OK;
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
32521 + printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=" MACSTR
32522 + " TK=", MAC2STR(ta));
32523 + for (i = 0; i < 16; i++)
32525 + key->key[ALG_TKIP_TEMP_ENCR_KEY + i]);
32527 + printk(KERN_DEBUG "TKIP decrypt: P1K=");
32528 + for (i = 0; i < 5; i++)
32529 + printk("%04x ", key->u.tkip.p1k_rx[queue][i]);
32532 +#endif /* CONFIG_TKIP_DEBUG */
32535 + tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
32536 + &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32538 +#ifdef CONFIG_TKIP_DEBUG
32541 + printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key=");
32542 + for (i = 0; i < 16; i++)
32543 + printk("%02x ", rc4key[i]);
32546 +#endif /* CONFIG_TKIP_DEBUG */
32548 + res = ieee80211_wep_decrypt_data(rc4key, 16, pos, payload_len - 12);
32550 + if (res == TKIP_DECRYPT_OK) {
32551 + /* FIX: these should be updated only after Michael MIC has been
32553 + /* Record previously received IV */
32554 + key->u.tkip.iv32_rx[queue] = iv32;
32555 + key->u.tkip.iv16_rx[queue] = iv16;
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
32567 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
32577 +#include <linux/types.h>
32578 +#include "ieee80211_key.h"
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);
32585 + TKIP_DECRYPT_OK = 0,
32586 + TKIP_DECRYPT_NO_EXT_IV = -1,
32587 + TKIP_DECRYPT_INVALID_KEYIDX = -2,
32588 + TKIP_DECRYPT_REPLAY = -3,
32590 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32591 + size_t payload_len, u8 *ta, int only_iv,
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
32600 + * Software WEP encryption implementation
32601 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
32602 + * Copyright 2003, Instant802 Networks, Inc.
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.
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>
32616 +#include <net/d80211.h>
32617 +#include "ieee80211_i.h"
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,
32677 +void ieee80211_wep_init(struct ieee80211_local *local)
32679 + /* start WEP IV from a random value */
32680 + get_random_bytes(&local->wep_iv, WEP_IV_LEN);
32684 +static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
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)
32698 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
32699 + struct ieee80211_key *key, u8 *iv)
32702 + if (ieee80211_wep_weak_iv(local->wep_iv, key->keylen))
32703 + local->wep_iv += 0x0100;
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;
32715 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
32716 + struct sk_buff *skb,
32717 + struct ieee80211_key *key)
32719 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32724 + fc = le16_to_cpu(hdr->frame_control);
32725 + fc |= WLAN_FC_ISWEP;
32726 + hdr->frame_control = cpu_to_le16(fc);
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,
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;
32744 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
32745 + struct sk_buff *skb,
32746 + struct ieee80211_key *key)
32748 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
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);
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,
32765 + u32 i, j, k, crc;
32768 +#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
32770 + /* Setup RC4 state */
32771 + for (i = 0; i < 256; i++)
32775 + for (i = 0; i < 256; i++) {
32776 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32778 + if (kpos >= klen)
32783 + /* Compute CRC32 over unencrypted data and apply RC4 to data */
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;
32792 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32796 + /* Append little-endian CRC32 and encrypt it to produce ICV */
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;
32805 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
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.
32815 + * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
32817 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
32818 + struct ieee80211_key *key)
32824 + if (key == NULL || key->alg != ALG_WEP)
32827 + klen = 3 + key->keylen;
32828 + rc4key = kmalloc(klen, GFP_ATOMIC);
32829 + if (rc4key == NULL)
32832 + iv = ieee80211_wep_add_iv(local, skb, key);
32833 + if (iv == NULL) {
32838 + len = skb->len - (iv + WEP_IV_LEN - skb->data);
32840 + /* Prepend 24-bit IV to RC4 key */
32841 + memcpy(rc4key, iv, 3);
32843 + /* Copy rest of the WEP key (the secret part) */
32844 + memcpy(rc4key + 3, key->key, key->keylen);
32846 + /* Add room for ICV */
32847 + skb_put(skb, WEP_ICV_LEN);
32849 + ieee80211_wep_encrypt_data(rc4key, klen, iv + WEP_IV_LEN, len);
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,
32863 + u32 i, j, k, crc;
32865 + u8 kpos, *pos, crcbuf[WEP_ICV_LEN], *cpos;
32867 + /* Setup RC4 state */
32868 + for (i = 0; i < 256; i++)
32872 + for (i = 0; i < 256; i++) {
32873 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32875 + if (kpos >= klen)
32880 + /* Apply RC4 to data and compute CRC32 over decrypted data */
32884 + for (k = 0; k < data_len; k++) {
32885 + i = (i + 1) & 0xff;
32886 + j = (j + S[i]) & 0xff;
32888 + *pos ^= S[(S[i] + S[j]) & 0xff];
32889 + crc = crc32_table[(crc ^ *pos++) & 0xff] ^ (crc >> 8);
32893 + /* Decrypt little-endian CRC32 and verify that it matches with the
32894 + * received ICV */
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;
32904 + if (*cpos++ != (*pos++ ^ S[(S[i] + S[j]) & 0xff])) {
32905 + /* ICV mismatch */
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.
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.
32922 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
32923 + struct ieee80211_key *key)
32928 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32934 + fc = le16_to_cpu(hdr->frame_control);
32935 + if (!(fc & WLAN_FC_ISWEP))
32938 + hdrlen = ieee80211_get_hdrlen(fc);
32940 + if (skb->len < 8 + hdrlen)
32943 + len = skb->len - hdrlen - 8;
32945 + keyidx = skb->data[hdrlen + 3] >> 6;
32947 + if (key == NULL || keyidx != key->keyidx || key->alg != ALG_WEP)
32950 + klen = 3 + key->keylen;
32952 + rc4key = kmalloc(klen, GFP_ATOMIC);
32953 + if (rc4key == NULL)
32956 + /* Prepend 24-bit IV to RC4 key */
32957 + memcpy(rc4key, skb->data + hdrlen, 3);
32959 + /* Copy rest of the WEP key (the secret part) */
32960 + memcpy(rc4key + 3, key->key, key->keylen);
32962 + if (ieee80211_wep_decrypt_data(rc4key, klen,
32963 + skb->data + hdrlen + WEP_IV_LEN,
32965 + printk(KERN_DEBUG "WEP decrypt failed (ICV)\n");
32972 + skb_trim(skb, skb->len - WEP_ICV_LEN);
32975 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
32976 + skb_pull(skb, WEP_IV_LEN);
32982 +int ieee80211_wep_get_keyidx(struct sk_buff *skb)
32984 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32988 + fc = le16_to_cpu(hdr->frame_control);
32989 + if (!(fc & WLAN_FC_ISWEP))
32992 + hdrlen = ieee80211_get_hdrlen(fc);
32994 + if (skb->len < 8 + hdrlen)
32997 + return skb->data[hdrlen + 3] >> 6;
33001 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
33003 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33009 + fc = le16_to_cpu(hdr->frame_control);
33010 + if (!(fc & WLAN_FC_ISWEP))
33013 + hdrlen = ieee80211_get_hdrlen(fc);
33014 + ivpos = skb->data + hdrlen;
33015 + iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
33017 + if (ieee80211_wep_weak_iv(iv, key->keylen))
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
33027 + * Software WEP encryption implementation
33028 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
33029 + * Copyright 2003, Instant802 Networks, Inc.
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.
33039 +#include <linux/skbuff.h>
33040 +#include <linux/types.h>
33041 +#include "ieee80211_i.h"
33042 +#include "ieee80211_key.h"
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);
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
33070 + * Copyright 2004, Instant802 Networks, Inc.
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.
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>
33085 +#include <net/d80211.h>
33086 +#include "ieee80211_i.h"
33089 +#define CHILD_QDISC_OPS pfifo_qdisc_ops
33091 +static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
33093 + return (fc & 0x8C) == 0x88;
33097 +ieee80211_txrx_result
33098 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
33100 + u8 *data = rx->skb->data;
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;
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;
33113 + /* no qos control present */
33114 + tid = 0; /* 802.1d - Best Effort */
33117 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
33118 + I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
33120 + I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
33122 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
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;
33129 + return TXRX_CONTINUE;
33133 +ieee80211_txrx_result
33134 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
33137 + u8 *data = rx->skb->data;
33138 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
33140 + if (!WLAN_FC_IS_QOS_DATA(fc))
33141 + return TXRX_CONTINUE;
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);
33150 + return TXRX_CONTINUE;
33154 +/* maximum number of hardware queues we support. */
33155 +#define TC_80211_MAX_QUEUES 8
33157 +struct ieee80211_sched_data
33159 + struct tcf_proto *filter_list;
33160 + struct Qdisc *queues[TC_80211_MAX_QUEUES];
33161 + struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
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)
33168 + struct iphdr *ip;
33172 +#ifdef CONFIG_NET_SCHED
33173 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33174 + struct tcf_result res = { -1, 0 };
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;
33182 +#endif /* CONFIG_NET_SCHED */
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;
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))
33197 + ip = (struct iphdr *) (skb->data + offset);
33199 + dscp = ip->tos & 0xfc;
33221 +static inline int wme_downgrade_ac(struct sk_buff *skb)
33223 + switch (skb->priority) {
33226 + skb->priority = 5; /* VO -> VI */
33230 + skb->priority = 3; /* VI -> BE */
33234 + skb->priority = 2; /* BE -> BK */
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)
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);
33252 + const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
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;
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];
33269 + /* is this a QoS frame? */
33270 + qos = fc & (WLAN_FC_STYPE_QOS_DATA << 4);
33273 + skb->priority = 0; /* required for correct WPA/11i MIC */
33274 + return ieee802_1d_to_ac[skb->priority];
33277 + /* use the data classifier to determine what 802.1d tag the
33278 + * data frame has */
33279 + skb->priority = classify_1d(skb, qd);
33281 + /* incase we are a client verify acm is not set for this ac */
33282 + for (; unlikely(local->wmm_acm & BIT(skb->priority)); )
33284 + if (wme_downgrade_ac(skb)) {
33285 + /* No AC with lower priority has acm=0,
33286 + * drop packet. */
33291 + /* look up which queue to use for frames with this 1d tag */
33292 + return ieee802_1d_to_ac[skb->priority];
33296 +static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
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;
33307 + if (pkt_data->requeue) {
33308 + skb_queue_tail(&q->requeued[pkt_data->queue], skb);
33312 + queue = classify80211(skb, qd);
33314 + /* now we know the 1d priority, fill in the QoS header if there is one
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 */
33323 + qc->tag1d = skb->priority;
33324 + if (local->wifi_wme_noack_test)
33325 + qc->ack_policy = 1;
33328 + if (unlikely(queue >= local->hw->queues)) {
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);
33336 + queue = local->hw->queues - 1;
33339 + if (unlikely(queue < 0)) {
33341 + err = NET_XMIT_DROP;
33343 + pkt_data->queue = (unsigned int) queue;
33344 + qdisc = q->queues[queue];
33345 + err = qdisc->enqueue(skb, qdisc);
33346 + if (err == NET_XMIT_SUCCESS) {
33348 + qd->bstats.bytes += skb->len;
33349 + qd->bstats.packets++;
33350 + return NET_XMIT_SUCCESS;
33353 + qd->qstats.drops++;
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)
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;
33369 + /* we recorded which queue to use earlier! */
33370 + qdisc = q->queues[pkt_data->queue];
33372 + if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
33376 + qd->qstats.drops++;
33381 +static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
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;
33392 + /* find which hardware queues have space in them */
33393 + hw->get_tx_stats(dev, &stats);
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)
33401 + /* there is space - try and get a frame */
33402 + skb = skb_dequeue(&q->requeued[queue]);
33406 + qdisc = q->queues[queue];
33407 + skb = qdisc->dequeue(qdisc);
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 */
33419 +static void wme_qdiscop_reset(struct Qdisc* qd)
33421 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33422 + struct ieee80211_local *local = qd->dev->priv;
33423 + struct ieee80211_hw *hw = local->hw;
33426 + /* QUESTION: should we have some hardware flush functionality here? */
33428 + for (queue = 0; queue < hw->queues; queue++) {
33429 + skb_queue_purge(&q->requeued[queue]);
33430 + qdisc_reset(q->queues[queue]);
33436 +static void wme_qdiscop_destroy(struct Qdisc* qd)
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;
33444 + while ((tp = q->filter_list) != NULL) {
33445 + q->filter_list = tp->next;
33446 + tp->ops->destroy(tp);
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;
33457 +/* called whenever parameters are updated on existing qdisc */
33458 +static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
33460 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
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);
33467 + if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
33469 + memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
33475 +/* called during initial creation of qdisc on device */
33476 +static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
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;
33484 + /* check this device is an ieee80211 master type device */
33485 + if (dev->type != ARPHRD_IEEE80211)
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)
33494 + if (qd->flags & TCQ_F_INGRESS)
33497 + /* if options were passed in, set them */
33499 + err = wme_qdiscop_tune(qd, opt);
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);
33515 +static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
33517 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33518 + unsigned char *p = skb->tail;
33519 + struct tc_ieee80211_qopt opt;
33521 + memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
33522 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
33523 +*/ return skb->len;
33526 + skb_trim(skb, p - skb->data);*/
33531 +static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
33532 + struct Qdisc *new, struct Qdisc **old)
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;
33539 + if (queue >= hw->queues)
33543 + new = &noop_qdisc;
33545 + sch_tree_lock(qd);
33546 + *old = q->queues[queue];
33547 + q->queues[queue] = new;
33548 + qdisc_reset(*old);
33549 + sch_tree_unlock(qd);
33555 +static struct Qdisc *
33556 +wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
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;
33563 + if (queue >= hw->queues)
33566 + return q->queues[queue];
33570 +static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
33572 + struct ieee80211_local *local = qd->dev->priv;
33573 + struct ieee80211_hw *hw = local->hw;
33574 + unsigned long queue = TC_H_MIN(classid);
33576 + if (queue - 1 >= hw->queues)
33583 +static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
33586 + return wme_classop_get(qd, classid);
33590 +static void wme_classop_put(struct Qdisc *q, unsigned long cl)
33592 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33596 +static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
33597 + struct rtattr **tca, unsigned long *arg)
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__); */
33604 + if (cl - 1 > hw->queues)
33607 + /* TODO: put code to program hardware queue parameters here,
33608 + * to allow programming from tc command line */
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)
33618 + struct ieee80211_local *local = qd->dev->priv;
33619 + struct ieee80211_hw *hw = local->hw;
33620 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33622 + if (cl - 1 > hw->queues)
33628 +static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
33629 + struct sk_buff *skb, struct tcmsg *tcm)
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__); */
33636 + if (cl - 1 > hw->queues)
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? */
33645 +static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
33647 + struct ieee80211_local *local = qd->dev->priv;
33648 + struct ieee80211_hw *hw = local->hw;
33650 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33655 + for (queue = 0; queue < hw->queues; queue++) {
33656 + if (arg->count < arg->skip) {
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) {
33671 +static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
33672 + unsigned long cl)
33674 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33675 + /* printk("entering %s\n", __func__); */
33680 + return &q->filter_list;
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 =
33688 + .graft = wme_classop_graft,
33689 + .leaf = wme_classop_leaf,
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,
33697 + .tcf_chain = wme_classop_find_tcf,
33698 + .bind_tcf = wme_classop_bind,
33699 + .unbind_tcf = wme_classop_put,
33701 + .dump = wme_classop_dump_class,
33705 +/* queueing discipline operations */
33706 +static struct Qdisc_ops wme_qdisc_ops =
33709 + .cl_ops = &class_ops,
33710 + .id = "ieee80211",
33711 + .priv_size = sizeof(struct ieee80211_sched_data),
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 */
33718 + .init = wme_qdiscop_init,
33719 + .reset = wme_qdiscop_reset,
33720 + .destroy = wme_qdiscop_destroy,
33721 + .change = wme_qdiscop_tune,
33723 + .dump = wme_qdiscop_dump,
33727 +void ieee80211_install_qdisc(struct net_device *dev)
33729 + struct Qdisc *qdisc;
33731 + qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops);
33732 + if (qdisc == NULL) {
33733 + printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
33737 + /* same handle as would be allocated by qdisc_alloc_handle() */
33738 + qdisc->handle = 0x80010000;
33740 + qdisc_lock_tree(dev);
33741 + list_add_tail(&qdisc->list, &dev->qdisc_list);
33742 + dev->qdisc_sleeping = qdisc;
33743 + qdisc_unlock_tree(dev);
33747 +int ieee80211_wme_register(void)
33751 +#ifdef CONFIG_NET_SCHED
33752 + err = register_qdisc(&wme_qdisc_ops);
33758 +void ieee80211_wme_unregister(void)
33760 +#ifdef CONFIG_NET_SCHED
33761 + unregister_qdisc(&wme_qdisc_ops);
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
33769 + * IEEE 802.11 driver (80211.o) - QoS datatypes
33770 + * Copyright 2004, Instant802 Networks, Inc.
33771 + * Copyright 2005, Devicescape Software, Inc.
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.
33781 +#include <asm/byteorder.h>
33782 +#include <linux/netdevice.h>
33783 +#include <linux/types.h>
33784 +#include <net/pkt_sched.h>
33786 +#define QOS_CONTROL_LEN 2
33788 +#define QOS_CONTROL_ACK_POLICY_NORMAL 0
33789 +#define QOS_CONTROL_ACK_POLICY_NOACK 1
33791 +#define QOS_CONTROL_TID_MASK 0x0f
33792 +#define QOS_CONTROL_ACK_POLICY_SHIFT 5
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 */
33803 +#elif defined (__BIG_ENDIAN_BITFIELD)
33808 + tag1d:3; /* bits 0-2 */
33810 +#error "Please fix <asm/byteorder.h>"
33813 +} __attribute__ ((packed));
33815 +ieee80211_txrx_result
33816 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx);
33818 +ieee80211_txrx_result
33819 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx);
33821 +void ieee80211_install_qdisc(struct net_device *dev);
33823 +int ieee80211_wme_register(void);
33824 +void ieee80211_wme_unregister(void);
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
33832 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
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>
33850 +#include <net/d80211.h>
33851 +#include <net/d80211_common.h>
33852 +#include "ieee80211_i.h"
33853 +#include "michael.h"
33855 +#include "aes_ccm.h"
33857 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33858 +#include "hostapd_ioctl.h"
33859 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33862 +#define MICHAEL_MIC_HWACCEL
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)
33868 + struct ieee80211_hdr *hdr;
33874 + hdr = (struct ieee80211_hdr *) skb->data;
33875 + fc = le16_to_cpu(hdr->frame_control);
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;
33890 + *sa = hdr->addr2;
33891 + *da = hdr->addr1;
33897 + *data = skb->data + hdrlen;
33898 + *data_len = skb->len - hdrlen;
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;
33907 + *qos_tid = pos[0] & 0x0f;
33908 + *qos_tid |= 0x80; /* qos_included flag */
33912 + return skb->len < hdrlen ? -1 : 0;
33916 +ieee80211_txrx_result
33917 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
33919 + u8 *data, *sa, *da, *key, *mic, qos_tid;
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;
33930 + if (!tx->key || tx->key->alg != ALG_TKIP || skb->len < 24 ||
33931 + !WLAN_FC_DATA_PRESENT(fc))
33932 + return TXRX_CONTINUE;
33934 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
33935 + return TXRX_DROP;
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)) {
33943 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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
33950 + return TXRX_CONTINUE;
33952 +#endif /* MICHAEL_MIC_HWACCEL */
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,
33959 + printk(KERN_DEBUG "%s: failed to allocate more memory "
33960 + "for Michael MIC\n", tx->dev->name);
33961 + return TXRX_DROP;
33966 + authenticator = fc & WLAN_FC_FROMDS; /* FIX */
33968 + authenticator = 1;
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);
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;
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;
33993 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33995 + return TXRX_CONTINUE;
33999 +ieee80211_txrx_result
34000 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
34002 + u8 *data, *sa, *da, *key = NULL, qos_tid;
34005 + u8 mic[MICHAEL_MIC_LEN];
34006 + struct sk_buff *skb = rx->skb;
34007 + int authenticator = 1, wpa_test = 0;
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;
34016 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34017 + !(rx->fc & WLAN_FC_ISWEP) || !WLAN_FC_DATA_PRESENT(fc))
34018 + return TXRX_CONTINUE;
34020 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34021 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34024 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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;
34033 + /* Need to verify Michael MIC sometimes in software even when
34034 + * hwaccel is used. Atheros ar5212: fragmented frames and QoS
34036 + if (!rx->fragmented && !wpa_test)
34039 +#endif /* MICHAEL_MIC_HWACCEL */
34041 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
34042 + || data_len < MICHAEL_MIC_LEN)
34043 + return TXRX_DROP;
34045 + data_len -= MICHAEL_MIC_LEN;
34048 + authenticator = fc & WLAN_FC_TODS; /* FIX */
34050 + authenticator = 1;
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;
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
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]);
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 */
34086 + struct ieee80211_hdr *hdr;
34087 + union iwreq_data wrqu;
34088 + char *buf = kmalloc(128, GFP_ATOMIC);
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 ")",
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);
34105 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
34106 + ieee80211_msg_michael_mic_failure);
34108 + return TXRX_QUEUED;
34111 +#ifdef MICHAEL_MIC_HWACCEL
34113 +#endif /* MICHAEL_MIC_HWACCEL */
34114 + /* remove Michael MIC from payload */
34115 + skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
34117 + return TXRX_CONTINUE;
34121 +static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
34122 + struct sk_buff *skb, int test)
34124 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34125 + struct ieee80211_key *key = tx->key;
34126 + int hdrlen, len, tailneed;
34130 + fc = le16_to_cpu(hdr->frame_control);
34131 + hdrlen = ieee80211_get_hdrlen(fc);
34132 + len = skb->len - hdrlen;
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,
34144 + pos = skb_push(skb, TKIP_IV_LEN);
34145 + memmove(pos, pos + TKIP_IV_LEN, hdrlen);
34148 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34149 + if (test & WPA_TRIGGER_TX_REPLAY)
34150 + goto skip_iv_inc;
34152 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34154 + /* Increase IV for the frame */
34155 + key->u.tkip.iv16++;
34156 + if (key->u.tkip.iv16 == 0)
34157 + key->u.tkip.iv32++;
34159 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34160 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34165 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34167 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt
34168 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34170 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34172 + /* hwaccel - with preallocated room for IV */
34174 + ieee80211_tkip_add_iv(pos, key,
34175 + (u8) (key->u.tkip.iv16 >> 8),
34176 + (u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
34178 + (u8) key->u.tkip.iv16);
34180 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34184 + /* Add room for ICV */
34185 + skb_put(skb, TKIP_ICV_LEN);
34187 + hdr = (struct ieee80211_hdr *) skb->data;
34188 + ieee80211_tkip_encrypt_data(key, pos, len, hdr->addr2);
34193 +ieee80211_txrx_result
34194 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx)
34196 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34198 + struct ieee80211_key *key = tx->key;
34199 + struct sk_buff *skb = tx->skb;
34200 + int wpa_test = 0, test = 0;
34202 + fc = le16_to_cpu(hdr->frame_control);
34204 + if (!key || key->alg != ALG_TKIP || !WLAN_FC_DATA_PRESENT(fc))
34205 + return TXRX_CONTINUE;
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);
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)) {
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);
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);
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]" : "");
34240 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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;
34249 + if (tkip_encrypt_skb(tx, skb, test) < 0)
34250 + return TXRX_DROP;
34252 + if (tx->u.tx.extra_frag) {
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)
34261 + return TXRX_DROP;
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",
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]++;
34282 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34284 + return TXRX_CONTINUE;
34288 +ieee80211_txrx_result
34289 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx)
34291 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34293 + int hdrlen, res, hwaccel = 0, wpa_test = 0;
34294 + struct ieee80211_key *key = rx->key;
34295 + struct sk_buff *skb = rx->skb;
34297 + fc = le16_to_cpu(hdr->frame_control);
34298 + hdrlen = ieee80211_get_hdrlen(fc);
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;
34305 + if (!rx->sta || skb->len - hdrlen < 12)
34306 + return TXRX_DROP;
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]++;
34317 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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;
34327 + /* let TKIP code verify IV, but skip decryption */
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;
34342 + skb_trim(skb, skb->len - TKIP_ICV_LEN);
34345 + memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
34346 + skb_pull(skb, TKIP_IV_LEN);
34348 + return TXRX_CONTINUE;
34352 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
34356 + int a4_included, qos_included;
34357 + u8 qos_tid, *fc_pos, *data, *sa, *da;
34360 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
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);
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;
34373 + qos_included = 0;
34374 + /* First block, b_0 */
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);
34382 + b_0[14] = (data_len >> 8) & 0xff;
34383 + b_0[15] = data_len & 0xff;
34386 + /* AAD (extra authenticate-only data) / masked 802.11 header
34387 + * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
34389 + len_a = a4_included ? 28 : 22;
34390 + if (qos_included)
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);
34401 + /* Mask Seq#, leave Frag# */
34402 + aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
34404 + if (a4_included) {
34405 + memcpy(&aad[24], hdr->addr4, 6);
34409 + memset(&aad[24], 0, 8);
34410 + if (qos_included) {
34411 + u8 *dpos = &aad[a4_included ? 30 : 24];
34413 + /* Mask QoS Control field */
34414 + dpos[0] = qos_tid;
34420 +static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
34425 + hdr[3] = 0x20 | (key_id << 6);
34433 +static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
34441 + return (hdr[3] >> 6) & 0x03;
34445 +static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
34446 + struct sk_buff *skb, int test)
34448 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34449 + struct ieee80211_key *key = tx->key;
34450 + int hdrlen, len, tailneed;
34453 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34456 + fc = le16_to_cpu(hdr->frame_control);
34457 + hdrlen = ieee80211_get_hdrlen(fc);
34458 + len = skb->len - hdrlen;
34460 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34461 + ? 0 : CCMP_MIC_LEN;
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,
34471 + pos = skb_push(skb, CCMP_HDR_LEN);
34472 + memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
34473 + hdr = (struct ieee80211_hdr *) pos;
34476 + /* PN = PN + 1 */
34477 + pn = key->u.ccmp.tx_pn;
34479 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34480 + if (test & WPA_TRIGGER_TX_REPLAY)
34481 + goto skip_pn_inc;
34483 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34485 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
34491 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34492 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34497 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34499 + ccmp_pn2hdr(pos, pn, key->keyidx);
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;
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));
34516 +ieee80211_txrx_result
34517 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx)
34519 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34520 + struct ieee80211_key *key = tx->key;
34522 + struct sk_buff *skb = tx->skb;
34525 + fc = le16_to_cpu(hdr->frame_control);
34527 + if (!key || key->alg != ALG_CCMP || !WLAN_FC_DATA_PRESENT(fc))
34528 + return TXRX_CONTINUE;
34530 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34532 + test = tx->sta->wpa_trigger;
34533 + tx->sta->wpa_trigger = 0;
34535 + test = tx->local->wpa_trigger;
34536 + tx->local->wpa_trigger = 0;
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]" : "");
34549 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
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);
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;
34563 + if (ccmp_encrypt_skb(tx, skb, test) < 0)
34564 + return TXRX_DROP;
34566 + if (tx->u.tx.extra_frag) {
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)
34575 + return TXRX_DROP;
34579 + return TXRX_CONTINUE;
34583 +ieee80211_txrx_result
34584 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx)
34586 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
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];
34595 + fc = le16_to_cpu(hdr->frame_control);
34596 + hdrlen = ieee80211_get_hdrlen(fc);
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;
34603 + data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
34604 + if (!rx->sta || data_len < 0)
34605 + return TXRX_DROP;
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;
34612 + (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
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;
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 */
34632 + ccmp_special_blocks(skb, pn, b_0, aad, 1);
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;
34646 + memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
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);
34653 + return TXRX_CONTINUE;
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
34661 + * Copyright 2002-2004, Instant802 Networks, Inc.
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.
34671 +#include <linux/skbuff.h>
34672 +#include <linux/types.h>
34673 +#include "ieee80211_i.h"
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);
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);
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);
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);
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
34698 #include <linux/string.h>
34699 #include <net/ieee80211.h>
34702 MODULE_AUTHOR("Jouni Malinen");
34703 MODULE_DESCRIPTION("HostAP crypto");
34704 MODULE_LICENSE("GPL");
34705 @@ -33,11 +32,11 @@
34707 void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
34709 - struct ieee80211_crypt_data *entry, *next;
34710 + struct ieee80211_crypt_data *entry, *next;
34711 unsigned long flags;
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)
34719 @@ -141,9 +140,9 @@
34720 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
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);
34731 @@ -163,7 +162,7 @@
34732 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34737 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
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);
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)
34751 struct ieee80211_ccmp_data *key = priv;
34753 @@ -199,6 +200,9 @@
34754 if (skb_headroom(skb) < CCMP_HDR_LEN || skb->len < hdr_len)
34757 + if (aeskey != NULL && keylen >= CCMP_TK_LEN)
34758 + memcpy(aeskey, key->key, CCMP_TK_LEN);
34760 pos = skb_push(skb, CCMP_HDR_LEN);
34761 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
34763 @@ -238,7 +242,7 @@
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);
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
34777 struct ieee80211_tkip_data *priv;
34779 - priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
34780 + priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
34783 - memset(priv, 0, sizeof(*priv));
34785 priv->key_idx = key_idx;
34787 @@ -271,34 +270,33 @@
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)
34795 struct ieee80211_tkip_data *tkey = priv;
34797 - u8 *rc4key, *pos, *icv;
34799 struct ieee80211_hdr_4addr *hdr;
34802 hdr = (struct ieee80211_hdr_4addr *)skb->data;
34804 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
34808 + if (rc4key == NULL || keylen < 16)
34811 if (!tkey->tx_phase1_done) {
34812 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
34814 tkey->tx_phase1_done = 1;
34816 - rc4key = kmalloc(16, GFP_ATOMIC);
34819 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
34821 len = skb->len - hdr_len;
34822 pos = skb_push(skb, 8);
34823 memmove(pos, pos + 8, hdr_len);
34825 - icv = skb_put(skb, 4);
34828 *pos++ = *(rc4key + 1);
34829 @@ -309,28 +307,28 @@
34830 *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
34831 *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
34833 - crc = ~crc32_le(~0, pos, len);
34835 - icv[1] = crc >> 8;
34836 - icv[2] = crc >> 16;
34837 - icv[3] = crc >> 24;
34839 + if (tkey->tx_iv16 == 0) {
34840 + tkey->tx_phase1_done = 0;
34848 static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
34850 struct ieee80211_tkip_data *tkey = priv;
34852 - const u8 *rc4key;
34854 + u8 rc4key[16], *pos, *icv;
34856 struct scatterlist sg;
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));
34867 @@ -343,22 +341,23 @@
34868 len = skb->len - hdr_len;
34869 pos = skb->data + hdr_len;
34871 - rc4key = ieee80211_tkip_hdr(skb, hdr_len, priv);
34873 + if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
34876 + icv = skb_put(skb, 4);
34878 + crc = ~crc32_le(~0, pos, len);
34880 + icv[1] = crc >> 8;
34881 + icv[2] = crc >> 16;
34882 + icv[3] = crc >> 24;
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);
34891 - if (tkey->tx_iv16 == 0) {
34892 - tkey->tx_phase1_done = 0;
34899 @@ -379,7 +378,7 @@
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));
34908 @@ -695,6 +694,7 @@
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
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)
34927 struct prism2_wep_data *wep = priv;
34929 @@ -131,7 +132,7 @@
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))
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
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)
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
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;
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;
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)
34976 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
34977 for (i = 0; i < ieee->geo.bg_channels; i++)
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)
34988 @@ -133,6 +138,41 @@
34992 +u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
34994 + int index = ieee80211_channel_to_index(ieee, channel);
34997 + return IEEE80211_CH_INVALID;
34999 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35000 + return ieee->geo.bg[index].flags;
35002 + return ieee->geo.a[index].flags;
35005 +static const struct ieee80211_channel bad_channel = {
35007 + .flags = IEEE80211_CH_INVALID,
35011 +const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
35012 + *ieee, u8 channel)
35014 + int index = ieee80211_channel_to_index(ieee, channel);
35017 + return &bad_channel;
35019 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35020 + return &ieee->geo.bg[index];
35022 + return &ieee->geo.a[index];
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 @@
35037 +void ieee80211_network_reset(struct ieee80211_network *network)
35042 + if (network->ibss_dfs) {
35043 + kfree(network->ibss_dfs);
35044 + network->ibss_dfs = NULL;
35048 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
35052 if (!ieee->networks)
35055 + for (i = 0; i < MAX_NETWORK_COUNT; i++)
35056 + if (ieee->networks[i].ibss_dfs)
35057 + kfree(ieee->networks[i].ibss_dfs);
35059 kfree(ieee->networks);
35060 ieee->networks = NULL;
35062 @@ -195,7 +213,7 @@
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;
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 @@
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);
35088 -#endif /* CONFIG_NET_RADIO */
35089 #endif /* IW_WIRELESS_SPY */
35090 +#endif /* CONFIG_WIRELESS_EXT */
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)) {
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));
35106 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
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++;
35119 @@ -930,6 +937,45 @@
35123 +#ifdef CONFIG_IEEE80211_DEBUG
35124 +#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
35126 +static const char *get_info_element_string(u16 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);
35157 + return "UNKNOWN";
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 @@
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");
35175 case MFIE_TYPE_ERP_INFO:
35176 @@ -1091,10 +1139,49 @@
35178 "QoS Error need to parse QOS_PARAMETER IE\n");
35181 + case MFIE_TYPE_POWER_CONSTRAINT:
35182 + network->power_constraint = info_element->data[0];
35183 + network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
35186 + case MFIE_TYPE_CSA:
35187 + network->power_constraint = info_element->data[0];
35188 + network->flags |= NETWORK_HAS_CSA;
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;
35199 + case MFIE_TYPE_IBSS_DFS:
35200 + if (network->ibss_dfs)
35202 + network->ibss_dfs =
35203 + kmalloc(info_element->len, GFP_ATOMIC);
35204 + if (!network->ibss_dfs)
35206 + memcpy(network->ibss_dfs, info_element->data,
35207 + info_element->len);
35208 + network->flags |= NETWORK_HAS_IBSS_DFS;
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;
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);
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)
35232 - struct ieee80211_network network_resp;
35233 + struct ieee80211_network network_resp = {
35234 + .ibss_dfs = NULL,
35236 struct ieee80211_network *network = &network_resp;
35237 struct net_device *dev = ieee->dev;
35239 @@ -1253,7 +1342,22 @@
35243 - memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
35244 + ieee80211_network_reset(dst);
35245 + dst->ibss_dfs = src->ibss_dfs;
35247 + /* We only update the statistics if they were created by receiving
35248 + * the network information on the actual channel the network is on.
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));
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);
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;
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 @@
35274 struct net_device *dev = ieee->dev;
35275 - struct ieee80211_network network;
35276 + struct ieee80211_network network = {
35277 + .ibss_dfs = NULL,
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,
35285 MAC_ARG(target->bssid));
35286 + ieee80211_network_reset(target);
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");
35293 memcpy(target, &network, sizeof(*target));
35294 + network.ibss_dfs = NULL;
35295 list_add_tail(&target->list, &ieee->network_list);
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;
35305 spin_unlock_irqrestore(&ieee->lock, flags);
35306 @@ -1495,10 +1605,43 @@
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 *)
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)));
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 *)
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)));
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);
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 *)
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
35356 `--------------------------------------------------| |------'
35357 Total: 28 non-data bytes `----.----'
35359 - .- 'Frame data' expands to <---------------------------'
35360 + .- 'Frame data' expands, if WEP enabled, to <----------'
35363 + ,-----------------------.
35364 +Bytes | 4 | 0-2296 | 4 |
35365 + |-----|-----------|-----|
35366 +Desc. | IV | Encrypted | ICV |
35371 + .- 'Encrypted Packet' expands to
35374 ,---------------------------------------------------.
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 `----.----'
35382 - .- 'IP Packet' expands, if WEP enabled, to <--'
35385 - ,-----------------------.
35386 -Bytes | 4 | 0-2296 | 4 |
35387 - |-----|-----------|-----|
35388 -Desc. | IV | Encrypted | ICV |
35389 - | | IP Packet | |
35390 - `-----------------------'
35391 + `----------------------------------------------------
35392 Total: 8 non-data bytes
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,
35400 + ieee->sec.keys[ieee->sec.active_key],
35401 + ieee->sec.key_sizes[ieee->sec.active_key],
35403 atomic_dec(&crypt->refcnt);
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;
35415 - iwe.u.qual.level = network->stats.rssi;
35416 if (ieee->perfect_rssi == ieee->worst_rssi)
35417 iwe.u.qual.qual = 100;
35419 @@ -179,6 +177,13 @@
35420 iwe.u.qual.noise = network->stats.noise;
35423 + if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) {
35424 + iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
35425 + iwe.u.qual.level = 0;
35427 + iwe.u.qual.level = network->stats.signal;
35430 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
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);
35437 + memset(&iwe, 0, sizeof(iwe));
35438 if (network->wpa_ie_len) {
35439 - char buf[MAX_WPA_IE_LEN * 2 + 30];
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]);
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);
35457 + memset(&iwe, 0, sizeof(iwe));
35458 if (network->rsn_ie_len) {
35459 - char buf[MAX_WPA_IE_LEN * 2 + 30];
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]);
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);
35477 @@ -229,6 +222,28 @@
35478 if (iwe.u.data.length)
35479 start = iwe_stream_add_point(start, stop, &iwe, custom);
35481 + /* Add spectrum management information */
35484 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Channel flags: ");
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 ");
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 ");
35498 + if (iwe.cmd == IWEVCUSTOM) {
35499 + iwe.u.data.length = p - custom;
35500 + start = iwe_stream_add_point(start, stop, &iwe, custom);
35506 @@ -734,9 +749,98 @@
35510 +int ieee80211_wx_set_auth(struct net_device *dev,
35511 + struct iw_request_info *info,
35512 + union iwreq_data *wrqu,
35515 + struct ieee80211_device *ieee = netdev_priv(dev);
35516 + unsigned long flags;
35519 + spin_lock_irqsave(&ieee->lock, flags);
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:
35527 + * Host AP driver does not use these parameters and allows
35528 + * wpa_supplicant to control them internally.
35531 + case IW_AUTH_TKIP_COUNTERMEASURES:
35532 + break; /* FIXME */
35533 + case IW_AUTH_DROP_UNENCRYPTED:
35534 + ieee->drop_unencrypted = !!wrqu->param.value;
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;
35541 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35542 + ieee->ieee802_1x = !!wrqu->param.value;
35544 + case IW_AUTH_PRIVACY_INVOKED:
35545 + ieee->privacy_invoked = !!wrqu->param.value;
35548 + err = -EOPNOTSUPP;
35551 + spin_unlock_irqrestore(&ieee->lock, flags);
35555 +int ieee80211_wx_get_auth(struct net_device *dev,
35556 + struct iw_request_info *info,
35557 + union iwreq_data *wrqu,
35560 + struct ieee80211_device *ieee = netdev_priv(dev);
35561 + unsigned long flags;
35564 + spin_lock_irqsave(&ieee->lock, flags);
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 */
35574 + * Host AP driver does not use these parameters and allows
35575 + * wpa_supplicant to control them internally.
35577 + err = -EOPNOTSUPP;
35579 + case IW_AUTH_DROP_UNENCRYPTED:
35580 + wrqu->param.value = ieee->drop_unencrypted;
35582 + case IW_AUTH_WPA_ENABLED:
35583 + wrqu->param.value = ieee->wpa_enabled;
35585 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35586 + wrqu->param.value = ieee->ieee802_1x;
35589 + err = -EOPNOTSUPP;
35592 + spin_unlock_irqrestore(&ieee->lock, flags);
35596 EXPORT_SYMBOL(ieee80211_wx_set_encodeext);
35597 EXPORT_SYMBOL(ieee80211_wx_get_encodeext);
35599 EXPORT_SYMBOL(ieee80211_wx_get_scan);
35600 EXPORT_SYMBOL(ieee80211_wx_set_encode);
35601 EXPORT_SYMBOL(ieee80211_wx_get_encode);
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"
35615 +config WIRELESS_EXT
35619 endmenu # Networking
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
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/
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
35636 #include <linux/compat.h>
35637 #include <linux/kmod.h>
35638 #include <linux/audit.h>
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>
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);
35651 -#ifdef WIRELESS_EXT
35652 +#ifdef CONFIG_WIRELESS_EXT
35653 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
35654 err = dev_ioctl(cmd, argp);
35656 -#endif /* WIRELESS_EXT */
35657 +#endif /* CONFIG_WIRELESS_EXT */
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
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."
35672 + echo "$0 [ wlan_device local_ip wpasupplicant_config ]"
35675 + echo "Run with default parameters: $0"
35676 + echo "Manually define parameters: $0 wlan0 192.168.1.1 ./wpasupp.conf"
35678 + echo "Default parameters are: $0 wlan0 192.168.1.101 /etc/wpa_supplicant.conf"
35686 +if [ -z "$wlan_dev" ]; then
35689 +if [ -z "$sta_dev" ]; then
35692 +if [ -z "$ip_addr" ]; then
35693 + ip_addr="192.168.1.101"
35695 +if [ -z "$wpasupp_conf" ]; then
35696 + wpasupp_conf="/etc/wpa_supplicant.conf"
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"
35712 + if [ $res -ne 0 ]; then
35713 + echo "FAILED ($res)"
35718 +if [ -z "$(grep -e bcm43xx /proc/modules)" ]; then
35719 + echo "ERROR: bcm43xx module not loaded."
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."
35729 +run iwconfig $wlan_dev.11 mode managed
35730 +run ifconfig $wlan_dev.11 up
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
35738 +run wpa_supplicant -B -Dwext -i$sta_dev -c$wpasupp_conf
35741 +echo "You may want to set the default route, now:"
35742 +echo " route add default gw GATEWAY_IP_ADDRESS"